javax.xml.parsers.SAXParser Java Examples

The following examples show how to use javax.xml.parsers.SAXParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SAX2DOMTest.java    From openjdk-jdk9 with GNU General Public License v2.0 7 votes vote down vote up
@Test
public void test() throws Exception {
    SAXParserFactory fac = SAXParserFactory.newInstance();
    fac.setNamespaceAware(true);
    SAXParser saxParser = fac.newSAXParser();

    StreamSource sr = new StreamSource(this.getClass().getResourceAsStream("SAX2DOMTest.xml"));
    InputSource is = SAXSource.sourceToInputSource(sr);
    RejectDoctypeSaxFilter rf = new RejectDoctypeSaxFilter(saxParser);
    SAXSource src = new SAXSource(rf, is);
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    DOMResult result = new DOMResult();
    transformer.transform(src, result);

    Document doc = (Document) result.getNode();
    System.out.println("Name" + doc.getDocumentElement().getLocalName());

    String id = "XWSSGID-11605791027261938254268";
    Element selement = doc.getElementById(id);
    if (selement == null) {
        System.out.println("getElementById returned null");
    }

}
 
Example #2
Source File: XercesParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Configure schema validation as recommended by the JAXP 1.2 spec.
 * The <code>properties</code> object may contains information about
 * the schema local and language. 
 * @param properties parser optional info
 */
private static void configureOldXerces(SAXParser parser, 
                                       Properties properties) 
        throws ParserConfigurationException, 
               SAXNotSupportedException {

    String schemaLocation = (String)properties.get("schemaLocation");
    String schemaLanguage = (String)properties.get("schemaLanguage");

    try{
        if (schemaLocation != null) {
            parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
            parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
        }
    } catch (SAXNotRecognizedException e){
        log.info(parser.getClass().getName() + ": " 
                                    + e.getMessage() + " not supported."); 
    }

}
 
Example #3
Source File: OscarDataParser.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
public void parseDocument(URL oscarURL) {
    //get a factory
    SAXParserFactory spf = SAXParserFactory.newInstance();

    try {
        //get a new instance of parser
        SAXParser sp = spf.newSAXParser();

        //parse the file and also register this class for call backs
        InputStream is = new BufferedInputStream(oscarURL.openStream());
        sp.parse(is, this);
        System.out.println("done parsing count="+count);
        is.close();

    } catch (SAXException se) {
        se.printStackTrace();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (IOException ie) {
        ie.printStackTrace();
    }
}
 
Example #4
Source File: ScanClient.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Obtain data logged by a scan
 *  @param id ID that uniquely identifies a scan (within JVM of the scan engine)
 *  @return {@link ScanData}
 *  @throws Exception on error
 */
public ScanData getScanData(final long id) throws Exception
{
    final HttpURLConnection connection = connect("/scan/" + id + "/data");
    try
    {
        checkResponse(connection);
        final InputStream stream = connection.getInputStream();
        final ScanDataSAXHandler handler = new ScanDataSAXHandler();
        final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        parser.parse(stream, handler);
        return handler.getScanData();
    }
    finally
    {
        connection.disconnect();
    }
}
 
Example #5
Source File: Bug6946312Test.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test() throws SAXException, ParserConfigurationException, IOException {
    Schema schema = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema").newSchema(new StreamSource(new StringReader(xmlSchema)));

    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
    saxParserFactory.setNamespaceAware(true);
    saxParserFactory.setSchema(schema);
    // saxParserFactory.setFeature("http://java.sun.com/xml/schema/features/report-ignored-element-content-whitespace",
    // true);

    SAXParser saxParser = saxParserFactory.newSAXParser();

    XMLReader xmlReader = saxParser.getXMLReader();

    xmlReader.setContentHandler(new MyContentHandler());

    // InputStream input =
    // ClassLoader.getSystemClassLoader().getResourceAsStream("test/test.xml");

    InputStream input = getClass().getResourceAsStream("Bug6946312.xml");
    System.out.println("Parse InputStream:");
    xmlReader.parse(new InputSource(input));
    if (!charEvent) {
        Assert.fail("missing character event");
    }
}
 
Example #6
Source File: IngredientHandler.java    From biermacht with Apache License 2.0 6 votes vote down vote up
public ArrayList<BeerStyle> getStylesFromXml(String filePath) throws IOException {
  ArrayList<BeerStyle> list = new ArrayList<BeerStyle>();
  BeerXmlReader myXMLHandler = new BeerXmlReader();
  SAXParserFactory spf = SAXParserFactory.newInstance();

  try {
    SAXParser sp = spf.newSAXParser();
    InputStream is = mContext.getAssets().open(filePath);
    sp.parse(is, myXMLHandler);

    list.addAll(myXMLHandler.getBeerStyles());
  } catch (Exception e) {
    Log.e("getStylesFromXml", e.toString());
  }

  return list;
}
 
Example #7
Source File: EsoReader.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
public void parseFile(String filePath) {
    String myerror = "";
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setValidating(false);
        SAXParser parser = factory.newSAXParser();
        InputSource inp = new InputSource (new FileReader(filePath));
        parser.parse(inp, this);
    } catch (SAXParseException err) {
        myerror = "\n** Parsing error" + ", line " + err.getLineNumber()
                + ", uri " + err.getSystemId();
        myerror += "\n" + err.getMessage();
        System.out.println("myerror = " + myerror);
    } catch (SAXException e) {
        Exception x = e;
        if (e.getException() != null)
            x = e.getException();
        myerror += "\nSAXException --" + x.getMessage();
        System.out.println("myerror = " + myerror);
    } catch (Exception eee) {
        eee.printStackTrace();
        myerror += "\nException --" + eee.getMessage();
        System.out.println("myerror = " + myerror);
    }
}
 
