Example usage for org.xml.sax XMLReader parse

List of usage examples for org.xml.sax XMLReader parse

Introduction

In this page you can find the example usage for org.xml.sax XMLReader parse.

Prototype

public void parse(String systemId) throws IOException, SAXException;

Source Link

Document

Parse an XML document from a system identifier (URI).

Usage

From source file:net.ontopia.persistence.proxy.ObjectRelationalMapping.java

/**
 * INTERNAL: Read a mapping description from the specified file.
 *//*w w  w.jav  a 2s  .c o  m*/
protected void loadMapping(InputSource isource) {

    // Read mapping file.
    ContentHandler handler = new MappingHandler(this);

    try {
        XMLReader parser = DefaultXMLReaderFactory.createXMLReader();
        parser.setContentHandler(handler);
        parser.setErrorHandler(new Slf4jSaxErrorHandler(log));
        parser.parse(isource);
    } catch (IOException e) {
        throw new OntopiaRuntimeException(e);
    } catch (SAXException e) {
        throw new OntopiaRuntimeException(e);
    }
}

From source file:net.pandoragames.far.ui.MimeConfParser.java

/**
 * Read the mime type definition from xml.
 * @param input xml to be read//from  ww  w  .  j  a v  a  2 s .com
 * @throws SAXException
 * @throws IOException
 */
public void parse(InputStream input) throws SAXException, IOException {
    Reader reader = new InputStreamReader(input);
    XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    InputSource xmlInput = new InputSource(reader);
    xmlReader.setContentHandler(new SAXHandler());
    xmlReader.parse(xmlInput);
}

From source file:com.typhoon.newsreader.engine.ChannelRefresh.java

