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:org.xwiki.contrib.repository.pypi.internal.searching.PypiPackageListIndexUpdateTask.java

protected List<String> parseHtmlPageToPackagenames(InputStream is)
        throws ParserConfigurationException, SAXException, IOException {
    SAXParserFactory parserFactor = SAXParserFactory.newInstance();
    SAXParser parser = parserFactor.newSAXParser();
    PypiPackageListSAXHandler handler = new PypiPackageListSAXHandler();
    parser.parse(is, handler);// www. j  a v a  2  s .c om
    return handler.getPackageNames();
}

From source file:com.zegoggles.smssync.XOAuthConsumer.java

protected String getUsernameFromContacts() {

    final HttpClient httpClient = new DefaultHttpClient();
    final String url = "https://www.google.com/m8/feeds/contacts/default/thin?max-results=1";
    final StringBuilder email = new StringBuilder();

    try {//w  w  w .j av  a  2 s. c o m
        HttpGet get = new HttpGet(sign(url));
        HttpResponse resp = httpClient.execute(get);
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        xr.setContentHandler(new DefaultHandler() {
            boolean inEmail;

            @Override
            public void startElement(String uri, String localName, String qName, Attributes atts) {
                inEmail = "email".equals(localName);
            }

            @Override
            public void characters(char[] c, int start, int length) {
                if (inEmail) {
                    email.append(c, start, length);
                }
            }
        });
        xr.parse(new InputSource(resp.getEntity().getContent()));
        return email.toString();

    } catch (oauth.signpost.exception.OAuthException e) {
        Log.e(TAG, "error", e);
        return null;
    } catch (org.xml.sax.SAXException e) {
        Log.e(TAG, "error", e);
        return null;
    } catch (java.io.IOException e) {
        Log.e(TAG, "error", e);
        return null;
    } catch (javax.xml.parsers.ParserConfigurationException e) {
        Log.e(TAG, "error", e);
        return null;
    }
}

From source file:de.uni_freiburg.informatik.ultimate.licence_manager.authors.SvnAuthorProvider.java

private SvnBlameSAXHandler parseSvnBlameOutput(InputStream input)
        throws ParserConfigurationException, SAXException, IOException {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();
    SvnBlameSAXHandler handler = new SvnBlameSAXHandler();
    saxParser.parse(input, handler);//  ww  w .  j a v a2  s  . co m
    return handler;
}

From source file:com.joliciel.frenchTreebank.upload.TreebankSAXParser.java

public void parseDocument(String filePath) {
    //get or create the treebank file
    treebankFile = this.getTreebankService().loadOrCreateTreebankFile(filePath);

    //get a factory
    SAXParserFactory spf = SAXParserFactory.newInstance();
    try {/*from   w  w w . ja v a2  s  .  c  o  m*/

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

        //parse the file and also register this class for call backs
        sp.parse(filePath, this);

    } catch (SAXException se) {
        se.printStackTrace();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (IOException ie) {
        ie.printStackTrace();
    }
}

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;//from   w w w  . j a v  a 2  s  .c om

    try {
        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:com.binomed.showtime.android.util.CineShowtimeFactory.java

private XMLReader getReader() throws Exception {
    if (reader == null) {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();

        reader = sp.getXMLReader();/*from   w ww .ja  v  a 2  s.c  o m*/
    }
    return reader;
}

From source file:com.brightcove.com.uploader.helper.MediaManagerHelper.java

private Long executeUpload(HttpPost method, DefaultHttpClient client)
        throws IOException, ClientProtocolException, ParserConfigurationException, SAXException {
    HttpResponse response = client.execute(method);
    HttpEntity entity = response.getEntity();
    InputStream instream = entity.getContent();
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();
    DefaultHandler dh = new MMHandler();

    saxParser.parse(instream, dh);/*from  ww w  .  j  a v a 2 s .  co m*/
    mLog.info("id: " + ((MMHandler) dh).getMediaId());

    return ((MMHandler) dh).getMediaId();
}

From source file:egat.cli.AbstractGameCommandHandler.java

protected void processCommand(InputStream inputStream, boolean symmetric) throws CommandProcessingException {

    try {//  w  ww .j a v  a2s.c o  m
        if (symmetric) {
            SAXParserFactory factory = SAXParserFactory.newInstance();

            SAXParser parser = factory.newSAXParser();

            SymmetricGameHandler handler = new SymmetricGameHandler();

            parser.parse(inputStream, handler);

            MutableSymmetricGame game = handler.getGame();

            processSymmetricGame(game);
        } else {

            SAXParserFactory factory = SAXParserFactory.newInstance();

            SAXParser parser = factory.newSAXParser();

            StrategicGameHandler handler = new StrategicGameHandler();

            parser.parse(inputStream, handler);

            MutableStrategicGame game = handler.getGame();

            processStrategicGame(game);

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

}

From source file:com.musala.core.RssProcessorImpl.java

private void readData() {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = null;/*  ww  w.j  a  v a  2  s. c o m*/
    try {
        parser = factory.newSAXParser();
        parser.parse(new InputSource(new URL(site.getRssLink()).openStream()), this);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:ca.nines.ise.util.XMLDriver.java

/**
 * Construct a driver./*from w  ww .  j  av  a  2  s.c  om*/
 *
 * @throws ParserConfigurationException
 * @throws TransformerConfigurationException
 * @throws SAXException
 * @throws TransformerException
 */
public XMLDriver() throws ParserConfigurationException, TransformerConfigurationException, SAXException,
        TransformerException {
    docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    nullTransformer = TransformerFactory.newInstance().newTransformer();

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

    xmlReader = saxParser.getXMLReader();
}