Example #8
Source File: DatasetReader.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reads a {@link CategoryDataset} from a stream.
 *
 * @param in  the stream.
 *
 * @return A dataset.
 *
 * @throws IOException if there is a problem reading the file.
 */
public static CategoryDataset readCategoryDatasetFromXML(InputStream in)
    throws IOException {

    CategoryDataset result = null;

    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
        SAXParser parser = factory.newSAXParser();
        CategoryDatasetHandler handler = new CategoryDatasetHandler();
        parser.parse(in, handler);
        result = handler.getDataset();
    }
    catch (SAXException e) {
        System.out.println(e.getMessage());
    }
    catch (ParserConfigurationException e2) {
        System.out.println(e2.getMessage());
    }
    return result;

}
 
Example #9
Source File: FeedHandler.java    From AntennaPodSP with MIT License 6 votes vote down vote up
public Feed parseFeed(Feed feed) throws SAXException, IOException,
        ParserConfigurationException, UnsupportedFeedtypeException {
    TypeGetter tg = new TypeGetter();
    TypeGetter.Type type = tg.getType(feed);
    SyndHandler handler = new SyndHandler(feed, type);

    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    SAXParser saxParser = factory.newSAXParser();
    File file = new File(feed.getFile_url());
    Reader inputStreamReader = new XmlStreamReader(file);
    InputSource inputSource = new InputSource(inputStreamReader);

    saxParser.parse(inputSource, handler);
    inputStreamReader.close();
    return handler.state.feed;
}
 
