Example usage for javax.xml.parsers SAXParser parse

List of usage examples for javax.xml.parsers SAXParser parse

Introduction

In this page you can find the example usage for javax.xml.parsers SAXParser parse.

Prototype

public void parse(InputSource is, DefaultHandler dh) throws SAXException, IOException 

Source Link

Document

Parse the content given org.xml.sax.InputSource as XML using the specified org.xml.sax.helpers.DefaultHandler .

Usage

From source file:com.wooki.services.ImportServiceImpl.java

public Book importDocbook(InputStream generatedXhtml) {
    HTMLParser handler = new HTMLParser();
    SAXParserFactory factory = SAXParserFactory.newInstance();

    // cration d'un parseur SAX
    SAXParser parser;

    try {//from  w  ww . ja  v  a 2  s . c  om
        parser = factory.newSAXParser();
        parser.parse(new InputSource(generatedXhtml), handler);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        logger.error(e.getLocalizedMessage());
        return null;
    } catch (SAXException e) {
        e.printStackTrace();
        logger.error(e.getLocalizedMessage());
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        logger.error(e.getLocalizedMessage());
        return null;
    }

    Book book = handler.getBook();
    Book toReturn = getBookManager().create(book.getTitle());
    return toReturn;
}

From source file:fulcrum.xml.Parser.java

/**
 * * Only provides parsing functions to the "fulcrum.xml" package.
 * //from   w w  w .j a  va 2 s.  c om
 * @see Document
 * 
 * @param f
 * @param document
 * @throws ParseException
 */
protected void parse(File f, Document document) throws ParseException {
    this.document = document;
    try {
        SAXParser sp = getParser();
        sp.parse(f, this);
    } catch (Exception e) {
        throw new ParseException(e);
    }
}

From source file:com.aurel.track.plugin.PluginParser.java

private void parse(InputStream is) {
    //get a factory
    SAXParserFactory spf = SAXParserFactory.newInstance();
    try {//from w  w  w. ja  v a2s  .  c  om
        //get a new instance of parser
        SAXParser sp = spf.newSAXParser();

        //parse the file and also register this class for call backs
        sp.parse(is, this);
    } catch (SAXException se) {
        LOGGER.error(ExceptionUtils.getStackTrace(se));
    } catch (ParserConfigurationException pce) {
        LOGGER.error(ExceptionUtils.getStackTrace(pce));
    } catch (IOException ie) {
        LOGGER.error(ExceptionUtils.getStackTrace(ie));
    }
}

From source file:joachimeichborn.geotag.io.parser.gpx.GpxParser.java

public joachimeichborn.geotag.model.Track read(final Path aGpxFile) throws IOException {
    logger.fine("Reading positions from " + aGpxFile);

    final List<PositionData> positions = new LinkedList<>();

    final SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);//  w  w  w  .  j ava 2 s.c  o  m
    try {
        final SAXParser saxParser = factory.newSAXParser();
        final Handler handler = new Handler();
        saxParser.parse(aGpxFile.toFile(), handler);

        positions.addAll(handler.getPositions());

    } catch (ParserConfigurationException | SAXException e) {
        throw new IOException(e);
    }

    logger.fine("Read " + positions.size() + " coordinates from " + aGpxFile);

    return new joachimeichborn.geotag.model.Track(aGpxFile, positions);
}

From source file:org.olat.core.commons.services.webdav.WebDAVExternalTest.java

private void parse(String response) {
    try {/*w  w w.  j  a  v a 2  s  .  co m*/
        SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
        InputSource in = new InputSource(new StringReader(response));
        saxParser.parse(in, new WebDAVHandler());
    } catch (ParserConfigurationException | SAXException | IOException e) {
        e.printStackTrace();
    }
}

From source file:com.tyndalehouse.step.tools.modules.ConvertXmlToOSISModule.java

private void convertToXml(final String moduleName, final File osisSource) throws Exception {
    LOGGER.debug("Reading [{}]", moduleName);

    SAXParserFactory spf = SAXParserFactory.newInstance();
    final SAXParser saxParser = spf.newSAXParser();
    final ExtractHeaderInformationSax header = new ExtractHeaderInformationSax();
    saxParser.parse(osisSource, header);

    LOGGER.debug(//from  ww  w.ja  v  a 2 s .  c o  m
            "title:[{}], description:[{}], copyright:[{}], license:[{}], language:[{}], versification:[{}]",
            header.getTitle(), header.getDescription(), header.getCopyright(), header.getLicense(),
            header.getLanguage(), header.getVersification());

    String sanitizedModuleName = moduleName.replace("-", "").toLowerCase();

    File outputDirectory = new File(BASE_OUTPUT, sanitizedModuleName);
    outputDirectory.mkdirs();
    BASE_ERRORS.mkdirs();
    //        
    //        LOGGER.debug("Converting [{}] to OSIS Module", sanitizedModuleName);
    //        Process p = Runtime.getRuntime().exec(String.format("osis2mod %s %s -z -v %s", outputDirectory.getAbsolutePath(), osisSource.getAbsolutePath(), header.getVersification()));
    //        LOGGER.debug("Conversion of [{}] finished.", sanitizedModuleName);
    //        outputErrors(p, moduleName);
    //        p.waitFor();

    outputConfFile(header, sanitizedModuleName, FileUtils.sizeOfDirectory(outputDirectory));

}

From source file:MockFedoraIT.java

private void parseIrodsFile(IrodsIFileSystem module, String testPath) throws LowlevelStorageException {
    InputStream is = module.read(new File(testPath));
    // initialize sax for this parse
    try {//from w w  w . ja va 2s  . c o  m
        SAXParserFactory spf = SAXParserFactory.newInstance();
        // spf.setValidating(false);
        // spf.setNamespaceAware(true);
        SAXParser parser = spf.newSAXParser();
        parser.parse(is, new DefaultHandler());
    } catch (Exception e) {
        throw new RuntimeException("Error with SAX parser", e);
    }
}

From source file:com.aurel.track.exchange.track.importer.ImporterFieldParser.java

public List<ISerializableLabelBean> parse(File xml) {
    //get a factory
    SAXParserFactory spf = SAXParserFactory.newInstance();
    try {//from ww w . j a v a 2  s.  co  m
        //get a new instance of parser
        SAXParser sp = spf.newSAXParser();
        //parse the file and also register this class for call backs 
        LOGGER.debug("Field parser started...");
        sp.parse(xml, this);
        LOGGER.debug("Field parser done...");
        return fieldBeans;
    } catch (SAXException se) {
        LOGGER.error(ExceptionUtils.getStackTrace(se));
    } catch (ParserConfigurationException pce) {
        LOGGER.error(ExceptionUtils.getStackTrace(pce));
    } catch (IOException ie) {
        LOGGER.error(ExceptionUtils.getStackTrace(ie));
    }
    return null;
}

From source file:net.sf.ehcache.config.Configurator.java

/**
 * Configures a bean from an XML file./*from w w w  .  j  a va2  s .c om*/
 */
public void configure(final Object bean, final File file) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Configuring ehcache from file: " + file.toString());
    }
    final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
    final BeanHandler handler = new BeanHandler(bean);
    parser.parse(file, handler);
}

From source file:net.sf.ehcache.config.Configurator.java

/**
 * Configures a bean from an XML file available as an URL.
 *///  w  ww. j a  va 2 s.  com
public void configure(final Object bean, final URL url) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Configuring ehcache from URL: " + url);
    }
    final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
    final BeanHandler handler = new BeanHandler(bean);
    parser.parse(url.toExternalForm(), handler);
}