Search in sources :

Example 6 with IStructuredModel

use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project jbosstools-hibernate by jbosstools.

the class SQLTypeContentProvider method getElements.

public Object[] getElements(Object inputElement) {
    IStructuredModel im = (IStructuredModel) inputElement;
    if (im instanceof IDOMModel) {
        IDOMModel model = (IDOMModel) im;
        // $NON-NLS-1$
        List childNodes = DOMModelUtil.getChildrenByTagName(model.getDocument(), "hibernate-reverse-engineering");
        if (childNodes.size() >= 1) {
            Element l = (Element) childNodes.get(0);
            // $NON-NLS-1$
            childNodes = DOMModelUtil.getChildrenByTagName(l, "type-mapping");
            if (childNodes.size() >= 1) {
                // $NON-NLS-1$
                childNodes = DOMModelUtil.getChildrenByTagName(l, "sql-type");
                Object[] o = new Object[childNodes.size()];
                for (int i = 0; i < childNodes.size(); i++) {
                    o[i] = childNodes.get(i);
                }
                return o;
            }
        }
    }
    return new Object[0];
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) List(java.util.List) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 7 with IStructuredModel

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

the class StructureSelectAction method getIndexedRegion.

protected IndexedRegion getIndexedRegion(int offset) {
    IndexedRegion indexedRegion = null;
    int lastOffset = offset;
    IDocument document = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
    IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
    if (model != null) {
        try {
            indexedRegion = model.getIndexedRegion(lastOffset);
            while (indexedRegion == null && lastOffset >= 0) {
                lastOffset--;
                indexedRegion = model.getIndexedRegion(lastOffset);
            }
        } finally {
            model.releaseFromRead();
        }
    }
    return indexedRegion;
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) IDocument(org.eclipse.jface.text.IDocument)

Example 8 with IStructuredModel

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

the class StructuredSelectActionDelegate method getIndexedRegion.

/**
 * This method will probably be removed and replaced by using new selection provider
 * @param document
 * @param offset
 * @return
 */
