Author: mareshkau
Date: 2011-02-24 14:25:36 -0500 (Thu, 24 Feb 2011)
New Revision: 29322
Modified:
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/I18nValidator.java
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/validation/I18nValidatorTest.java
Log:
https://issues.jboss.org/browse/JBIDE-7003, checking for value attr has been added
Modified:
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 2011-02-24
19:16:35 UTC (rev 29321)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidationComponent.java 2011-02-24
19:25:36 UTC (rev 29322)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.jsf.web.validation.i18n;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
import org.jboss.tools.jsf.JSFModelPlugin;
import org.jboss.tools.jsf.messages.JSFUIMessages;
@@ -40,6 +41,18 @@
return component;
}
+ public static I18nValidationComponent createI18nValidationComponent(IDOMAttr attr){
+ I18nValidationComponent component = new I18nValidationComponent();
+ component.setStartOffSet(attr.getValueRegionStartOffset()+1);
+ component.setLength(attr.getValueRegionText().length()-2);
+ component.setLine(attr.getStructuredDocument().getLineOfOffset(
+ component.getStartOffSet()) + 1);
+ component.createValidationMessage();
+ component.createMessageParams();
+ component.setInValidString(attr.getNodeValue());
+ return component;
+ }
+
public String getType() {
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-24
19:16:35 UTC (rev 29321)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidator.java 2011-02-24
19:25:36 UTC (rev 29322)
@@ -36,6 +36,7 @@
import org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext;
import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport;
import org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.jboss.tools.jsf.JSFModelPlugin;
import org.jboss.tools.jsf.jsf2.model.JSF2ComponentModelManager;
import org.jboss.tools.jsf.jsf2.util.JSF2ResourceUtil;
@@ -44,6 +45,8 @@
import org.jboss.tools.jst.jsp.bundle.BundleMapUtil;
import org.jboss.tools.jst.web.kb.WebKbPlugin;
import org.jboss.tools.jst.web.kb.preferences.ELSeverityPreferences;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
@@ -156,13 +159,31 @@
.add(I18nValidationComponent
.createI18nValidationComponent((IDOMText) childNode));
}
- } else {
- validateDOM(childNode, jsfnonValComponents);
}
+ if(childNode instanceof Element){
+ Element elementToValidate = (Element) childNode;
+ Attr notValid = getNotValidAttr(elementToValidate);
+ if(notValid!=null){
+ jsfnonValComponents
+ .add(I18nValidationComponent
+ .createI18nValidationComponent((IDOMAttr)notValid));
+ }
+ }
+
+ validateDOM(childNode, jsfnonValComponents);
}
}
-
/**
+ * Checks if Element containt non Externalized strings in value attribute
+ */
+ private Attr getNotValidAttr(Element elementToValidate){
+ Attr notValidNode = null;
+ if(!validateTextNode(elementToValidate.getAttribute("value"))){
//$NON-NLS-1$
+ notValidNode = elementToValidate.getAttributeNode("value"); //$NON-NLS-1$
+ }
+ return notValidNode;
+ }
+ /**
* Return false if not not valid
*
* @param String
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/validation/I18nValidatorTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/validation/I18nValidatorTest.java 2011-02-24
19:16:35 UTC (rev 29321)
+++
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/validation/I18nValidatorTest.java 2011-02-24
19:25:36 UTC (rev 29322)
@@ -32,6 +32,8 @@
public class I18nValidatorTest extends AbstractResourceMarkerTest {
private IPreferenceStore store;
+ private IFile testFile;
+ private static final int NUMBER_OF_EXT_PROBLEMS_IN_FILE = 3;
@Override
protected void setUp() throws Exception {
@@ -39,17 +41,17 @@
setProject(ResourcesPlugin.getWorkspace().getRoot()
.getProject("i18nTestProject")); //$NON-NLS-1$
store = WebKbPlugin.getDefault().getPreferenceStore();
+ testFile =
getProject().getFile("WebContent/externalization-validator-test-case-1.xhtml");
//$NON-NLS-1$
}
public void testShowErrorMarkers() throws CoreException {
store.setValue(ELSeverityPreferences.NON_EXTERNALIZED_STRINGS,
ELSeverityPreferences.WARNING);
- IFile testFile =
getProject().getFile("WebContent/externalization-validator-test-case-1.xhtml");
//$NON-NLS-1$
testFile.deleteMarkers(I18nValidationComponent.PROBLEM_ID, true,
IResource.DEPTH_ZERO);
IMarker[] elMarkers = testFile.findMarkers(I18nValidationComponent.PROBLEM_ID, true,
IResource.DEPTH_ZERO);
assertEquals("Markers should be cleaned", 0,elMarkers.length); //$NON-NLS-1$
ValidationFramework.getDefault().validate(testFile, new NullProgressMonitor());
elMarkers = testFile.findMarkers(I18nValidationComponent.PROBLEM_ID, true,
IResource.DEPTH_ZERO);
- assertEquals("Should be 2 Markers", 2,elMarkers.length); //$NON-NLS-1$
+ assertEquals("Should be "+NUMBER_OF_EXT_PROBLEMS_IN_FILE+"
Markers", NUMBER_OF_EXT_PROBLEMS_IN_FILE,elMarkers.length); //$NON-NLS-1$
//$NON-NLS-2$
}
public void testDefaultStateI19nValidator() {
@@ -59,7 +61,6 @@
}
public void testChangeMarkerSeverity() throws CoreException {
- IFile testFile =
getProject().getFile("WebContent/externalization-validator-test-case-1.xhtml");
//$NON-NLS-1$
testFile.deleteMarkers(I18nValidationComponent.PROBLEM_ID, true,
IResource.DEPTH_ZERO);
IMarker[] elMarkers = testFile.findMarkers(I18nValidationComponent.PROBLEM_ID, true,
IResource.DEPTH_ZERO);
//changing severity level on ignoring(disable validator)
@@ -72,15 +73,26 @@
store.setValue(ELSeverityPreferences.NON_EXTERNALIZED_STRINGS,
ELSeverityPreferences.WARNING);
ValidationFramework.getDefault().validate(testFile, new NullProgressMonitor());
elMarkers = testFile.findMarkers(I18nValidationComponent.PROBLEM_ID, true,
IResource.DEPTH_ZERO);
- assertEquals("There shouldn't be 2 validation markers",
2,elMarkers.length); //$NON-NLS-1$
+ assertEquals("There shouldn't be "+NUMBER_OF_EXT_PROBLEMS_IN_FILE+"
validation markers", NUMBER_OF_EXT_PROBLEMS_IN_FILE,elMarkers.length); //$NON-NLS-1$
//$NON-NLS-2$
assertEquals("Marker Severity should be
warning",(Integer)IMarker.SEVERITY_WARNING,
(Integer)elMarkers[0].getAttribute(IMarker.SEVERITY));//$NON-NLS-1$
//changing severity level on warning
store.setValue(ELSeverityPreferences.NON_EXTERNALIZED_STRINGS,
ELSeverityPreferences.ERROR);
ValidationFramework.getDefault().validate(testFile, new NullProgressMonitor());
elMarkers = testFile.findMarkers(I18nValidationComponent.PROBLEM_ID, true,
IResource.DEPTH_ZERO);
- assertEquals("There shouldn't be 2 validation markers",
2,elMarkers.length); //$NON-NLS-1$
+ assertEquals("There shouldn't be "+NUMBER_OF_EXT_PROBLEMS_IN_FILE+"
validation markers", NUMBER_OF_EXT_PROBLEMS_IN_FILE,elMarkers.length); //$NON-NLS-1$
//$NON-NLS-2$
assertEquals("Marker Severity should be
warning",(Integer)IMarker.SEVERITY_ERROR,
(Integer)elMarkers[0].getAttribute(IMarker.SEVERITY));//$NON-NLS-1$
-
}
+
+// public void testRegionLineIsCorrect() throws CoreException{
+// store.setValue(ELSeverityPreferences.NON_EXTERNALIZED_STRINGS,
ELSeverityPreferences.WARNING);
+// ValidationFramework.getDefault().validate(testFile, new NullProgressMonitor());
+// IMarker[] elMarkers = testFile.findMarkers(I18nValidationComponent.PROBLEM_ID, true,
IResource.DEPTH_ZERO);
+// assertEquals("There shouldn't be
"+NUMBER_OF_EXT_PROBLEMS_IN_FILE+" validation markers",
NUMBER_OF_EXT_PROBLEMS_IN_FILE,elMarkers.length); //$NON-NLS-1$ //$NON-NLS-2$
+// assertEquals("Marker Severity should be
warning",(Integer)IMarker.SEVERITY_WARNING,
(Integer)elMarkers[0].getAttribute(IMarker.SEVERITY));//$NON-NLS-1$
+//
+// assertEquals("Line number should
be",8,elMarkers[0].getAttribute(IMarker.LINE_NUMBER)); //$NON-NLS-1$
+// assertEquals("Line number should
be",10,elMarkers[1].getAttribute(IMarker.LINE_NUMBER)); //$NON-NLS-1$
+// assertEquals("Line number should
be",12,elMarkers[2].getAttribute(IMarker.LINE_NUMBER)); //$NON-NLS-1$
+// }
}