Search in sources :

Example 6 with XSLAttribute

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

use of org.eclipse.wst.xsl.core.model.XSLAttribute 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 8 with XSLAttribute

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

the class XSLModelObjectFactory method configure.

private void configure(IDOMNode node, XSLElement element) {
    setPositionInfo(node, element);
    IDOMElement domElem = (IDOMElement) node;
    element.setName(domElem.getLocalName());
    NamedNodeMap map = node.getAttributes();
    for (int i = 0; i < map.getLength(); i++) {
        IDOMAttr attr = (IDOMAttr) map.item(i);
        XSLAttribute xslatt = new XSLAttribute(element, attr.getName(), attr.getValue());
        setPositionInfo(attr, xslatt);
        element.setAttribute(xslatt);
    }
    setParentElement(node, element);
}
Also used : IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) NamedNodeMap(org.w3c.dom.NamedNodeMap) XSLAttribute(org.eclipse.wst.xsl.core.model.XSLAttribute) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 9 with XSLAttribute

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

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

the class XSLValidator method validateXPath.

private void validateXPath(XSLElement xslEl, XSLValidationReport report, String attName) throws MaxErrorsExceededException {
    XSLAttribute att = xslEl.getAttribute(attName);
    if (att != null && att.getValue() != null) {
        try {
            String xslVersion = xslEl.getStylesheet().getVersion();
            String xpathExp = att.getValue();
            if (xslVersion.equals(XSLT2_Version)) {
                XPath20Helper.compile(xpathExp);
            } else {
                XSLTXPathHelper.compile(att.getValue());
            }
        } catch (XPathExpressionException e) {
            createMarker(report, att, getPreference(ValidationPreferences.XPATHS), Messages.XSLValidator_1);
        } catch (NullPointerException e) {
        // not sure why NPE is being thrown here
        }
    }
}
Also used : XSLAttribute(org.eclipse.wst.xsl.core.model.XSLAttribute) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Aggregations

XSLAttribute (org.eclipse.wst.xsl.core.model.XSLAttribute)10 Template (org.eclipse.wst.xsl.core.model.Template)4 IFile (org.eclipse.core.resources.IFile)3 ArrayList (java.util.ArrayList)2 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)2 IDOMAttr (org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2 Include (org.eclipse.wst.xsl.core.model.Include)2 StylesheetModel (org.eclipse.wst.xsl.core.model.StylesheetModel)2 Test (org.junit.Test)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 Path (org.eclipse.core.runtime.Path)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)1 Parameter (org.eclipse.wst.xsl.core.model.Parameter)1 Stylesheet (org.eclipse.wst.xsl.core.model.Stylesheet)1 Attr (org.w3c.dom.Attr)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1