Author: yzhishko
Date: 2010-04-29 12:20:09 -0400 (Thu, 29 Apr 2010)
New Revision: 21799
Added:
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/CreateJSF2CompositeAttrs.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeComponent.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/components/
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/IJSF2ValidationComponent.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/components/JSF2URITempComponent.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
Removed:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2Validator.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2MarkerResolution.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentParams.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentsUtil.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
trunk/jsf/plugins/org.jboss.tools.jsf/resources/templates/composite.xhtml
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/JSFUIMessages.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/messages.properties
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ComponentsValidator.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ValidationInfo.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/util/JSF2ResourceUtil.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2TemplateManager.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5930 - a part of fix
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2010-04-29 16:20:08 UTC
(rev 21798)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2010-04-29 16:20:09 UTC
(rev 21799)
@@ -49,3 +49,4 @@
Bundle-Version: 3.1.0.qualifier
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: org.eclipse.wst.sse.ui.internal.reconcile.validator
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2010-04-29 16:20:08 UTC (rev 21798)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2010-04-29 16:20:09 UTC (rev 21799)
@@ -550,5 +550,30 @@
<persistent
value="true">
</persistent>
+ <attribute
+ name="problemType">
+ </attribute>
+ <super
+ type="org.eclipse.core.resources.textmarker">
+ </super>
+ <attribute
+ name="baseElement">
+ </attribute>
</extension>
+ <extension
+ point="org.eclipse.wst.sse.ui.sourcevalidation">
+ <validator
+ class="org.jboss.tools.jsf.web.validation.jsf2.JSF2SourceValidator"
+ id="org.jboss.tools.jsf.jsf2sourcevalidator"
+ scope="total">
+ <contentTypeIdentifier
+ id="org.eclipse.wst.html.core.htmlsource">
+ <partitionType id="org.eclipse.wst.html.HTML_DEFAULT"/>
+ </contentTypeIdentifier>
+ <contentTypeIdentifier
+ id="org.eclipse.jst.jsp.core.jspsource">
+ <partitionType id="org.eclipse.jst.jsp.DEFAULT_JSP"/>
+ </contentTypeIdentifier>
+ </validator>
+ </extension>
</plugin>
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/resources/templates/composite.xhtml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/resources/templates/composite.xhtml 2010-04-29
16:20:08 UTC (rev 21798)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/resources/templates/composite.xhtml 2010-04-29
16:20:09 UTC (rev 21799)
@@ -7,7 +7,6 @@
<!-- INTERFACE -->
<composite:interface>
- <composite:attribute name=""/>
</composite:interface>
<!-- IMPLEMENTATION -->
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/JSFUIMessages.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/JSFUIMessages.java 2010-04-29
16:20:08 UTC (rev 21798)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/JSFUIMessages.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -118,13 +118,17 @@
public static String DeleteFacesConfigHandler_DeleteReferenceFromWebXML;
public static String DeleteGroupHandler_Delete;
public static String DeleteGroupHandler_DeleteFileFromDisk;
-
public static String DeleteManagedBeanHandler_CannotDeleteFile;
public static String DeleteManagedBeanHandler_Failure;
public static String DeleteManagedPropertyHandler_Delete;
public static String DeleteManagedPropertyHandler_DeleteJavaProperty;
- public static String Create_JSF_2_Composition_Component;
-
+ public static String Create_JSF_2_Composite_Component;
+ public static String Missing_JSF_2_Composite_Component;
+ public static String Missing_JSF_2_Component_Attr;
+ public static String Create_JSF_2_Interface_Attr;
+ public static String Missing_JSF_2_Resources_Folder;
+ public static String Create_JSF_2_Resources_Folder;
+
static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, JSFUIMessages.class);
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/messages.properties
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/messages.properties 2010-04-29
16:20:08 UTC (rev 21798)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/messages.properties 2010-04-29
16:20:09 UTC (rev 21799)
@@ -99,4 +99,9 @@
DeleteManagedBeanHandler_Failure=Failure
DeleteManagedPropertyHandler_Delete=Delete {0}
DeleteManagedPropertyHandler_DeleteJavaProperty=Delete java property
-Create_JSF_2_Composition_Component=Create JSF 2 composition component in a project
resources folder
+Create_JSF_2_Composite_Component=Create JSF 2 composite component in a project resources
folder
+Missing_JSF_2_Composite_Component=Composite component "{0}" was not found in a
project resources directory
+Missing_JSF_2_Component_Attr=Attribute "{0}" is not defined for "{1}"
composite component
+Create_JSF_2_Interface_Attr=Create attribute in an interface declaration of a composite
component
+Missing_JSF_2_Resources_Folder=Resources folder "{0}" is missing in a project
root directory
+Create_JSF_2_Resources_Folder=Create a folder container for JSF 2 resources
\ No newline at end of file
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ComponentsValidator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ComponentsValidator.java 2010-04-29
16:20:08 UTC (rev 21798)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ComponentsValidator.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -1,19 +1,18 @@
- /*******************************************************************************
- * 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
- ******************************************************************************/
+/*******************************************************************************
+ * 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;
import java.io.InputStream;
import java.util.Scanner;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -27,7 +26,10 @@
import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport;
import org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;
import org.jboss.tools.jsf.JSFModelPlugin;
-import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentParams;
+import org.jboss.tools.jsf.web.validation.jsf2.components.IJSF2ValidationComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2AttrTempComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2CompositeTempComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2URITempComponent;
import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
import org.jboss.tools.jst.web.kb.IKbProject;
import org.jboss.tools.jst.web.kb.KbProjectFactory;
@@ -35,7 +37,7 @@
/**
*
* @author yzhishko
- *
+ *
*/
@SuppressWarnings("restriction")
@@ -53,12 +55,8 @@
if (!isValidate(file)) {
return result;
}
- IProject project = file.getProject();
- kbProject = KbProjectFactory.getKbProject(project, false);
- if (kbProject != null) {
- this.file = file;
- return super.validate(resource, kind, state, monitor);
- }
+ this.file = file;
+ return super.validate(resource, kind, state, monitor);
}
return result;
}
@@ -66,18 +64,22 @@
@Override
public ValidationReport validate(String uri, InputStream inputstream,
NestedValidatorContext context, ValidationResult result) {
- JSF2Validator validator = JSF2Validator.getInstance();
+ JSF2XMLValidator validator = JSF2XMLValidator.getInstance();
return validator.validate(file, uri);
}
protected boolean isValidate(IFile file) {
boolean isValidate = false;
+ if (file.getProject() == null
+ || file.getProject().isAccessible() == false) {
+ return false;
+ }
try {
InputStream is = file.getContents();
Scanner scanner = new Scanner(is);
while (scanner.hasNextLine()) {
- if (scanner.nextLine().indexOf(
- JSF2ResourceUtil.JSF2_URI_PREFIX) != -1) {
+ if (scanner.nextLine()
+ .indexOf(JSF2ResourceUtil.JSF2_URI_PREFIX) != -1) {
isValidate = true;
scanner.close();
break;
@@ -85,7 +87,13 @@
}
} catch (CoreException e) {
JSFModelPlugin.getPluginLog().logError(e);
+ return isValidate;
}
+ IProject project = file.getProject();
+ kbProject = KbProjectFactory.getKbProject(project, false);
+ if (kbProject == null) {
+ isValidate = false;
+ }
return isValidate;
}
@@ -96,16 +104,39 @@
if (args == null) {
return;
}
- for (int i = 0; i < args.length; i++) {
- if (args[i] instanceof JSF2ComponentParams) {
- message
- .setAttribute(
- JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY,
- ((JSF2ComponentParams) args[i])
- .getRelativateLocation());
- break;
+ if (args[0] instanceof JSF2CompositeTempComponent) {
+ JSF2CompositeTempComponent component = (JSF2CompositeTempComponent) args[0];
+ message.setAttribute(IJSF2ValidationComponent.JSF2_TYPE_KEY,
+ component.getType());
+ message.setAttribute(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY,
+ component.getComponentResourceLocation());
+ String[] attrNames = component.getAttrNames();
+ if (attrNames != null) {
+ for (int i = 0; i < attrNames.length; i++) {
+ message.setAttribute(
+ IJSF2ValidationComponent.JSF2_ATTR_NAME_KEY
+ + String.valueOf(i), attrNames[i]);
+ }
}
+ return;
}
+ if (args[0] instanceof JSF2AttrTempComponent) {
+ JSF2AttrTempComponent component = (JSF2AttrTempComponent) args[0];
+ message.setAttribute(IJSF2ValidationComponent.JSF2_TYPE_KEY,
+ component.getType());
+ message.setAttribute(IJSF2ValidationComponent.JSF2_ATTR_NAME_KEY,
+ component.getName());
+ message.setAttribute(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY,
+ component.getComponentResourceLocation());
+ return;
+ }
+ if (args[0] instanceof JSF2URITempComponent) {
+ JSF2URITempComponent component = (JSF2URITempComponent) args[0];
+ message.setAttribute(IJSF2ValidationComponent.JSF2_TYPE_KEY,
+ IJSF2ValidationComponent.JSF2_URI_TYPE);
+ message.setAttribute(IJSF2ValidationComponent.JSF2_URI_NAME_KEY,
+ component.getURI());
+ }
}
}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,205 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.Locale;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+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;
+import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
+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.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class JSF2SourceValidator implements IValidator, ISourceValidator {
+
+ private IDOMDocument document;
+
+ public void cleanup(IReporter reporter) {
+ }
+
+ public void validate(IValidationContext helper, IReporter reporter)
+ throws ValidationException {
+ if (document != null) {
+ if (helper instanceof IncrementalHelper) {
+ IncrementalHelper incrementalHelper = (IncrementalHelper) helper;
+ IProject project = incrementalHelper.getProject();
+ if (project == null) {
+ return;
+ }
+ String filePath = helper.getURIs()[0];
+ if (filePath == null) {
+ return;
+ }
+ filePath = filePath.substring(filePath.indexOf('/') + 1);
+ IResource resource = project.findMember(filePath
+ .substring(filePath.indexOf('/') + 1));
+ if (resource instanceof IFile) {
+ reportProblems(reporter,
+ JSF2XMLValidator.getValidationComponents(document,
+ (IFile) resource));
+ }
+ }
+ }
+ }
+
+ public void connect(IDocument document) {
+ if (document instanceof IStructuredDocument) {
+ IStructuredModel model = StructuredModelManager.getModelManager()
+ .getExistingModelForRead(document);
+ if (model instanceof IDOMModel) {
+ this.document = ((IDOMModel) model).getDocument();
+ }
+ }
+ }
+
+ public void disconnect(IDocument document) {
+ document = null;
+ }
+
+ public void validate(IRegion dirtyRegion, IValidationContext helper,
+ IReporter reporter) {
+ if (document != null) {
+ Element element = findNodeFromRegion(dirtyRegion);
+ if (element == null) {
+ return;
+ }
+ if (helper instanceof IncrementalHelper) {
+ IncrementalHelper incrementalHelper = (IncrementalHelper) helper;
+ IProject project = incrementalHelper.getProject();
+ if (project == null) {
+ return;
+ }
+ String filePath = helper.getURIs()[0];
+ if (filePath == null) {
+ return;
+ }
+ filePath = filePath.substring(filePath.indexOf('/') + 1);
+ IResource resource = project.findMember(filePath
+ .substring(filePath.indexOf('/') + 1));
+ if (resource instanceof IFile) {
+ reportProblems(reporter, JSF2XMLValidator
+ .getValidationComponents(element, (IFile) resource));
+ }
+ }
+ }
+ }
+
+ private void reportProblems(IReporter reporter,
+ IJSF2ValidationComponent[] validationComponents) {
+ for (int i = 0; i < validationComponents.length; i++) {
+ reporter.addMessage(this, new LocalizedMessage(
+ validationComponents[i]));
+ }
+ }
+
+ private static class LocalizedMessage extends Message {
+
+ private IJSF2ValidationComponent component;
+
+ public LocalizedMessage(IJSF2ValidationComponent component) {
+ this.component = component;
+ }
+
+ @Override
+ public int getLineNumber() {
+ return component.getLine();
+ }
+
+ @Override
+ public int getLength() {
+ return component.getLength();
+ }
+
+ @Override
+ public int getOffset() {
+ return component.getStartOffSet();
+ }
+
+ @Override
+ public String getText() {
+ return component.getValidationMessage();
+ }
+
+ @Override
+ public String getText(Locale locale) {
+ return component.getValidationMessage();
+ }
+
+ @Override
+ public String getText(Locale locale, ClassLoader classLoader) {
+ return component.getValidationMessage();
+ }
+
+ @Override
+ public String getText(ClassLoader classLoader) {
+ return component.getValidationMessage();
+ }
+
+ @Override
+ public int getSeverity() {
+ return IMessage.NORMAL_SEVERITY;
+ }
+
+ }
+
+ private Element findNodeFromRegion(IRegion region) {
+ int offset = region.getOffset();
+ Element[] elements = new Element[1];
+ findElementAttOffSet(offset, document.getDocumentElement(), elements);
+ return elements[0];
+ }
+
+ private void findElementAttOffSet(int offSet, Node scanEl,
+ Element[] returnEl) {
+ if (scanEl instanceof IDOMElement) {
+ if (isElementAttOffset(offSet, (IDOMElement) scanEl)) {
+ returnEl[0] = (IDOMElement) scanEl;
+ return;
+ }
+ NodeList childNodes = scanEl.getChildNodes();
+ if (childNodes != null) {
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ findElementAttOffSet(offSet, childNodes.item(i), returnEl);
+ }
+ }
+ }
+ }
+
+ private boolean isElementAttOffset(int offSet, IDOMElement element) {
+ return element.getStartOffset() == offSet;
+ }
+
+}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ValidationInfo.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ValidationInfo.java 2010-04-29
16:20:08 UTC (rev 21798)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ValidationInfo.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -1,13 +1,13 @@
- /*******************************************************************************
- * 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
- ******************************************************************************/
+/*******************************************************************************
+ * 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;
@@ -16,11 +16,11 @@
/**
*
* @author yzhishko
- *
+ *
*/
@SuppressWarnings("restriction")
-public class JSF2ValidationInfo extends XMLValidationInfo{
+public class JSF2ValidationInfo extends XMLValidationInfo {
public JSF2ValidationInfo(String uri) {
super(uri);
Deleted:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2Validator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2Validator.java 2010-04-29
16:20:08 UTC (rev 21798)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2Validator.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -1,155 +0,0 @@
- /*******************************************************************************
- * 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;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-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.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.eclipse.wst.xml.core.internal.validation.core.ValidationReport;
-import org.jboss.tools.common.el.core.resolver.ELContext;
-import org.jboss.tools.jsf.JSFModelPlugin;
-import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentParams;
-import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentsUtil;
-import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
-import org.jboss.tools.jst.web.kb.IPageContext;
-import org.jboss.tools.jst.web.kb.PageContextFactory;
-import org.jboss.tools.jst.web.kb.internal.XmlContextImpl;
-import org.w3c.dom.Element;
-
-/**
- *
- * @author yzhishko
- *
- */
-
-@SuppressWarnings("restriction")
-public class JSF2Validator {
-
- public static String JSF2_PROBLEM_ID = JSFModelPlugin.PLUGIN_ID
- + ".jsf2problemmarker"; //$NON-NLS-1$
-
- private JSF2ValidationInfo validationInfo;
- private IFile file;
-
- private static JSF2Validator instance = new JSF2Validator();
-
- public ValidationReport validate(IFile file, String uri) {
- validationInfo = new JSF2ValidationInfo(uri);
- this.file = file;
- validate(file);
- return validationInfo;
- }
-
- private JSF2Validator() {
-
- }
-
- public static JSF2Validator getInstance() {
- return instance;
- }
-
- private void validate(IFile file) {
- ELContext elContext = PageContextFactory.createPageContext(file);
- if (elContext instanceof IPageContext) {
- validateAsDOM(file);
- } else if (elContext instanceof XmlContextImpl) {
- if ("xhtml".equals(file.getFileExtension())) { //$NON-NLS-1$
- validateAsDOM(file);
- }
- }
- }
-
- private void validateAsDOM(IFile file) {
- IDOMDocument document = getDocumentForFile(file);
- if (document != null) {
- Map<String, List<Element>> jsf2Components = JSF2ComponentsUtil
- .findJSF2CompositeComponents(document);
- createMarkers(jsf2Components);
- }
- }
-
- private void createMarkers(Map<String, List<Element>> jsf2Components) {
- Set<String> elementsNameSet = new HashSet<String>(0);
- Collection<List<Element>> elementsCollection = jsf2Components.values();
- for (List<Element> list : elementsCollection) {
- if (list != null) {
- for (Element element : list) {
- if (!elementsNameSet.contains(element.getNodeName())) {
- IDOMElement domElement = (IDOMElement) element;
- createMarkerForElement(domElement);
- elementsNameSet.add(element.getNodeName());
- }
- }
- }
- }
- }
-
- private void createMarkerForElement(IDOMElement domElement) {
- if (!JSF2ResourceUtil.isJSF2CompositeComponentExists(file.getProject(),
- domElement)) {
- int line = ((IDOMDocument) domElement.getOwnerDocument())
- .getStructuredDocument().getLineOfOffset(
- domElement.getStartOffset());
- validationInfo.addWarning(createWarningMessage(domElement),
- line + 1, 0, validationInfo.getFileURI(), null,
- new Object[] { JSF2ComponentParams.create(domElement) });
- }
- }
-
- private String createWarningMessage(IDOMElement element) {
- StringBuilder builder = new StringBuilder("Composite component ");
//$NON-NLS-1$
- String nodeName = element.getNodeName();
- if (nodeName.lastIndexOf(':') != -1) {
- nodeName = nodeName.substring(nodeName.lastIndexOf(':') + 1);
- }
- builder.append("\"" + nodeName + "\" "); //$NON-NLS-1$
//$NON-NLS-2$
- builder.append("was not found in a project resources folder"); //$NON-NLS-1$
- return builder.toString();
- }
-
- private IDOMDocument getDocumentForFile(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;
- }
-
-}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2XMLValidator.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+import org.eclipse.core.resources.IFile;
+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.eclipse.wst.xml.core.internal.validation.core.ValidationReport;
+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.JSF2ComponentRecognizer;
+import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentUtil;
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.PageContextFactory;
+import org.jboss.tools.jst.web.kb.internal.XmlContextImpl;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class JSF2XMLValidator {
+
+ public static String JSF2_PROBLEM_ID = JSFModelPlugin.PLUGIN_ID
+ + ".jsf2problemmarker"; //$NON-NLS-1$
+
+ private JSF2ValidationInfo validationInfo;
+
+ private static JSF2XMLValidator instance = new JSF2XMLValidator();
+
+ public ValidationReport validate(IFile file, String uri) {
+ validationInfo = new JSF2ValidationInfo(uri);
+ validate(file);
+ return validationInfo;
+ }
+
+ private JSF2XMLValidator() {
+
+ }
+
+ public static JSF2XMLValidator getInstance() {
+ return instance;
+ }
+
+ private void validate(IFile file) {
+ ELContext elContext = PageContextFactory.createPageContext(file);
+ if (elContext instanceof IPageContext) {
+ validateAsDOM(file);
+ } else if (elContext instanceof XmlContextImpl) {
+ if ("xhtml".equals(file.getFileExtension())) { //$NON-NLS-1$
+ validateAsDOM(file);
+ }
+ }
+ }
+
+ private void validateAsDOM(IFile file) {
+ IDOMDocument document = JSF2ComponentUtil
+ .getReadableDocumentForFile(file);
+ IJSF2ValidationComponent[] components = getValidationComponents(
+ document, file);
+ if (components != null) {
+ for (int i = 0; i < components.length; i++) {
+ createMarkerForComponent(components[i]);
+ }
+ }
+ }
+
+ private void createMarkerForComponent(
+ IJSF2ValidationComponent jsf2ValidationComponent) {
+ validationInfo.addWarning(jsf2ValidationComponent
+ .getValidationMessage(), jsf2ValidationComponent.getLine(), 0,
+ validationInfo.getFileURI(), null, jsf2ValidationComponent
+ .getMessageParams());
+ }
+
+ public static IJSF2ValidationComponent[] getValidationComponents(Node node,
+ 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
+ .entrySet();
+ 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]);
+ }
+ }
+ }
+ }
+ IDOMAttr[] attrs = JSF2ComponentUtil.findURIContainers(node);
+ Set<String> attrValuesSet = new HashSet<String>(0);
+ for (int i = 0; i < attrs.length; i++) {
+ if (!attrValuesSet.contains(attrs[i].getValue())) {
+ attrValuesSet.add(attrs[i].getValue());
+ IJSF2ValidationComponent validationComponent = JSF2ComponentRecognizer
+ .recognizeURIValidationComponent(file.getProject(),
+ attrs[i]);
+ if (validationComponent != null) {
+ components.add(validationComponent);
+ }
+ }
+ }
+ return components.toArray(new IJSF2ValidationComponent[0]);
+ }
+}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeAttrs.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeAttrs.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeAttrs.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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.action;
+
+import java.util.Map;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
+import org.jboss.tools.jsf.JSFModelPlugin;
+import org.jboss.tools.jsf.messages.JSFUIMessages;
+import org.jboss.tools.jsf.web.validation.jsf2.JSF2XMLValidator;
+import org.jboss.tools.jsf.web.validation.jsf2.components.IJSF2ValidationComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CreateJSF2CompositeAttrs implements IMarkerResolution {
+
+ public String getLabel() {
+ return JSFUIMessages.Create_JSF_2_Interface_Attr;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void run(final IMarker marker) {
+ try {
+ Map attrsMap = marker.getAttributes();
+ Object object = attrsMap
+ .get(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY);
+ final IFile createdFile = JSF2ResourceUtil
+ .createCompositeComponentFile(
+ marker.getResource().getProject(),
+ new Path((String) object),
+ new String[] { (String) marker
+ .getAttribute(IJSF2ValidationComponent.JSF2_ATTR_NAME_KEY) });
+ marker.getResource().getProject().deleteMarkers(
+ JSF2XMLValidator.JSF2_PROBLEM_ID, false, 1);
+ if (createdFile != null) {
+ IDE.openEditor(PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage(),
+ createdFile);
+ }
+ Job validateJob = new Job("JSF 2 Components Validator") { //$NON-NLS-1$
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ ValidationFramework.getDefault().validate(
+ new IProject[] { marker.getResource()
+ .getProject() }, false, false,
+ new NullProgressMonitor());
+ } catch (CoreException e) {
+ return new Status(IStatus.CANCEL,
+ JSFModelPlugin.PLUGIN_ID, "Cancel"); //$NON-NLS-1$
+ }
+ return IValidatorJob.OK_STATUS;
+ }
+ };
+ validateJob.schedule(500);
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ }
+ }
+
+}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeComponent.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeComponent.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeComponent.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * 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.action;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
+import org.jboss.tools.jsf.JSFModelPlugin;
+import org.jboss.tools.jsf.messages.JSFUIMessages;
+import org.jboss.tools.jsf.web.validation.jsf2.JSF2XMLValidator;
+import org.jboss.tools.jsf.web.validation.jsf2.components.IJSF2ValidationComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CreateJSF2CompositeComponent implements IMarkerResolution {
+
+ public String getLabel() {
+ return JSFUIMessages.Create_JSF_2_Composite_Component;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void run(final IMarker marker) {
+ try {
+ Map attrsMap = marker.getAttributes();
+ Object object = attrsMap
+ .get(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY);
+ final IFile createdFile = JSF2ResourceUtil
+ .createCompositeComponentFile(marker.getResource()
+ .getProject(), new Path((String) object),
+ getAttributes(marker));
+ marker.getResource().deleteMarkers(
+ JSF2XMLValidator.JSF2_PROBLEM_ID, false, 1);
+ if (createdFile != null) {
+ IDE.openEditor(PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage(),
+ createdFile);
+ }
+ Job validateJob = new Job("JSF 2 Components Validator") { //$NON-NLS-1$
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ ValidationFramework.getDefault().validate(
+ new IProject[] { marker.getResource()
+ .getProject() }, false, false,
+ new NullProgressMonitor());
+ } catch (CoreException e) {
+ return new Status(IStatus.CANCEL,
+ JSFModelPlugin.PLUGIN_ID, "Cancel"); //$NON-NLS-1$
+ }
+ return IValidatorJob.OK_STATUS;
+ }
+ };
+ validateJob.schedule(500);
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private String[] getAttributes(IMarker marker) throws CoreException {
+ Map attrsMap = marker.getAttributes();
+ if (attrsMap != null) {
+ Set<String> set = new HashSet<String>(0);
+ Set<Entry> entries = attrsMap.entrySet();
+ for (Entry entry : entries) {
+ String key = (String) entry.getKey();
+ if (key.startsWith(IJSF2ValidationComponent.JSF2_ATTR_NAME_KEY)) {
+ set.add((String) entry.getValue());
+ }
+ }
+ return set.toArray(new String[0]);
+ }
+ return null;
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2ResourcesFolder.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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.action;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
+import org.jboss.tools.jsf.JSFModelPlugin;
+import org.jboss.tools.jsf.messages.JSFUIMessages;
+import org.jboss.tools.jsf.web.validation.jsf2.JSF2XMLValidator;
+import org.jboss.tools.jsf.web.validation.jsf2.components.IJSF2ValidationComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CreateJSF2ResourcesFolder implements IMarkerResolution {
+
+ public String getLabel() {
+ return JSFUIMessages.Create_JSF_2_Resources_Folder;
+ }
+
+ public void run(final IMarker marker) {
+ try {
+ JSF2ResourceUtil.createResourcesFolderByNameSpace(marker
+ .getResource().getProject(), (String) marker
+ .getAttribute(IJSF2ValidationComponent.JSF2_URI_NAME_KEY));
+ marker.getResource().getProject().deleteMarkers(
+ JSF2XMLValidator.JSF2_PROBLEM_ID, false, 1);
+ Job validateJob = new Job("JSF 2 Components Validator") { //$NON-NLS-1$
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ ValidationFramework.getDefault().validate(
+ new IProject[] { marker.getResource()
+ .getProject() }, false, false,
+ new NullProgressMonitor());
+ } catch (CoreException e) {
+ return new Status(IStatus.CANCEL,
+ JSFModelPlugin.PLUGIN_ID, "Cancel"); //$NON-NLS-1$
+ }
+ return IValidatorJob.OK_STATUS;
+ }
+ };
+ validateJob.schedule(500);
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ }
+ }
+
+}
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-04-29
16:20:08 UTC (rev 21798)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2ComponentResolutionGenerator.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -1,13 +1,13 @@
- /*******************************************************************************
- * 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
- ******************************************************************************/
+/*******************************************************************************
+ * 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.action;
@@ -16,13 +16,13 @@
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator;
import org.jboss.tools.jsf.JSFModelPlugin;
-import org.jboss.tools.jsf.web.validation.jsf2.JSF2Validator;
-import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
+import org.jboss.tools.jsf.web.validation.jsf2.JSF2XMLValidator;
+import org.jboss.tools.jsf.web.validation.jsf2.components.IJSF2ValidationComponent;
/**
*
* @author yzhishko
- *
+ *
*/
public class JSF2ComponentResolutionGenerator implements
@@ -32,16 +32,28 @@
try {
String markerType = marker.getType();
if (markerType == null
- || !JSF2Validator.JSF2_PROBLEM_ID.equals(markerType)) {
+ || !JSF2XMLValidator.JSF2_PROBLEM_ID.equals(markerType)) {
return new IMarkerResolution[0];
}
- if (marker.getAttribute(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY) == null) {
- return new IMarkerResolution[0];
+ String fixType = (String) marker
+ .getAttribute(IJSF2ValidationComponent.JSF2_TYPE_KEY);
+ if (fixType != null) {
+ if (fixType
+ .equals(IJSF2ValidationComponent.JSF2_COMPOSITE_COMPONENT_TYPE)) {
+ return new IMarkerResolution[] { new CreateJSF2CompositeComponent() };
+ }
+ if (fixType
+ .equals(IJSF2ValidationComponent.JSF2_FIXABLE_ATTR_TYPE)) {
+ return new IMarkerResolution[] { new CreateJSF2CompositeAttrs() };
+ }
+ if (fixType.equals(IJSF2ValidationComponent.JSF2_URI_TYPE)) {
+ return new IMarkerResolution[] { new CreateJSF2ResourcesFolder() };
+ }
}
} catch (CoreException e) {
JSFModelPlugin.getPluginLog().logError(e);
- }
- return new JSF2MarkerResolution[] { new JSF2MarkerResolution() };
+ }
+ return new CreateJSF2CompositeComponent[] { new CreateJSF2CompositeComponent() };
}
}
Deleted:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2MarkerResolution.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2MarkerResolution.java 2010-04-29
16:20:08 UTC (rev 21798)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2MarkerResolution.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -1,82 +0,0 @@
- /*******************************************************************************
- * 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.action;
-
-import java.util.Map;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.ui.IMarkerResolution;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.IDE;
-import org.eclipse.wst.validation.ValidationFramework;
-import org.jboss.tools.jsf.JSFModelPlugin;
-import org.jboss.tools.jsf.messages.JSFUIMessages;
-import org.jboss.tools.jsf.web.validation.jsf2.JSF2Validator;
-import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
-
-/**
- *
- * @author yzhishko
- *
- */
-
-public class JSF2MarkerResolution implements IMarkerResolution {
-
- public String getLabel() {
- return JSFUIMessages.Create_JSF_2_Composition_Component;
- }
-
- @SuppressWarnings("unchecked")
- public void run(final IMarker marker) {
- try {
- Map attrsMap = marker.getAttributes();
- Object object = attrsMap
- .get(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY);
- final IFile createdFile = JSF2ResourceUtil
- .createJSF2CompositeComponent(marker.getResource()
- .getProject(), new Path((String) object));
- marker.getResource().deleteMarkers(JSF2Validator.JSF2_PROBLEM_ID,
- false, 1);
- if (createdFile != null) {
- IDE.openEditor(PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage(),
- createdFile);
- }
- new Thread("JSF2 Validator") { //$NON-NLS-1$
- public void run() {
- SafeRunner.run(new SafeRunnable() {
-
- public void run() throws Exception {
- try {
- ValidationFramework.getDefault().validate(
- new IProject[] { marker.getResource()
- .getProject() }, false, false,
- new NullProgressMonitor());
- } catch (CoreException e) {
- JSFModelPlugin.getPluginLog().logError(e);
- }
- }
- });
- };
- }.start();
- } catch (CoreException e) {
- JSFModelPlugin.getPluginLog().logError(e);
- }
- }
-
-}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/IJSF2ValidationComponent.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/IJSF2ValidationComponent.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/IJSF2ValidationComponent.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public interface IJSF2ValidationComponent {
+
+ String JSF2_TYPE_KEY = "JSF2_TYPE_KEY"; //$NON-NLS-1$
+
+ String JSF2_COMPONENT_NAME_KEY = "AJSF2_COMPONENT_NAME_KEY"; //$NON-NLS-1$
+
+ String JSF2_ATTR_NAME_KEY = "ATTR_NAME_KEY"; //$NON-NLS-1$
+
+ String JSF2_URI_NAME_KEY = "JSF2_URI_NAME_KEY"; //$NON-NLS-1$
+
+ String JSF2_URI_TYPE_KEY = "JSF2_URI_TYPE_KEY"; //$NON-NLS-1$
+
+ String JSF2_COMPOSITE_COMPONENT_TYPE = "JSF2_COMPOSITE_COMPONENT_TYPE";
//$NON-NLS-1$
+
+ String JSF2_UNFIXABLE_ATTR_TYPE = "JSF2_UNFIXABLE_ATTR_TYPE"; //$NON-NLS-1$
+
+ String JSF2_FIXABLE_ATTR_TYPE = "JSF2_FIXABLE_ATTR_TYPE"; //$NON-NLS-1$
+
+ String JSF2_URI_TYPE = "JSF2_URI_TYPE"; //$NON-NLS-1$
+
+ int getLine();
+
+ int getStartOffSet();
+
+ int getLength();
+
+ String getValidationMessage();
+
+ Object[] getMessageParams();
+
+ String getType();
+
+ String getComponentResourceLocation();
+
+ int getSeverity();
+
+}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2AttrTempComponent.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
+import org.jboss.tools.jsf.messages.JSFUIMessages;
+import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class JSF2AttrTempComponent implements IJSF2ValidationComponent {
+
+ private int length;
+ private int startOffSet;
+ private int line;
+ private String validationMessage = ""; //$NON-NLS-1$
+ private Object[] messageParams;
+ private String type = JSF2_UNFIXABLE_ATTR_TYPE;
+ private ElementImpl parentEl;
+ private IDOMAttr attr;
+ private String componentResLocation;
+
+ public JSF2AttrTempComponent(IDOMAttr attr, ElementImpl parentEl) {
+ this.attr = attr;
+ this.parentEl = parentEl;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ void setLength(int length) {
+ this.length = length;
+ }
+
+ public int getLine() {
+ return line;
+ }
+
+ void setLine(int lineNumber) {
+ this.line = lineNumber;
+ }
+
+ public int getStartOffSet() {
+ return startOffSet;
+ }
+
+ void setStartOffSet(int startOffSet) {
+ this.startOffSet = startOffSet;
+ }
+
+ void createValidationMessage() {
+ String nodeName = parentEl.getNodeName();
+ if (nodeName.indexOf(':') > -1) {
+ nodeName = nodeName.substring(nodeName.lastIndexOf(':') + 1);
+ }
+ this.validationMessage = MessageFormat.format(
+ JSFUIMessages.Missing_JSF_2_Component_Attr, attr.getName(),
+ nodeName);
+ }
+
+ public String getValidationMessage() {
+ return validationMessage;
+ }
+
+ void createMessageParams() {
+ this.messageParams = new Object[] { this };
+ }
+
+ public Object[] getMessageParams() {
+ return messageParams;
+ }
+
+ void setType(String type) {
+ this.type = type;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getName() {
+ return attr.getName();
+ }
+
+ public String getComponentResourceLocation() {
+ if (componentResLocation == null) {
+ 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);
+ }
+ componentResLocation = relativeLocation + "/" + nodeName +
".xhtml"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return componentResLocation;
+ }
+
+ public int getSeverity() {
+ return IMessage.NORMAL_SEVERITY;
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2ComponentFactory.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * 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.util.ArrayList;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import org.eclipse.core.resources.IFile;
+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;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class JSF2ComponentFactory {
+
+ public static IJSF2ValidationComponent createCompositeTempComponent(
+ IDOMElement element) {
+ JSF2CompositeTempComponent component = new JSF2CompositeTempComponent(
+ (ElementImpl) element);
+ component.setStartOffSet(element.getStartOffset());
+ component.setLength(element.getStartEndOffset()
+ - component.getStartOffSet());
+ component.setLine(element.getStructuredDocument().getLineOfOffset(
+ component.getStartOffSet()) + 1);
+ component.createValidationMessage();
+ component.createMessageParams();
+ return component;
+ }
+
+ public static IJSF2ValidationComponent[] createUnfixableAttrTempComponents(
+ ZipEntry zipContainer, IDOMElement elementWithAttrs) {
+ return null;
+ }
+
+ public static IJSF2ValidationComponent[] createFixableAttrTempComponents(
+ IFile compContainerFile, IDOMElement elementWithAttrs) {
+ List<IJSF2ValidationComponent> components = new
ArrayList<IJSF2ValidationComponent>(
+ 0);
+ IDOMDocument document = JSF2ComponentUtil
+ .getReadableDocumentForFile(compContainerFile);
+ IDOMElement interfaceElement = JSF2ComponentModelManager.getManager()
+ .checkCompositeInterface(document);
+ List<String> interfaceAttrs = getInterfaceAttrs(interfaceElement);
+ 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_FIXABLE_ATTR_TYPE);
+ component.setStartOffSet(attr.getStartOffset());
+ component.setLine(attr.getStructuredDocument().getLineOfOffset(
+ component.getStartOffSet()) + 1);
+ component.setLength(attr.getName().length());
+ component.createValidationMessage();
+ component.createMessageParams();
+ components.add(component);
+ }
+ }
+ return components.toArray(new IJSF2ValidationComponent[0]);
+ }
+
+ public static IJSF2ValidationComponent createURITempComponent(
+ IDOMAttr attrContainer) {
+ JSF2URITempComponent component = new JSF2URITempComponent(attrContainer
+ .getValue());
+ component.setStartOffSet(attrContainer.getStartOffset());
+ component.setLength(attrContainer.getValueRegionStartOffset()
+ - component.getStartOffSet()
+ + attrContainer.getValue().length() + 2);
+ component.setLine(attrContainer.getStructuredDocument()
+ .getLineOfOffset(component.getStartOffSet()) + 1);
+ component.createMessageParams();
+ component.createValidationMessage();
+ return component;
+ }
+
+ private static List<String> getInterfaceAttrs(IDOMElement interfaceElement) {
+ List<String> interfaceAttrs = new ArrayList<String>(0);
+ if (interfaceElement != null) {
+ String prefix = interfaceElement.getPrefix();
+ String nodeName = "attribute"; //$NON-NLS-1$
+ if (prefix != null && !"".equals(prefix)) { //$NON-NLS-1$
+ nodeName = prefix + ":" + nodeName; //$NON-NLS-1$
+ }
+ NodeList attrsElements = interfaceElement
+ .getElementsByTagName(nodeName);
+ if (attrsElements != null) {
+ for (int i = 0; i < attrsElements.getLength(); i++) {
+ Node el = attrsElements.item(i);
+ if (el instanceof IDOMElement) {
+ IDOMElement element = (IDOMElement) el;
+ String attrvalue = element.getAttribute("name"); //$NON-NLS-1$
+ if (attrvalue != null && !"".equals(attrvalue)) { //$NON-NLS-1$
+ interfaceAttrs.add(attrvalue);
+ }
+ }
+ }
+ }
+ }
+ return interfaceAttrs;
+ }
+
+ private static IDOMAttr[] getExistingAttrs(IDOMElement validateElement) {
+ List<IDOMAttr> existingAttrs = new ArrayList<IDOMAttr>(0);
+ NamedNodeMap attrsMap = validateElement.getAttributes();
+ if (attrsMap != null) {
+ for (int i = 0; i < attrsMap.getLength(); i++) {
+ Node node = attrsMap.item(i);
+ if (node instanceof IDOMAttr) {
+ existingAttrs.add((IDOMAttr) node);
+ }
+ }
+ }
+ return existingAttrs.toArray(new IDOMAttr[0]);
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2CompositeTempComponent.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,106 @@
+package org.jboss.tools.jsf.web.validation.jsf2.components;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
+import org.jboss.tools.jsf.messages.JSFUIMessages;
+import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
+import org.w3c.dom.NamedNodeMap;
+
+@SuppressWarnings("restriction")
+public class JSF2CompositeTempComponent implements IJSF2ValidationComponent {
+ private int length;
+ private int startOffSet;
+ private int line;
+ private String validationMessage = ""; //$NON-NLS-1$
+ private Object[] messageParams;
+ private List<String> attrNames = new ArrayList<String>(0);
+ private ElementImpl element;
+ private String componentResLoc;
+
+ public JSF2CompositeTempComponent(ElementImpl element) {
+ this.element = element;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ void setLength(int length) {
+ this.length = length;
+ }
+
+ public int getLine() {
+ return line;
+ }
+
+ void setLine(int lineNumber) {
+ this.line = lineNumber;
+ }
+
+ public int getStartOffSet() {
+ return startOffSet;
+ }
+
+ void setStartOffSet(int startOffSet) {
+ this.startOffSet = startOffSet;
+ }
+
+ void createValidationMessage() {
+ String nodeName = element.getNodeName();
+ if (nodeName.indexOf(':') > -1) {
+ nodeName = nodeName.substring(nodeName.lastIndexOf(':') + 1);
+ }
+ this.validationMessage = MessageFormat.format(
+ JSFUIMessages.Missing_JSF_2_Composite_Component, nodeName);
+ }
+
+ public String getValidationMessage() {
+ return validationMessage;
+ }
+
+ void createMessageParams() {
+ NamedNodeMap attrsMap = element.getAttributes();
+ if (attrsMap != null && attrsMap.getLength() != 0) {
+ for (int i = 0; i < attrsMap.getLength(); i++) {
+ IDOMAttr attr = (IDOMAttr) attrsMap.item(i);
+ attrNames.add(attr.getName());
+ }
+ }
+ this.messageParams = new Object[] { this };
+ }
+
+ public Object[] getMessageParams() {
+ return messageParams;
+ }
+
+ public String[] getAttrNames() {
+ return attrNames.toArray(new String[0]);
+ }
+
+ public String getType() {
+ return JSF2_COMPOSITE_COMPONENT_TYPE;
+ }
+
+ public String getComponentResourceLocation() {
+ if (componentResLoc == null) {
+ 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);
+ }
+ componentResLoc = relativeLocation + "/" + nodeName + ".xhtml";
//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return componentResLoc;
+ }
+
+ public int getSeverity() {
+ return IMessage.NORMAL_SEVERITY;
+ }
+
+}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2URITempComponent.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2URITempComponent.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2URITempComponent.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * 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;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.jboss.tools.jsf.messages.JSFUIMessages;
+import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class JSF2URITempComponent implements IJSF2ValidationComponent {
+
+ private int length;
+ private int startOffSet;
+ private int line;
+ private String validationMessage = ""; //$NON-NLS-1$
+ private Object[] messageParams;
+ private String URI;
+
+ public JSF2URITempComponent(String URI) {
+ this.URI = URI;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ void setLength(int length) {
+ this.length = length;
+ }
+
+ public int getLine() {
+ return line;
+ }
+
+ void setLine(int lineNumber) {
+ this.line = lineNumber;
+ }
+
+ public int getStartOffSet() {
+ return startOffSet;
+ }
+
+ void setStartOffSet(int startOffSet) {
+ this.startOffSet = startOffSet;
+ }
+
+ void createValidationMessage() {
+ String mesParam = "/resources" +
URI.replaceAll(JSF2ResourceUtil.JSF2_URI_PREFIX, ""); //$NON-NLS-1$
//$NON-NLS-2$
+ this.validationMessage = MessageFormat.format(
+ JSFUIMessages.Missing_JSF_2_Resources_Folder, mesParam);
+ }
+
+ public String getValidationMessage() {
+ return validationMessage;
+ }
+
+ public Object[] getMessageParams() {
+ return messageParams;
+ }
+
+ void createMessageParams() {
+ messageParams = new Object[] { this };
+ }
+
+ public String getType() {
+ return JSF2_URI_TYPE;
+ }
+
+ public String getComponentResourceLocation() {
+ return ""; //$NON-NLS-1$
+ }
+
+ public int getSeverity() {
+ return IMessage.NORMAL_SEVERITY;
+ }
+
+ public String getURI() {
+ return URI;
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentModelManager.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * 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.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+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.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.format.DocumentNodeFormatter;
+import org.jboss.tools.jsf.JSFModelPlugin;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class JSF2ComponentModelManager {
+
+ private static JSF2ComponentModelManager instance = new JSF2ComponentModelManager();
+
+ private JSF2ComponentModelManager() {
+
+ }
+
+ public static JSF2ComponentModelManager getManager() {
+ return instance;
+ }
+
+ public IFile updateJSF2CompositeComponentFile(
+ IFile componentFileContatiner, String[] attrNames) {
+ IDOMDocument document = null;
+ IModelManager manager = StructuredModelManager.getModelManager();
+ if (manager == null) {
+ return componentFileContatiner;
+ }
+ IStructuredModel model = null;
+ try {
+ model = manager.getModelForEdit(componentFileContatiner);
+ if (model instanceof IDOMModel) {
+ IDOMModel domModel = (IDOMModel) model;
+ 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);
+ }
+ }
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ } catch (IOException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ } finally {
+ if (model != null) {
+ model.releaseFromEdit();
+ }
+ }
+ return componentFileContatiner;
+ }
+
+ public void updateJSF2CompositeComponent(IDOMDocument componentDoc,
+ String[] attrNames) {
+ IDOMElement[] interfaceElement = new IDOMElement[1];
+ findInterfaceComponent(componentDoc, interfaceElement);
+ createCompositeCompInterface(interfaceElement[0], attrNames);
+ }
+
+ private void findInterfaceComponent(Node node,
+ IDOMElement[] interfaceElement) {
+ if (node instanceof IDOMDocument) {
+ IDOMDocument document = (IDOMDocument) node;
+ findInterfaceComponent(document.getDocumentElement(),
+ interfaceElement);
+ }
+ if (node instanceof ElementImpl) {
+ 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$
+ interfaceElement[0] = impl;
+ return;
+ }
+ } else {
+ NodeList nodeList = node.getChildNodes();
+ if (nodeList != null) {
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ findInterfaceComponent(nodeList.item(i),
+ interfaceElement);
+ }
+ }
+ }
+ }
+ }
+
+ private void createCompositeCompInterface(IDOMElement element,
+ String[] attrNames) {
+ Document document = (Document) element.getOwnerDocument();
+ String prefix = element.getPrefix();
+ if (prefix != null && !"".equals(prefix)) { //$NON-NLS-1$
+ for (int i = 0; i < attrNames.length; i++) {
+ Element attrEl = document
+ .createElementNS(JSF2ResourceUtil.JSF2_URI_PREFIX,
+ prefix + ":attribute"); //$NON-NLS-1$
+ attrEl.setAttribute("name", attrNames[i]); //$NON-NLS-1$
+ element.appendChild(attrEl);
+ }
+ } else {
+ for (int i = 0; i < attrNames.length; i++) {
+ Element attrEl = document.createElementNS(
+ JSF2ResourceUtil.JSF2_URI_PREFIX, "attribute"); //$NON-NLS-1$
+ attrEl.setAttribute("name", attrNames[i]); //$NON-NLS-1$
+ element.appendChild(attrEl);
+ }
+ }
+ DocumentNodeFormatter formatter = new DocumentNodeFormatter();
+ formatter.format(document);
+ }
+
+ public IFile revalidateCompositeComponentFile(IFile file) {
+ IDOMDocument document = JSF2ComponentUtil
+ .getReadableDocumentForFile(file);
+ if (document == null) {
+ return null;
+ }
+ IDOMElement interfaceElement = checkCompositeInterface(document);
+ if (interfaceElement == null) {
+ return null;
+ }
+ return file;
+ }
+
+ public IDOMElement checkCompositeInterface(IDOMDocument document) {
+ if (document == null) {
+ return null;
+ }
+ Element element = document.getDocumentElement();
+ if (element == null) {
+ return null;
+ }
+ if (!"html".equals(element.getNodeName())) { //$NON-NLS-1$
+ return null;
+ }
+ ElementImpl elementImpl = (ElementImpl) element;
+ if (!"http://www.w3.org/1999/xhtml".equals(elementImpl.getNamespaceURI())) {
//$NON-NLS-1$
+ return null;
+ }
+ NodeList children = element.getChildNodes();
+ if (children == null) {
+ return null;
+ }
+ 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$
+ }
+ if ("interface".equals(nodeName)) { //$NON-NLS-1$
+ if (JSF2ResourceUtil.JSF2_URI_PREFIX
+ .equals(((ElementImpl) el).getNamespaceURI())) {
+ return (IDOMElement) el;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+}
Deleted:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentParams.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentParams.java 2010-04-29
16:20:08 UTC (rev 21798)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentParams.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -1,62 +0,0 @@
- /*******************************************************************************
- * 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.util;
-
-import org.eclipse.wst.xml.core.internal.document.ElementImpl;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-
-/**
- *
- * @author yzhishko
- *
- */
-
-@SuppressWarnings("restriction")
-public class JSF2ComponentParams {
-
- private String relativeLocation;
-
- private JSF2ComponentParams() {
-
- }
-
- public static JSF2ComponentParams create(IDOMElement element) {
- JSF2ComponentParams componentParams = new JSF2ComponentParams();
- if (element != null) {
- ElementImpl elementImpl = (ElementImpl) element;
- String nameSpaceURI = elementImpl.getNamespaceURI();
- if (nameSpaceURI == null
- || nameSpaceURI.indexOf(JSF2ResourceUtil.JSF2_URI_PREFIX) == -1) {
- return null;
- }
- String nodeName = element.getNodeName();
- if (nodeName.lastIndexOf(':') != -1) {
- nodeName = nodeName.substring(nodeName.lastIndexOf(':') + 1);
- }
- String relativeLocation = nameSpaceURI.replaceFirst(
- JSF2ResourceUtil.JSF2_URI_PREFIX, ""); //$NON-NLS-1$
- componentParams.setRelativateLocation(relativeLocation
- + "/" + nodeName + ".xhtml"); //$NON-NLS-1$ //$NON-NLS-2$
-
- }
- return componentParams;
- }
-
- public void setRelativateLocation(String relativateLocation) {
- this.relativeLocation = relativateLocation;
- }
-
- public String getRelativateLocation() {
- return relativeLocation;
- }
-
-}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentRecognizer.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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.util;
+
+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.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;
+import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2ComponentFactory;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class JSF2ComponentRecognizer {
+
+ public static IJSF2ValidationComponent[] recognizeCompositeValidationComponents(
+ IFile file, IDOMElement element) {
+ List<IJSF2ValidationComponent> validationComponents = new
ArrayList<IJSF2ValidationComponent>(
+ 0);
+ Object container = JSF2ResourceUtil.findCompositeComponentContainer(
+ file.getProject(), element);
+ if (container == null) {
+ IJSF2ValidationComponent component = JSF2ComponentFactory
+ .createCompositeTempComponent(element);
+ validationComponents.add(component);
+ } else if (container instanceof IFile) {
+ IJSF2ValidationComponent[] components = JSF2ComponentFactory
+ .createFixableAttrTempComponents((IFile) container, element);
+ for (int i = 0; i < components.length; i++) {
+ validationComponents.add(components[i]);
+ }
+ } else if (container instanceof ZipEntry) {
+ IJSF2ValidationComponent[] components = JSF2ComponentFactory
+ .createUnfixableAttrTempComponents((ZipEntry) container,
+ element);
+ for (int i = 0; i < components.length; i++) {
+ validationComponents.add(components[i]);
+ }
+ }
+ return validationComponents.toArray(new IJSF2ValidationComponent[0]);
+ }
+
+ public static IJSF2ValidationComponent recognizeURIValidationComponent(
+ IProject project, IDOMAttr attrContainer) {
+ if (!JSF2ResourceUtil.isResourcesFolderExists(project, attrContainer
+ .getValue())) {
+ return JSF2ComponentFactory.createURITempComponent(attrContainer);
+ }
+ return null;
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentUtil.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * 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.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;
+import org.w3c.dom.NodeList;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class JSF2ComponentUtil {
+
+ public static Map<String, List<Element>> findCompositeComponents(Node node)
{
+ Map<String, List<Element>> elementsMap = new HashMap<String,
List<Element>>(
+ 0);
+ findChildCompositeComponents(node, elementsMap);
+ return elementsMap;
+ }
+
+ private static void findChildCompositeComponents(Node node,
+ Map<String, List<Element>> elementsMap) {
+ if (node instanceof IDOMDocument) {
+ node = ((IDOMDocument) node).getDocumentElement();
+ findChildCompositeComponents(node, elementsMap);
+ } else if (node instanceof ElementImpl) {
+ ElementImpl elementImpl = (ElementImpl) node;
+ String namespaceURI = elementImpl.getNamespaceURI();
+ if (namespaceURI != null
+ && namespaceURI
+ .startsWith(JSF2ResourceUtil.JSF2_URI_PREFIX)
+ && !namespaceURI.equals(JSF2ResourceUtil.JSF2_URI_PREFIX)) {
+ List<Element> elements = elementsMap.get(namespaceURI);
+ if (elements == null) {
+ elements = new ArrayList<Element>(0);
+ }
+ elements.add(elementImpl);
+ elementsMap.put(namespaceURI, elements);
+ }
+ NodeList children = node.getChildNodes();
+ if (children != null) {
+ for (int i = 0; i < children.getLength(); i++) {
+ findChildCompositeComponents(children.item(i), elementsMap);
+ }
+ }
+ }
+ }
+
+ 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);
+ return attrs.toArray(new IDOMAttr[0]);
+ }
+
+ private static void findChildURIContainers(Node node,
+ List<IDOMAttr> attrsList) {
+ if (node instanceof IDOMDocument) {
+ node = ((IDOMDocument) node).getDocumentElement();
+ findChildURIContainers(node, attrsList);
+ } else if (node instanceof ElementImpl) {
+ ElementImpl elementImpl = (ElementImpl) node;
+ NamedNodeMap attrsMap = elementImpl.getAttributes();
+ if (attrsMap != null && attrsMap.getLength() != 0) {
+ for (int i = 0; i < attrsMap.getLength(); i++) {
+ IDOMAttr attr = (IDOMAttr) attrsMap.item(i);
+ String attrValue = attr.getValue();
+ if (attrValue != null
+ && attrValue
+ .indexOf(JSF2ResourceUtil.JSF2_URI_PREFIX) > -1) {
+ String compPath = attrValue.replaceFirst(
+ JSF2ResourceUtil.JSF2_URI_PREFIX, ""); //$NON-NLS-1$
+ if (!"".equals(compPath.trim())) { //$NON-NLS-1$
+ if (isCorrectCompositeShemaAttrName(attr.getName())) {
+ attrsList.add(attr);
+ }
+ }
+ }
+ }
+ }
+ NodeList children = node.getChildNodes();
+ if (children != null) {
+ for (int i = 0; i < children.getLength(); i++) {
+ findChildURIContainers((IDOMNode) children.item(i),
+ attrsList);
+ }
+ }
+ }
+ }
+
+ private static boolean isCorrectCompositeShemaAttrName(String attrName) {
+ if (attrName == null) {
+ return false;
+ }
+ if ("xmlns".equals(attrName.trim()) ||
"uri".equals(attrName.trim())) { //$NON-NLS-1$ //$NON-NLS-2$
+ return true;
+ }
+ if (attrName.indexOf(':') < 0) {
+ return false;
+ }
+ attrName = attrName.substring(0, attrName.indexOf(':')).trim();
+ if ("xmlns".equals(attrName)) { //$NON-NLS-1$
+ return true;
+ }
+ return false;
+ }
+
+}
Deleted:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentsUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentsUtil.java 2010-04-29
16:20:08 UTC (rev 21798)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentsUtil.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -1,69 +0,0 @@
- /*******************************************************************************
- * 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.util;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.eclipse.wst.xml.core.internal.document.ElementImpl;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- *
- * @author yzhishko
- *
- */
-
-@SuppressWarnings("restriction")
-public class JSF2ComponentsUtil {
-
- public static Map<String, List<Element>> findJSF2CompositeComponents(
- IDOMDocument document) {
- Map<String, List<Element>> elementsMap = new HashMap<String,
List<Element>>(
- 0);
- findJSF2ChildCompositeComponents(document, elementsMap);
- return elementsMap;
- }
-
- private static void findJSF2ChildCompositeComponents(Node node,
- Map<String, List<Element>> elementsMap) {
- if (node instanceof IDOMDocument) {
- node = ((IDOMDocument) node).getDocumentElement();
- findJSF2ChildCompositeComponents(node, elementsMap);
- } else if (node instanceof ElementImpl) {
- ElementImpl elementImpl = (ElementImpl) node;
- String namespaceURI = elementImpl.getNamespaceURI();
- if (namespaceURI != null
- && namespaceURI
- .startsWith(JSF2ResourceUtil.JSF2_URI_PREFIX)
- && !namespaceURI.equals(JSF2ResourceUtil.JSF2_URI_PREFIX)) {
- List<Element> elements = elementsMap.get(namespaceURI);
- if (elements == null) {
- elements = new ArrayList<Element>(0);
- }
- elements.add(elementImpl);
- elementsMap.put(namespaceURI, elements);
- }
- NodeList children = node.getChildNodes();
- if (children != null) {
- for (int i = 0; i < children.getLength(); i++) {
- findJSF2ChildCompositeComponents(children.item(i), elementsMap);
- }
- }
- }
- }
-
-}
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-04-29
16:20:08 UTC (rev 21798)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ResourceUtil.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -1,18 +1,17 @@
- /*******************************************************************************
- * 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
- ******************************************************************************/
+/*******************************************************************************
+ * 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.util;
import java.util.zip.ZipEntry;
-
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -37,7 +36,7 @@
/**
*
* @author yzhishko
- *
+ *
*/
@SuppressWarnings("restriction")
@@ -47,12 +46,12 @@
public static final String COMPONENT_RESOURCE_PATH_KEY =
"component_resource_path_key"; //$NON-NLS-1$
- public static boolean isJSF2CompositeComponentExists(IProject project,
+ public static Object findCompositeComponentContainer(IProject project,
IDOMElement jsf2Element) {
ElementImpl elementImpl = (ElementImpl) jsf2Element;
String nameSpaceURI = elementImpl.getNamespaceURI();
if (nameSpaceURI == null || nameSpaceURI.indexOf(JSF2_URI_PREFIX) == -1) {
- return false;
+ return null;
}
String nodeName = jsf2Element.getNodeName();
if (nodeName.lastIndexOf(':') != -1) {
@@ -69,15 +68,109 @@
"/" + nodeName + ".xhtml"); //$NON-NLS-1$ //$NON-NLS-2$
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
if (file.exists()) {
- return true;
+ return file;
}
}
return searchInClassPath(project, "META-INF" + relativeLocation
//$NON-NLS-1$
+ "/" + nodeName + ".xhtml"); //$NON-NLS-1$ //$NON-NLS-2$
}
- public static IFile createJSF2CompositeComponent(IProject project,
+ private static ZipEntry searchInClassPath(IProject project,
+ String classPathResource) {
+ IJavaProject javaProject = JavaCore.create(project);
+ try {
+ for (IPackageFragmentRoot fragmentRoot : javaProject
+ .getAllPackageFragmentRoots()) {
+ if (fragmentRoot instanceof JarPackageFragmentRoot) {
+ JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot)
fragmentRoot;
+ ZipEntry zipEntry = jarPackageFragmentRoot.getJar()
+ .getEntry(classPathResource);
+ if (zipEntry != null) {
+ return zipEntry;
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ }
+ return null;
+ }
+
+ public static IPath findResourcesFolderByNameSpace(IProject project,
+ String nameSpaceURI) {
+ if (nameSpaceURI == null || nameSpaceURI.indexOf(JSF2_URI_PREFIX) == -1) {
+ return null;
+ }
+ String relativeLocation = "/resources" + nameSpaceURI.replaceFirst(
//$NON-NLS-1$
+ JSF2ResourceUtil.JSF2_URI_PREFIX, ""); //$NON-NLS-1$
+ IVirtualComponent component = ComponentCore.createComponent(project);
+ if (component != null) {
+ IVirtualFolder webRootFolder = component.getRootFolder().getFolder(
+ new Path("/")); //$NON-NLS-1$
+ IContainer folder = webRootFolder.getUnderlyingFolder();
+ IPath path = folder.getFullPath().append(relativeLocation);
+ IFolder resFolder = ResourcesPlugin.getWorkspace().getRoot()
+ .getFolder(path);
+ if (resFolder.exists()) {
+ return resFolder.getFullPath();
+ }
+ }
+ return null;
+ }
+
+ public static boolean isResourcesFolderExists(IProject project,
+ String nameSpaceURI) {
+ return findResourcesFolderByNameSpace(project, nameSpaceURI) == null ? false
+ : true;
+ }
+
+ public static IFolder createResourcesFolderByNameSpace(IProject project,
+ String nameSpaceURI) throws CoreException {
+ IFolder compositeCompResFolder = null;
+ String relativeLocation = nameSpaceURI.replaceFirst(
+ JSF2ResourceUtil.JSF2_URI_PREFIX, ""); //$NON-NLS-1$
+ if (!project.exists()) {
+ return null;
+ }
+ if (!project.isAccessible()) {
+ try {
+ project.open(new NullProgressMonitor());
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ return compositeCompResFolder;
+ }
+ }
+ IVirtualComponent component = ComponentCore.createComponent(project);
+ if (component != null) {
+ IVirtualFolder webRootFolder = component.getRootFolder().getFolder(
+ new Path("/")); //$NON-NLS-1$
+ IContainer folder = webRootFolder.getUnderlyingFolder();
+ IFolder webFolder = ResourcesPlugin.getWorkspace().getRoot()
+ .getFolder(folder.getFullPath());
+ IFolder resourcesFolder = webFolder.getFolder("resources"); //$NON-NLS-1$
+ NullProgressMonitor monitor = new NullProgressMonitor();
+ if (!resourcesFolder.exists()) {
+ resourcesFolder.create(true, true, monitor);
+ }
+ String[] segments = new Path(relativeLocation).segments();
+ compositeCompResFolder = resourcesFolder;
+ for (int i = 0; i < segments.length; i++) {
+ compositeCompResFolder = compositeCompResFolder
+ .getFolder(segments[i]);
+ if (!compositeCompResFolder.exists()) {
+ compositeCompResFolder.create(true, true, monitor);
+ }
+ }
+
+ }
+ return compositeCompResFolder;
+ }
+
+ public static IFile createCompositeComponentFile(IProject project,
IPath resourceRelativePath) throws CoreException {
+ IFile compositeCompResFile = null;
if (!project.exists()) {
return null;
}
@@ -86,6 +179,7 @@
project.open(new NullProgressMonitor());
} catch (CoreException e) {
JSFModelPlugin.getPluginLog().logError(e);
+ return compositeCompResFile;
}
}
IVirtualComponent component = ComponentCore.createComponent(project);
@@ -109,39 +203,33 @@
componentPathFolder.create(true, true, monitor);
}
}
- IFile file = componentPathFolder
+ compositeCompResFile = componentPathFolder
.getFile(segments[segments.length - 1]);
- if (!file.exists()) {
- file.create(JSF2TemplateManager.getManager()
+ if (!compositeCompResFile.exists()) {
+ compositeCompResFile.create(JSF2TemplateManager.getManager()
.createStreamFromTemplate("composite.xhtml"), true, //$NON-NLS-1$
monitor);
+ } else {
+ compositeCompResFile = JSF2ComponentModelManager.getManager()
+ .revalidateCompositeComponentFile(compositeCompResFile);
}
- return file;
}
- return null;
+ return compositeCompResFile;
}
- private static boolean searchInClassPath(IProject project,
- String classPathResource) {
- IJavaProject javaProject = JavaCore.create(project);
- try {
- for (IPackageFragmentRoot fragmentRoot : javaProject
- .getAllPackageFragmentRoots()) {
- if (fragmentRoot instanceof JarPackageFragmentRoot) {
- JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot)
fragmentRoot;
- ZipEntry zipEntry = jarPackageFragmentRoot.getJar()
- .getEntry(classPathResource);
- if (zipEntry != null) {
- return true;
- }
- }
- }
- } catch (JavaModelException e) {
- JSFModelPlugin.getPluginLog().logError(e);
- } catch (CoreException e) {
- JSFModelPlugin.getPluginLog().logError(e);
+ public static IFile createCompositeComponentFile(IProject project,
+ IPath resourceRelativePath, String[] attrNames)
+ throws CoreException {
+ IFile jsf2ResFile = createCompositeComponentFile(project,
+ resourceRelativePath);
+ if (jsf2ResFile == null) {
+ return null;
}
- return false;
+ if (attrNames == null || attrNames.length == 0) {
+ return jsf2ResFile;
+ }
+ return JSF2ComponentModelManager.getManager()
+ .updateJSF2CompositeComponentFile(jsf2ResFile, attrNames);
}
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2TemplateManager.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2TemplateManager.java 2010-04-29
16:20:08 UTC (rev 21798)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2TemplateManager.java 2010-04-29
16:20:09 UTC (rev 21799)
@@ -1,13 +1,13 @@
- /*******************************************************************************
- * 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
- ******************************************************************************/
+/*******************************************************************************
+ * 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.util;
@@ -16,11 +16,13 @@
/**
*
* @author yzhishko
- *
+ *
*/
public class JSF2TemplateManager {
+ public static final String COMPOSITE_COMPONENT_TEMPLATE_NAME =
"composite.xhtml"; //$NON-NLS-1$
+
private static JSF2TemplateManager instance = new JSF2TemplateManager();
private JSF2TemplateManager() {