List of usage examples for org.xml.sax InputSource setPublicId
public void setPublicId(String publicId)
From source file:org.apache.myfaces.config.impl.FacesConfigEntityResolver.java
public InputSource resolveEntity(String publicId, String systemId) throws IOException { InputStream stream;//from w w w. ja v a2 s.c o m if (systemId.equals(FACES_CONFIG_1_0_DTD_SYSTEM_ID)) { stream = ClassUtils.getResourceAsStream(FACES_CONFIG_1_0_DTD_RESOURCE); } else if (systemId.equals(FACES_CONFIG_1_1_DTD_SYSTEM_ID)) { stream = ClassUtils.getResourceAsStream(FACES_CONFIG_1_1_DTD_RESOURCE); } else if (systemId.startsWith("jar:")) { URL url = new URL(systemId); JarURLConnection conn = (JarURLConnection) url.openConnection(); JarEntry jarEntry = conn.getJarEntry(); if (jarEntry == null) { log.fatal("JAR entry '" + systemId + "' not found."); } //_jarFile.getInputStream(jarEntry); stream = conn.getJarFile().getInputStream(jarEntry); } else { if (_externalContext == null) { stream = ClassUtils.getResourceAsStream(systemId); } else { if (systemId.startsWith("file:")) { systemId = systemId.substring(7); // remove file:// } stream = _externalContext.getResourceAsStream(systemId); } } if (stream == null) { return null; } InputSource is = new InputSource(stream); is.setPublicId(publicId); is.setSystemId(systemId); is.setEncoding("ISO-8859-1"); return is; }
From source file:org.apache.myfaces.custom.skin.config.ConfigParser.java
/** * *///from w ww . j a v a 2 s . co m static public RequestContextBean parseConfigFile(ExternalContext externalContext) { RequestContextBean bean = new RequestContextBean(); InputStream in = externalContext.getResourceAsStream(_SKINS_CONFIG_FILE); if (in == null) { in = externalContext.getResourceAsStream(_TRINIDAD_CONFIG_FILE); } if (in != null) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); Digester digester = new Digester(factory.newSAXParser()); digester.setValidating(false); digester.setNamespaceAware(true); digester.setUseContextClassLoader(true); RequestContextBean.addXmlRules(digester); InputSource input = new InputSource(); input.setByteStream(in); input.setPublicId(_SKINS_CONFIG_FILE); digester.parse(input); bean = (RequestContextBean) digester.getRoot(); } catch (IOException ioe) { _LOG.warning(ioe); } catch (ParserConfigurationException pce) { _LOG.warning(pce); } catch (SAXException saxe) { _LOG.warning(saxe); } finally { try { in.close(); } catch (IOException ioe) { // Ignore ; } } } return bean; }
From source file:org.apache.myfaces.shared_impl.webapp.webxml.WebXmlParser.java
private InputSource createContextInputSource(String publicId, String systemId) { InputStream inStream = _context.getResourceAsStream(systemId); if (inStream == null) { // there is no such entity return null; }// w ww .jav a2s. c o m InputSource is = new InputSource(inStream); is.setPublicId(publicId); is.setSystemId(systemId); //the next line was removed - encoding should be determined automatically out of the inputStream //DEFAULT_ENCODING was ISO-8859-1 //is.setEncoding(DEFAULT_ENCODING); return is; }
From source file:org.apache.myfaces.shared_impl.webapp.webxml.WebXmlParser.java
private InputSource createClassloaderInputSource(String publicId, String systemId) { InputStream inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(systemId); if (inStream == null) { // there is no such entity return null; }/* w w w . j av a 2 s . co m*/ InputSource is = new InputSource(inStream); is.setPublicId(publicId); is.setSystemId(systemId); //the next line was removed - encoding should be determined automatically out of the inputStream //encoding should be determined automatically out of the inputStream //DEFAULT_ENCODING was ISO-8859-1 //is.setEncoding(DEFAULT_ENCODING); return is; }
From source file:org.apache.ode.axis2.util.Axis2UriResolver.java
public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) { if (LOG.isDebugEnabled()) { LOG.debug("resolveEntity: targetNamespace=" + targetNamespace + " schemaLocation=" + schemaLocation + " baseUri=" + baseUri); }//from w w w.j av a 2s . co m InputStream is; try { URI base = new URI(baseUri); URI uri = base.resolve(schemaLocation); is = uri.toURL().openStream(); if (is == null) { LOG.error("Exception resolving entity: schemaLocation=" + schemaLocation + " baseUri=" + baseUri); return null; } InputSource source = new InputSource(is); source.setSystemId(uri.toString()); source.setPublicId(schemaLocation); return new InputSource(is); } catch (Exception e) { LOG.error("Exception resolving entity: schemaLocation=" + schemaLocation + " baseUri=" + baseUri, e); return null; } }
From source file:org.apereo.portal.utils.DocumentFactory.java
public static Document getDocumentFromStream(InputStream stream, String publicId) throws IOException, SAXException { DocumentBuilder builder = getThreadDocumentBuilder(); InputSource source = new InputSource(stream); source.setPublicId(publicId); Document doc = builder.parse(source); return doc;//from w w w . j a va2 s. c o m }
From source file:org.apereo.portal.utils.DocumentFactory.java
public static Document getDocumentFromStream(InputStream stream, EntityResolver er, String publicId) throws IOException, SAXException { DocumentBuilder builder = getThreadDocumentBuilder(); builder.setEntityResolver(er);/*from ww w . j a v a 2 s . c o m*/ InputSource source = new InputSource(stream); source.setPublicId(publicId); Document doc = builder.parse(source); return doc; }
From source file:org.apereo.portal.utils.ResourceLoader.java
/** * Returns the requested resource as a SAX input source. * @param requestingClass the java.lang.Class object of the class that is attempting to load the resource * @param resource a String describing the full or partial URL of the resource to load * @return the requested resource as a SAX input source * @throws ResourceMissingException//from www. ja v a 2 s . c o m * @throws java.io.IOException */ public static InputSource getResourceAsSAXInputSource(Class<?> requestingClass, String resource) throws ResourceMissingException, IOException { URL url = getResourceAsURL(requestingClass, resource); InputSource source = new InputSource(url.openStream()); source.setPublicId(url.toExternalForm()); return source; }
From source file:org.betaconceptframework.astroboa.configuration.W3CRelatedSchemaEntityResolver.java
private InputSource locateEntity(String systemId, String publicId) throws IOException { URL xsdOrDtdLocation = null;//from ww w . j a v a 2s . c o m if (publicId != null && schemaURLsPerPublicId.containsKey(publicId)) { xsdOrDtdLocation = schemaURLsPerPublicId.get(publicId); } if (systemId == null) { return null; } String xsdOrDtdFilename = (systemId.contains(CmsConstants.FORWARD_SLASH) ? StringUtils.substringAfterLast(systemId, CmsConstants.FORWARD_SLASH) : systemId); //Check if schema is available locally if (xsdOrDtdLocation == null) { xsdOrDtdLocation = this.getClass() .getResource(xmlSchemaHomeDir + CmsConstants.FORWARD_SLASH + xsdOrDtdFilename); } //Try on the WEB if (xsdOrDtdLocation == null) { xsdOrDtdLocation = new URL(systemId); } try { InputSource is = new InputSource(xsdOrDtdLocation.openStream()); //System Id is the path of this URL is.setSystemId(xsdOrDtdLocation.toString()); is.setPublicId(publicId); schemaURLsPerPublicId.put(publicId, xsdOrDtdLocation); return is; } catch (Throwable isEx) { //Log a warning and let the Xerces parser to locate the schema LoggerFactory.getLogger(getClass()).warn("Unable to resolve schema for " + publicId + " " + systemId + " in URL " + xsdOrDtdLocation.toString(), isEx); //continue with parser provided by Java. If schema cannot be located, an exception will be thrown return null; } }
From source file:org.betaconceptframework.astroboa.engine.definition.RepositoryEntityResolver.java
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(systemId) || XMLConstants.XML_NS_URI.equals(systemId) || CmsConstants.XML_SCHEMA_LOCATION.equals(systemId) || CmsConstants.XML_SCHEMA_DTD_LOCATION.equals(systemId)) { return entityResolverForBuiltInSchemas.resolveXmlSchemaRelatedToW3C(publicId, systemId); }// ww w . jav a 2 s . c o m byte[] schema = getSchema(systemId); if (schema == null) { return null; } InputSource is = new InputSource(new ByteArrayInputStream(schema)); is.setSystemId(systemId); is.setPublicId(publicId); return is; }