public List<FeedsListItem> parser(String link) {
    if (link.contains("www.24h.com.vn")) {
        try {/*w w w  . ja v  a2  s.  c o  m*/
            URL url = new URL(link);
            URLConnection connection = url.openConnection();
            connection.addRequestProperty("http.agent", USER_AGENT);
            InputSource input = new InputSource(url.openStream());
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(false);
            SAXParser parser = factory.newSAXParser();
            XMLReader reader = parser.getXMLReader();

            reader.setContentHandler(this);
            reader.parse(input);

            return getFeedsList();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        try {
            // URL url= new URL(link);
            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet(link);
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(false);
            SAXParser parser = factory.newSAXParser();
            XMLReader reader = parser.getXMLReader();
            reader.setContentHandler(this);
            InputSource inStream = new InputSource();
            inStream.setCharacterStream(new StringReader(EntityUtils.toString(entity)));
            reader.parse(inStream);
            return getFeedsList();
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return null;
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
            return null;
        } catch (SAXException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}

From source file:eu.apenet.dpt.utils.util.Ead2EdmInformation.java

private void determineDaoInformation(File fileToRead)
        throws IOException, SAXException, ParserConfigurationException {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    XMLReader xr = sp.getXMLReader();
    EadContentHandler myContentHandler = new EadContentHandler();
    xr.setContentHandler(myContentHandler);
    xr.parse(new InputSource(new InputStreamReader(new BOMInputStream(new FileInputStream(fileToRead)))));

    if (this.roleType == null) {
        this.roleType = "UNSPECIFIED";
    }//  ww w .  j  a  v  a2s  .c o m
}

From source file:org.gots.weather.provider.google.GoogleWeatherTask.java

@Override
protected WeatherConditionInterface doInBackground(Object... arg0) {
    if (force || ws == null) {

        try {//from w  w w  .ja  v a  2  s . c o  m

            // android.os.Debug.waitForDebugger();
            /*************/

            HttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet(url.toURI());

            // create a response handler
            ResponseHandler<String> responseHandler = new BasicResponseHandler();

            String responseBody = httpclient.execute(httpget, responseHandler);
            // Log.d(DEBUG_TAG, "response from httpclient:n "+responseBody);

            ByteArrayInputStream is = new ByteArrayInputStream(responseBody.getBytes());

            /* Get a SAXParser from the SAXPArserFactory. */
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();

            /* Get the XMLReader of the SAXParser we created. */
            XMLReader xr = sp.getXMLReader();

            /* Create a new ContentHandler and apply it to the XML-Reader */
            GoogleWeatherHandler gwh = new GoogleWeatherHandler();
            xr.setContentHandler(gwh);

            // InputSource is = new InputSource(url.openStream());
            /* Parse the xml-data our URL-call returned. */
            xr.parse(new InputSource(is));

            /* Our Handler now provides the parsed weather-data to us. */
            ws = gwh.getWeatherSet();
        } catch (Exception e) {
            Log.e("WeatherManager", "WeatherQueryError", e);

        }
        force = false;
    }
    Calendar requestCalendar = Calendar.getInstance();
    requestCalendar.setTime(requestedDay);
    if (ws == null)
        return new WeatherCondition(requestedDay);
    else if (requestCalendar.get(Calendar.DAY_OF_YEAR) == Calendar.getInstance().get(Calendar.DAY_OF_YEAR))
        return ws.getWeatherCurrentCondition();
    else if (requestCalendar.get(Calendar.DAY_OF_YEAR) > Calendar.getInstance().get(Calendar.DAY_OF_YEAR))
        return ws.getWeatherForecastConditions().get(
                requestCalendar.get(Calendar.DAY_OF_YEAR) - Calendar.getInstance().get(Calendar.DAY_OF_YEAR));
    return new WeatherCondition(requestedDay);

}

From source file:com.zyz.mobile.book.UserBookData.java

/**
 * open the info xml file. create one if it cannot be found
 *///w w w. j  a  v  a  2  s. c o  m
public boolean parse() {
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader reader = sp.getXMLReader();
        reader.setContentHandler(this);
        reader.parse(new InputSource(new FileReader(mInfoFile)));
    } catch (Exception e) {
        // constructor doesn't check for validity of the file
        // catch all exceptions here
        Log.e(TAG, "Failed to parse xml file?");
        return false;
    }
    return true;
}

From source file:com.dhenton9000.excel.ExcelParser.java

public SheetResults parse(InputStream inputStream) throws Exception {

    OPCPackage pkg = OPCPackage.open(inputStream);
    XSSFReader reader = new XSSFReader(pkg);
    this.sst = reader.getSharedStringsTable();

    SAXParserFactory saxFactory = SAXParserFactory.newInstance();
    SAXParser saxParser = saxFactory.newSAXParser();
    XMLReader parser = saxParser.getXMLReader();
    parser.setContentHandler(this);

    // There should only be one sheet
    final Iterator<InputStream> it = reader.getSheetsData();
    final InputStream sheet = it.next();

    final InputSource sheetSource = new InputSource(sheet);
    parser.parse(sheetSource);
    sheet.close();//from  w w  w  . ja  va 2s.c o  m

    return getSheetResults();

}

From source file:com.webcohesion.ofx4j.client.impl.OFXHomeFIDataStore.java

private BaseFinancialInstitutionData loadInstitutionData(String href) throws IOException, SAXException {
    if (LOG.isInfoEnabled()) {
        LOG.info("Loading institution data from: " + href);
    }/*from   ww w  .  ja  va  2  s  . com*/

    URL url = new URL(href);
    XMLReader xmlReader = new Parser();
    xmlReader.setFeature("http://xml.org/sax/features/namespaces", false);
    xmlReader.setFeature("http://xml.org/sax/features/validation", false);
    InstitutionContentHandler institutionHandler = new InstitutionContentHandler();
    xmlReader.setContentHandler(institutionHandler);
    xmlReader.parse(new InputSource(url.openStream()));
    return institutionHandler.data;
}

From source file:be.fedict.eidviewer.lib.file.imports.EidQuickKeyXMLFile.java

public void load(File file) throws CertificateException, FileNotFoundException, SAXException, IOException {
    logger.fine("Loading eID Quick Keys XML File");

    XMLReader reader = null;

    certificateFactory = CertificateFactory.getInstance("X.509");
    FileInputStream fis = new FileInputStream(file);

    reader = XMLReaderFactory.createXMLReader();
    reader.setContentHandler(this);
    reader.setErrorHandler(this);
    BufferedReader in = new BufferedReader(new InputStreamReader(fis));
    reader.parse(new InputSource(in));

    X509Utilities.setCertificateChainsFromCertificates(eidData, rootCert, citizenCert, authenticationCert,
            signingCert, rrnCert);/*from w  w  w  .  j av  a  2s .  c o m*/
}

From source file:net.sourceforge.fenixedu.utilTests.ParseMetadata.java

public Vector<Element> parseMetadata(String metadataFile) throws ParseException {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(true);//from   w w w. j a  va  2 s.com
    try {
        SAXParser saxParser = spf.newSAXParser();
        XMLReader reader = saxParser.getXMLReader();
        reader.setContentHandler(this);
        reader.setErrorHandler(this);
        StringReader sr = new StringReader(metadataFile);
        InputSource input = new InputSource(sr);
        MetadataResolver resolver = new MetadataResolver();
        reader.setEntityResolver(resolver);
        reader.parse(input);
    } catch (Exception e) {
        throw new ParseException();
    }

    setMembers(vector);
    return vector;
}