Author: dsakovich
Date: 2008-01-24 15:41:24 -0500 (Thu, 24 Jan 2008)
New Revision: 5955
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionSrc.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1686
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 2008-01-24
19:12:50 UTC (rev 5954)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionSrc.java 2008-01-24
20:41:24 UTC (rev 5955)
@@ -7,7 +7,7 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.editor.template.expression;
import java.io.File;
@@ -34,156 +34,183 @@
import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.css.ResourceReference;
+import org.jboss.tools.vpe.editor.template.VpeCreatorUtil;
import org.w3c.dom.Node;
public class VpeFunctionSrc extends VpeFunction {
static final String IMG_UNRESOLVED = "unresolved.gif";
static final String IMG_PREFIX = "file:///";
- public VpeValue exec(VpePageContext pageContext, Node sourceNode) {
- String tagValue = getParameter(0).exec(pageContext, sourceNode).stringValue();
- tagValue = processValue(pageContext, sourceNode, tagValue);
-
- // decode string from utf
- try {
- tagValue = URLDecoder.decode(tagValue,"UTF-8");
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ public VpeValue exec(VpePageContext pageContext, Node sourceNode) {
+ String tagValue = getParameter(0).exec(pageContext, sourceNode)
+ .stringValue();
+ 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");
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
- IPath tagPath = new Path(tagValue);
- if (tagPath.isEmpty()) return new VpeValue(getUnresolved());
+ 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) ||
"file:".equalsIgnoreCase(device))) return new VpeValue(tagValue);
+ String device = (tagPath.getDevice() == null ? tagPath.segment(0)
+ : tagPath.getDevice());
+ if (device != null
+ && ("http:".equalsIgnoreCase(device) || "file:"
+ .equalsIgnoreCase(device)))
+ return new VpeValue(tagValue);
- File locFile = tagPath.toFile();
- if (locFile.exists()) return new VpeValue(getPrefix() + locFile.getAbsolutePath());
+ 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);
+ 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() ? 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))) {
+ resourceReference = pageContext
+ .getRuntimeAbsoluteFolder(file);
+ tagValue = tagValue.substring(1);
} else {
- IPath basePath = tagPath.isAbsolute() ? getRootPath(input) : inputPath;
- if (basePath != null) {
- imgPath = basePath.append(tagPath);
- }
+ resourceReference = pageContext
+ .getRuntimeRelativeFolder(file);
}
- if (imgPath != null && imgPath.toFile().exists()) {
- return new VpeValue(getPrefix() + imgPath.toString());
- } else {
- IFile file = null;
- if (input instanceof IFileEditorInput) {
- file = ((IFileEditorInput)input).getFile();
- }
+ String location = null;
+ if (resourceReference != null) {
+ location = resourceReference.getLocation();
+ }
- if (null != file) {
- ResourceReference resourceReference = null;
- if ("/".equals(tagValue.substring(0, 1))) {
- resourceReference = pageContext.getRuntimeAbsoluteFolder(file);
- tagValue = tagValue.substring(1);
- } else {
- resourceReference = pageContext.getRuntimeRelativeFolder(file);
- }
+ if (null == location && null != file.getLocation()) {
+ location = file.getLocation().toFile().getParent();
+ }
- 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());
- }
- }
+ if (null != location) {
+ File f = new File(location + File.separator + tagValue);
+ if (f.exists()) {
+ return new VpeValue(getPrefix() + f.getPath());
}
}
+ }
+ }
+
+ return new VpeValue(getUnresolved());
+ }
- return new VpeValue(getUnresolved());
+ protected IPath getInputParentPath(IEditorInput input) {
+ IPath inputPath = null;
+ if (input instanceof ILocationProvider) {
+ inputPath = ((ILocationProvider) input).getPath(input);
+ } else if (input instanceof IFileEditorInput) {
+ IFile inputFile = ((IFileEditorInput) input).getFile();
+ if (inputFile != null) {
+ inputPath = inputFile.getLocation();
+ }
}
+ if (inputPath != null && !inputPath.isEmpty()) {
+ inputPath = inputPath.removeLastSegments(1);
+ }
+ return inputPath;
+ }
- protected IPath getInputParentPath(IEditorInput input) {
- IPath inputPath = null;
- if (input instanceof ILocationProvider) {
- inputPath = ((ILocationProvider)input).getPath(input);
- } else if (input instanceof IFileEditorInput) {
- IFile inputFile = ((IFileEditorInput)input).getFile();
- if (inputFile != null) {
- inputPath = inputFile.getLocation();
+ protected IPath getRootPath(IEditorInput input) {
+ IPath rootPath = null;
+ if (input instanceof IFileEditorInput) {
+ IProject project = ((IFileEditorInput) input).getFile()
+ .getProject();
+ if (project != null && project.isOpen()) {
+ IModelNature modelNature = EclipseResourceUtil
+ .getModelNature(project);
+ if (modelNature != null) {
+ XModel model = modelNature.getModel();
+ String rootPathStr = WebProject.getInstance(model)
+ .getWebRootLocation();
+ if (rootPathStr != null) {
+ rootPath = new Path(rootPathStr);
+ } else {
+ rootPath = project.getLocation();
}
+ } else {
+ rootPath = project.getLocation();
}
- if (inputPath != null && !inputPath.isEmpty()) {
- inputPath = inputPath.removeLastSegments(1);
- }
- return inputPath;
+ }
}
-
- protected IPath getRootPath(IEditorInput input) {
- IPath rootPath = null;
- if (input instanceof IFileEditorInput) {
- IProject project = ((IFileEditorInput)input).getFile().getProject();
- if(project != null && project.isOpen()) {
- IModelNature modelNature = EclipseResourceUtil.getModelNature(project);
- if (modelNature != null) {
- XModel model = modelNature.getModel();
- String rootPathStr = WebProject.getInstance(model).getWebRootLocation();
- if(rootPathStr!=null) {
- rootPath = new Path(rootPathStr);
- } else {
- rootPath = project.getLocation();
- }
- } else {
- rootPath = project.getLocation();
- }
- }
- }
- return rootPath;
- }
+ return rootPath;
+ }
- protected String getUnresolved() {
- return IMG_UNRESOLVED;
+ protected String getUnresolved() {
+ return IMG_UNRESOLVED;
+ }
+
+ protected String getPrefix() {
+ return IMG_PREFIX;
+ }
+
+ String processValue(VpePageContext pageContext, Node sourceNode,
+ String tagValue) {
+ String attrName = null;
+ if (getParameter(0) instanceof VpeAttributeOperand) {
+ attrName = ((VpeAttributeOperand) getParameter(0))
+ .getAttributeName();
}
+ String query = (attrName == null) ? null : "/"
+ + sourceNode.getNodeName() + "@" + attrName;
- protected String getPrefix() {
- return IMG_PREFIX;
- }
-
- String processValue(VpePageContext pageContext, Node sourceNode, String tagValue) {
- String attrName = null;
- if(getParameter(0) instanceof VpeAttributeOperand) {
- attrName = ((VpeAttributeOperand)getParameter(0)).getAttributeName();
- }
- String query = (attrName == null) ? null : "/" + sourceNode.getNodeName() +
"@" + attrName;
-
- IDocument document =
pageContext.getSourceBuilder().getStructuredTextViewer().getDocument();
- if(document == null || query == null) return tagValue;
- WtpKbConnector connector = pageContext.getConnector();
- try {
- AttributeDescriptor descriptor = connector.getAttributeInformation(query);
- if(descriptor == null) return tagValue;
- AttributeValueDescriptor[] ds = descriptor.getValueDesriptors();
- for (int i = 0; i < ds.length; i++) {
- if(!"file".equals(ds[i].getType())) continue;
- ParamList params = ds[i].getParams();
- String[] vs = params.getParamsValues(IFilePathEncoder.PATH_ADDITION);
- if(vs == null || vs.length == 0) continue;
- if(tagValue.startsWith(vs[0])) tagValue = tagValue.substring(vs[0].length());
- }
- } catch (Exception e) {
- VpePlugin.getPluginLog().logError(e);
- }
+ IDocument document = pageContext.getSourceBuilder()
+ .getStructuredTextViewer().getDocument();
+ if (document == null || query == null)
+ return tagValue;
+ WtpKbConnector connector = pageContext.getConnector();
+ try {
+ AttributeDescriptor descriptor = connector
+ .getAttributeInformation(query);
+ if (descriptor == null)
return tagValue;
+ AttributeValueDescriptor[] ds = descriptor.getValueDesriptors();
+ for (int i = 0; i < ds.length; i++) {
+ if (!"file".equals(ds[i].getType()))
+ continue;
+ ParamList params = ds[i].getParams();
+ String[] vs = params
+ .getParamsValues(IFilePathEncoder.PATH_ADDITION);
+ if (vs == null || vs.length == 0)
+ continue;
+ if (tagValue.startsWith(vs[0]))
+ tagValue = tagValue.substring(vs[0].length());
+ }
+ } catch (Exception e) {
+ VpePlugin.getPluginLog().logError(e);
}
-
+ return tagValue;
+ }
+
}
\ No newline at end of file