[jbosstools-commits] JBoss Tools SVN: r6698 - in trunk/vpe/plugins: org.jboss.tools.vpe.html/templates and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Mar 5 11:43:48 EST 2008


Author: svasilyev
Date: 2008-03-05 11:43:48 -0500 (Wed, 05 Mar 2008)
New Revision: 6698

Modified:
   trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml
   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/VpeFunctionSrc.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1410

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	2008-03-05 16:25:58 UTC (rev 6697)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionHref.java	2008-03-05 16:43:48 UTC (rev 6698)
@@ -22,7 +22,7 @@
 
 public class VpeFunctionHref extends VpeFunctionSrc {
     protected String getUnresolved() {
-	    return "";
+	    return ""; //$NON-NLS-1$
     }
 
     String[] getSignatures() {
@@ -30,34 +30,48 @@
 	}
 
     public VpeValue exec(VpePageContext pageContext, Node sourceNode) {
-		String tagValue = getParameter(0).exec(pageContext, sourceNode).stringValue();
+	String tagValue = getParameter(0).exec(pageContext, sourceNode).stringValue();
 
-		IPath tagPath = new Path(tagValue);
-		if (tagPath.isEmpty()) return new VpeValue(getUnresolved());
+	tagValue = resolveEL(tagValue);
+	
+	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();
 
-		File locFile = tagPath.toFile();
-		if (locFile.exists()) return new VpeValue(getPrefix() + locFile.getAbsolutePath()); 
+	if (device != null
+		&& ("http:".equalsIgnoreCase(device) //$NON-NLS-1$
+			|| "file:".equalsIgnoreCase(device))) { //$NON-NLS-1$
+	    return new VpeValue(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);
-		    }
-		}
+	File locFile = tagPath.toFile();
+	if (locFile.exists()) {
+	    return new VpeValue(getPrefix() + locFile.getAbsolutePath());
+	}
 
-		if (imgPath != null && imgPath.toFile().exists()) { 
-		    return new VpeValue(getPrefix() + imgPath.toOSString());
-		}
+	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);
+	    }
+	}
 
-		return new VpeValue(getUnresolved());
+	if (imgPath != null && imgPath.toFile().exists()) {
+	    return new VpeValue(getPrefix() + imgPath.toOSString());
 	}
+
+	return new VpeValue(getUnresolved());
+    }
 }
