Author: yzhishko
Date: 2010-05-03 04:37:11 -0400 (Mon, 03 May 2010)
New Revision: 21850
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2XMLValidator.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2ResourcesFolder.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2ComponentResolutionGenerator.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2AttrTempComponent.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2ComponentFactory.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2CompositeTempComponent.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentModelManager.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentRecognizer.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentUtil.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ResourceUtil.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5930 main functionality was added only tests and
demos remain.
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2010-05-03 07:42:31 UTC
(rev 21849)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2010-05-03 08:37:11 UTC
(rev 21850)
@@ -45,7 +45,8 @@
org.eclipse.wst.validation,
org.eclipse.jdt.core.manipulation,
org.eclipse.jst.j2ee,
- org.eclipse.ui.ide
+ org.eclipse.ui.ide,
+ org.eclipse.wst.html.core;bundle-version="1.1.300"
Bundle-Version: 3.1.0.qualifier
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java 2010-05-03
07:42:31 UTC (rev 21849)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java 2010-05-03
08:37:11 UTC (rev 21850)
@@ -17,9 +17,6 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator;
import org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalHelper;
import org.eclipse.wst.validation.internal.core.Message;
@@ -30,8 +27,8 @@
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.jboss.tools.jsf.web.validation.jsf2.components.IJSF2ValidationComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentModelManager;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -76,19 +73,8 @@
}
public void connect(IDocument document) {
- if (document instanceof IStructuredDocument) {
- IStructuredModel model = StructuredModelManager.getModelManager()
- .getExistingModelForRead(document);
- try {
- if (model instanceof IDOMModel) {
- this.document = ((IDOMModel) model).getDocument();
- }
- } finally {
- if(model!=null) {
- model.releaseFromRead();
- }
- }
- }
+ this.document = JSF2ComponentModelManager
+ .getReadableDOMDocument(document);
}
public void disconnect(IDocument document) {
@@ -208,4 +194,4 @@
return element.getStartOffset() == offSet;
}
-}
+}
\ No newline at end of file
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2XMLValidator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2XMLValidator.java 2010-05-03
07:42:31 UTC (rev 21849)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2XMLValidator.java 2010-05-03
08:37:11 UTC (rev 21850)
@@ -25,6 +25,7 @@
import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.jsf.JSFModelPlugin;
import org.jboss.tools.jsf.web.validation.jsf2.components.IJSF2ValidationComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentModelManager;
import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentRecognizer;
import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentUtil;
import org.jboss.tools.jst.web.kb.IPageContext;
@@ -75,8 +76,8 @@
}
private void validateAsDOM(IFile file) {
- IDOMDocument document = JSF2ComponentUtil
- .getReadableDocumentForFile(file);
+ IDOMDocument document = JSF2ComponentModelManager
+ .getReadableDOMDocument(file);
IJSF2ValidationComponent[] components = getValidationComponents(
document, file);
if (components != null) {
@@ -98,7 +99,6 @@
IFile file) {
List<IJSF2ValidationComponent> components = new
ArrayList<IJSF2ValidationComponent>(
0);
- Set<String> tagNameSet = new HashSet<String>(0);
Map<String, List<Element>> compositeComponentsMap = JSF2ComponentUtil
.findCompositeComponents(node);
Set<Entry<String, List<Element>>> entries = compositeComponentsMap
@@ -106,14 +106,11 @@
for (Entry<String, List<Element>> entry : entries) {
List<Element> elements = entry.getValue();
for (Element element : elements) {
- if (!(tagNameSet.contains(element.getNodeName()))) {
- tagNameSet.add(element.getNodeName());
- IJSF2ValidationComponent[] validationComponents = JSF2ComponentRecognizer
- .recognizeCompositeValidationComponents(file,
- (IDOMElement) element);
- for (int i = 0; i < validationComponents.length; i++) {
- components.add(validationComponents[i]);
- }
+ IJSF2ValidationComponent[] validationComponents = JSF2ComponentRecognizer
+ .recognizeCompositeValidationComponents(file,
+ (IDOMElement) element);
+ for (int i = 0; i < validationComponents.length; i++) {
+ components.add(validationComponents[i]);
}
}
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2ResourcesFolder.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2ResourcesFolder.java 2010-05-03
07:42:31 UTC (rev 21849)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2ResourcesFolder.java 2010-05-03
08:37:11 UTC (rev 21850)
@@ -31,7 +31,7 @@
/**
*
* @author yzhishko
- *
+ *
*/
public class CreateJSF2ResourcesFolder implements IMarkerResolution {
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2ComponentResolutionGenerator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2ComponentResolutionGenerator.java 2010-05-03
07:42:31 UTC (rev 21849)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2ComponentResolutionGenerator.java 2010-05-03
08:37:11 UTC (rev 21850)
@@ -53,7 +53,7 @@
} catch (CoreException e) {
JSFModelPlugin.getPluginLog().logError(e);
}
- return new CreateJSF2CompositeComponent[] { new CreateJSF2CompositeComponent() };
+ return new IMarkerResolution[0];
}
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2AttrTempComponent.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2AttrTempComponent.java 2010-05-03
07:42:31 UTC (rev 21849)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2AttrTempComponent.java 2010-05-03
08:37:11 UTC (rev 21850)
@@ -68,10 +68,7 @@
}
void createValidationMessage() {
- String nodeName = parentEl.getNodeName();
- if (nodeName.indexOf(':') > -1) {
- nodeName = nodeName.substring(nodeName.lastIndexOf(':') + 1);
- }
+ String nodeName = parentEl.getLocalName();
this.validationMessage = MessageFormat.format(
JSFUIMessages.Missing_JSF_2_Component_Attr, attr.getName(),
nodeName);
@@ -106,10 +103,7 @@
String uriString = parentEl.getNamespaceURI();
String relativeLocation = uriString.replaceFirst(
JSF2ResourceUtil.JSF2_URI_PREFIX, ""); //$NON-NLS-1$
- String nodeName = parentEl.getNodeName();
- if (nodeName.indexOf(':') > -1) {
- nodeName = nodeName.substring(nodeName.lastIndexOf(':') + 1);
- }
+ String nodeName = parentEl.getLocalName();
componentResLocation = relativeLocation + "/" + nodeName +
".xhtml"; //$NON-NLS-1$ //$NON-NLS-2$
}
return componentResLocation;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2ComponentFactory.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2ComponentFactory.java 2010-05-03
07:42:31 UTC (rev 21849)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2ComponentFactory.java 2010-05-03
08:37:11 UTC (rev 21850)
@@ -12,15 +12,17 @@
package org.jboss.tools.jsf.web.validation.jsf2.components;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
-import java.util.zip.ZipEntry;
+import java.util.Set;
+
import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.internal.core.JarEntryFile;
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentModelManager;
-import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentUtil;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -34,6 +36,12 @@
@SuppressWarnings("restriction")
public class JSF2ComponentFactory {
+ private static Set<String> uncheckedAttrs = new HashSet<String>(0);
+
+ static {
+ uncheckedAttrs.add("id"); //$NON-NLS-1$
+ }
+
public static IJSF2ValidationComponent createCompositeTempComponent(
IDOMElement element) {
JSF2CompositeTempComponent component = new JSF2CompositeTempComponent(
@@ -49,19 +57,45 @@
}
public static IJSF2ValidationComponent[] createUnfixableAttrTempComponents(
- ZipEntry zipContainer, IDOMElement elementWithAttrs) {
- return null;
+ JarEntryFile container, IDOMElement elementWithAttrs) {
+ List<IJSF2ValidationComponent> validationComponents = new
ArrayList<IJSF2ValidationComponent>(
+ 0);
+ IDOMDocument containerDocument = JSF2ComponentModelManager
+ .getReadableDOMDocument(container);
+ IDOMElement interfaceElement = JSF2ComponentModelManager.getManager()
+ .checkCompositeInterface(containerDocument);
+ Set<String> interfaceAttrs = getInterfaceAttrs(interfaceElement);
+ interfaceAttrs.addAll(uncheckedAttrs);
+ IDOMAttr[] existingAttrs = getExistingAttrs(elementWithAttrs);
+ for (int i = 0; i < existingAttrs.length; i++) {
+ if (!interfaceAttrs.contains(existingAttrs[i].getName())) {
+ IDOMAttr attr = existingAttrs[i];
+ JSF2AttrTempComponent component = new JSF2AttrTempComponent(
+ attr, (ElementImpl) elementWithAttrs);
+ component
+ .setType(IJSF2ValidationComponent.JSF2_UNFIXABLE_ATTR_TYPE);
+ component.setStartOffSet(attr.getStartOffset());
+ component.setLine(attr.getStructuredDocument().getLineOfOffset(
+ component.getStartOffSet()) + 1);
+ component.setLength(attr.getName().length());
+ component.createValidationMessage();
+ component.createMessageParams();
+ validationComponents.add(component);
+ }
+ }
+ return validationComponents.toArray(new IJSF2ValidationComponent[0]);
}
public static IJSF2ValidationComponent[] createFixableAttrTempComponents(
IFile compContainerFile, IDOMElement elementWithAttrs) {
List<IJSF2ValidationComponent> components = new
ArrayList<IJSF2ValidationComponent>(
0);
- IDOMDocument document = JSF2ComponentUtil
- .getReadableDocumentForFile(compContainerFile);
+ IDOMDocument document = JSF2ComponentModelManager
+ .getReadableDOMDocument(compContainerFile);
IDOMElement interfaceElement = JSF2ComponentModelManager.getManager()
.checkCompositeInterface(document);
- List<String> interfaceAttrs = getInterfaceAttrs(interfaceElement);
+ Set<String> interfaceAttrs = getInterfaceAttrs(interfaceElement);
+ interfaceAttrs.addAll(uncheckedAttrs);
IDOMAttr[] existingAttrs = getExistingAttrs(elementWithAttrs);
for (int i = 0; i < existingAttrs.length; i++) {
if (!interfaceAttrs.contains(existingAttrs[i].getName())) {
@@ -97,8 +131,8 @@
return component;
}
- private static List<String> getInterfaceAttrs(IDOMElement interfaceElement) {
- List<String> interfaceAttrs = new ArrayList<String>(0);
+ private static Set<String> getInterfaceAttrs(IDOMElement interfaceElement) {
+ Set<String> interfaceAttrs = new HashSet<String>(0);
if (interfaceElement != null) {
String prefix = interfaceElement.getPrefix();
String nodeName = "attribute"; //$NON-NLS-1$
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2CompositeTempComponent.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2CompositeTempComponent.java 2010-05-03
07:42:31 UTC (rev 21849)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2CompositeTempComponent.java 2010-05-03
08:37:11 UTC (rev 21850)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
package org.jboss.tools.jsf.web.validation.jsf2.components;
import java.text.MessageFormat;
@@ -10,6 +21,12 @@
import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
import org.w3c.dom.NamedNodeMap;
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
@SuppressWarnings("restriction")
public class JSF2CompositeTempComponent implements IJSF2ValidationComponent {
private int length;
@@ -50,10 +67,7 @@
}
void createValidationMessage() {
- String nodeName = element.getNodeName();
- if (nodeName.indexOf(':') > -1) {
- nodeName = nodeName.substring(nodeName.lastIndexOf(':') + 1);
- }
+ String nodeName = element.getLocalName();
this.validationMessage = MessageFormat.format(
JSFUIMessages.Missing_JSF_2_Composite_Component, nodeName);
}
@@ -90,10 +104,7 @@
String uriString = element.getNamespaceURI();
String relativeLocation = uriString.replaceFirst(
JSF2ResourceUtil.JSF2_URI_PREFIX, ""); //$NON-NLS-1$
- String nodeName = element.getNodeName();
- if (nodeName.indexOf(':') > -1) {
- nodeName = nodeName.substring(nodeName.lastIndexOf(':') + 1);
- }
+ String nodeName = element.getLocalName();
componentResLoc = relativeLocation + "/" + nodeName + ".xhtml";
//$NON-NLS-1$ //$NON-NLS-2$
}
return componentResLoc;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentModelManager.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentModelManager.java 2010-05-03
07:42:31 UTC (rev 21849)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentModelManager.java 2010-05-03
08:37:11 UTC (rev 21850)
@@ -13,14 +13,21 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
-
+import java.io.InputStream;
+import java.util.Scanner;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.internal.core.JarEntryFile;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.wst.html.core.internal.encoding.HTMLModelLoader;
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.sse.core.internal.text.JobSafeStructuredDocument;
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
@@ -65,15 +72,9 @@
model.reload(componentFileContatiner.getContents());
document = domModel.getDocument();
updateJSF2CompositeComponent(document, attrNames);
- try {
- componentFileContatiner.setContents(
- new ByteArrayInputStream(document
- .getStructuredDocument().getText()
- .getBytes()), true, false,
- new NullProgressMonitor());
- } catch (CoreException e) {
- JSFModelPlugin.getPluginLog().logError(e);
- }
+ componentFileContatiner.setContents(new ByteArrayInputStream(
+ document.getStructuredDocument().getText().getBytes()),
+ true, false, new NullProgressMonitor());
}
} catch (CoreException e) {
JSFModelPlugin.getPluginLog().logError(e);
@@ -105,10 +106,8 @@
ElementImpl impl = (ElementImpl) node;
String nameSpace = impl.getNamespaceURI();
if (JSF2ResourceUtil.JSF2_URI_PREFIX.equals(nameSpace)) {
- String nodeName = impl.getNodeName();
- String compName = nodeName.substring(
- nodeName.lastIndexOf(':') + 1).trim();
- if ("interface".equals(compName)) { //$NON-NLS-1$
+ String nodeName = impl.getLocalName();
+ if ("interface".equals(nodeName)) { //$NON-NLS-1$
interfaceElement[0] = impl;
return;
}
@@ -149,8 +148,7 @@
}
public IFile revalidateCompositeComponentFile(IFile file) {
- IDOMDocument document = JSF2ComponentUtil
- .getReadableDocumentForFile(file);
+ IDOMDocument document = getReadableDOMDocument(file);
if (document == null) {
return null;
}
@@ -176,27 +174,86 @@
if (!"http://www.w3.org/1999/xhtml".equals(elementImpl.getNamespaceURI())) {
//$NON-NLS-1$
return null;
}
- NodeList children = element.getChildNodes();
- if (children == null) {
- return null;
+ IDOMElement[] interfaceElement = new IDOMElement[1];
+ findInterfaceComponent(document, interfaceElement);
+ return interfaceElement[0];
+ }
+
+ public static IDOMDocument getReadableDOMDocument(IFile file) {
+ IDOMDocument document = null;
+ IModelManager manager = StructuredModelManager.getModelManager();
+ if (manager == null) {
+ return document;
}
- for (int i = 0; i < children.getLength(); i++) {
- if (children.item(i) instanceof Element) {
- Element el = (Element) children.item(i);
- String nodeName = el.getNodeName();
- if (nodeName.indexOf(':') > -1) {
- nodeName = nodeName
- .substring(nodeName.lastIndexOf(":") + 1); //$NON-NLS-1$
+ IStructuredModel model = null;
+ try {
+ model = manager.getModelForRead(file);
+ if (model instanceof IDOMModel) {
+ IDOMModel domModel = (IDOMModel) model;
+ document = domModel.getDocument();
+ }
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ } catch (IOException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ } finally {
+ if (model != null) {
+ model.releaseFromRead();
+ }
+ }
+ return document;
+ }
+
+ public static IDOMDocument getReadableDOMDocument(JarEntryFile file) {
+ IDOMDocument document = null;
+ IStructuredModel model = null;
+ InputStream inputStream;
+ try {
+ inputStream = file.getContents();
+ if (inputStream != null) {
+ StringBuffer buffer = new StringBuffer(""); //$NON-NLS-1$
+ Scanner in = new Scanner(inputStream);
+ while (in.hasNextLine()) {
+ buffer.append(in.nextLine());
}
- if ("interface".equals(nodeName)) { //$NON-NLS-1$
- if (JSF2ResourceUtil.JSF2_URI_PREFIX
- .equals(((ElementImpl) el).getNamespaceURI())) {
- return (IDOMElement) el;
- }
+ model = new HTMLModelLoader().newModel();
+ model.setStructuredDocument(new JobSafeStructuredDocument(
+ new XMLSourceParser()));
+ model.getStructuredDocument().set(buffer.toString());
+ if (model instanceof IDOMModel) {
+ document = ((IDOMModel) model).getDocument();
}
}
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ } finally {
+ model = null;
}
- return null;
+ return document;
}
+ public static IDOMDocument getReadableDOMDocument(IDocument textDocument) {
+ IDOMDocument document = null;
+ if (!(textDocument instanceof IStructuredDocument)) {
+ return document;
+ }
+ IModelManager manager = StructuredModelManager.getModelManager();
+ if (manager == null) {
+ return document;
+ }
+ IStructuredModel model = null;
+ try {
+ model = manager.getModelForRead((IStructuredDocument) textDocument);
+ if (model instanceof IDOMModel) {
+ IDOMModel domModel = (IDOMModel) model;
+ document = domModel.getDocument();
+ }
+ } finally {
+ if (model != null) {
+ model.releaseFromRead();
+ }
+ }
+ return document;
+ }
+
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentRecognizer.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentRecognizer.java 2010-05-03
07:42:31 UTC (rev 21849)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentRecognizer.java 2010-05-03
08:37:11 UTC (rev 21850)
@@ -12,9 +12,9 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.zip.ZipEntry;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.internal.core.JarEntryFile;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.jboss.tools.jsf.web.validation.jsf2.components.IJSF2ValidationComponent;
@@ -45,10 +45,10 @@
for (int i = 0; i < components.length; i++) {
validationComponents.add(components[i]);
}
- } else if (container instanceof ZipEntry) {
+ } else if (container instanceof JarEntryFile) {
IJSF2ValidationComponent[] components = JSF2ComponentFactory
- .createUnfixableAttrTempComponents((ZipEntry) container,
- element);
+ .createUnfixableAttrTempComponents(
+ (JarEntryFile) container, element);
for (int i = 0; i < components.length; i++) {
validationComponents.add(components[i]);
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentUtil.java 2010-05-03
07:42:31 UTC (rev 21849)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentUtil.java 2010-05-03
08:37:11 UTC (rev 21850)
@@ -11,23 +11,14 @@
package org.jboss.tools.jsf.web.validation.jsf2.util;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.jboss.tools.jsf.JSFModelPlugin;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -77,31 +68,6 @@
}
}
- public static IDOMDocument getReadableDocumentForFile(IFile file) {
- IDOMDocument document = null;
- IModelManager manager = StructuredModelManager.getModelManager();
- if (manager == null) {
- return document;
- }
- IStructuredModel model = null;
- try {
- model = manager.getModelForRead(file);
- if (model instanceof IDOMModel) {
- IDOMModel domModel = (IDOMModel) model;
- document = domModel.getDocument();
- }
- } catch (CoreException e) {
- JSFModelPlugin.getPluginLog().logError(e);
- } catch (IOException e) {
- JSFModelPlugin.getPluginLog().logError(e);
- } finally {
- if (model != null) {
- model.releaseFromRead();
- }
- }
- return document;
- }
-
public static IDOMAttr[] findURIContainers(Node scanNode) {
List<IDOMAttr> attrs = new ArrayList<IDOMAttr>(0);
findChildURIContainers(scanNode, attrs);
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ResourceUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ResourceUtil.java 2010-05-03
07:42:31 UTC (rev 21849)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ResourceUtil.java 2010-05-03
08:37:11 UTC (rev 21850)
@@ -25,6 +25,9 @@
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.JarEntryDirectory;
+import org.eclipse.jdt.internal.core.JarEntryFile;
+import org.eclipse.jdt.internal.core.JarEntryResource;
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
@@ -46,6 +49,10 @@
public static final String COMPONENT_RESOURCE_PATH_KEY =
"component_resource_path_key"; //$NON-NLS-1$
+ public static final int JAR_FILE_RESOURCE_TYPE = 1;
+
+ public static final int JAR_DIRECTORY_RESOURCE_TYPE = JAR_FILE_RESOURCE_TYPE <<
1;
+
public static Object findCompositeComponentContainer(IProject project,
IDOMElement jsf2Element) {
ElementImpl elementImpl = (ElementImpl) jsf2Element;
@@ -53,10 +60,7 @@
if (nameSpaceURI == null || nameSpaceURI.indexOf(JSF2_URI_PREFIX) == -1) {
return null;
}
- String nodeName = jsf2Element.getNodeName();
- if (nodeName.lastIndexOf(':') != -1) {
- nodeName = nodeName.substring(nodeName.lastIndexOf(':') + 1);
- }
+ String nodeName = jsf2Element.getLocalName();
String relativeLocation = "/resources" + nameSpaceURI.replaceFirst(
//$NON-NLS-1$
JSF2ResourceUtil.JSF2_URI_PREFIX, ""); //$NON-NLS-1$
IVirtualComponent component = ComponentCore.createComponent(project);
@@ -67,16 +71,16 @@
IPath path = folder.getFullPath().append(relativeLocation).append(
"/" + nodeName + ".xhtml"); //$NON-NLS-1$ //$NON-NLS-2$
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
- if (file.exists()) {
+ if (file.isAccessible()) {
return file;
}
}
return searchInClassPath(project, "META-INF" + relativeLocation
//$NON-NLS-1$
- + "/" + nodeName + ".xhtml"); //$NON-NLS-1$ //$NON-NLS-2$
+ + "/" + nodeName + ".xhtml", JAR_FILE_RESOURCE_TYPE);
//$NON-NLS-1$ //$NON-NLS-2$
}
- private static ZipEntry searchInClassPath(IProject project,
- String classPathResource) {
+ private static JarEntryResource searchInClassPath(IProject project,
+ String classPathResource, int jarResourceType) {
IJavaProject javaProject = JavaCore.create(project);
try {
for (IPackageFragmentRoot fragmentRoot : javaProject
@@ -86,7 +90,18 @@
ZipEntry zipEntry = jarPackageFragmentRoot.getJar()
.getEntry(classPathResource);
if (zipEntry != null) {
- return zipEntry;
+ if (jarResourceType == JAR_FILE_RESOURCE_TYPE) {
+ JarEntryFile fileInJar = new JarEntryFile(
+ classPathResource);
+ fileInJar.setParent(jarPackageFragmentRoot);
+ return fileInJar;
+ }
+ if (jarResourceType == JAR_DIRECTORY_RESOURCE_TYPE) {
+ JarEntryDirectory directoryInJar = new JarEntryDirectory(
+ classPathResource);
+ directoryInJar.setParent(jarPackageFragmentRoot);
+ return directoryInJar;
+ }
}
}
}
@@ -98,8 +113,8 @@
return null;
}
- public static IPath findResourcesFolderByNameSpace(IProject project,
- String nameSpaceURI) {
+ public static Object findResourcesFolderContainerByNameSpace(
+ IProject project, String nameSpaceURI) {
if (nameSpaceURI == null || nameSpaceURI.indexOf(JSF2_URI_PREFIX) == -1) {
return null;
}
@@ -113,16 +128,17 @@
IPath path = folder.getFullPath().append(relativeLocation);
IFolder resFolder = ResourcesPlugin.getWorkspace().getRoot()
.getFolder(path);
- if (resFolder.exists()) {
- return resFolder.getFullPath();
+ if (resFolder.isAccessible()) {
+ return resFolder;
}
}
- return null;
+ return searchInClassPath(project,
+ "META-INF" + relativeLocation, JAR_DIRECTORY_RESOURCE_TYPE); //$NON-NLS-1$
}
public static boolean isResourcesFolderExists(IProject project,
String nameSpaceURI) {
- return findResourcesFolderByNameSpace(project, nameSpaceURI) == null ? false
+ return findResourcesFolderContainerByNameSpace(project, nameSpaceURI) == null ? false
: true;
}