Author: yradtsevich
Date: 2008-11-28 09:58:58 -0500 (Fri, 28 Nov 2008)
New Revision: 12124
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlBodyTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
trunk/vpe/tests/org.jboss.tools.vpe.html.test/resources/htmlTest/WebContent/pages/components/core/body.html.xml
trunk/vpe/tests/org.jboss.tools.vpe.html.test/resources/htmlTest/WebContent/pages/components/core/html.html.xml
Log:
RESOLVED - issue JBIDE-3280: Styles crash in <body> tag after refresh button press.
https://jira.jboss.org/jira/browse/JBIDE-3280
- The bug has been fixed.
- HtmlBodyTemplate has been refactored
- Tests have been rewritten
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-11-28
14:44:57 UTC (rev 12123)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-11-28
14:58:58 UTC (rev 12124)
@@ -115,7 +115,7 @@
private MozillaEditor visualEditor;
private XulRunnerEditor xulRunnerEditor;
- private nsIDOMDocument visualDocument;
+
// JBIDE-2170 Sergey Dzmitrovich
// private nsIDOMElement visualContentArea;
private VpePageContext pageContext;
@@ -178,7 +178,7 @@
super(domMapping, sorceAdapter, templateManager);
this.visualEditor = visualEditor;
xulRunnerEditor = visualEditor.getXulRunnerEditor();
- this.visualDocument = visualEditor.getDomDocument();
+
// this.visualContentArea = visualEditor.getContentArea();
this.dnd = new VpeDnD();
this.pageContext = pageContext;
@@ -308,24 +308,24 @@
}
if (block) {
if (YES_STRING.equals(VpePreference.USE_DETAIL_BORDER.getValue())) {
- border = visualDocument.createElement(HTML.TAG_TABLE);
+ border = getVisualDocument().createElement(HTML.TAG_TABLE);
border.setAttribute(ATRIBUTE_CELLSPACING, ZERO_STRING);
border.setAttribute(ATRIBUTE_CELLPADDING, ZERO_STRING);
- nsIDOMElement tr1 = visualDocument.createElement(HTML.TAG_TR);
+ nsIDOMElement tr1 = getVisualDocument().createElement(HTML.TAG_TR);
border.appendChild(tr1);
- nsIDOMElement td1 = visualDocument.createElement(HTML.TAG_TD);
+ nsIDOMElement td1 = getVisualDocument().createElement(HTML.TAG_TD);
td1.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
DOTTED_BORDER_STYLE_FOR_TD);
- nsIDOMText text = visualDocument.createTextNode(sourceNode
+ nsIDOMText text = getVisualDocument().createTextNode(sourceNode
.getNodeName());
td1.appendChild(text);
tr1.appendChild(td1);
- nsIDOMElement tr2 = visualDocument.createElement(HTML.TAG_TR);
+ nsIDOMElement tr2 = getVisualDocument().createElement(HTML.TAG_TR);
border.appendChild(tr2);
- nsIDOMElement td2 = visualDocument.createElement(HTML.TAG_TD);
+ nsIDOMElement td2 = getVisualDocument().createElement(HTML.TAG_TD);
tr2.appendChild(td2);
- nsIDOMElement p = visualDocument.createElement(HTML.TAG_P);
+ nsIDOMElement p = getVisualDocument().createElement(HTML.TAG_P);
p.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
DOTTED_BORDER_STYLE);
td2.appendChild(p);
@@ -333,15 +333,15 @@
p.appendChild(visualNode);
} else {
- border = visualDocument.createElement(HTML.TAG_TABLE);
+ border = getVisualDocument().createElement(HTML.TAG_TABLE);
border.setAttribute(ATRIBUTE_CELLSPACING, ZERO_STRING);
border.setAttribute(ATRIBUTE_CELLPADDING, ZERO_STRING);
- nsIDOMElement tr2 = visualDocument.createElement(HTML.TAG_TR);
+ nsIDOMElement tr2 = getVisualDocument().createElement(HTML.TAG_TR);
border.appendChild(tr2);
- nsIDOMElement td2 = visualDocument.createElement(HTML.TAG_TD);
+ nsIDOMElement td2 = getVisualDocument().createElement(HTML.TAG_TD);
tr2.appendChild(td2);
- nsIDOMElement p = visualDocument.createElement(HTML.TAG_P);
+ nsIDOMElement p = getVisualDocument().createElement(HTML.TAG_P);
p.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
DOTTED_BORDER_STYLE);
td2.appendChild(p);
@@ -349,15 +349,15 @@
p.appendChild(visualNode);
}
} else {
- border = visualDocument.createElement(HTML.TAG_SPAN);
+ border = getVisualDocument().createElement(HTML.TAG_SPAN);
border.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
DOTTED_BORDER_STYLE);
if (YES_STRING.equals(VpePreference.USE_DETAIL_BORDER.getValue())) {
- nsIDOMElement name = visualDocument
+ nsIDOMElement name = getVisualDocument()
.createElement(HTML.TAG_SPAN);
name.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
DOTTED_BORDER_STYLE_FOR_SPAN);
- nsIDOMText text = visualDocument.createTextNode(sourceNode
+ nsIDOMText text = getVisualDocument().createTextNode(sourceNode
.getNodeName());
name.appendChild(text);
border.appendChild(name);
@@ -562,13 +562,13 @@
childrenInfoList);
}
} else if(sourceNode.getNodeType() == Node.ELEMENT_NODE&&visualNewNode != null
&& isShowInvisibleTags()){
- nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
+ nsIDOMElement span = getVisualDocument().createElement(HTML.TAG_SPAN);
span.appendChild(visualNewNode);
addChildren(template, sourceNode,span);
visualNewNode= span;
}
getPageContext().setCurrentVisualNode(visualOldContainer);
- template.validate(getPageContext(), sourceNode, visualDocument,
+ template.validate(getPageContext(), sourceNode, getVisualDocument(),
creationData);
getPageContext().setCurrentVisualNode(null);
@@ -681,7 +681,7 @@
if (visualContainer != null) {
// wrap node to span
- wrapper = visualDocument.createElement(HTML.TAG_SPAN);
+ wrapper = getVisualDocument().createElement(HTML.TAG_SPAN);
wrapper.appendChild(visualContainer);
// add all invisible tags to wrapper
@@ -722,11 +722,11 @@
// /////////////////////////////////////////////////////////////////////////
public nsIDOMNode addStyleNodeToHead(String styleText) {
- nsIDOMNode newStyle = visualDocument
+ nsIDOMNode newStyle = getVisualDocument()
.createElement(VpeStyleUtil.ATTRIBUTE_STYLE);
if (styleText != null) {
- nsIDOMText newText = visualDocument.createTextNode(styleText);
+ nsIDOMText newText = getVisualDocument().createTextNode(styleText);
newStyle.appendChild(newText);
}
getHeadNode().appendChild(newStyle);
@@ -735,11 +735,11 @@
public nsIDOMNode replaceStyleNodeToHead(nsIDOMNode oldStyleNode,
String styleText) {
- nsIDOMElement newStyle = visualDocument
+ nsIDOMElement newStyle = getVisualDocument()
.createElement(VpeStyleUtil.ATTRIBUTE_STYLE);
if (styleText != null) {
- nsIDOMNode newText = visualDocument.createTextNode(styleText);
+ nsIDOMNode newText = getVisualDocument().createTextNode(styleText);
newStyle.appendChild(newText);
}
@@ -879,12 +879,12 @@
Node sourceContainer, nsIDOMNode visualContainer) {
if (containerTemplate != null) {
containerTemplate.setPseudoContent(pageContext, sourceContainer,
- visualContainer, visualDocument);
+ visualContainer, getVisualDocument());
} else {
try {
VpeDefaultPseudoContentCreator.getInstance().setPseudoContent(
pageContext, sourceContainer, visualContainer,
- visualDocument);
+ getVisualDocument());
} catch (VpeExpressionException ex) {
VpeExpressionException exception = new VpeExpressionException(
"Error for source node" + sourceContainer.toString(), ex); //$NON-NLS-1$
@@ -904,7 +904,7 @@
System.out.println("-------------------- addPseudoElement: " //$NON-NLS-1$
+ visualParent.getNodeName());
}
- nsIDOMElement visualPseudoElement = visualDocument
+ nsIDOMElement visualPseudoElement = getVisualDocument()
.createElement(PSEUDO_ELEMENT);
visualPseudoElement.setAttribute(PSEUDO_ELEMENT_ATTR, YES_STRING);
visualParent.appendChild(visualPseudoElement);
@@ -1123,7 +1123,7 @@
if (elementMapping.getBorder() != null) {
updateElement(sourceElement);
} else if (template.isRecreateAtAttrChange(pageContext,
- sourceElement, visualDocument,
+ sourceElement, getVisualDocument(),
(nsIDOMElement) elementMapping.getVisualNode(),
elementMapping.getData(), name, value)) {
updateElement(sourceElement);
@@ -1154,7 +1154,7 @@
}
// setXmlnsAttribute(elementMapping, name, value);
template.setAttribute(pageContext, sourceElement,
- visualDocument, visualElement, elementMapping
+ getVisualDocument(), visualElement, elementMapping
.getData(), name, value);
resetTooltip(sourceElement, visualElement);
}
@@ -1295,7 +1295,7 @@
} else {
VpeTemplate template = elementMapping.getTemplate();
if (template.isRecreateAtAttrChange(pageContext, sourceElement,
- visualDocument, (nsIDOMElement) elementMapping
+ getVisualDocument(), (nsIDOMElement) elementMapping
.getVisualNode(), elementMapping.getData(),
name, null)) {
updateElement(sourceElement);
@@ -1398,7 +1398,7 @@
* vpe="ATTR_VPE_INLINE_LINK_VALUE">file content</style> It is
* LinkReplacer
*/
- linkNode = visualDocument.createElement(HTML.TAG_STYLE);
+ linkNode = getVisualDocument().createElement(HTML.TAG_STYLE);
linkNode.setAttribute(ATTR_VPE, ATTR_VPE_INLINE_LINK_VALUE);
/* Copy links attributes into our <style> */
@@ -1421,7 +1421,7 @@
styleForParse, href_val);
in.close();
- nsIDOMText textNode = visualDocument
+ nsIDOMText textNode = getVisualDocument()
.createTextNode(styleForParse);
linkNode.appendChild(textNode);
return linkNode;
@@ -1440,7 +1440,7 @@
}
}
- linkNode = visualDocument.createElement(HTML.TAG_LINK);
+ linkNode = getVisualDocument().createElement(HTML.TAG_LINK);
linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_REL, rel_val);
linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_HREF, href_val);
linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_EXT, ext_val);
@@ -1547,7 +1547,7 @@
.getTagDescription(
pageContext,
(Element) nodeMapping.getSourceNode(),
- visualDocument,
+ getVisualDocument(),
(nsIDOMElement) nodeMapping.getVisualNode()
.queryInterface(
nsIDOMElement.NS_IDOMELEMENT_IID),
@@ -1563,7 +1563,7 @@
.getNodeMapping(element);
if (elementMapping != null) {
elementMapping.getTemplate().resize(pageContext,
- (Element) elementMapping.getSourceNode(), visualDocument,
+ (Element) elementMapping.getSourceNode(), getVisualDocument(),
element, elementMapping.getData(), resizerConstrains, top,
left, width, height);
}
@@ -1590,7 +1590,7 @@
&& elementMapping.getSourceNode() instanceof Element) {
return elementMapping.getTemplate().canInnerDrag(pageContext,
(Element) elementMapping.getSourceNode(),
- visualDocument, visualDragElement,
+ getVisualDocument(), visualDragElement,
elementMapping.getData());
}
}
@@ -2231,7 +2231,6 @@
* the dnd to set
*/
public void setDnd(VpeDnD dnd) {
-
this.dnd = dnd;
}
@@ -2254,18 +2253,10 @@
* @return the visualDocument
*/
protected nsIDOMDocument getVisualDocument() {
- return visualDocument;
+ return visualEditor.getDomDocument();
}
/**
- * @param visualDocument
- * the visualDocument to set
- */
- protected void setVisualDocument(nsIDOMDocument visualDocument) {
- this.visualDocument = visualDocument;
- }
-
- /**
* Check this file is facelet
*
* @return this if file is facelet, otherwize false
@@ -2336,12 +2327,12 @@
* @return
*/
public nsIDOMNode createInvisbleElementLabel(Node sourceNode) {
- nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
+ nsIDOMElement span = getVisualDocument().createElement(HTML.TAG_SPAN);
span.setAttribute(HTML.TAG_STYLE,
"border: 1px dashed GREY; color: GREY; font-size: 12px;"); //$NON-NLS-1$
- nsIDOMText text = visualDocument.createTextNode(sourceNode
+ nsIDOMText text = getVisualDocument().createTextNode(sourceNode
.getNodeName());
span.appendChild(text);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlBodyTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlBodyTemplate.java 2008-11-28
14:44:57 UTC (rev 12123)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlBodyTemplate.java 2008-11-28
14:58:58 UTC (rev 12124)
@@ -19,103 +19,89 @@
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNamedNodeMap;
import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMNodeList;
import org.mozilla.xpcom.XPCOMException;
import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
/**
- *
* @author ezheleznyakov(a)exadel.com
- *
*/
public class HtmlBodyTemplate extends VpeAbstractTemplate {
- private nsIDOMElement bodyOld;
- private static String STYLE_FOR_DIV = ""; //$NON-NLS-1$
- private static String ID = "id"; //$NON-NLS-1$
-
- /**
- *
- */
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
+ final nsIDOMElement body = getBody(visualDocument.getDocumentElement());
- goToTree(visualDocument.getDocumentElement());
-
- nsIDOMNamedNodeMap attrsMap = bodyOld.getAttributes();
+ nsIDOMNamedNodeMap attrsMap = body.getAttributes();
long len = attrsMap.getLength();
int j = 0;
for (int i = 0; i < len; i++) {
nsIDOMNode attr = attrsMap.item(j);
- if (ID.equalsIgnoreCase(attr.getNodeName())) {
+ if (HTML.ATTR_ID.equalsIgnoreCase(attr.getNodeName())) {
j++;
- continue;
+ } else {
+ body.removeAttribute(attr.getNodeName());
}
- bodyOld.removeAttribute(attr.getNodeName());
}
- for (int i = 0; i < sourceNode.getAttributes().getLength(); i++) {
- String name = sourceNode.getAttributes().item(i).getNodeName();
- if(ID.equalsIgnoreCase(name))
- continue;
- String value = sourceNode.getAttributes().item(i).getNodeValue();
- // all full path for 'url'
- if (VpeStyleUtil.ATTRIBUTE_STYLE.equalsIgnoreCase(name))
- value = VpeStyleUtil.addFullPathIntoURLValue(value, pageContext
- .getEditPart().getEditorInput());
- if (VpeStyleUtil.PARAMETR_BACKGROND.equalsIgnoreCase(name))
- value = VpeStyleUtil.addFullPathIntoBackgroundValue(value,
- pageContext.getEditPart().getEditorInput());
- //FIX FOR JBIDE-1568, added by Max Areshkau
- try{
- bodyOld.setAttribute(name, value);
- }catch(XPCOMException ex ) {
- //jsut ignore it
- }
-
+ final nsIDOMElement div = visualDocument.createElement(HTML.TAG_DIV);
+ final NamedNodeMap sourceNodeAttributes = sourceNode.getAttributes();
+ for (int i = 0; i < sourceNodeAttributes.getLength(); i++) {
+ final Node sourceNodeAttribute = sourceNodeAttributes.item(i);
+ final String name = sourceNodeAttribute.getNodeName();
+ String value = sourceNodeAttribute.getNodeValue();
+ if(HTML.ATTR_ID.equalsIgnoreCase(name)) {
+ div.setAttribute(HTML.ATTR_ID, value);
+ } else {
+ // all full path for 'url'
+ if (VpeStyleUtil.ATTRIBUTE_STYLE.equalsIgnoreCase(name))
+ value = VpeStyleUtil.addFullPathIntoURLValue(value, pageContext
+ .getEditPart().getEditorInput());
+ if (VpeStyleUtil.PARAMETR_BACKGROND.equalsIgnoreCase(name))
+ value = VpeStyleUtil.addFullPathIntoBackgroundValue(value,
+ pageContext.getEditPart().getEditorInput());
+ //FIX FOR JBIDE-1568, added by Max Areshkau
+ try{
+ body.setAttribute(name, value);
+ }catch(XPCOMException ex ) {
+ //jsut ignore it
+ }
+ }
}
- nsIDOMElement div = visualDocument.createElement(HTML.TAG_DIV);
- div.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, STYLE_FOR_DIV);
-
return new VpeCreationData(div);
}
/**
+ * Finds {@code BODY}-element
*
- * @param node
+ * @param node a visual node
+ * @return the nearest child of {@code node} named {@code 'BODY'}
*/
- private void goToTree(nsIDOMNode node) {
+ private nsIDOMElement getBody(nsIDOMNode node) {
- for (int i = 0; i < node.getChildNodes().getLength(); i++)
- if (HTML.TAG_BODY.equalsIgnoreCase(node.getChildNodes().item(i)
- .getNodeName()))
- bodyOld = (nsIDOMElement) node.getChildNodes().item(i)
+ final nsIDOMNodeList nodeChildren = node.getChildNodes();
+ for (int i = 0; i < nodeChildren.getLength(); i++) {
+ final nsIDOMNode nodeChild = nodeChildren.item(i);
+ if (HTML.TAG_BODY.equalsIgnoreCase(nodeChild
+ .getNodeName())) {
+ return (nsIDOMElement) nodeChild
.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- else
- goToTree(node.getChildNodes().item(i));
+ } else {
+ nsIDOMElement body = getBody(nodeChild);
+ if (body != null) {
+ return body;
+ }
+ }
+ }
+
+ return null;
}
/**
- * Checks, whether it is necessary to re-create an element at change of
- * attribute
- *
- * @param pageContext
- * Contains the information on edited page.
- * @param sourceElement
- * The current element of the source tree.
- * @param visualDocument
- * The document of the visual tree.
- * @param visualNode
- * The current node of the visual tree.
- * @param data
- * The arbitrary data, built by a method <code>create</code>
- * @param name
- * Attribute name
- * @param value
- * Attribute value
- * @return <code>true</code> if it is required to re-create an element at
- * a modification of attribute, <code>false</code> otherwise.
+ * {@inheritDoc}
*/
public boolean isRecreateAtAttrChange(VpePageContext pageContext,
Element sourceElement, nsIDOMDocument visualDocument,
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.html.test/resources/htmlTest/WebContent/pages/components/core/body.html.xml
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.html.test/resources/htmlTest/WebContent/pages/components/core/body.html.xml 2008-11-28
14:44:57 UTC (rev 12123)
+++
trunk/vpe/tests/org.jboss.tools.vpe.html.test/resources/htmlTest/WebContent/pages/components/core/body.html.xml 2008-11-28
14:58:58 UTC (rev 12124)
@@ -1,10 +1,10 @@
<tests>
<test id="body">
- <DIV STYLE="" >
+ <DIV ID="body">
<H1 STYLE="-moz-user-modify: read-write;">
<SPAN>
body
- </SPAN>
+ </SPAN>
</H1>
</DIV>
</test>
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.html.test/resources/htmlTest/WebContent/pages/components/core/html.html.xml
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.html.test/resources/htmlTest/WebContent/pages/components/core/html.html.xml 2008-11-28
14:44:57 UTC (rev 12123)
+++
trunk/vpe/tests/org.jboss.tools.vpe.html.test/resources/htmlTest/WebContent/pages/components/core/html.html.xml 2008-11-28
14:58:58 UTC (rev 12124)
@@ -6,7 +6,7 @@
STYLE="font-style: italic; color: green; -moz-user-modify: read-only;"
/>
</DIV>
- <DIV STYLE="">
+ <DIV>
<H1 STYLE="-moz-user-modify: read-write;">
<SPAN>
html