Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jsf
diff options
context:
space:
mode:
authorcrogers2010-05-07 18:25:30 +0000
committercrogers2010-05-07 18:25:30 +0000
commit44b83ae8a5ec36f49961f6cf23c34119f856926b (patch)
tree62dee144fd113a335ff2cb260a27e4aa9c5fc050 /jsf
parentcf3bbb5091f6d4338ee96810c046e459aa816781 (diff)
downloadwebtools.jsf-44b83ae8a5ec36f49961f6cf23c34119f856926b.tar.gz
webtools.jsf-44b83ae8a5ec36f49961f6cf23c34119f856926b.tar.xz
webtools.jsf-44b83ae8a5ec36f49961f6cf23c34119f856926b.zip
[Bug 252861] Add tag converter transform operation to support generating markup based on view mode.
Diffstat (limited to 'jsf')
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/plugin.xml56
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/DTTagConverterContext.java20
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/operations/internal/CheckModeOperation.java81
3 files changed, 131 insertions, 26 deletions
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/plugin.xml b/jsf/plugins/org.eclipse.jst.pagedesigner/plugin.xml
index dff36d073..d52b35ea5 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/plugin.xml
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/plugin.xml
@@ -53,74 +53,78 @@
<extension point="org.eclipse.jst.pagedesigner.pageDesignerExtension">
<linkCreator class="org.eclipse.jst.pagedesigner.actions.link.HtmlLinkCreator" linkIdentifier="Html Link"/>
- <tagTransformOperation
+ <tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.AppendChildElementOperation"
id="AppendChildElementOperation">
- </tagTransformOperation>
+ </tagTransformOperation>
<tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.AppendChildTextFromXPathOperation"
id="AppendChildTextFromXPathOperation">
- </tagTransformOperation>
+ </tagTransformOperation>
<tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.AppendChildTextOperation"
id="AppendChildTextOperation">
- </tagTransformOperation>
+ </tagTransformOperation>
<tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.ConvertAttributeToTextOperation"
id="ConvertAttributeToTextOperation">
- </tagTransformOperation>
+ </tagTransformOperation>
<tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.CopyAllAttributesOperation"
id="CopyAllAttributesOperation">
- </tagTransformOperation>
+ </tagTransformOperation>
<tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.CopyAttributeOperation"
id="CopyAttributeOperation">
- </tagTransformOperation>
+ </tagTransformOperation>
<tagTransformOperation
- class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.CopyAttributeWithRenameOperation"
- id="CopyAttributeWithRenameOperation">
+ class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.CopyAttributeWithRenameOperation"
+ id="CopyAttributeWithRenameOperation">
</tagTransformOperation>
<tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.CopyChildrenOperation"
id="CopyChildrenOperation">
- </tagTransformOperation>
+ </tagTransformOperation>
<tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.CreateAttributeFromXPathOperation"
id="CreateAttributeFromXPathOperation">
- </tagTransformOperation>
+ </tagTransformOperation>
<tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.CreateAttributeOperation"
id="CreateAttributeOperation">
- </tagTransformOperation>
- <tagTransformOperation
+ </tagTransformOperation>
+ <tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.CreateElementOperation"
id="CreateElementOperation">
- </tagTransformOperation>
- <tagTransformOperation
+ </tagTransformOperation>
+ <tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.IfNotOperation"
id="IfNotOperation">
- </tagTransformOperation>
- <tagTransformOperation
+ </tagTransformOperation>
+ <tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.IfOperation"
id="IfOperation">
- </tagTransformOperation>
- <tagTransformOperation
+ </tagTransformOperation>
+ <tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.IterateOverElementsOperation"
id="IterateOverElementsOperation">
- </tagTransformOperation>
- <tagTransformOperation
+ </tagTransformOperation>
+ <tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.MakeParentElementCurrentOperation"
id="MakeParentElementCurrentOperation">
- </tagTransformOperation>
- <tagTransformOperation
+ </tagTransformOperation>
+ <tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.RemoveAttributeOperation"
id="RemoveAttributeOperation">
- </tagTransformOperation>
- <tagTransformOperation
+ </tagTransformOperation>
+ <tagTransformOperation
class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.RenameAttributeOperation"
id="RenameAttributeOperation">
- </tagTransformOperation>
+ </tagTransformOperation>
+ <tagTransformOperation
+ class="org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal.CheckModeOperation"
+ id="CheckModeOperation">
+ </tagTransformOperation>
</extension>
<extension id="org.eclipse.jst.pagedesigner.commands" point="org.eclipse.ui.commands">
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/DTTagConverterContext.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/DTTagConverterContext.java
index aa60bff01..2316f4eff 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/DTTagConverterContext.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/DTTagConverterContext.java
@@ -11,6 +11,7 @@
package org.eclipse.jst.pagedesigner.dtmanager.converter.internal;
import org.eclipse.jst.pagedesigner.converter.ConvertPosition;
+import org.eclipse.jst.pagedesigner.converter.IConverterFactory;
import org.eclipse.jst.pagedesigner.dtmanager.converter.AbstractTagConverterContext;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -76,4 +77,23 @@ public class DTTagConverterContext extends AbstractTagConverterContext {
}
}
+ /**
+ * Utility method to get the current converter mode. Values are
+ * defined in <code>IConverterFactory</code>.
+ *
+ * <br>This method is available on the DTTagConverter but was not
+ * part of the ITagConverter and not available as a public API.
+ * The addition of this method allows an ITransformOperation for
+ * a DTTagConverter to get at the mode.
+ * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=252861
+ *
+ * @return the converter mode. If unable to get the mode, return -1.
+ */
+ public int getMode() {
+ if (tagConverter != null) {
+ return ((DTTagConverter) tagConverter).getMode();
+ }
+
+ return IConverterFactory.MODE_DESIGNER;
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/operations/internal/CheckModeOperation.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/operations/internal/CheckModeOperation.java
new file mode 100644
index 000000000..554bab794
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/operations/internal/CheckModeOperation.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+* Copyright (c) 2010 Oracle Corporation 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:
+* Oracle Corporation - initial API and implementation and/or initial documentation
+*******************************************************************************/
+package org.eclipse.jst.pagedesigner.dtmanager.converter.operations.internal;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jst.pagedesigner.converter.IConverterFactory;
+import org.eclipse.jst.pagedesigner.dtmanager.converter.internal.DTTagConverterContext;
+import org.eclipse.jst.pagedesigner.dtmanager.converter.operations.AbstractTransformOperation;
+import org.w3c.dom.Element;
+
+
+/**
+ * Transform operation that executes child ITransformOperation
+ * instances if the view mode matches the argument (parameter) provided.
+ *
+ * <br><b>Note:</b> requires ITransformOperation.setTagConverterContext() to
+ * have been called to provide a valid ITagConverterContext instance prior to
+ * a call to the transform() method.
+ */
+public class CheckModeOperation extends AbstractTransformOperation {
+
+ /**
+ * Constant indicating the current render mode is design
+ */
+ public static final String MODE_DESIGN = "design"; //$NON-NLS-1$
+ /**
+ * Constant indicating the current render mode is preview
+ */
+ public static final String MODE_PREVIEW = "preview"; //$NON-NLS-1$
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.dtmanager.converter.ITransformOperation#transform(org.w3c.dom.Element, org.w3c.dom.Element)
+ */
+ @Override
+ public Element transform(Element srcElement, Element curElement) {
+ if (getParameters().length < 1) {
+ getLog().error("Warning.TransformOperationFactory.TooFewParameters", //$NON-NLS-1$
+ getTransformOperationID());
+ return null;
+ }
+
+ String modeParam = getParameters()[0];
+ Assert.isNotNull(modeParam);
+
+ int currentMode = getMode();
+ if ((MODE_DESIGN.equals(modeParam) && currentMode == IConverterFactory.MODE_DESIGNER)
+ || (MODE_PREVIEW.equals(modeParam) && currentMode == IConverterFactory.MODE_PREVIEW)) {
+ return executeChildOperations(srcElement, curElement);
+ }
+
+ // if we haven't transformed the element at all, and this is
+ // just the initial transform, return null
+ if (srcElement == curElement) {
+ return null;
+ }
+
+ // otherwise, return the currently transformed element
+ return curElement;
+ }
+
+ /**
+ * @return the converter mode. If unable to get the mode, return -1.
+ */
+ protected int getMode() {
+ if (tagConverterContext != null
+ && tagConverterContext instanceof DTTagConverterContext) {
+ return ((DTTagConverterContext) tagConverterContext).getMode();
+ }
+
+ return -1;
+ }
+}

Back to the top