Author: sdzmitrovich
Date: 2008-03-19 07:30:49 -0400 (Wed, 19 Mar 2008)
New Revision: 7001
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputFormatTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputLabelTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputTextTemplate.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1718
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java 2008-03-19
00:04:06 UTC (rev 7000)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java 2008-03-19
11:30:49 UTC (rev 7001)
@@ -1,46 +1,37 @@
package org.jboss.tools.jsf.vpe.jsf.template;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
-import org.jboss.tools.vpe.editor.bundle.BundleMap;
+import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
+import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
+import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
+import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
+import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMText;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
-public abstract class AbstractOutputJsfTemplate extends AbstractEditableJsfTemplate {
+public abstract class AbstractOutputJsfTemplate extends
+ AbstractEditableJsfTemplate {
/**
- * name of "value" attribute
- */
- protected static final String VALUE_ATTR_NAME = "value";
-
- /**
- * name of "binding" attribute
- */
- protected static final String BINDING_ATTR_NAME = "binding";
-
- /**
- * name of "escape" attribute
- */
- protected static final String ESCAPE_ATTR_NAME = "escape";
-
- /**
- * name of "dir" attribute
- */
- protected static final String DIR_ATTR_NAME = "dir";
-
- /**
*
* @param element
* @return
*/
protected Attr getOutputAttributeNode(Element element) {
- if (element.hasAttribute(VALUE_ATTR_NAME))
- return element.getAttributeNode(VALUE_ATTR_NAME);
- else if (element.hasAttribute(BINDING_ATTR_NAME))
- return element.getAttributeNode(BINDING_ATTR_NAME);
+ if (element.hasAttribute(JSF.ATTR_VALUE))
+ return element.getAttributeNode(JSF.ATTR_VALUE);
+ else if (element.hasAttribute(JSF.ATTR_BINDING))
+ return element.getAttributeNode(JSF.ATTR_BINDING);
return null;
@@ -55,8 +46,93 @@
protected void copyOutputJsfAttributes(nsIDOMElement visualElement,
Element sourceElement) {
copyGeneralJsfAttributes(visualElement, sourceElement);
- copyAttribute(visualElement, sourceElement, DIR_ATTR_NAME,
- HTML.ATTR_DIR);
+ copyAttribute(visualElement, sourceElement, JSF.ATTR_DIR, HTML.ATTR_DIR);
}
+
+ /**
+ *
+ * @param pageContext
+ * @param visualDocument
+ * @param sourceElement
+ * @param targetVisualElement
+ * @param creationData
+ */
+ protected void processOutputAttribute(VpePageContext pageContext,
+ nsIDOMDocument visualDocument, Element sourceElement,
+ nsIDOMElement targetVisualElement, VpeCreationData creationData) {
+
+ VpeElementData elementData = new VpeElementData();
+
+ Attr outputAttr = getOutputAttributeNode(sourceElement);
+
+ // prepare value
+ String newValue = prepareAttrValue(pageContext, sourceElement,
+ outputAttr);
+
+ if (outputAttr != null) {
+ // if escape then contents of value (or other attribute) is only
+ // text
+ if (!sourceElement.hasAttribute(JSF.ATTR_ESCAPE)
+ || "true".equalsIgnoreCase(sourceElement //$NON-NLS-1$
+ .getAttribute(JSF.ATTR_ESCAPE))) {
+
+ String value = outputAttr.getNodeValue();
+
+ nsIDOMText text;
+ // if bundleValue differ from value then will be represent
+ // bundleValue, but text will be not edit
+ boolean isEditable = value.equals(newValue);
+
+ text = visualDocument.createTextNode(newValue);
+ // add attribute for ability of editing
+
+ elementData.addAttributeData(new VpeAttributeData(outputAttr,
+ text, isEditable));
+
+ targetVisualElement.appendChild(text);
+
+ }
+ // then text can be html code
+ else {
+
+ // create info
+ VpeChildrenInfo spanInfo = new VpeChildrenInfo(
+ targetVisualElement);
+
+ // get atribute's offset
+ int offset = ((IDOMAttr) outputAttr)
+ .getValueRegionStartOffset();
+
+ // reparse attribute's value
+ NodeList list = NodeProxyUtil.reparseAttributeValue(newValue,
+ offset);
+
+ // add children to info
+ for (int i = 0; i < list.getLength(); i++) {
+
+ Node child = list.item(i);
+
+ // add info to creation data
+ spanInfo.addSourceChild(child);
+ }
+
+ elementData.addAttributeData(new VpeAttributeData(outputAttr,
+ targetVisualElement, false));
+
+ creationData.addChildrenInfo(spanInfo);
+
+ }
+
+ creationData.setElementData(elementData);
+
+ }
+
+ }
+
+ protected String prepareAttrValue(VpePageContext pageContext,
+ Element parent, Attr attr) {
+
+ return ComponentUtil.getBundleValue(pageContext, attr);
+ }
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputFormatTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputFormatTemplate.java 2008-03-19
00:04:06 UTC (rev 7000)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputFormatTemplate.java 2008-03-19
11:30:49 UTC (rev 7001)
@@ -17,16 +17,12 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
-import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
+import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
-import org.jboss.tools.vpe.editor.mapping.VpeElementData;
-import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMText;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -41,11 +37,6 @@
public class JsfOutputFormatTemplate extends AbstractOutputJsfTemplate {
/**
- * name of "param" tag
- */
- private static final String PARAM_NAME = "param"; //$NON-NLS-1$
-
- /**
* name of "choice"
*/
private static final String CHOICE_NAME = "choice"; //$NON-NLS-1$
@@ -81,8 +72,6 @@
Element element = (Element) sourceNode;
- VpeElementData elementData = new VpeElementData();
-
// create span element
nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
@@ -92,68 +81,9 @@
// copy attributes
copyOutputJsfAttributes(span, element);
- // get attribute to represent
- Attr attr = getOutputAttributeNode(element);
+ processOutputAttribute(pageContext, visualDocument, element, span,
+ creationData);
- if (attr != null) {
-
- // offset of attr
- int offset = ((IDOMAttr) attr).getValueRegionStartOffset();
-
- // value of attribute
- String value = attr.getNodeValue();
-
- // find parameters and update value
- String newValue = updateNodeValue(value, getParams(element));
- // if escape then contents of value (or other attribute) is only
- // text
- if (!element.hasAttribute(ESCAPE_ATTR_NAME)
- || "true".equalsIgnoreCase(element
- .getAttribute(ESCAPE_ATTR_NAME))) {
-
- // get bundle value
- newValue = ComponentUtil.getBundleValue(pageContext, newValue, offset);
-
- nsIDOMText text;
- // if bundleValue differ from value then will be represent
- // bundleValue, but text will be not edit
- boolean isEditable = value.equals(newValue);
-
- text = visualDocument.createTextNode(newValue);
- // add attribute for ability of editing
- elementData.addAttributeData(new VpeAttributeData(attr, text,
- isEditable));
-
- span.appendChild(text);
- }
- // then text can be html code
- else {
-
- // create info
- VpeChildrenInfo spanInfo = new VpeChildrenInfo(span);
-
- // reparse attribute's value
- NodeList list = NodeProxyUtil.reparseAttributeValue(newValue,
- offset);
-
- // add children to info
- for (int i = 0; i < list.getLength(); i++) {
-
- Node child = list.item(i);
-
- spanInfo.addSourceChild(child);
- }
- elementData.addAttributeData(new VpeAttributeData(attr, span,
- false));
-
- creationData.addChildrenInfo(spanInfo);
-
- }
-
- }
-
- creationData.setElementData(elementData);
-
return creationData;
}
@@ -166,6 +96,16 @@
return true;
}
+ @Override
+ protected String prepareAttrValue(VpePageContext pageContext,
+ Element parent, Attr attr) {
+ int offset = ((IDOMAttr) attr).getValueRegionStartOffset();
+
+ String newString = prepareAttrValueByParams(attr.getNodeValue(),
+ getParams(parent));
+ return ComponentUtil.getBundleValue(pageContext, newString, offset);
+ }
+
/**
* find message format elements and update value
*
@@ -173,7 +113,8 @@
* @param paramList
* @return
*/
- private String updateNodeValue(String nodeValue, List<Element> paramList) {
+ private String prepareAttrValueByParams(String nodeValue,
+ List<Element> paramList) {
// matcher
Matcher matcher = Pattern.compile(MESSAGE_FORMAT_ELEMENTS_PATTERN)
@@ -249,7 +190,7 @@
if (num < paramList.size()) {
// get param's value
- value = paramList.get(num).getAttribute(VALUE_ATTR_NAME);
+ value = paramList.get(num).getAttribute(JSF.ATTR_VALUE);
}
} catch (NumberFormatException e) {
// illegal param value
@@ -299,7 +240,7 @@
Node child = nodeList.item(i);
- if (PARAM_NAME.equals(child.getLocalName()))
+ if (JSF.TAG_PARAM.equals(child.getLocalName()))
params.add((Element) child);
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputLabelTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputLabelTemplate.java 2008-03-19
00:04:06 UTC (rev 7000)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputLabelTemplate.java 2008-03-19
11:30:49 UTC (rev 7001)
@@ -10,21 +10,14 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.jsf.template;
-import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
-import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
+import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
-import org.jboss.tools.vpe.editor.mapping.VpeElementData;
-import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMText;
-import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
/**
* @author Sergey Dzmitrovich
@@ -34,11 +27,6 @@
*/
public class JsfOutputLabelTemplate extends AbstractOutputJsfTemplate {
- /**
- * name of "for" attribute
- */
- protected static final String FOR_ATTR_NAME = "for"; //$NON-NLS-1$
-
/*
* (non-Javadoc)
*
@@ -50,75 +38,19 @@
Element element = (Element) sourceNode;
- VpeElementData elementData = new VpeElementData();
-
// create label element
nsIDOMElement label = visualDocument.createElement(HTML.TAG_LABEL);
// copy attributes
copyOutputJsfAttributes(label, element);
- copyAttribute(label, element, FOR_ATTR_NAME, HTML.ATTR_FOR);
+ copyAttribute(label, element, JSF.ATTR_FOR, HTML.ATTR_FOR);
// creation data
VpeCreationData creationData = new VpeCreationData(label);
- // get attribute to represent
- Attr attr = getOutputAttributeNode(element);
+ processOutputAttribute(pageContext, visualDocument, element, label,
+ creationData);
- if (attr != null) {
-
- // if escape then contents of value (or other attribute) is only
- // text
- if (!element.hasAttribute(ESCAPE_ATTR_NAME)
- || ("true".equalsIgnoreCase(element //$NON-NLS-1$
- .getAttribute(ESCAPE_ATTR_NAME)))) {
-
- String value = attr.getNodeValue();
-
- // get bundle value
- String bundleValue = ComponentUtil.getBundleValue(pageContext, attr);
-
- nsIDOMText text;
- // if bundleValue differ from value then will be represent
- // bundleValue, but text will be not edit
- boolean isEditable = value.equals(bundleValue);
-
- text = visualDocument.createTextNode(bundleValue);
- // add attribute for ability of editing
- elementData.addAttributeData(new VpeAttributeData(attr, text,
- isEditable));
-
- label.appendChild(text);
- }
- // then text can be html code
- else {
-
- // create info
- VpeChildrenInfo labelInfo = new VpeChildrenInfo(label);
-
- // reparse attribute's value
- NodeList list = NodeProxyUtil.reparseAttributeValue(attr);
-
- // add children to info
- for (int i = 0; i < list.getLength(); i++) {
-
- Node child = list.item(i);
-
- labelInfo.addSourceChild(child);
- }
-
- elementData.addAttributeData(new VpeAttributeData(attr, label,
- false));
-
- // add info to creation data
- creationData.addChildrenInfo(labelInfo);
-
- }
-
- }
-
- creationData.setElementData(elementData);
-
return creationData;
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputTextTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputTextTemplate.java 2008-03-19
00:04:06 UTC (rev 7000)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputTextTemplate.java 2008-03-19
11:30:49 UTC (rev 7001)
@@ -10,22 +10,14 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.jsf.template;
-import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
-import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
-import org.jboss.tools.vpe.editor.mapping.VpeElementData;
-import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
-import org.mozilla.interfaces.nsIDOMText;
-import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
/**
* @author Sergey Dzmitrovich
@@ -46,8 +38,6 @@
Element element = (Element) sourceNode;
- VpeElementData elementData = new VpeElementData();
-
// create span element
nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
@@ -57,60 +47,9 @@
// copy attributes
copyOutputJsfAttributes(span, element);
- // get attribute to represent
- Attr attr = getOutputAttributeNode(element);
+ processOutputAttribute(pageContext, visualDocument, element, span,
+ creationData);
- if (attr != null) {
- // if escape then contents of value (or other attribute) is only
- // text
- if (!element.hasAttribute(ESCAPE_ATTR_NAME)
- || "true".equalsIgnoreCase(element //$NON-NLS-1$
- .getAttribute(ESCAPE_ATTR_NAME))) {
-
- String value = attr.getNodeValue();
-
- // get bundle value
- String bundleValue = ComponentUtil.getBundleValue(pageContext, attr);
-
- nsIDOMText text;
- // if bundleValue differ from value then will be represent
- // bundleValue, but text will be not edit
- boolean isEditable = value.equals(bundleValue);
-
- text = visualDocument.createTextNode(bundleValue);
- // add attribute for ability of editing
-
- elementData.addAttributeData(new VpeAttributeData(attr, text,
- isEditable));
- span.appendChild(text);
- }
- // then text can be html code
- else {
-
- // create info
- VpeChildrenInfo spanInfo = new VpeChildrenInfo(span);
-
- // reparse attribute's value
- NodeList list = NodeProxyUtil.reparseAttributeValue(attr);
-
- // add children to info
- for (int i = 0; i < list.getLength(); i++) {
-
- Node child = list.item(i);
-
- // add info to creation data
- spanInfo.addSourceChild(child);
- }
- elementData.addAttributeData(new VpeAttributeData(attr, span,
- false));
- creationData.addChildrenInfo(spanInfo);
-
- }
-
- }
-
- creationData.setElementData(elementData);
-
return creationData;
}
@@ -123,8 +62,12 @@
return true;
}
- /* (non-Javadoc)
- * @see
org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#setPseudoContent(org.jboss.tools.vpe.editor.context.VpePageContext,
org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMNode,
org.mozilla.interfaces.nsIDOMDocument)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#setPseudoContent(org.jboss.tools.vpe.editor.context.VpePageContext,
+ * org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMNode,
+ * org.mozilla.interfaces.nsIDOMDocument)
*/
@Override
public void setPseudoContent(VpePageContext pageContext,
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java 2008-03-19
11:30:49 UTC (rev 7001)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.vpe.jsf.template.util;
+
+/**
+ *
+ * @author Sergey Dzmitrovich
+ *
+ */
+public class JSF {
+
+ public static final String TAG_PARAM = "param"; //$NON-NLS-1$
+
+ public static final String ATTR_VALUE = "value"; //$NON-NLS-1$
+
+ public static final String ATTR_BINDING = "binding"; //$NON-NLS-1$
+
+ public static final String ATTR_ESCAPE = "escape"; //$NON-NLS-1$
+
+ public static final String ATTR_DIR = "dir"; //$NON-NLS-1$
+
+ public static final String ATTR_FOR = "for"; //$NON-NLS-1$
+
+}