Author: scabanovich
Date: 2007-07-24 07:49:12 -0400 (Tue, 24 Jul 2007)
New Revision: 2619
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EntityXMLRegistration.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/SimpleWebFileLoader.java
Log:
EXIN-86 model gets access to dtds from wtp
Modified: trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF 2007-07-24
11:24:59 UTC (rev 2618)
+++ trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF 2007-07-24
11:49:12 UTC (rev 2619)
@@ -78,6 +78,7 @@
org.eclipse.ant.ui,
org.eclipse.ltk.core.refactoring,
org.eclipse.ltk.ui.refactoring,
+ org.eclipse.wst.common.uriresolver,
org.eclipse.core.resources;visibility:=reexport,
org.eclipse.core.runtime;visibility:=reexport
Bundle-Version: 2.0.0
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java 2007-07-24
11:24:59 UTC (rev 2618)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java 2007-07-24
11:49:12 UTC (rev 2619)
@@ -130,7 +130,8 @@
if("incorrectBody".equals(name) && value.length() > 0) {
set("isIncorrect", "yes");
// setErrors(value, hasDTD(), !hasDTD()); //never validate dtd
- setErrors(value, false, false);
+ int resolution =
EntityXMLRegistration.getInstance().resolve(getModelEntity());
+ setErrors(value, resolution == EntityXMLRegistration.DTD, resolution ==
EntityXMLRegistration.SCHEMA);
}
}
@@ -225,7 +226,8 @@
boolean errors1 = ("yes".equals(get("_hasErrors_")));
loaderError = null;
// setErrors(body, hasDTD(), !hasDTD()); //never validate dtd
- setErrors(body, false, false);
+ int resolution = EntityXMLRegistration.getInstance().resolve(getModelEntity());
+ setErrors(body, resolution == EntityXMLRegistration.DTD, resolution ==
EntityXMLRegistration.SCHEMA);
boolean errors2 = (get("errors") != null &&
get("errors").length() > 0);
if(errors1 && errors2) {
super.set("incorrectBody".intern(), body);
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/SimpleWebFileLoader.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/SimpleWebFileLoader.java 2007-07-24
11:24:59 UTC (rev 2618)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/SimpleWebFileLoader.java 2007-07-24
11:49:12 UTC (rev 2619)
@@ -78,9 +78,10 @@
}
protected Document loadDocument(XModelObject object, String body) {
+ int resolution =
EntityXMLRegistration.getInstance().resolve(object.getModelEntity());
String[] errors =
// XMLUtil.getXMLErrors(new StringReader(body), isCheckingDTD(),
isCheckingSchema());
- XMLUtil.getXMLErrors(new StringReader(body), false, false);
+ XMLUtil.getXMLErrors(new StringReader(body), resolution == EntityXMLRegistration.DTD,
resolution == EntityXMLRegistration.SCHEMA);
if(errors != null && errors.length > 0) {
object.setAttributeValue("isIncorrect", "yes");
object.set("correctBody", "");
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EntityXMLRegistration.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EntityXMLRegistration.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EntityXMLRegistration.java 2007-07-24
11:49:12 UTC (rev 2619)
@@ -0,0 +1,76 @@
+package org.jboss.tools.common.model.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.wst.common.uriresolver.internal.ExtensibleURIResolver;
+import org.jboss.tools.common.meta.XAttribute;
+import org.jboss.tools.common.meta.XModelEntity;
+import org.jboss.tools.common.xml.XMLEntityResolver;
+
+public class EntityXMLRegistration {
+ private static EntityXMLRegistration instance = new EntityXMLRegistration();
+
+ public static int UNRESOLVED = -1;
+ public static int DTD = 0;
+ public static int SCHEMA = 1;
+ public static int MISSING = 2;
+
+ private EntityXMLRegistration() {}
+
+ public static EntityXMLRegistration getInstance() {
+ return instance;
+ }
+
+ private Map<XModelEntity, Integer> resolved = new HashMap<XModelEntity,
Integer>();
+
+ public int resolve(XModelEntity entity) {
+ Integer i = resolved.get(entity);
+ if(i != null) return i.intValue();
+
+ XAttribute a = entity.getAttribute("publicId");
+ if(a != null) {
+ return resolveDTD(entity, a);
+ }
+ a = entity.getAttribute("xsi:schemaLocation");
+ if(a != null) {
+// return resolveSchema(entity, a);
+ }
+ resolved.put(entity, new Integer(UNRESOLVED));
+ return UNRESOLVED;
+ }
+
+ private int resolveDTD(XModelEntity entity, XAttribute a) {
+ String v = a.getDefaultValue();
+ if(XMLEntityResolver.getInstance().isResolved(v, null)) {
+ resolved.put(entity, new Integer(DTD));
+ return DTD;
+ }
+ ExtensibleURIResolver r = new ExtensibleURIResolver();
+ String s = r.resolve(null, v, null);
+ if(s != null && s.length() > 0) {
+ resolved.put(entity, new Integer(DTD));
+ XMLEntityResolver.registerPublicEntity(v, s);
+ return DTD;
+ }
+ resolved.put(entity, new Integer(MISSING));
+ return MISSING;
+ }
+
+ private int resolveSchema(XModelEntity entity, XAttribute a) {
+ String v = a.getDefaultValue();
+ String[] vs = v.split(" ");
+ if(vs == null || vs.length < 2) {
+ resolved.put(entity, new Integer(MISSING));
+ return MISSING;
+ }
+ ExtensibleURIResolver r = new ExtensibleURIResolver();
+ String s = r.resolve(null, vs[0], vs[1]);
+ if(s != null && s.length() > 0) {
+ resolved.put(entity, new Integer(SCHEMA));
+ return SCHEMA;
+ }
+ return SCHEMA;
+ }
+
+}