Author: mareshkau
Date: 2011-02-14 07:59:32 -0500 (Mon, 14 Feb 2011)
New Revision: 29132
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nMarkerResolutionGenerator.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidationComponent.java
Modified:
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/jsf2/util/JSF2ResourceUtil.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/LocalizedMessage.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidator.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java
Log:
https://issues.jboss.org/browse/JBIDE-7003, marker shows now for non-ext strings.
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/plugin.properties
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/plugin.properties 2011-02-14 12:50:15 UTC (rev
29131)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/plugin.properties 2011-02-14 12:59:32 UTC (rev
29132)
@@ -7,6 +7,8 @@
JSF2ProblemName = JSF 2 Problem
+i18nProblemName = Externalization Problem
+
KBProblemName=JSF EL Problem
KB_REQUIRED_FOR_JSF=JSF
\ 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 2011-02-14 12:50:15 UTC (rev 29131)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2011-02-14 12:59:32 UTC (rev 29132)
@@ -543,7 +543,16 @@
markerType="org.jboss.tools.jsf.jsf2problemmarker">
</markerResolutionGenerator>
</extension>
+
<extension
+ point="org.eclipse.ui.ide.markerResolution">
+ <markerResolutionGenerator
+
class="org.jboss.tools.jsf.web.validation.i18n.I18nMarkerResolutionGenerator"
+ markerType="org.jboss.tools.jsf.i18nproblemmarker">
+ </markerResolutionGenerator>
+ </extension>
+
+ <extension
id="jsf2problemmarker"
name="%JSF2ProblemName"
point="org.eclipse.core.resources.markers">
@@ -563,6 +572,28 @@
type="org.eclipse.core.resources.textmarker">
</super>
</extension>
+
+ <extension
+ id="i18nproblemmarker"
+ name="%i18nProblemName"
+ point="org.eclipse.core.resources.markers">
+ <super
+ type="org.eclipse.core.resources.problemmarker">
+ </super>
+ <persistent
+ value="true">
+ </persistent>
+ <attribute
+ name="problemType">
+ </attribute>
+ <attribute
+ name="baseElement">
+ </attribute>
+ <super
+ type="org.eclipse.core.resources.textmarker">
+ </super>
+ </extension>
+
<extension
point="org.eclipse.wst.sse.ui.sourcevalidation">
<validator
@@ -606,6 +637,44 @@
</contentTypeIdentifier>
</validator>
</extension>
+
+ <extension
+ id="jsf2"
+ name="%JSF2_ComponentsValidator.name"
+ point="org.eclipse.wst.validation.validatorV2">
+ <validator
+ build="true"
+ class="org.jboss.tools.jsf.web.validation.i18n.I18nValidator"
+ manual="true"
+ markerId="org.jboss.tools.jsf.i18nproblemmarker"
+
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>
+ <contentType
+ id="org.eclipse.jst.jsp.core.jspsource">
+ </contentType>
+ </rules>
+ </include>
+ </validator>
+ </extension>
<extension
point="org.eclipse.wst.sse.ui.quickFixProcessor">
<quickFixProcessor
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/util/JSF2ResourceUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/util/JSF2ResourceUtil.java 2011-02-14
12:50:15 UTC (rev 29131)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/util/JSF2ResourceUtil.java 2011-02-14
12:59:32 UTC (rev 29132)
@@ -17,6 +17,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -33,6 +34,8 @@
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.sse.ui.internal.reconcile.validator.IncrementalHelper;
+import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
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;
@@ -273,5 +276,31 @@
}
return projectResourceRelativePath;
}
-
+ /**
+ * Get validating resource
+ * @param helper
+ * @return IResource on which validator works
+ */
+ public static IResource getValidatingResource(IValidationContext helper){
+ IResource resource=null;
+ if (helper instanceof IncrementalHelper) {
+ IncrementalHelper incrementalHelper = (IncrementalHelper) helper;
+ IProject project = incrementalHelper.getProject();
+ if (project == null) {
+ return resource;
+ }
+ String[] uris = helper.getURIs();
+ if (uris == null || uris.length < 1) {
+ return resource;
+ }
+ String filePath = uris[0];
+ if (filePath == null) {
+ return resource;
+ }
+ filePath = filePath.substring(filePath.indexOf('/') + 1);
+ resource = project.findMember(filePath
+ .substring(filePath.indexOf('/') + 1));
+ }
+ return resource;
+ }
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/LocalizedMessage.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/LocalizedMessage.java 2011-02-14
12:50:15 UTC (rev 29131)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/LocalizedMessage.java 2011-02-14
12:59:32 UTC (rev 29132)
@@ -18,6 +18,7 @@
import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.jboss.tools.jsf.jsf2.util.JSF2ResourceUtil;
+import org.jboss.tools.jsf.web.validation.i18n.I18nValidationComponent;
import org.jboss.tools.jsf.web.validation.jsf2.JSF2XMLValidator;
import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2AttrTempComponent;
import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2CompositeTempComponent;
@@ -70,6 +71,18 @@
return jsf2LocMessage;
}
+ public static Message createJSFLocalizedMessage(
+ IJSFValidationComponent ijsfValidationComponent) {
+ LocalizedMessage i18nLocMessage = new LocalizedMessage();
+ i18nLocMessage.component = ijsfValidationComponent;
+ i18nLocMessage.setAttribute("problemType",
I18nValidationComponent.PROBLEM_ID); //$NON-NLS-1$
+ i18nLocMessage.setAttribute(IMarker.LINE_NUMBER, i18nLocMessage.getLineNumber());
+ i18nLocMessage.setAttribute(IMarker.SEVERITY, 1);
+ i18nLocMessage.setAttribute(ValidatorMessage.ValidationId,
"org.jboss.tools.jsf.i18n.source");
+ i18nLocMessage.setAttribute(IMarker.MESSAGE,i18nLocMessage.getText());
+ return i18nLocMessage;
+ }
+
@Override
public int getLineNumber() {
return component.getLine();
@@ -109,4 +122,5 @@
public int getSeverity() {
return IMessage.NORMAL_SEVERITY;
}
+
}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nMarkerResolutionGenerator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nMarkerResolutionGenerator.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nMarkerResolutionGenerator.java 2011-02-14
12:59:32 UTC (rev 29132)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 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.i18n;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolutionGenerator;
+
+/**
+ * @author mareshkau
+ *
+ */
+public class I18nMarkerResolutionGenerator implements
+ IMarkerResolutionGenerator {
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.ui.IMarkerResolutionGenerator#getResolutions(org.eclipse.core.resources.IMarker)
+ */
+ @Override
+ public IMarkerResolution[] getResolutions(IMarker marker) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidationComponent.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidationComponent.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidationComponent.java 2011-02-14
12:59:32 UTC (rev 29132)
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 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.i18n;
+
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
+import org.jboss.tools.jsf.JSFModelPlugin;
+import org.jboss.tools.jsf.web.validation.JSFAbstractValidationComponent;
+
+/**
+ * @author mareshkau
+ *
+ */
+public class I18nValidationComponent extends JSFAbstractValidationComponent{
+ public static String PROBLEM_ID = JSFModelPlugin.PLUGIN_ID
+ + ".i18nproblemmarker"; //$NON-NLS-1$
+
+ //component creating usung factory method
+ private I18nValidationComponent(){}
+
+ public static I18nValidationComponent createI18nValidationComponent(IDOMText element){
+ I18nValidationComponent component = new I18nValidationComponent();
+ component.setStartOffSet(element.getStartOffset());
+ component.setLength(element.getLength());
+ component.setLine(element.getStructuredDocument().getLineOfOffset(
+ component.getStartOffSet()) + 1);
+ component.createValidationMessage();
+ component.createMessageParams();
+ return component;
+ }
+
+
+ @Override
+ public String getType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getComponentResourceLocation() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void createValidationMessage() {
+ setValidationMessage("Non externalized String literal; It should be moved to
resource bundles.");
+ }
+
+}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidator.java 2011-02-14
12:50:15 UTC (rev 29131)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidator.java 2011-02-14
12:59:32 UTC (rev 29132)
@@ -13,15 +13,25 @@
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator;
+import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.core.ValidationException;
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.validation.eclipse.Validator;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
+import org.jboss.tools.jsf.JSFModelPlugin;
import org.jboss.tools.jsf.jsf2.model.JSF2ComponentModelManager;
+import org.jboss.tools.jsf.jsf2.util.JSF2ResourceUtil;
+import org.jboss.tools.jsf.web.validation.IJSFValidationComponent;
+import org.jboss.tools.jsf.web.validation.LocalizedMessage;
import org.jboss.tools.jst.jsp.bundle.BundleMapUtil;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -34,7 +44,7 @@
*
*/
@SuppressWarnings("restriction")
-public class I18nValidator implements ISourceValidator, IValidator{
+public class I18nValidator extends Validator implements ISourceValidator, IValidator{
private IDOMDocument document;
public void connect(IDocument document) {
this.document=JSF2ComponentModelManager
@@ -59,10 +69,32 @@
throws ValidationException {
List<Node> notValidNodes = new ArrayList<Node>();
validateDOM(document, notValidNodes);
-
+ List<IJSFValidationComponent> jsfValComponents = new
ArrayList<IJSFValidationComponent>();
+ for (Node node : notValidNodes) {
+ jsfValComponents.add(I18nValidationComponent.createI18nValidationComponent((IDOMText)node));
+ }
+ reportProblems(helper, reporter, jsfValComponents);
}
+ private void reportProblems(IValidationContext helper, IReporter reporter,
+ List<IJSFValidationComponent> jsfValComponents ) {
+ IResource resource = JSF2ResourceUtil.getValidatingResource(helper);
+ if(resource==null) return;
+ try {
+ resource.deleteMarkers(I18nValidationComponent.PROBLEM_ID, false,
IResource.DEPTH_INFINITE);
+ for (IJSFValidationComponent ijsfValidationComponent : jsfValComponents) {
+ Message locMessage =
LocalizedMessage.createJSFLocalizedMessage(ijsfValidationComponent);
+ reporter.addMessage(this, locMessage);
+ IMarker marker = resource.createMarker(I18nValidationComponent.PROBLEM_ID);
+ marker.setAttributes(locMessage.getAttributes());
+ }
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ }
+ }
+
+
private void validateDOM(Node node, List<Node> nonExtStings){
NodeList childNodes = node.getChildNodes();
for(int i=0;i<childNodes.getLength();i++) {
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java 2011-02-14
12:50:15 UTC (rev 29131)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java 2011-02-14
12:59:32 UTC (rev 29132)
@@ -13,13 +13,11 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
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.IReporter;
@@ -28,6 +26,7 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.jboss.tools.jsf.JSFModelPlugin;
import org.jboss.tools.jsf.jsf2.model.JSF2ComponentModelManager;
+import org.jboss.tools.jsf.jsf2.util.JSF2ResourceUtil;
import org.jboss.tools.jsf.web.validation.IJSFValidationComponent;
import org.jboss.tools.jsf.web.validation.LocalizedMessage;
@@ -51,23 +50,7 @@
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[] uris = helper.getURIs();
- if (uris == null || uris.length < 1) {
- return;
- }
- String filePath = uris[0];
- if (filePath == null) {
- return;
- }
- filePath = filePath.substring(filePath.indexOf('/') + 1);
- IResource resource = project.findMember(filePath
- .substring(filePath.indexOf('/') + 1));
+ IResource resource = JSF2ResourceUtil.getValidatingResource(helper);
if (resource instanceof IFile) {
validateFile = (IFile) resource;
reportProblems(reporter,
@@ -75,7 +58,6 @@
(IFile) resource),resource);
}
}
- }
}
public void connect(IDocument document) {