Author: dmaliarevich
Date: 2012-02-08 08:42:35 -0500 (Wed, 08 Feb 2012)
New Revision: 38498
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionHref.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionJsf2Resource.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
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/Jsf2ResourceUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-10819 - Method FileUtil.getJSF2ResourcePath(..) was
updated to return the real "resources" folder path.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionHref.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionHref.java 2012-02-08
13:34:47 UTC (rev 38497)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionHref.java 2012-02-08
13:42:35 UTC (rev 38498)
@@ -55,7 +55,7 @@
File locFile = tagPath.toFile();
if (locFile.exists()) {
- return new VpeValue(getPrefix() + locFile.getAbsolutePath());
+ return new VpeValue(getPrefix() + tagPath.toString());
}
IEditorInput input = pageContext.getEditPart().getEditorInput();
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionJsf2Resource.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionJsf2Resource.java 2012-02-08
13:34:47 UTC (rev 38497)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionJsf2Resource.java 2012-02-08
13:42:35 UTC (rev 38498)
@@ -33,10 +33,7 @@
if ("".equals(library)) { //$NON-NLS-1$
library = null;
}
-
String name = getParameter(1).exec(pageContext, sourceNode).stringValue();
-
- String resourcePath = FileUtil.getJSF2ResourcePath(pageContext, library, name);
- return new VpeValue(resourcePath);
+ return new VpeValue(FileUtil.getJSF2ResourcePath(pageContext, library, name));
}
}
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 2012-02-08
13:34:47 UTC (rev 38497)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionSrc.java 2012-02-08
13:42:35 UTC (rev 38498)
@@ -44,102 +44,88 @@
public class VpeFunctionSrc extends VpeFunction {
static final String IMG_UNRESOLVED = "unresolved_image.gif"; //$NON-NLS-1$
static final String IMG_PREFIX = "file:///"; //$NON-NLS-1$
-// private static final Pattern resourcePatternWithSinglCoat=
Pattern.compile("[#\\$]\\{\\s*resource\\s*\\[\\s*'(.*)'\\s*\\]\\s*\\}");
//$NON-NLS-1$
-// private static final Pattern resourcePatternWithDoableCoat=
Pattern.compile("[#\\$]\\{\\s*resource\\s*\\[\\s*\"(.*)\"\\s*\\]\\s*\\}");
//$NON-NLS-1$
-
public VpeValue exec(VpePageContext pageContext, Node sourceNode) throws
VpeExpressionException {
- String tagValue = getParameter(0).exec(pageContext, sourceNode)
- .stringValue();
-// tagValue = resolveEL(pageContext,tagValue);
- IFile iFile = VpeCreatorUtil.getFile(tagValue, pageContext);
-
- if (iFile != null) {
- return new VpeValue(getPrefix()+iFile.getLocation().toString());
- }
- tagValue = processValue(pageContext, sourceNode, tagValue);
-
- // decode string from utf
- try {
- tagValue = URLDecoder.decode(tagValue, "UTF-8"); //$NON-NLS-1$
- } catch (UnsupportedEncodingException e) {
-
- VpePlugin.getPluginLog().logError(e);
- } catch (IllegalArgumentException ex) {
- //if user enter invalid URL, for example " % sss",
- //illegal argument exception will be throwed,
- //brouser will not processed this url, so we just slow this exeption
- //You can check it's by inserting next code
- //<h:graphicImage value=" %=
request.getContextPath()%/images/logos/banner.png"/>
- tagValue=""; //$NON-NLS-1$
- }
-
- IPath tagPath = new Path(tagValue);
- if (tagPath.isEmpty())
- return new VpeValue(getUnresolved());
-
- String device = (tagPath.getDevice() == null ? tagPath.segment(0)
- : tagPath.getDevice());
- if (device != null
- && ("http:".equalsIgnoreCase(device) //$NON-NLS-1$
- || "file:".equalsIgnoreCase(device))) //$NON-NLS-1$
- return new VpeValue(tagValue);
-
- File locFile = tagPath.toFile();
- if (locFile.exists())
- return new VpeValue(getPrefix() + locFile.getAbsolutePath());
-
- IEditorInput input = pageContext.getEditPart().getEditorInput();
- IPath inputPath = getInputParentPath(input);
- IPath imgPath = null;
- if (input instanceof ILocationProvider) {
- imgPath = inputPath.append(tagValue);
- } else {
- IPath basePath = tagPath.isAbsolute() ? VpeStyleUtil.getRootPath(input)
- : inputPath;
- if (basePath != null) {
- imgPath = basePath.append(tagPath);
- }
- }
-
- if (imgPath != null && imgPath.toFile().exists()) {
- return new VpeValue(getPrefix() + imgPath.toString());
- } else {
- IFile file = null;
- if (input instanceof IFileEditorInput) {
- file = ((IFileEditorInput) input).getFile();
- }
-
- if (null != file) {
- ResourceReference resourceReference = null;
- if ("/".equals(tagValue.substring(0, 1))) { //$NON-NLS-1$
- resourceReference = pageContext
- .getRuntimeAbsoluteFolder(file);
- tagValue = tagValue.substring(1);
- } else {
- resourceReference = pageContext
- .getRuntimeRelativeFolder(file);
- }
-
- String location = null;
- if (resourceReference != null) {
- location = resourceReference.getLocation();
- }
-
- if (null == location && null != file.getLocation()) {
- location = file.getLocation().toFile().getParent();
- }
-
- if (null != location) {
- File f = new File(location + File.separator + tagValue);
- if (f.exists()) {
- return new VpeValue(getPrefix() + f.getPath());
- }
- }
- }
- }
-
- return new VpeValue(getUnresolved());
+ String tagValue = getParameter(0).exec(pageContext, sourceNode).stringValue();
+ // tagValue = resolveEL(pageContext,tagValue);
+ IFile iFile = VpeCreatorUtil.getFile(tagValue, pageContext);
+ if (iFile != null) {
+ return new VpeValue(getPrefix()+iFile.getLocation().toString());
+ }
+ tagValue = processValue(pageContext, sourceNode, tagValue);
+ // decode string from utf
+ try {
+ tagValue = URLDecoder.decode(tagValue, "UTF-8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ VpePlugin.getPluginLog().logError(e);
+ } catch (IllegalArgumentException ex) {
+ //if user enter invalid URL, for example " % sss",
+ //illegal argument exception will be throwed,
+ //brouser will not processed this url, so we just slow this exeption
+ //You can check it's by inserting next code
+ //<h:graphicImage value=" %=
request.getContextPath()%/images/logos/banner.png"/>
+ tagValue=""; //$NON-NLS-1$
+ }
+ IPath tagPath = new Path(tagValue);
+ if (tagPath.isEmpty()) {
+ return new VpeValue(getUnresolved());
+ }
+ String device = (tagPath.getDevice() == null ? tagPath.segment(0)
+ : tagPath.getDevice());
+ if (device != null
+ && ("http:".equalsIgnoreCase(device) //$NON-NLS-1$
+ || "file:".equalsIgnoreCase(device))) { //$NON-NLS-1$
+ return new VpeValue(tagValue);
+ }
+ File locFile = tagPath.toFile();
+ if (locFile.exists()) {
+ return new VpeValue(getPrefix() + tagPath.toString());
+ }
+ IEditorInput input = pageContext.getEditPart().getEditorInput();
+ IPath inputPath = getInputParentPath(input);
+ IPath imgPath = null;
+ if (input instanceof ILocationProvider) {
+ imgPath = inputPath.append(tagValue);
+ } else {
+ IPath basePath = tagPath.isAbsolute()
+ ? VpeStyleUtil.getRootPath(input) : inputPath;
+ if (basePath != null) {
+ imgPath = basePath.append(tagPath);
+ }
+ }
+ if (imgPath != null && imgPath.toFile().exists()) {
+ return new VpeValue(getPrefix() + imgPath.toString());
+ } else {
+ IFile file = null;
+ if (input instanceof IFileEditorInput) {
+ file = ((IFileEditorInput) input).getFile();
+ }
+ if (null != file) {
+ ResourceReference resourceReference = null;
+ if ("/".equals(tagValue.substring(0, 1))) { //$NON-NLS-1$
+ resourceReference = pageContext
+ .getRuntimeAbsoluteFolder(file);
+ tagValue = tagValue.substring(1);
+ } else {
+ resourceReference = pageContext
+ .getRuntimeRelativeFolder(file);
+ }
+ String location = null;
+ if (resourceReference != null) {
+ location = resourceReference.getLocation();
+ }
+ if (null == location && null != file.getLocation()) {
+ location = file.getLocation().toFile().getParent();
+ }
+ if (null != location) {
+ File f = new File(location + File.separator + tagValue);
+ if (f.exists()) {
+ return new VpeValue(getPrefix() + f.getPath());
+ }
+ }
+ }
+ }
+ return new VpeValue(getUnresolved());
}
protected IPath getInputParentPath(IEditorInput input) {
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 2012-02-08
13:34:47 UTC (rev 38497)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FileUtil.java 2012-02-08
13:42:35 UTC (rev 38498)
@@ -84,7 +84,7 @@
*/
public static final String getJSF2ResourcePath(VpePageContext pageContext,
String resourceStr) {
- if (resourceStr.contains(":")) { //$NON-NLS-1$
+ if (resourceStr.contains(":")) { //$NON-NLS-1$
String[] parts = resourceStr.split(":"); //$NON-NLS-1$
return getJSF2ResourcePath(pageContext, parts[0], parts[1]);
} else {
@@ -94,43 +94,41 @@
/**
* Returns the path to the resource specified by the {@code library}
- * and the {@code name}.
- *
- * See JBIDE-5638
- *
+ * and the {@code name}. See JBIDE-5638
* @param library may be {@code null}
- *
* @author mareshkau
* @author yradtsevich
- *
* @see <a
href="http://java.sun.com/javaee/javaserverfaces/2.0/docs/api/javax/...
*/
public static final String getJSF2ResourcePath(VpePageContext pageContext,
String library, String name) {
- String tempString = library == null ? name
- : library + '/' + name;
-
- tempString = FileUtil.JSF2_RESOURCES + tempString;
+ String tempPath = (library == null ? name : library + '/' + name);
+ tempPath = FileUtil.JSF2_RESOURCES + tempPath;
String result = ""; //$NON-NLS-1$
// if file not accessible and try to search in jar files
- if(VpeCreatorUtil.getFile(tempString, pageContext)==null) {
- String tempEntryPath =seachResourceInClassPath(pageContext,
- "META-INF" + tempString); //$NON-NLS-1$
- if(tempEntryPath!=null) {
- result = tempEntryPath;
- }
- } else {
- result = tempString;
- }
+ IFile file = VpeCreatorUtil.getFile(tempPath, pageContext);
+ if (file == null) {
+ String tempEntryPath = seachResourceInClassPath(pageContext,
+ "META-INF" + tempPath); //$NON-NLS-1$
+ if (tempEntryPath != null) {
+ result = tempEntryPath;
+ }
+ } else {
+ /*
+ *
https://issues.jboss.org/browse/JBIDE-10819
+ * The result path should be taken from the found file.
+ */
+ result = file.getLocation().toString();
+ }
return result;
- }
+ }
public static boolean isExistsInJSF2Resources(VpePageContext pageContext, String
resStr) {
String resourceString = resStr;
resourceString = resourceString.replaceAll(":", "/");
//$NON-NLS-1$//$NON-NLS-2$
resourceString = FileUtil.JSF2_RESOURCES+resourceString;
if(FileUtil.getFile(pageContext.getEditPart().getEditorInput(),
resourceString)!=null ||
- FileUtil.seachResourceInClassPath(pageContext,
"META-INF"+resourceString)!=null) {
+ FileUtil.seachResourceInClassPath(pageContext,
"META-INF"+resourceString)!=null) { //$NON-NLS-1$
return true;
}
return false;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/Jsf2ResourceUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/Jsf2ResourceUtil.java 2012-02-08
13:34:47 UTC (rev 38497)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/Jsf2ResourceUtil.java 2012-02-08
13:42:35 UTC (rev 38498)
@@ -19,16 +19,16 @@
import org.w3c.dom.Node;
/**
- * Class created for processing jsf 2.0 resources, see following issues
- * JBIDE-2550, JBIDE-4812,
+ * Class created for processing jsf 2.0 resources,
+ * see following issues JBIDE-2550, JBIDE-4812
*
* @author mareshkau
*/
public class Jsf2ResourceUtil {
- private static final Pattern resourcePatternWithSinglCoat = Pattern
+ private static final Pattern resourcePatternWithSingleQuotes = Pattern
.compile("[#\\$]\\{\\s*resource\\s*\\[\\s*'(.*)'\\s*\\]\\s*\\}");
//$NON-NLS-1$
- private static final Pattern resourcePatternWithDoableCoat = Pattern
+ private static final Pattern resourcePatternWithDoableQuotes = Pattern
.compile("[#\\$]\\{\\s*resource\\s*\\[\\s*\"(.*)\"\\s*\\]\\s*\\}");
//$NON-NLS-1$
private static final Pattern jsfExternalContextPath = Pattern
.compile("^\\s*(\\#|\\$)\\{facesContext.externalContext.requestContextPath\\}");
//$NON-NLS-1$
@@ -80,8 +80,8 @@
* @author mareshkau, fix for
https://jira.jboss.org/jira/browse/JBIDE-5985
*/
public static boolean isExternalContextPathString(String attributeValue) {
- Matcher externalContextPathMatcher = jsfExternalContextPath
- .matcher(attributeValue);
+ Matcher externalContextPathMatcher =
+ jsfExternalContextPath.matcher(attributeValue);
boolean result = false;
if (externalContextPathMatcher.find()) {
result = true;
@@ -95,8 +95,8 @@
* @return true if string contains #{request.contextPath}
*/
public static boolean isRequestContextPathString(String attributeValue) {
- Matcher requestContextPathMatcher = jsfRequestContextPath
- .matcher(attributeValue);
+ Matcher requestContextPathMatcher =
+ jsfRequestContextPath.matcher(attributeValue);
return requestContextPathMatcher.find();
}
@@ -142,17 +142,15 @@
VpePageContext pageContext, String value) {
String result = null;
// fix for JBIDE-2550, author Maksim Areshkau
- Matcher singleCoatMatcher = resourcePatternWithSinglCoat.matcher(value);
- Matcher doubleCoatMatcher = resourcePatternWithDoableCoat
- .matcher(value);
- if (doubleCoatMatcher.find()) {
- result = FileUtil.getJSF2ResourcePath(pageContext,
- doubleCoatMatcher.group(1));
- } else if (singleCoatMatcher.find()) {
- result = FileUtil.getJSF2ResourcePath(pageContext,
- singleCoatMatcher.group(1));
+ Matcher singleQuotesMatcher =
+ resourcePatternWithSingleQuotes.matcher(value);
+ Matcher doubleQuotesMatcher =
+ resourcePatternWithDoableQuotes.matcher(value);
+ if (doubleQuotesMatcher.find()) {
+ result = FileUtil.getJSF2ResourcePath(pageContext, doubleQuotesMatcher.group(1));
+ } else if (singleQuotesMatcher.find()) {
+ result = FileUtil.getJSF2ResourcePath(pageContext, singleQuotesMatcher.group(1));
}
-
return result;
}
@@ -163,15 +161,14 @@
* @return
*/
public static boolean isJSF2ResourceString(String attributeValue) {
- Matcher singleCoatMatcher = resourcePatternWithSinglCoat
- .matcher(attributeValue);
- Matcher doubleCoatMatcher = resourcePatternWithDoableCoat
- .matcher(attributeValue);
- boolean result = false;
- if (doubleCoatMatcher.find() || singleCoatMatcher.find()) {
- result = true;
+ Matcher singleQuotesMatcher =
+ resourcePatternWithSingleQuotes.matcher(attributeValue);
+ Matcher doubleQuotesMatcher =
+ resourcePatternWithDoableQuotes.matcher(attributeValue);
+ if (doubleQuotesMatcher.find() || singleQuotesMatcher.find()) {
+ return true;
}
- return result;
+ return false;
}
/**