Search in sources :

Example 16 with URIResolver

use of org.eclipse.wst.sse.core.internal.util.URIResolver in project webtools.sourceediting by eclipse.

the class ElementImplTests method getModelForRead.

public IStructuredModel getModelForRead(String path) {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        InputStream inStream = getClass().getResourceAsStream(path);
        if (inStream == null)
            throw new FileNotFoundException("Can't file resource stream " + path);
        final String baseFile = getClass().getResource(path).toString();
        model = modelManager.getModelForRead(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 17 with URIResolver

use of org.eclipse.wst.sse.core.internal.util.URIResolver in project webtools.sourceediting by eclipse.

the class TestPartitionFormatterXML 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)

Aggregations

URIResolver (org.eclipse.wst.sse.core.internal.util.URIResolver)17 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)12 IProject (org.eclipse.core.resources.IProject)10 FileNotFoundException (java.io.FileNotFoundException)7 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 IPath (org.eclipse.core.runtime.IPath)5 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)5 IContainer (org.eclipse.core.resources.IContainer)4 IFile (org.eclipse.core.resources.IFile)4 Path (org.eclipse.core.runtime.Path)4 IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)3 ProjectResolver (org.eclipse.wst.sse.core.internal.util.ProjectResolver)3 FileInputStream (java.io.FileInputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 ResourceInUse (org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1