Search in sources :

Example 1 with Function

use of org.eclipse.wst.xsl.core.model.Function in project webtools.sourceediting by eclipse.

the class XSLElementFactory method createFunction.

public XSLElement createFunction() {
    stylesheetParserData.setCurrentTemplate(null);
    Function function = new Function(stylesheetParserData.getStylesheet());
    stylesheetParserData.getFunctions().push(function);
    stylesheetParserData.getStylesheet().addFunction(function);
    return function;
}
Also used : Function(org.eclipse.wst.xsl.core.model.Function)

Example 2 with Function

use of org.eclipse.wst.xsl.core.model.Function in project webtools.sourceediting by eclipse.

the class XSLElementFactory method createParamater.

public XSLElement createParamater() {
    Parameter param = new Parameter(stylesheetParserData.getStylesheet());
    // determine whether param has a value
    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node childNode = childNodes.item(i);
        if (childNode.getNodeType() != Node.ATTRIBUTE_NODE) {
            param.setValue(true);
            break;
        }
    }
    if (stylesheetParserData.getParentEl() != null) {
        if (stylesheetParserData.getParentEl().getModelType() == XSLModelObject.Type.FUNCTION) {
            Function function = (Function) stylesheetParserData.getParentEl();
            function.addParameter(param);
        } else if (stylesheetParserData.getParentEl().getModelType() == XSLModelObject.Type.TEMPLATE && stylesheetParserData.getElementStack().size() == 2 && stylesheetParserData.getCurrentTemplate() != null) {
            Template template = (Template) stylesheetParserData.getParentEl();
            template.addParameter(param);
        }
    }
    return param;
}
Also used : Function(org.eclipse.wst.xsl.core.model.Function) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Parameter(org.eclipse.wst.xsl.core.model.Parameter) CallTemplate(org.eclipse.wst.xsl.core.model.CallTemplate) Template(org.eclipse.wst.xsl.core.model.Template)

Example 3 with Function

use of org.eclipse.wst.xsl.core.model.Function in project webtools.sourceediting by eclipse.

the class XSLWorkbenchAdapter method getLabel.

public String getLabel(Object o) {
    String label = null;
    XSLModelObject obj = (XSLModelObject) o;
    switch(obj.getModelType()) {
        case STYLESHEET:
            Stylesheet stylesheet = (Stylesheet) obj;
            label = stylesheet.getVersion() == null ? "?" : // $NON-NLS-1$
            stylesheet.getVersion();
            break;
        case IMPORT:
            Import imp = (Import) obj;
            label = imp.getHref();
            break;
        case INCLUDE:
            Include inc = (Include) obj;
            label = inc.getHref();
            break;
        case TEMPLATE:
            Template t = (Template) obj;
            StringBuffer sb = new StringBuffer();
            if (t.getName() != null)
                // $NON-NLS-1$
                sb.append(t.getName()).append(" ");
            if (t.getMatch() != null)
                // $NON-NLS-1$
                sb.append(t.getMatch()).append(" ");
            if (t.getMode() != null)
                // $NON-NLS-1$//$NON-NLS-2$
                sb.append("(").append(t.getMode()).append(")");
            label = sb.toString();
            break;
        case VARIABLE:
            Variable v = (Variable) obj;
            label = v.getName();
            break;
        case FUNCTION:
            Function f = (Function) obj;
            label = f.getName();
    }
    return label;
}
Also used : Function(org.eclipse.wst.xsl.core.model.Function) Import(org.eclipse.wst.xsl.core.model.Import) Variable(org.eclipse.wst.xsl.core.model.Variable) XSLModelObject(org.eclipse.wst.xsl.core.model.XSLModelObject) Include(org.eclipse.wst.xsl.core.model.Include) Stylesheet(org.eclipse.wst.xsl.core.model.Stylesheet) Template(org.eclipse.wst.xsl.core.model.Template)

Example 4 with Function

use of org.eclipse.wst.xsl.core.model.Function in project webtools.sourceediting by eclipse.

the class TestStylesheet method testGetFunctionFunc1.

@Test
public void testGetFunctionFunc1() {
    Stylesheet stylesheet = builder.getStylesheet(getFile("XSLT20FunctionTest.xsl"), false);
    assertNotNull("Model failed to load, returned NULL", stylesheet);
    List<Function> functionList = stylesheet.getFunctions();
    for (Function function : functionList) {
        if (function.getName().equals("func1")) {
            return;
        }
    }
    fail("Did not find XSL func func1");
}
Also used : Function(org.eclipse.wst.xsl.core.model.Function) Stylesheet(org.eclipse.wst.xsl.core.model.Stylesheet) Test(org.junit.Test)

Example 5 with Function

use of org.eclipse.wst.xsl.core.model.Function in project webtools.sourceediting by eclipse.

the class TestStylesheet method testGetFunction.

@Test
public void testGetFunction() {
    Stylesheet stylesheet = builder.getStylesheet(getFile("XSLT20FunctionTest.xsl"), false);
    assertNotNull("Model failed to load, returned NULL", stylesheet);
    List<Function> functionList = stylesheet.getFunctions();
    assertEquals("Wrong number of global variables returned.", 2, functionList.size());
}
Also used : Function(org.eclipse.wst.xsl.core.model.Function) Stylesheet(org.eclipse.wst.xsl.core.model.Stylesheet) Test(org.junit.Test)

Aggregations

Function (org.eclipse.wst.xsl.core.model.Function)5 Stylesheet (org.eclipse.wst.xsl.core.model.Stylesheet)3 Template (org.eclipse.wst.xsl.core.model.Template)2 Test (org.junit.Test)2 CallTemplate (org.eclipse.wst.xsl.core.model.CallTemplate)1 Import (org.eclipse.wst.xsl.core.model.Import)1 Include (org.eclipse.wst.xsl.core.model.Include)1 Parameter (org.eclipse.wst.xsl.core.model.Parameter)1 Variable (org.eclipse.wst.xsl.core.model.Variable)1 XSLModelObject (org.eclipse.wst.xsl.core.model.XSLModelObject)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1