List of usage examples for org.xml.sax XMLReader setContentHandler
public void setContentHandler(ContentHandler handler);
From source file:edu.ucsd.xmlrpc.xmlrpc.server.XmlRpcStreamServer.java
protected XmlRpcRequest getRequest(final XmlRpcStreamRequestConfig pConfig, InputStream pStream) throws XmlRpcException { final XmlRpcRequestParser parser = new XmlRpcRequestParser(pConfig, getTypeFactory()); final XMLReader xr = SAXParsers.newXMLReader(); xr.setContentHandler(parser); try {/*from w w w . j a v a 2 s . com*/ xr.parse(new InputSource(pStream)); } catch (SAXException e) { Exception ex = e.getException(); if (ex != null && ex instanceof XmlRpcException) { throw (XmlRpcException) ex; } throw new XmlRpcException("Failed to parse XML-RPC request: " + e.getMessage(), e); } catch (IOException e) { throw new XmlRpcException("Failed to read XML-RPC request: " + e.getMessage(), e); } final List params = parser.getParams(); // Ucsd modified code return new XmlRpcClientRequestImpl(pConfig, parser.getMethodName(), parser.getParams(), parser.getJobID()); // end }
From source file:com.webcohesion.ofx4j.io.BaseOFXReader.java
/** * Parse an OFX version 2 stream from the first OFX element (defined by the {@link #getFirstElementStart() first element characters}). * * @param reader The reader.//from w w w . ja va 2s . c o m */ protected void parseV2FromFirstElement(Reader reader) throws IOException, OFXParseException { try { XMLReader xmlReader = XMLReaderFactory.createXMLReader(); xmlReader.setFeature("http://xml.org/sax/features/namespaces", false); xmlReader.setContentHandler(new OFXV2ContentHandler(getContentHandler())); xmlReader.parse(new InputSource(reader)); } catch (SAXException e) { if (e.getCause() instanceof OFXParseException) { throw (OFXParseException) e.getCause(); } throw new OFXParseException(e); } }
From source file:com.bdaum.juploadr.uploadapi.locrrest.LocrMethod.java
/** * @param responseBodyAsString// ww w . j av a 2 s. c om * @return * @throws AuthException */ public boolean parseResponse(String response) throws ProtocolException { try { XMLReader reader = XMLReaderFactory.createXMLReader(); handler = getResponseHandler(); reader.setContentHandler(handler); reader.parse(new InputSource(new StringReader(response))); if (!handler.isSuccessful()) { throw defaultExceptionFor(handler.getErrorCode()); } return handler.isSuccessful(); } catch (SAXException e) { throw new AuthException(Messages.getString("juploadr.ui.error.response.unreadable.noreason"), //$NON-NLS-1$ e); } catch (IOException e) { // this can't happen } return false; }
From source file:com.test.demo.ccbpay.XLSX2CSV.java
/** * Parses and shows the content of one sheet * using the specified styles and shared-strings tables. * * @param styles/*from w w w. j a v a2 s .c o m*/ * @param strings * @param sheetInputStream */ public void processSheet(StylesTable styles, ReadOnlySharedStringsTable strings, SheetContentsHandler sheetHandler, InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException { DataFormatter formatter = new DataFormatter(); InputSource sheetSource = new InputSource(sheetInputStream); try { XMLReader sheetParser = SAXHelper.newXMLReader(); ContentHandler handler = new XSSFSheetXMLHandler(styles, null, strings, sheetHandler, formatter, false); sheetParser.setContentHandler(handler); sheetParser.parse(sheetSource); } catch (ParserConfigurationException e) { throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage()); } }
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 .j a 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.chitek.util.XMLConfigParser.java
/** * Parses the given XML and uses reflection to apply the configuration.<br /> * 'setting' uses the set... methods in the configuration for all found settings. * Supported types are boolean, int and String.<br /> * 'config' creates a new instance of the given type and uses the add... method * in the configuration class to add new elements. The type of the new class is * determined by the parameter type of the add... method. * // w w w . j a v a2s . co m * @param clazz * The Class to return * @param typeName * The name of the XML-Element with the configuration * @param configXML * The XML configuration to parse * @return A new instance of clazz * @throws Exception */ public Object parseXML(Class<?> clazz, String typeName, String configXML) throws Exception { Object config = clazz.newInstance(); try { XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); reader.setContentHandler(new ContentHandler(config, typeName)); reader.parse(new InputSource(new StringReader(configXML))); } catch (Exception e) { throw e; } return config; }
From source file:com.keithhutton.ws.proxy.ProxyServlet.java
private XmlRpcRequest getMethodAndParamsFromRequest(ServletRequest req) throws XmlRpcException { final XmlRpcStreamRequestConfig pConfig = getConfig((HttpServletRequest) req); final XmlRpcRequestParser parser = new XmlRpcRequestParser(pConfig, getTypeFactory()); final XMLReader xr = SAXParsers.newXMLReader(); xr.setContentHandler(parser); try {/* w w w .j a va 2 s .co m*/ xr.parse(new InputSource(req.getInputStream())); } catch (SAXException e) { Exception ex = e.getException(); if (ex != null && ex instanceof XmlRpcException) { throw (XmlRpcException) ex; } throw new XmlRpcException("Failed to parse XML-RPC request: " + e.getMessage(), e); } catch (IOException e) { throw new XmlRpcException("Failed to read XML-RPC request: " + e.getMessage(), e); } final List params = parser.getParams(); final int paramCount = params == null ? 0 : params.size(); XmlRpcRequest xmlRpcRequest = new XmlRpcRequest() { public XmlRpcRequestConfig getConfig() { return pConfig; } public String getMethodName() { return parser.getMethodName(); } public int getParameterCount() { return params == null ? 0 : params.size(); } public Object getParameter(int pIndex) { return paramCount > 0 ? params.get(pIndex) : null; } }; this.log.info("xmlRpcRequest method = " + xmlRpcRequest.getMethodName()); this.log.info("xmlRpcRequest pcount = " + xmlRpcRequest.getParameterCount()); this.log.info("xmlRpcRequest param1 = " + xmlRpcRequest.getParameter(0)); return xmlRpcRequest; }
From source file:org.apache.commons.rdf.impl.sparql.SparqlClient.java
List<Map<String, RdfTerm>> queryResultSet(final String query) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(endpoint); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("query", query)); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); CloseableHttpResponse response2 = httpclient.execute(httpPost); try {//from w ww.j av a 2s . com HttpEntity entity2 = response2.getEntity(); InputStream in = entity2.getContent(); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); SAXParser saxParser = spf.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); final SparqlsResultsHandler sparqlsResultsHandler = new SparqlsResultsHandler(); xmlReader.setContentHandler(sparqlsResultsHandler); xmlReader.parse(new InputSource(in)); /* for (int ch = in.read(); ch != -1; ch = in.read()) { System.out.print((char)ch); } */ // do something useful with the response body // and ensure it is fully consumed EntityUtils.consume(entity2); return sparqlsResultsHandler.getResults(); } catch (ParserConfigurationException ex) { throw new RuntimeException(ex); } catch (SAXException ex) { throw new RuntimeException(ex); } finally { response2.close(); } }
From source file:com.zegoggles.smssync.auth.XOAuthConsumer.java
private String extractEmail(HttpResponse response) throws ParserConfigurationException, SAXException, IOException { final XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); final FeedHandler feedHandler = new FeedHandler(); xmlReader.setContentHandler(feedHandler); xmlReader.parse(new InputSource(response.getEntity().getContent())); return feedHandler.getEmail(); }
From source file:com.zazuko.blv.outbreak.tools.SparqlClient.java
List<Map<String, RDFTerm>> queryResultSet(final String query) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(endpoint); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("query", query)); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); CloseableHttpResponse response2 = httpclient.execute(httpPost); try {// w w w. j a v a2 s . co m HttpEntity entity2 = response2.getEntity(); InputStream in = entity2.getContent(); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); SAXParser saxParser = spf.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); final SparqlsResultsHandler sparqlsResultsHandler = new SparqlsResultsHandler(); xmlReader.setContentHandler(sparqlsResultsHandler); xmlReader.parse(new InputSource(in)); /* for (int ch = in.read(); ch != -1; ch = in.read()) { System.out.print((char)ch); } */ // do something useful with the response body // and ensure it is fully consumed EntityUtils.consume(entity2); return sparqlsResultsHandler.getResults(); } catch (ParserConfigurationException ex) { throw new RuntimeException(ex); } catch (SAXException ex) { throw new RuntimeException(ex); } finally { response2.close(); } }