protected IndexedRegion getIndexedRegion(IDocument document, int offset) {
    IndexedRegion indexedRegion = null;
    int lastOffset = offset;
    IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
    if (model != null) {
        try {
            indexedRegion = model.getIndexedRegion(lastOffset);
            while (indexedRegion == null && lastOffset >= 0) {
                lastOffset--;
                indexedRegion = model.getIndexedRegion(lastOffset);
            }
        } finally {
            model.releaseFromRead();
        }
    }
    return indexedRegion;
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 9 with IStructuredModel

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

the class HTMLValidator method getModel.

/**
 */
protected IDOMModel getModel(IProject project, IFile file) {
    if (project == null || file == null)
        return null;
    if (!file.exists())
        return null;
    if (!canHandle(file))
        return null;
    IModelManager manager = StructuredModelManager.getModelManager();
    if (manager == null)
        return null;
    IStructuredModel model = null;
    try {
        file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
    } catch (CoreException e) {
        Logger.logException(e);
    }
    try {
        try {
            model = manager.getModelForRead(file);
        } catch (UnsupportedEncodingException ex) {
            // retry ignoring META charset for invalid META charset
            // specification
            // recreate input stream, because it is already partially read
            model = manager.getModelForRead(file, new String(), null);
        }
    } catch (UnsupportedEncodingException ex) {
    } catch (IOException ex) {
    } catch (CoreException e) {
        Logger.logException(e);
    }
    if (model == null)
        return null;
    if (!(model instanceof IDOMModel)) {
        releaseModel(model);
        return null;
    }
    return (IDOMModel) model;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 10 with IStructuredModel

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

the class URLModelProvider method getCommonModelFor.

/**
 * <code>baseModel</code>: the model containing the link
 * <code>ref</code>: the link URL string
 */
private IStructuredModel getCommonModelFor(final IStructuredModel baseModel, final String ref, final int which) throws IOException {
    // first, create absolute url
    String absURL = resolveURI(baseModel, ref, true);
    if ((absURL == null) || (absURL.length() == 0)) {
        return null;
    }
    // need to remove file:// scheme if necessary
    try {
        final java.net.URL aURL = new java.net.URL(absURL);
        // resolve it by finding the file it points to
        if (!aURL.getProtocol().equals("platform")) {
            // $NON-NLS-1$
            if (aURL.getProtocol().equals("file") && (aURL.getHost().equals("localhost") || aURL.getHost().length() == 0)) {
                // $NON-NLS-2$//$NON-NLS-1$
                absURL = aURL.getFile();
                final IPath ipath = new Path(absURL);
                // if path has a device, and if it begins with
                // IPath.SEPARATOR, remove it
                final String device = ipath.getDevice();
                if ((device != null) && (device.length() > 0)) {
                    if (device.charAt(0) == IPath.SEPARATOR) {
                        final String newDevice = device.substring(1);
                        absURL = ipath.setDevice(newDevice).toString();
                    }
                }
            }
        }
    } catch (java.net.MalformedURLException mfuExc) {
    }
    // next, decide project
    IProject project = null;
    final IPath fullIPath = new Path(absURL);
    IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot();
    IContainer container = workspace.getContainerForLocation(fullIPath);
    if (container != null) {
        // fullIPath doesn't exist in workspace
        project = container.getProject();
    }
    // now, get absURL's IFile
    if ((project != null) && (project.getLocation().isPrefixOf(fullIPath) == false)) {
        // it's at outside of Project
        return null;
    }
    IStructuredModel model = null;
    if (project != null) {
        IPath filePath = fullIPath.removeFirstSegments(project.getLocation().segmentCount());
        IFile file = (filePath != null && !filePath.isEmpty()) ? project.getFile(filePath) : null;
        if (file == null) {
            return null;
        }
        // obtain model
        if (which == GET_MODEL_FOR_EDIT) {
            model = getModelForEdit(file);
        } else if (which == GET_MODEL_FOR_READ) {
            model = getModelForRead(file);
        }
        // responsibility
        if (model != null && model.getSynchronizationStamp() == IResource.NULL_STAMP)
            model.resetSynchronizationStamp(file);
    } else {
        String id = null;
        InputStream inStream = null;
        // obtain resolver
        URIResolver resolver = (project != null) ? (URIResolver) project.getAdapter(URIResolver.class) : null;
        if (resolver == null) {
            // ProjectResolver can take care of the case if project is
            // null.
            resolver = new ProjectResolver(project);
        }
        if (resolver == null) {
            return null;
        }
        // there is no project. we can't expect IProject help to create
        // id/inputStream
        java.io.File file = fullIPath.toFile();
        // obatin id
        id = calculateId(fullIPath);
        // obtain InputStream
        try {
            inStream = new FileInputStream(file);
        } catch (FileNotFoundException fnfe) {
            // the file does not exist, or we don't have read permission
            return null;
        }
        // obtain model
        try {
            if (which == GET_MODEL_FOR_EDIT) {
                model = getModelManager().getModelForEdit(id, inStream, resolver);
            } else if (which == GET_MODEL_FOR_READ) {
                model = getModelManager().getModelForRead(id, inStream, resolver);
            }
        } catch (UnsupportedEncodingException ue) {
        } catch (IOException ioe) {
        } finally {
            // close now !
            if (inStream != null) {
                inStream.close();
            }
        }
    }
    // set locationid
    if (model != null && model.getBaseLocation() == null) {
        model.setBaseLocation(fullIPath.toString());
    }
    return model;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ProjectResolver(org.eclipse.wst.sse.core.internal.util.ProjectResolver) FileNotFoundException(java.io.FileNotFoundException) URIResolver(org.eclipse.wst.sse.core.internal.util.URIResolver) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) FileInputStream(java.io.FileInputStream) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IContainer(org.eclipse.core.resources.IContainer)

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