Search in sources :

Example 6 with Template

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

the class XSLHyperlinkDetector method createWithParamHyperLink.

private IHyperlink createWithParamHyperLink(IFile currentFile, Element elem, Attr attr, IRegion hyperlinkRegion) {
    IHyperlink hyperlink = null;
    StylesheetModel sf = XSLCore.getInstance().getStylesheet(currentFile);
    if (sf != null) {
        Node parentNode = elem.getParentNode();
        Attr parentAttribute = (Attr) parentNode.getAttributes().getNamedItem(ATTR_NAME);
        String templateName = parentAttribute.getValue();
        List<Template> templates = sf.getTemplatesByName(templateName);
        if (templates != null && templates.size() == 1) {
            Template template = templates.get(0);
            List<Parameter> parameters = template.getParameters();
            for (Parameter param : parameters) {
                String paramName = attr.getValue();
                XSLAttribute parameterNameAttr = param.getAttribute(ATTR_NAME);
                if (parameterNameAttr != null && parameterNameAttr.getValue().equals(paramName)) {
                    hyperlink = new SourceFileHyperlink(hyperlinkRegion, template.getStylesheet().getFile(), param);
                }
            }
        }
    }
    return hyperlink;
}
Also used : XSLAttribute(org.eclipse.wst.xsl.core.model.XSLAttribute) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) Parameter(org.eclipse.wst.xsl.core.model.Parameter) StylesheetModel(org.eclipse.wst.xsl.core.model.StylesheetModel) Attr(org.w3c.dom.Attr) IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) Template(org.eclipse.wst.xsl.core.model.Template)

Example 7 with Template

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

the class CallTemplateContentAssistRequest method getCompletionProposals.

/**
 * (non-Javadoc)
 * @see org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest#getCompletionProposals()
 */
@Override
public ArrayList<ICompletionProposal> getCompletionProposals() {
    proposals.clear();
    IFile editorFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(getLocation()));
    StylesheetModel model = XSLCore.getInstance().getStylesheet(editorFile);
    List<Template> templates = model.getTemplates();
    for (Template template : templates) {
        XSLAttribute attribute = template.getAttribute(ATTR_NAME);
        if (attribute != null) {
            String proposalInfo = getAdditionalInfo(template);
            CustomCompletionProposal proposal = new CustomCompletionProposal(attribute.getValue(), getStartOffset() + 1, 0, attribute.getValue().length(), XSLPluginImageHelper.getInstance().getImage(XSLPluginImages.IMG_TEMPLATE), attribute.getValue(), null, proposalInfo, 0);
            addProposal(proposal);
        }
    }
    return getAllCompletionProposals();
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) XSLAttribute(org.eclipse.wst.xsl.core.model.XSLAttribute) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) StylesheetModel(org.eclipse.wst.xsl.core.model.StylesheetModel) Template(org.eclipse.wst.xsl.core.model.Template)

Example 8 with Template

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

the class TemplateModeAttributeContentAssist method addModeProposals.

/**
 * @param model
 */
protected void addModeProposals(StylesheetModel model) {
    List<Template> templates = model.getTemplates();
    ArrayList<String> modes = new ArrayList<String>();
    for (Template template : templates) {
        XSLAttribute attribute = template.getAttribute(MODE_ATTRIBUTE);
        IDOMNode xmlNode = (IDOMNode) node;
        if (attribute != null && xmlNode.getStartOffset() != template.getOffset()) {
            CustomCompletionProposal proposal = new CustomCompletionProposal(attribute.getValue(), getStartOffset() + 1, 0, attribute.getValue().length(), XSLPluginImageHelper.getInstance().getImage(XSLPluginImages.IMG_MODE), attribute.getValue(), null, null, 0);
            if (modes.indexOf(attribute.getValue()) == -1) {
                proposals.add(proposal);
                modes.add(attribute.getValue());
            }
        }
    }
    modes.clear();
}
Also used : XSLAttribute(org.eclipse.wst.xsl.core.model.XSLAttribute) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ArrayList(java.util.ArrayList) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) Template(org.eclipse.wst.xsl.core.model.Template)

Example 9 with Template

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

the class TestStylesheetModel method testFindAvailableTemplateModes.

@Test
public void testFindAvailableTemplateModes() {
    ArrayList<String> modes = new ArrayList();
    model = XSLCore.getInstance().getStylesheet(getFile("modeTest.xsl"));
    List<Template> templates = model.getTemplates();
    assertTrue("No templates returned.", templates.size() > 0);
    for (Template template : templates) {
        XSLAttribute attribute = template.getAttribute("mode");
        if (attribute != null) {
            if (modes.indexOf(attribute.getValue()) == -1) {
                modes.add(attribute.getValue());
            }
        }
    }
    assertEquals("Wrong number of mode templates returned.", 3, modes.size());
}
Also used : XSLAttribute(org.eclipse.wst.xsl.core.model.XSLAttribute) ArrayList(java.util.ArrayList) Template(org.eclipse.wst.xsl.core.model.Template) Test(org.junit.Test)

Example 10 with Template

use of org.eclipse.wst.xsl.core.model.Template 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)

Aggregations

Template (org.eclipse.wst.xsl.core.model.Template)12 StylesheetModel (org.eclipse.wst.xsl.core.model.StylesheetModel)4 XSLAttribute (org.eclipse.wst.xsl.core.model.XSLAttribute)4 CallTemplate (org.eclipse.wst.xsl.core.model.CallTemplate)3 Parameter (org.eclipse.wst.xsl.core.model.Parameter)3 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)2 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2 Function (org.eclipse.wst.xsl.core.model.Function)2 Stylesheet (org.eclipse.wst.xsl.core.model.Stylesheet)2 XSLModelObject (org.eclipse.wst.xsl.core.model.XSLModelObject)2 Test (org.junit.Test)2 Node (org.w3c.dom.Node)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Path (org.eclipse.core.runtime.Path)1 Position (org.eclipse.jface.text.Position)1