Author: ezheleznyakov
Date: 2007-09-07 06:26:18 -0400 (Fri, 07 Sep 2007)
New Revision: 3485
Added:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/lib/
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/lib/jhighlight-1.0.jar
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInsertTemplate.java
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/.classpath
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/META-INF/MANIFEST.MF
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/build.properties
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/ComponentUtil.java
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/templates/vpe-templates-richfaces.xml
Log:
http://jira.jboss.com/jira/browse/JBIDE-847
Create <rich:insert> template
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/.classpath
===================================================================
---
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/.classpath 2007-09-07
10:03:06 UTC (rev 3484)
+++
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/.classpath 2007-09-07
10:26:18 UTC (rev 3485)
@@ -3,5 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="lib" path="lib/jhighlight-1.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/META-INF/MANIFEST.MF
===================================================================
---
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/META-INF/MANIFEST.MF 2007-09-07
10:03:06 UTC (rev 3484)
+++
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/META-INF/MANIFEST.MF 2007-09-07
10:26:18 UTC (rev 3485)
@@ -16,3 +16,5 @@
org.mozilla.xpcom
Eclipse-LazyStart: true
Bundle-Vendor: Red Hat, Inc.
+Bundle-ClassPath: lib/jhighlight-1.0.jar,
+ .
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/build.properties
===================================================================
---
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/build.properties 2007-09-07
10:03:06 UTC (rev 3484)
+++
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/build.properties 2007-09-07
10:26:18 UTC (rev 3485)
@@ -4,7 +4,8 @@
.,\
resources/,\
templates/,\
- plugin.xml
+ plugin.xml,\
+ lib/jhighlight-1.0.jar
src.includes = src/,\
resources/,\
templates/
Added:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/lib/jhighlight-1.0.jar
===================================================================
(Binary files differ)
Property changes on:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/lib/jhighlight-1.0.jar
___________________________________________________________________
Name: svn:mime-type
+ application/x-jar
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/ComponentUtil.java
===================================================================
---
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/ComponentUtil.java 2007-09-07
10:03:06 UTC (rev 3484)
+++
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/ComponentUtil.java 2007-09-07
10:26:18 UTC (rev 3485)
@@ -7,7 +7,7 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.jsf.vpe.richfaces;
import java.io.File;
@@ -33,32 +33,36 @@
public class ComponentUtil {
/**
- * Gets child of Facet element by name.
- * If facet has a few children the method will return first one.
+ * Gets child of Facet element by name. If facet has a few children the
+ * method will return first one.
+ *
* @param sourceElement
* @param facetName
- * @param returnTextNode return child text node if facet doesn't have any child
elements;
+ * @param returnTextNode
+ * return child text node if facet doesn't have any child
+ * elements;
* @return
*/
- public static Node getFacet(Element sourceElement, String facetName, boolean
returnTextNode) {
+ public static Node getFacet(Element sourceElement, String facetName,
+ boolean returnTextNode) {
NodeList children = sourceElement.getChildNodes();
- for(int i=0; i<children.getLength(); i++) {
+ for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
- if(node instanceof Element && "f:facet".equals(node.getNodeName()))
{
- Element element = (Element)node;
+ if (node instanceof Element && "f:facet".equals(node.getNodeName()))
{
+ Element element = (Element) node;
String name = element.getAttribute("name");
- if(facetName.equals(name)) {
+ if (facetName.equals(name)) {
NodeList childNodes = element.getChildNodes();
Text textNode = null;
- for(int j=0; j<childNodes.getLength(); j++) {
+ for (int j = 0; j < childNodes.getLength(); j++) {
Node child = childNodes.item(j);
- if(child instanceof Element) {
+ if (child instanceof Element) {
return child;
- } else if(child instanceof Text) {
- textNode = (Text)child;
+ } else if (child instanceof Text) {
+ textNode = (Text) child;
}
}
- if(returnTextNode) {
+ if (returnTextNode) {
return textNode;
}
}
@@ -68,32 +72,36 @@
}
/**
- * Gets all facets of sourceElement.
- * If facet has a few children the method will return first one.
+ * Gets all facets of sourceElement. If facet has a few children the method
+ * will return first one.
+ *
* @param sourceElement
* @param facetName
- * @param returnTextNode return child text node if facet doesn't have any child
elements;
+ * @param returnTextNode
+ * return child text node if facet doesn't have any child
+ * elements;
* @return
*/
- public static ArrayList<Node> getFacets(Element sourceElement, boolean
returnTextNode) {
+ public static ArrayList<Node> getFacets(Element sourceElement,
+ boolean returnTextNode) {
ArrayList<Node> facets = new ArrayList<Node>();
NodeList children = sourceElement.getChildNodes();
- for(int i=0; i<children.getLength(); i++) {
+ for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
- if(node instanceof Element && "f:facet".equals(node.getNodeName()))
{
- Element element = (Element)node;
+ if (node instanceof Element && "f:facet".equals(node.getNodeName()))
{
+ Element element = (Element) node;
NodeList childNodes = element.getChildNodes();
Text textNode = null;
- for(int j=0; j<childNodes.getLength(); j++) {
+ for (int j = 0; j < childNodes.getLength(); j++) {
Node child = childNodes.item(j);
- if(child instanceof Element) {
+ if (child instanceof Element) {
facets.add(child);
break;
- } else if(child instanceof Text) {
- textNode = (Text)child;
+ } else if (child instanceof Text) {
+ textNode = (Text) child;
}
}
- if(returnTextNode && facets.isEmpty()) {
+ if (returnTextNode && facets.isEmpty()) {
facets.add(textNode);
}
}
@@ -102,31 +110,37 @@
}
/**
- * Gets child of Facet element by name.
- * If facet has a few children the method will return first one.
+ * Gets child of Facet element by name. If facet has a few children the
+ * method will return first one.
+ *
* @param sourceElement
* @param facetName
* @return
*/
public static Element getFacet(Element sourceElement, String facetName) {
- return (Element)getFacet(sourceElement, facetName, false);
+ return (Element) getFacet(sourceElement, facetName, false);
}
/**
- * Returns true if "rendered" attribute of source element does not contain
"false" value.
+ * Returns true if "rendered" attribute of source element does not contain
+ * "false" value.
+ *
* @param sourceElement
* @return
*/
public static boolean isRendered(Element sourceElement) {
- return
!"false".equalsIgnoreCase(sourceElement.getAttribute("rendered"));
+ return !"false"
+ .equalsIgnoreCase(sourceElement.getAttribute("rendered"));
}
/**
* Sets CSS link in visual html document.
+ *
* @param pageContext
* @param cssHref
*/
- public static void setCSSLink(VpePageContext pageContext, String cssHref, String ext) {
+ public static void setCSSLink(VpePageContext pageContext, String cssHref,
+ String ext) {
String pluginPath = RichFacesTemplatesActivator.getPluginResourcePath();
IPath pluginFile = new Path(pluginPath);
File cssFile = pluginFile.append(cssHref).toFile();
@@ -137,104 +151,120 @@
}
public static String getAbsoluteResourcePath(String resourcePathInPlugin) {
- String pluginPath = RichFacesTemplatesActivator.getPluginResourcePath();
- IPath pluginFile = new Path(pluginPath);
- File file = pluginFile.append(resourcePathInPlugin).toFile();
- if (file.exists()) {
- return file.getAbsolutePath();
- } else {
- throw new RuntimeException("Can't get path for " +
resourcePathInPlugin);
- }
+ String pluginPath = RichFacesTemplatesActivator.getPluginResourcePath();
+ IPath pluginFile = new Path(pluginPath);
+ File file = pluginFile.append(resourcePathInPlugin).toFile();
+ if (file.exists()) {
+ return file.getAbsolutePath();
+ } else {
+ throw new RuntimeException("Can't get path for "
+ + resourcePathInPlugin);
+ }
}
-
- /**
- * Adds image as attribute to IMG tag
- *
- * @param img
- * @param fileImageName
- */
- public static void setImg(nsIDOMElement img, String fileImageName) {
- img.setAttribute("src", "file://" +
getAbsoluteResourcePath(fileImageName));
- }
- /**
- * Returns all child source elements of component but facets.
- * @param sourceElement
- * @param returnTextNodes return child text nodes and elements or elements only;
- * @return
- */
- public static List<Node> getChildren(Element sourceElement, boolean
returnTextNodes) {
- ArrayList<Node> children = new ArrayList<Node>();
+ /**
+ * Adds image as attribute to IMG tag
+ *
+ * @param img
+ * @param fileImageName
+ */
+ public static void setImg(nsIDOMElement img, String fileImageName) {
+ img.setAttribute("src", "file://"
+ + getAbsoluteResourcePath(fileImageName));
+ }
+
+ /**
+ * Returns all child source elements of component but facets.
+ *
+ * @param sourceElement
+ * @param returnTextNodes
+ * return child text nodes and elements or elements only;
+ * @return
+ */
+ public static List<Node> getChildren(Element sourceElement,
+ boolean returnTextNodes) {
+ ArrayList<Node> children = new ArrayList<Node>();
NodeList nodeList = sourceElement.getChildNodes();
- for(int i=0; i<nodeList.getLength(); i++) {
+ for (int i = 0; i < nodeList.getLength(); i++) {
Node child = nodeList.item(i);
- if((child instanceof Element || returnTextNodes) &&
(!child.getNodeName().equals("f:facet"))) {
+ if ((child instanceof Element || returnTextNodes)
+ && (!child.getNodeName().equals("f:facet"))) {
children.add(child);
}
}
- return children;
- }
+ return children;
+ }
- /**
- * Returns all child source elements of component but facets.
- * @param sourceElement
- * @return
- */
- public static List<Node> getChildren(Element sourceElement) {
- return getChildren(sourceElement, false);
- }
-
-
- /**
- * Returns all child visual elements of component but facets.
- * @param visualElement
- * @param
- * @return returnTextNodes return child text nodes and elements or elements only;
- */
- public static List<nsIDOMNode> getChildren(nsIDOMElement visualElement, boolean
returnTextNodes) {
- ArrayList<nsIDOMNode> children = new ArrayList<nsIDOMNode>();
+ /**
+ * Returns all child source elements of component but facets.
+ *
+ * @param sourceElement
+ * @return
+ */
+ public static List<Node> getChildren(Element sourceElement) {
+ return getChildren(sourceElement, false);
+ }
+
+ /**
+ * Returns all child visual elements of component but facets.
+ *
+ * @param visualElement
+ * @param
+ * @return returnTextNodes return child text nodes and elements or elements
+ * only;
+ */
+ public static List<nsIDOMNode> getChildren(nsIDOMElement visualElement,
+ boolean returnTextNodes) {
+ ArrayList<nsIDOMNode> children = new ArrayList<nsIDOMNode>();
nsIDOMNodeList nodeList = visualElement.getChildNodes();
- for(int i=0; i<nodeList.getLength(); i++) {
- nsIDOMNode child = nodeList.item(i);
- if((child instanceof nsIDOMElement || returnTextNodes) &&
(!child.getNodeName().equals("f:facet"))) {
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ nsIDOMNode child = nodeList.item(i);
+ if ((child instanceof nsIDOMElement || returnTextNodes)
+ && (!child.getNodeName().equals("f:facet"))) {
children.add(child);
}
}
- return children;
- }
-
- /**
- * Returns all child visual elements of component but facets.
- * @param visualElement
- * @return
- */
- public static List<nsIDOMNode> getChildren(nsIDOMElement visualElement) {
- return getChildren(visualElement, false);
- }
+ return children;
+ }
- /**
- * Copies all attributes from source node to visual node.
- * @param sourceNode
- * @param visualNode
- */
- public static void copyAttributes(Node sourceNode, nsIDOMElement visualElement) {
+ /**
+ * Returns all child visual elements of component but facets.
+ *
+ * @param visualElement
+ * @return
+ */
+ public static List<nsIDOMNode> getChildren(nsIDOMElement visualElement) {
+ return getChildren(visualElement, false);
+ }
+
+ /**
+ * Copies all attributes from source node to visual node.
+ *
+ * @param sourceNode
+ * @param visualNode
+ */
+ public static void copyAttributes(Node sourceNode,
+ nsIDOMElement visualElement) {
NamedNodeMap namedNodeMap = sourceNode.getAttributes();
for (int i = 0; i < namedNodeMap.getLength(); i++) {
Node attribute = namedNodeMap.item(i);
- visualElement.setAttribute(attribute.getNodeName(), attribute.getNodeValue());
+ visualElement.setAttribute(attribute.getNodeName(), attribute
+ .getNodeValue());
}
}
-
+
/**
* Returns true if sourceNode is Facet
+ *
* @param sourceNode
* @param facetName
* @return
*/
public static boolean isFacet(Node sourceNode, String facetName) {
- if(sourceNode!=null && sourceNode instanceof Element &&
sourceNode.getNodeName().equals("f:facet")) {
- String name = ((Element)sourceNode).getAttribute("name");
- if(facetName.equals(name)) {
+ if (sourceNode != null && sourceNode instanceof Element
+ && sourceNode.getNodeName().equals("f:facet")) {
+ String name = ((Element) sourceNode).getAttribute("name");
+ if (facetName.equals(name)) {
return true;
}
}
@@ -242,24 +272,29 @@
}
/**
- * Returns Style with background image for default RichFaces skin.
+ * Returns Style with background image for default RichFaces skin.
+ *
* @return
*/
public static String getHeaderBackgoundImgStyle() {
- String imgPath =
ComponentUtil.getAbsoluteResourcePath("common/background.gif");
- String style = "background-image: url(file:///" +
imgPath.replace('\\', '/') + ");";
+ String imgPath = ComponentUtil
+ .getAbsoluteResourcePath("common/background.gif");
+ String style = "background-image: url(file:///"
+ + imgPath.replace('\\', '/') + ");";
return style;
}
-
+
/**
* Returns value of attribute.
+ *
* @param sourceElement
* @param attributeName
* @return
*/
- public static String getAttribute(Element sourceElement, String attributeName) {
+ public static String getAttribute(Element sourceElement,
+ String attributeName) {
String attribute = sourceElement.getAttribute(attributeName);
- if(attribute==null) {
+ if (attribute == null) {
attribute = "";
}
return attribute;
@@ -267,18 +302,20 @@
/**
* Returns value of attribute.
+ *
* @param sourceElement
* @param attributeName
* @return
*/
- public static String getAttribute(nsIDOMElement sourceElement, String attributeName) {
+ public static String getAttribute(nsIDOMElement sourceElement,
+ String attributeName) {
String attribute = sourceElement.getAttribute(attributeName);
- if(attribute==null) {
+ if (attribute == null) {
attribute = "";
}
return attribute;
}
-
+
/**
* @param style
* @param name
@@ -305,51 +342,78 @@
*/
public static String addParameter(String style, String element) {
String s = style.trim();
- return style + (s.length() == 0 || s.endsWith(";") ? "" :
";") + element;
+ return style + (s.length() == 0 || s.endsWith(";") ? "" :
";")
+ + element;
}
-
- /** Adds image as attribute to IMG tag from users worcpace
- * @param pageContext Page Context
- * @param img img element to which set picture
- * @param fileImageName image name
- * @param undefinedImgName default image when image is undefined
+
+ /**
+ * Adds image as attribute to IMG tag from users worcpace
+ *
+ * @param pageContext
+ * Page Context
+ * @param img
+ * img element to which set picture
+ * @param fileImageName
+ * image name
+ * @param undefinedImgName
+ * default image when image is undefined
*/
- public static void setImgFromResources(VpePageContext pageContext, nsIDOMElement
img, String fileImageName, String undefinedImgName) {
- IEditorInput input = pageContext.getEditPart().getEditorInput();
- IPath inputPath = getInputParentPath(input);
- File file=new File(inputPath.toOSString()+File.separator+fileImageName);
- if(file.exists()){
- img.setAttribute(HtmlComponentUtil.HTML_ATR_SRC,
- HtmlComponentUtil.FILE_PROTOCOL+inputPath.toOSString()+
- File.separator+fileImageName);
- } else {
- img.setAttribute(HtmlComponentUtil.HTML_ATR_SRC, undefinedImgName);
+ public static void setImgFromResources(VpePageContext pageContext,
+ nsIDOMElement img, String fileImageName, String undefinedImgName) {
+ IEditorInput input = pageContext.getEditPart().getEditorInput();
+ IPath inputPath = getInputParentPath(input);
+ File file = new File(inputPath.toOSString() + File.separator
+ + fileImageName);
+ if (file.exists()) {
+ img.setAttribute(HtmlComponentUtil.HTML_ATR_SRC,
+ HtmlComponentUtil.FILE_PROTOCOL + inputPath.toOSString()
+ + File.separator + fileImageName);
+ } else {
+ img.setAttribute(HtmlComponentUtil.HTML_ATR_SRC, undefinedImgName);
}
}
- /**
- * Returns locale of user input
- * @param input
- * @return
- */
+ /**
+ * Open file
+ *
+ * @param pageContext
+ * Page Context
+ * @param fileName
+ * file name
+ * @return file
+ */
+ public static File openFile(VpePageContext pageContext, String fileName) {
+ IEditorInput input = pageContext.getEditPart().getEditorInput();
+ IPath inputPath = getInputParentPath(input);
+ File file = new File(inputPath.toOSString() + File.separator + fileName);
+ return file;
+ }
+
+ /**
+ * Returns locale of user input
+ *
+ * @param input
+ * @return
+ */
public static IPath getInputParentPath(IEditorInput input) {
- IPath inputPath = null;
+ IPath inputPath = null;
if (input instanceof ILocationProvider) {
- inputPath = ((ILocationProvider)input).getPath(input);
+ inputPath = ((ILocationProvider) input).getPath(input);
} else if (input instanceof IFileEditorInput) {
- IFile inputFile = ((IFileEditorInput)input).getFile();
- if (inputFile != null) {
- inputPath = inputFile.getLocation();
- }
+ IFile inputFile = ((IFileEditorInput) input).getFile();
+ if (inputFile != null) {
+ inputPath = inputFile.getLocation();
+ }
}
if (inputPath != null && !inputPath.isEmpty()) {
- inputPath = inputPath.removeLastSegments(1);
+ inputPath = inputPath.removeLastSegments(1);
}
- return inputPath;
+ return inputPath;
}
/**
* Move attributes from sourceNode to html
+ *
* @param sourceNode
* @param visualNode
* @param attrName
@@ -357,10 +421,12 @@
* @param prefValue
* @param defValue
*/
- public static void correctAttribute(Element sourceNode, nsIDOMElement visualNode,
- String attrName, String htmlAttrName, String prefValue, String defValue) {
+ public static void correctAttribute(Element sourceNode,
+ nsIDOMElement visualNode, String attrName, String htmlAttrName,
+ String prefValue, String defValue) {
String attrValue = ((Element) sourceNode).getAttribute(attrName);
- if (prefValue != null && prefValue.trim().length() > 0 && attrValue
!= null) {
+ if (prefValue != null && prefValue.trim().length() > 0
+ && attrValue != null) {
attrValue = prefValue.trim() + " " + attrValue;
}
if (attrValue != null) {
Added:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInsertTemplate.java
===================================================================
---
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInsertTemplate.java
(rev 0)
+++
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInsertTemplate.java 2007-09-07
10:26:18 UTC (rev 3485)
@@ -0,0 +1,276 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.vpe.richfaces.template;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.StringBufferInputStream;
+import java.util.HashMap;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
+import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMText;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+import com.uwyn.jhighlight.renderer.Renderer;
+import com.uwyn.jhighlight.renderer.XhtmlRendererFactory;
+
+/**
+ *
+ * @author ezheleznyakov(a)exadel.com
+ *
+ */
+public class RichFacesInsertTemplate extends VpeAbstractTemplate {
+
+ private static String SRC_ATTR_NAME = "src";
+ private static String HIGHTLIGHT_ATTR_NAME = "highlight";
+
+ private static String CODE_TAG = "code>";
+
+ private static String CLASS = "class=";
+
+ private static String STYLE = "style=";
+
+ private static String OPEN_BRACKET = "{";
+
+ private static String CLOSE_BRACKET = "}";
+
+ private static String SPACE = " ";
+
+ private static String SPAN_TAG = "<span style=\"color:
rgb(255,255,255)\">_</span>";
+
+ private static String EMPTY_STRING = "";
+
+ private nsIDOMDocument visualDocument;
+
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+
+ this.visualDocument = visualDocument;
+
+ nsIDOMElement div = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_DIV);
+
+ String srcValue = ((Element) sourceNode).getAttribute(SRC_ATTR_NAME);
+ String highlightValue = ((Element) sourceNode)
+ .getAttribute(HIGHTLIGHT_ATTR_NAME);
+
+ VpeCreationData vpeCreationData = new VpeCreationData(div);
+
+ File file = ComponentUtil.openFile(pageContext, srcValue);
+ String finalStr = "";
+ String buf = "";
+
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ new FileInputStream(file)));
+
+ while ((buf = br.readLine()) != null)
+ finalStr += buf + "\n";
+
+ } catch (Exception e) {
+ finalStr = "Resources " + srcValue + " not found.";
+ div.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, "color: red; "
+ + "font-weight: bold;");
+ nsIDOMText text = visualDocument.createTextNode(finalStr);
+ div.appendChild(text);
+ return vpeCreationData;
+ }
+
+ if (!serchInSupportedTypes(highlightValue))
+ return vpeCreationData;
+
+ if (highlightValue == null) {
+ finalStr = finalStr.replace('\n', ' ');
+ nsIDOMText text = visualDocument.createTextNode(finalStr);
+ div.appendChild(text);
+ return vpeCreationData;
+ }
+
+ Renderer renderer = XhtmlRendererFactory.getRenderer(highlightValue);
+ String transformStr = null;
+ try {
+ transformStr = renderer.highlight("", finalStr, "utf-8", false);
+ transformStr = convertString(transformStr, highlightValue);
+ Node node = parseTransformString(transformStr);
+ buildVisualNode(node, div);
+ } catch (IOException e1) {
+ return vpeCreationData;
+ }
+ return vpeCreationData;
+ }
+
+ /**
+ *
+ * @param str
+ * @param highlightValue
+ * highlight attribute value
+ */
+ private String convertString(String str, String highlightValue) {
+
+ HashMap<String, String> map = new HashMap<String, String>();
+
+ if (highlightValue.equalsIgnoreCase("html")
+ || highlightValue.equalsIgnoreCase("xhtml")
+ || highlightValue.equalsIgnoreCase("lzx"))
+ highlightValue = "xml";
+ if (highlightValue.equalsIgnoreCase("groovy")) {
+ highlightValue = "java";
+ }
+ if (highlightValue.equalsIgnoreCase("c++")) {
+ highlightValue = "cpp";
+ }
+
+ String sym = "." + highlightValue + "_";
+
+ for (int i = 0; i < str.length();) {
+ int start = str.indexOf(sym, i);
+ if (start == -1)
+ break;
+ int startBracket = str.indexOf(OPEN_BRACKET, start);
+ String key = str.substring(start + 1, startBracket - 1);
+ int endBracket = str.indexOf(CLOSE_BRACKET, startBracket);
+ String value = str.substring(startBracket + 2, endBracket - 2);
+ i = endBracket;
+ map.put(key, value);
+ }
+
+ int start = str.indexOf(CODE_TAG);
+ int end = str.indexOf(CODE_TAG, start + 1);
+ str = str.substring(start - 1, end + 5);
+
+ str = str.replaceAll(CLASS, STYLE);
+
+ Set<String> set = map.keySet();
+
+ for (String key : set) {
+ String value = map.get(key);
+ str = str.replaceAll(key, value);
+ }
+ str = str.replace(SPACE, SPAN_TAG);
+ return str;
+ }
+
+ /**
+ *
+ * @param fileTransform
+ */
+ @SuppressWarnings("deprecation")
+ public Node parseTransformString(String transformString) {
+
+ DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
+
+ DocumentBuilder builder = null;
+ Document doc = null;
+ Node node = null;
+ try {
+ builder = fact.newDocumentBuilder();
+ doc = builder.parse(new StringBufferInputStream(transformString));
+ node = doc.getElementsByTagName("code").item(0);
+ } catch (Exception e) {
+ return node;
+ }
+ return node;
+ }
+
+ /**
+ *
+ * @param highlightValue
+ * value of highlight attribute
+ * @return true of highlight value correct
+ */
+
+ private boolean serchInSupportedTypes(String highlightValue) {
+
+ if (highlightValue == null)
+ return true;
+
+ if (highlightValue.trim().equals(EMPTY_STRING))
+ return false;
+
+ Set<?> set = XhtmlRendererFactory.getSupportedTypes();
+
+ for (Object object : set)
+ if (highlightValue.equalsIgnoreCase((String) object))
+ return true;
+
+ return false;
+ }
+
+ /**
+ *
+ * @param node
+ * @param el
+ * @return
+ */
+ private void buildVisualNode(Node node, nsIDOMElement el) {
+
+ if (node instanceof Text) {
+ nsIDOMText text = visualDocument.createTextNode(node
+ .getTextContent());
+ el.appendChild(text);
+
+ } else {
+ nsIDOMElement elem = visualDocument.createElement(node
+ .getNodeName());
+ el.appendChild(elem);
+
+ for (int i = 0; i < node.getAttributes().getLength(); i++)
+ elem.setAttribute(node.getAttributes().item(i).getNodeName(),
+ node.getAttributes().item(i).getNodeValue());
+
+ for (int i = 0; i < node.getChildNodes().getLength(); i++)
+ buildVisualNode(node.getChildNodes().item(i), elem);
+ }
+ }
+
+ /**
+ * Checks, whether it is necessary to re-create an element at change of
+ * attribute
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceElement
+ * The current element of the source tree.
+ * @param visualDocument
+ * The document of the visual tree.
+ * @param visualNode
+ * The current node of the visual tree.
+ * @param data
+ * The arbitrary data, built by a method <code>create</code>
+ * @param name
+ * Atrribute name
+ * @param value
+ * Attribute value
+ * @return <code>true</code> if it is required to re-create an element at
+ * a modification of attribute, <code>false</code> otherwise.
+ */
+ public boolean isRecreateAtAttrChange(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualNode, Object data, String name, String value) {
+ return true;
+ }
+}
\ No newline at end of file
Property changes on:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInsertTemplate.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/templates/vpe-templates-richfaces.xml
===================================================================
---
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/templates/vpe-templates-richfaces.xml 2007-09-07
10:03:06 UTC (rev 3484)
+++
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/templates/vpe-templates-richfaces.xml 2007-09-07
10:26:18 UTC (rev 3485)
@@ -529,5 +529,18 @@
</span>
</vpe:template>
</vpe:tag>
+
+ <vpe:tag name="rich:insert" case-sensetive="yes">
+ <vpe:template children="yes" modify="yes"
class="org.jboss.tools.jsf.vpe.richfaces.template.RichFacesInsertTemplate">
+ <vpe:resize>
+ <vpe:width width-attr="style.width" />
+ <vpe:height height-attr="style.height" />
+ </vpe:resize>
+ <vpe:dnd>
+ <vpe:drag start-enable="yes" />
+ <vpe:drop container="yes"/>
+ </vpe:dnd>
+ </vpe:template>
+ </vpe:tag>
</vpe:templates>
\ No newline at end of file