Example #10
Source File: PrintTable.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    try {
        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
        saxParserFactory.setNamespaceAware(true);

        SAXParser saxParser = saxParserFactory.newSAXParser();

        ParserVocabulary referencedVocabulary = new ParserVocabulary();

        VocabularyGenerator vocabularyGenerator = new VocabularyGenerator(referencedVocabulary);
        File f = new File(args[0]);
        saxParser.parse(f, vocabularyGenerator);

        printVocabulary(referencedVocabulary);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #11
Source File: cfWDDX.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
public static cfData wddx2Cfml( String _wddxString, cfSession _Session ) throws cfmRunTimeException{
wddxHandler handler = new wddxHandler( _Session );//TODO: remove, _output );			
SAXParserFactory factory = SAXParserFactory.newInstance(); 
         
try{
	SAXParser xmlParser = factory.newSAXParser();
	InputSource ip = new InputSource( new StringReader( _wddxString ));
	xmlParser.parse( ip, handler );
    return handler.getResult();
}catch(Exception e){
	cfCatchData	catchData	= new cfCatchData( _Session );
   catchData.setType( "WDDX" );
   catchData.setDetail( "CFWDDX" );
 	catchData.setMessage( "Error deserializing WDDX string: " + (e instanceof NullPointerException ? "Badly Formatted xml" : e.getMessage() ) );
	throw new cfmRunTimeException( catchData );  
}
}
 
Example #12
Source File: BackendManager.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
public ArrayList<Episode> fetchEpisodes(String feedUrl, Podcast podcast) {
    try {
        Request request = new Request.Builder().url(feedUrl).build();
        String response = BackendManager.getInstance().sendSimpleSynchronicRequest(request);
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        EpisodesXMLHandler episodesXMLHandler = new EpisodesXMLHandler();
        xr.setContentHandler(episodesXMLHandler);

        //TODO could be encoding problem
        InputSource inputSource = new InputSource(new StringReader(response));
        xr.parse(inputSource);
        ArrayList<Episode> parsedEpisodes = episodesXMLHandler.getParsedEpisods();
        if (podcast != null) {
            podcast.setDescription(episodesXMLHandler.getPodcastSummary());
        }
        return parsedEpisodes;
    } catch (Exception e) {
        Logger.printError(TAG, "Can't fetch episodes for url: " + feedUrl);
        e.printStackTrace();
        return new ArrayList<Episode>();
    }
}
 
Example #13
Source File: OscarDataParser.java    From Darcula with Apache License 2.0 6 votes vote down vote up
public void parseDocument(URL oscarURL) {
    //get a factory
    SAXParserFactory spf = SAXParserFactory.newInstance();

    try {
        //get a new instance of parser
        SAXParser sp = spf.newSAXParser();

        //parse the file and also register this class for call backs
        InputStream is = new BufferedInputStream(oscarURL.openStream());
        sp.parse(is, this);
        System.out.println("done parsing count="+count);
        is.close();

    } catch (SAXException se) {
        se.printStackTrace();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (IOException ie) {
        ie.printStackTrace();
    }
}
 
Example #14
Source File: TunedDocumentLoader.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public Document loadDocument(InputSource inputSource, EntityResolver entityResolver,
                             ErrorHandler errorHandler, int validationMode, boolean namespaceAware)
    throws Exception {
    if (validationMode == XmlBeanDefinitionReader.VALIDATION_NONE) {
        SAXParserFactory parserFactory =
            namespaceAware ? nsasaxParserFactory : saxParserFactory;
        SAXParser parser = parserFactory.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        reader.setEntityResolver(entityResolver);
        reader.setErrorHandler(errorHandler);
        SAXSource saxSource = new SAXSource(reader, inputSource);
        W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
        StaxUtils.copy(saxSource, writer);
        return writer.getDocument();
    }
    return super.loadDocument(inputSource, entityResolver, errorHandler, validationMode,
                              namespaceAware);
}
 
Example #15
Source File: BodyParserSAX.java    From jbosh with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public BodyParserResults parse(String xml) throws BOSHException {
    BodyParserResults result = new BodyParserResults();
    Exception thrown;
    try {
        InputStream inStream = new ByteArrayInputStream(xml.getBytes());
        SAXParser parser = getSAXParser();
        parser.parse(inStream, new Handler(parser, result));
        return result;
    } catch (SAXException saxx) {
        thrown = saxx;
    } catch (IOException iox) {
        thrown = iox;
    }
    throw(new BOSHException("Could not parse body:\n" + xml, thrown));
}
 
Example #16
Source File: PositionXmlParser.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@NonNull
private Document parse(@NonNull String xml, @NonNull InputSource input, boolean checkBom)
        throws ParserConfigurationException, SAXException, IOException {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setFeature(NAMESPACE_FEATURE, true);
        factory.setFeature(NAMESPACE_PREFIX_FEATURE, true);
        SAXParser parser = factory.newSAXParser();
        DomBuilder handler = new DomBuilder(xml);
        parser.parse(input, handler);
        return handler.getDocument();
    } catch (SAXException e) {
        if (checkBom && e.getMessage().contains("Content is not allowed in prolog")) {
            // Byte order mark in the string? Skip it. There are many markers
            // (see http://en.wikipedia.org/wiki/Byte_order_mark) so here we'll
            // just skip those up to the XML prolog beginning character, <
            xml = xml.replaceFirst("^([\\W]+)<","<");  //$NON-NLS-1$ //$NON-NLS-2$
            return parse(xml, new InputSource(new StringReader(xml)), false);
        }
        throw e;
    }
}
 
Example #17
Source File: JAXPParser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void parse( InputSource source, ContentHandler handler,
    ErrorHandler errorHandler, EntityResolver entityResolver )

    throws SAXException, IOException {

    try {
        SAXParser saxParser = allowFileAccess(factory.newSAXParser(), false);
        XMLReader reader = new XMLReaderEx(saxParser.getXMLReader());

        reader.setContentHandler(handler);
        if(errorHandler!=null)
            reader.setErrorHandler(errorHandler);
        if(entityResolver!=null)
            reader.setEntityResolver(entityResolver);
        reader.parse(source);
    } catch( ParserConfigurationException e ) {
        // in practice this won't happen
        SAXParseException spe = new SAXParseException(e.getMessage(),null,e);
        errorHandler.fatalError(spe);
        throw spe;
    }
}
 
Example #18
Source File: Filter.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Parse and load the given filter file.
 *
 * @param fileName
 *            name of the filter file
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
private void parse(String fileName, @WillClose InputStream stream) throws IOException, SAXException, ParserConfigurationException {
    try {
        SAXBugCollectionHandler handler = new SAXBugCollectionHandler(this, new File(fileName));
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        parserFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
        parserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", Boolean.TRUE);
        parserFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE);
        parserFactory.setFeature("http://xml.org/sax/features/external-general-entities", Boolean.FALSE);
        parserFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", Boolean.FALSE);
        SAXParser parser = parserFactory.newSAXParser();
        XMLReader xr = parser.getXMLReader();
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        Reader reader = Util.getReader(stream);
        xr.parse(new InputSource(reader));
    } finally {
        Util.closeSilently(stream);
    }
}
 