\ No newline at end of file

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-03-05 16:25:58 UTC (rev 6697)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeFunctionSrc.java	2008-03-05 16:43:48 UTC (rev 6698)
@@ -38,12 +38,15 @@
 import org.w3c.dom.Node;
 
 public class VpeFunctionSrc extends VpeFunction {
-    static final String IMG_UNRESOLVED = "unresolved.gif";
-    static final String IMG_PREFIX = "file:///";
+    static final String IMG_UNRESOLVED = "unresolved.gif"; //$NON-NLS-1$
+    static final String IMG_PREFIX = "file:///"; //$NON-NLS-1$
 
     public VpeValue exec(VpePageContext pageContext, Node sourceNode) {
 	String tagValue = getParameter(0).exec(pageContext, sourceNode)
 		.stringValue();
+	
+	tagValue = resolveEL(tagValue);
+	
 	IFile iFile = VpeCreatorUtil.getFile(tagValue, pageContext);
 	if (iFile != null) {
 	    return new VpeValue(getPrefix()+iFile.getLocation().toString());
@@ -52,7 +55,7 @@
 
 	// decode string from utf
 	try {
-	    tagValue = URLDecoder.decode(tagValue, "UTF-8");
+	    tagValue = URLDecoder.decode(tagValue, "UTF-8"); //$NON-NLS-1$
 	} catch (UnsupportedEncodingException e) {
 	    // TODO Auto-generated catch block
 	    e.printStackTrace();
@@ -65,8 +68,8 @@
 	String device = (tagPath.getDevice() == null ? tagPath.segment(0)
 		: tagPath.getDevice());
 	if (device != null
-		&& ("http:".equalsIgnoreCase(device) || "file:"
-			.equalsIgnoreCase(device)))
+		&& ("http:".equalsIgnoreCase(device) //$NON-NLS-1$
+			|| "file:".equalsIgnoreCase(device))) //$NON-NLS-1$
 	    return new VpeValue(tagValue);
 
 	File locFile = tagPath.toFile();
@@ -96,7 +99,7 @@
 
 	    if (null != file) {
 		ResourceReference resourceReference = null;
-		if ("/".equals(tagValue.substring(0, 1))) {
+		if ("/".equals(tagValue.substring(0, 1))) { //$NON-NLS-1$
 		    resourceReference = pageContext
 			    .getRuntimeAbsoluteFolder(file);
 		    tagValue = tagValue.substring(1);
@@ -179,38 +182,54 @@
 	    String tagValue) {
 	String attrName = null;
 	if (getParameter(0) instanceof VpeAttributeOperand) {
-	    attrName = ((VpeAttributeOperand) getParameter(0))
-		    .getAttributeName();
+	    attrName = ((VpeAttributeOperand) getParameter(0)).getAttributeName();
 	}
-	String query = (attrName == null) ? null : "/"
-		+ sourceNode.getNodeName() + "@" + attrName;
+	
+	String query = attrName == null
+			? null
+			: "/" + sourceNode.getNodeName() + "@" + attrName; //$NON-NLS-1$  //$NON-NLS-2$
 
-	IDocument document = pageContext.getSourceBuilder()
-		.getStructuredTextViewer().getDocument();
-	if (document == null || query == null)
+	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)
+	    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()))
+		if (!"file".equals(ds[i].getType())) {//$NON-NLS-1$
 		    continue;
+		}
+		
 		ParamList params = ds[i].getParams();
-		String[] vs = params
-			.getParamsValues(IFilePathEncoder.PATH_ADDITION);
-		if (vs == null || vs.length == 0)
+		String[] vs = params.getParamsValues(IFilePathEncoder.PATH_ADDITION);
+		if (vs == null || vs.length == 0) {
 		    continue;
-		if (tagValue.startsWith(vs[0]))
+		}
+		
+		if (tagValue.startsWith(vs[0])) {
 		    tagValue = tagValue.substring(vs[0].length());
+		}
 	    }
 	} catch (Exception e) {
 	    VpePlugin.getPluginLog().logError(e);
 	}
+	
 	return tagValue;
     }
 
+    /*
+     * temporary solution to solve #{facesContext.externalContext.requestContextPath}
+     */
+    protected String resolveEL(String value) {
+	String resolvedValue = value.replaceFirst("^\\s*(\\#|\\$)\\{facesContext.externalContext.requestContextPath\\}", ""); //$NON-NLS-1$ //$NON-NLS-2$
+	
+	return resolvedValue;
+    }
 }
\ No newline at end of file

Modified: trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml	2008-03-05 16:25:58 UTC (rev 6697)
+++ trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml	2008-03-05 16:43:48 UTC (rev 6698)
@@ -1252,9 +1252,26 @@
 	</vpe:tag>
 
 	<vpe:tag name="img" case-sensitive="no">
+		<!-- in this case the tag is a facelets's tag -->
+		<vpe:if test="attrpresent('jsfc')" >
+			<vpe:template children="no" modify="no">
+				<vpe:copy
+						attrs="style,class,width,height,border,hspace,vspace">
+					<vpe:attribute name="src" value="{src(@value)}" />
+				</vpe:copy>
+				<vpe:resize>
+					<vpe:width width-attr="style.width" />
+					<vpe:height height-attr="style.height" />
+				</vpe:resize>
+				<vpe:dnd>
+					<vpe:drag start-enable="yes" />
+				</vpe:dnd>
+			</vpe:template>
+		</vpe:if>
+		<!-- default template -->
 		<vpe:template children="no" modify="no">
 			<vpe:copy
-				attrs="style,class,width,height,border,hspace,vspace">
+					attrs="style,class,width,height,border,hspace,vspace">
 				<vpe:attribute name="src" value="{src(@src)}" />
 			</vpe:copy>
 			<vpe:resize>




More information about the jbosstools-commits mailing list