Author: akazakov
Date: 2010-09-08 12:02:20 -0400 (Wed, 08 Sep 2010)
New Revision: 24816
Modified:
branches/jbosstools-3.2.0.M2/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/MetaLibLoader.java
Log:
https://jira.jboss.org/browse/JBIDE-7026 Fixed in M2 brunch
Modified:
branches/jbosstools-3.2.0.M2/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/MetaLibLoader.java
===================================================================
---
branches/jbosstools-3.2.0.M2/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/MetaLibLoader.java 2010-09-08
14:29:20 UTC (rev 24815)
+++
branches/jbosstools-3.2.0.M2/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/MetaLibLoader.java 2010-09-08
16:02:20 UTC (rev 24816)
@@ -17,6 +17,7 @@
import org.w3c.dom.*;
import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
@@ -99,9 +100,14 @@
stream1 = url.openStream();
stream2 = new BufferedInputStream(stream1, 16384);
-
Element g = parse(stream2);
if(g == null) {
+ ModelPlugin.getPluginLog().logError("SAX parser failed to load meta resource
" + name);
+ stream1 = url.openStream();
+ stream2 = new BufferedInputStream(stream1, 16384);
+ g = XMLUtilities.getElement(stream2, new EmptyResolver());
+ }
+ if(g == null) {
ModelPlugin.getPluginLog().logInfo("Corrupted meta resource " + name);
//$NON-NLS-1$
} else {
load0(g, name, url.toString());
@@ -158,7 +164,9 @@
p.parse(stream);
Element g = p.documentElement;
g = XMLUtilities.getUniqueChild(g, "XModelEntityGroup"); //$NON-NLS-1$
- p.documentElement.removeChild(g);
+ if(g != null) {
+ p.documentElement.removeChild(g);
+ }
return g;
}
@@ -241,14 +249,35 @@
ModelPlugin.getPluginLog().logError(e);
}
}
+
+ XMLReader newInstance() throws SAXException {
+ try {
+ return (XMLReader)
ModelPlugin.getDefault().getBundle().loadClass(DEFAULT_SAX_PARSER_CLASS_NAME).newInstance();
+ } catch (ClassNotFoundException e1) {
+ throw new SAXException("SAX2 driver class " +
DEFAULT_SAX_PARSER_CLASS_NAME +
+ " not found", e1);
+ } catch (IllegalAccessException e2) {
+ throw new SAXException("SAX2 driver class " +
DEFAULT_SAX_PARSER_CLASS_NAME +
+ " found but cannot be loaded", e2);
+ } catch (InstantiationException e3) {
+ throw new SAXException("SAX2 driver class " +
DEFAULT_SAX_PARSER_CLASS_NAME +
+ " loaded but cannot be instantiated (no empty public constructor?)",
+ e3);
+ } catch (ClassCastException e4) {
+ throw new SAXException("SAX2 driver class " +
DEFAULT_SAX_PARSER_CLASS_NAME +
+ " does not implement XMLReader", e4);
+ }
+ }
XMLReader createParser() {
DefaultHandler handler = new DefaultHandler();
XMLReader parserInstance = null;
try {
- parserInstance =
XMLReaderFactory.createXMLReader(DEFAULT_SAX_PARSER_CLASS_NAME);
+ parserInstance = newInstance();
+ //XMLReaderFactory.createXMLReader(DEFAULT_SAX_PARSER_CLASS_NAME);
} catch (SAXException e) {
+ ModelPlugin.getPluginLog().logError("default parser failed: " +
e.getMessage());
return null;
}
@@ -260,14 +289,6 @@
SAXValidator.setFeature(parserInstance, VALIDATION_DYNAMIC_FEATURE_ID, false);
SAXValidator.setFeature(parserInstance, FATAL_ERROR_PROCESSING_FEATURE_ID,
false);
- class EmptyHandler implements org.apache.xerces.xni.parser.XMLEntityResolver {
-
- public XMLInputSource resolveEntity(XMLResourceIdentifier id)
- throws XNIException, IOException {
- return new XMLInputSource(id.getPublicId(), id.getBaseSystemId(),
id.getBaseSystemId(), new StringReader(""), null);
- }
-
- }
try {
if(MetaLibLoader.validateMetaXML) {
parserInstance.setProperty(ENTITY_RESOLVER_PROPERTY_ID, new
XMLEntityResolverImpl());
@@ -332,3 +353,18 @@
public void startPrefixMapping(String prefix, String uri) throws SAXException {}
}
+
+class EmptyHandler implements org.apache.xerces.xni.parser.XMLEntityResolver {
+
+ public XMLInputSource resolveEntity(XMLResourceIdentifier id)
+ throws XNIException, IOException {
+ return new XMLInputSource(id.getPublicId(), id.getBaseSystemId(), id.getBaseSystemId(),
new StringReader(""), null);
+ }
+
+}
+
+class EmptyResolver implements EntityResolver {
+ public InputSource resolveEntity(String publicID, String systemID) throws SAXException,
IOException {
+ return new InputSource(new StringReader("")); //$NON-NLS-1$
+ }
+}
\ No newline at end of file