List of usage examples for javax.xml.parsers SAXParser parse
public void parse(InputSource is, DefaultHandler dh) throws SAXException, IOException
From source file:de.doering.dwca.iocwbn.ChecklistBuilder.java
private void parsePage(Eml eml) throws IOException, SAXException, ParserConfigurationException { // get webapge String url = XML_DOWNLOAD.replace("{VERSION}", VERSION); log.info("Downloading latest IOC world bird list from {}", url); DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(url); // execute//from w ww . j a va 2s . c om HttpResponse response = client.execute(get); HttpEntity entity = response.getEntity(); // parse page SAXParserFactory factory = SAXParserFactory.newInstance(); final SAXParser parser = factory.newSAXParser(); IocXmlHandler handler = new IocXmlHandler(writer, eml); try { Reader reader = new InputStreamReader(entity.getContent(), ENCODING); parser.parse(new InputSource(reader), handler); } catch (Exception e) { log.error("Cannot process IOC XML", e); } }
From source file:gov.nasa.ensemble.core.jscience.xml.XMLProfileParser.java
@Override protected void doParse(URI uri, InputStream inputStream) { try {/*from w w w . ja v a 2 s.c o m*/ SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); XMLProfileHandler xmlProfileHandler = new XMLProfileHandler(); xmlProfileHandler.setParsingDataPoints(parsingDataPoints); parser.parse(inputStream, xmlProfileHandler); for (Profile profile : xmlProfileHandler.getProfiles()) addProfile(uri, profile); } catch (Exception e) { errorHandler.unhandledException(e); } }
From source file:com.wadpam.ricotta.web.IndexController.java
protected void importXML(String blobKey, InputStream in) throws ParserConfigurationException, SAXException, IOException { SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); DefaultHandler dh = new RicottaImportHandler(blobKey, uberDao); parser.parse(in, dh); }
From source file:org.syncope.core.init.ContentLoader.java
@Transactional public void load() { // 0. DB connection, to be used below Connection conn = DataSourceUtils.getConnection(dataSource); // 1. Check wether we are allowed to load default content into the DB Statement statement = null;// w w w .j av a2s . c o m ResultSet resultSet = null; boolean existingData = false; try { statement = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); resultSet = statement.executeQuery("SELECT * FROM " + SyncopeConf.class.getSimpleName()); resultSet.last(); existingData = resultSet.getRow() > 0; } catch (SQLException e) { LOG.error("Could not access to table " + SyncopeConf.class.getSimpleName(), e); // Setting this to true make nothing to be done below existingData = true; } finally { try { if (resultSet != null) { resultSet.close(); } } catch (SQLException e) { LOG.error("While closing SQL result set", e); } try { if (statement != null) { statement.close(); } } catch (SQLException e) { LOG.error("While closing SQL statement", e); } } if (existingData) { LOG.info("Data found in the database, leaving untouched"); return; } LOG.info("Empty database found, loading default content"); // 2. Create views LOG.debug("Creating views"); try { InputStream viewsStream = getClass().getResourceAsStream("/views.xml"); Properties views = new Properties(); views.loadFromXML(viewsStream); for (String idx : views.stringPropertyNames()) { LOG.debug("Creating view {}", views.get(idx).toString()); try { statement = conn.createStatement(); statement.executeUpdate(views.get(idx).toString().replaceAll("\\n", " ")); statement.close(); } catch (SQLException e) { LOG.error("Could not create view ", e); } } LOG.debug("Views created, go for indexes"); } catch (Throwable t) { LOG.error("While creating views", t); } // 3. Create indexes LOG.debug("Creating indexes"); try { InputStream indexesStream = getClass().getResourceAsStream("/indexes.xml"); Properties indexes = new Properties(); indexes.loadFromXML(indexesStream); for (String idx : indexes.stringPropertyNames()) { LOG.debug("Creating index {}", indexes.get(idx).toString()); try { statement = conn.createStatement(); statement.executeUpdate(indexes.get(idx).toString()); statement.close(); } catch (SQLException e) { LOG.error("Could not create index ", e); } } LOG.debug("Indexes created, go for default content"); } catch (Throwable t) { LOG.error("While creating indexes", t); } finally { DataSourceUtils.releaseConnection(conn, dataSource); } try { conn.close(); } catch (SQLException e) { LOG.error("While closing SQL connection", e); } // 4. Load default content SAXParserFactory factory = SAXParserFactory.newInstance(); try { SAXParser parser = factory.newSAXParser(); parser.parse(getClass().getResourceAsStream("/content.xml"), importExport); LOG.debug("Default content successfully loaded"); } catch (Throwable t) { LOG.error("While loading default content", t); } }
From source file:edu.scripps.fl.pubchem.promiscuity.OverallListsAndMapsFactory.java
public Map<Long, List<Protein>> getAIDProteinMap(List<Long> aids) throws Exception { log.info("Number of aids in eSummary request: " + aids.size()); log.info("Memory usage before getting aid eSummary document: " + memUsage()); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); AssayESummaryHandler handler = new AssayESummaryHandler(); InputStream is = EUtilsFactory.getInstance().getSummaries(aids, "pcassay"); saxParser.parse(is, handler); log.info("Memory usage after getting aid eSummary document: " + memUsage()); return handler.getMap(); }
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); mLog.info("id: " + ((MMHandler) dh).getMediaId()); return ((MMHandler) dh).getMediaId(); }
From source file:com.sismics.util.AdblockUtil.java
/** * Returns list of known subscriptions./*from w ww. j ava 2 s . co m*/ */ public List<Subscription> getSubscriptions() { if (subscriptions == null) { subscriptions = new ArrayList<Subscription>(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser; try { parser = factory.newSAXParser(); parser.parse(AdblockUtil.class.getResourceAsStream("/adblock/subscriptions.xml"), new SubscriptionParser(subscriptions)); } catch (Exception e) { log.error("Error parsing subscriptions", e); } } return subscriptions; }
From source file:bg.fourweb.android.rss.Parser.java
public Feed parse(final String url, ProgressObserver obs) { final HttpClient client = CompatHttp.getHttpClient(); // configure the HTTP client client.getParams().setIntParameter("http.socket.timeout", opts.getConnectionTimeout()); try {//from w w w .j ava2s. com final HttpUriRequest get = new HttpGet(url); final HttpResponse resp = client.execute(get); // prepare content length (it's needed for progress indication) int contentLength = 0; final Header[] contentLengthHeaders = resp.getHeaders("Content-Length"); if (ArrayUtils.isEmpty(contentLengthHeaders) == false) { final Header contentLengthHeader = contentLengthHeaders[0]; final String contentLengthValue = contentLengthHeader.getValue(); if (StringUtils.isEmpty(contentLengthValue) == false) { try { contentLength = Integer.parseInt(contentLengthValue); } catch (NumberFormatException ignored) { // NOP } } } // prepare progress observers final ProgressInputStream body = new ProgressInputStream(resp.getEntity().getContent(), contentLength); if (obs != null) { body.addProgressObserver(obs); } // handler h = prepareHandler(); // parse SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); parser.parse(body, h); return h.getProductFeed(); } catch (Throwable e) { if (DBG) { Log.w(TAG, "", e); } } finally { CompatHttp.closeHttpClient(client); } return null; }
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); } catch (Exception e) { logger.catching(e);//from w w w. j a v a 2 s . c om logger.error("Error while parsing XFA content"); } }
From source file:fulcrum.xml.Parser.java
/** * * Only provides parsing functions to the "fulcrum.xml" package. * /*from ww w.j ava 2 s . c o m*/ * @see Document * * @param xmlDocument * @param document * @throws ParseException */ protected void parse(byte[] xmlDocument, Document document) throws ParseException { try { this.document = document; SAXParser sp = getParser(); ByteArrayInputStream bais = new ByteArrayInputStream(xmlDocument); sp.parse(bais, this); } catch (Exception e) { throw new ParseException(e); } }