Search in sources :

Example 71 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class AbstractPsychoPathWTPTest method load.

public Document load(java.net.URL url) throws Exception {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    InputStream inStream = url.openStream();
    if (inStream == null)
        throw new FileNotFoundException("Can't file resource stream " + url.getFile());
    model = (IDOMModel) modelManager.getModelForRead(url.toString(), inStream, null);
    return model.getDocument();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) FileNotFoundException(java.io.FileNotFoundException)

Example 72 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class TestCleanupProcessorXML method getModelForEdit.

/**
 * must release model (from edit) after
 *
 * @param filename
 *            relative to this class (TestCleanupProcessorXML)
 */
private IStructuredModel getModelForEdit(final String filename) {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        InputStream inStream = getClass().getResourceAsStream(filename);
        if (inStream == null)
            throw new FileNotFoundException("Can't file resource stream " + filename);
        final String baseFile = getClass().getResource(filename).toString();
        model = modelManager.getModelForEdit(baseFile, inStream, new URIResolver() {

            String fBase = baseFile;

            public String getFileBaseLocation() {
                return fBase;
            }

            public String getLocationByURI(String uri) {
                return getLocationByURI(uri, fBase);
            }

            public String getLocationByURI(String uri, boolean resolveCrossProjectLinks) {
                return getLocationByURI(uri);
            }

            public String getLocationByURI(String uri, String baseReference) {
                int lastSlash = baseReference.lastIndexOf("/");
                if (lastSlash > 0)
                    return baseReference.substring(0, lastSlash + 1) + uri;
                return baseReference;
            }

            public String getLocationByURI(String uri, String baseReference, boolean resolveCrossProjectLinks) {
                return getLocationByURI(uri, baseReference);
            }

            public IProject getProject() {
                return null;
            }

            public IContainer getRootLocation() {
                return null;
            }

            public InputStream getURIStream(String uri) {
                return getClass().getResourceAsStream(getLocationByURI(uri));
            }

            public void setFileBaseLocation(String newLocation) {
                this.fBase = newLocation;
            }

            public void setProject(IProject newProject) {
            }
        });
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return model;
}
Also used : InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) FileNotFoundException(java.io.FileNotFoundException) URIResolver(org.eclipse.wst.sse.core.internal.util.URIResolver) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject)

Example 73 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class XSITypeTest method testXSIType.

public void testXSIType() {
    IStructuredModel structuredModel = null;
    try {
        // $NON-NLS-1$
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(PROJECT_NAME + "/test.xml"));
        IModelManager modelManager = StructuredModelManager.getModelManager();
        structuredModel = modelManager.getModelForRead(file);
        Document document = ((IDOMModel) structuredModel).getDocument();
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
        NodeList nodeList = null;
        CMElementDeclaration cmElementDeclaration = null;
        // Check for local XSI type
        // $NON-NLS-1$
        nodeList = document.getElementsByTagName("a");
        cmElementDeclaration = modelQuery.getCMElementDeclaration((Element) nodeList.item(0));
        // $NON-NLS-1$
        assertNotNull("Local XSI type failed to be resolved", cmElementDeclaration);
        // Check for external XSI type
        // $NON-NLS-1$
        nodeList = document.getElementsByTagName("b");
        cmElementDeclaration = modelQuery.getCMElementDeclaration((Element) nodeList.item(0));
        // $NON-NLS-1$
        assertNotNull("External XSI type failed to be resolved", cmElementDeclaration);
    } catch (Exception exception) {
        exception.printStackTrace();
    } finally {
        if (structuredModel != null) {
            structuredModel.releaseFromRead();
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Document(org.w3c.dom.Document)

Example 74 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class TestFormatProcessorXML method getModelForEdit.

/**
 * must release model (from edit) after
 *
 * @param filename
 *            relative to this class (TestStructuredPartitioner)
 */
private IStructuredModel getModelForEdit(final String filename) {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        InputStream inStream = getClass().getResourceAsStream(filename);
        if (inStream == null)
            throw new FileNotFoundException("Can't file resource stream " + filename);
        final String baseFile = getClass().getResource(filename).toString();
        model = modelManager.getModelForEdit(baseFile, inStream, new URIResolver() {

            String fBase = baseFile;

            public String getFileBaseLocation() {
                return fBase;
            }

            public String getLocationByURI(String uri) {
                return getLocationByURI(uri, fBase);
            }

            public String getLocationByURI(String uri, boolean resolveCrossProjectLinks) {
                return getLocationByURI(uri);
            }

            public String getLocationByURI(String uri, String baseReference) {
                int lastSlash = baseReference.lastIndexOf("/");
                if (lastSlash > 0)
                    return baseReference.substring(0, lastSlash + 1) + uri;
                return baseReference;
            }

            public String getLocationByURI(String uri, String baseReference, boolean resolveCrossProjectLinks) {
                return getLocationByURI(uri, baseReference);
            }

            public IProject getProject() {
                return null;
            }

            public IContainer getRootLocation() {
                return null;
            }

            public InputStream getURIStream(String uri) {
                return getClass().getResourceAsStream(getLocationByURI(uri));
            }

            public void setFileBaseLocation(String newLocation) {
                this.fBase = newLocation;
            }

            public void setProject(IProject newProject) {
            }
        });
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return model;
}
Also used : InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) FileNotFoundException(java.io.FileNotFoundException) URIResolver(org.eclipse.wst.sse.core.internal.util.URIResolver) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject)

Example 75 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class DTDFileTest method testGetTopLevelNodeAt.

public void testGetTopLevelNodeAt() throws Exception {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    DTDModelImpl model = (DTDModelImpl) modelManager.createUnManagedStructuredModelFor(ContentTypeIdForDTD.ContentTypeID_DTD);
    String dtdText = "<!ELEMENT NewElement3 (#PCDATA)><!ENTITY % NewEntity SYSTEM \"\" >";
    IStructuredDocument document = model.getStructuredDocument();
    document.set(dtdText);
    model.setStructuredDocument(document);
    DTDFile dtdFile = model.getDTDFile();
    DTDNode dtdNode = dtdFile.getTopLevelNodeAt(32);
    assertNotNull("Node is null", dtdNode);
    assertEquals("Unexpected Node Type.", "NewEntity", dtdNode.getName());
}
Also used : DTDModelImpl(org.eclipse.wst.dtd.core.internal.document.DTDModelImpl) DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) DTDFile(org.eclipse.wst.dtd.core.internal.DTDFile)

Aggregations

IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)139 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)102 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)45 IOException (java.io.IOException)37 InputStream (java.io.InputStream)27 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)27 IFile (org.eclipse.core.resources.IFile)23 CoreException (org.eclipse.core.runtime.CoreException)21 BadLocationException (org.eclipse.jface.text.BadLocationException)13 FileNotFoundException (java.io.FileNotFoundException)12 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)11 Document (org.w3c.dom.Document)10 ArrayList (java.util.ArrayList)9 IProject (org.eclipse.core.resources.IProject)9 StringBufferInputStream (java.io.StringBufferInputStream)8 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)7 IDocument (org.eclipse.jface.text.IDocument)6 PageDirectiveAdapter (org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)6 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5