Author: scabanovich
Date: 2010-02-02 09:13:44 -0500 (Tue, 02 Feb 2010)
New Revision: 20073
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/facelet/model/FaceletTaglibEntityRecognizer.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/model/FileCompositeComponentRecognizer.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/AuxEntityRecognizer.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFEntityRecognizer.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5781
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/facelet/model/FaceletTaglibEntityRecognizer.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/facelet/model/FaceletTaglibEntityRecognizer.java 2010-02-02
14:12:50 UTC (rev 20072)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/facelet/model/FaceletTaglibEntityRecognizer.java 2010-02-02
14:13:44 UTC (rev 20073)
@@ -10,18 +10,9 @@
******************************************************************************/
package org.jboss.tools.jsf.facelet.model;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
import org.jboss.tools.common.model.loaders.EntityRecognizer;
-import org.w3c.dom.Document;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
+import org.jboss.tools.common.model.loaders.EntityRecognizerContext;
+import org.jboss.tools.common.model.loaders.XMLRecognizerContext;
/**
* @author Viacheslav Kabanovich
@@ -29,16 +20,17 @@
public class FaceletTaglibEntityRecognizer implements EntityRecognizer,
FaceletTaglibConstants {
- public String getEntityName(String ext, String body) {
+ public String getEntityName(EntityRecognizerContext context) {
+ String body = context.getBody();
if (body == null)
return null;
- String doctype = getUnforamtedDoctypeFromBody(body);
- if (doctype != null && !doctype.equals("")) { //$NON-NLS-1$
- doctype = checkDocType(doctype);
- if (doctype.indexOf(DOC_PUBLICID) > -1)
+ XMLRecognizerContext xml = context.getXMLContext();
+ if(xml.isDTD()) {
+ String publicId = xml.getPublicId();
+ if(DOC_PUBLICID.equals(publicId)) {
return ENT_FACELET_TAGLIB;
- }
- if (is20(body))
+ }
+ } else if (is20(body))
return ENT_FACELET_TAGLIB_20;
return null;
}
@@ -55,55 +47,4 @@
s.indexOf("\"http://java.sun.com/xml/ns/javaee\"") > 0;
//$NON-NLS-1$
}
- private String checkDocType(String docTypeString) {
- final StringBuffer docTypeBuffer = new StringBuffer(""); //$NON-NLS-1$
- Reader xml = new StringReader(docTypeString + "<root></root>");
//$NON-NLS-1$
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- dbf.setValidating(true);
- try {
- DocumentBuilder db = dbf.newDocumentBuilder();
- db.setErrorHandler(new ErrorHandler() {
- public void warning(SAXParseException exception)
- throws SAXException {
- }
-
- public void fatalError(SAXParseException exception)
- throws SAXException {
- }
-
- public void error(SAXParseException exception)
- throws SAXException {
- }
- });
- db.setEntityResolver(new EntityResolver() {
- public InputSource resolveEntity(String publicId,
- String systemId) throws SAXException, IOException {
- docTypeBuffer.append(publicId);
- return new InputSource(new StringReader("")); //$NON-NLS-1$
- }
- });
- @SuppressWarnings("unused")
- Document dom = db.parse(new InputSource(xml));
- } catch (Exception e) {
- return docTypeBuffer.toString();
- } finally {
- try {
- xml.close();
- } catch (IOException e) {
- }
- }
- return docTypeBuffer.toString();
- }
-
- private String getUnforamtedDoctypeFromBody(String body) {
- int i = body.indexOf("<!DOCTYPE"); //$NON-NLS-1$
- if (i < 0)
- return null;
- int j = body.indexOf(">", i); //$NON-NLS-1$
- if (j < 0)
- return null;
- return body.substring(i, j+1);
- }
-
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/model/FileCompositeComponentRecognizer.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/model/FileCompositeComponentRecognizer.java 2010-02-02
14:12:50 UTC (rev 20072)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/model/FileCompositeComponentRecognizer.java 2010-02-02
14:13:44 UTC (rev 20073)
@@ -1,12 +1,17 @@
package org.jboss.tools.jsf.jsf2.model;
import org.jboss.tools.common.model.loaders.EntityRecognizer;
+import org.jboss.tools.common.model.loaders.EntityRecognizerContext;
public class FileCompositeComponentRecognizer implements EntityRecognizer,
CompositeComponentConstants {
public FileCompositeComponentRecognizer() {}
- public String getEntityName(String ext, String body) {
+ public String getEntityName(EntityRecognizerContext context) {
+ return getEntityName(context.getExtension(), context.getBody());
+ }
+
+ String getEntityName(String ext, String body) {
if(body == null) return null;
if(isComponents(body)) {
return ENT_FILE_COMPONENT;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/AuxEntityRecognizer.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/AuxEntityRecognizer.java 2010-02-02
14:12:50 UTC (rev 20072)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/AuxEntityRecognizer.java 2010-02-02
14:13:44 UTC (rev 20073)
@@ -16,7 +16,11 @@
public AuxEntityRecognizer() {}
- public String getEntityName(String ext, String body) {
+ public String getEntityName(EntityRecognizerContext context) {
+ return getEntityName(context.getExtension(), context.getBody());
+ }
+
+ String getEntityName(String ext, String body) {
if (body == null) return null;
return "jsfdia".equals(ext) ? "FileAnyAuxiliary" : null;
//$NON-NLS-1$ //$NON-NLS-2$
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFEntityRecognizer.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFEntityRecognizer.java 2010-02-02
14:12:50 UTC (rev 20072)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFEntityRecognizer.java 2010-02-02
14:13:44 UTC (rev 20073)
@@ -11,7 +11,6 @@
package org.jboss.tools.jsf.model;
import java.io.IOException;
-
import org.jboss.tools.common.model.loaders.*;
import org.jboss.tools.common.xml.XMLEntityResolver;
import org.jboss.tools.jsf.JSFModelPlugin;
@@ -30,17 +29,19 @@
public JSFEntityRecognizer() {}
- public String getEntityName(String ext, String body) {
+ public String getEntityName(EntityRecognizerContext context) {
+ String body = context.getBody();
if(body == null) return null;
- int i = body.indexOf("<!DOCTYPE"); //$NON-NLS-1$
- if(i >= 0) {
- int j = body.indexOf(">", i); //$NON-NLS-1$
- if(j < 0) return null;
- String dt = body.substring(i, j);
- if(dt.indexOf("faces-config") < 0) return null; //$NON-NLS-1$
- if(dt.indexOf(DOC_PUBLICID) > 0) return ENT_FACESCONFIG;
- if(dt.indexOf(DOC_PUBLICID_11) > 0) return ENT_FACESCONFIG_11;
- if(dt.indexOf("SYSTEM") > 0 &&
dt.indexOf("web-facesconfig_1_1.dtd") > 0) return ENT_FACESCONFIG_11;
//$NON-NLS-1$ //$NON-NLS-2$
+ XMLRecognizerContext xml = context.getXMLContext();
+ if(xml.isDTD()) {
+ String publicId = xml.getPublicId();
+ String systemId = xml.getSystemId();
+ String root = xml.getRootName();
+ if(!"faces-config".equals(root)) return null; //$NON-NLS-1$
+ if(DOC_PUBLICID.equals(publicId)) return ENT_FACESCONFIG;
+ if(DOC_PUBLICID_11.equals(publicId)) return ENT_FACESCONFIG_11;
+ if(systemId != null &&
systemId.indexOf("web-facesconfig_1_1.dtd") >= 0) return ENT_FACESCONFIG_11;
//$NON-NLS-1$
+ return null;
}
String versionSuffix = getVersion(body);
if(SUFF_12.equals(versionSuffix)) {