Search in sources :

Example 1 with StylesheetModel

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

the class XSLValidator method validate.

/**
 * Validate the given XSL file using the specified report.
 *
 * @param xslFile
 *            the XSL file
 * @param report
 *            the report to use for reporting validation errors
 * @param forceBuild
 *            true if build should always be forced
 * @return the validation report
 * @throws CoreException
 *             if any exception occurs while validating
 */
public void validate(IFile xslFile, XSLValidationReport report, boolean forceBuild) throws CoreException {
    StylesheetModel stylesheet;
    if (forceBuild)
        stylesheet = XSLCore.getInstance().buildStylesheet(xslFile);
    else
        stylesheet = XSLCore.getInstance().getStylesheet(xslFile);
    project = xslFile.getProject();
    long start;
    if (Debug.debugXSLModel) {
        start = System.currentTimeMillis();
    }
    if (stylesheet != null) {
        try {
            calculateProblems(stylesheet, report);
        } catch (MaxErrorsExceededException e) {
        // do nothing
        }
    }
    if (Debug.debugXSLModel) {
        long end = System.currentTimeMillis();
        System.out.println(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "VALIDATE " + xslFile + " in " + (end - start) + "ms");
    }
}
Also used : StylesheetModel(org.eclipse.wst.xsl.core.model.StylesheetModel)

Example 2 with StylesheetModel

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

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

the class AbstractModelTest method validate.

/**
 * Validate the file
 *
 * @param file
 * @return
 * @throws CoreException
 * @throws XPathExpressionException
 * @throws IOException
 */
protected XSLValidationReport validate(IFile file) throws CoreException, XPathExpressionException, IOException {
    XSLValidationReport report = new XSLValidationReport(file.getLocationURI().toString());
    XSLValidator.getInstance().validate(file, report, true);
    StylesheetModel model = XSLCore.getInstance().getStylesheet(file);
    assertFalse("Stylesheet model is null", model == null);
    Map<Integer, String> expectedErrors = calculateErrorsAndWarnings(file);
    validateErrors(model, report, expectedErrors);
    return report;
}
Also used : XSLValidationReport(org.eclipse.wst.xsl.core.internal.validation.XSLValidationReport) StylesheetModel(org.eclipse.wst.xsl.core.model.StylesheetModel)

Example 4 with StylesheetModel

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

the class AbstractXSLContentAssistRequest method getStylesheetModel.

protected StylesheetModel getStylesheetModel() {
    IFile editorFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(getLocation()));
    StylesheetModel model = XSLCore.getInstance().getStylesheet(editorFile);
    return model;
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) StylesheetModel(org.eclipse.wst.xsl.core.model.StylesheetModel)

Example 5 with StylesheetModel

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

Aggregations

StylesheetModel (org.eclipse.wst.xsl.core.model.StylesheetModel)13 IFile (org.eclipse.core.resources.IFile)5 Template (org.eclipse.wst.xsl.core.model.Template)4 Path (org.eclipse.core.runtime.Path)2 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)2 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)2 ValidationResult (org.eclipse.wst.validation.ValidationResult)2 XSLValidationReport (org.eclipse.wst.xsl.core.internal.validation.XSLValidationReport)2 XSLAttribute (org.eclipse.wst.xsl.core.model.XSLAttribute)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Position (org.eclipse.jface.text.Position)1 Annotation (org.eclipse.jface.text.source.Annotation)1 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)1 ValidatorMessage (org.eclipse.wst.validation.ValidatorMessage)1 IDOMAttr (org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)1 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)1 ValidationMessage (org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage)1 ValidationReport (org.eclipse.wst.xml.core.internal.validation.core.ValidationReport)1