Author: yzhishko
Date: 2010-04-21 04:46:06 -0400 (Wed, 21 Apr 2010)
New Revision: 21573
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/resources/templates/
trunk/jsf/plugins/org.jboss.tools.jsf/resources/templates/composite.xhtml
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/
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/JSF2Validator.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/
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/JSF2MarkerResolution.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/
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
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
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
trunk/jsf/plugins/org.jboss.tools.jsf/plugin.properties
trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
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
Log:
https://jira.jboss.org/jira/browse/JBIDE-5930 - first version of quick fix for composite
components
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-21 08:38:08 UTC
(rev 21572)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2010-04-21 08:46:06 UTC
(rev 21573)
@@ -44,7 +44,8 @@
org.eclipse.wst.common.modulecore,
org.eclipse.wst.validation,
org.eclipse.jdt.core.manipulation,
- org.eclipse.jst.j2ee
+ org.eclipse.jst.j2ee,
+ org.eclipse.ui.ide
Bundle-Version: 2.0.0
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/plugin.properties
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/plugin.properties 2010-04-21 08:38:08 UTC (rev
21572)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/plugin.properties 2010-04-21 08:46:06 UTC (rev
21573)
@@ -2,3 +2,7 @@
pluginName=JBoss Tools JSF
XHTML_Validator.name = XHTML Syntax Validator
+
+JSF2_ComponentsValidator.name = JSF2 Components Validator
+
+JSF2ProblemName = JSF 2 Problem
\ No newline at end of file
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2010-04-21 08:38:08 UTC (rev 21572)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2010-04-21 08:46:06 UTC (rev 21573)
@@ -499,4 +499,56 @@
<adapter type="org.eclipse.core.resources.IProject"/>
</factory>
</extension>
-</plugin>
\ No newline at end of file
+ <extension
+ id="jsf2"
+ name="%JSF2_ComponentsValidator.name"
+ point="org.eclipse.wst.validation.validatorV2">
+ <validator
+ build="true"
+
class="org.jboss.tools.jsf.web.validation.jsf2.JSF2ComponentsValidator"
+ manual="true"
+ markerId="org.jboss.tools.jsf.jsf2problemmarker"
+
sourceid="org.eclipse.wst.xml.ui.internal.validation.DelegatingSourceValidatorForXML"
+ version="4">
+ <include>
+ <rules>
+ <contentType
+ id="org.eclipse.wst.html.core.htmlsource">
+ </contentType>
+ <contentType
+ id="org.eclipse.jst.jsp.core.jspfragmentsource">
+ </contentType>
+ <contentType
+ id="org.eclipse.jst.jsp.core.tagsource">
+ </contentType>
+ <fileext
+ caseSensitive="false"
+ ext="xhtml">
+ </fileext>
+ <fileext
+ caseSensitive="false"
+ ext="jsp">
+ </fileext>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+ <extension
+ point="org.eclipse.ui.ide.markerResolution">
+ <markerResolutionGenerator
+
class="org.jboss.tools.jsf.web.validation.jsf2.action.JSF2ComponentResolutionGenerator"
+ markerType="org.jboss.tools.jsf.jsf2problemmarker">
+ </markerResolutionGenerator>
+ </extension>
+ <extension
+ id="jsf2problemmarker"
+ name="%JSF2ProblemName"
+ point="org.eclipse.core.resources.markers">
+ <super
+ type="org.eclipse.core.resources.problemmarker">
+ </super>
+ <persistent
+ value="true">
+ </persistent>
+ </extension>
+</plugin>
Added: trunk/jsf/plugins/org.jboss.tools.jsf/resources/templates/composite.xhtml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/resources/templates/composite.xhtml
(rev 0)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/resources/templates/composite.xhtml 2010-04-21
08:46:06 UTC (rev 21573)
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:composite="http://java.sun.com/jsf/composite">
+
+ <!-- INTERFACE -->
+ <composite:interface>
+ <composite:attribute name=""/>
+ </composite:interface>
+
+ <!-- IMPLEMENTATION -->
+ <composite:implementation>
+ </composite:implementation>
+
+</html>
\ No newline at end of file
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-21
08:38:08 UTC (rev 21572)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/JSFUIMessages.java 2010-04-21
08:46:06 UTC (rev 21573)
@@ -123,6 +123,7 @@
public static String DeleteManagedBeanHandler_Failure;
public static String DeleteManagedPropertyHandler_Delete;
public static String DeleteManagedPropertyHandler_DeleteJavaProperty;
+ public static String Create_JSF_2_Composition_Component;
static {
// load message values from bundle file
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-21
08:38:08 UTC (rev 21572)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/messages.properties 2010-04-21
08:46:06 UTC (rev 21573)
@@ -99,3 +99,4 @@
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
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ComponentsValidator.java 2010-04-21
08:46:06 UTC (rev 21573)
@@ -0,0 +1,111 @@
+ /*******************************************************************************
+ * 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;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext;
+import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage;
+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.util.JSF2ResourceUtil;
+import org.jboss.tools.jst.web.kb.IKbProject;
+import org.jboss.tools.jst.web.kb.KbProjectFactory;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class JSF2ComponentsValidator extends Validator {
+
+ private IKbProject kbProject;
+ private IFile file;
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind,
+ ValidationState state, IProgressMonitor monitor) {
+ ValidationResult result = new ValidationResult();
+ if (resource instanceof IFile) {
+ IFile file = (IFile) resource;
+ 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);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public ValidationReport validate(String uri, InputStream inputstream,
+ NestedValidatorContext context, ValidationResult result) {
+ JSF2Validator validator = JSF2Validator.getInstance();
+ return validator.validate(file, uri);
+ }
+
+ protected boolean isValidate(IFile file) {
+ boolean isValidate = false;
+ try {
+ InputStream is = file.getContents();
+ Scanner scanner = new Scanner(is);
+ while (scanner.hasNextLine()) {
+ if (scanner.nextLine().indexOf(
+ JSF2ResourceUtil.JSF2_URI_PREFIX) != -1) {
+ isValidate = true;
+ scanner.close();
+ break;
+ }
+ }
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ }
+ return isValidate;
+ }
+
+ @Override
+ protected void addInfoToMessage(ValidationMessage validationMessage,
+ IMessage message) {
+ Object[] args = validationMessage.getMessageArguments();
+ 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;
+ }
+ }
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ValidationInfo.java 2010-04-21
08:46:06 UTC (rev 21573)
@@ -0,0 +1,29 @@
+ /*******************************************************************************
+ * 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 org.eclipse.wst.xml.core.internal.validation.XMLValidationInfo;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class JSF2ValidationInfo extends XMLValidationInfo{
+
+ public JSF2ValidationInfo(String uri) {
+ super(uri);
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2Validator.java 2010-04-21
08:46:06 UTC (rev 21573)
@@ -0,0 +1,155 @@
+ /*******************************************************************************
+ * 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/action/JSF2ComponentResolutionGenerator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2ComponentResolutionGenerator.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2ComponentResolutionGenerator.java 2010-04-21
08:46:06 UTC (rev 21573)
@@ -0,0 +1,47 @@
+ /*******************************************************************************
+ * 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.runtime.CoreException;
+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;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class JSF2ComponentResolutionGenerator implements
+ IMarkerResolutionGenerator {
+
+ public IMarkerResolution[] getResolutions(IMarker marker) {
+ try {
+ String markerType = marker.getType();
+ if (markerType == null
+ || !JSF2Validator.JSF2_PROBLEM_ID.equals(markerType)) {
+ return new IMarkerResolution[0];
+ }
+ if (marker.getAttribute(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY) == null) {
+ return new IMarkerResolution[0];
+ }
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ }
+ return new JSF2MarkerResolution[] { new JSF2MarkerResolution() };
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2MarkerResolution.java 2010-04-21
08:46:06 UTC (rev 21573)
@@ -0,0 +1,82 @@
+ /*******************************************************************************
+ * 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/util/JSF2ComponentParams.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentParams.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentParams.java 2010-04-21
08:46:06 UTC (rev 21573)
@@ -0,0 +1,62 @@
+ /*******************************************************************************
+ * 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/JSF2ComponentsUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentsUtil.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentsUtil.java 2010-04-21
08:46:06 UTC (rev 21573)
@@ -0,0 +1,69 @@
+ /*******************************************************************************
+ * 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);
+ }
+ }
+ }
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ResourceUtil.java 2010-04-21
08:46:06 UTC (rev 21573)
@@ -0,0 +1,147 @@
+ /*******************************************************************************
+ * 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;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.jboss.tools.jsf.JSFModelPlugin;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class JSF2ResourceUtil {
+
+ public static final String JSF2_URI_PREFIX =
"http://java.sun.com/jsf/composite"; //$NON-NLS-1$
+
+ public static final String COMPONENT_RESOURCE_PATH_KEY =
"component_resource_path_key"; //$NON-NLS-1$
+
+ public static boolean isJSF2CompositeComponentExists(IProject project,
+ IDOMElement jsf2Element) {
+ ElementImpl elementImpl = (ElementImpl) jsf2Element;
+ String nameSpaceURI = elementImpl.getNamespaceURI();
+ if (nameSpaceURI == null || nameSpaceURI.indexOf(JSF2_URI_PREFIX) == -1) {
+ return false;
+ }
+ String nodeName = jsf2Element.getNodeName();
+ if (nodeName.lastIndexOf(':') != -1) {
+ nodeName = nodeName.substring(nodeName.lastIndexOf(':') + 1);
+ }
+ 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).append(
+ "/" + nodeName + ".xhtml"); //$NON-NLS-1$ //$NON-NLS-2$
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ if (file.exists()) {
+ return true;
+ }
+ }
+ return searchInClassPath(project, "META-INF" + relativeLocation
//$NON-NLS-1$
+ + "/" + nodeName + ".xhtml"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public static IFile createJSF2CompositeComponent(IProject project,
+ IPath resourceRelativePath) throws CoreException {
+ if (!project.exists()) {
+ return null;
+ }
+ if (!project.isAccessible()) {
+ try {
+ project.open(new NullProgressMonitor());
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ }
+ }
+ 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 = resourceRelativePath.segments();
+ IFolder componentPathFolder = resourcesFolder;
+ for (int i = 0; i < segments.length - 1; i++) {
+ componentPathFolder = componentPathFolder
+ .getFolder(segments[i]);
+ if (!componentPathFolder.exists()) {
+ componentPathFolder.create(true, true, monitor);
+ }
+ }
+ IFile file = componentPathFolder
+ .getFile(segments[segments.length - 1]);
+ if (!file.exists()) {
+ file.create(JSF2TemplateManager.getManager()
+ .createStreamFromTemplate("composite.xhtml"), true, //$NON-NLS-1$
+ monitor);
+ }
+ return file;
+ }
+ return null;
+ }
+
+ 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);
+ }
+ return false;
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2TemplateManager.java 2010-04-21
08:46:06 UTC (rev 21573)
@@ -0,0 +1,41 @@
+ /*******************************************************************************
+ * 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.InputStream;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class JSF2TemplateManager {
+
+ private static JSF2TemplateManager instance = new JSF2TemplateManager();
+
+ private JSF2TemplateManager() {
+
+ }
+
+ public static JSF2TemplateManager getManager() {
+ return instance;
+ }
+
+ public InputStream createStreamFromTemplate(String templateName) {
+ InputStream stream = null;
+ stream = JSF2TemplateManager.class
+ .getResourceAsStream("/resources/templates/" + templateName);
//$NON-NLS-1$
+ return stream;
+ }
+
+}