Example #19
Source File: RepoDetails.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
public static RepoDetails getFromFile(InputStream inputStream, int pushRequests) {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        SAXParser parser = factory.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        RepoDetails repoDetails = new RepoDetails();
        MockRepo mockRepo = new MockRepo(100, pushRequests);
        RepoXMLHandler handler = new RepoXMLHandler(mockRepo, repoDetails);
        reader.setContentHandler(handler);
        InputSource is = new InputSource(new BufferedInputStream(inputStream));
        reader.parse(is);
        return repoDetails;
    } catch (ParserConfigurationException | SAXException | IOException e) {
        e.printStackTrace();
        fail();

        // Satisfies the compiler, but fail() will always throw a runtime exception so we never
        // reach this return statement.
        return null;
    }
}
 
Example #20
Source File: JAXPParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void parse( InputSource source, ContentHandler handler,
    ErrorHandler errorHandler, EntityResolver entityResolver )

    throws SAXException, IOException {

    try {
        SAXParser saxParser = allowFileAccess(factory.newSAXParser(), false);
        XMLReader reader = new XMLReaderEx(saxParser.getXMLReader());

        reader.setContentHandler(handler);
        if(errorHandler!=null)
            reader.setErrorHandler(errorHandler);
        if(entityResolver!=null)
            reader.setEntityResolver(entityResolver);
        reader.parse(source);
    } catch( ParserConfigurationException e ) {
        // in practice this won't happen
        SAXParseException spe = new SAXParseException(e.getMessage(),null,e);
        errorHandler.fatalError(spe);
        throw spe;
    }
}
 
Example #21
Source File: XML_SAX_StAX_FI.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void parse(InputStream xml, OutputStream finf, String workingDirectory) throws Exception {
    StAXDocumentSerializer documentSerializer = new StAXDocumentSerializer();
    documentSerializer.setOutputStream(finf);

    SAX2StAXWriter saxTostax = new SAX2StAXWriter(documentSerializer);

    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
    saxParserFactory.setNamespaceAware(true);
    SAXParser saxParser = saxParserFactory.newSAXParser();

    XMLReader reader = saxParser.getXMLReader();
    reader.setProperty("http://xml.org/sax/properties/lexical-handler", saxTostax);
    reader.setContentHandler(saxTostax);

    if (workingDirectory != null) {
        reader.setEntityResolver(createRelativePathResolver(workingDirectory));
    }
    reader.parse(new InputSource(xml));

    xml.close();
    finf.close();
}
 
Example #22
Source File: ProductImportParser.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Parse the given XML string an create/update the corresponding entities
 * 
 * @param xml
 *            the XML string
 * @return the parse return code
 * @throws Exception
 */
public int parse(byte[] xml) throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    SchemaFactory sf = SchemaFactory
            .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    try (InputStream inputStream = ResourceLoader.getResourceAsStream(
            getClass(), getSchemaName())) {
        Schema schema = sf.newSchema(new StreamSource(inputStream));
        spf.setSchema(schema);
    }
    SAXParser saxParser = spf.newSAXParser();
    XMLReader reader = saxParser.getXMLReader();
    reader.setFeature(Constants.XERCES_FEATURE_PREFIX
            + Constants.DISALLOW_DOCTYPE_DECL_FEATURE, true);
    reader.setContentHandler(this);
    reader.parse(new InputSource(new ByteArrayInputStream(xml)));
    return 0;
}
 
