List of usage examples for org.xml.sax InputSource setSystemId
public void setSystemId(String systemId)
From source file:com.adaptris.transform.Source.java
public InputSource getInputSource() throws IOException, URISyntaxException { InputSource is = new InputSource(); if (this.url != null) { is.setSystemId(this.url); is.setCharacterStream(this.charStream); is.setByteStream(URLHelper.connect(url)); } else {//from www .ja v a 2 s . c o m is.setSystemId(this.url); is.setCharacterStream(this.charStream); } return is; }
From source file:org.data.support.beans.factory.xml.QueryDTDResolver.java
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public ID [" + publicId + "] and system ID [" + systemId + "]"); }// w w w .j a va 2 s . c o m if (systemId != null && systemId.endsWith(DTD_EXTENSION)) { int lastPathSeparator = systemId.lastIndexOf("/"); for (String DTD_NAME : DTD_NAMES) { int dtdNameStart = systemId.indexOf(DTD_NAME); if (dtdNameStart > lastPathSeparator) { String dtdFile = systemId.substring(dtdNameStart); if (logger.isTraceEnabled()) { logger.trace("Trying to locate [" + dtdFile + "] in Spring jar"); } try { Resource resource = new ClassPathResource(dtdFile, getClass()); InputSource source = new InputSource(resource.getInputStream()); source.setPublicId(publicId); source.setSystemId(systemId); if (logger.isDebugEnabled()) { logger.debug("Found queries DTD [" + systemId + "] in classpath: " + dtdFile); } return source; } catch (IOException ex) { if (logger.isDebugEnabled()) { logger.debug( "Could not resolve queries DTD [" + systemId + "]: not found in class path", ex); } } } } } // Use the default behavior -> download from website or wherever. return null; }
From source file:com.knitml.core.xml.PluggableSchemaResolver.java
public InputSource resolveEntity(String publicId, String systemId) throws IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public id [" + publicId + "] and system id [" + systemId + "]"); }/*from w w w . j ava2 s. c om*/ if (systemId != null) { String resourceLocation = getSchemaMapping(systemId); if (resourceLocation != null) { Resource resource = new ClassPathResource(resourceLocation, this.classLoader); InputSource source = new InputSource(resource.getInputStream()); source.setPublicId(publicId); source.setSystemId(systemId); if (logger.isDebugEnabled()) { logger.debug("Found XML schema [" + systemId + "] in classpath: " + resourceLocation); } return source; } } return null; }
From source file:de.tudarmstadt.ukp.dkpro.core.io.xml.XmlReaderText.java
@Override public void getNext(CAS aCAS) throws IOException, CollectionException { Resource res = nextFile();//w w w. ja v a 2 s .co m initCas(aCAS, res); InputStream is = null; try { JCas jcas = aCAS.getJCas(); is = res.getInputStream(); // Create handler Handler handler = newSaxHandler(); handler.setJCas(jcas); handler.setLogger(getLogger()); // Parser XML SAXParserFactory pf = SAXParserFactory.newInstance(); SAXParser parser = pf.newSAXParser(); InputSource source = new InputSource(is); source.setPublicId(res.getLocation()); source.setSystemId(res.getLocation()); parser.parse(source, handler); // Set up language if (getConfigParameterValue(PARAM_LANGUAGE) != null) { aCAS.setDocumentLanguage((String) getConfigParameterValue(PARAM_LANGUAGE)); } } catch (CASException e) { throw new CollectionException(e); } catch (ParserConfigurationException e) { throw new CollectionException(e); } catch (SAXException e) { throw new IOException(e); } finally { closeQuietly(is); } }
From source file:bpelg.packaging.ode.util.BgSchemaCollection.java
public void read(String location, URI baseUri) throws Exception { if (log.isDebugEnabled()) { log.debug("Reading schema at '" + location + "' with baseUri '" + baseUri + "'"); }//from w w w . j av a 2s.c o m if (baseUri == null) { baseUri = this.baseUri; } URI loc; if (baseUri != null) { loc = resolve(baseUri, location); if (!loc.isAbsolute()) { throw new IllegalArgumentException( "Unable to resolve '" + loc.toString() + "' relative to '" + baseUri + "'"); } } else { loc = new URI(location); if (!loc.isAbsolute()) { throw new IllegalArgumentException( "Location '" + loc.toString() + "' is not absolute and no baseUri specified"); } } InputSource inputSource = new InputSource(); inputSource.setByteStream(loc.toURL().openStream()); inputSource.setSystemId(loc.toString()); read(inputSource); }
From source file:org.data.support.beans.factory.xml.SchemaResolver.java
public InputSource resolveEntity(String publicId, String systemId) throws IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public id [" + publicId + "] and system id [" + systemId + "]"); }/* w w w . j a v a 2 s . co m*/ if (systemId != null) { String resourceLocation = getSchemaMappings().get(systemId); if (resourceLocation != null) { Resource resource = new ClassPathResource(resourceLocation, this.classLoader); try { InputSource source = new InputSource(resource.getInputStream()); source.setPublicId(publicId); source.setSystemId(systemId); if (logger.isDebugEnabled()) { logger.debug("Found XML schema [" + systemId + "] in classpath: " + resourceLocation); } return source; } catch (FileNotFoundException ex) { if (logger.isDebugEnabled()) { logger.debug("Couldn't find XML schema [" + systemId + "]: " + resource, ex); } } } } return null; }
From source file:com.adaptris.util.text.xml.Resolver.java
/** * @see EntityResolver#resolveEntity(String, String) *///from w w w.jav a 2 s.c o m @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException { debugLog("Resolving [{}][{}]", publicId, systemId); InputSource result = null; try { InputSource ret = new InputSource(retrieveAndCache(new URLString(systemId))); ret.setPublicId(publicId); ret.setSystemId(systemId); result = ret; } catch (Exception e) { debugLog("Couldn't handle [{}][{}], fallback to default parser behaviour", publicId, systemId); result = null; } return result; }
From source file:org.callimachusproject.xml.InputSourceResolver.java
private InputSource create(String type, InputStream in, String systemId) throws UnsupportedEncodingException { Matcher m = CHARSET.matcher(type); if (m.find()) { Reader reader = new InputStreamReader(in, m.group(1)); InputSource source = new InputSource(reader); if (systemId != null) { source.setSystemId(systemId); }//from www.j av a2 s . c o m return source; } InputSource source = new InputSource(in); if (systemId != null) { source.setSystemId(systemId); } return source; }
From source file:de.smartics.maven.alias.MavenAliasMojo.java
private InputSource createSource() throws MojoExecutionException { final File file = new File(aliasLocation); try {//from ww w .ja va 2s. com final InputStream in = new BufferedInputStream(new FileInputStream(file)); final InputSource source = new InputSource(); source.setSystemId(aliasLocation); source.setByteStream(in); return source; } catch (final FileNotFoundException e) { throw new MojoExecutionException("Cannot read alias XML file '" + aliasLocation + "'.", e); } }
From source file:de.ii.xtraplatform.ogc.api.gml.parser.OGCEntityResolver.java
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { // TODO: temporary basic auth hack // protected schema files if (systemId != null && systemId.startsWith("https://") && useBasicAuth) { HttpResponse response = null;/*from w w w . ja v a 2 s .co m*/ LOGGER.debug("resolving protected schema: {}", systemId); try { HttpGet httpGet = new HttpGet(systemId); String basic_auth = new String(Base64.encodeBase64((user + ":" + password).getBytes())); httpGet.addHeader("Authorization", "Basic " + basic_auth); response = untrustedSslHttpClient.execute(httpGet, new BasicHttpContext()); String stringFromStream = CharStreams .toString(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); InputSource is = new InputSource(new StringReader(stringFromStream)); is.setSystemId(systemId); return is; } catch (IOException ex) { ex.printStackTrace(); LOGGER.error("Error parsing application schema. {}", ex); throw new SchemaParseException("Error parsing application schema. {}", ex.getMessage()); } finally { if (response != null) { EntityUtils.consumeQuietly(response.getEntity()); } } } //LOGGER.info(" --- {} --- {} ", systemId, publicId); if (publicId != null && publicId.equals("http://www.opengis.net/gml")) { if (!isAvailable(systemId)) { return new InputSource("http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"); } } if (publicId != null && publicId.equals("http://www.opengis.net/gml/3.2")) { if (!isAvailable(systemId)) { return new InputSource("http://schemas.opengis.net/gml/3.2.1/gml.xsd"); } } if (publicId != null && publicId.equals("http://www.w3.org/1999/xlink")) { if (!isAvailable(systemId)) { return new InputSource("http://www.w3.org/1999/xlink.xsd"); } } if (publicId != null && publicId.equals("http://www.aixm.aero/schema/5.1")) { if (!isAvailable(systemId)) { return new InputSource("http://www.aixm.aero/gallery/content/public/schema/5.1/AIXM_Features.xsd"); } } if (systemId != null) { // Workaround for broken Schema in dwd-WFS if (systemId.endsWith("gml.xsd") && systemId.contains("kunden.dwd.de")) { return new InputSource("http://schemas.opengis.net/gml/3.2.1/gml.xsd"); } /*if (systemId.endsWith("basicTypes.xsd") && redirect.contains("http://www.opengis.net/gml/3.2")) { return new InputSource("http://schemas.opengis.net/gml/3.2.1/basicTypes.xsd"); } if (systemId.endsWith("xlinks.xsd") && redirect.contains("http://www.w3.org/1999/xlink")) { return new InputSource("http://www.w3.org/1999/xlink.xsd"); }*/ // workaround for A4I DescribeFeatureType (seen in 10.2.1) // also occurs with native XtraServer, moved to general workarounds if (publicId == null && systemId.contains("&REQUEST=DescribeFeatureType&TYPENAMES=ns:AbstractFeature")) { return createFakeSchema("http://www.opengis.net/gml/3.2"); } // A4I workarounds if (systemId.contains("/exts/InspireFeatureDownload/service")) { String url = systemId; // workaround for A4I 10.1 SP1 (Patch1) blank encoding bug in GET parameters if (url.contains("OUTPUT_FORMAT=")) { int start = url.indexOf("OUTPUT_FORMAT=") + 13; int end = url.indexOf("&", start); String out = url.substring(start, end).replaceAll("%20", ""); url = url.substring(0, start) + out + url.substring(end); } if (!url.equals(systemId)) { LOGGER.debug("original systemId: {}", systemId); LOGGER.debug("changed systemId: {}", url); return new InputSource(url); } } } // ignore multiple imports into the same namespace if (publicId != null) { if (!uris.containsKey(publicId)) { uris.put(publicId, systemId); } if (systemId != null && !systemId.equals(uris.get(publicId))) { return createFakeSchema(publicId); } } return null; }