List of usage examples for javax.xml.parsers SAXParserFactory newInstance
public static SAXParserFactory newInstance()
From source file:com.google.code.docbook4j.renderer.BaseRenderer.java
protected SAXParserFactory createParserFactory() { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setXIncludeAware(true);/* w w w.ja v a2 s . c o m*/ factory.setNamespaceAware(true); return factory; }
From source file:com.aionengine.gameserver.dataholders.loadingutils.XmlMerger.java
/** * Check for modifications of included files. * * @return <code>true</code> if at least one of included files has modifications. * @throws IOException IO Error. * @throws SAXException Document parsing error. * @throws ParserConfigurationException if a SAX parser cannot * be created which satisfies the requested configuration. *///from w w w.j a va 2 s . c o m private boolean checkFileModifications() throws Exception { long destFileTime = destFile.lastModified(); if (sourceFile.lastModified() > destFileTime) { logger.debug("Source file was modified "); return true; } Properties metadata = restoreFileModifications(metaDataFile); if (metadata == null) // new file or smth else. return true; SAXParserFactory parserFactory = SAXParserFactory.newInstance(); SAXParser parser = parserFactory.newSAXParser(); TimeCheckerHandler handler = new TimeCheckerHandler(baseDir, metadata); parser.parse(sourceFile, handler); return handler.isModified(); }
From source file:com.agiletec.aps.system.common.entity.ApsEntityManager.java
/** * Create and populate the entity as specified by its type and XML definition. * @param entityTypeCode The Entity Type code. * @param xml The XML of the associated entity. * @return The populated entity.//from w w w. j a va2 s . com * @throws ApsSystemException If errors detected while retrieving the entity. */ protected IApsEntity createEntityFromXml(String entityTypeCode, String xml) throws ApsSystemException { try { IApsEntity entityPrototype = this.getEntityPrototype(entityTypeCode); SAXParserFactory parseFactory = SAXParserFactory.newInstance(); SAXParser parser = parseFactory.newSAXParser(); InputSource is = new InputSource(new StringReader(xml)); EntityHandler handler = this.getEntityHandler(); handler.initHandler(entityPrototype, this.getXmlAttributeRootElementName(), this.getCategoryManager()); parser.parse(is, handler); return entityPrototype; } catch (Throwable t) { _logger.error("Error detected while creating the entity. typecode: {} - xml: {}", entityTypeCode, xml, t); //ApsSystemUtils.logThrowable(t, this, "createEntityFromXml"); throw new ApsSystemException("Error detected while creating the entity", t); } }
From source file:org.peterbaldwin.client.android.delicious.DeliciousApiRequest.java
/** * {@inheritDoc}/* w w w . java 2 s . com*/ */ public void run() { Message msg = mHandler.obtainMessage(); msg.arg1 = mRequestType; msg.arg2 = mRequestId; msg.what = HANDLE_ERROR; msg.obj = "unknown error"; boolean cacheUpdated = false; try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); ContentHandler handler = mResponseHandler.getContentHandler(); reader.setContentHandler(handler); InputStream in = null; if (in == null && mUseCache && mCacheFile != null) { in = readFromCache(); } if (in == null) { in = readFromNetwork(); if (mUpdateCache && mCacheFile != null) { in = updateCache(in); cacheUpdated = true; } } try { InputSource input = new InputSource(in); long start = now(); try { reader.parse(input); } finally { logTiming("parse", start); } } finally { in.close(); } msg.what = HANDLE_DONE; msg.obj = mResponseHandler; } catch (ConnectionException e) { setError(msg, e); int statusCode = e.getStatusCode(); if (statusCode == HttpStatus.SC_UNAUTHORIZED) { msg.what = HANDLE_AUTH_ERROR; msg.obj = "invalid username or password"; } else { msg.what = HANDLE_ERROR; msg.obj = "unexpected response: " + statusCode; } } catch (IOException e) { setError(msg, e); } catch (ParserConfigurationException e) { setError(msg, e); } catch (SAXException e) { setError(msg, e); } catch (RuntimeException e) { setError(msg, e); } catch (Error e) { setError(msg, e); } finally { mHandler.sendMessage(msg); } if (msg.what != HANDLE_AUTH_ERROR && !cacheUpdated && mAlwaysUpdateCache && mCacheFile != null) { // If the authentication is valid, but the cache was not updated, // silently update the cache in the background after dispatching the // result to the handler. try { InputStream in = readFromNetwork(); in = updateCache(in); in.close(); Log.i(LOG_TAG, "cache file updated: " + mCacheFile); } catch (IOException e) { Log.e(LOG_TAG, "error updating cache", e); } catch (RuntimeException e) { Log.e(LOG_TAG, "error updating cache", e); } catch (Error e) { Log.e(LOG_TAG, "error updating cache", e); } } }
From source file:com.commonsware.android.EMusicDownloader.SingleAlbum.java
private void getInfoFromXML() { //Show a progress dialog while reading XML final ProgressDialog dialog = ProgressDialog.show(this, "", getString(R.string.loading), true, true); setProgressBarIndeterminateVisibility(true); Thread t3 = new Thread() { public void run() { waiting(200);/*w ww. j a v a 2s .co m*/ try { //Log.d("EMD - ","About to parse"); URL url = new URL(urlAddress); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); XMLHandlerSingleAlbum myXMLHandler = new XMLHandlerSingleAlbum(); xr.setContentHandler(myXMLHandler); xr.parse(new InputSource(url.openStream())); //Log.d("EMD - ","Done Parsing"); statuscode = myXMLHandler.statuscode; if (statuscode != 200 && statuscode != 206) { throw new Exception(); } genre = myXMLHandler.genre; genreId = myXMLHandler.genreId; labelId = myXMLHandler.labelId; label = myXMLHandler.label; date = myXMLHandler.releaseDate; rating = myXMLHandler.rating; imageURL = myXMLHandler.imageURL; artist = myXMLHandler.artist; artistId = myXMLHandler.artistId; //Log.d("EMD - ","Set genre etc.."); numberOfTracks = myXMLHandler.nItems; trackNames = myXMLHandler.tracks; //sampleAddresses = myXMLHandler.sampleAddress; //sampleExists = myXMLHandler.sampleExists; //vSamplesExist = myXMLHandler.samplesExist; handlerSetContent.sendEmptyMessage(0); dialog.dismiss(); updateImage(); } catch (Exception e) { final Exception ef = e; nameTextView.post(new Runnable() { public void run() { nameTextView.setText(R.string.couldnt_get_album_info); } }); } //Remove Progress Dialog if (dialog.isShowing()) { dialog.dismiss(); } handlerDoneLoading.sendEmptyMessage(0); } }; t3.start(); }
From source file:com.aionemu.gameserver.dataholders.loadingutils.XmlMerger.java
/** * Check for modifications of included files. * * @return <code>true</code> if at least one of included files has * modifications./*from w w w. j av a 2 s . c o m*/ * @throws IOException IO Error. * @throws SAXException Document parsing error. * @throws ParserConfigurationException if a SAX parser cannot be created * which satisfies the requested configuration. */ private boolean checkFileModifications() throws Exception { long destFileTime = destFile.lastModified(); if (sourceFile.lastModified() > destFileTime) { logger.debug("Source file was modified "); return true; } Properties metadata = restoreFileModifications(metaDataFile); if (metadata == null) // new file or smth else. { return true; } SAXParserFactory parserFactory = SAXParserFactory.newInstance(); SAXParser parser = parserFactory.newSAXParser(); TimeCheckerHandler handler = new TimeCheckerHandler(baseDir, metadata); parser.parse(sourceFile, handler); return handler.isModified(); }
From source file:geeshang.nasaimage.MainActivity.java
private void download() { new Thread() { @Override/* w ww .java 2 s . c om*/ public void run() { super.run(); MyDefaultHandler defaultHandler = new MyDefaultHandler(MainActivity.this); try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); InputStream inputStream = downloader.download(NASA_URL); if (inputStream != null) { parser.parse(inputStream, defaultHandler); } } catch (ParserConfigurationException | SAXException | IOException e) { e.printStackTrace(); } MainActivity.this.myHandler.post(new Runnable() { @Override public void run() { resetView(); } }); getImage(); setProgressBarGone(); MainActivity.this.myHandler.post(new Runnable() { @Override public void run() { resetView(); } }); } }.start(); }
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 w w w .ja va 2 s .c o m*/ mLog.info("id: " + ((MMHandler) dh).getMediaId()); return ((MMHandler) dh).getMediaId(); }
From source file:captureplugin.drivers.dreambox.connector.DreamboxConnector.java
/** * @return List of Timers/*from www. j a va 2s. c o m*/ */ private ArrayList<HashMap<String, String>> getTimers() { if (!mConfig.hasValidAddress()) { return null; } try { InputStream stream = openStreamForLocalUrl("/web/timerlist"); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); DreamboxTimerHandler handler = new DreamboxTimerHandler(); saxParser.parse(stream, handler); return handler.getTimers(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } return null; }
From source file:com.typhoon.newsreader.engine.ChannelRefresh.java
public long syncDB(Handler h, long id, String rssurl) throws Exception { mHandler = h;//from w w w. java 2 s . c o m mID = id; mRSSURL = rssurl; SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); xr.setContentHandler(this); xr.setErrorHandler(this); URL url = new URL(mRSSURL); URLConnection c = url.openConnection(); c.setRequestProperty("User-Agent", "Android/m3-rc37a"); xr.parse(new InputSource(c.getInputStream())); return mID; }