Search in sources :

Example 1 with Template

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

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

the class XSLElementFactory method createTemplate.

public XSLElement createTemplate() {
    stylesheetParserData.setCurrentTemplate(new Template(stylesheetParserData.getStylesheet()));
    stylesheetParserData.getStylesheet().addTemplate(stylesheetParserData.getCurrentTemplate());
    return stylesheetParserData.getCurrentTemplate();
}
Also used : CallTemplate(org.eclipse.wst.xsl.core.model.CallTemplate) Template(org.eclipse.wst.xsl.core.model.Template)

Example 3 with Template

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

the class TestStylesheet method testgetLocalTemplatesTemplates.

@Test
public void testgetLocalTemplatesTemplates() {
    Stylesheet model = builder.getStylesheet(getFile("style1.xsl"), false);
    assertNotNull("Model failed to load, returned NULL", model);
    List<Template> templatesList = model.getTemplates();
    assertEquals("Wrong number of templates returned.", 2, templatesList.size());
}
Also used : Stylesheet(org.eclipse.wst.xsl.core.model.Stylesheet) Template(org.eclipse.wst.xsl.core.model.Template) Test(org.junit.Test)

Example 4 with Template

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

the class OverrideIndicatorManager method updateAnnotations.

/**
 * Updates the override and implements annotations based on the given AST.
 *
 * @param ast
 *            the compilation unit AST
 * @param progressMonitor
 *            the progress monitor
 * @since 1.0
 */
public void updateAnnotations() {
    StylesheetModel stylesheetComposed = XSLCore.getInstance().getStylesheet(file);
    final Map<Annotation, Position> annotationMap = new HashMap<Annotation, Position>(50);
    List<Template> nestedTemplates = stylesheetComposed.findAllNestedTemplates();
    for (Template template : stylesheetComposed.getStylesheet().getTemplates()) {
        // check for overridden stylesheets
        for (Template nestedTemplate : nestedTemplates) {
            IFile nestedFile = nestedTemplate.getStylesheet().getFile();
            if (nestedFile != null) {
                if (template.matchesByMatchOrName(nestedTemplate)) {
                    // the template overrides another templates as its name matches, or its match and mode matches
                    if (template.getName() != null) {
                        String text = NLS.bind(Messages.XSLEditorOverrideTemplate, template.getName(), nestedFile.getName());
                        annotationMap.put(// $NON-NLS-1$
                        new OverrideIndicator(text, "binding.getKey()"), new Position(template.getOffset(), template.getLength()));
                    } else {
                        String[] overrideParms = { template.getMatch(), template.getMode(), nestedFile.getName() };
                        String text = NLS.bind(Messages.XSLEditorOverrideTemplateMode, overrideParms);
                        annotationMap.put(// $NON-NLS-1$
                        new OverrideIndicator(text, "binding.getKey()"), new Position(template.getOffset(), template.getLength()));
                    }
                }
            }
        }
    }
    synchronized (fAnnotationModelLockObject) {
        if (fAnnotationModel instanceof IAnnotationModelExtension) {
            ((IAnnotationModelExtension) fAnnotationModel).replaceAnnotations(fOverrideAnnotations, annotationMap);
        } else {
            removeAnnotations();
            Iterator iter = annotationMap.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry mapEntry = (Map.Entry) iter.next();
                fAnnotationModel.addAnnotation((Annotation) mapEntry.getKey(), (Position) mapEntry.getValue());
            }
        }
        fOverrideAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) StylesheetModel(org.eclipse.wst.xsl.core.model.StylesheetModel) Annotation(org.eclipse.jface.text.source.Annotation) Template(org.eclipse.wst.xsl.core.model.Template) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with Template

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

the class XSLWorkbenchAdapter method getImageDescriptor.

public ImageDescriptor getImageDescriptor(Object object) {
    XSLModelObject obj = (XSLModelObject) object;
    String path = null;
    switch(obj.getModelType()) {
        case STYLESHEET:
            path = XSLPluginImages.IMG_ELM_STYLESHET;
            break;
        case IMPORT:
        case INCLUDE:
            path = XSLPluginImages.IMG_ELM_IMPORT_INCLUDE;
            break;
        case TEMPLATE:
            {
                Template template = (Template) obj;
                if (template.getName() != null) {
                    path = XSLPluginImages.IMG_ELM_TEMPLATE_NAME;
                } else {
                    path = XSLPluginImages.IMG_ELM_TEMPLATE;
                }
                break;
            }
        case VARIABLE:
            path = XSLPluginImages.IMG_ELM_VARIABLE;
            break;
        case FUNCTION:
            path = XSLPluginImages.IMG_ELM_FUNCTION;
            break;
    }
    return path == null ? null : AbstractUIPlugin.imageDescriptorFromPlugin(XSLUIPlugin.PLUGIN_ID, path);
}
Also used : XSLModelObject(org.eclipse.wst.xsl.core.model.XSLModelObject) 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