Search in sources :

Example 11 with Stylesheet

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

the class StylesheetBuilder method parseModel.

private Stylesheet parseModel(IDOMModel model, IFile file) {
    IDOMDocument document = model.getDocument();
    Stylesheet sf = new Stylesheet(file);
    StylesheetParser walker = new StylesheetParser(sf);
    walker.walkDocument(document);
    return sf;
}
Also used : IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Stylesheet(org.eclipse.wst.xsl.core.model.Stylesheet)

Example 12 with Stylesheet

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

the class StylesheetBuilder method build.

private Stylesheet build(IFile file) {
    long start = System.currentTimeMillis();
    if (Debug.debugXSLModel) {
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("Building " + file + "...");
    }
    Stylesheet stylesheet = null;
    IStructuredModel smodel = null;
    try {
        smodel = StructuredModelManager.getModelManager().getExistingModelForRead(file);
        if (smodel == null) {
            smodel = StructuredModelManager.getModelManager().getModelForRead(file);
            if (Debug.debugXSLModel) {
                long endParse = System.currentTimeMillis();
                System.out.println(// $NON-NLS-1$ //$NON-NLS-2$
                "PARSE " + file + " in " + (endParse - start) + // $NON-NLS-1$
                "ms");
            }
        } else if (Debug.debugXSLModel) {
            long endParse = System.currentTimeMillis();
            System.out.println(// $NON-NLS-1$ //$NON-NLS-2$
            "NO-PARSE " + file + " in " + (endParse - start) + // $NON-NLS-1$
            "ms");
        }
        // start = System.currentTimeMillis();
        if (smodel != null && smodel instanceof IDOMModel) {
            IDOMModel model = (IDOMModel) smodel;
            stylesheet = parseModel(model, file);
        }
    } catch (IOException e) {
        XSLCorePlugin.log(e);
    } catch (CoreException e) {
        XSLCorePlugin.log(e);
    } finally {
        if (smodel != null)
            smodel.releaseFromRead();
    }
    if (Debug.debugXSLModel) {
        long end = System.currentTimeMillis();
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        System.out.println("BUILD " + file + " in " + (end - start) + "ms");
    }
    return stylesheet;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) Stylesheet(org.eclipse.wst.xsl.core.model.Stylesheet)

Example 13 with Stylesheet

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

the class StylesheetBuilder method getStylesheet.

/**
 * Get the <code>Stylesheet</code> associated with the given file. If either
 * the <code>Stylesheet</code> has not yet been created or
 * <code>force</code> is specified then the <code>Stylesheet</code> is
 * built.
 *
 * @param file
 *            the XSL file
 * @param force
 *            <code>true</code> to force a parse of the file
 * @return the <code>Stylesheet</code>
 */
public Stylesheet getStylesheet(IFile file, boolean force) {
    Stylesheet stylesheet = builtFiles.get(file);
    if (stylesheet == null || force) {
        stylesheet = build(file);
        builtFiles.put(file, stylesheet);
    }
    return stylesheet;
}
Also used : Stylesheet(org.eclipse.wst.xsl.core.model.Stylesheet)

Example 14 with Stylesheet

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

the class XSLWorkbenchAdapter method getLabel.

public String getLabel(Object o) {
    String label = null;
    XSLModelObject obj = (XSLModelObject) o;
    switch(obj.getModelType()) {
        case STYLESHEET:
            Stylesheet stylesheet = (Stylesheet) obj;
            label = stylesheet.getVersion() == null ? "?" : // $NON-NLS-1$
            stylesheet.getVersion();
            break;
        case IMPORT:
            Import imp = (Import) obj;
            label = imp.getHref();
            break;
        case INCLUDE:
            Include inc = (Include) obj;
            label = inc.getHref();
            break;
        case TEMPLATE:
            Template t = (Template) obj;
            StringBuffer sb = new StringBuffer();
            if (t.getName() != null)
                // $NON-NLS-1$
                sb.append(t.getName()).append(" ");
            if (t.getMatch() != null)
                // $NON-NLS-1$
                sb.append(t.getMatch()).append(" ");
            if (t.getMode() != null)
                // $NON-NLS-1$//$NON-NLS-2$
                sb.append("(").append(t.getMode()).append(")");
            label = sb.toString();
            break;
        case VARIABLE:
            Variable v = (Variable) obj;
            label = v.getName();
            break;
        case FUNCTION:
            Function f = (Function) obj;
            label = f.getName();
    }
    return label;
}
Also used : Function(org.eclipse.wst.xsl.core.model.Function) Import(org.eclipse.wst.xsl.core.model.Import) Variable(org.eclipse.wst.xsl.core.model.Variable) XSLModelObject(org.eclipse.wst.xsl.core.model.XSLModelObject) Include(org.eclipse.wst.xsl.core.model.Include) Stylesheet(org.eclipse.wst.xsl.core.model.Stylesheet) Template(org.eclipse.wst.xsl.core.model.Template)

Example 15 with Stylesheet

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

the class TestStylesheet method testGetFunctionFunc1.

@Test
public void testGetFunctionFunc1() {
    Stylesheet stylesheet = builder.getStylesheet(getFile("XSLT20FunctionTest.xsl"), false);
    assertNotNull("Model failed to load, returned NULL", stylesheet);
    List<Function> functionList = stylesheet.getFunctions();
    for (Function function : functionList) {
        if (function.getName().equals("func1")) {
            return;
        }
    }
    fail("Did not find XSL func func1");
}
Also used : Function(org.eclipse.wst.xsl.core.model.Function) Stylesheet(org.eclipse.wst.xsl.core.model.Stylesheet) Test(org.junit.Test)

Aggregations

Stylesheet (org.eclipse.wst.xsl.core.model.Stylesheet)19 Test (org.junit.Test)12 Function (org.eclipse.wst.xsl.core.model.Function)3 Import (org.eclipse.wst.xsl.core.model.Import)2 Include (org.eclipse.wst.xsl.core.model.Include)2 Template (org.eclipse.wst.xsl.core.model.Template)2 Variable (org.eclipse.wst.xsl.core.model.Variable)2 XSLModelObject (org.eclipse.wst.xsl.core.model.XSLModelObject)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1 StylesheetModel (org.eclipse.wst.xsl.core.model.StylesheetModel)1 XSLAttribute (org.eclipse.wst.xsl.core.model.XSLAttribute)1