下面列出了org.xml.sax.SAXException#getException ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Creates an UnmarshalException from a SAXException.
*
* This is an utility method provided for the derived classes.
*
* <p>
* When a provider-implemented ContentHandler wants to throw a
* JAXBException, it needs to wrap the exception by a SAXException.
* If the unmarshaller implementation blindly wrap SAXException
* by JAXBException, such an exception will be a JAXBException
* wrapped by a SAXException wrapped by another JAXBException.
* This is silly.
*
* <p>
* This method checks the nested exception of SAXException
* and reduce those excessive wrapping.
*
* @return the resulting UnmarshalException
*/
protected UnmarshalException createUnmarshalException( SAXException e ) {
// check the nested exception to see if it's an UnmarshalException
Exception nested = e.getException();
if(nested instanceof UnmarshalException)
return (UnmarshalException)nested;
if(nested instanceof RuntimeException)
// typically this is an unexpected exception,
// just throw it rather than wrap it, so that the full stack
// trace can be displayed.
throw (RuntimeException)nested;
// otherwise simply wrap it
if(nested!=null)
return new UnmarshalException(nested);
else
return new UnmarshalException(e);
}
public ScriptDocument(String name, InputStream input)
{
_name = name;
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
_document = builder.parse( input );
} catch (SAXException sxe) {
// Error generated during parsing)
Exception x = sxe;
if (sxe.getException() != null)
x = sxe.getException();
x.printStackTrace();
} catch (ParserConfigurationException pce) {
// Parser with specified options can't be built
pce.printStackTrace();
} catch (IOException ioe) {
// I/O error
ioe.printStackTrace();
}
}
public ParserContext( XSOMParser owner, XMLParser parser ) {
this.owner = owner;
this.parser = parser;
try {
parse(new InputSource(ParserContext.class.getResource("datatypes.xsd").toExternalForm()));
SchemaImpl xs = (SchemaImpl)
schemaSet.getSchema("http://www.w3.org/2001/XMLSchema");
xs.addSimpleType(schemaSet.anySimpleType,true);
xs.addComplexType(schemaSet.anyType,true);
} catch( SAXException e ) {
// this must be a bug of XSOM
if(e.getException()!=null)
e.getException().printStackTrace();
else
e.printStackTrace();
throw new InternalError();
}
}
/**
* Creates an UnmarshalException from a SAXException.
*
* This is an utility method provided for the derived classes.
*
* <p>
* When a provider-implemented ContentHandler wants to throw a
* JAXBException, it needs to wrap the exception by a SAXException.
* If the unmarshaller implementation blindly wrap SAXException
* by JAXBException, such an exception will be a JAXBException
* wrapped by a SAXException wrapped by another JAXBException.
* This is silly.
*
* <p>
* This method checks the nested exception of SAXException
* and reduce those excessive wrapping.
*
* @return the resulting UnmarshalException
*/
protected UnmarshalException createUnmarshalException( SAXException e ) {
// check the nested exception to see if it's an UnmarshalException
Exception nested = e.getException();
if(nested instanceof UnmarshalException)
return (UnmarshalException)nested;
if(nested instanceof RuntimeException)
// typically this is an unexpected exception,
// just throw it rather than wrap it, so that the full stack
// trace can be displayed.
throw (RuntimeException)nested;
// otherwise simply wrap it
if(nested!=null)
return new UnmarshalException(nested);
else
return new UnmarshalException(e);
}
/**
* Creates an UnmarshalException from a SAXException.
*
* This is an utility method provided for the derived classes.
*
* <p>
* When a provider-implemented ContentHandler wants to throw a
* JAXBException, it needs to wrap the exception by a SAXException.
* If the unmarshaller implementation blindly wrap SAXException
* by JAXBException, such an exception will be a JAXBException
* wrapped by a SAXException wrapped by another JAXBException.
* This is silly.
*
* <p>
* This method checks the nested exception of SAXException
* and reduce those excessive wrapping.
*
* @return the resulting UnmarshalException
*/
protected UnmarshalException createUnmarshalException( SAXException e ) {
// check the nested exception to see if it's an UnmarshalException
Exception nested = e.getException();
if(nested instanceof UnmarshalException)
return (UnmarshalException)nested;
if(nested instanceof RuntimeException)
// typically this is an unexpected exception,
// just throw it rather than wrap it, so that the full stack
// trace can be displayed.
throw (RuntimeException)nested;
// otherwise simply wrap it
if(nested!=null)
return new UnmarshalException(nested);
else
return new UnmarshalException(e);
}
/**
* Creates an UnmarshalException from a SAXException.
*
* This is an utility method provided for the derived classes.
*
* <p>
* When a provider-implemented ContentHandler wants to throw a
* JAXBException, it needs to wrap the exception by a SAXException.
* If the unmarshaller implementation blindly wrap SAXException
* by JAXBException, such an exception will be a JAXBException
* wrapped by a SAXException wrapped by another JAXBException.
* This is silly.
*
* <p>
* This method checks the nested exception of SAXException
* and reduce those excessive wrapping.
*
* @return the resulting UnmarshalException
*/
protected UnmarshalException createUnmarshalException( SAXException e ) {
// check the nested exception to see if it's an UnmarshalException
Exception nested = e.getException();
if(nested instanceof UnmarshalException)
return (UnmarshalException)nested;
if(nested instanceof RuntimeException)
// typically this is an unexpected exception,
// just throw it rather than wrap it, so that the full stack
// trace can be displayed.
throw (RuntimeException)nested;
// otherwise simply wrap it
if(nested!=null)
return new UnmarshalException(nested);
else
return new UnmarshalException(e);
}
/**
* Parses a set of styles from <code>inputStream</code>, adding the
* resulting styles to the passed in DefaultSynthStyleFactory.
* Resources are resolved either from a URL or from a Class. When calling
* this method, one of the URL or the Class must be null but not both at
* the same time.
*
* @param inputStream XML document containing the styles to read
* @param factory DefaultSynthStyleFactory that new styles are added to
* @param urlResourceBase the URL used to resolve any resources, such as Images
* @param classResourceBase the Class used to resolve any resources, such as Images
* @param defaultsMap Map that UIDefaults properties are placed in
*/
public void parse(InputStream inputStream,
DefaultSynthStyleFactory factory,
URL urlResourceBase, Class<?> classResourceBase,
Map<String, Object> defaultsMap)
throws ParseException, IllegalArgumentException {
if (inputStream == null || factory == null ||
(urlResourceBase == null && classResourceBase == null)) {
throw new IllegalArgumentException(
"You must supply an InputStream, StyleFactory and Class or URL");
}
assert(!(urlResourceBase != null && classResourceBase != null));
_factory = factory;
_classResourceBase = classResourceBase;
_urlResourceBase = urlResourceBase;
_defaultsMap = defaultsMap;
try {
try {
SAXParser saxParser = SAXParserFactory.newInstance().
newSAXParser();
saxParser.parse(new BufferedInputStream(inputStream), this);
} catch (ParserConfigurationException e) {
throw new ParseException("Error parsing: " + e, 0);
}
catch (SAXException se) {
throw new ParseException("Error parsing: " + se + " " +
se.getException(), 0);
}
catch (IOException ioe) {
throw new ParseException("Error parsing: " + ioe, 0);
}
} finally {
reset();
}
}
public void parseFile(String filePath) {
initPart();
fileName = new File(filePath).getName();
initSingletonId(filePath);
String myerror = "";
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
SAXParser parser = factory.newSAXParser();
InputSource inp = new InputSource (new FileReader(filePath));
parser.parse(inp, this);
/*
System.out.println("eventTermArrayList.size(); = " + eventTermArrayList.size());
System.out.println("timeLinks = " + timeLinks.size());
System.out.println("locationLinks = " + locationLinks.size());
System.out.println("plotLinks = " + plotLinks.size());
*/
} catch (SAXParseException err) {
myerror = "\n** Parsing error" + ", line " + err.getLineNumber()
+ ", uri " + err.getSystemId();
myerror += "\n" + err.getMessage();
System.out.println("myerror = " + myerror);
} catch (SAXException e) {
Exception x = e;
if (e.getException() != null)
x = e.getException();
myerror += "\nSAXException --" + x.getMessage();
System.out.println("myerror = " + myerror);
} catch (Exception eee) {
eee.printStackTrace();
myerror += "\nException --" + eee.getMessage();
System.out.println("myerror = " + myerror);
}
//System.out.println("myerror = " + myerror);
}
public MockIndicatorCriteriaDAO(String filename)
{
try
{
userRoleDAO = new MockUserRoleDAO(filename);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
theFile = docBuilder.parse (new File(filename));
NodeList indicatorCriteriaNodes = theFile.getElementsByTagName("indicator-criteria");
//force a nested load of everything
loadIndicatorCriteriasFromNodeList(indicatorCriteriaNodes);
}
catch (SAXParseException err)
{
log.debug ("** Parsing error" + ", line "
+ err.getLineNumber () + ", uri " + err.getSystemId ());
log.debug(" " + err.getMessage ());
}
catch (SAXException se)
{
Exception x = se.getException ();
((x == null) ? se : x).printStackTrace ();
}
catch (Exception e)
{
log.debug(e.getClass().getName() + ": " + e.getMessage ());
}
}
/**
* <p>Locates an external subset for documents which do not explicitly
* provide one. If no external subset is provided, this method should
* return <code>null</code>.</p>
*
* @param grammarDescription a description of the DTD
*
* @throws XNIException Thrown on general error.
* @throws IOException Thrown if resolved entity stream cannot be
* opened or some other i/o error occurs.
*/
public XMLInputSource getExternalSubset(XMLDTDDescription grammarDescription)
throws XNIException, IOException {
if (fEntityResolver != null) {
String name = grammarDescription.getRootName();
String baseURI = grammarDescription.getBaseSystemId();
// Resolve using EntityResolver2
try {
InputSource inputSource = fEntityResolver.getExternalSubset(name, baseURI);
return (inputSource != null) ? createXMLInputSource(inputSource, baseURI) : null;
}
// error resolving external subset
catch (SAXException e) {
Exception ex = e.getException();
if (ex == null) {
ex = e;
}
throw new XNIException(ex);
}
}
// unable to resolve external subset
return null;
}
/**
* <p>Locates an external subset for documents which do not explicitly
* provide one. If no external subset is provided, this method should
* return <code>null</code>.</p>
*
* @param grammarDescription a description of the DTD
*
* @throws XNIException Thrown on general error.
* @throws IOException Thrown if resolved entity stream cannot be
* opened or some other i/o error occurs.
*/
public XMLInputSource getExternalSubset(XMLDTDDescription grammarDescription)
throws XNIException, IOException {
if (fEntityResolver != null) {
String name = grammarDescription.getRootName();
String baseURI = grammarDescription.getBaseSystemId();
// Resolve using EntityResolver2
try {
InputSource inputSource = fEntityResolver.getExternalSubset(name, baseURI);
return (inputSource != null) ? createXMLInputSource(inputSource, baseURI) : null;
}
// error resolving external subset
catch (SAXException e) {
Exception ex = e.getException();
if (ex == null) {
ex = e;
}
throw new XNIException(ex);
}
}
// unable to resolve external subset
return null;
}
protected final void addStart(final String name, final Attributes attrs) {
try {
h.startElement("", name, name, attrs);
} catch (SAXException ex) {
throw new RuntimeException(ex.getMessage(), ex.getException());
}
}
/**
* <p>Locates an external subset for documents which do not explicitly
* provide one. If no external subset is provided, this method should
* return <code>null</code>.</p>
*
* @param grammarDescription a description of the DTD
*
* @throws XNIException Thrown on general error.
* @throws IOException Thrown if resolved entity stream cannot be
* opened or some other i/o error occurs.
*/
public XMLInputSource getExternalSubset(XMLDTDDescription grammarDescription)
throws XNIException, IOException {
if (fEntityResolver != null) {
String name = grammarDescription.getRootName();
String baseURI = grammarDescription.getBaseSystemId();
// Resolve using EntityResolver2
try {
InputSource inputSource = fEntityResolver.getExternalSubset(name, baseURI);
return (inputSource != null) ? createXMLInputSource(inputSource, baseURI) : null;
}
// error resolving external subset
catch (SAXException e) {
Exception ex = e.getException();
if (ex == null) {
ex = e;
}
throw new XNIException(ex);
}
}
// unable to resolve external subset
return null;
}
protected void addDocumentEnd() {
try {
h.endDocument();
} catch (SAXException ex) {
throw new RuntimeException(ex.getMessage(), ex.getException());
}
}
public CQL2XServerFindCommand() {
// initialize stack
cqlStack = new java.util.Stack();
// initialize SAX Parser
SAXParserFactory factory;
factory = SAXParserFactory.newInstance();
factory.setNamespaceAware( true );
try {
saxParser = factory.newSAXParser();
} catch (SAXException sxe) {
// Error generated by this application
// (or a parser-initialization error)
Exception x = sxe;
if (sxe.getException() != null) {
x = sxe.getException();
}
log.warn( "CQL2XServerFindCommand() SAX exception: " + sxe.getMessage(),
x );
} catch (ParserConfigurationException pce) {
// Parser with specified options can't be built
log.warn( "CQL2XServerFindCommand() SAX parser cannot be built with " +
"specified options" );
}
}
public MockTargetDAO(String filename)
{
factory.setProfileManager(new MockProfileManager(filename));
userRoleDAO = new MockUserRoleDAO(filename);
annotationDAO = new MockAnnotationDAO(filename);
siteDAO = new MockSiteDAO(filename);
try
{
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
theFile = docBuilder.parse (new File(filename));
NodeList profileNodes = theFile.getElementsByTagName("profile");
NodeList targetNodes = theFile.getElementsByTagName("target");
NodeList groupNodes = theFile.getElementsByTagName("group");
NodeList groupMemberNodes = theFile.getElementsByTagName("group-member");
//force a nested load of everything
loadProfilesFromNodeList(profileNodes);
loadTargetsFromNodeList(targetNodes);
loadGroupsFromNodeList(groupNodes);
loadGroupMembersFromNodeList(groupMemberNodes);
}
catch (SAXParseException err)
{
log.debug ("** Parsing error" + ", line "
+ err.getLineNumber () + ", uri " + err.getSystemId ());
log.debug(" " + err.getMessage ());
}
catch (SAXException se)
{
Exception x = se.getException ();
((x == null) ? se : x).printStackTrace ();
}
catch (Exception e)
{
log.debug(e.getClass().getName() + ": " + e.getMessage ());
}
}
/**
* Resolves an external parsed entity. If the entity cannot be
* resolved, this method should return null.
*
* @param resourceIdentifier contains the physical co-ordinates of the resource to be resolved
*
* @throws XNIException Thrown on general error.
* @throws IOException Thrown if resolved entity stream cannot be
* opened or some other i/o error occurs.
*/
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
throws XNIException, IOException {
// When both pubId and sysId are null, the user's entity resolver
// can do nothing about it. We'd better not bother calling it.
// This happens when the resourceIdentifier is a GrammarDescription,
// which describes a schema grammar of some namespace, but without
// any schema location hint. -Sg
String pubId = resourceIdentifier.getPublicId();
String sysId = resourceIdentifier.getExpandedSystemId();
if (pubId == null && sysId == null)
return null;
// resolve entity using SAX entity resolver
if (fEntityResolver != null && resourceIdentifier != null) {
try {
InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
if (inputSource != null) {
String publicId = inputSource.getPublicId();
String systemId = inputSource.getSystemId();
String baseSystemId = resourceIdentifier.getBaseSystemId();
InputStream byteStream = inputSource.getByteStream();
Reader charStream = inputSource.getCharacterStream();
String encoding = inputSource.getEncoding();
XMLInputSource xmlInputSource =
new XMLInputSource(publicId, systemId, baseSystemId);
xmlInputSource.setByteStream(byteStream);
xmlInputSource.setCharacterStream(charStream);
xmlInputSource.setEncoding(encoding);
return xmlInputSource;
}
}
// error resolving entity
catch (SAXException e) {
Exception ex = e.getException();
if (ex == null) {
ex = e;
}
throw new XNIException(ex);
}
}
// unable to resolve entity
return null;
}
/**
* Resolves an external parsed entity. If the entity cannot be
* resolved, this method should return null.
*
* @param resourceIdentifier contains the physical co-ordinates of the resource to be resolved
*
* @throws XNIException Thrown on general error.
* @throws IOException Thrown if resolved entity stream cannot be
* opened or some other i/o error occurs.
*/
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
throws XNIException, IOException {
if (fEntityResolver != null) {
String pubId = resourceIdentifier.getPublicId();
String sysId = resourceIdentifier.getLiteralSystemId();
String baseURI = resourceIdentifier.getBaseSystemId();
String name = null;
if (resourceIdentifier instanceof XMLDTDDescription) {
name = "[dtd]";
}
else if (resourceIdentifier instanceof XMLEntityDescription) {
name = ((XMLEntityDescription) resourceIdentifier).getEntityName();
}
// When both pubId and sysId are null, the user's entity resolver
// can do nothing about it. We'd better not bother calling it.
// This happens when the resourceIdentifier is a GrammarDescription,
// which describes a schema grammar of some namespace, but without
// any schema location hint. -Sg
if (pubId == null && sysId == null) {
return null;
}
// Resolve using EntityResolver2
try {
InputSource inputSource =
fEntityResolver.resolveEntity(name, pubId, baseURI, sysId);
return (inputSource != null) ? createXMLInputSource(inputSource, baseURI) : null;
}
// error resolving entity
catch (SAXException e) {
Exception ex = e.getException();
if (ex == null) {
ex = e;
}
throw new XNIException(ex);
}
}
// unable to resolve entity
return null;
}
/**
* Resolves an external parsed entity. If the entity cannot be
* resolved, this method should return null.
*
* @param resourceIdentifier contains the physical co-ordinates of the resource to be resolved
*
* @throws XNIException Thrown on general error.
* @throws IOException Thrown if resolved entity stream cannot be
* opened or some other i/o error occurs.
*/
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
throws XNIException, IOException {
// When both pubId and sysId are null, the user's entity resolver
// can do nothing about it. We'd better not bother calling it.
// This happens when the resourceIdentifier is a GrammarDescription,
// which describes a schema grammar of some namespace, but without
// any schema location hint. -Sg
String pubId = resourceIdentifier.getPublicId();
String sysId = resourceIdentifier.getExpandedSystemId();
if (pubId == null && sysId == null)
return null;
// resolve entity using SAX entity resolver
if (fEntityResolver != null && resourceIdentifier != null) {
try {
InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
if (inputSource != null) {
String publicId = inputSource.getPublicId();
String systemId = inputSource.getSystemId();
String baseSystemId = resourceIdentifier.getBaseSystemId();
InputStream byteStream = inputSource.getByteStream();
Reader charStream = inputSource.getCharacterStream();
String encoding = inputSource.getEncoding();
XMLInputSource xmlInputSource =
new XMLInputSource(publicId, systemId, baseSystemId);
xmlInputSource.setByteStream(byteStream);
xmlInputSource.setCharacterStream(charStream);
xmlInputSource.setEncoding(encoding);
return xmlInputSource;
}
}
// error resolving entity
catch (SAXException e) {
Exception ex = e.getException();
if (ex == null) {
ex = e;
}
throw new XNIException(ex);
}
}
// unable to resolve entity
return null;
}
/**
* Resolves an external parsed entity. If the entity cannot be
* resolved, this method should return null.
*
* @param resourceIdentifier contains the physical co-ordinates of the resource to be resolved
*
* @throws XNIException Thrown on general error.
* @throws IOException Thrown if resolved entity stream cannot be
* opened or some other i/o error occurs.
*/
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
throws XNIException, IOException {
// When both pubId and sysId are null, the user's entity resolver
// can do nothing about it. We'd better not bother calling it.
// This happens when the resourceIdentifier is a GrammarDescription,
// which describes a schema grammar of some namespace, but without
// any schema location hint. -Sg
String pubId = resourceIdentifier.getPublicId();
String sysId = resourceIdentifier.getExpandedSystemId();
if (pubId == null && sysId == null)
return null;
// resolve entity using SAX entity resolver
if (fEntityResolver != null && resourceIdentifier != null) {
try {
InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
if (inputSource != null) {
String publicId = inputSource.getPublicId();
String systemId = inputSource.getSystemId();
String baseSystemId = resourceIdentifier.getBaseSystemId();
InputStream byteStream = inputSource.getByteStream();
Reader charStream = inputSource.getCharacterStream();
String encoding = inputSource.getEncoding();
XMLInputSource xmlInputSource =
new XMLInputSource(publicId, systemId, baseSystemId);
xmlInputSource.setByteStream(byteStream);
xmlInputSource.setCharacterStream(charStream);
xmlInputSource.setEncoding(encoding);
return xmlInputSource;
}
}
// error resolving entity
catch (SAXException e) {
Exception ex = e.getException();
if (ex == null) {
ex = e;
}
throw new XNIException(ex);
}
}
// unable to resolve entity
return null;
}