private static XMLEntityResolver getXmlEntityResolver(String encoding) { return new XMLEntityResolver() { public XMLInputSource resolveEntity(XMLResourceIdentifier arg) throws XNIException, IOException { URL url = new URL(arg.getExpandedSystemId()); return new XMLInputSource(arg.getPublicId(), arg.getExpandedSystemId(), arg.getExpandedSystemId(), url.openStream(), "UTF-8"); } }; } }
private XMLInputSource newInputSource( String replacementText ) { StringBuffer systemID = new StringBuffer( _systemID ); systemID.append( "script" ).append( ++_scriptIndex ); return new XMLInputSource( null, systemID.toString(), null, new StringReader( replacementText ), "UTF-8" ); }
private XMLInputSource newInputSource( String replacementText ) { StringBuffer systemID = new StringBuffer( _systemID ); systemID.append( "script" ).append( ++_scriptIndex ); return new XMLInputSource( null, systemID.toString(), null, new StringReader( replacementText ), "UTF-8" ); }
XMLInputSource convert(InputSource in) { Reader rdr = in.getCharacterStream(); InputStream str = in.getByteStream(); String publicID = in.getPublicId(); String systemID = in.getSystemId(); if (rdr == null && str == null) { return new XMLInputSource(publicID, systemID, systemID); } else if (rdr == null) { return new XMLInputSource(publicID, systemID, systemID, str, null); } else if (str == null) { return new XMLInputSource(publicID, systemID, systemID, rdr, null); } return null; } boolean parseSome() {
private XMLInputSource newInputSource( String replacementText ) { StringBuffer systemID = new StringBuffer( _systemID ); systemID.append( "script" ).append( ++_scriptIndex ); return new XMLInputSource( null, systemID.toString(), null, new StringReader( replacementText ), "UTF-8" ); }
private static XMLInputSource saxToXMLInputSource(InputSource sis) { String publicId = sis.getPublicId(); String systemId = sis.getSystemId(); Reader charStream = sis.getCharacterStream(); if (charStream != null) { return new XMLInputSource(publicId, systemId, null, charStream, null); } InputStream byteStream = sis.getByteStream(); if (byteStream != null) { return new XMLInputSource(publicId, systemId, null, byteStream, sis.getEncoding()); } return new XMLInputSource(publicId, systemId, null); }
/** * Validates the specified XML instance document according to the contained schema references ( * <code>xsi:schemaLocation</code> attribute) and/or to the explicitly specified schema references. * * @param source * provides the XML document to be validated, must not be null * @param schemaUris * URIs of schema documents to be considered, can be null (only the <code>xsi:schemaLocation</code> * attribute is considered then) * @return list of validation events (errors/warnings) that occured, never null, size of 0 means valid document */ public static List<SchemaValidationEvent> validate( InputStream source, String... schemaUris ) { return validate( new XMLInputSource( null, null, null, source, null ), schemaUris ); }
private Grammar getGrammar(String urlString) throws Exception { URL url = new URL(urlString); InputStream in = url.openStream(); return getGrammarParser().preparseGrammar("http://www.w3.org/TR/REC-xml", new XMLInputSource(urlString, urlString, urlString, in, null)); }
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException { XMLInputSource src = new XMLInputSource(resourceIdentifier); String resourceName = resourceIdentifier.getLiteralSystemId(); String base; try { base = new URI(FileUtils.encodePath(resourceIdentifier.getBaseSystemId())).toURL().getFile(); } catch (URISyntaxException e) { throw new RuntimeException("Base system id incorrect, parser error", e); } if (new File(new File(base).getParent(), resourceName).exists()) src.setByteStream(new File(new File(base).getParent(), resourceName).toURL().openStream()); else src.setByteStream(new File(_docRoot, resourceName).toURL().openStream()); return src; } }
@Override public XMLInputSource resolveEntity( XMLResourceIdentifier identifier ) throws XNIException, IOException { String systemId = identifier.getExpandedSystemId(); String redirectedSystemId = systemId != null ? redirect( systemId ) : null; LOG.debug( "'" + systemId + "' -> '" + redirectedSystemId + "'" ); return new XMLInputSource( null, redirectedSystemId, null ); }
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException { XMLInputSource src = new XMLInputSource(resourceIdentifier); String resourceName = resourceIdentifier.getLiteralSystemId(); String base; try { base = new URI(FileUtils.encodePath(resourceIdentifier.getBaseSystemId())).toURL().getFile(); } catch (URISyntaxException e) { throw new RuntimeException("Base system id incorrect, parser error", e); } if (new File(new File(base).getParent(), resourceName).exists()) src.setByteStream(new File(new File(base).getParent(), resourceName).toURL().openStream()); else src.setByteStream(new File(_docRoot, resourceName).toURL().openStream()); return src; } }
@Override public void endElement(QName element, Augmentations augs) throws XNIException { if (currentOsmlTag != null && "script".equalsIgnoreCase(element.rawname)) { QName endingTag = currentOsmlTag; currentOsmlTag = null; XMLInputSource scriptSource = new XMLInputSource(null, null, null); scriptSource.setCharacterStream(new StringReader(scriptContent.toString())); scriptContent.setLength(0); // Evaluate the content of the script block immediately scanner.evaluateInputSource(scriptSource); super.endElement(endingTag, augs); } else { super.endElement(element, augs); } }
@Override public void endElement(QName element, Augmentations augs) throws XNIException { if (currentOsmlTag != null && "script".equalsIgnoreCase(element.rawname)) { QName endingTag = currentOsmlTag; currentOsmlTag = null; XMLInputSource scriptSource = new XMLInputSource(null, null, null); scriptSource.setCharacterStream(new StringReader(scriptContent.toString())); scriptContent.setLength(0); // Evaluate the content of the script block immediately scanner.evaluateInputSource(scriptSource); super.endElement(endingTag, augs); } else { super.endElement(element, augs); } }
private XMLInputSource getXMLInputSource(InputSource inputSource, XMLResourceIdentifier resId) throws IOException { String encoding = inputSource.getEncoding(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copyStream(baos, inputSource.getByteStream()); // [JBWS-2325] InputStream is = new ByteArrayInputStream(baos.toByteArray()); return new XMLInputSource(resId.getPublicId(), resId.getExpandedSystemId(), resId.getBaseSystemId(), is, encoding); } }
public XMLInputSource resolveEntity(XMLResourceIdentifier arg) throws XNIException, IOException { URL url = new URL(arg.getExpandedSystemId()); return new XMLInputSource(arg.getPublicId(), arg.getExpandedSystemId(), arg.getExpandedSystemId(), url.openStream(), "UTF-8"); } };
private static XMLInputSource toXMLInputSource(InputSource in) { XMLInputSource xin = new XMLInputSource(in.getPublicId(), in.getSystemId(), null); xin.setByteStream(in.getByteStream()); xin.setCharacterStream(in.getCharacterStream()); xin.setEncoding(in.getEncoding()); return xin; } }
private static XMLInputSource toXMLInputSource(InputSource in) { XMLInputSource xin = new XMLInputSource(in.getPublicId(), in.getSystemId(), null); xin.setByteStream(in.getByteStream()); xin.setCharacterStream(in.getCharacterStream()); xin.setEncoding(in.getEncoding()); return xin; } }
public XSModel loadURI(String uri) { try { Grammar g = loadGrammar(new XMLInputSource(null, uri, null)); return ((XSGrammar)g).toXSModel(); } catch (Exception e){ reportDOMFatalError(e); return null; } }
@Override public XMLInputSource resolveEntity(XMLResourceIdentifier id) throws XNIException, IOException { String systemId = id.getLiteralSystemId(); debug("Resolving " + systemId); XMLInputSource source = new XMLInputSource(id); source.setByteStream(resolver.getStream(systemId)); return source; } }
public XSModel loadURIList(StringList uriList) { int length = uriList.getLength(); SchemaGrammar[] gs = new SchemaGrammar[length]; for (int i = 0; i < length; i++) { try { gs[i] = (SchemaGrammar) loadGrammar(new XMLInputSource(null, uriList.item(i), null)); } catch (Exception e) { reportDOMFatalError(e); return null; } } return new XSModelImpl(gs); }