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?"

(New page: == 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 Dependenc...)
 
m (Answer: indentation)
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 ==  
 
1. Create a plug-in project
 
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
 
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.taglibraries.
 
3. In the Plug-in manifest editor, go to the Extensions tab, and add org.eclipse.jet.taglibraries.
 +
 
4. Create a tagLibrary entry under this. Give it an ID like "MyCustomWorkspaceTags", and a default prefix like mcws.
 
4. Create a tagLibrary entry under this. Give it an ID like "MyCustomWorkspaceTags", and a default prefix like mcws.
 +
 
5. Under the tagLibrary entry, create a tag of wanted type and name.
 
5. Under the tagLibrary entry, create a tag of wanted type and name.
 +
 
5. Under the Tag node, add as much attributes you need, and set options (required or note, type).
 
5. Under the Tag node, add as much attributes you need, and set options (required or note, type).
 +
 
6. Return the the conditionalTag entry, and click on the 'class' entry to create the Java class for the tag. Specify a class name and check the package, a case problem could happen.
 
6. Return the the conditionalTag entry, and click on the 'class' entry to create the Java class for the tag. Specify a class name and check the package, a case problem could happen.
6. Code the Java class.
+
 
 +
7. Code the Java class.
 +
 
  
 
The following example is an AbstractConditionalTag which name is "resourcesExists". It has an attribute called "path" (required = true, String).
 
The following example is an AbstractConditionalTag which name is "resourcesExists". It has an attribute called "path" (required = true, String).
Line 38: Line 49:
 
</pre>
 
</pre>
  
Usage would then be in your template :
+
In your template :
 +
 
 
Taglib declaration :
 
Taglib declaration :
 
<pre><%@taglib id="your-plugin-id.MyCustomWorkspaceTags" prefix="mcws"%></pre>
 
<pre><%@taglib id="your-plugin-id.MyCustomWorkspaceTags" prefix="mcws"%></pre>

Revision as of 11:45, 25 June 2007

Question

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

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.taglibraries.

4. Create a tagLibrary entry under this. Give it an ID like "MyCustomWorkspaceTags", and a default prefix like mcws.

5. Under the tagLibrary entry, create a tag of wanted type and name.

5. Under the Tag node, add as much attributes you need, and set options (required or note, type).

6. Return the the conditionalTag entry, and click on the 'class' entry to create the Java class for the tag. Specify a class name and check the package, a case problem could happen.

7. Code the Java class.


The following example is an AbstractConditionalTag which name is "resourcesExists". It has an attribute called "path" (required = true, String).

package org.eclipse.jet.example.customtags;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.taglib.AbstractConditionalTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;

/**
 * Implements <mcws:resourceExists path="somepath">
 *
 */
public class ResourceExistsTag extends AbstractConditionalTag {
  public boolean doEvalCondition(TagInfo td, JET2Context context)
    throws JET2TagException {
    String path = getAttribute("path");	
    IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    return resource != null && resource.exists();
  }
}

In your template :

Taglib declaration :

<%@taglib id="your-plugin-id.MyCustomWorkspaceTags" prefix="mcws"%>

Tag usage :

<mcws:resourceExists path="someproject/somefolder/somefile.c">
    ... do this if exits
</mcws:resourceExists>

See Also

Back to the M2T-JET-FAQ

Back to the top