Author: sdzmitrovich
Date: 2008-06-09 12:07:59 -0400 (Mon, 09 Jun 2008)
New Revision: 8646
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/DocTypeUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FaceletUtil.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlBodyTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
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/mozilla/MozillaEditor.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaPreview.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java
Log:
JBIDE-2170
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelTemplate.java 2008-06-09
15:53:50 UTC (rev 8645)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelTemplate.java 2008-06-09
16:07:59 UTC (rev 8646)
@@ -87,7 +87,7 @@
// FIX for JBIDE-1213 (Max Areshkau)
if(data.getNode()!=null) {
String bodyClass = ((Element)sourceNode).getAttribute("bodyClass");
- applyStylesToTable(data.getNode(), bodyClass);
+ //applyStylesToTable(data.getNode(), bodyClass);
}
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-06-09
15:53:50 UTC (rev 8645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-06-09
16:07:59 UTC (rev 8646)
@@ -20,7 +20,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionItem;
@@ -137,10 +136,10 @@
import org.jboss.tools.vpe.editor.template.VpeTemplateListener;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
+import org.jboss.tools.vpe.editor.util.DocTypeUtil;
import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
import org.jboss.tools.vpe.editor.util.TextUtil;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
-import org.jboss.tools.vpe.editor.util.VpeDebugUtil;
import org.jboss.tools.vpe.editor.util.VpeDndUtil;
import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.selbar.SelectionBar;
@@ -1454,16 +1453,28 @@
}
void visualRefreshImpl() {
- visualEditor.hideResizer();
- visualBuilder.setSelectionRectangle(null);
- IDOMModel sourceModel = (IDOMModel) getModel();
- if (sourceModel != null) {
- IDOMDocument sourceDocument = sourceModel.getDocument();
- visualBuilder.rebuildDom(sourceDocument);
- } else {
- visualBuilder.rebuildDom(null);
+
+ visualEditor.hideResizer();
+
+ String currentDoctype = DocTypeUtil.getDoctype(visualEditor
+ .getEditorInput());
+
+ if (!visualEditor.getDoctype().equals(currentDoctype)) {
+
+ visualEditor.reload();
+
+ }else {
+
+ visualBuilder.setSelectionRectangle(null);
+ IDOMModel sourceModel = (IDOMModel) getModel();
+ if (sourceModel != null) {
+ IDOMDocument sourceDocument = sourceModel.getDocument();
+ visualBuilder.rebuildDom(sourceDocument);
+ } else {
+ visualBuilder.rebuildDom(null);
+ }
+ }
}
- }
public void preLongOperation() {
switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
@@ -2919,5 +2930,22 @@
}
return changeEvents;
}
+
+ public void reinit() {
+ visualBuilder.setSelectionRectangle(null);
+ visualEditor.setEditorDomEventListener(this);
+ IDOMModel sourceModel = (IDOMModel) getModel();
+ if (sourceModel != null) {
+ IDOMDocument sourceDocument = sourceModel.getDocument();
+ visualBuilder.rebuildDom(sourceDocument);
+ } else {
+ visualBuilder.rebuildDom(null);
+ }
+
+ visualSelectionController.setSelection(xulRunnerEditor
+ .getSelection());
+
+ }
+
}
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-06-09
15:53:50 UTC (rev 8645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-06-09
16:07:59 UTC (rev 8646)
@@ -67,6 +67,7 @@
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
import org.jboss.tools.vpe.editor.template.VpeToggableTemplate;
import org.jboss.tools.vpe.editor.template.dnd.VpeDnd;
+import org.jboss.tools.vpe.editor.util.FaceletUtil;
import org.jboss.tools.vpe.editor.util.HTML;
import org.jboss.tools.vpe.editor.util.TextUtil;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
@@ -115,10 +116,12 @@
private MozillaEditor visualEditor;
private XulRunnerEditor xulRunnerEditor;
private nsIDOMDocument visualDocument;
- private nsIDOMElement visualContentArea;
+ // JBIDE-2170 Sergey Dzmitrovich
+ // private nsIDOMElement visualContentArea;
private VpePageContext pageContext;
private VpeDnD dnd;
- private nsIDOMNode headNode;
+ // JBIDE-2170 Sergey Dzmitrovich
+ // private nsIDOMNode headNode;
private List includeStack;
// TODO Max Areshkau JBIDE-1457
// boolean rebuildFlag = false;
@@ -167,18 +170,6 @@
private Map<IFile, Document> includeDocuments = new HashMap<IFile,
Document>();
-
- /**
- * facelet elements, if there are these elements on a page then other
- * elements are deleted
- */
- static private HashSet<String> faceletRootElements = new HashSet<String>();
-
- static {
- faceletRootElements.add("composition"); //$NON-NLS-1$
- faceletRootElements.add("component"); //$NON-NLS-1$
- }
-
public VpeVisualDomBuilder(VpeDomMapping domMapping,
INodeAdapter sorceAdapter, VpeTemplateManager templateManager,
MozillaEditor visualEditor, VpePageContext pageContext) {
@@ -186,10 +177,10 @@
this.visualEditor = visualEditor;
xulRunnerEditor = visualEditor.getXulRunnerEditor();
this.visualDocument = visualEditor.getDomDocument();
- this.visualContentArea = visualEditor.getContentArea();
+// this.visualContentArea = visualEditor.getContentArea();
this.dnd = new VpeDnD();
this.pageContext = pageContext;
- this.headNode = visualEditor.getHeadNode();
+// this.headNode = visualEditor.getHeadNode();
dropper = new VpeDnd();
dropper.setDndData(false, true);
@@ -219,77 +210,35 @@
pageContext.refreshConnector();
pageContext.installIncludeElements();
if (isFacelet()) {
- Element root = getRootElement(sourceDocument);
- if(root != null)
- {
- addNode(root, null, visualContentArea);
+ Element root = FaceletUtil.getRootFaceletElement(sourceDocument);
+ if (root != null) {
+ addNode(root, null, getContentArea());
}
} else {
- addChildren(null, sourceDocument, visualContentArea);
+ addChildren(null, sourceDocument, getContentArea());
}
/*
* Fixes
http://jira.jboss.com/jira/browse/JBIDE-2126.
* To provide appropriate context menu functionality
* visual content area should be mapped in any case.
*/
- registerNodes(new VpeNodeMapping(sourceDocument, visualContentArea));
+ registerNodes(new VpeNodeMapping(sourceDocument, getContentArea()));
}
- private Element getRootElement(Document sourceDocument) {
-
- NodeList nodeList = sourceDocument.getChildNodes();
- Element root = null;
-
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node child = nodeList.item(i);
- if (child.getNodeType() == Node.ELEMENT_NODE) {
- root = (Element) child;
- break;
- }
- }
-
- if (root != null) {
- Element trimmedElement = findFaceletRootElement(root);
- if (trimmedElement != null)
- root = trimmedElement;
- }
- return root;
- }
-
- private Element findFaceletRootElement(Element element) {
-
- NodeList children = element.getChildNodes();
-
- for (int i = 0; i < children.getLength(); i++) {
- Node child = children.item(i);
- if (child.getNodeType() == Node.ELEMENT_NODE) {
-
- Element trimmedElement = findFaceletRootElement((Element) child);
- if (trimmedElement != null)
- return trimmedElement;
-
- }
- }
-
- if (faceletRootElements.contains(element.getLocalName()))
- return element;
- return null;
- }
-
public void rebuildDom(Document sourceDocument) {
// clearIncludeDocuments();
cleanHead();
- domMapping.clear(visualContentArea);
+ domMapping.clear(getContentArea());
super.dispose();
pageContext.clearAll();
refreshExternalLinks();
pageContext.getBundle().refreshRegisteredBundles();
- nsIDOMNodeList children = visualContentArea.getChildNodes();
+ nsIDOMNodeList children = getContentArea().getChildNodes();
long len = children.getLength();
for (long i = len - 1; i >= 0; i--) {
- visualContentArea.removeChild(children.item(i));
+ getContentArea().removeChild(children.item(i));
}
if (sourceDocument != null) {
@@ -663,7 +612,7 @@
nsIDOMText newText = visualDocument.createTextNode(styleText);
newStyle.appendChild(newText);
}
- headNode.appendChild(newStyle);
+ getHeadNode().appendChild(newStyle);
return newStyle;
}
@@ -677,12 +626,12 @@
newStyle.appendChild(newText);
}
- headNode.replaceChild(newStyle, oldStyleNode);
+ getHeadNode().replaceChild(newStyle, oldStyleNode);
return newStyle;
}
public void removeStyleNodeFromHead(nsIDOMNode oldStyleNode) {
- headNode.removeChild(oldStyleNode);
+ getHeadNode().removeChild(oldStyleNode);
}
void addExternalLinks() {
@@ -704,7 +653,7 @@
}
void removeExternalLinks() {
- nsIDOMNodeList childs = headNode.getChildNodes();
+ nsIDOMNodeList childs = getHeadNode().getChildNodes();
long length = childs.getLength();
for (long i = length - 1; i >= 0; i--) {
nsIDOMNode node = childs.item(i);
@@ -721,7 +670,7 @@
.equalsIgnoreCase(element.getAttribute(ATTR_VPE))))
&& YES_STRING.equalsIgnoreCase(element
.getAttribute(VpeTemplateManager.ATTR_LINK_EXT))) {
- headNode.removeChild(node);
+ getHeadNode().removeChild(node);
}
}
}
@@ -850,7 +799,7 @@
}
public boolean isEmptyDocument() {
- nsIDOMNodeList visualNodes = visualContentArea.getChildNodes();
+ nsIDOMNodeList visualNodes = getContentArea().getChildNodes();
long len = visualNodes.getLength();
if ((len == 0)
|| (len == 1 && (isEmptyText(visualNodes.item(0)) ||
isPseudoElement(visualNodes
@@ -1291,11 +1240,11 @@
}
boolean isContentArea(nsIDOMNode visualNode) {
- return visualContentArea.equals(visualNode);
+ return getContentArea().equals(visualNode);
}
nsIDOMElement getContentArea() {
- return visualContentArea;
+ return visualEditor.getContentArea();
}
public void setSelectionRectangle(nsIDOMElement visualElement) {
@@ -1314,8 +1263,8 @@
//TODO Dzmitry Sakovich
// Fix priority CSS classes JBIDE-1713
- nsIDOMNode firstNode = headNode.getFirstChild();
- headNode.insertBefore(newNode, firstNode);
+ nsIDOMNode firstNode = getHeadNode().getFirstChild();
+ getHeadNode().insertBefore(newNode, firstNode);
return newNode;
}
@@ -1323,7 +1272,7 @@
String href_val, String ext_val) {
nsIDOMNode newNode = createLinkNode(href_val,
ATTR_REL_STYLESHEET_VALUE, ext_val);
- headNode.replaceChild(newNode, oldNode);
+ getHeadNode().replaceChild(newNode, oldNode);
return newNode;
}
@@ -1337,7 +1286,7 @@
}
public void removeLinkNodeFromHead(nsIDOMNode node) {
- headNode.removeChild(node);
+ getHeadNode().removeChild(node);
}
private nsIDOMElement createLinkNode(String href_val, String rel_val,
@@ -1401,7 +1350,7 @@
}
private nsIDOMNode getLinkNode(String href_val, String ext_val) {
- nsIDOMNodeList children = headNode.getChildNodes();
+ nsIDOMNodeList children = getHeadNode().getChildNodes();
long len = children.getLength();
for (long i = len - 1; i >= 0; i--) {
nsIDOMNode node = children.item(i);
@@ -1424,7 +1373,7 @@
}
private void cleanHead() {
- nsIDOMNodeList children = headNode.getChildNodes();
+ nsIDOMNodeList children = getHeadNode().getChildNodes();
long len = children.getLength();
for (long i = len - 1; i >= 0; i--) {
nsIDOMNode node = children.item(i);
@@ -1444,14 +1393,14 @@
// nsIStyleSheetLinkingElement linkingElement = new
// nsIStyleSheetLinkingElement(linkAddress);
// linkingElement.removeStyleSheet();
- node = headNode.removeChild(node);
+ node = getHeadNode().removeChild(node);
}
} else if (HTML.TAG_STYLE.equalsIgnoreCase(node.getNodeName())
&& (!YES_STRING
.equalsIgnoreCase(((nsIDOMElement) node
.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))
.getAttribute(ATTR_VPE)))) {
- node = headNode.removeChild(node);
+ node = getHeadNode().removeChild(node);
}
}
}
@@ -1580,7 +1529,7 @@
}
if (sourceDropContainer == null) {
sourceDropContainer = domMapping
- .getNearSourceNode(visualContentArea);
+ .getNearSourceNode(getContentArea());
sourceDropOffset = sourceDropContainer.getChildNodes()
.getLength();
}
@@ -2144,7 +2093,7 @@
clearIncludeDocuments();
includeDocuments = null;
cleanHead();
- domMapping.clear(visualContentArea);
+ domMapping.clear(getContentArea());
pageContext.dispose();
super.dispose();
}
@@ -2364,4 +2313,8 @@
public Map<IFile, Document> getIncludeDocuments() {
return includeDocuments;
}
+
+ public nsIDOMNode getHeadNode() {
+ return visualEditor.getHeadNode();
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2008-06-09
15:53:50 UTC (rev 8645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2008-06-09
16:07:59 UTC (rev 8646)
@@ -56,6 +56,7 @@
import org.jboss.tools.vpe.editor.toolbar.VpeToolBarManager;
import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
import org.jboss.tools.vpe.editor.toolbar.format.TextFormattingToolBar;
+import org.jboss.tools.vpe.editor.util.DocTypeUtil;
import org.jboss.tools.vpe.editor.util.HTML;
import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
@@ -67,7 +68,7 @@
import org.mozilla.interfaces.nsIDOMNodeList;
public class MozillaEditor extends EditorPart implements IReusableEditor {
- protected static final String INIT_URL = "file://" + (new
File(VpePlugin.getDefault().getResourcePath("ve"),
"init.html")).getAbsolutePath(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ protected static final String INIT_URL = /*"file://" +*/ (new
File(VpePlugin.getDefault().getResourcePath("ve"),
"init.html")).getAbsolutePath(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// private static final String INIT_URL = "chrome://vpe/content/init.html";
//$NON-NLS-1$
private static final String CONTENT_AREA_ID = "__content__area__";
//$NON-NLS-1$
@@ -86,7 +87,9 @@
private FormatControllerManager formatControllerManager = new
FormatControllerManager();
private VpeController controller;
private Link link = null;
- private boolean loaded;
+ private boolean loaded;
+ private boolean loadPage;
+ private String doctype;
public void doSave(IProgressMonitor monitor) {
}
@@ -212,10 +215,20 @@
cmpEd.setBackground(buttonDarker);
try {
+ loadPage = true;
xulRunnerEditor = new XulRunnerEditor(cmpEd) {
public void onLoadWindow() {
- super.onLoadWindow();
- MozillaEditor.this.onLoadWindow();
+ // if the first load page
+ if (loadPage) {
+ super.onLoadWindow();
+ MozillaEditor.this.onLoadWindow();
+ loadPage = false;
+ }
+ // if only refresh page
+ else {
+ MozillaEditor.this.onReloadWindow();
+ }
+
}
public void onElementResize(nsIDOMElement element, int resizerConstrains, int top,
int left, int width, int height) {
if (editorDomEventListener != null) {
@@ -249,7 +262,10 @@
}
});
- xulRunnerEditor.setURL(INIT_URL);
+
+ doctype = DocTypeUtil.getDoctype(getEditorInput());
+ xulRunnerEditor.setText(doctype
+ + DocTypeUtil.getContentInitFile(new File(INIT_URL)));
// Wait while visual part is loaded
while (!loaded) {
if (!Display.getCurrent().readAndDispatch())
@@ -629,6 +645,36 @@
this.contentAreaEventListener = contentAreaEventListener;
}
+
+
+ /**
+ *
+ */
+ private void onReloadWindow() {
+ removeDomEventListeners();
+ contentArea = findContentArea();
+ addDomEventListeners();
+ controller.reinit();
+
+ }
+ /**
+ *
+ */
+ public void reload() {
+
+ doctype = DocTypeUtil.getDoctype(getEditorInput());
+ xulRunnerEditor.setText(doctype
+ + DocTypeUtil.getContentInitFile(new File(INIT_URL)));
+
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getDoctype() {
+ return doctype;
+ }
}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaPreview.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaPreview.java 2008-06-09
15:53:50 UTC (rev 8645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaPreview.java 2008-06-09
16:07:59 UTC (rev 8646)
@@ -36,6 +36,7 @@
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+import org.jboss.tools.vpe.editor.util.DocTypeUtil;
import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
@@ -89,7 +90,9 @@
super.onDispose();
}
});
- getXulRunnerEditor().setURL(INIT_URL);
+// getXulRunnerEditor().setURL(INIT_URL);
+ getXulRunnerEditor().setText(DocTypeUtil.prepareInitFile(INIT_URL,
+ getEditorInput()));
getXulRunnerEditor().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
} catch (Exception e) {
Label title = new Label(parent, SWT.WRAP);
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/DocTypeUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/DocTypeUtil.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/DocTypeUtil.java 2008-06-09
16:07:59 UTC (rev 8646)
@@ -0,0 +1,353 @@
+package org.jboss.tools.vpe.editor.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.eclipse.core.filebuffers.LocationKind;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.editors.text.ILocationProvider;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.FileBufferModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class DocTypeUtil {
+
+ static private List<String> urlTags;
+
+ static {
+ urlTags = new ArrayList<String>();
+ urlTags.add("link"); //$NON-NLS-1$
+ }
+
+ static private List<String> urlAttributes;
+
+ static {
+ urlAttributes = new ArrayList<String>();
+ urlAttributes.add("href"); //$NON-NLS-1$
+ }
+
+ /**
+ * get doctype by {@link IEditorInput}
+ *
+ * @param editorInput
+ * @return
+ */
+ static public String getDoctype(IEditorInput editorInput) {
+
+ // if opened file is located in eclipse workspace
+ if (editorInput instanceof IFileEditorInput) {
+ IFile f = ((IFileEditorInput) editorInput).getFile();
+ return (f == null || !f.exists()) ? null : getDoctype(f);
+ }
+ // if opened file is not located in eclipse workspace
+ else if (editorInput instanceof ILocationProvider) {
+ IPath path = ((ILocationProvider) editorInput).getPath(editorInput);
+ if (path == null || path.segmentCount() < 1)
+ return null;
+ return getDoctype(path.toFile());
+ }
+ return null;
+
+ }
+
+ /**
+ * get doctype by {@link IFile}
+ *
+ * @param file
+ * @return
+ */
+ static public String getDoctype(IFile file) {
+
+ String docTypeValue = null;
+
+ // get document
+ IDOMDocument document = getDocument(file);
+
+ if (document != null) {
+
+ /*
+ * if there is "component" element (ui:composition or ui:component )
+ * so we don't use doctype from current page (as all text outside
+ * this elements will be removed)
+ */
+
+ // find "component" element
+ Element componentElement = FaceletUtil
+ .findComponentElement(document.getDocumentElement());
+
+ // if "component" element was not found return doctype from current
+ // page
+ if (componentElement == null) {
+
+ IDOMDocumentType documentType = (IDOMDocumentType) document
+ .getDoctype();
+
+ if (documentType != null)
+ docTypeValue = documentType.getSource();
+
+ }
+
+ // if "component" element was not found return doctype from current
+ // page
+ else if ((componentElement != null)
+ && (FaceletUtil.TAG_COMPOSITION.equals(componentElement
+ .getLocalName()))
+ && (componentElement
+ .hasAttribute(FaceletUtil.ATTR_TEMPLATE))) {
+
+ // get attribute "template"
+ Attr attr = ((Element) componentElement)
+ .getAttributeNode(FaceletUtil.ATTR_TEMPLATE);
+
+ if (attr.getNodeValue().trim().length() > 0) {
+
+ // get name of template file
+ String fileName = attr.getNodeValue().trim();
+
+ // get file
+ IFile templateFile = FileUtil.getFile(fileName, file);
+
+ if (templateFile != null)
+ docTypeValue = getDoctype(templateFile);
+
+ }
+
+ }
+ }
+ return docTypeValue != null ? docTypeValue.trim() : ""; //$NON-NLS-1$
+ }
+
+ /**
+ * get doctype by {@link File}
+ *
+ * @param file
+ * @return
+ */
+ static public String getDoctype(File file) {
+
+ String docTypeValue = null;
+
+ // get document
+ IDOMDocument document = getDocument(file);
+
+ if (document != null) {
+
+ /*
+ * if there is "component" element (ui:composition or ui:component )
+ * so we don't use doctype from current page (as all text outside
+ * this elements will be removed)
+ */
+
+ // find "component" element
+ Element componentElement = FaceletUtil
+ .findComponentElement(document.getDocumentElement());
+
+ // if "component" element was not found return doctype from current
+ // page
+ if (componentElement == null) {
+
+ IDOMDocumentType documentType = (IDOMDocumentType) document
+ .getDoctype();
+
+ if (documentType != null)
+ docTypeValue = documentType.getSource();
+
+ }
+
+ // if "component" element was not found return doctype from current
+ // page
+ else if ((componentElement != null)
+ && (FaceletUtil.TAG_COMPOSITION.equals(componentElement
+ .getLocalName()))
+ && (componentElement
+ .hasAttribute(FaceletUtil.ATTR_TEMPLATE))) {
+
+ // get attribute "template"
+ Attr attr = ((Element) componentElement)
+ .getAttributeNode(FaceletUtil.ATTR_TEMPLATE);
+
+ if (attr.getNodeValue().trim().length() > 0) {
+
+ // get name of template file
+ String fileName = attr.getNodeValue().trim();
+
+ // get file
+ File templateFile = new File(file.getParent(), fileName);
+
+ if (templateFile.exists())
+ docTypeValue = getDoctype(templateFile);
+
+ }
+
+ }
+ }
+ return docTypeValue != null ? docTypeValue.trim() : ""; //$NON-NLS-1$
+
+ }
+
+ /**
+ * get document by {@link IFile}
+ *
+ * @param file
+ * @return
+ */
+ static private IDOMDocument getDocument(IFile file) {
+
+ IDOMDocument document = null;
+
+ if (file != null) {
+ try {
+
+ // get model
+ IDOMModel model = (IDOMModel) StructuredModelManager
+ .getModelManager().getModelForRead(file);
+
+ if (model != null)
+ document = model.getDocument();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return document;
+ }
+
+ /**
+ * get document by {@link File}
+ *
+ * @param file
+ * @return
+ */
+ static private IDOMDocument getDocument(File file) {
+
+ // if (file.exists()) {
+ //
+ // String content = org.jboss.tools.common.util.FileUtil
+ // .readFile(file);
+ //
+ // IStructuredDocument newStructuredDocument = StructuredDocumentFactory
+ // .getNewStructuredDocumentInstance(new JSPSourceParser());
+ //
+ // newStructuredDocument.set(content);
+ //
+ // IDOMModel modelForJSP = new DOMModelForJSP();
+ // modelForJSP.setStructuredDocument(newStructuredDocument);
+ //
+ // return modelForJSP.getDocument();
+ //
+ // }
+ // return null;
+
+ IDOMModel model = null;
+
+ ITextFileBufferManager bufferManager = FileBuffers
+ .getTextFileBufferManager();
+ IPath location = new Path(file.getAbsolutePath());
+
+ try {
+ bufferManager.connect(location, LocationKind.LOCATION,
+ new NullProgressMonitor());
+
+ ITextFileBuffer buffer = bufferManager.getTextFileBuffer(location,
+ LocationKind.LOCATION);
+ if (buffer != null) {
+
+ IDocument bufferDocument = buffer.getDocument();
+ if (bufferDocument instanceof IStructuredDocument) {
+ model = (IDOMModel) FileBufferModelManager.getInstance()
+ .getModel((IStructuredDocument) bufferDocument);
+ } else {
+
+ bufferManager.disconnect(location, LocationKind.IFILE,
+ new NullProgressMonitor());
+ }
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+
+ return model.getDocument();
+ }
+
+ /**
+ * get
+ *
+ * @param initFilePath
+ * @param editorInput
+ * @return
+ */
+ public static String prepareInitFile(String initFilePath,
+ IEditorInput editorInput) {
+
+ return getDoctype(editorInput)
+ + getContentInitFile(new File(initFilePath));
+
+ }
+
+ /**
+ * get content of initFile, corrected paths on a page
+ *
+ * @param initFile
+ * @return
+ */
+ public static String getContentInitFile(File initFile) {
+
+ IDOMDocument document = getDocument(initFile);
+
+ if (document != null) {
+ // for each tag's name
+ for (String tag : urlTags) {
+
+ NodeList list = document.getElementsByTagName(tag);
+
+ for (int i = 0; i < list.getLength(); i++) {
+
+ Element element = (Element) list.item(i);
+
+ // for each attribute's name
+ for (String attributeName : urlAttributes) {
+
+ if (element.hasAttribute(attributeName)) {
+
+ Attr attr = element.getAttributeNode(attributeName);
+
+ // corrected path
+ attr.setValue(initFile.getParent() + File.separator
+ + attr.getValue());
+
+ }
+
+ }
+
+ }
+
+ }
+
+ return (document).getSource();
+ }
+
+ return ""; //$NON-NLS-1$
+
+ }
+}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FaceletUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FaceletUtil.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FaceletUtil.java 2008-06-09
16:07:59 UTC (rev 8646)
@@ -0,0 +1,69 @@
+package org.jboss.tools.vpe.editor.util;
+
+import java.util.HashSet;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class FaceletUtil {
+
+ public static final String TAG_COMPOSITION = "composition"; //$NON-NLS-1$
+ public static final String TAG_COMPONENT = "component"; //$NON-NLS-1$
+
+ public static final String ATTR_TEMPLATE = "template"; //$NON-NLS-1$
+
+ /**
+ * facelet elements, if there are these elements on a page then other
+ * elements are deleted
+ */
+ static public HashSet<String> componentElements = new HashSet<String>();
+
+ static {
+ componentElements.add(TAG_COMPOSITION); //$NON-NLS-1$
+ componentElements.add(TAG_COMPONENT); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @param root
+ * @return
+ */
+ public static Element findComponentElement(Element root) {
+
+ NodeList children = root.getChildNodes();
+
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+
+ Element trimmedElement = findComponentElement((Element) child);
+ if (trimmedElement != null)
+ return trimmedElement;
+
+ }
+ }
+
+ if (componentElements.contains(root.getLocalName()))
+ return root;
+
+ return null;
+ }
+
+ /**
+ *
+ * @param document
+ * @return
+ */
+ public static Element getRootFaceletElement(Document document) {
+
+ Element root = document.getDocumentElement();
+
+ Element component = findComponentElement(root);
+
+ return component != null ? component : root;
+
+ }
+
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2008-06-09
15:53:50 UTC (rev 8645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2008-06-09
16:07:59 UTC (rev 8646)
@@ -90,6 +90,10 @@
public static final String VALUE_TOP_ALIGN = "top"; //$NON-NLS-1$
public static final String VALUE_MIDDLE_ALIGN = "middle"; //$NON-NLS-1$
public static final String VALUE_TEXT_TYPE = "text"; //$NON-NLS-1$
+ public static final String VALUE_PASSWORD_TYPE = "password"; //$NON-NLS-1$
public static final String VALUE_IMAGE_TYPE = "image"; //$NON-NLS-1$
-
+ public static final String VALUE_RADIOBUTTON_TYPE = "radiobutton";
//$NON-NLS-1$
+ public static final String VALUE_CHECKBOX_TYPE = "checkbox"; //$NON-NLS-1$
+ public static final String VALUE_HIDDEN_TYPE = "hidden"; //$NON-NLS-1$
+ public static final String VALUE_BUTTON_TYPE = "button"; //$NON-NLS-1$
}
\ No newline at end of file
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-06-09
15:53:50 UTC (rev 8645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlBodyTemplate.java 2008-06-09
16:07:59 UTC (rev 8646)
@@ -40,7 +40,7 @@
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
- goToTree(visualDocument.getChildNodes().item(0));
+ goToTree(visualDocument.getDocumentElement());
nsIDOMNamedNodeMap attrsMap = bodyOld.getAttributes();
long len = attrsMap.getLength();
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java 2008-06-09
15:53:50 UTC (rev 8645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java 2008-06-09
16:07:59 UTC (rev 8646)
@@ -434,4 +434,8 @@
protected void onDispose() {
}
+
+ public void setText(String html) {
+ browser.setText(html);
+ }
}