Author: dmaliarevich
Date: 2011-10-25 12:32:15 -0400 (Tue, 25 Oct 2011)
New Revision: 35986
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
Log:
https://issues.jboss.org/browse/JBIDE-9417 - jsf template was updated, escaped attr name
was added.
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 2011-10-25
16:02:06 UTC (rev 35985)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java 2011-10-25
16:32:15 UTC (rev 35986)
@@ -35,24 +35,23 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-public abstract class AbstractOutputJsfTemplate extends
- AbstractEditableJsfTemplate {
+public abstract class AbstractOutputJsfTemplate extends AbstractEditableJsfTemplate {
- /**
- *
- * @param element
- * @return
+ /*
+ *
https://issues.jboss.org/browse/JBIDE-9417
+ * For some templates escape attribute name could differ,
+ * so it was made editable.
*/
+ protected String escapeAttributeName = JSF.ATTR_ESCAPE;
+
@Override
public Attr getOutputAttributeNode(Element element) {
-
- if (element.hasAttribute(JSF.ATTR_VALUE))
+ if (element.hasAttribute(JSF.ATTR_VALUE)) {
return element.getAttributeNode(JSF.ATTR_VALUE);
- else if (element.hasAttribute(JSF.ATTR_BINDING))
+ } else if (element.hasAttribute(JSF.ATTR_BINDING)) {
return element.getAttributeNode(JSF.ATTR_BINDING);
-
+ }
return null;
-
}
/**
@@ -61,127 +60,76 @@
* @param visualElement
* @param sourceElement
*/
- protected void copyOutputJsfAttributes(nsIDOMElement visualElement,
- Element sourceElement) {
+ protected void copyOutputJsfAttributes(nsIDOMElement visualElement, Element
sourceElement) {
copyGeneralJsfAttributes(sourceElement, visualElement);
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) {
-
VpeElementProxyData elementData = new VpeElementProxyData();
-
Attr outputAttr = getOutputAttributeNode(sourceElement);
-
if (outputAttr != null) {
-
- // prepare value
String newValue = prepareAttrValue(pageContext, sourceElement, outputAttr);
- // 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))) {
-
+ /*
+ * if escape then contents of value (or other attribute) is only text
+ */
+ if (!sourceElement.hasAttribute(escapeAttributeName)
+ ||
"true".equalsIgnoreCase(sourceElement.getAttribute(escapeAttributeName))) {
//$NON-NLS-1$
String value = outputAttr.getValue();
-
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.addNodeData(new AttributeData(outputAttr, text,
- isEditable));
-
+ elementData.addNodeData(new AttributeData(outputAttr, text, isEditable));
targetVisualElement.appendChild(text);
-
- }
- // then text can be html code
- else {
-
- // create info
- VpeChildrenInfo targetVisualInfo = new VpeChildrenInfo(
- targetVisualElement);
-
+ } else {
+ /*
+ * then text can be html code
+ * create VpeChildrenInfo to process source nodes
+ */
+ VpeChildrenInfo targetVisualInfo = new VpeChildrenInfo(targetVisualElement);
// get atribute's offset
-
//mareshkau because it's node can be a proxy, see JBIDE-3144
if(!(outputAttr instanceof IDOMAttr)) {
- outputAttr = (Attr)
((((Attr)outputAttr).getOwnerElement()).getAttributes().getNamedItem(outputAttr.getLocalName()));
+ outputAttr = (Attr) ((((Attr)outputAttr).getOwnerElement())
+ .getAttributes().getNamedItem(outputAttr.getLocalName()));
}
-
- int offset = ((IDOMAttr) outputAttr)
- .getValueRegionStartOffset();
-
+ int offset = ((IDOMAttr) outputAttr).getValueRegionStartOffset();
// reparse attribute's value
NodeList list = NodeProxyUtil.reparseAttributeValue(
elementData, newValue, offset + 1);
-
// add children to info
for (int i = 0; i < list.getLength(); i++) {
-
Node child = list.item(i);
-
// add info to creation data
targetVisualInfo.addSourceChild(child);
}
-
- elementData.addNodeData(new AttributeData(outputAttr,
- targetVisualElement, true));
-
+ elementData.addNodeData(new AttributeData(outputAttr, targetVisualElement, true));
creationData.addChildrenInfo(targetVisualInfo);
-
}
-
}
-
creationData.setElementData(elementData);
}
-
-// @Deprecated
-// protected String prepareAttrValue(VpePageContext pageContext,
-// Element parent, Attr attr) {
-//
-// return ComponentUtil.getBundleValue(pageContext, attr);
-// }
- /*
- * (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,
Node sourceContainer, nsIDOMNode visualContainer,
nsIDOMDocument visualDocument) {
- // Empty
+ /*
+ * Do nothing
+ */
}
@Override
public NodeData getNodeData(nsIDOMNode node, VpeElementData elementData,
VpeDomMapping domMapping) {
- // TODO Auto-generated method stub
NodeData nodeData = super.getNodeData(node, elementData, domMapping);
if (nodeData == null) {
-
VpeNodeMapping nodeMapping = domMapping.getNodeMapping(node);
-
if (nodeMapping != null) {
if (nodeMapping instanceof VpeElementMapping) {
nodeData = super.getNodeData(node,
@@ -201,19 +149,12 @@
public nsIDOMNode getVisualNodeBySourcePosition(
VpeElementMapping elementMapping, Point selectionRange, VpeDomMapping domMapping) {
nsIDOMNode node = null;
-
if ((elementMapping.getElementData() instanceof VpeElementProxyData)
- && (((VpeElementProxyData) elementMapping.getElementData())
- .getNodelist() != null)) {
-
- VpeElementProxyData elementProxyData = (VpeElementProxyData) elementMapping
- .getElementData();
-
+ && (((VpeElementProxyData) elementMapping.getElementData()).getNodelist() !=
null)) {
+ VpeElementProxyData elementProxyData = (VpeElementProxyData)
elementMapping.getElementData();
VpeNodeMapping nodeMapping = NodeProxyUtil.findNodeByPosition(
domMapping, elementProxyData.getNodelist(), selectionRange);
-
if (nodeMapping != null) {
-
if (nodeMapping instanceof VpeElementMapping) {
node = super.getVisualNodeBySourcePosition(
(VpeElementMapping) nodeMapping, selectionRange, domMapping);
@@ -222,17 +163,27 @@
}
}
}
-
if (node == null) {
- node = super.getVisualNodeBySourcePosition(elementMapping,
- selectionRange, domMapping);
+ node = super.getVisualNodeBySourcePosition(elementMapping, selectionRange,
domMapping);
}
return node;
}
-
- protected String prepareAttrValue(VpePageContext pageContext,
- Element parent, Attr attr) {
- return attr.getNodeValue();
- }
+ protected String prepareAttrValue(VpePageContext pageContext, Element parent, Attr attr)
{
+ /*
+ * Currently used only in JsfOutputFormatTemplate
+ */
+ return attr.getNodeValue();
+ }
+
+ /**
+ * If tag uses different attribute name than "escape" for displaying escaped
sequence --
+ * subclasses could set an appropriate attribute name directly
+ *
+ * @param escapeAttributeName the new attribute name
+ */
+ protected void setEscapeAttributeName(String escapeAttributeName) {
+ this.escapeAttributeName = escapeAttributeName;
+ }
+
}
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 2011-10-25
16:02:06 UTC (rev 35985)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfOutputFormatTemplate.java 2011-10-25
16:32:15 UTC (rev 35986)
@@ -97,12 +97,8 @@
}
@Override
- protected String prepareAttrValue(VpePageContext pageContext,
- Element parent, Attr attr) {
- String newString = prepareAttrValueByParams(attr.getNodeValue(),
- getParams(parent));
-
- return newString;
+ protected String prepareAttrValue(VpePageContext pageContext, Element parent, Attr attr)
{
+ return prepareAttrValueByParams(attr.getNodeValue(), getParams(parent));
}
/**
@@ -112,39 +108,26 @@
* @param paramList
* @return
*/
- private String prepareAttrValueByParams(String nodeValue,
- List<Element> paramList) {
-
+ private String prepareAttrValueByParams(String nodeValue, List<Element> paramList)
{
// matcher
- Matcher matcher = Pattern.compile(MESSAGE_FORMAT_ELEMENTS_PATTERN)
- .matcher(nodeValue);
-
+ Matcher matcher = Pattern.compile(MESSAGE_FORMAT_ELEMENTS_PATTERN).matcher(nodeValue);
int lastPos = 0;
StringBuilder sb = new StringBuilder();
-
while (matcher.find()) {
-
// get next message format elements
String messageFormatElement = matcher.group();
// set end and start
int start = matcher.start();
int end = matcher.end();
-
// get value of message format element
- String value = parseMessageFormatElement(messageFormatElement,
- paramList);
-
+ String value = parseMessageFormatElement(messageFormatElement, paramList);
// update value
sb.append(nodeValue.substring(lastPos, start));
sb.append(value);
-
lastPos = end;
}
-
sb.append(nodeValue.substring(lastPos));
-
return sb.toString();
-
}
/**
@@ -196,10 +179,8 @@
// illegal param value
}
}
-
// return or value or starting value
return value != null ? value : messageFormatElement;
-
}
/**
@@ -209,19 +190,15 @@
* @return
*/
private String getChoice(String choiceString) {
-
// separate all choices
String[] choices = choiceString.split(CHOICES_SEPARATOR);
-
// separate first choice pair(choice value / choice string)
String[] choice = choices[0].split(CHOICE_PAIR_SEPARATOR);
-
// return choice string
- if (choice.length > 1)
+ if (choice.length > 1) {
return choice[1];
-
+ }
return null;
-
}
/**
@@ -231,21 +208,14 @@
* @return
*/
private List<Element> getParams(Element sourcElement) {
-
NodeList nodeList = sourcElement.getChildNodes();
-
List<Element> params = new ArrayList<Element>();
-
for (int i = 0; i < nodeList.getLength(); i++) {
-
Node child = nodeList.item(i);
-
- if (JSF.TAG_PARAM.equals(child.getLocalName()))
+ if (JSF.TAG_PARAM.equals(child.getLocalName())) {
params.add((Element) child);
-
+ }
}
-
return params;
-
}
}