Search in sources :

Example 1 with Parameter

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

the class XSLValidator method checkCallTemplates.

private void checkCallTemplates(StylesheetModel stylesheetComposed, XSLValidationReport report) throws MaxErrorsExceededException {
    for (CallTemplate calledTemplate : stylesheetComposed.getStylesheet().getCalledTemplates()) {
        if (calledTemplate.getName() != null) {
            // get the list of templates that might be being called by this
            // template call
            List<Template> templateList = stylesheetComposed.getTemplatesByName(calledTemplate.getName());
            if (templateList.size() == 0) {
                Object[] messageArgs = { calledTemplate.getName() };
                createMarker(report, calledTemplate.getAttribute("name"), getPreference(ValidationPreferences.CALL_TEMPLATES), // $NON-NLS-1$
                MessageFormat.format(Messages.XSLValidator_18, messageArgs));
            } else {
                Template namedTemplate = templateList.get(0);
                for (Parameter calledTemplateParam : calledTemplate.getParameters()) {
                    boolean found = false;
                    for (Parameter namedTemplateParam : namedTemplate.getParameters()) {
                        if (calledTemplateParam.getName().equals(namedTemplateParam.getName())) {
                            found = true;
                            if (!namedTemplateParam.isValue() && !calledTemplateParam.isValue()) {
                                Object[] messageArgs = { calledTemplateParam.getName() };
                                createMarker(report, calledTemplateParam, getPreference(ValidationPreferences.EMPTY_PARAM), MessageFormat.format(Messages.XSLValidator_20, messageArgs));
                            }
                            break;
                        }
                    }
                    if (!found) {
                        Object[] messageArgs = { calledTemplateParam.getName() };
                        createMarker(report, calledTemplateParam.getAttribute("name"), getPreference(ValidationPreferences.MISSING_PARAM), // $NON-NLS-1$
                        MessageFormat.format(Messages.XSLValidator_22, messageArgs));
                    }
                }
                if (getPreference(ValidationPreferences.MISSING_PARAM) > IMarker.SEVERITY_INFO) {
                    for (Parameter namedTemplateParam : namedTemplate.getParameters()) {
                        if (!namedTemplateParam.isValue()) {
                            boolean found = false;
                            for (Parameter calledTemplateParam : calledTemplate.getParameters()) {
                                if (calledTemplateParam.getName().equals(namedTemplateParam.getName())) {
                                    found = true;
                                    break;
                                }
                            }
                            if (!found) {
                                Object[] messageArgs = { namedTemplateParam.getName() };
                                createMarker(report, calledTemplate, getPreference(ValidationPreferences.MISSING_PARAM), MessageFormat.format(Messages.XSLValidator_3, messageArgs));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Parameter(org.eclipse.wst.xsl.core.model.Parameter) CallTemplate(org.eclipse.wst.xsl.core.model.CallTemplate) CallTemplate(org.eclipse.wst.xsl.core.model.CallTemplate) Template(org.eclipse.wst.xsl.core.model.Template)

Example 2 with Parameter

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

the class XSLValidator method checkParameters.

private void checkParameters(XSLValidationReport report, Template template) throws MaxErrorsExceededException {
    List<Parameter> parameters = new ArrayList<Parameter>(template.getParameters());
    // reverse the parameters order for checking - for duplicate parameters
    // the first one is valid
    Collections.reverse(parameters);
    Set<Parameter> duplicateParameters = new HashSet<Parameter>();
    // check parameters
    for (Parameter param : parameters) {
        if (param.getName() == null) {
            // name is required
            createMarker(report, param, getPreference(ValidationPreferences.NAME_ATTRIBUTE_MISSING), Messages.XSLValidator_14);
        } else if (param.getName().trim().length() == 0) {
            // name value is
            // required
            createMarker(report, param, getPreference(ValidationPreferences.NAME_ATTRIBUTE_EMPTY), Messages.XSLValidator_15);
        } else if (duplicateParameters.contains(param)) {
            // the parameter
            continue;
        } else {
            // check a parameter with the same name does not exist
            for (Parameter checkParam : parameters) {
                if (param != checkParam) {
                    if (param.getName().equals(checkParam.getName())) {
                        duplicateParameters.add(checkParam);
                        createMarker(report, param, getPreference(ValidationPreferences.DUPLICATE_PARAMETER), Messages.XSLValidator_16);
                    }
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Parameter(org.eclipse.wst.xsl.core.model.Parameter) HashSet(java.util.HashSet)

Example 3 with Parameter

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

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

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

the class XSLElementFactory method createWithParamParm.

public XSLElement createWithParamParm() {
    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;
        }
    }
    // get the previous call-template
    CallTemplate currentCallTemplate = stylesheetParserData.getCallTemplates().peek();
    currentCallTemplate.addParameter(param);
    return param;
}
Also used : 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)

Aggregations

Parameter (org.eclipse.wst.xsl.core.model.Parameter)6 CallTemplate (org.eclipse.wst.xsl.core.model.CallTemplate)3 Template (org.eclipse.wst.xsl.core.model.Template)3 Node (org.w3c.dom.Node)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 NodeList (org.w3c.dom.NodeList)2 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1 IDOMAttr (org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)1 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)1 Function (org.eclipse.wst.xsl.core.model.Function)1 StylesheetModel (org.eclipse.wst.xsl.core.model.StylesheetModel)1 XSLAttribute (org.eclipse.wst.xsl.core.model.XSLAttribute)1 Attr (org.w3c.dom.Attr)1