Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoritrimble2006-10-30 18:59:16 +0000
committeritrimble2006-10-30 18:59:16 +0000
commit38bf0b94a9097fc95b4b875bc8f1c9c881bd53e8 (patch)
tree3441d21142de85a91748c8f8299c17ad152ae6b5 /jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter
parent676c1fe37e7743b8edcb79b521e6f965f05d0ce8 (diff)
downloadwebtools.jsf-38bf0b94a9097fc95b4b875bc8f1c9c881bd53e8.tar.gz
webtools.jsf-38bf0b94a9097fc95b4b875bc8f1c9c881bd53e8.tar.xz
webtools.jsf-38bf0b94a9097fc95b4b875bc8f1c9c881bd53e8.zip
Initial contribution.
Diffstat (limited to 'jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter')
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/AbstractTagConverter.java447
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConvertPosition.java42
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterFacRegistryReader.java76
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterFactoryRegistry.java121
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterUtil.java102
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DefaultUnknownTagConverter.java91
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumDeepTagConverter.java79
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumDescriptionTagConverter.java65
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumTagConverter.java94
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HTMLStringTagConverter.java107
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HiddenTagConverter.java153
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HiddenTagConverter2.java60
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/IConverterFactory.java39
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/IDOMFactory.java39
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ITagConverter.java121
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/JSFConverterUtil.java66
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/PreferenceReader.java28
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToDumBlock.java59
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToInlineBlock.java79
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToSpan.java66
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/ATagConverter.java78
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/HTMLConverterFactory.java89
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/TableTagConverter.java76
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/jsp/IncludeTagConverterPreview.java197
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/jsp/JSPConverterFactory.java96
25 files changed, 2470 insertions, 0 deletions
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/AbstractTagConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/AbstractTagConverter.java
new file mode 100644
index 000000000..8bfd3ecdd
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/AbstractTagConverter.java
@@ -0,0 +1,447 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo;
+import org.eclipse.jst.pagedesigner.dom.DOMUtil;
+import org.eclipse.jst.pagedesigner.preview.PageExpressionContext;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+/**
+ * This is base class for all non-hidden tag converters.
+ *
+ * @author mengbo
+ * @version 1.5
+ */
+public abstract class AbstractTagConverter implements ITagConverter,
+ ITagEditInfo, INodeAdapter, IDOMFactory {
+ private IDOMDocument _targetDocument;
+
+ private Element _hostElement;
+
+ private Element _resultElement;
+
+ private List _childNodes = Collections.EMPTY_LIST;
+
+ private Map _childNodePositions = Collections.EMPTY_MAP;
+
+ private int _mode;
+
+ private int _minWidth;
+
+ private int _minHeight;
+
+ private boolean _needBorderDecorator;
+
+ /**
+ *
+ */
+ public AbstractTagConverter(Element host) {
+ _hostElement = host;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#setTargetDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)
+ */
+ public void setDestDocument(IDOMDocument document) {
+ _targetDocument = document;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#convertRefresh(java.lang.Object)
+ */
+ public final void convertRefresh(Object context) {
+ _resultElement = null;
+ _childNodes = new ArrayList();
+ _childNodePositions = new HashMap();
+
+ _resultElement = doConvertRefresh();
+ if (_resultElement instanceof INodeNotifier) {
+ ((INodeNotifier) _resultElement).addAdapter(this);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.wst.sse.core.internal.provisional.INodeAdapter#notifyChanged(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier,
+ * int, java.lang.Object, java.lang.Object, java.lang.Object, int)
+ */
+ public void notifyChanged(INodeNotifier notifier, int eventType,
+ Object changedFeature, Object oldValue, Object newValue, int pos) {
+ // do nothing.
+ }
+
+ /**
+ * Child class should override this method. The child class should NEVER
+ * change the host DOM structure.
+ *
+ * @return the convert result. Should be an HTML element.
+ */
+ protected abstract Element doConvertRefresh();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#getHostElement()
+ */
+ public final Element getHostElement() {
+ return _hostElement;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#getResultElement()
+ */
+ public final Element getResultElement() {
+ return _resultElement;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#getChildModeList()
+ */
+ public final List getChildModeList() {
+ return _childNodes;
+ }
+
+ /**
+ * child class should call this method.
+ *
+ * @param childNode
+ * the childNode of the hostElement that should be futher
+ * converted.
+ * @param position
+ *
+ */
+ protected void addChild(Node childNode, ConvertPosition position) {
+ _childNodes.add(childNode);
+ _childNodePositions.put(childNode, position);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#getChildVisualPosition(org.w3c.dom.Node)
+ */
+ public final ConvertPosition getChildVisualPosition(Node childModel) {
+ return (ConvertPosition) _childNodePositions.get(childModel);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#isVisualByHTML()
+ */
+ public boolean isVisualByHTML() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#getVisualImage()
+ */
+ public Image getVisualImage() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#dispose()
+ */
+ public void dispose() {
+ }
+
+ protected boolean shouldIgnore(Node node) {
+ int nodeType = node.getNodeType();
+ switch (nodeType) {
+ case Node.TEXT_NODE:
+ case Node.CDATA_SECTION_NODE:
+ case Node.ELEMENT_NODE:
+ return false;
+ default:
+ return true;
+ }
+
+ }
+
+ /**
+ * utility method for those converter that only converts the host tag's name
+ * and directly copy children.
+ *
+ */
+ protected void copyChildren(Element src, Element dest) {
+ Node node = src.getFirstChild();
+ int index = 0;
+ for (; node != null; node = node.getNextSibling()) {
+ if (!shouldIgnore(node)) {
+ addChild(node, new ConvertPosition(dest, index++));
+ }
+ }
+ }
+
+ /**
+ * utility method for those converter that directly copy children.
+ *
+ */
+ protected void dumCopyChildren(Element src, Element dest) {
+ Node node = src.getFirstChild();
+ Document destDoc = dest.getOwnerDocument();
+ for (; node != null; node = node.getNextSibling()) {
+ if (!shouldIgnore(node)) {
+ Node n = DOMUtil.cloneNodeDeepIgnoreError(destDoc, node);
+ dest.appendChild(n);
+ }
+ }
+ }
+
+ /**
+ * In the future, the conversion result HTML DOM tree could be in another
+ * document.
+ *
+ * @return
+ */
+ public IDOMDocument getDestDocument() {
+ if (this._targetDocument != null) {
+ return this._targetDocument;
+ } else {
+ return (IDOMDocument) _hostElement.getOwnerDocument();
+ }
+ }
+
+ /**
+ * shortcut method. Child class should always use this method to create a
+ * result element.
+ *
+ * @param tagName
+ * @return
+ */
+ public Element createElement(String tagName) {
+ return getDestDocument().createElement(tagName);
+ }
+
+ /**
+ * shortcut method. Child class should always use this method to create a
+ * text node.
+ *
+ * @param text
+ * @return
+ */
+ public Text createText(String text) {
+ return getDestDocument().createTextNode(text);
+ }
+
+ protected String mapURL(String original) {
+ // TODO: how to map URL? such as original url look like:
+ // getContext().getPath()+...
+ return original;
+ }
+
+ // TODO: FIXME: XXX:
+ // if the value is expression, we may want to do something here!!!
+ protected String mapValue(String value) {
+ if (value == null) {
+ return null;
+ }
+ if (isDesignerMode()) {
+ // if there has jsf binding expressions
+ int checkPos = value.indexOf("#{");
+ if (checkPos != -1) {
+ String mapValue = "";
+ int preferType = PreferenceReader.getMapValueType();
+ switch (preferType) {
+ case PreferenceReader.FULL_EXPRESSION_TYPE:
+ mapValue = value;
+ break;
+ case PreferenceReader.LAST_EXPRESSION_TYPE:
+ String strBackup = value;
+ StringBuffer sb = new StringBuffer();
+ while (strBackup.indexOf("#{") != -1) {
+ int pos = strBackup.indexOf("#{");
+ int endBracketPos = strBackup.indexOf("}", pos + 1);
+ if (endBracketPos != -1) {
+ sb.append(strBackup.substring(0, pos + 2));
+ String exp = strBackup.substring(pos + 2,
+ endBracketPos);
+ if (allowTrim(exp)) {
+ int lastDotPos = exp.lastIndexOf(".");
+ if (lastDotPos != -1) {
+ String convertedExp = exp
+ .substring(lastDotPos + 1);
+ sb.append(convertedExp);
+ } else {
+ sb.append(exp);
+ }
+
+ } else {
+ sb.append(exp);
+ }
+ sb.append("}");
+ } else {
+ break;
+ }
+ if (strBackup.length() > endBracketPos + 1) {
+ strBackup = strBackup.substring(endBracketPos + 1);
+ } else {
+ strBackup = "";
+ break;
+ }
+
+ }
+ sb.append(strBackup);
+ mapValue = sb.toString();
+ break;
+ case PreferenceReader.REAL_VALUE_TYPE:
+ // TODO calculate the expression value
+ default:
+ mapValue = value;
+ break;
+ }
+
+ return mapValue;
+ }
+ } else {
+ // preview mode. let's try to display the value.
+ try {
+ return (String) PageExpressionContext.getCurrent()
+ .evaluateExpression(value, String.class, null);
+ } catch (Exception ex) {
+ // can't calculate the result. ignore.
+ // ex.printStackTrace();
+ }
+ }
+ return value;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo#needBorderDecorator()
+ */
+ public boolean needBorderDecorator() {
+ return this._needBorderDecorator;
+ }
+
+ public void setNeedBorderDecorator(boolean b) {
+ this._needBorderDecorator = b;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo#needTableDecorator()
+ */
+ public boolean needTableDecorator() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.wst.sse.core.internal.provisional.INodeAdapter#isAdapterForType(java.lang.Object)
+ */
+ public boolean isAdapterForType(Object type) {
+ if (type == ITagEditInfo.class) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @param mode
+ */
+ public final void setMode(int mode) {
+ this._mode = mode;
+ }
+
+ public final boolean isPreviewMode() {
+ return this._mode == IConverterFactory.MODE_PREVIEW;
+ }
+
+ public final boolean isDesignerMode() {
+ return this._mode == IConverterFactory.MODE_DESIGNER;
+ }
+
+ public final int getMode() {
+ return this._mode;
+ }
+
+ /**
+ * The method is used to judge whether the value binding and method binding
+ * expression is allowed to be trimmed.Currently only expression contains
+ * only letter,digit,and '.' is allowed to be trimmed.
+ *
+ * @param expression
+ * value binding or method binding expression
+ * @return
+ */
+ private boolean allowTrim(String expression) {
+ for (int i = 0, size = expression.length(); i < size; i++) {
+ char ch = expression.charAt(i);
+ if (!Character.isLetterOrDigit(ch) && (ch != '.') && (ch != '_')) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#getMinWidth()
+ */
+ public int getMinWidth() {
+ return this._minWidth;
+ }
+
+ public void setMinWidth(int minWidth) {
+ this._minWidth = minWidth;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#getMinHeight()
+ */
+ public int getMinHeight() {
+ return this._minHeight;
+ }
+
+ public void setMinHeight(int minHeight) {
+ this._minHeight = minHeight;
+ }
+
+ public static boolean hasAttribute(Element element, String attrname) {
+ return element.hasAttribute(attrname);
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConvertPosition.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConvertPosition.java
new file mode 100644
index 000000000..97f2ba85b
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConvertPosition.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import org.w3c.dom.Node;
+
+/**
+ * This class is used to locate a position for child model nodes.
+ *
+ * @author mengbo
+ * @version 1.5
+ */
+public class ConvertPosition {
+ Node _parentNode;
+
+ int _index;
+
+ /**
+ *
+ */
+ public ConvertPosition(Node parent, int index) {
+ this._parentNode = parent;
+ this._index = index;
+ }
+
+ public Node getParentNode() {
+ return _parentNode;
+ }
+
+ public int getIndex() {
+ return _index;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterFacRegistryReader.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterFacRegistryReader.java
new file mode 100644
index 000000000..21f3d889e
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterFacRegistryReader.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jst.pagedesigner.IJMTConstants;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class ConverterFacRegistryReader {
+ static IConverterFactory[] _handlers = null;
+
+ public static synchronized IConverterFactory[] getAllHandlers() {
+ if (_handlers == null) {
+ _handlers = readAllHandlers();
+ }
+ return _handlers;
+
+ }
+
+ private static IConverterFactory[] readAllHandlers() {
+ List result = new ArrayList();
+ IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
+ .getExtensionPoint(PDPlugin.getPluginId(),
+ IJMTConstants.EXTENSION_POINT_PAGEDESIGNER);
+ IExtension[] extensions = extensionPoint.getExtensions();
+
+ for (int i = 0; i < extensions.length; i++) {
+ IExtension ext = extensions[i];
+ IConfigurationElement[] dropHandlers = ext
+ .getConfigurationElements();
+
+ for (int j = 0; j < dropHandlers.length; j++) {
+ if (dropHandlers[j].getName().equals(
+ IJMTConstants.TAG_CONVERTER_FACTORY)) {
+ dropHandlers[j].getAttribute("class");
+ Object obj;
+ try {
+ obj = dropHandlers[j]
+ .createExecutableExtension("class");
+
+ if (obj instanceof IConverterFactory) {
+ result.add(obj);
+ }
+ } catch (CoreException e) {
+ // ignore the exception
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ IConverterFactory[] ret = new IConverterFactory[result.size()];
+ result.toArray(ret);
+ return ret;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterFactoryRegistry.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterFactoryRegistry.java
new file mode 100644
index 000000000..ba738678e
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterFactoryRegistry.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jst.pagedesigner.IJMTConstants;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.jst.pagedesigner.converter.html.HTMLConverterFactory;
+import org.eclipse.jst.pagedesigner.converter.jsp.JSPConverterFactory;
+import org.eclipse.jst.pagedesigner.utils.CMUtil;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.w3c.dom.Element;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class ConverterFactoryRegistry {
+ List _factories = new ArrayList();
+
+ private static ConverterFactoryRegistry _instance;
+
+ /**
+ *
+ */
+ private ConverterFactoryRegistry() {
+ _factories.add(new JSPConverterFactory());
+ _factories.add(new HTMLConverterFactory());
+
+ IConverterFactory facs[] = ConverterFacRegistryReader.getAllHandlers();
+ if (facs != null) {
+ for (int i = 0; i < facs.length; i++) {
+ addFactory(facs[i]);
+ }
+ }
+ }
+
+ public void addFactory(IConverterFactory fac) {
+ _factories.add(fac);
+ }
+
+ public ITagConverter createTagConverter(Element ele, int mode,
+ IDOMDocument targetDocument) {
+ ITagConverter converter = internalCreateTagConverter(ele, mode);
+ if (converter != null) {
+ converter.setDestDocument(targetDocument);
+ }
+ return converter;
+ }
+
+ public ITagConverter internalCreateTagConverter(Element ele, int mode) {
+ String uri = CMUtil.getElementNamespaceURI(ele);
+ // first round, match uri
+ for (int i = 0, size = _factories.size(); i < size; i++) {
+ IConverterFactory fac = (IConverterFactory) _factories.get(i);
+ String facuri = fac.getSupportedURI();
+ if (facuri != null && facuri.equals(uri)) {
+ ITagConverter converter = fac.createConverter(ele, mode);
+ if (converter != null) {
+ return converter;
+ }
+ }
+ }
+ // second round
+ for (int i = 0, size = _factories.size(); i < size; i++) {
+ IConverterFactory fac = (IConverterFactory) _factories.get(i);
+ String facuri = fac.getSupportedURI();
+ if (facuri == null) {
+ ITagConverter converter = fac.createConverter(ele, mode);
+ if (converter != null) {
+ return converter;
+ }
+ }
+ }
+
+ // can't find. We need some default tag converter for it.
+ // if the tag is empty, show it as icon.
+ if (uri == null || IJMTConstants.URI_HTML.equals(uri)) {
+ // basically, for HTML or non JSP tag, directly renders it.
+ return new DumTagConverter(ele);
+ } else {
+ CMElementDeclaration decl = CMUtil.getElementDeclaration(ele);
+ if (decl == null) {
+ return new DumTagConverter(ele);
+ }
+ int contentType = decl.getContentType();
+ if (contentType == CMElementDeclaration.EMPTY) {
+ // if the tag is empty, show it as icon.
+ return new HiddenTagConverter(ele, getUnknownImage());
+ } else {
+ return new DefaultUnknownTagConverter(ele);
+ }
+ }
+
+ }
+
+ Image getUnknownImage() {
+ return PDPlugin.getDefault().getImage(
+ "palette/GENERIC/small/PD_Palette_Default.gif");
+ }
+
+ public static ConverterFactoryRegistry getInstance() {
+ if (_instance == null) {
+ _instance = new ConverterFactoryRegistry();
+ }
+ return _instance;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterUtil.java
new file mode 100644
index 000000000..b082303c9
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterUtil.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import java.util.Set;
+
+import org.eclipse.jst.pagedesigner.IHTMLConstants;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class ConverterUtil {
+ /**
+ *
+ * @param source
+ * @param dest
+ * @param ignore
+ */
+ public static void copyAllAttributes(Element source, Element dest,
+ Set ignore) {
+ NamedNodeMap attrs = source.getAttributes();
+ for (int i = 0, size = attrs.getLength(); i < size; i++) {
+ Attr attr = (Attr) attrs.item(i);
+ if (ignore == null || !ignore.contains(attr.getName())) {
+ dest.setAttribute(attr.getName(), attr.getValue());
+ }
+ }
+ }
+
+ /**
+ * copy a single attribute (if exist)
+ *
+ * @param source
+ * @param srcattr
+ * @param dest
+ * @param destattr
+ */
+ public static void copyAttribute(Element source, String srcattr,
+ Element dest, String destattr) {
+ Attr attr = source.getAttributeNode(srcattr);
+ if (attr != null) {
+ dest.setAttribute(destattr, attr.getValue());
+ }
+ }
+
+ /**
+ * @param hostElement
+ * @return
+ */
+ public static boolean isEmptyContainer(Element hostElement) {
+ NodeList nl = hostElement.getChildNodes();
+ if (nl == null || nl.getLength() == 0) {
+ return true;
+ }
+
+ for (int i = 0, n = nl.getLength(); i < n; i++) {
+ Node node = nl.item(i);
+ if (!(node instanceof IDOMText)) {
+ return false;
+ }
+ if (!((IDOMText) node).isElementContentWhitespace()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static Element createDescriptionElement(IDOMDocument document,
+ String text) {
+ if (document == null) {
+ return null;
+ }
+ Element span = document.createElement(IHTMLConstants.TAG_SPAN); //$NON-NLS-1$
+ span.setAttribute(
+ "style", "color:gray;font-style:italic;font-size:normal;"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (text == null) {
+ span.appendChild(document.createTextNode(PDPlugin
+ .getResourceString("ConverterUtil.Description"))); //$NON-NLS-1$
+ } else {
+ span.appendChild(document.createTextNode(text));
+ }
+ return span;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DefaultUnknownTagConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DefaultUnknownTagConverter.java
new file mode 100644
index 000000000..d09a2fe11
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DefaultUnknownTagConverter.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import org.eclipse.jst.pagedesigner.utils.DOMUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+/**
+ * This tag converter is for those unsupported jsp tags.
+ *
+ * @author mengbo
+ * @version 1.5
+ */
+public class DefaultUnknownTagConverter extends AbstractTagConverter {
+
+ /**
+ * @param host
+ */
+ public DefaultUnknownTagConverter(Element host) {
+ super(host);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
+ */
+ protected Element doConvertRefresh() {
+ Element hostEle = this.getHostElement();
+ Element divEle = createElement("div");
+ String style = DOMUtil.getAttributeIgnoreCase(hostEle, "style");
+ if (style == null) {
+ style = "";
+ }
+ if (style.length() > 0 && !style.endsWith(";")) {
+ style += ";";
+ }
+ style += "border: none; padding: 0; margin: 0";
+ divEle.setAttribute("style", style);
+ Element div2 = createElement("span");
+ div2.setAttribute("style", "background-color: cyan; border: none;");
+ Text txt = createText(hostEle.getTagName());
+ div2.appendChild(txt);
+
+ divEle.appendChild(div2);
+
+ Element div3 = createElement("div");
+ div3.setAttribute("style", "margin: 0; padding: 0");
+ divEle.appendChild(div3);
+
+ copyChildren(getHostElement(), div3);
+ return divEle;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo#isWidget()
+ */
+ public boolean isWidget() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#needBorderDecorator()
+ */
+ public boolean needBorderDecorator() {
+ return true;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumDeepTagConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumDeepTagConverter.java
new file mode 100644
index 000000000..c56d0760c
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumDeepTagConverter.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import org.eclipse.jst.pagedesigner.IHTMLConstants;
+import org.eclipse.jst.pagedesigner.dom.DOMUtil;
+import org.w3c.dom.Element;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class DumDeepTagConverter extends AbstractTagConverter {
+
+ /**
+ * @param host
+ */
+ public DumDeepTagConverter(Element host) {
+ super(host);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
+ */
+ protected Element doConvertRefresh() {
+ return (Element) DOMUtil.cloneNodeDeepIgnoreError(getDestDocument(),
+ getHostElement());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ return true;
+ }
+
+ /**
+ * @param result
+ * @return
+ */
+ private boolean internalIsWidget(Element result) {
+ String tagname = result.getTagName();
+ if (IHTMLConstants.TAG_INPUT.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_SELECT.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_TEXTAREA.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_IMG.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_HEAD.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_SCRIPT.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_LINK.equalsIgnoreCase(tagname)) {
+ return true;
+ } else {
+
+ return false;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#isWidget()
+ */
+ public boolean isWidget() {
+ return true;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumDescriptionTagConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumDescriptionTagConverter.java
new file mode 100644
index 000000000..2221a5279
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumDescriptionTagConverter.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import org.w3c.dom.Element;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class DumDescriptionTagConverter extends AbstractTagConverter {
+ /**
+ * @param host
+ */
+ public DumDescriptionTagConverter(Element host) {
+ super(host);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
+ */
+ protected Element doConvertRefresh() {
+ Element result = createElement(getHostElement().getTagName());
+ ConverterUtil.copyAllAttributes(getHostElement(), result, null);
+ copyChildren(getHostElement(), result);
+
+ if (!this.isPreviewMode()
+ && ConverterUtil.isEmptyContainer(getHostElement())) {
+ result.appendChild(ConverterUtil.createDescriptionElement(
+ getDestDocument(), null));
+ }
+
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo#isWidget()
+ */
+ public boolean isWidget() {
+ return false;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumTagConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumTagConverter.java
new file mode 100644
index 000000000..6abec2f10
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DumTagConverter.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import org.eclipse.jst.pagedesigner.IHTMLConstants;
+import org.w3c.dom.Element;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class DumTagConverter extends AbstractTagConverter {
+ /**
+ *
+ */
+ public DumTagConverter(Element host, boolean needBorder) {
+ this(host);
+ this.setNeedBorderDecorator(needBorder);
+ }
+
+ public DumTagConverter(Element host) {
+ super(host);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
+ */
+ protected Element doConvertRefresh() {
+ Element result = createElement(getHostElement().getTagName());
+ ConverterUtil.copyAllAttributes(getHostElement(), result, null);
+ if (!internalIsWidget(result)) {
+ copyChildren(getHostElement(), result);
+ } else {
+ dumCopyChildren(getHostElement(), result);
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ if (isWidget()) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @param result
+ * @return
+ */
+ private boolean internalIsWidget(Element result) {
+ String tagname = result.getTagName();
+ if (IHTMLConstants.TAG_INPUT.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_SELECT.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_TEXTAREA.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_IMG.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_OBJECT.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_HEAD.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_SCRIPT.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_LINK.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_BR.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_STYLE.equalsIgnoreCase(tagname)
+ || IHTMLConstants.TAG_HR.equalsIgnoreCase(tagname)) {
+ return true;
+ } else {
+
+ return false;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#isWidget()
+ */
+ public boolean isWidget() {
+ return internalIsWidget(getResultElement());
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HTMLStringTagConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HTMLStringTagConverter.java
new file mode 100644
index 000000000..610b0c061
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HTMLStringTagConverter.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.jst.pagedesigner.common.logging.Logger;
+import org.eclipse.jst.pagedesigner.common.utils.ResourceUtils;
+import org.eclipse.jst.pagedesigner.dom.DOMUtil;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.w3c.dom.Element;
+
+/**
+ * For some tag, could generate some XML code.
+ *
+ * @author mengbo
+ * @version 1.5
+ */
+public abstract class HTMLStringTagConverter extends AbstractTagConverter {
+
+ static Logger _log = PDPlugin.getLogger(HTMLStringTagConverter.class);
+
+ /**
+ * @param host
+ */
+ public HTMLStringTagConverter(Element host) {
+ super(host);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
+ */
+ protected Element doConvertRefresh() {
+ // following are XML implementation. Assume the string is welformed HTML
+ // try
+ // {
+ // String html = getGeneratedHTML();
+ // DocumentBuilder builder =
+ // DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ // Element result = builder.parse(new InputSource(new
+ // StringReader(html))).getDocumentElement();
+ // return (Element)DOMUtil.cloneNodeDeep(this.getDestDocument(),
+ // result);
+ // }
+ // catch(Exception ex)
+ // {
+ // Element temp = createElement("div");
+ // temp.appendChild(createText("ERROR: "+ex.getMessage()));
+ // return temp;
+ // }
+ InputStream stream = null;
+ try {
+ String id = "" + System.currentTimeMillis() + ".html";
+ IModelManager manager = StructuredModelManager.getModelManager();
+ stream = new ByteArrayInputStream(getGeneratedHTML().getBytes());
+ IDOMModel model = (IDOMModel) manager.getModelForRead(id, stream,
+ null);
+ Element root = model.getDocument().getDocumentElement();
+ Element resultEle = (Element) DOMUtil.cloneNodeDeepIgnoreError(
+ getDestDocument(), root);
+ model.releaseFromRead();
+ return resultEle;
+ } catch (Throwable ex) {
+ _log.error("Log.Error.HTMLStringTagConverter.Error", ex);
+ Element temp = createElement("div");
+ temp.appendChild(createText("Error loading: " + ex.getMessage()));
+ return temp;
+ } finally {
+ ResourceUtils.ensureClosed(stream);
+ }
+ }
+
+ public abstract String getGeneratedHTML() throws Exception;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo#isWidget()
+ */
+ public boolean isWidget() {
+ return true;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HiddenTagConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HiddenTagConverter.java
new file mode 100644
index 000000000..23714d7ad
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HiddenTagConverter.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * This is for those tags that don't convert to HTML. So they will not display
+ * anything in preview, and will display a small icon in designer.
+ *
+ * @author mengbo
+ * @version 1.5
+ */
+public class HiddenTagConverter implements ITagConverter {
+ private Element _hostElement;
+
+ private Image _image;
+
+ private int _mode;
+
+ /**
+ *
+ */
+ public HiddenTagConverter(Element host, Image image) {
+ _hostElement = host;
+ _image = image;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#setDestDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)
+ */
+ public void setDestDocument(IDOMDocument document) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#convertRefresh(java.lang.Object)
+ */
+ public void convertRefresh(Object context) {
+ // do nothing
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#getHostElement()
+ */
+ public Element getHostElement() {
+ return _hostElement;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#isVisualByHTML()
+ */
+ public boolean isVisualByHTML() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#getVisualImage()
+ */
+ public Image getVisualImage() {
+ return _image;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#getResultElement()
+ */
+ public Element getResultElement() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#getChildModeList()
+ */
+ public List getChildModeList() {
+ return Collections.EMPTY_LIST;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#getChildVisualPosition(org.w3c.dom.Node)
+ */
+ public ConvertPosition getChildVisualPosition(Node childModel) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#isWidget()
+ */
+ public boolean isWidget() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.visualtag.ITagConverter#dispose()
+ */
+ public void dispose() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#setMode(int)
+ */
+ public void setMode(int mode) {
+ this._mode = mode;
+ }
+
+ public int getMode() {
+ return _mode;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HiddenTagConverter2.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HiddenTagConverter2.java
new file mode 100644
index 000000000..c374d21c0
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/HiddenTagConverter2.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import org.eclipse.jst.pagedesigner.dom.DOMUtil;
+import org.eclipse.swt.graphics.Image;
+import org.w3c.dom.Element;
+
+/**
+ * HiddenTagConverter2 is similiar to HiddenTagConverter, with the following
+ * difference:
+ *
+ * <ol>
+ * <li>HiddenTagConverter2 will copy the DOM sub tree to the destination
+ * document.</li>
+ * </ol>
+ *
+ * @author mengbo
+ * @version 1.5
+ */
+public class HiddenTagConverter2 extends AbstractTagConverter {
+
+ private Image _image;
+
+ public HiddenTagConverter2(Element host, Image image) {
+ super(host);
+ this._image = image;
+ }
+
+ protected Element doConvertRefresh() {
+ return (Element) DOMUtil.cloneNodeDeepIgnoreError(getDestDocument(),
+ getHostElement());
+ }
+
+ public boolean isVisualByHTML() {
+ return false;
+ }
+
+ public Image getVisualImage() {
+ return _image;
+ }
+
+ public boolean isMultiLevel() {
+ return true;
+ }
+
+ public boolean isWidget() {
+ return true;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/IConverterFactory.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/IConverterFactory.java
new file mode 100644
index 000000000..002a7b0e0
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/IConverterFactory.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import org.w3c.dom.Element;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public interface IConverterFactory {
+ public static final int MODE_DESIGNER = 0;
+
+ public static final int MODE_PREVIEW = 1;
+
+ /**
+ *
+ * @param element
+ * @return null if this factory don't support this element
+ */
+ public ITagConverter createConverter(Element element, int mode);
+
+ /**
+ * get the URI namespace that this factory support. "null" means this
+ * factory can be used as default factory.
+ *
+ * @return null if this factory don't have a specific URI to support.
+ */
+ public String getSupportedURI();
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/IDOMFactory.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/IDOMFactory.java
new file mode 100644
index 000000000..dd0748990
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/IDOMFactory.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+/**
+ * Factory interface. AbstractTagConverter will implement it.
+ *
+ * @author mengbo
+ * @version 1.5
+ */
+public interface IDOMFactory {
+ /**
+ * create element
+ *
+ * @param tag
+ * @return
+ */
+ public Element createElement(String tag);
+
+ /**
+ * create text node
+ *
+ * @param content
+ * @return
+ */
+ public Text createText(String content);
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ITagConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ITagConverter.java
new file mode 100644
index 000000000..3b504b4ef
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ITagConverter.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import java.util.List;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * ITagConverter is used to convert a custom tag to a HTML tag. Each
+ * ITagConverter instance will be dedicated to a single custom tag element.
+ *
+ * @author mengbo
+ * @version 1.5
+ */
+public interface ITagConverter {
+ /**
+ * Set the target document where the converted node should belong to.
+ *
+ * @param document
+ */
+ public void setDestDocument(IDOMDocument document);
+
+ /**
+ * refresh the internal state of this ITagConverter. This method normally is
+ * called when the host element change.
+ *
+ * @param context
+ */
+ public void convertRefresh(Object context);
+
+ /**
+ * The host element being converted.
+ *
+ * @return
+ */
+ public Element getHostElement();
+
+ /**
+ * for some tags, they don't convert to HTML. In that case, this method
+ * should return false for them. And if this method return false, then
+ * should return an image in <code>getVisualImage()</code> for displaying
+ * in the designer.
+ *
+ * @return
+ */
+ public boolean isVisualByHTML();
+
+ /**
+ * if isVisualByHTML() return false, then this method should return an image
+ * to be displayed in designer.
+ *
+ * Normally this image will be a shared image for those hidden elements. It
+ * is this class's responsibility to dispose the image if the image is not a
+ * shared one.
+ *
+ * @return
+ */
+ public Image getVisualImage();
+
+ /**
+ * the element after conversion.
+ *
+ * @return
+ */
+ public Element getResultElement();
+
+ /**
+ * get the list of children that should be continuely converted.
+ *
+ * @return
+ */
+ public List getChildModeList();
+
+ /**
+ * For child nodes that need further convert, return their position in the
+ * converted DOM tree.
+ *
+ * @param childModel
+ * @return
+ */
+ public ConvertPosition getChildVisualPosition(Node childModel);
+
+ /**
+ * When the convert result in multi-level element. If this method return
+ * false, then the caller should not use child nodes of
+ * <code>getHostElement()</code>
+ *
+ * @return
+ */
+ public boolean isMultiLevel();
+
+ /**
+ *
+ * @return
+ */
+ public boolean isWidget();
+
+ /**
+ *
+ *
+ */
+ public void dispose();
+
+ /**
+ * @param mode
+ */
+ public void setMode(int mode);
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/JSFConverterUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/JSFConverterUtil.java
new file mode 100644
index 000000000..5ac56f8c7
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/JSFConverterUtil.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class JSFConverterUtil {
+ private static List NamedBooleanList = Arrays.asList(new String[] {
+ "disabled", "readonly", "ismap" });
+
+ /**
+ *
+ * @param source
+ * @param dest
+ * @param ignore
+ */
+ public static void copyAllAttributes(Element source, Element dest,
+ Set ignore) {
+ NamedNodeMap attrs = source.getAttributes();
+ for (int i = 0, size = attrs.getLength(); i < size; i++) {
+ Attr attr = (Attr) attrs.item(i);
+ if (ignore == null || !ignore.contains(attr.getName())) {
+ if (NamedBooleanList.contains(attr.getName())
+ && "false".equalsIgnoreCase(attr.getValue())) {
+ continue;
+ }
+ dest.setAttribute(attr.getName(), attr.getValue());
+ }
+ }
+ }
+
+ /**
+ * copy a single attribute (if exist)
+ *
+ * @param source
+ * @param srcattr
+ * @param dest
+ * @param destattr
+ */
+ public static void copyAttribute(Element source, String srcattr,
+ Element dest, String destattr) {
+ Attr attr = source.getAttributeNode(srcattr);
+ if (attr != null) {
+ dest.setAttribute(destattr, attr.getValue());
+ }
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/PreferenceReader.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/PreferenceReader.java
new file mode 100644
index 000000000..71b2830c3
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/PreferenceReader.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class PreferenceReader {
+ public final static int FULL_EXPRESSION_TYPE = 0;
+
+ public final static int LAST_EXPRESSION_TYPE = 1;
+
+ public final static int REAL_VALUE_TYPE = 2;
+
+ public static int getMapValueType() {
+ return LAST_EXPRESSION_TYPE;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToDumBlock.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToDumBlock.java
new file mode 100644
index 000000000..619875da6
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToDumBlock.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import org.eclipse.jst.pagedesigner.IHTMLConstants;
+import org.w3c.dom.Element;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class TagConverterToDumBlock extends AbstractTagConverter {
+
+ /**
+ * @param host
+ */
+ public TagConverterToDumBlock(Element host) {
+ super(host);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
+ */
+ protected Element doConvertRefresh() {
+ Element result = createElement(IHTMLConstants.TAG_DIV);
+ copyChildren(getHostElement(), result);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo#isWidget()
+ */
+ public boolean isWidget() {
+ return false;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToInlineBlock.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToInlineBlock.java
new file mode 100644
index 000000000..3e4a41400
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToInlineBlock.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import org.w3c.dom.Element;
+
+/**
+ * This converter can be used simply convert the tag to inline div, and copy all
+ * the children
+ *
+ * NOTE: It behave almost same as "span". In fact, we may remove this later, if
+ * our css engine support "minWidth"/"minHeight" for inline element.
+ *
+ * NOTE: it will not copy attributes!
+ *
+ * @author mengbo
+ * @version 1.5
+ * @see org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo#getMinHeight()
+ * @see org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo#getMinWidth()
+ */
+public class TagConverterToInlineBlock extends AbstractTagConverter {
+ private int model;
+
+ /**
+ * @param host
+ */
+ public TagConverterToInlineBlock(Element host, int model) {
+ super(host);
+ this.model = model;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
+ */
+ protected Element doConvertRefresh() {
+ Element result = null;
+ if (model == IConverterFactory.MODE_PREVIEW) {
+ result = createElement("span");
+ copyChildren(getHostElement(), result);
+ } else {
+ result = createElement("div");
+ result
+ .setAttribute(
+ "style",
+ "display:inline-block; border-width:0; margin:0; min-width:1.2em;min-height:1.2em;");
+ copyChildren(getHostElement(), result);
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isWidget()
+ */
+ public boolean isWidget() {
+ return false;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToSpan.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToSpan.java
new file mode 100644
index 000000000..5dfa8006f
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/TagConverterToSpan.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter;
+
+import org.w3c.dom.Element;
+
+/**
+ * This converter can be used simply convert the tag to span, and copy all the
+ * children
+ *
+ * NOTE: it will not copy attributes!
+ *
+ * @author mengbo
+ * @version 1.5
+ */
+public class TagConverterToSpan extends AbstractTagConverter {
+
+ /**
+ * @param host
+ */
+ public TagConverterToSpan(Element host) {
+ super(host);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
+ */
+ protected Element doConvertRefresh() {
+ // Register a named facet on the UIComponent associated with the
+ // closest parent UIComponent custom action.
+ // we'll render facet as a inline flow figure. so treat it as simple
+ // <span> here.
+ Element result = createElement("span");
+ copyChildren(getHostElement(), result);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isWidget()
+ */
+ public boolean isWidget() {
+ return false;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/ATagConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/ATagConverter.java
new file mode 100644
index 000000000..ab9708102
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/ATagConverter.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter.html;
+
+import org.eclipse.jst.pagedesigner.converter.ConverterUtil;
+import org.eclipse.jst.pagedesigner.converter.DumTagConverter;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class ATagConverter extends DumTagConverter {
+ private boolean _emptyContainer = false;
+
+ /**
+ * @param host
+ */
+ public ATagConverter(Element host) {
+ super(host);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
+ */
+ protected Element doConvertRefresh() {
+ _emptyContainer = ConverterUtil.isEmptyContainer(getHostElement());
+ if (_emptyContainer) {
+ Element resultEle = createElement("a");
+ ConverterUtil.copyAllAttributes(getHostElement(), resultEle, null);
+ Text fakedNode = createText("link");
+ resultEle.appendChild(fakedNode);
+ return resultEle;
+ } else {
+ return super.doConvertRefresh();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#needBorderDecorator()
+ */
+ public boolean needBorderDecorator() {
+ return _emptyContainer;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ return _emptyContainer;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo#isWidget()
+ */
+ public boolean isWidget() {
+ return _emptyContainer;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/HTMLConverterFactory.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/HTMLConverterFactory.java
new file mode 100644
index 000000000..b17a6c65b
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/HTMLConverterFactory.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter.html;
+
+import org.eclipse.jst.pagedesigner.IHTMLConstants;
+import org.eclipse.jst.pagedesigner.IJMTConstants;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.jst.pagedesigner.converter.AbstractTagConverter;
+import org.eclipse.jst.pagedesigner.converter.DumDescriptionTagConverter;
+import org.eclipse.jst.pagedesigner.converter.DumTagConverter;
+import org.eclipse.jst.pagedesigner.converter.HiddenTagConverter2;
+import org.eclipse.jst.pagedesigner.converter.IConverterFactory;
+import org.eclipse.jst.pagedesigner.converter.ITagConverter;
+import org.eclipse.jst.pagedesigner.utils.HTMLUtil;
+import org.eclipse.swt.graphics.Image;
+import org.w3c.dom.Element;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class HTMLConverterFactory implements IConverterFactory {
+
+ /**
+ * the constructor
+ */
+ public HTMLConverterFactory() {
+ super();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.IConverterFactory#createConverter(org.w3c.dom.Element)
+ */
+ public ITagConverter createConverter(Element element, int mode) {
+ String tagName = element.getLocalName();
+
+ if (mode == MODE_PREVIEW) {
+ return new DumTagConverter(element);
+ }
+ if (!HTMLUtil.isVisualHtmlElement(tagName)) {
+ return new HiddenTagConverter2(element, getUnknownImage());
+ }
+
+ AbstractTagConverter c;
+ if (IHTMLConstants.TAG_TABLE.equalsIgnoreCase(tagName)) {
+ c = new TableTagConverter(element);
+ } else if (IHTMLConstants.TAG_A.equalsIgnoreCase(tagName)) {
+ c = new ATagConverter(element);
+ } else if (IHTMLConstants.TAG_FORM.equalsIgnoreCase(tagName)) {
+ // for those HTML tag that we want to build a border decorator,
+ // should
+ // go there.
+ c = new DumTagConverter(element, true);
+ } else if (IHTMLConstants.TAG_HTML.equalsIgnoreCase(tagName)
+ || IHTMLConstants.TAG_BODY.equalsIgnoreCase(tagName)) {
+ c = new DumDescriptionTagConverter(element);
+ c.setNeedBorderDecorator(true);
+ } else {
+ c = new DumTagConverter(element);
+ }
+ c.setMode(mode);
+ return c;
+ }
+
+ private static Image getUnknownImage() {
+ return PDPlugin.getDefault().getImage(
+ "palette/GENERIC/small/PD_Palette_Default.gif");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.IConverterFactory#getSupportedURI()
+ */
+ public String getSupportedURI() {
+ return IJMTConstants.URI_HTML;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/TableTagConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/TableTagConverter.java
new file mode 100644
index 000000000..eaf192863
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/html/TableTagConverter.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter.html;
+
+import org.eclipse.jst.pagedesigner.converter.AbstractTagConverter;
+import org.eclipse.jst.pagedesigner.converter.ConverterUtil;
+import org.w3c.dom.Element;
+
+/**
+ * @author mengbo
+ */
+public class TableTagConverter extends AbstractTagConverter {
+ /**
+ * @param host
+ */
+ public TableTagConverter(Element host) {
+ super(host);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
+ */
+ protected Element doConvertRefresh() {
+ Element result = createElement(getHostElement().getTagName());
+ ConverterUtil.copyAllAttributes(getHostElement(), result, null);
+ copyChildren(getHostElement(), result);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo#isWidget()
+ */
+ public boolean isWidget() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#needTableDecorator()
+ */
+ public boolean needTableDecorator() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#needBorderDecorator()
+ */
+ public boolean needBorderDecorator() {
+ return false;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/jsp/IncludeTagConverterPreview.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/jsp/IncludeTagConverterPreview.java
new file mode 100644
index 000000000..00c0f9909
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/jsp/IncludeTagConverterPreview.java
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter.jsp;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.pagedesigner.IHTMLConstants;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.jst.pagedesigner.common.logging.Logger;
+import org.eclipse.jst.pagedesigner.converter.AbstractTagConverter;
+import org.eclipse.jst.pagedesigner.jsp.core.internal.pagevar.DocumentPageVariableAdapter;
+import org.eclipse.jst.pagedesigner.jsp.core.pagevar.adapter.PageVariableAdapterFactory;
+import org.eclipse.jst.pagedesigner.preview.PageExpressionContext;
+import org.eclipse.jst.pagedesigner.preview.PreviewConvertContext;
+import org.eclipse.wst.sse.core.internal.util.URIResolver;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * This is the tag converter for preview.
+ *
+ * @author mengbo
+ * @version 1.5
+ */
+public class IncludeTagConverterPreview extends AbstractTagConverter {
+ private static Logger _log = PDPlugin
+ .getLogger(IncludeTagConverterPreview.class);
+
+ private String _fileAttrName;
+
+ /**
+ * @param host
+ */
+ public IncludeTagConverterPreview(Element host, String fileAttrname) {
+ super(host);
+ this._fileAttrName = fileAttrname;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
+ */
+ protected Element doConvertRefresh() {
+ String fileName = getResolvedURL(getHostElement(), this._fileAttrName);
+ if (fileName == null || fileName.length() == 0) {
+ return null;
+ } else {
+ IPath includedPath = new Path(fileName);
+ includedPath.makeAbsolute();
+
+ IFile file = getFile(includedPath);
+ if (file == null) {
+ return null;
+ } else {
+ return previewFile(file);
+ }
+ }
+ }
+
+ public IFile getFile(IPath includedPath) {
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject[] projects = workspaceRoot.getProjects();
+
+ for (int i = 0, length = projects.length; i < length; i++) {
+ IPath path = projects[i].getLocation();
+ path = path.makeAbsolute();
+ if (path != null && path.isPrefixOf(includedPath)) {
+ // -1 so we still have the project path
+ includedPath = includedPath.removeFirstSegments(path
+ .segmentCount() - 1);
+ return ResourcesPlugin.getWorkspace().getRoot().getFile(
+ includedPath);
+ }
+ }
+ return null;
+ }
+
+ public Element previewFile(IFile file) {
+ IDOMModel xmlModel = null;
+ DocumentPageVariableAdapter provider = null;
+ boolean pushedPageVarProvider = false;
+ try {
+
+ xmlModel = (IDOMModel) PDPlugin.getModelManager().getModelForRead(
+ file);
+ if (xmlModel != null) {
+ IDOMDocument doc = xmlModel.getDocument();
+
+ // XXX: need to also register page variable adapters. In the
+ // future, this should go to some
+ // SSE system registry mechanism.
+ xmlModel.getFactoryRegistry().addFactory(
+ new PageVariableAdapterFactory());
+ provider = new DocumentPageVariableAdapter(doc);
+ doc.addAdapter(provider);
+
+ provider.refresh();
+ PageExpressionContext.getCurrent()
+ .pushPageVarProvider(provider);
+
+ Node child = xmlModel.getDocument().getFirstChild();
+ PreviewConvertContext context = new PreviewConvertContext(this
+ .getDestDocument());
+ List results = new ArrayList();
+ while (child != null) {
+ Node node = context.previewConvert(child);
+ if (node != null) {
+ results.add(node);
+ }
+ child = child.getNextSibling();
+ }
+
+ if (results.size() == 0) {
+ return null;
+ } else if (results.size() == 1
+ && results.get(0) instanceof Element) {
+ return (Element) results.get(0);
+ } else {
+ Element ret = createElement(IHTMLConstants.TAG_SPAN);
+ for (int i = 0, n = results.size(); i < n; i++) {
+ ret.appendChild((Node) results.get(i));
+ }
+ return ret;
+ }
+ }
+ } catch (CoreException e) {
+ _log.error("PreviewUtil.previewFile.CoreException", e);
+ } catch (IOException e) {
+ _log.error("PreviewUtil.previewFile.IOException", e);
+ } catch (Exception ex) {
+ _log.error("PreviewUtil.previewFile.CoreException", ex);
+ } finally {
+ if (pushedPageVarProvider) {
+ PageExpressionContext.getCurrent().popPageVarProvider(provider);
+ }
+ if (xmlModel != null) {
+ xmlModel.releaseFromRead();
+ }
+ }
+ return null;
+ }
+
+ static String getResolvedURL(Element element, String attrName) {
+ URIResolver resolver = null;
+ if (element instanceof IDOMNode) {
+ resolver = ((IDOMNode) element).getModel().getResolver();
+ }
+ if (null == resolver) {
+ return null;
+ }
+ String src = element.getAttribute(attrName);
+ if (src != null && src.length() > 0) {
+ return resolver.getLocationByURI(src);
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isMultiLevel()
+ */
+ public boolean isMultiLevel() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo#isWidget()
+ */
+ public boolean isWidget() {
+ return false;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/jsp/JSPConverterFactory.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/jsp/JSPConverterFactory.java
new file mode 100644
index 000000000..9931241f4
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/jsp/JSPConverterFactory.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.converter.jsp;
+
+import org.eclipse.jst.pagedesigner.IJMTConstants;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.jst.pagedesigner.converter.HiddenTagConverter;
+import org.eclipse.jst.pagedesigner.converter.IConverterFactory;
+import org.eclipse.jst.pagedesigner.converter.ITagConverter;
+import org.eclipse.jst.pagedesigner.converter.TagConverterToDumBlock;
+import org.eclipse.jst.pagedesigner.jsp.core.IJSPCoreConstants;
+import org.eclipse.swt.graphics.Image;
+import org.w3c.dom.Element;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class JSPConverterFactory implements IConverterFactory {
+ /**
+ *
+ */
+ public JSPConverterFactory() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.IConverterFactory#createConverter(org.w3c.dom.Element)
+ */
+ public ITagConverter createConverter(Element element, int mode) {
+ String tagName = element.getLocalName();
+ Image image = getJSPSharedImage(tagName);
+
+ if (mode == IConverterFactory.MODE_PREVIEW) {
+ // we want to generate the included page in preview, so
+ // handle differently
+ if (IJSPCoreConstants.TAG_INCLUDE.equalsIgnoreCase(tagName)) {
+ IncludeTagConverterPreview c = new IncludeTagConverterPreview(
+ element, "page");
+ c.setMode(mode);
+ return c;
+ } else if (IJSPCoreConstants.TAG_DIRECTIVE_INCLUDE
+ .equalsIgnoreCase(tagName)) {
+ IncludeTagConverterPreview c = new IncludeTagConverterPreview(
+ element, "file");
+ c.setMode(mode);
+ return c;
+ } else if (IJSPCoreConstants.TAG_ROOT.equalsIgnoreCase(tagName)) {
+ TagConverterToDumBlock c = new TagConverterToDumBlock(element);
+ c.setNeedBorderDecorator(true);
+ c.setMode(mode);
+ return c;
+ } else {
+ return new HiddenTagConverter(element, image);
+ }
+ } else {
+ if (IJSPCoreConstants.TAG_ROOT.equalsIgnoreCase(tagName)) {
+ TagConverterToDumBlock c = new TagConverterToDumBlock(element);
+ c.setNeedBorderDecorator(true);
+ c.setMode(mode);
+ return c;
+ }
+ return new HiddenTagConverter(element, image);
+ }
+ }
+
+ /**
+ * @param tagName
+ * @return
+ */
+ private Image getJSPSharedImage(String tagName) {
+ Image image = PDPlugin.getDefault().getImage(
+ "palette/JSP/small/JSP_" + tagName.toUpperCase() + ".gif");
+ return image;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.pagedesigner.converter.IConverterFactory#getSupportedURI()
+ */
+ public String getSupportedURI() {
+ return IJMTConstants.URI_JSP;
+ }
+
+}

Back to the top