下面列出了org.xml.sax.InputSource#getSystemId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void parse(InputSource input) throws IOException, SAXException {
try {
InputStream s = input.getByteStream();
if (s == null) {
String systemId = input.getSystemId();
if (systemId == null) {
throw new SAXException(CommonResourceBundle.getInstance().getString("message.inputSource"));
}
parse(systemId);
} else {
parse(s);
}
} catch (FastInfosetException e) {
logger.log(Level.FINE, "parsing error", e);
throw new SAXException(e);
}
}
/**
* Creates an XMLInputSource from a SAX InputSource.
*/
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {
String publicId = source.getPublicId();
String systemId = source.getSystemId();
String baseSystemId = baseURI;
InputStream byteStream = source.getByteStream();
Reader charStream = source.getCharacterStream();
String encoding = source.getEncoding();
XMLInputSource xmlInputSource =
new XMLInputSource(publicId, systemId, baseSystemId);
xmlInputSource.setByteStream(byteStream);
xmlInputSource.setCharacterStream(charStream);
xmlInputSource.setEncoding(encoding);
return xmlInputSource;
}
public void parse(
InputSource source,
ContentHandler contentHandler,
ErrorHandler errorHandler,
EntityResolver entityResolver )
throws SAXException, IOException {
String systemId = source.getSystemId();
Document dom = forest.get(systemId);
if(dom==null) {
// if no DOM tree is built for it,
// let the fall back parser parse the original document.
//
// for example, XSOM parses datatypes.xsd (XML Schema part 2)
// but this will never be built into the forest.
fallbackParser.parse( source, contentHandler, errorHandler, entityResolver );
return;
}
scanner.scan( dom, contentHandler );
}
/**
* Parse a DTD.
*/
public void parse(String uri)
throws IOException, SAXException {
InputSource in;
init();
// System.out.println ("parse (\"" + uri + "\")");
in = resolver.resolveEntity(null, uri);
// If custom resolver punts resolution to parser, handle it ...
if (in == null) {
in = 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 (in.getSystemId() == null) {
warning("P-065", null);
in.setSystemId(uri);
}
parseInternal(in);
}
/**
Configure log4j by reading in a log4j.dtd compliant XML
configuration file.
*/
protected
void doConfigure(final InputSource inputSource, LoggerRepository repository)
throws FactoryConfigurationError {
if (inputSource.getSystemId() == null) {
inputSource.setSystemId("dummy://log4j.dtd");
}
ParseAction action = new ParseAction() {
public Document parse(final DocumentBuilder parser) throws SAXException, IOException {
return parser.parse(inputSource);
}
public String toString() {
return "input source [" + inputSource.toString() + "]";
}
};
doConfigure(action, repository);
}
/**
* Creates an XMLInputSource from a SAX InputSource.
*/
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {
String publicId = source.getPublicId();
String systemId = source.getSystemId();
String baseSystemId = baseURI;
InputStream byteStream = source.getByteStream();
Reader charStream = source.getCharacterStream();
String encoding = source.getEncoding();
XMLInputSource xmlInputSource =
new XMLInputSource(publicId, systemId, baseSystemId);
xmlInputSource.setByteStream(byteStream);
xmlInputSource.setCharacterStream(charStream);
xmlInputSource.setEncoding(encoding);
return xmlInputSource;
}
public void parse(InputSource input) throws IOException, SAXException {
try {
InputStream s = input.getByteStream();
if (s == null) {
String systemId = input.getSystemId();
if (systemId == null) {
throw new SAXException(CommonResourceBundle.getInstance().getString("message.inputSource"));
}
parse(systemId);
} else {
parse(s);
}
} catch (FastInfosetException e) {
logger.log(Level.FINE, "parsing error", e);
throw new SAXException(e);
}
}
public void parse(InputSource source, ContentHandler handler, ErrorHandler errorHandler, EntityResolver entityResolver)
throws SAXException, IOException {
String systemId = source.getSystemId();
Document dom = forest.get(systemId);
if (dom == null) {
// if no DOM tree is built for it,
// let the fall back parser parse the original document.
//
// for example, XSOM parses datatypes.xsd (XML Schema part 2)
// but this will never be built into the forest.
fallbackParser.parse(source, handler, errorHandler, entityResolver);
return;
}
scanner.scan(dom, handler);
}
/**
* Parse a DTD.
*/
public void parse(String uri)
throws IOException, SAXException {
InputSource in;
init();
// System.out.println ("parse (\"" + uri + "\")");
in = resolver.resolveEntity(null, uri);
// If custom resolver punts resolution to parser, handle it ...
if (in == null) {
in = 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 (in.getSystemId() == null) {
warning("P-065", null);
in.setSystemId(uri);
}
parseInternal(in);
}
public static FileObject toFileObject(InputSource src) {
try {
String sysId = src.getSystemId();
return FileUtil.toFileObject(new File(new URI(sysId)));
} catch (URISyntaxException ex) {
LOG.log(Level.WARNING, "File URI malformed", ex);
return null;
}
}
public SAXInputSource(XMLReader reader, InputSource inputSource) {
super(inputSource != null ? inputSource.getPublicId() : null,
inputSource != null ? inputSource.getSystemId() : null, null);
if (inputSource != null) {
setByteStream(inputSource.getByteStream());
setCharacterStream(inputSource.getCharacterStream());
setEncoding(inputSource.getEncoding());
}
fInputSource = inputSource;
fXMLReader = reader;
}
public static void setSystemId(InputSource inputSource, URL contextUrl, String input) {
if (inputSource.getSystemId() == null) {
String systemId = XmlUtils.getSystemId(contextUrl, input);
if (systemId != null) {
inputSource.setSystemId(systemId);
}
}
}
private boolean parseSomeSetup(InputSource source)
throws SAXException, IOException, IllegalAccessException,
java.lang.reflect.InvocationTargetException,
java.lang.InstantiationException
{
if(fConfigSetInput!=null)
{
// Obtain input from SAX inputSource object, construct XNI version of
// that object. Logic adapted from Xerces2.
Object[] parms1={source.getPublicId(),source.getSystemId(),null};
Object xmlsource=fConfigInputSourceCtor.newInstance(parms1);
Object[] parmsa={source.getByteStream()};
fConfigSetByteStream.invoke(xmlsource,parmsa);
parmsa[0]=source.getCharacterStream();
fConfigSetCharStream.invoke(xmlsource,parmsa);
parmsa[0]=source.getEncoding();
fConfigSetEncoding.invoke(xmlsource,parmsa);
// Bugzilla5272 patch suggested by Sandy Gao.
// Has to be reflection to run with Xerces2
// after compilation against Xerces1. or vice
// versa, due to return type mismatches.
Object[] noparms=new Object[0];
fReset.invoke(fIncrementalParser,noparms);
parmsa[0]=xmlsource;
fConfigSetInput.invoke(fPullParserConfig,parmsa);
// %REVIEW% Do first pull. Should we instead just return true?
return parseSome();
}
else
{
Object[] parm={source};
Object ret=fParseSomeSetup.invoke(fIncrementalParser,parm);
return ((Boolean)ret).booleanValue();
}
}
/**
* Loads a configuration file from the specified input source.
*
* @param source the input source
* @throws ConfigurationException if an error occurs
*/
private void load(final InputSource source) throws ConfigurationException
{
if (locator == null)
{
throw new ConfigurationException("Load operation not properly "
+ "initialized! Do not call read(InputStream) directly,"
+ " but use a FileHandler to load a configuration.");
}
try
{
final URL sourceURL = locator.getSourceURL();
if (sourceURL != null)
{
source.setSystemId(sourceURL.toString());
}
final DocumentBuilder builder = createDocumentBuilder();
final Document newDocument = builder.parse(source);
final Document oldDocument = getDocument();
initProperties(XMLDocumentHelper.forSourceDocument(newDocument),
oldDocument == null);
}
catch (final SAXParseException spe)
{
throw new ConfigurationException("Error parsing " + source.getSystemId(), spe);
}
catch (final Exception e)
{
this.getLogger().debug("Unable to load the configuration: " + e);
throw new ConfigurationException("Unable to load the configuration", e);
}
}
public InputSource getBaseInputSource() {
InputSource is = parent.getBaseInputSource();
fromParent = true;
if (is == null) {
is = getInputSource();
fromParent = false;
} else {
baseUri = is.getSystemId();
}
last = is;
return is;
}
/**
* Constructs an input source from a SAX InputSource
* object.
*
* @param inputSource a SAX InputSource
* @param isCreatedByResolver a flag to indicate whether the source is
* created by a resolver
*/
public XMLInputSource(InputSource inputSource, boolean isCreatedByResolver) {
fPublicId = inputSource.getPublicId();
fSystemId = inputSource.getSystemId();
fByteStream = inputSource.getByteStream();
fCharStream = inputSource.getCharacterStream();
fEncoding = inputSource.getEncoding();
fIsCreatedByResolver = isCreatedByResolver;
}
public SAXInputSource(XMLReader reader, InputSource inputSource) {
super(inputSource != null ? inputSource.getPublicId() : null,
inputSource != null ? inputSource.getSystemId() : null, null);
if (inputSource != null) {
setByteStream(inputSource.getByteStream());
setCharacterStream(inputSource.getCharacterStream());
setEncoding(inputSource.getEncoding());
}
fInputSource = inputSource;
fXMLReader = reader;
}
private boolean parseSomeSetup(InputSource source)
throws SAXException, IOException, IllegalAccessException,
java.lang.reflect.InvocationTargetException,
java.lang.InstantiationException
{
if(fConfigSetInput!=null)
{
// Obtain input from SAX inputSource object, construct XNI version of
// that object. Logic adapted from Xerces2.
Object[] parms1={source.getPublicId(),source.getSystemId(),null};
Object xmlsource=fConfigInputSourceCtor.newInstance(parms1);
Object[] parmsa={source.getByteStream()};
fConfigSetByteStream.invoke(xmlsource,parmsa);
parmsa[0]=source.getCharacterStream();
fConfigSetCharStream.invoke(xmlsource,parmsa);
parmsa[0]=source.getEncoding();
fConfigSetEncoding.invoke(xmlsource,parmsa);
// Bugzilla5272 patch suggested by Sandy Gao.
// Has to be reflection to run with Xerces2
// after compilation against Xerces1. or vice
// versa, due to return type mismatches.
Object[] noparms=new Object[0];
fReset.invoke(fIncrementalParser,noparms);
parmsa[0]=xmlsource;
fConfigSetInput.invoke(fPullParserConfig,parmsa);
// %REVIEW% Do first pull. Should we instead just return true?
return parseSome();
}
else
{
Object[] parm={source};
Object ret=fParseSomeSetup.invoke(fIncrementalParser,parm);
return ((Boolean)ret).booleanValue();
}
}
private boolean parseSomeSetup(InputSource source)
throws SAXException, IOException, IllegalAccessException,
java.lang.reflect.InvocationTargetException,
java.lang.InstantiationException
{
if(fConfigSetInput!=null)
{
// Obtain input from SAX inputSource object, construct XNI version of
// that object. Logic adapted from Xerces2.
Object[] parms1={source.getPublicId(),source.getSystemId(),null};
Object xmlsource=fConfigInputSourceCtor.newInstance(parms1);
Object[] parmsa={source.getByteStream()};
fConfigSetByteStream.invoke(xmlsource,parmsa);
parmsa[0]=source.getCharacterStream();
fConfigSetCharStream.invoke(xmlsource,parmsa);
parmsa[0]=source.getEncoding();
fConfigSetEncoding.invoke(xmlsource,parmsa);
// Bugzilla5272 patch suggested by Sandy Gao.
// Has to be reflection to run with Xerces2
// after compilation against Xerces1. or vice
// versa, due to return type mismatches.
Object[] noparms=new Object[0];
fReset.invoke(fIncrementalParser,noparms);
parmsa[0]=xmlsource;
fConfigSetInput.invoke(fPullParserConfig,parmsa);
// %REVIEW% Do first pull. Should we instead just return true?
return parseSome();
}
else
{
Object[] parm={source};
Object ret=fParseSomeSetup.invoke(fIncrementalParser,parm);
return ((Boolean)ret).booleanValue();
}
}
private InputSource resolvedEntity(InputSource entity) {
String msg = "Resolved to: " + entity.getSystemId() + ".";
LOGGER.debug(msg);
return entity;
}