Refine search
InputSource inputSource = entityResolver.resolveEntity( publicId, systemId); if (inputSource == null) { try { EntityParser entityParser = new EntityParser(encoding, xmlReader, pointer, inputSource.getPublicId(), inputSource.getSystemId());
/** * @param is * @throws SAXException * @throws IOException * @throws MalformedURLException */ private void tokenize(InputSource is) throws SAXException, IOException, MalformedURLException { if (is == null) { throw new IllegalArgumentException("Null input."); } if (is.getByteStream() == null && is.getCharacterStream() == null) { String systemId = is.getSystemId(); if (systemId == null) { throw new IllegalArgumentException("No byte stream, no character stream nor URI."); } if (entityResolver != null) { is = entityResolver.resolveEntity(is.getPublicId(), systemId); } if (is.getByteStream() == null || is.getCharacterStream() == null) { is = new InputSource(); is.setSystemId(systemId); is.setByteStream(new URL(systemId).openStream()); } } driver.tokenize(is); }
public Parser resolveEntity(String publicId, String systemId) throws SAXException, IOException { InputSource source = core.resolveEntity(publicId,systemId); if(source==null) return null; // default // ideally entity resolvers should be giving us the system ID for the resource // (or otherwise we won't be able to resolve references within this imported WSDL correctly), // but if none is given, the system ID before the entity resolution is better than nothing. if(source.getSystemId()!=null) systemId = source.getSystemId(); URL url = new URL(systemId); InputStream stream; if (useStreamFromEntityResolver) { stream = source.getByteStream(); } else { stream = url.openStream(); } return new Parser(url, new TidyXMLStreamReader(XMLStreamReaderFactory.create(url.toExternalForm(), stream, true), stream)); } }
/** * Parse a DTD. */ public void parse(String uri) throws IOException, SAXException { InputSource inSource; init(); // System.out.println ("parse (\"" + uri + "\")"); inSource = resolver.resolveEntity(null, uri); // If custom resolver punts resolution to parser, handle it ... if (inSource == null) { inSource = Resolver.createInputSource(new java.net.URL(uri), false); // ... or if custom resolver doesn't correctly construct the // input entity, patch it up enough so relative URIs work, and // issue a warning to minimize later confusion. } else if (inSource.getSystemId() == null) { warning("P-065", null); inSource.setSystemId(uri); } parseInternal(inSource); }
public InputSource getInputSource (EntityResolver r) throws IOException, SAXException { InputSource retval; retval = r.resolveEntity (publicId, systemId); // SAX sez if null is returned, use the URI directly if (retval == null) retval = Resolver.createInputSource (new URL (systemId), false); return retval; } }
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (BootstrapResolver.xmlCatalogPubId.equals(publicId) || BootstrapResolver.xmlCatalogSysId.equals(systemId)) { URL url = BootstrapResolver.class.getResource("/org/apache/xml/resolver/etc/catalog.dtd"); if (url != null) { InputSource in = new InputSource(url.toString()); // Avoid any weirdness the parser may perform on URLs in.setByteStream(url.openStream()); in.setPublicId(publicId); return in; } } if (entityResolver != null) return entityResolver.resolveEntity(publicId, systemId); return null; } }
URL url = new URL(baseURI); String ref = new URL(url, systemID).toExternalForm(); InputSource isrc = mEntityResolver.resolveEntity(publicID, ref); if (isrc != null) { InputStream in = isrc.getByteStream(); if (in != null) { return in; Reader r = isrc.getCharacterStream(); if (r != null) { return r;
try source = resolver.resolveEntity(namespace, absoluteURL); Reader reader = source.getCharacterStream(); if (reader != null) InputStream bytes = source.getByteStream(); if (bytes != null) String encoding = source.getEncoding(); XmlOptions options = new XmlOptions(); options.setLoadLineNumbers(); options.setLoadMessageDigest(); options.setDocumentSourceName(absoluteURL); URL urlDownload = new URL(urlToLoad); return loader.parse(urlDownload, null, options); options.setLoadLineNumbers(); options.setLoadMessageDigest(); URL urlDownload = new URL(absoluteURL);
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { InputSource source = super.resolveEntity(publicId, systemId); if (null == source && null != systemId) { // try the schema and dtd resolver in turn, ignoring the suffix in publicId LOG.log(Level.FINE, "Attempting to resolve systemId {0}", systemId); source = schemaResolver.resolveEntity(publicId, systemId); if (null == source) { source = dtdResolver.resolveEntity(publicId, systemId); } } String resourceLocation = schemaMappings.get(systemId); if (resourceLocation != null && publicId == null) { Resource resource = new ClassPathResource(resourceLocation, classLoader); if (resource != null && resource.exists()) { source.setPublicId(systemId); source.setSystemId(resource.getURL().toString()); } } return source; } }
/** * Delegate to {@link #entityResolver} if available. * * <p> * * <p>Note this is an XMLSchema based parser, all attempts to resolved DTDs are rejected. * * @param publicId The public identifier, or null if none is available. * @param systemId The system identifier provided in the XML document. * @return The new input source, or null to require the default behavior. * @exception java.io.IOException If there is an error setting up the new input source. * @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. */ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { // avoid dtd files if (systemId != null && systemId.endsWith("dtd")) { return new InputSource(new StringReader("")); } if (entityResolver != null) { return entityResolver.resolveEntity(publicId, systemId); } else { return super.resolveEntity(publicId, systemId); } } // hints
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { log.trace("Trying to locate XML entity {} as configuration points schema.", systemId); Schema schema = schemas.findSchema(systemId); if (schema == null) { if (defaultEntityResolver != null) { return defaultEntityResolver.resolveEntity(publicId, systemId); } else { return null; } } log.debug("Found XML schema for systemId {}: {}", systemId, schema); InputSource inputSource = new InputSource(schema.getInputStream()); inputSource.setPublicId(publicId); inputSource.setSystemId(systemId); return inputSource; } }
throw new IllegalStateException(); docBuilder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (systemId.endsWith("include.txt")) { return new InputSource(includeStream);
/** * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String) */ @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (systemId.startsWith(XHTML_PREFIX)) { String name = systemId.substring(XHTML_PREFIX.length()); //final InputStream resourceAsStream = getClass().getResourceAsStream(name); URL resource = getClass().getResource(name); if (resource != null) { InputSource inputSource = new InputSource(resource.toExternalForm()); inputSource.setPublicId(publicId); //inputSource.setByteStream(resourceAsStream); return inputSource; } } // Let file: URLs just get loaded using the default mechanism if (systemId.startsWith("file:") || systemId.startsWith("jar:")) { return null; } if (m_next != null) { return m_next.resolveEntity(publicId, systemId); } else { return null; } } }
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { int index = systemId.lastIndexOf('/'); String fileName = systemId.substring(index+1); String entity = entities.get(fileName); if(entity == null) { InputSource inputSource = delegate.resolveEntity(publicId, systemId); entity = IOUtils.toString(inputSource.getCharacterStream()); entities.put(fileName, entity); } return new InputSource(new StringReader(entity)); }
public Parser resolveEntity (String publicId, String systemId) throws IOException, XMLStreamException { if (systemId != null) { SDDocumentSource doc = metadata.get(systemId); if (doc != null) return new Parser(doc); synchronized(this) { while(origMetadata.hasNext()) { doc = origMetadata.next(); String extForm = doc.getSystemId().toExternalForm(); this.metadata.put(extForm,doc); if (systemId.equals(extForm)) return new Parser(doc); } } } if (resolver != null) { try { InputSource source = resolver.resolveEntity(publicId, systemId); if (source != null) { Parser p = new Parser(null, XMLStreamReaderFactory.create(source, true)); return p; } } catch (SAXException e) { throw new XMLStreamException(e); } } return null; }
protected boolean canResolveEntity(String publicId, String systemId) throws SAXException, IOException { final InputSource resolvedEntity = muleEntityResolver.resolveEntity(publicId, systemId); try { return resolvedEntity != null; } finally { if (resolvedEntity != null) { if (resolvedEntity.getByteStream() != null) { resolvedEntity.getByteStream().close(); } if (resolvedEntity.getCharacterStream() != null) { resolvedEntity.getCharacterStream().close(); } } } }
@Override @Nullable public InputSource resolveEntity(String publicId, @Nullable String systemId) throws SAXException, IOException { if (systemId != null) { if (systemId.endsWith(DTD_SUFFIX)) { return this.dtdResolver.resolveEntity(publicId, systemId); } else if (systemId.endsWith(XSD_SUFFIX)) { return this.schemaResolver.resolveEntity(publicId, systemId); } } return null; }
private static Schema getSchema(EntityResolver entityResolver) throws SAXException, IOException { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); if(entityResolver instanceof LocalXSDEntityResolver) { return schemaFactory.newSchema(((LocalXSDEntityResolver)entityResolver).getSchemaSources()); } return schemaFactory.newSchema(new StreamSource(entityResolver.resolveEntity("default", "default").getByteStream())); }
/** * Resolve the cache.xml XSD using the {@link PivotalEntityResolver}. Verifies that the * META-INF/schemas files are correctly found. * * @since GemFire 8.1 */ @Test public void testResolveEntity() throws Exception { final InputSource inputSource = getEntityResolver().resolveEntity(null, getSystemId()); assertNotNull(inputSource); assertEquals(getSystemId(), inputSource.getSystemId()); }
@Override public Reader getCharacterStream() { final Reader originalReader = inputSource.getCharacterStream(); if (originalReader == null) { return null; } else { try { InputSource resolvedEntity = this.entityResolver.resolveEntity( getPublicId(), getSystemId()); if (resolvedEntity != null) { return resolvedEntity.getCharacterStream(); } else { return originalReader; } } catch (IOException ioex) { return originalReader; } catch (SAXException saxex) { return originalReader; } } }