Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "JET FAQ How do I create custom XPath Function?"

(Answer)
 
Line 1: Line 1:
 
== Question ==  
 
== Question ==  
 
JET provides tools for creating custom XPath functions. How does it work ?
 
JET provides tools for creating custom XPath functions. How does it work ?
 
== Question==
 
JET provides an API for creating custom XPath functions. How can I make mine ?
 
  
 
== Answer ==  
 
== Answer ==  

Latest revision as of 11:53, 25 June 2007

Question

JET provides tools for creating custom XPath functions. How does it work ?

Answer

1. Create a plug-in project

2. In the Plug-in manifest editor, go to the Dependencies tab and add : org.eclipse.jet, org.eclipse.core.runtime, org.eclipse.core.resources

3. In the Plug-in manifest editor, go to the Extensions tab, and add org.eclipse.jet.xpathfunctions.

4. Add a xpathFunction entry under this. Set the name, and the min/max arguments as you wish.

5. Click the Implementation link, and specify a Class to implement the function.

6. Code the class.

The following example is an XPathFunction which name is "resourceExists", and min/max attributes are set to 1.

package org.eclipse.jet.example.customfunction;

import java.util.List;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jet.xpath.XPathFunction;
import org.eclipse.jet.xpath.XPathUtil;

public class ResourceExistsFunction implements XPathFunction {

  public Object evaluate(List args) {
    String path = XPathUtil.xpathString(args.get(0));
    IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    return Boolean.valueOf(resource != null && resource.exists());
  }
}

In your template, usage would then be:

<c:if test="resourceExists('someproject/somefolder/somefile.c')">
    .. do this if file exists
</c:if>

See Also

Back to the M2T-JET-FAQ

Back to the top