Search in sources :

Example 11 with IStructuredModel

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

the class URLModelProvider method getModelForEdit.

/**
 */
private IStructuredModel getModelForEdit(IFile file) throws IOException {
    if (file == null)
        return null;
    IModelManager manager = getModelManager();
    // create a fake InputStream
    IStructuredModel model = null;
    try {
        model = manager.getModelForEdit(file);
    } catch (UnsupportedCharsetException ex) {
        try {
            model = manager.getModelForEdit(file, EncodingRule.FORCE_DEFAULT);
        } catch (IOException ioe) {
        } catch (CoreException ce) {
        }
    } catch (CoreException ce) {
    }
    return model;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 12 with IStructuredModel

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

the class URLModelProvider method getModelForRead.

/**
 */
private IStructuredModel getModelForRead(IFile file) throws IOException {
    if (file == null)
        return null;
    IModelManager manager = getModelManager();
    // create a fake InputStream
    IStructuredModel model = null;
    try {
        model = manager.getModelForRead(file);
    } catch (UnsupportedCharsetException ex) {
        try {
            model = manager.getModelForRead(file, EncodingRule.FORCE_DEFAULT);
        } catch (IOException ioe) {
        } catch (CoreException ce) {
        }
    } catch (CoreException ce) {
    }
    return model;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 13 with IStructuredModel

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

the class AnchorHyperlinkDetector method getCurrentNode.

/**
 * Returns the node the cursor is currently on in the document. null if no
 * node is selected
 *
 * @param offset
 * @return Node either element, doctype, text, or null
 */
private Node getCurrentNode(IDocument document, int offset) {
    // get the current node at the offset (returns either: element,
    // doctype, text)
    IndexedRegion inode = null;
    IStructuredModel sModel = null;
    try {
        sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document);
        if (sModel != null) {
            inode = sModel.getIndexedRegion(offset);
            if (inode == null) {
                inode = sModel.getIndexedRegion(offset - 1);
            }
        }
    } finally {
        if (sModel != null)
            sModel.releaseFromRead();
    }
    if (inode instanceof Node) {
        return (Node) inode;
    }
    return null;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 14 with IStructuredModel

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

the class LinkElementAdapter method retrieveModel.

/**
 */
private ICSSModel retrieveModel() {
    if (!isValidAttribute()) {
        return null;
    }
    // null,attr check is done in isValidAttribute()
    Element element = getElement();
    // $NON-NLS-1$
    String href = element.getAttribute("href");
    IDOMModel baseModel = ((IDOMNode) element).getModel();
    if (baseModel == null)
        return null;
    Object id = baseModel.getId();
    if (!(id instanceof String))
        return null;
    // String base = (String)id;
    // get ModelProvideAdapter
    IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(ModelProvideAdapterClass);
    URLModelProvider provider = new URLModelProvider();
    try {
        IStructuredModel newModel = provider.getModelForRead(baseModel, href);
        if (newModel == null)
            return null;
        if (!(newModel instanceof ICSSModel)) {
            newModel.releaseFromRead();
            return null;
        }
        // notify adapter
        if (adapter != null)
            adapter.modelProvided(newModel);
        return (ICSSModel) newModel;
    } catch (UnsupportedEncodingException e) {
    } catch (IOException e) {
    }
    return null;
}
Also used : IModelProvideAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 15 with IStructuredModel

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

the class LinkElementAdapter method createModel.

protected ICSSModel createModel() {
    // create phantom(broken link) external CSS model
    if (getElement() == null)
        return null;
    IStructuredModel baseModel = ((IDOMNode) getElement()).getModel();
    ICSSModel newModel = (ICSSModel) baseModel.getModelManager().createUnManagedStructuredModelFor(CSS_ID);
    // calculate base location and set
    // get resolver in Model
    URIResolver resolver = baseModel.getResolver();
    // resolve to absolute url : this need not exact location of css file. It is important that absurl is not null.
    String ref = getElement().getAttribute(HTML40Namespace.ATTR_NAME_HREF);
    String absurl = (resolver != null && ref != null && ref.length() > 0) ? resolver.getLocationByURI(ref, true) : null;
    if ((absurl == null) || (absurl.length() == 0)) {
        IPath basePath = new Path(baseModel.getBaseLocation());
        URLHelper helper = new URLHelper(basePath.removeLastSegments(1).toString());
        // $NON-NLS-1$
        absurl = helper.toAbsolute(ref == null ? "" : ref);
    }
    if ((absurl == null) || (absurl.length() == 0)) {
        absurl = ref;
    }
    if (absurl == null) {
        // $NON-NLS-1$
        absurl = "";
    }
    newModel.setBaseLocation(absurl);
    // set style listener
    newModel.addStyleListener(this);
    return newModel;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) URIResolver(org.eclipse.wst.sse.core.internal.util.URIResolver) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Aggregations

IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)482 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)110 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)102 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)81 IFile (org.eclipse.core.resources.IFile)75 IOException (java.io.IOException)69 CoreException (org.eclipse.core.runtime.CoreException)49 IDocument (org.eclipse.jface.text.IDocument)46 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)42 InputStream (java.io.InputStream)40 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)36 Path (org.eclipse.core.runtime.Path)35 BadLocationException (org.eclipse.jface.text.BadLocationException)34 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)32 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)32 IProject (org.eclipse.core.resources.IProject)31 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)31 IPath (org.eclipse.core.runtime.IPath)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 Document (org.w3c.dom.Document)19