List of usage examples for javax.xml.parsers SAXParser parse
public void parse(InputSource is, DefaultHandler dh) throws SAXException, IOException
From source file:com.quinsoft.zeidon.standardoe.ActivateOisFromXmlStream.java
private ViewImpl read() { try {//from w w w . ja va2 s . co m SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); DefaultHandler handler = new SaxParserHandler(); saxParser.parse(inputStream, handler); // If user wanted just one root remove others if we have more than one. // We don't want to abort the loading of entities in the middle of // the stream because that could throw off XML processing. EntityCursorImpl rootCursor = view.getViewCursor().getEntityCursor(lodDef.getRoot()); if (control.contains(ActivateFlags.fSINGLE) && rootCursor.getEntityCount() > 1) { rootCursor.setFirst(); while (rootCursor.setNext().isSet()) rootCursor.dropEntity(); rootCursor.setFirst(); } if (selectedInstances.size() > 0) setCursors(); else view.reset(); return view; } catch (Exception e) { ZeidonException ze = ZeidonException.wrapException(e); if (locator != null) ze.appendMessage("Line/col = %d/%d", locator.getLineNumber(), locator.getColumnNumber()); throw ze; } }
From source file:dreamboxdataservice.DreamboxDataService.java
/** * @param service Service-ID//from w ww . j a v a2 s. c o m * @return Data of specific service */ public TreeMap<String, String> getServiceData(String service) { try { URL url = new URL("http://" + mProperties.getProperty("ip", "") + "/web/getservices?sRef=" + service); URLConnection connection = url.openConnection(); String userpassword = mProperties.getProperty("username", "") + ":" + IOUtilities .xorEncode(mProperties.getProperty("password", ""), DreamboxSettingsPanel.PASSWORDSEED); String encoded = new String(Base64.encodeBase64(userpassword.getBytes())); connection.setRequestProperty("Authorization", "Basic " + encoded); connection.setConnectTimeout(10); InputStream stream = connection.getInputStream(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); DreamboxHandler handler = new DreamboxHandler(); saxParser.parse(stream, handler); return handler.getData(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:dreamboxdataservice.DreamboxDataService.java
/** * @param service Service-ID/*from w w w.j a v a 2s . c o m*/ * @return Data of specific service */ public TreeMap<String, String> getServiceDataBonquets(String service) { try { URL url = new URL("http://" + mProperties.getProperty("ip", "") + "/web/getservices?bRef=" + service); URLConnection connection = url.openConnection(); String userpassword = mProperties.getProperty("username", "") + ":" + IOUtilities .xorEncode(mProperties.getProperty("password", ""), DreamboxSettingsPanel.PASSWORDSEED); String encoded = new String(Base64.encodeBase64(userpassword.getBytes())); connection.setRequestProperty("Authorization", "Basic " + encoded); connection.setConnectTimeout(10); InputStream stream = connection.getInputStream(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); DreamboxHandler handler = new DreamboxHandler(); saxParser.parse(stream, handler); return handler.getData(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:org.transdroid.search.RssFeedSearch.PretomeAdapter.java
@Override protected RssParser getRssParser(final String url) { return new RssParser(url) { @Override/*from w w w .j av a2s . c o m*/ public void parse() throws ParserConfigurationException, SAXException, IOException { HttpClient httpclient = initialise(); HttpResponse result = httpclient.execute(new HttpGet(url)); //FileInputStream urlInputStream = new FileInputStream("/sdcard/rsstest2.txt"); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); InputSource is = new InputSource(); // Pretome supplies UTF-8 compatible character data yet incorrectly defined a windows-1251 encode: override is.setEncoding("UTF-8"); is.setCharacterStream(new InputStreamReader(result.getEntity().getContent())); sp.parse(is, this); } }; }
From source file:com.phonemetra.lockclock.weather.YahooWeatherProvider.java
@Override public WeatherInfo getWeatherInfo(String id, String localizedCityName, boolean metric) { String url = String.format(URL_WEATHER, id, metric ? "c" : "f"); String response = HttpRetriever.retrieve(url); if (response == null) { return null; }/* w w w. ja v a2s.c o m*/ SAXParserFactory factory = SAXParserFactory.newInstance(); try { SAXParser parser = factory.newSAXParser(); StringReader reader = new StringReader(response); WeatherHandler handler = new WeatherHandler(); parser.parse(new InputSource(reader), handler); if (handler.isComplete()) { // There are cases where the current condition is unknown, but the forecast // is not - using the (inaccurate) forecast is probably better than showing // the question mark if (handler.conditionCode == 3200) { handler.condition = handler.forecasts.get(0).condition; handler.conditionCode = handler.forecasts.get(0).conditionCode; } WeatherInfo w = new WeatherInfo(mContext, id, localizedCityName != null ? localizedCityName : handler.city, handler.condition, handler.conditionCode, handler.temperature, handler.temperatureUnit, handler.humidity, handler.windSpeed, handler.windDirection, handler.speedUnit, handler.forecasts, System.currentTimeMillis()); Log.d(TAG, "Weather updated: " + w); return w; } else { Log.w(TAG, "Received incomplete weather XML (id=" + id + ")"); } } catch (ParserConfigurationException e) { Log.e(TAG, "Could not create XML parser", e); } catch (SAXException e) { Log.e(TAG, "Could not parse weather XML (id=" + id + ")", e); } catch (IOException e) { Log.e(TAG, "Could not parse weather XML (id=" + id + ")", e); } return null; }
From source file:com.trailmagic.image.util.ImagesParserImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = false) public void parseFile(File metadataFile) { try {// w w w . j a v a 2s .c o m SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true); SAXParser parser = factory.newSAXParser(); s_logger.info("Parsing " + metadataFile.getPath() + "..."); parser.parse(metadataFile, this); s_logger.info("done"); } catch (Throwable t) { t.printStackTrace(); System.exit(1); } }
From source file:dreamboxdataservice.DreamboxDataService.java
private void getEPGData(TvDataUpdateManager updateManager, Channel ch) { try {/*from w ww . j av a2 s . c om*/ URL url = new URL("http://" + mProperties.getProperty("ip", "") + "/web/epgservice?sRef=" + StringUtils.replace(StringUtils.replace(ch.getId().substring(5), "_", ":"), " ", "%20")); URLConnection connection = url.openConnection(); String userpassword = mProperties.getProperty("username", "") + ":" + IOUtilities .xorEncode(mProperties.getProperty("password", ""), DreamboxSettingsPanel.PASSWORDSEED); String encoded = new String(Base64.encodeBase64(userpassword.getBytes())); connection.setRequestProperty("Authorization", "Basic " + encoded); connection.setConnectTimeout(60); InputStream stream = connection.getInputStream(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); DreamboxChannelHandler handler = new DreamboxChannelHandler(updateManager, ch); saxParser.parse(stream, handler); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.sshtools.daemon.configuration.ServerConfiguration.java
/** * * * @param in/* w w w. j av a2 s.c o m*/ * * @throws SAXException * @throws ParserConfigurationException * @throws IOException */ public void reload(InputStream in) throws SAXException, ParserConfigurationException, IOException { allowedSubsystems.clear(); serverHostKeys.clear(); allowedAuthentications.clear(); requiredAuthentications.clear(); commandPort = 12222; port = 22; listenAddress = "0.0.0.0"; maxConnections = 10; maxAuthentications = 5; terminalProvider = ""; authorizationFile = "authorization.xml"; userConfigDirectory = "%D/.ssh2"; authenticationBanner = ""; allowTcpForwarding = true; currentElement = null; SAXParserFactory saxFactory = SAXParserFactory.newInstance(); SAXParser saxParser = saxFactory.newSAXParser(); saxParser.parse(in, this); }
From source file:fr.paris.lutece.plugins.dila.modules.solr.utils.parsers.DilaSolrPublicParser.java
/** * Launches the parsing on each public card * * @param fileBasePath the base path// w ww . j a v a 2 s. c om * @param parser the SAX parser */ private void parseAllPublicCards(File fileBasePath, SAXParser parser) { if (fileBasePath.isFile()) { // Launches the parsing of this public card (with the current handler) try { parser.parse(fileBasePath.getAbsolutePath(), this); } catch (SAXException e) { AppLogService.error(e.getMessage(), e); } catch (IOException e) { AppLogService.error(e.getMessage(), e); } } else { // Processes all the files of the current directory File[] files = fileBasePath.listFiles(); for (File fileCurrent : files) { // Launches the parsing on each public card (recursive) parseAllPublicCards(fileCurrent, parser); } } }
From source file:com.wooki.test.unit.ConversionsTest.java
@Test(enabled = true) public void docbookConversion() { String result = "<book> <bookinfo> <title>An Example Book</title> <author> <firstname>Your first name</firstname> <surname>Your surname</surname> <affiliation> <address><email>foo@example.com</email></address> </affiliation> </author> <copyright> <year>2000</year> <holder>Copyright string here</holder> </copyright> <abstract> <para>If your book has an abstract then it should go here.</para> </abstract> </bookinfo> <preface> <title>Preface</title> <para>Your book may have a preface, in which case it should be placed here.</para> </preface> <chapter> <title>My First Chapter</title> <para>This is the first chapter in my book.</para> <sect1> <title>My First Section</title> <para>This is the first section in my book.</para> </sect1> </chapter> </book>"; Resource resource = new ByteArrayResource(result.getBytes()); InputStream xhtml = fromDocbookConvertor.performTransformation(resource); File htmlFile = null;/*from w w w. j a va2s. c o m*/ try { htmlFile = File.createTempFile("wooki", ".html"); FileOutputStream fos = new FileOutputStream(htmlFile); logger.debug("HTML File is " + htmlFile.getAbsolutePath()); byte[] content = null; int available = 0; while ((available = xhtml.available()) > 0) { content = new byte[available]; xhtml.read(content); fos.write(content); } fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); logger.error(e.getLocalizedMessage()); return; } logger.debug("Docbook to xhtml ok"); SAXParserFactory factory = SAXParserFactory.newInstance(); // cration d'un parseur SAX SAXParser parser; try { parser = factory.newSAXParser(); parser.parse(new InputSource(new FileInputStream(htmlFile)), htmlParser); } catch (ParserConfigurationException e) { e.printStackTrace(); logger.error(e.getLocalizedMessage()); } catch (SAXException e) { e.printStackTrace(); logger.error(e.getLocalizedMessage()); } catch (IOException e) { e.printStackTrace(); logger.error(e.getLocalizedMessage()); } Book book = htmlParser.getBook(); logger.debug("The book title is " + book.getTitle()); }