Author: mareshkau
Date: 2009-10-15 10:02:14 -0400 (Thu, 15 Oct 2009)
New Revision: 18109
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/Jsf2CustomComponentTemplate.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5015/
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5015/login.xhtml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5015/login.xhtml.xml
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/WEB-INF/lib/jbide2550.jar
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2550Test.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCustomTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDReference.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionSrc.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FileUtil.java
Log:
Jsf2.0 costom camponent support has been added to VPE,
https://jira.jboss.org/jira/browse/JBIDE-5015
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/Jsf2CustomComponentTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/Jsf2CustomComponentTemplate.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/Jsf2CustomComponentTemplate.java 2009-10-15
14:02:14 UTC (rev 18109)
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IStorage;
+import org.jboss.tools.jst.web.tld.TaglibData;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.VpeCustomTemplate;
+import org.jboss.tools.vpe.editor.template.custom.CustomTLDReference;
+import org.jboss.tools.vpe.editor.util.XmlUtil;
+import org.w3c.dom.Node;
+
+/**
+ * Class implements support for custom jsf 2.0 components
+ *
+ * @author mareshkau
+ *
+ */
+public class Jsf2CustomComponentTemplate extends VpeCustomTemplate{
+
+ @Override
+ protected IStorage getCustomTemplateStorage(VpePageContext pageContext, Node
sourceNode){
+ String sourcePrefix = sourceNode.getPrefix();
+
+ List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,pageContext);
+
+ TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourcePrefix, taglibs);
+
+ if(sourceNodeTaglib == null) {
+ return null;
+ }
+
+ String sourceNodeUri = sourceNodeTaglib.getUri();
+
+ return CustomTLDReference.getJsf2CustomComponentStorage(pageContext, sourceNodeUri,
sourceNode.getLocalName());
+ }
+}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml 2009-10-15
14:01:19 UTC (rev 18108)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml 2009-10-15
14:02:14 UTC (rev 18109)
@@ -4,6 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<vpe:template-taglib
uri="http://java.sun.com/jsf/html"
prefix="h" />
<vpe:template-taglib
uri="http://java.sun.com/jsf/core"
prefix="f" />
+ <vpe:template-taglib
uri="http://java.sun.com/jsf/composite"
prefix="composite" />
<vpe:tag name="f:loadBundle" case-sensitive="yes">
<vpe:template children="no" modify="no">
@@ -178,7 +179,6 @@
</vpe:template>
</vpe:tag>
- <!-- Проблема с адресацией от приложения (30 of 4) -->
<vpe:tag name="h:commandButton" case-sensitive="yes">
<!-- This is a very big if-statement.
Its goal is to add support of 'disabled property'
@@ -905,9 +905,37 @@
</vpe:if>
</vpe:tag>
<!-- End of JSF 2.0 Tags -->
+
+ <!-- Jsf 2.0 composite tags -->
+ <vpe:tag name="composite:implementation"
case-sensitive="yes">
+ <vpe:if test="tld_version('min=2.0')">
+ <vpe:template children="yes" modify="yes"
+ class="org.jboss.tools.jsf.vpe.facelets.template.VpeCompositionTemplate"
+ namespaceIdentifier="org.jboss.tools.jsf.vpe.facelets">
+ </vpe:template>
+ </vpe:if>
+ </vpe:tag>
+ <vpe:tag name="composite:interface" case-sensitive="yes">
+ <vpe:if test="tld_version('min=2.0')">
+ <vpe:template children="yes" modify="no"/>
+ </vpe:if>
+ </vpe:tag>
+
+ <vpe:tag name="composite:actionSource" case-sensitive="yes">
+ <vpe:if test="tld_version('min=2.0')">
+ <vpe:template children="no" modify="no"/>
+ </vpe:if>
+ </vpe:tag>
+
+ <vpe:tag name="vpejsf2customTemplate" case-sensitive="yes">
+ <vpe:template children="yes" modify="yes"
+ class="org.jboss.tools.jsf.vpe.jsf.template.Jsf2CustomComponentTemplate">
+ </vpe:template>
+ </vpe:tag>
<!-- Default template -->
<vpe:template children="yes" modify="no">
<vpe:any value="{name()}" title="{tagstring()}"/>
</vpe:template>
-</vpe:templates>
\ No newline at end of file
+
+</vpe:templates>
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/WEB-INF/lib/jbide2550.jar
===================================================================
(Binary files differ)
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5015/login.xhtml
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5015/login.xhtml
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5015/login.xhtml 2009-10-15
14:02:14 UTC (rev 18109)
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ez="http://java.sun.com/jsf/composite/ezcomp"
+
xmlns:jar="http://java.sun.com/jsf/composite/jarPage">
+<h:head>
+ <title>A simple example of EZComp</title>
+</h:head>
+<h:body>
+ <h:form id="jbide5015">
+ <jar:echo echo="Hello, Custom Jsf 2.O Components" />
+ <ez:loginPanel id="loginPanel">
+ <f:actionListener for="loginEvent"
+ binding="#{bean.loginEventListener}" />
+ </ez:loginPanel>
+ </h:form>
+</h:body>
+</html>
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5015/login.xhtml.xml
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5015/login.xhtml.xml
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsf2test/WebContent/pages/JBIDE/5015/login.xhtml.xml 2009-10-15
14:02:14 UTC (rev 18109)
@@ -0,0 +1,56 @@
+<tests>
+<test id="jbide5015">
+<FORM STYLE="border: 1px dotted rgb(255, 102, 0); padding: 5px;" >
+<DIV VPE:INCLUDE-ELEMENT="yes" STYLE="-moz-user-modify:
read-only;" >
+<DIV STYLE="-moz-user-modify: read-only;">
+<DIV STYLE="display: none; -moz-user-modify: read-only;">
+<H1 STYLE="-moz-user-modify: read-only;">
+Not present in rendered output
+</H1>
+</DIV>
+<DIV STYLE="-moz-user-modify: read-only;"><BR
VPE:PSEUDO-ELEMENT="yes" STYLE="font-style: italic; color: green;
-moz-user-modify: read-only;"/>
+
+<DIV VPE:INCLUDE-ELEMENT="yes" STYLE="-moz-user-modify:
read-only;">
+<H1 STYLE="-moz-user-modify: read-only;">
+<SPAN CLASS="vpe-text" STYLE="-moz-user-modify: read-only;">
+Hello, Custom Jsf 2.O Components
+</SPAN>
+</H1>
+</DIV>
+</DIV>
+</DIV>
+</DIV>
+<DIV VPE:INCLUDE-ELEMENT="yes" STYLE="-moz-user-modify:
read-only;">
+<DIV STYLE="-moz-user-modify: read-only;">
+<DIV STYLE="display: none; -moz-user-modify: read-only;">
+<H1 STYLE="-moz-user-modify: read-only;">
+Not present in rendered output
+</H1>
+</DIV>
+<DIV STYLE="-moz-user-modify: read-only;">
+<DIV VPE:INCLUDE-ELEMENT="yes" STYLE="-moz-user-modify:
read-only;">
+<P STYLE="-moz-user-modify: read-only;">
+<SPAN CLASS="vpe-text" STYLE="-moz-user-modify: read-only;">
+Username:
+</SPAN>
+<INPUT STYLE="-moz-user-modify: read-only;"/>
+
+</P>
+<P STYLE="-moz-user-modify: read-only;">
+<SPAN CLASS="vpe-text" STYLE="-moz-user-modify: read-only;">
+Password:
+</SPAN>
+<INPUT TYPE="password" STYLE="-moz-user-modify: read-only;"/>
+
+</P>
+<P STYLE="-moz-user-modify: read-only;">
+<INPUT TYPE="button" VALUE="login" STYLE="-moz-user-modify:
read-only;"/>
+
+</P>
+</DIV>
+</DIV>
+</DIV>
+</DIV>
+</FORM>
+</test>
+</tests>
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2550Test.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2550Test.java 2009-10-15
14:01:19 UTC (rev 18108)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2550Test.java 2009-10-15
14:02:14 UTC (rev 18109)
@@ -31,6 +31,9 @@
performContentTest("JBIDE/4954/inputUserName.jsp"); //$NON-NLS-1$
}
+ public void testForJSF2CustomTags() throws Throwable{
+ performContentTest("JBIDE/5015/login.xhtml"); //$NON-NLS-1$
+ }
@Override
protected String getTestProjectName() {
return JsfAllTests.IMPORT_JSF_20_PROJECT_NAME;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCustomTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCustomTemplate.java 2009-10-15
14:01:19 UTC (rev 18108)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCustomTemplate.java 2009-10-15
14:02:14 UTC (rev 18109)
@@ -45,9 +45,8 @@
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
- IStorage sourceFileStorage = CustomTLDReference
- .getCustomElementPath(sourceNode, pageContext);
-
+ IStorage sourceFileStorage = getCustomTemplateStorage(pageContext, sourceNode);
+
if (sourceFileStorage instanceof IFile) {
//add attributes to EL list
IFile file =(IFile) sourceFileStorage;
@@ -157,4 +156,14 @@
offset+=sourceNode.getPrefix().length()+1+1;
return new Region(offset, 0);
}
+ /**
+ * Culculate and returns storage to custom file
+ * @author mareshkau
+ * @param pageContext
+ * @param sourceNode
+ * @return
+ */
+ protected IStorage getCustomTemplateStorage(VpePageContext pageContext, Node
sourceNode){
+ return CustomTLDReference.getCustomElementStorage(sourceNode, pageContext);
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java 2009-10-15
14:01:19 UTC (rev 18108)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java 2009-10-15
14:02:14 UTC (rev 18109)
@@ -270,6 +270,8 @@
//mareshkau, contains a name of custom template
private static final String CUSTOM_TEMPLATE_NAME="vpeCustomTemplate";
//$NON-NLS-1$
+ private static final String JSF2_CUSTOM_TEMPLATE="vpejsf2customTemplate";
//$NON-NLS-1$
+
/**
* added by Max Areshkau, JBIDE-1494
* Contains default text formating data
@@ -393,9 +395,14 @@
return templateTaglibPrefix + ":" + sourceNode.getLocalName();
//$NON-NLS-1$
}
- if(sourceNodeUri!=null &&
CustomTLDReference.isExistInCustomTlds(pageContext,sourceNodeUri)){
+ if(sourceNodeUri!=null
+ && CustomTLDReference.isExistInCustomTlds(pageContext,sourceNodeUri)) {
return VpeTemplateManager.CUSTOM_TEMPLATE_NAME;
}
+ if(sourceNodeUri!=null
+ &&CustomTLDReference.isExistInJsf2CustomComponenets(pageContext,sourceNodeUri,sourceNode.getLocalName())
) {
+ return VpeTemplateManager.JSF2_CUSTOM_TEMPLATE;
+ }
return null;
default :
return null;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDReference.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDReference.java 2009-10-15
14:01:19 UTC (rev 18108)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDReference.java 2009-10-15
14:02:14 UTC (rev 18109)
@@ -10,7 +10,11 @@
******************************************************************************/
package org.jboss.tools.vpe.editor.template.custom;
-
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -28,7 +32,9 @@
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.jst.web.project.WebProject;
import org.jboss.tools.jst.web.tld.TaglibData;
+import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.util.FileUtil;
import org.jboss.tools.vpe.editor.util.XmlUtil;
import org.w3c.dom.Node;
@@ -40,6 +46,8 @@
*/
public class CustomTLDReference {
+ private static final String JSF2_CUSTOM_COMPONENT_URI =
"http://java.sun.com/jsf/composite/"; //$NON-NLS-1$
+
/**
* Returns absolute path to custom template file, if such exist or null
* otherwise
@@ -47,17 +55,17 @@
* @param sourceNode
* @return full path to custom template if exist or null if not exist
*/
- public static IStorage getCustomElementPath(Node sourceNode,
+ public static IStorage getCustomElementStorage(Node sourceNode,
VpePageContext pageContext) {
List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,
pageContext);
TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourceNode
.getPrefix(), taglibs);
String uri = sourceNodeTaglib.getUri();
- XModelObject xmodel = getCustomTaglibObject(pageContext,uri);
+ XModelObject xmodel = getCustomTaglibObject(pageContext, uri);
XModelObject o = xmodel.getChildByPath(sourceNode.getLocalName()
- +XModelObjectConstants.SEPARATOR +"declaration"); //$NON-NLS-1$
+ + XModelObjectConstants.SEPARATOR + "declaration"); //$NON-NLS-1$
String sourceAttributeValue = null;
if (o != null) {
sourceAttributeValue = o.getAttributeValue("source"); //$NON-NLS-1$
@@ -68,14 +76,18 @@
}
if (xmodel instanceof SimpleFileImpl) {
IFile iFile = ((SimpleFileImpl) xmodel).getFile();
- if(iFile==null) {
- //possibly it's a jar file
+ if (iFile == null) {
+ // possibly it's a jar file
- XModelObject sourceFile =
xmodel.getParent().getParent().getChildByPath(sourceAttributeValue.substring(1));
- if(sourceFile instanceof RecognizedFileImpl) {
- String content = ((RecognizedFileImpl)sourceFile).getAsText();
- String name =((RecognizedFileImpl)sourceFile).getPresentationString();
- IStorage customStorage = new VpeCustomStringStorage(content, name);
+ XModelObject sourceFile = xmodel.getParent().getParent()
+ .getChildByPath(sourceAttributeValue.substring(1));
+ if (sourceFile instanceof RecognizedFileImpl) {
+ String content = ((RecognizedFileImpl) sourceFile)
+ .getAsText();
+ String name = ((RecognizedFileImpl) sourceFile)
+ .getPresentationString();
+ IStorage customStorage = new VpeCustomStringStorage(
+ content, name);
return customStorage;
}
return null;
@@ -94,8 +106,104 @@
}
/**
+ * Checks is resource exist in custom jsf 2 tags
*
+ * @author mareshkau
* @param pageContext
+ * @param sourceNodeUri
+ * @param sourceNodeName
+ * @return
+ */
+
+ public static boolean isExistInJsf2CustomComponenets(
+ VpePageContext pageContext, String sourceNodeUri,
+ String sourceNodeName) {
+ boolean result = false;
+ // check uri if it jsf 2.0 URI
+ sourceNodeUri = sourceNodeUri.trim();
+ if (sourceNodeUri != null
+ && sourceNodeUri.startsWith(JSF2_CUSTOM_COMPONENT_URI)) {
+ // calculating resource path string
+ String jsfComponentResourcePath = sourceNodeUri.substring(
+ JSF2_CUSTOM_COMPONENT_URI.length(), sourceNodeUri.length());
+ String fileName = pageContext.getEditPart().getEditorInput()
+ .getName();
+ String jsfComponentExtension = ".xhtml"; //$NON-NLS-1$
+ if (fileName != null && fileName.lastIndexOf('.') != -1) {
+ String fileExtension = fileName.substring(fileName
+ .lastIndexOf('.'), fileName.length());
+ if (fileExtension != null && fileExtension.length() > 0) {
+ jsfComponentExtension = fileExtension;
+ }
+ jsfComponentResourcePath = jsfComponentResourcePath + '/'
+ + sourceNodeName + jsfComponentExtension;
+ result = FileUtil.isExistsInJSF2Resources(pageContext,
+ jsfComponentResourcePath);
+ }
+
+ }
+ return result;
+ }
+
+ public static IStorage getJsf2CustomComponentStorage(VpePageContext pageContext, String
sourceNodeUri, String sourceNodeName){
+ IStorage result=null;
+ //check uri if it jsf 2.0 URI
+ sourceNodeUri = sourceNodeUri.trim();
+ if(sourceNodeUri!=null && sourceNodeUri.startsWith(JSF2_CUSTOM_COMPONENT_URI))
{
+ //calculating resource path string
+ String jsfComponentResourcePath =
sourceNodeUri.substring(JSF2_CUSTOM_COMPONENT_URI.length(),sourceNodeUri.length());
+ String fileName = pageContext.getEditPart().getEditorInput().getName();
+ String jsfComponentExtension = ".xhtml"; //$NON-NLS-1$
+ if(fileName!=null && fileName.lastIndexOf('.')!=-1){
+ String fileExtension =
fileName.substring(fileName.lastIndexOf('.'),fileName.length());
+ if(fileExtension!=null && fileExtension.length()>0) {
+ jsfComponentExtension = fileExtension;
+ }
+ jsfComponentResourcePath=jsfComponentResourcePath+'/'+sourceNodeName+jsfComponentExtension;
+ String fullResourcePath = FileUtil.processJSF2Resource(pageContext,
jsfComponentResourcePath);
+ result = FileUtil.getFile(pageContext.getEditPart().getEditorInput(),
fullResourcePath);
+ if(result!=null) {
+ return result;
+ }
+ File fileToOpen = new File(fullResourcePath);
+ if (fileToOpen.exists() && fileToOpen.isFile()) {
+ StringBuffer fileContent = new StringBuffer();
+ try {
+ BufferedReader input = new BufferedReader(new FileReader(fileToOpen));
+ try {
+ String line = null; //not declared within while loop
+ /*
+ * readLine is a bit quirky :
+ * it returns the content of a line MINUS the newline.
+ * it returns null only for the END of the stream.
+ * it returns an empty String if two newlines appear in a row.
+ */
+ while (( line = input.readLine()) != null){
+ fileContent.append(line);
+
+ }
+
+ } catch (IOException e) {
+ VpePlugin.reportProblem(e);
+ }finally {
+ input.close();
+ }
+
+ } catch (FileNotFoundException e) {
+ VpePlugin.reportProblem(e);
+ }catch (IOException e) {
+ VpePlugin.reportProblem(e);
+ }
+ result = new VpeCustomStringStorage(fileContent.toString(), fileToOpen.getName());
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @param pageContext
* @param uri
* node namespace uri
* @return true if such template defined in facelets lib or falce if not
@@ -103,7 +211,7 @@
*/
public static boolean isExistInCustomTlds(VpePageContext pageContext,
String uri) {
- return getCustomTaglibObject(pageContext,uri)!=null?true:false;
+ return getCustomTaglibObject(pageContext, uri) != null ? true : false;
}
/**
@@ -124,7 +232,8 @@
xm = mn.getModel();
}
if (xm != null) {
- return WebProject.getInstance(xm).getTaglibMapping().getTaglibObject(uri);
+ return WebProject.getInstance(xm).getTaglibMapping()
+ .getTaglibObject(uri);
}
}
return null;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionSrc.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionSrc.java 2009-10-15
14:01:19 UTC (rev 18108)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionSrc.java 2009-10-15
14:02:14 UTC (rev 18109)
@@ -53,6 +53,7 @@
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.VpeCreatorUtil;
import org.jboss.tools.vpe.editor.util.ElService;
+import org.jboss.tools.vpe.editor.util.FileUtil;
import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
import org.w3c.dom.Node;
@@ -272,9 +273,9 @@
Matcher singleCoatMatcher =
resourcePatternWithSinglCoat.matcher(resolvedValue);
Matcher doubleCoatMatcher =
resourcePatternWithDoableCoat.matcher(resolvedValue);
if(doubleCoatMatcher.find()) {
- resolvedValue = processJSF2Resource(pageContext, doubleCoatMatcher);
+ resolvedValue = FileUtil.processJSF2Resource(pageContext,
doubleCoatMatcher.group(1));
}else if(singleCoatMatcher.find()){
- resolvedValue = processJSF2Resource(pageContext, singleCoatMatcher);
+ resolvedValue = FileUtil.processJSF2Resource(pageContext,
singleCoatMatcher.group(1));
}
//Fix for JBIDE-3030
@@ -287,85 +288,6 @@
resolvedValue = ElService.getInstance().replaceEl(file, resolvedValue);
return resolvedValue;
}
- /**
- * See JBIDE-2550
- * @param matcher
- * @return
- */
- private static final String processJSF2Resource(VpePageContext pageContext, Matcher
matcher){
- String resulString = matcher.group(1);
- resulString=resulString.replaceAll(":", "/");
//$NON-NLS-1$//$NON-NLS-2$
- resulString = "/resources/"+resulString; //$NON-NLS-1$
- // if file not accessible and try to search in jar files
- if(VpeCreatorUtil.getFile(resulString, pageContext)==null) {
- String tempEntryPath =seachResourceInClassPath(pageContext,
"META-INF"+resulString); //$NON-NLS-1$
- if(tempEntryPath!=null) {
- resulString = tempEntryPath;
- }
- }
- return resulString;
- }
- /**
- * Function search into project class path resource, if resource founded in jar file,
make a
- * temp copy of this resource and return path to copy.
- * @author mareshkau
- * @param pageContext
- * @param classPathResource
- * @return
- */
- private static String seachResourceInClassPath(VpePageContext pageContext, String
classPathResource) {
- String result = null;
- final IFile currentFile = (IFile)
pageContext.getVisualBuilder().getCurrentIncludeInfo().getStorage();
- final IProject project = currentFile.getProject();
- IJavaProject javaProject = JavaCore.create(project);
- try {
- for (IPackageFragmentRoot fragmentRoot : javaProject.getAllPackageFragmentRoots()) {
- if(fragmentRoot instanceof JarPackageFragmentRoot) {
- JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot)
fragmentRoot;
- ZipEntry zipEntry = jarPackageFragmentRoot.getJar().getEntry(classPathResource);
- if(zipEntry!=null){
- InputStream inputStream =
jarPackageFragmentRoot.getJar().getInputStream(zipEntry);
- IPath stateLocation = VpePlugin.getDefault().getStateLocation();
-
- String fileName = null;
- String fileExtension = null;
- if(classPathResource.lastIndexOf(".")!=-1) { //$NON-NLS-1$ //added by
mareshkau, fix for JBIDE-4954
- fileName =
classPathResource.substring(classPathResource.lastIndexOf("/")+1,classPathResource.lastIndexOf("."));
//$NON-NLS-1$ //$NON-NLS-2$
- fileExtension =
classPathResource.substring(classPathResource.lastIndexOf("."),classPathResource.length());
//$NON-NLS-1$
- }
- if(fileName!=null && fileName.length()>0
- && fileExtension!=null && fileExtension.length()>0) {
- File temporaryFile =File.createTempFile(
- fileName,
- fileExtension,
- new File(stateLocation.toOSString()));
- temporaryFile.deleteOnExit();
- OutputStream out = new FileOutputStream(temporaryFile,false);
- byte[] buf = new byte[1024];
- int len;
- while ((len = inputStream.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- inputStream.close();
- out.close();
- result = IMG_PREFIX + temporaryFile.getAbsolutePath();
- }
- }
- }
- }
- } catch (JavaModelException e) {
- VpePlugin.reportProblem(e);
- } catch (IllegalStateException e) {
- VpePlugin.reportProblem(e);
- } catch (FileNotFoundException e) {
- VpePlugin.reportProblem(e);
- } catch (CoreException e) {
- VpePlugin.reportProblem(e);
- } catch (IOException e) {
- VpePlugin.reportProblem(e);
- }
- return result;
- }
public static String getAbsoluteResourcePath(String resourcePathInPlugin) {
String pluginPath = VpePlugin.getPluginResourcePath();
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FileUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FileUtil.java 2009-10-15
14:01:19 UTC (rev 18108)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FileUtil.java 2009-10-15
14:02:14 UTC (rev 18109)
@@ -11,14 +11,26 @@
package org.jboss.tools.vpe.editor.util;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.ZipEntry;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
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.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPage;
@@ -34,12 +46,110 @@
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.resref.core.ResourceReference;
import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.VpeCreatorUtil;
import org.jboss.tools.vpe.resref.core.AbsoluteFolderReferenceList;
import org.jboss.tools.vpe.resref.core.RelativeFolderReferenceList;
public class FileUtil {
+ private static final String JSF2_RESOURCES = "/resources/"; //$NON-NLS-1$
+ /**
+ * See JBIDE-2550
+ * @author mareshkau
+ * @param matcher
+ * @return
+ */
+ public static final String processJSF2Resource(VpePageContext pageContext, String
resStr){
+ String resulString = resStr;
+ resulString=resulString.replaceAll(":", "/");
//$NON-NLS-1$//$NON-NLS-2$
+ resulString = "/resources/"+resulString; //$NON-NLS-1$
+ // if file not accessible and try to search in jar files
+ if(VpeCreatorUtil.getFile(resulString, pageContext)==null) {
+ String tempEntryPath =seachResourceInClassPath(pageContext,
"META-INF"+resulString); //$NON-NLS-1$
+ if(tempEntryPath!=null) {
+ resulString = tempEntryPath;
+ }
+ }
+ return resulString;
+ }
+
+ public static boolean isExistsInJSF2Resources(VpePageContext pageContext, String
resStr) {
+ String resourceString = resStr;
+ resourceString = resourceString.replaceAll(":", "/");
//$NON-NLS-1$//$NON-NLS-2$
+ resourceString = "/resources/"+resourceString; //$NON-NLS-1$
+ if(FileUtil.getFile(pageContext.getEditPart().getEditorInput(),
resourceString)!=null ||
+ seachResourceInClassPath(pageContext, "META-INF"+resourceString)!=null)
{
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Function search into project class path resource, if resource founded in jar file,
make a
+ * temp copy of this resource and return path to copy.
+ * @author mareshkau
+ * @param pageContext
+ * @param classPathResource
+ * @return path to file
+ */
+ private static String seachResourceInClassPath(VpePageContext pageContext, String
classPathResource) {
+ String result = null;
+ final IFile currentFile = (IFile)
pageContext.getVisualBuilder().getCurrentIncludeInfo().getStorage();
+ final IProject project = currentFile.getProject();
+ IJavaProject javaProject = JavaCore.create(project);
+ try {
+ for (IPackageFragmentRoot fragmentRoot : javaProject.getAllPackageFragmentRoots()) {
+ if(fragmentRoot instanceof JarPackageFragmentRoot) {
+ JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot)
fragmentRoot;
+ ZipEntry zipEntry = jarPackageFragmentRoot.getJar().getEntry(classPathResource);
+ if(zipEntry!=null){
+ InputStream inputStream =
jarPackageFragmentRoot.getJar().getInputStream(zipEntry);
+ IPath stateLocation = VpePlugin.getDefault().getStateLocation();
+
+ String fileName = null;
+ String fileExtension = null;
+ if(classPathResource.lastIndexOf(".")!=-1) { //$NON-NLS-1$ //added by
mareshkau, fix for JBIDE-4954
+ fileName =
classPathResource.substring(classPathResource.lastIndexOf("/")+1,classPathResource.lastIndexOf("."));
//$NON-NLS-1$ //$NON-NLS-2$
+ fileExtension =
classPathResource.substring(classPathResource.lastIndexOf("."),classPathResource.length());
//$NON-NLS-1$
+ }
+ if(fileName!=null && fileName.length()>0
+ && fileExtension!=null && fileExtension.length()>0) {
+ File temporaryFile =File.createTempFile(
+ fileName,
+ fileExtension,
+ new File(stateLocation.toOSString()));
+ temporaryFile.deleteOnExit();
+ OutputStream out = new FileOutputStream(temporaryFile,false);
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = inputStream.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ inputStream.close();
+ out.close();
+ result = temporaryFile.getAbsolutePath();
+ }
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ VpePlugin.reportProblem(e);
+ } catch (IllegalStateException e) {
+ VpePlugin.reportProblem(e);
+ } catch (FileNotFoundException e) {
+ VpePlugin.reportProblem(e);
+ } catch (CoreException e) {
+ VpePlugin.reportProblem(e);
+ } catch (IOException e) {
+ VpePlugin.reportProblem(e);
+ }
+ return result;
+ }
+
+
+
public static IFile getFile(IEditorInput input, String value) {
IPath tagPath = new Path(value);
if (tagPath.isEmpty()) return null;