Example #23
Source File: DatasetReader.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reads a {@link PieDataset} from a stream.
 *
 * @param in  the input stream.
 *
 * @return A dataset.
 *
 * @throws IOException if there is an I/O error.
 */
public static PieDataset readPieDatasetFromXML(InputStream in)
    throws IOException {

    PieDataset result = null;
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
        SAXParser parser = factory.newSAXParser();
        PieDatasetHandler handler = new PieDatasetHandler();
        parser.parse(in, handler);
        result = handler.getDataset();
    }
    catch (SAXException e) {
        System.out.println(e.getMessage());
    }
    catch (ParserConfigurationException e2) {
        System.out.println(e2.getMessage());
    }
    return result;

}
 
Example #24
Source File: SupplementaryChars.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private SAXParser getParser() {
    SAXParser parser = null;
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        parser = factory.newSAXParser();
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    }
    return parser;
}
 
Example #25
Source File: XmlNode.java    From Hive-XML-SerDe with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param inputStream
 */
protected void initialize(InputStream inputStream) {
    try {
        SAXParser saxParser = FACTORY.newSAXParser();
        saxParser.parse(new InputSource(inputStream), this);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #26
Source File: DeviceParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
private static SAXParser getParser(int version) throws ParserConfigurationException, SAXException {
    Schema schema = DeviceSchema.getSchema(version);
    if (schema != null) {
        sParserFactory.setSchema(schema);
    }
    return sParserFactory.newSAXParser();
}
 
Example #27
Source File: RecordCounter.java    From aliada-tool with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void process(final Exchange exchange) throws Exception {
	final File inputFile = exchange.getIn().getBody(File.class);
	
	final Integer jobId = exchange.getIn().getHeader(Constants.JOB_ID_ATTRIBUTE_NAME, Integer.class);
	final JobInstance configuration = cache.getJobInstance(jobId);
	if (configuration == null) {
		log.error(MessageCatalog._00038_UNKNOWN_JOB_ID, jobId);
		throw new IllegalArgumentException(String.valueOf(jobId));
	}
	
	final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
	parser.parse(inputFile, new DefaultHandler() {
		private int howManyRecords;
		
		@Override
		public void startElement(
				final String uri, 
				final String localName, 
				final String qName, 
				final Attributes attributes) throws SAXException {
			if (qName.endsWith(recordElementNameWithNamespace) || qName.equals(recordElementName)) {
				howManyRecords++;
			}
		}
		
		@Override
		public void endDocument() throws SAXException {
			log.info(MessageCatalog._00046_JOB_SIZE, jobId, howManyRecords);
			final JobResource resource = jobRegistry.getJobResource(jobId);
			if (resource != null) {
				resource.setTotalRecordsCount(howManyRecords);					
			}
		}
	});
}
 
Example #28
Source File: SAXParserFactoryImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new instance of <code>SAXParser</code> using the currently
 * configured factory parameters.
 * @return javax.xml.parsers.SAXParser
 */
public SAXParser newSAXParser()
    throws ParserConfigurationException
{
    SAXParser saxParserImpl;
    try {
        saxParserImpl = new SAXParserImpl(this, features, fSecureProcess);
    } catch (SAXException se) {
        // Translate to ParserConfigurationException
        throw new ParserConfigurationException(se.getMessage());
    }
    return saxParserImpl;
}
 
Example #29
Source File: TrxBinder.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
@Override
public void process(File source) throws Exception {
	zeroTime = TIME_MILLIS_FORMAT.parse("00:00:00.000");
	SAXParserFactory factory = SAXParserFactory.newInstance();
	SAXParser saxParser = factory.newSAXParser();
	saxParser.parse(source, this);
}
 
Example #30
Source File: Xlsx2TmxHelper.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void parse(InputStream sheetInputStream, ReadOnlySharedStringsTable sharedStringsTable,
		AbstractWriter tmxWriter) throws ParserConfigurationException, SAXException, IOException {
	InputSource sheetSource = new InputSource(sheetInputStream);
	SAXParserFactory saxFactory = SAXParserFactory.newInstance();
	SAXParser saxParser = saxFactory.newSAXParser();
	XMLReader sheetParser = saxParser.getXMLReader();
	ContentHandler handler = new XSSFHander(sharedStringsTable);
	sheetParser.setContentHandler(handler);
	sheetParser.parse(sheetSource);
	if (langCodes.isEmpty()) {
		throw new SAXException("EMPTY-LANG-CODE");
	}
	writeEnd();
}