List of usage examples for org.xml.sax InputSource setByteStream
public void setByteStream(InputStream byteStream)
From source file:org.runnerup.export.JoggSESynchronizer.java
@Override public Status connect() { if (isConnected) { return Status.OK; }//from w ww .ja v a2s .co m Status s = Status.NEED_AUTH; s.authMethod = Synchronizer.AuthMethod.USER_PASS; if (username == null || password == null) { return s; } Exception ex = null; HttpURLConnection conn = null; try { /** * Login by making an empty save-gpx call and see what error message * you get Invalid/"Invalid Userdetails" => wrong user/pass * NOK/"Root element is missing" => OK */ final String LOGIN_OK = "NOK"; conn = (HttpURLConnection) new URL(BASE_URL).openConnection(); conn.setDoOutput(true); conn.setRequestMethod(RequestMethod.POST.name()); conn.addRequestProperty("Host", "jogg.se"); conn.addRequestProperty("Content-Type", "text/xml"); final BufferedWriter wr = new BufferedWriter(new PrintWriter(conn.getOutputStream())); saveGPX(wr, ""); wr.flush(); wr.close(); final InputStream in = new BufferedInputStream(conn.getInputStream()); final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); final DocumentBuilder db = dbf.newDocumentBuilder(); final InputSource is = new InputSource(); is.setByteStream(in); final Document doc = db.parse(is); conn.disconnect(); conn = null; final String path[] = { "soap:Envelope", "soap:Body", "SaveGpxResponse", "SaveGpxResult", "ResponseStatus", "ResponseCode" }; final Node e = navigate(doc, path); Log.e(getName(), "reply: " + e.getTextContent()); if (e != null && e.getTextContent() != null && LOGIN_OK.contentEquals(e.getTextContent())) { isConnected = true; return Synchronizer.Status.OK; } return s; } catch (final MalformedURLException e) { ex = e; } catch (final IOException e) { ex = e; } catch (final ParserConfigurationException e) { ex = e; } catch (final SAXException e) { ex = e; } if (conn != null) conn.disconnect(); s = Synchronizer.Status.ERROR; s.ex = ex; if (ex != null) { ex.printStackTrace(); } return s; }
From source file:org.runnerup.export.JoggSESynchronizer.java
@Override public Status upload(final SQLiteDatabase db, final long mID) { Status s;// w ww .j av a 2 s. c om if ((s = connect()) != Status.OK) { return s; } Exception ex = null; HttpURLConnection conn = null; final GPX gpx = new GPX(db); try { final StringWriter gpxString = new StringWriter(); gpx.export(mID, gpxString); conn = (HttpURLConnection) new URL(BASE_URL).openConnection(); conn.setDoOutput(true); conn.setRequestMethod(RequestMethod.POST.name()); conn.addRequestProperty("Host", "jogg.se"); conn.addRequestProperty("Content-Type", "text/xml; charset=utf-8"); final BufferedWriter wr = new BufferedWriter(new PrintWriter(conn.getOutputStream())); saveGPX(wr, gpxString.toString()); wr.flush(); wr.close(); final InputStream in = new BufferedInputStream(conn.getInputStream()); final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); final DocumentBuilder dob = dbf.newDocumentBuilder(); final InputSource is = new InputSource(); is.setByteStream(in); final Document doc = dob.parse(is); conn.disconnect(); conn = null; final String path[] = { "soap:Envelope", "soap:Body", "SaveGpxResponse", "SaveGpxResult", "ResponseStatus", "ResponseCode" }; final Node e = navigate(doc, path); Log.e(getName(), "reply: " + e.getTextContent()); if (e != null && e.getTextContent() != null && "OK".contentEquals(e.getTextContent())) { s = Status.OK; s.activityId = mID; return s; } throw new Exception(e.getTextContent()); } catch (final MalformedURLException e) { ex = e; } catch (final IOException e) { ex = e; } catch (final ParserConfigurationException e) { ex = e; } catch (final SAXException e) { ex = e; } catch (final DOMException e) { ex = e; e.printStackTrace(); } catch (final Exception e) { ex = e; } if (conn != null) conn.disconnect(); s = Synchronizer.Status.ERROR; s.ex = ex; s.activityId = mID; if (ex != null) { ex.printStackTrace(); } return s; }
From source file:org.seasar.struts.hotdeploy.impl.ModuleConfigLoaderImpl.java
protected void parseModuleConfigFile(Digester digester, URL url) throws UnavailableException { InputStream input = null;//from w w w . jav a 2 s .co m try { InputSource is = new InputSource(url.toExternalForm()); URLConnection conn = url.openConnection(); conn.setUseCaches(false); conn.connect(); input = conn.getInputStream(); is.setByteStream(input); digester.parse(is); } catch (IOException e) { handleConfigException(url.toString(), e); } catch (SAXException e) { handleConfigException(url.toString(), e); } finally { if (input != null) { try { input.close(); } catch (IOException e) { throw new UnavailableException(e.getMessage()); } } } }
From source file:org.vfny.geoserver.config.MultipleActionServlet.java
/** * <p>Parses one module config file.</p> * * @param digester Digester instance that does the parsing * @param path The path to the config file to parse. * * @throws UnavailableException if file cannot be read or parsed * @since Struts 1.2//w w w . ja va 2 s . co m */ protected void parseModuleConfigFile(Digester digester, String path) throws UnavailableException { InputStream input = null; try { Resource[] resources = WebApplicationContextUtils.getWebApplicationContext(getServletContext()) .getResources(path); final int length = resources.length; for (int i = 0; i < length; i++) { URL url = resources[i].getURL(); /*getServletContext().getResource(path)*/ ; // If the config isn't in the servlet context, try the class loader // which allows the config files to be stored in a jar if (url == null) { url = getClass().getResource(path); } if (url == null) { String msg = internal.getMessage("configMissing", path); log.error(msg); throw new UnavailableException(msg); } InputSource is = new InputSource(url.toExternalForm()); input = url.openStream(); is.setByteStream(input); digester.parse(is); } } catch (MalformedURLException e) { handleConfigException(path, e); } catch (IOException e) { handleConfigException(path, e); } catch (SAXException e) { handleConfigException(path, e); } finally { if (input != null) { try { input.close(); } catch (IOException e) { throw new UnavailableException(e.getMessage()); } } } }
From source file:org.vfny.geoserver.config.web.MultipleActionServlet.java
/** * <p>Parses one module config file.</p> * * @param digester Digester instance that does the parsing * @param path The path to the config file to parse. * @param config//from w w w . ja va2 s . c om * * @throws UnavailableException if file cannot be read or parsed * @since Struts 1.2 */ protected void parseModuleConfigFile(Digester digester, String path, ModuleConfig config) throws UnavailableException { InputStream input = null; Resource[] resources = null; try { resources = WebApplicationContextUtils.getWebApplicationContext(getServletContext()).getResources(path); } catch (IOException ex) { handleConfigException(path, ex); } final int length = resources.length; for (int i = 0; i < length; i++) { try { URL url = resources[i].getURL(); /*getServletContext().getResource(path)*/ ; // If the config isn't in the servlet context, try the class loader // which allows the config files to be stored in a jar if (url == null) { url = getClass().getResource(path); } if (url == null) { String msg = internal.getMessage("configMissing", path); log.error(msg); throw new UnavailableException(msg); } InputSource is = new InputSource(url.toExternalForm()); input = url.openStream(); is.setByteStream(input); digester.parse(is); } catch (MalformedURLException e) { handleConfigException(path, e); } catch (IOException e) { handleConfigException(path, e); } catch (SAXException e) { handleConfigException(path, e); } finally { if (input != null) { try { input.close(); if ((length > 1) && (i < (length - 1))) { digester.push(config); } } catch (IOException e) { throw new UnavailableException(e.getMessage()); } } } } }
From source file:org.wso2.carbon.bpel.core.ode.integration.axis2.Axis2WSDLLocator.java
public InputSource getBaseInputSource() { try {// w w w .ja v a 2 s . c om InputSource is = new InputSource(); is.setByteStream(openResource(baseUri)); is.setSystemId(baseUri.toString()); return is; } catch (IOException e) { log.error("Unable to create InputSource for " + baseUri, e); return null; } }
From source file:org.wso2.carbon.bpel.core.ode.integration.axis2.Axis2WSDLLocator.java
public InputSource getImportInputSource(String parent, String imprt) { URI uri;/* w ww .j a v a 2 s . c o m*/ try { uri = parent == null ? baseUri.resolve(imprt) : new URI(parent).resolve(imprt); } catch (URISyntaxException e1) { log.error("URI syntax error: parent=" + parent, e1); return null; } if (log.isDebugEnabled()) { log.debug("Get import: import=" + imprt + " parent=" + parent); } InputSource is = new InputSource(); try { is.setByteStream(openResource(uri)); } catch (Exception e) { log.error("Unable to open import resource: " + uri, e); return null; } is.setSystemId(uri.toString()); latest = uri.toString(); return is; }
From source file:org.wso2.carbon.humantask.core.deployment.HumanTaskWSDLLocator.java
public InputSource getBaseInputSource() { try {/*www.java 2s . co m*/ InputSource is = new InputSource(); is.setByteStream(openResource(baseUri)); is.setSystemId(baseUri.toString()); return is; } catch (IOException e) { log.error("Unable to create InputSource for " + baseUri, e); return null; } }
From source file:org.xchain.namespaces.sax.UrlSourceCommand.java
/** * The name of the parameter.// w w w. j a v a 2s. c o m */ public boolean execute(JXPathContext context) throws Exception { InputSource inputSource = null; XMLReader xmlReader = null; DependencyTracker dependencyTracker = DependencyTracker.getInstance(); String systemId = getSystemId(context); URL url = UrlFactory.getInstance().newUrl(getLocator().getSystemId(), systemId); inputSource = new InputSource(); inputSource.setSystemId(systemId); inputSource.setByteStream(url.openStream()); // set the source in the pipeline config. PipelineCommand.getPipelineConfig().setSource(inputSource); if (xmlReader != null) { PipelineCommand.getPipelineConfig().setXmlReader(xmlReader); } return false; }