[jbosstools-commits] JBoss Tools SVN: r23032 - in trunk: vpe/tests/org.jboss.tools.vpe.ui.test/META-INF and 1 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Fri Jun 25 07:34:38 EDT 2010
Author: dmaliarevich
Date: 2010-06-25 07:34:37 -0400 (Fri, 25 Jun 2010)
New Revision: 23032
Modified:
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleListener.java
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleManager.java
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleAttribyteContainer.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/META-INF/MANIFEST.MF
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComponentContentTest.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestDomUtil.java
Log:
https://jira.jboss.org/browse/JBIDE-6539 , in ComponentContentTest style attribute will be compared by its parmeters insted of the whole style string.
Modified: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleListener.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleListener.java 2010-06-25 11:19:15 UTC (rev 23031)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleListener.java 2010-06-25 11:34:37 UTC (rev 23032)
@@ -37,8 +37,6 @@
private ListenerList listeners = new ListenerList();
- private CSSStyleManager styleManager = new CSSStyleManager();
-
private StyleContainer currentStyle;
private IWorkbenchPart currentPart;
@@ -93,7 +91,7 @@
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- StyleContainer newStyle = styleManager.recognizeCSSStyle(selection);
+ StyleContainer newStyle = CSSStyleManager.recognizeCSSStyle(selection);
if (isImportant(part)
&& ((currentStyle == null) || !(currentStyle.equals(newStyle)))) {
Modified: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleManager.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleManager.java 2010-06-25 11:19:15 UTC (rev 23031)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleManager.java 2010-06-25 11:34:37 UTC (rev 23032)
@@ -10,6 +10,9 @@
******************************************************************************/
package org.jboss.tools.jst.css.common;
+import java.util.HashMap;
+import java.util.Map;
+
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -24,6 +27,9 @@
import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSConstants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -32,74 +38,79 @@
import org.w3c.dom.css.CSSStyleSheet;
import org.w3c.dom.css.ElementCSSInlineStyle;
+// TODO: Auto-generated Javadoc
/**
+ * The Class CSSStyleManager.
+ *
* @author Sergey Dzmitrovich
- *
*/
public class CSSStyleManager {
+ /** The Constant STYLE_TAG_NAME. */
public static final String STYLE_TAG_NAME = "style"; //$NON-NLS-1$
+ /** The Constant STYLE_ATTRIBUTE_NAME. */
public static final String STYLE_ATTRIBUTE_NAME = "style"; //$NON-NLS-1$
/**
- *
- * @param selection
- * @return
+ * Recognize css style.
+ *
+ * @param node the selected node
+ * @return the style container
*/
- public StyleContainer recognizeCSSStyle(ISelection selection) {
-
+ public static StyleContainer recognizeCSSStyle(Object node) {
StyleContainer container = null;
+ // if selected object is node in css file
+ if (node instanceof ICSSNode) {
+ CSSStyleRule styleRule = getStyleRule((ICSSNode) node);
+ if (styleRule != null)
+ container = new CSSStyleRuleContainer(styleRule);
+ } else if ((node instanceof Element)
+ || (node instanceof Attr)) {
+ Element selectedElement = null;
+ if (node instanceof Attr) {
+ selectedElement = ((Attr) node).getOwnerElement();
+ } else {
+ selectedElement = (Element) node;
+ }
+ if (isSuitableElement(selectedElement)) {
+ container = new StyleAttribyteContainer(selectedElement);
+ }
+ }
+ return container;
+ }
+
+ /**
+ * Recognize css style.
+ *
+ * @param selection the selection
+ * @return the style container
+ */
+ public static StyleContainer recognizeCSSStyle(ISelection selection) {
+ StyleContainer container = null;
if (selection instanceof IStructuredSelection) {
-
Object selectedObject = ((IStructuredSelection) selection)
.getFirstElement();
-
- // if selected object is node in css file
- if (selectedObject instanceof ICSSNode) {
-
- CSSStyleRule styleRule = getStyleRule((ICSSNode) selectedObject);
-
- if (styleRule != null)
- container = new CSSStyleRuleContainer(styleRule);
-
- } else if ((selectedObject instanceof Element)
- || (selectedObject instanceof Attr)) {
-
- Element selectedElement = null;
-
- if (selectedObject instanceof Attr)
- selectedElement = ((Attr) selectedObject).getOwnerElement();
- else
- selectedElement = (Element) selectedObject;
-
- if (isSuitableElement(selectedElement)) {
-
- container = new StyleAttribyteContainer(selectedElement);
-
- }
- } else if ((selectedObject instanceof Text)
+ container = recognizeCSSStyle(selectedObject);
+ /*
+ * When container was not found and
+ * the selection is text selection then:
+ */
+ if ((null == container) && (selectedObject instanceof Text)
&& (selection instanceof ITextSelection)) {
-
Text styleText = (Text) selectedObject;
-
Node parentNode = styleText.getParentNode();
-
if ((parentNode != null)
&& STYLE_TAG_NAME.equalsIgnoreCase(parentNode
.getNodeName())) {
-
int offset = getRelationalOffset(styleText,
((ITextSelection) selection).getOffset());
-
CSSStyleSheet sheet = getSheet(parentNode);
-
ICSSNode node = getNode(sheet, offset);
-
CSSStyleRule styleRule = getStyleRule(node);
-
if (styleRule != null) {
- container = new StyleElementRuleContainer(styleText, styleRule);
+ container = new StyleElementRuleContainer(
+ styleText, styleRule);
}
}
}
@@ -108,11 +119,12 @@
}
/**
- *
- * @param styleContainer
- * @return
+ * Gets the sheet.
+ *
+ * @param styleContainer the style container
+ * @return the sheet
*/
- private CSSStyleSheet getSheet(Node styleContainer) {
+ private static CSSStyleSheet getSheet(Node styleContainer) {
if (styleContainer instanceof INodeNotifier) {
@@ -131,12 +143,13 @@
}
/**
- *
- * @param sheet
- * @param offset
- * @return
+ * Gets the node.
+ *
+ * @param sheet the sheet
+ * @param offset the offset
+ * @return the node
*/
- private ICSSNode getNode(CSSStyleSheet sheet, int offset) {
+ private static ICSSNode getNode(CSSStyleSheet sheet, int offset) {
ICSSModel model = ((ICSSDocument) sheet).getModel();
@@ -149,11 +162,12 @@
}
/**
- *
- * @param element
- * @return
+ * Checks if element has "style" property.
+ *
+ * @param element the element
+ * @return true, if is suitable element
*/
- private boolean isSuitableElement(Element element) {
+ private static boolean isSuitableElement(Element element) {
if (element instanceof ElementCSSInlineStyle
&& isAttributeAvailable(element, STYLE_TAG_NAME)) {
@@ -164,11 +178,12 @@
}
/**
- *
- * @param node
- * @return
+ * Gets the style rule.
+ *
+ * @param node the node
+ * @return the style rule
*/
- private CSSStyleRule getStyleRule(ICSSNode node) {
+ private static CSSStyleRule getStyleRule(ICSSNode node) {
while (node != null) {
@@ -182,20 +197,23 @@
}
/**
- *
- * @param selection
- * @param styleText
- * @return
+ * Gets the relational offset.
+ *
+ * @param basicNode the basic node
+ * @param absoluteOffset the absolute offset
+ * @return the relational offset
*/
- private int getRelationalOffset(Node basicNode, int absoluteOffset) {
+ private static int getRelationalOffset(Node basicNode, int absoluteOffset) {
return absoluteOffset - ((IndexedRegion) basicNode).getStartOffset();
}
/**
- * @param element
- * @param attrName
- * @return
+ * Checks if attribute is available.
+ *
+ * @param element the element
+ * @param attrName the attr name
+ * @return true, if is attribute available
*/
private static boolean isAttributeAvailable(Element element, String attrName) {
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element
@@ -213,4 +231,30 @@
return false;
}
+
+
+ /**
+ * Gets the style attributes.
+ *
+ * @param styleString the style string
+ * @return the style attributes
+ */
+ public static Map<String, String> getStyleAttributes(String styleString) {
+ Map<String, String> styleMap = new HashMap<String, String>();
+ if ((styleString != null) && (styleString.length() > 0)) {
+ String[] styles = styleString.split(Constants.SEMICOLON);
+ for (String styleElement : styles) {
+ String[] styleElementParts = styleElement.trim().split(
+ Constants.COLON);
+ if ((styleElementParts != null)
+ && (styleElementParts.length == 2)
+ && Util.searchInElement(styleElementParts[0],
+ CSSConstants.CSS_STYLES_MAP)) {
+ styleMap.put(styleElementParts[0], styleElementParts[1]);
+ }
+ }
+ }
+ return styleMap;
+ }
+
}
Modified: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleAttribyteContainer.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleAttribyteContainer.java 2010-06-25 11:19:15 UTC (rev 23031)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleAttribyteContainer.java 2010-06-25 11:34:37 UTC (rev 23032)
@@ -48,29 +48,8 @@
}
public Map<String, String> getStyleAttributes() {
-
- String styleString = element.getAttribute(STYLE_ATTRIBUTE_NAME);
-
- Map<String, String> styleMap = new HashMap<String, String>();
-
- if ((styleString != null) && (styleString.length() > 0)) {
-
- String[] styles = styleString.split(Constants.SEMICOLON);
- for (String styleElement : styles) {
- String[] styleElementParts = styleElement.trim().split(
- Constants.COLON);
- if ((styleElementParts != null)
- && (styleElementParts.length == 2)
- && Util.searchInElement(styleElementParts[0],
- CSSConstants.CSS_STYLES_MAP)) {
-
- styleMap.put(styleElementParts[0], styleElementParts[1]);
- }
- }
-
- }
-
- return styleMap;
+ return CSSStyleManager.getStyleAttributes(element
+ .getAttribute(STYLE_ATTRIBUTE_NAME));
}
public Object getStyleObject() {
Modified: trunk/vpe/tests/org.jboss.tools.vpe.ui.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.test/META-INF/MANIFEST.MF 2010-06-25 11:19:15 UTC (rev 23031)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.test/META-INF/MANIFEST.MF 2010-06-25 11:34:37 UTC (rev 23032)
@@ -11,6 +11,7 @@
org.eclipse.core.resources,
org.eclipse.ui.ide,
org.jboss.tools.jst.jsp,
+ org.jboss.tools.jst.css,
org.jboss.tools.vpe.xulrunner;bundle-version="3.1.0",
org.mozilla.xpcom;bundle-version="1.9.1",
org.eclipse.jface.text,
Modified: trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComponentContentTest.java
===================================================================
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComponentContentTest.java 2010-06-25 11:19:15 UTC (rev 23031)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComponentContentTest.java 2010-06-25 11:34:37 UTC (rev 23032)
@@ -44,16 +44,17 @@
/**
*
* there are several conditions:
- *
+ * <p>
* 1) xml file which contain tests must be named 'name of test page' +
* '.xml'
- *
+ * <br>
* Example: test.jsp and test.jsp.xml
- *
+ * <p>
* 2) a tag <test> in xml file and required element in test page must have
* the same attribute "id"
- *
+ * <br>
* Example: <tests>... <test id="testId" > ...<tests> - in xml file and
+ * <br>
* <html>... <x:testElement id="testId" > ... </html> - in test page
*
* @param elementPagePath
Modified: trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestDomUtil.java
===================================================================
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestDomUtil.java 2010-06-25 11:19:15 UTC (rev 23031)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestDomUtil.java 2010-06-25 11:34:37 UTC (rev 23032)
@@ -18,15 +18,23 @@
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jboss.tools.common.model.util.XMLUtil;
+import org.jboss.tools.jst.css.common.CSSStyleManager;
+import org.jboss.tools.jst.css.common.StyleContainer;
import org.jboss.tools.vpe.editor.util.Constants;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
import org.mozilla.interfaces.nsIDOMAttr;
+import org.mozilla.interfaces.nsIDOMCSSStyleDeclaration;
+import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNamedNodeMap;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;
@@ -36,6 +44,8 @@
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.w3c.dom.css.CSSStyleDeclaration;
+import org.w3c.dom.css.ElementCSSInlineStyle;
/**
* @author Sergey Dzmitrovich
@@ -148,7 +158,6 @@
}
// compare node's attributes
if (modelNode.getNodeType() == Node.ELEMENT_NODE) {
-
compareAttributes(modelNode.getAttributes(), vpeNode
.getAttributes());
}
@@ -220,79 +229,91 @@
for (int i = 0; i < modelAttributes.getLength(); i++) {
Attr modelAttr = (Attr) modelAttributes.item(i);
String name = modelAttr.getName();
-
// if the attribute has to be skipped, then do it
if ( name != null
&& skippedAtributes.contains(name.toUpperCase()) ) {
continue;
}
-
// if there are limitation of attributes
if (ILLEGAL_ATTRIBUTES.equals(name)) {
-
String[] illegalAttributes = modelAttr.getNodeValue().split(
ILLEGAL_ATTRIBUTES_SEPARATOR);
-
for (String illegalAttributeName : illegalAttributes) {
if (vpeAttributes.getNamedItem(illegalAttributeName.trim()) != null)
throw new ComparisonException("illegal attribute :" //$NON-NLS-1$
+ illegalAttributeName);
}
-
} else {
-
-
- if (vpeAttributes.getNamedItem(
- name) == null)
+ if (vpeAttributes.getNamedItem(name) == null) {
throw new ComparisonException("there is not : \"" + name //$NON-NLS-1$
+ "\" attribute"); //$NON-NLS-1$
-
+ }
nsIDOMAttr vpeAttr = queryInterface(
vpeAttributes.getNamedItem(name), nsIDOMAttr.class);
-
-
-
-// if (HTML.ATTR_STYLE.equalsIgnoreCase(name)) {
-//
-// String[] modelParameters = modelAttr.getNodeValue().split(
-// Constants.SEMICOLON);
-// String[] vpeParameters = vpeAttr.getNodeValue().split(
-// Constants.SEMICOLON);
-//
-// for (int j = 0; j < modelParameters.length; j++) {
-// String modelParam = modelParameters[j];
-// String vpeParam = vpeParameters[j];
-//
-// String[] splittedModelParam = modelParam.split(
-// Constants.COLON, 2);
-//
-// String[] splittedVpeParam = vpeParam.split(
-// Constants.COLON, 2);
-//
-// if (!splittedModelParam[0].trim().equals(
-// splittedVpeParam[0].trim())) {
-// throw new ComparisonException(
-// "param of style attribute is\""
-// + splittedVpeParam[0].trim()
-// + "\" but must be \""
-// + splittedModelParam[0].trim()
-// + "\"");
-// }
-//
-//// compareComplexStrings(splittedModelParam[0].trim(), splittedVpeParam[0].trim());
-//
-//
-// if (splittedModelParam.length > 1)
-// compareComplexStrings(splittedModelParam[1].trim(),
-// splittedVpeParam[1].trim());
-//
-// }
-//
-// }
-
+ /*
+ * By default every attribute show pass through
+ * compareComplexStrings(..) method.
+ * For "style" attribute there is a separate comparison.
+ */
+ boolean performComplexStringsComparison = true;
+ if (HTML.ATTR_STYLE.equalsIgnoreCase(name)) {
+ String xmlAttrValue = modelAttr.getNodeValue();
+ /*
+ * Check if it is not a regular expression.
+ * Otherwise perform Complex Strings Comparison
+ * as usual.
+ */
+ if (!(xmlAttrValue.startsWith(START_REGEX)
+ && xmlAttrValue.endsWith(END_REGEX))) {
+ performComplexStringsComparison = false;
+ /*
+ * Parse style attribute value
+ */
+ Map<String, String> vpeStyle = CSSStyleManager
+ .getStyleAttributes(vpeAttr.getNodeValue());
+ Map<String, String> xmlStyle = CSSStyleManager
+ .getStyleAttributes(xmlAttrValue);
+ /*
+ * Major condition is that
+ * all styles from the xml file should present
+ * in the style attribute of the vpe element.
+ */
+ if (xmlStyle.size() > vpeStyle.size()) {
+ throw new ComparisonException(
+ "VPE element has less style parameters [" //$NON-NLS-1$
+ + vpeStyle.size()
+ + "] than was specified [" //$NON-NLS-1$
+ + xmlStyle.size() + "]."); //$NON-NLS-1$
+ } else {
+ if ((xmlStyle.size() > 0) && (vpeStyle.size() > 0)) {
+ for (String key : xmlStyle.keySet()) {
+ if (vpeStyle.containsKey(key)) {
+ if (!xmlStyle.get(key).equalsIgnoreCase(
+ vpeStyle.get(key))) {
+ throw new ComparisonException(
+ "Style value for parameter [" //$NON-NLS-1$
+ + key
+ + "] is different. Expected [" //$NON-NLS-1$
+ + xmlStyle.get(key)
+ + "] but was [" //$NON-NLS-1$
+ + vpeStyle.get(key)
+ + "]"); //$NON-NLS-1$
+ }
+ } else {
+ throw new ComparisonException(
+ "Style parameter [" //$NON-NLS-1$
+ + key
+ + "] is missing in the VPE element"); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ }
+ }
+ if (performComplexStringsComparison) {
compareComplexStrings(modelAttr.getNodeValue().trim(),
vpeAttr.getNodeValue().trim());
-
+ }
}
}
}
More information about the jbosstools-commits
mailing list