List of usage examples for org.xml.sax InputSource setSystemId
public void setSystemId(String systemId)
From source file:org.seasar.mayaa.impl.util.xml.XMLHandler.java
public InputSource resolveEntity(String publicId, String systemId) { String path = systemId;//from w w w . j a v a 2 s . c om Map entities = getEntityMap(); if (entities != null && entities.containsKey(publicId)) { path = (String) entities.get(publicId); } else if (entities != null && entities.containsKey(systemId)) { path = (String) entities.get(systemId); } else { int pos = systemId.lastIndexOf('/'); if (pos != -1) { path = systemId.substring(pos); } } Class neighborClass = getNeighborClass(); if (neighborClass == null) { neighborClass = getClass(); } ClassLoaderSourceDescriptor source = new ClassLoaderSourceDescriptor(); source.setSystemID(path); source.setNeighborClass(neighborClass); if (source.exists()) { InputSource ret = new InputSource(source.getInputStream()); ret.setPublicId(publicId); ret.setSystemId(path); return ret; } Log log = getLog(); if (log != null && log.isWarnEnabled()) { String message = StringUtil.getMessage(XMLHandler.class, 0, publicId, systemId); log.warn(message); } return null; }
From source file:org.springframework.beans.factory.xml.BeansDtdResolver.java
@Override @Nullable//from ww w. jav a 2 s . co m public InputSource resolveEntity(String publicId, @Nullable String systemId) throws IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public ID [" + publicId + "] and system ID [" + systemId + "]"); } if (systemId != null && systemId.endsWith(DTD_EXTENSION)) { int lastPathSeparator = systemId.lastIndexOf("/"); int dtdNameStart = systemId.indexOf(DTD_NAME, lastPathSeparator); if (dtdNameStart != -1) { String dtdFile = DTD_NAME + DTD_EXTENSION; if (logger.isTraceEnabled()) { logger.trace("Trying to locate [" + dtdFile + "] in Spring jar on classpath"); } 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 beans DTD [" + systemId + "] in classpath: " + dtdFile); } return source; } catch (IOException ex) { if (logger.isDebugEnabled()) { logger.debug("Could not resolve beans DTD [" + systemId + "]: not found in classpath", ex); } } } } // Use the default behavior -> download from website or wherever. return null; }
From source file:org.springframework.beans.factory.xml.PluggableSchemaResolver.java
@Override @Nullable//from w ww. ja v a2 s . com public InputSource resolveEntity(String publicId, @Nullable String systemId) throws IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public id [" + publicId + "] and system id [" + systemId + "]"); } 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:org.springframework.beans.factory.xml.ResourceEntityResolver.java
@Override @Nullable//from w ww.ja va 2s.com public InputSource resolveEntity(String publicId, @Nullable String systemId) throws SAXException, IOException { InputSource source = super.resolveEntity(publicId, systemId); if (source == null && systemId != null) { String resourcePath = null; try { String decodedSystemId = URLDecoder.decode(systemId, "UTF-8"); String givenUrl = new URL(decodedSystemId).toString(); String systemRootUrl = new File("").toURI().toURL().toString(); // Try relative to resource base if currently in system root. if (givenUrl.startsWith(systemRootUrl)) { resourcePath = givenUrl.substring(systemRootUrl.length()); } } catch (Exception ex) { // Typically a MalformedURLException or AccessControlException. if (logger.isDebugEnabled()) { logger.debug("Could not resolve XML entity [" + systemId + "] against system root URL", ex); } // No URL (or no resolvable URL) -> try relative to resource base. resourcePath = systemId; } if (resourcePath != null) { if (logger.isTraceEnabled()) { logger.trace( "Trying to locate XML entity [" + systemId + "] as resource [" + resourcePath + "]"); } Resource resource = this.resourceLoader.getResource(resourcePath); source = new InputSource(resource.getInputStream()); source.setPublicId(publicId); source.setSystemId(systemId); if (logger.isDebugEnabled()) { logger.debug("Found XML entity [" + systemId + "]: " + resource); } } } return source; }
From source file:org.springframework.xml.sax.SaxUtils.java
/** * Creates a SAX <code>InputSource</code> from the given resource. Sets the system identifier to the resource's * <code>URL</code>, if available. * * @param resource the resource/*from w w w . ja v a2s . co m*/ * @return the input source created from the resource * @throws IOException if an I/O exception occurs * @see InputSource#setSystemId(String) * @see #getSystemId(org.springframework.core.io.Resource) */ public static InputSource createInputSource(Resource resource) throws IOException { InputSource inputSource = new InputSource(resource.getInputStream()); inputSource.setSystemId(getSystemId(resource)); return inputSource; }
From source file:org.springmodules.remoting.xmlrpc.dom.XmlRpcDtdResolver.java
/** * @see EntityResolver#resolveEntity(String, String) *//* w ww . j a v a 2s. c o m*/ public InputSource resolveEntity(String publicId, String systemId) { if (logger.isDebugEnabled()) { logger.debug("Trying to resolve XML entity with public ID [" + publicId + "] and system ID [" + systemId + "]"); } if (systemId != null && systemId.indexOf(DTD_NAME) > systemId.lastIndexOf("/")) { String dtdFile = systemId.substring(systemId.indexOf(DTD_NAME)); if (logger.isDebugEnabled()) { logger.debug("Trying to locate [" + dtdFile + "] under [" + SEARCH_PACKAGE + "]"); } try { Resource resource = new ClassPathResource(SEARCH_PACKAGE + dtdFile, getClass()); InputSource source = new InputSource(resource.getInputStream()); source.setPublicId(publicId); source.setSystemId(systemId); if (logger.isDebugEnabled()) { logger.debug("Found beans DTD [" + systemId + "] in classpath"); } return source; } catch (IOException ex) { if (logger.isDebugEnabled()) { logger.debug("Could not resolve beans DTD [" + systemId + "]: not found in class path", ex); } } } return null; }
From source file:org.tinygroup.jspengine.compiler.JspConfig.java
private void processWebDotXml(ServletContext ctxt) throws JasperException { InputStream is = null;//from w ww. j a v a 2s . co m try { URL uri = ctxt.getResource(WEB_XML); if (uri == null) { // no web.xml return; } is = uri.openStream(); InputSource ip = new InputSource(is); ip.setSystemId(uri.toExternalForm()); ParserUtils pu = new ParserUtils(); /* SJSAS 6384538 TreeNode webApp = pu.parseXMLDocument(WEB_XML, ip); */ // START SJSAS 6384538 TreeNode webApp = pu.parseXMLDocument(WEB_XML, ip, options.isValidationEnabled()); // END SJSAS 6384538 if (webApp == null || webApp.findAttribute("version") == null || Double.valueOf(webApp.findAttribute("version")).doubleValue() < 2.4) { defaultIsELIgnored = "true"; return; } TreeNode jspConfig = webApp.findChild("jsp-config"); if (jspConfig == null) { return; } jspProperties = new Vector(); Iterator jspPropertyList = jspConfig.findChildren("jsp-property-group"); while (jspPropertyList.hasNext()) { TreeNode element = (TreeNode) jspPropertyList.next(); Iterator list = element.findChildren(); Vector urlPatterns = new Vector(); String pageEncoding = null; String scriptingInvalid = null; String elIgnored = null; String isXml = null; Vector includePrelude = new Vector(); Vector includeCoda = new Vector(); String trimSpaces = null; String poundAllowed = null; while (list.hasNext()) { element = (TreeNode) list.next(); String tname = element.getName(); if ("url-pattern".equals(tname)) urlPatterns.addElement(element.getBody()); else if ("page-encoding".equals(tname)) pageEncoding = element.getBody(); else if ("is-xml".equals(tname)) isXml = element.getBody(); else if ("el-ignored".equals(tname)) elIgnored = element.getBody(); else if ("scripting-invalid".equals(tname)) scriptingInvalid = element.getBody(); else if ("include-prelude".equals(tname)) includePrelude.addElement(element.getBody()); else if ("include-coda".equals(tname)) includeCoda.addElement(element.getBody()); else if ("trim-directive-whitespaces".equals(tname)) trimSpaces = element.getBody(); else if ("deferred-syntax-allowed-as-literal".equals(tname)) poundAllowed = element.getBody(); } if (urlPatterns.size() == 0) { continue; } makeJspPropertyGroups(jspProperties, urlPatterns, isXml, elIgnored, scriptingInvalid, trimSpaces, poundAllowed, pageEncoding, includePrelude, includeCoda); } } catch (Exception ex) { throw new JasperException(ex); } finally { if (is != null) { try { is.close(); } catch (Throwable t) { } } } }
From source file:org.toobsframework.transformpipeline.domain.BaseXMLTransformer.java
protected InputSource getInputSource(String xsl) throws TransformerException { StreamSource source = ((StreamSource) uriResolver.resolve(xsl + ".xsl", "")); InputSource iSource = new InputSource(source.getInputStream()); iSource.setSystemId(source.getSystemId()); return iSource; }
From source file:org.topazproject.xml.transform.CustomEntityResolver.java
/** * Resolve the specified entity using the configured <code>URLRetriever</code> (and any * of its delegates).//from ww w . j a v a 2 s . co m * * @param publicId The public identifier of the external entity being referenced, or null if * none was supplied. * @param systemId The system identifier of the external entity being referenced. * @return An InputSource object describing the new input source, or null to request that the * parser open a regular URI connection to the system identifier. * @throws IOException Indicates a problem retrieving the entity. */ public InputSource resolveEntity(String publicId, String systemId) throws IOException { if (log.isDebugEnabled()) log.debug("Resolving entity '" + systemId + "'"); byte[] res = retriever.retrieve(systemId, publicId); if (log.isDebugEnabled()) log.debug("Entity '" + systemId + "' " + (res != null ? "found" : "not found")); if (res == null) return null; InputSource is = new InputSource(new ByteArrayInputStream(res)); is.setPublicId(publicId); is.setSystemId(systemId); return is; }
From source file:org.tuckey.web.filters.urlrewrite.ConfHandler.java
private InputSource loadAstroboaPortalUrlRewriteRules(String systemId) { //Locate url rewrite rules URL urlRewriteRules = null;/*from w w w .ja v a 2 s . co m*/ try { urlRewriteRules = this.getClass().getClassLoader() .getResource(PortalStringConstants.ASTROBOA_URL_REWRITE_RULES_XML_FILENAME); if (urlRewriteRules == null) { log.error("Could not locate " + PortalStringConstants.ASTROBOA_URL_REWRITE_RULES_XML_FILENAME); return null; } InputSource is = new InputSource(urlRewriteRules.openStream()); is.setSystemId(urlRewriteRules.toString()); return is; } catch (Exception e) { log.error("A problem occured while locating astroboa-urlrewrite-rules.xml", e); return null; } }