Example usage for javax.xml.parsers SAXParserFactory newSAXParser

List of usage examples for javax.xml.parsers SAXParserFactory newSAXParser

Introduction

In this page you can find the example usage for javax.xml.parsers SAXParserFactory newSAXParser.

Prototype


public abstract SAXParser newSAXParser() throws ParserConfigurationException, SAXException;

Source Link

Document

Creates a new instance of a SAXParser using the currently configured factory parameters.

Usage

From source file:com.xhsoft.framework.common.init.ConfigLoad.java

/**
 * <p>Description:?xmlString?</p>
 * @param strFilePath   /*ww  w . j a  v a2  s. c  om*/
 * @return String
 * @author wenzhi
 * @version 1.0
 */
public void parser(String strFilePath) {
    try {
        /**??*/
        InputStream stream = this.getClass().getResourceAsStream(strFilePath);
        if (stream == null) {
            log.warn(strFilePath + " not found");
        }
        /**SAXParser??*/
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser saxParser = spf.newSAXParser();
        saxParser.parse(stream, this);
        /** ??*/
        this.loadConfig(this.configMap);
    } catch (Exception ex) {
        log.error(" " + strFilePath + " ! ?.");
        ex.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(// w w  w.  j av  a2  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:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static String getSubscriptionArnFromString(String res) {
    javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
    javax.xml.parsers.SAXParser saxParser;

    SubscribeParser p = new SubscribeParser();

    try {//from  ww  w  .  j a  v  a2 s  .  c om
        saxParser = fac.newSAXParser();
        saxParser.parse(new ByteArrayInputStream(res.getBytes()), p);

    } catch (Exception ex) {
        logger.error("Exception parsing", ex);
    }
    String arn = p.getSubscriptionArn();
    return arn;
}

From source file:com.inferiorhumanorgans.WayToGo.Agency.NextBus.RouteList.RouteListXMLTask.java

@Override
protected Void doInBackground(final NextBusAgency... someAgencies) {
    Assert.assertEquals(1, someAgencies.length);
    super.doInBackground(someAgencies);
    String theNBName = theAgency.getNextBusName();

    Log.i(LOG_NAME, "Trying to get the route list for " + theNBName + ".");

    InputStream content = null;/*from   w  ww  .  j av  a 2s .c o  m*/
    ClientConnectionManager connman = new ThreadSafeClientConnManager(params, registry);
    DefaultHttpClient hc = new DefaultHttpClient(connman, params);

    String theNBURL = "http://webservices.nextbus.com/service/publicXMLFeed?command=routeList&a=";
    theNBURL += Uri.encode(theNBName);
    Log.i(LOG_NAME, "Fetching from: " + theNBURL);
    HttpGet getRequest = new HttpGet(theNBURL);
    try {
        content = hc.execute(getRequest).getEntity().getContent();
    } catch (ClientProtocolException ex) {
        Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex);
        this.cancel(true);
        return null;
    }

    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();

        XMLReader xr = sp.getXMLReader();

        xr.setContentHandler(theDataHandler);

        xr.parse(new InputSource(content));

    } catch (ParserConfigurationException pce) {
        Log.e(LOG_NAME + " SAX XML", "sax parse error", pce);
    } catch (AbortXMLParsingException abrt) {
        Log.i(LOG_NAME + " AsyncXML", "Cancelled!!!!!");
    } catch (SAXException se) {
        Log.e(LOG_NAME + " SAX XML", "sax error", se);
    } catch (IOException ioe) {
        Log.e(LOG_NAME + " SAX XML", "sax parse io error", ioe);
    }
    //Log.i(LOG_NAME + " SAX XML", "Done parsing XML for " + theNBName);
    return null;
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static boolean verifyErrorResponse(String res, String code, String message) {

    SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
    SAXParser saxParser;/* w w  w .  ja  va2  s.  c o  m*/

    ErrorParser p = new ErrorParser();
    res = res.trim();

    try {
        saxParser = fac.newSAXParser();
        saxParser.parse(new ByteArrayInputStream(res.getBytes()), p);
    } catch (Exception ex) {
        logger.error("Exception parsing error response", ex);
    }

    if (code != null) {

        String rescode = p.getCode();

        if (!code.equals(rescode)) {
            logger.error("Wrong error code");
            return false;
        }
    }

    if (message != null) {

        String resmessage = p.getMessage();

        if (!resmessage.equals(message)) {
            logger.error("Wrong error messahe");
            return false;
        }
    }

    return true;
}

From source file:com.rany.albeg.wein.rssr.RssReader.java

private void init(RssReaderListener readCompleteListener) {

    mReadyToRead = true;//from   ww w  . ja va 2 s .co  m
    mRssReaderListener = readCompleteListener;
    mRssReaderXmlHandler = new RssReaderXMLHandler();

    try {

        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser parser = factory.newSAXParser();

        mXMLReader = parser.getXMLReader();
        mXMLReader.setContentHandler(mRssReaderXmlHandler);

    } catch (ParserConfigurationException e) {
        Log.e(TAG, "ParserConfigurationException");
    } catch (SAXException e) {
        Log.e(TAG, "SAXException init()");
    }

}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static TopicAttributeParser getTopicAttributesFromString(String res) {
    javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
    javax.xml.parsers.SAXParser saxParser;

    TopicAttributeParser p = new TopicAttributeParser();

    try {//from   w  ww  .  ja  va 2s  .  c  o m
        saxParser = fac.newSAXParser();
        saxParser.parse(new ByteArrayInputStream(res.getBytes()), p);

    } catch (Exception ex) {
        logger.error("Exception parsing", ex);
    }

    return p;
}

From source file:com.qspin.qtaste.recorder.SpyInstaller.java

public SpyInstaller(String pXmlFilterDefinitionPath) {
    super();/*from  w ww  .  j a v a  2  s .c  om*/
    mFilter = new ArrayList<RecorderFilter>();
    if (pXmlFilterDefinitionPath != null) {
        FilterXmlHandler gestionnaire = new FilterXmlHandler();
        try {
            SAXParserFactory fabrique = SAXParserFactory.newInstance();
            SAXParser parseur = fabrique.newSAXParser();
            parseur.parse(pXmlFilterDefinitionPath, gestionnaire);
            for (Filter f : gestionnaire.getDecodedFilters()) {
                mFilter.add(new RecorderFilter(f));
            }
        } catch (IOException pExc) {
            LOGGER.error(pExc);
        } catch (SAXException pExc) {
            LOGGER.error(pExc);
        } catch (ParserConfigurationException pExc) {
            LOGGER.error(pExc);
        }
    }
}

From source file:com.pnf.plugin.pdf.XFAParser.java

public void parse(byte[] xmlContent) throws ParserConfigurationException, SAXException, IOException {
    CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
    decoder.onMalformedInput(CodingErrorAction.REPLACE);
    decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
    CharBuffer parsed = decoder.decode(ByteBuffer.wrap(xmlContent));

    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = factory.newSAXParser();

    try (@SuppressWarnings("deprecation")
    InputStream is = new ReaderInputStream(new CharArrayReader(parsed.array()))) {
        parser.parse(is, xfa);/*w  ww .j  a  v a2 s  . c o m*/
    } catch (Exception e) {
        logger.catching(e);
        logger.error("Error while parsing XFA content");
    }
}

From source file:com.entertailion.android.slideshow.rss.RssHandler.java

public RssFeed getFeed(String data) throws Exception {
    feed = null;//from   www . jav a  2s  .  com
    SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    XMLReader xr = sp.getXMLReader();

    InputSource inStream = new org.xml.sax.InputSource();
    inStream.setCharacterStream(new StringReader(data));

    xr.setContentHandler(this);
    feed = new RssFeed();
    xr.parse(inStream);

    xr = null;
    sp = null;
    spf = null;

    return feed;
}