From jbosstools-commits at lists.jboss.org Tue Oct 5 08:13:50 2010
Content-Type: multipart/mixed; boundary="===============3840613313823157634=="
MIME-Version: 1.0
From: jbosstools-commits at lists.jboss.org
To: jbosstools-commits at lists.jboss.org
Subject: [jbosstools-commits] JBoss Tools SVN: r25487 - in trunk:
jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/7209
and 5 other directories.
Date: Tue, 05 Oct 2010 08:13:50 -0400
Message-ID: <201010051213.o95CDoUB024554@svn01.web.mwc.hst.phx2.redhat.com>
--===============3840613313823157634==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: yradtsevich
Date: 2010-10-05 08:13:48 -0400 (Tue, 05 Oct 2010)
New Revision: 25487
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebCo=
ntent/pages/JBIDE/7209/
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebCo=
ntent/pages/JBIDE/7209/getNodeByXPath.html
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf=
/vpe/jsf/test/jbide/SourceDomUtilTest.java
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf=
/vpe/jsf/test/JsfAllTests.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DndUti=
l.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD=
.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/uti=
l/SourceDomUtil.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/t=
est/ComponentContentTest.java
Log:
https://jira.jboss.org/browse/JBIDE-7209 :
DnD does not work for files with XHTML namespace
- calls to org.eclipse.wst.xml.xpath.core.util.XSLTXPathHelper.selectSingle=
Node which works incorrectly are replaced by new method org.jboss.tools.vpe=
.editor.util.SourceDomUtil.getNodeByXPath
Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/W=
ebContent/pages/JBIDE/7209/getNodeByXPath.html
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebC=
ontent/pages/JBIDE/7209/getNodeByXPath.html (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebC=
ontent/pages/JBIDE/7209/getNodeByXPath.html 2010-10-05 12:13:48 UTC (rev 25=
487)
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
Modified: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/to=
ols/jsf/vpe/jsf/test/JsfAllTests.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/js=
f/vpe/jsf/test/JsfAllTests.java 2010-10-05 12:10:20 UTC (rev 25486)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/js=
f/vpe/jsf/test/JsfAllTests.java 2010-10-05 12:13:48 UTC (rev 25487)
@@ -93,6 +93,7 @@
import org.jboss.tools.jsf.vpe.jsf.test.jbide.RenderFacetAndInsertChildren=
Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.SelectAllAndCut_JBIDE4853;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.SelectWholeElement_JBIDE4713;
+import org.jboss.tools.jsf.vpe.jsf.test.jbide.SourceDomUtilTest;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.TaglibXMLUnformatedDTD_JBIDE=
5642;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.TestContextPathResolution;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.TestFViewLocaleAttribute_JBI=
DE5218;
@@ -102,6 +103,7 @@
import org.jboss.tools.jsf.vpe.jsf.test.jbide.VPERefreshTest;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.VisualRefreshComment_JBIDE60=
67;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.VpeI18nTest_JBIDE4887;
+import org.jboss.tools.jsf.vpe.jsf.test.jbide.XulRunnerVpeUtilsTest;
import org.jboss.tools.vpe.ui.test.VpeTestSetup;
=
/**
@@ -135,6 +137,8 @@
/*
* Other tests
*/
+ suite.addTestSuite(SourceDomUtilTest.class);
+ suite.addTestSuite(XulRunnerVpeUtilsTest.class);
suite.addTestSuite(JSF2ValidatorTest.class);
suite.addTestSuite(DocBookTemplatesTest.class);
// suite.addTestSuite(DnD_JBIDE5042_JBIDE6229_Test.class);
Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools=
/jsf/vpe/jsf/test/jbide/SourceDomUtilTest.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/js=
f/vpe/jsf/test/jbide/SourceDomUtilTest.java (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/js=
f/vpe/jsf/test/jbide/SourceDomUtilTest.java 2010-10-05 12:13:48 UTC (rev 25=
487)
@@ -0,0 +1,83 @@
+/*************************************************************************=
******
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ *************************************************************************=
*****/
+package org.jboss.tools.jsf.vpe.jsf.test.jbide;
+
+import java.text.MessageFormat;
+
+import org.jboss.tools.jsf.vpe.jsf.test.JsfAllTests;
+import org.jboss.tools.vpe.editor.VpeController;
+import org.jboss.tools.vpe.editor.util.SourceDomUtil;
+import org.jboss.tools.vpe.ui.test.VpeTest;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Tests for {@link SourceDomUtil} class. =
+ * =
+ * @author Yahor Radtsevich (yradtsevich)
+ * @see JBIDE-7209
+ */
+public class SourceDomUtilTest extends VpeTest {
+ private static final String TEST_FILE_PATH
+ =3D "JBIDE/7209/getNodeByXPath.html"; //$NON-NLS-1$
+ private static final String ID_1 =3D "id1"; //$NON-NLS-1$
+ private static final String ID_2 =3D "id2"; //$NON-NLS-1$
+ private static final String X_PATH_3 =3D "/html/body/table/tr/td[1]/@oncl=
ick"; //$NON-NLS-1$
+ private static final String VALUE_3 =3D "f()"; //$NON-NLS-1$
+
+ private VpeController vpeController;
+
+ public SourceDomUtilTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ vpeController =3D openInVpe(JsfAllTests.IMPORT_PROJECT_NAME,
+ TEST_FILE_PATH);
+ }
+ =
+ /////////////////////////////////////////////////////////////////////////=
///
+ // JUNIT TESTING METHODS
+ /**
+ * Test for {@link SourceDomUtil#getXPath(Node)} and
+ * {@link SourceDomUtil#getNodeByXPath(Document, String)}.
+ * =
+ * @see JBIDE-7209=
a>
+ */
+ public void testGetNodeByXPath() {
+ Document document =3D vpeController.getPageContext()
+ .getSourceBuilder().getSourceDocument();
+ =
+ Node node1 =3D document.getElementById(ID_1);
+ assertNotNull(node1);
+ String xPath1 =3D SourceDomUtil.getXPath(node1);
+ assertEquals(MessageFormat.format(
+ "getNodeByXPath is not inverse of getXPath for {0}", ID_1), //$NON-NLS=
-1$
+ node1, SourceDomUtil.getNodeByXPath(document, xPath1));
+ =
+ Node node2 =3D document.getElementById(ID_2);
+ assertNotNull(node2);
+ String xPath2 =3D SourceDomUtil.getXPath(node2);
+ assertEquals(MessageFormat.format(
+ "getNodeByXPath is not inverse of getXPath for {0}", ID_2), //$NON-NL=
S-1$
+ node2, SourceDomUtil.getNodeByXPath(document, xPath2));
+ =
+ Node node3 =3D SourceDomUtil.getNodeByXPath(document, X_PATH_3);
+ assertTrue(MessageFormat.format("{0} is not an attribute", X_PATH_3), /=
/$NON-NLS-1$
+ node3 instanceof Attr);
+ assertEquals(MessageFormat.format(
+ "Value of {0} is not equal to {1}", X_PATH_3, VALUE_3), //$NON-NLS-1$
+ VALUE_3, ((Attr)node3).getValue());
+ }
+}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd=
/DndUtil.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DndUt=
il.java 2010-10-05 12:10:20 UTC (rev 25486)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DndUt=
il.java 2010-10-05 12:13:48 UTC (rev 25487)
@@ -268,7 +268,8 @@
public static Node getNodeFromDragSession(VpePageContext pageContext) {
String xPath =3D DndUtil.getDragTransferDataAsString(VPE_XPATH_FLAVOR);
if (xPath !=3D null) {
- return SourceDomUtil.getNodeByXPath(pageContext, xPath);
+ return SourceDomUtil.getNodeByXPath(
+ pageContext.getSourceBuilder().getSourceDocument(), xPath);
} else {
return null;
}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd=
/VpeDnD.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDn=
D.java 2010-10-05 12:10:20 UTC (rev 25486)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDn=
D.java 2010-10-05 12:13:48 UTC (rev 25487)
@@ -42,6 +42,7 @@
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
import org.jboss.tools.vpe.editor.mozilla.listener.MozillaDndListener;
import org.jboss.tools.vpe.editor.mozilla.listener.MozillaSelectionListene=
r;
+import org.jboss.tools.vpe.editor.util.SourceDomUtil;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
import org.jboss.tools.vpe.editor.util.VpeDndUtil;
import org.jboss.tools.vpe.messages.VpeUIMessages;
@@ -488,7 +489,7 @@
iTransferable.setTransferData("text/html", nodeSourceData, nodeSourceDat=
aLength); //$NON-NLS-1$
iTransferable.setTransferData("text/unicode", nodeSourceData, nodeSource=
DataLength); //$NON-NLS-1$
=
- String xPath =3D XSLTXPathHelper.calculateXPathToNode(node);
+ String xPath =3D SourceDomUtil.getXPath(node);
nsISupportsString xPathData =3D createNsISupportsString(xPath);
iTransferable.setTransferData(DndUtil.VPE_XPATH_FLAVOR, xPathData, xPath=
.length() * 2);
=
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/edi=
tor/util/SourceDomUtil.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ut=
il/SourceDomUtil.java 2010-10-05 12:10:20 UTC (rev 25486)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ut=
il/SourceDomUtil.java 2010-10-05 12:13:48 UTC (rev 25487)
@@ -13,15 +13,13 @@
import java.util.HashSet;
import java.util.Set;
=
-import javax.xml.transform.TransformerException;
-
import org.eclipse.wst.xml.xpath.core.util.XSLTXPathHelper;
-import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.proxy.VpeProxyUtil;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -114,16 +112,73 @@
}
=
/**
- * Returns source node by its XPath.
+ * Returns a XPath expression given a DOM Node.
+ * =
+ * @param node The DOM Node to create the XPath expression.
+ * =
+ * @see XSLTXPathHelper#calculateXPathToNode(Node)
*/
- public static Node getNodeByXPath(VpePageContext pageContext, String xPat=
h) {
- Node node =3D null;
+ public static String getXPath(Node node) {
+ return XSLTXPathHelper.calculateXPathToNode(node);
+ }
+ =
+ /**
+ * Inverse function for {@link #getXPath(Node)}.
+ * =
+ * @param document ancestor document for xPath
+ * @param xPath XPath to a node in one of the following form:
+ *
+ *
"/html/body/table/tr/td",
+ *
"/html/body/table/tr/td[1]",
+ *
"/html/body/table/tr/td[1]/@onclick".
+ * =
+ * @return node for the given {@code xPath}, or {@code null}
+ * if the node is not found.
+ */
+ public static Node getNodeByXPath(Document document, String xPath) {
+ Node currentNode =3D document;
try {
- node =3D XSLTXPathHelper.selectSingleNode(
- pageContext.getSourceBuilder().getSourceDocument(), xPath);
- } catch (TransformerException e) {
- VpePlugin.reportProblem(e);
+ String[] nodeNames =3D xPath.split("/"); //$NON-NLS-1$
+ =
+ // begin from 1 to skip the first element which is empty
+ for (int i =3D 1; i < nodeNames.length; i++) {
+ String nodeName =3D nodeNames[i];
+ if (nodeName.charAt(0) !=3D '@') {
+ currentNode =3D currentNode.getFirstChild();
+ if (nodeName.charAt(nodeName.length() - 1) !=3D ']') {
+ while (currentNode.getNodeType() !=3D Node.ELEMENT_NODE =
+ || !currentNode.getNodeName().equals(nodeName)) {
+ currentNode =3D currentNode.getNextSibling();
+ }
+ } else {
+ int openingBracketIndex =3D nodeName.lastIndexOf('[');
+ String stringPosition =3D nodeName.substring(
+ openingBracketIndex + 1,
+ nodeName.length() - 1);
+ nodeName =3D nodeName.substring(0, openingBracketIndex);
+ =
+ int position =3D Integer.parseInt(stringPosition);
+ int curPosition =3D 0;
+ while (true) {
+ if (currentNode.getNodeType() =3D=3D Node.ELEMENT_NODE =
+ && currentNode.getNodeName().equals(nodeName)) {
+ ++curPosition;
+ if (curPosition =3D=3D position) {
+ break;
+ }
+ }
+ currentNode =3D currentNode.getNextSibling();
+ }
+ }
+ } else {
+ String attributeName =3D nodeName.substring(1, nodeName.length());
+ currentNode =3D currentNode.getAttributes().getNamedItem(attributeNam=
e);
+ }
+ }
+ } catch (Exception e) {
+ return null;
}
- return node;
+
+ return currentNode;
}
}
Modified: trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/v=
pe/ui/test/ComponentContentTest.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/=
test/ComponentContentTest.java 2010-10-05 12:10:20 UTC (rev 25486)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/=
test/ComponentContentTest.java 2010-10-05 12:13:48 UTC (rev 25487)
@@ -24,6 +24,7 @@
import org.jboss.tools.test.util.WorkbenchUtils;
import org.jboss.tools.vpe.editor.VpeController;
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.editor.util.SourceDomUtil;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
import org.w3c.dom.Document;
@@ -110,7 +111,7 @@
try{
compareElements(controller, xmlTestDocument, id, id);
} catch (DOMComparisonException e) {
- String xPathToNode =3D XSLTXPathHelper.calculateXPathToNode(e.getNode(=
));
+ String xPathToNode =3D SourceDomUtil.getXPath(e.getNode());
String testFileName =3D xmlTestFile.getPath();
String message =3D e.getMessage();
fail(String.format("%s[%s]:\n%s", testFileName, xPathToNode, message))=
; //$NON-NLS-1$
--===============3840613313823157634==--