Search in sources :

Example 16 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel 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 17 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class CSSFormatUtil method collectCSSNodes.

public List collectCSSNodes(IStructuredModel model, int start, int length) {
    List nodes = new ArrayList();
    IndexedRegion startNode = model.getIndexedRegion(start);
    IndexedRegion endNode = model.getIndexedRegion(start + length - 1);
    if (startNode == null || endNode == null) {
        return nodes;
    }
    if (model instanceof ICSSModel && startNode instanceof ICSSNode && endNode instanceof ICSSNode) {
        // CSS model
        ICSSNode ca = getCommonAncestor((ICSSNode) startNode, (ICSSNode) endNode);
        if (ca != null) {
            for (ICSSNode node = ca.getFirstChild(); node != null && start + length < ((IndexedRegion) node).getStartOffset(); node = node.getNextSibling()) {
                if (start < ((IndexedRegion) node).getEndOffset()) {
                    nodes.add(node);
                }
            }
        }
    } else if (model instanceof IDOMModel && startNode instanceof IDOMNode && endNode instanceof IDOMNode) {
        if (startNode instanceof Text) {
            startNode = (IndexedRegion) ((Text) startNode).getParentNode();
        }
        if (endNode instanceof Text) {
            endNode = (IndexedRegion) ((Text) endNode).getParentNode();
        }
        // HTML model, maybe
        IDOMNode ca = (IDOMNode) getCommonAncestor((Node) startNode, (Node) endNode);
        findCSS(nodes, ca);
    }
    return nodes;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Text(org.w3c.dom.Text) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 18 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel 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 19 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class HTMLValidator method validateFile.

/**
 * @param result
 */
private void validateFile(IValidationContext helper, IReporter reporter, IFile file, ValidationResult result) {
    if ((reporter != null) && (reporter.isCancelled() == true)) {
        throw new OperationCanceledException();
    }
    if (!shouldValidate(file)) {
        return;
    }
    IDOMModel model = getModel(file.getProject(), file);
    if (model == null)
        return;
    try {
        Collection dependencies = null;
        NodeImpl document = null;
        if (model.getDocument() instanceof NodeImpl) {
            document = (NodeImpl) model.getDocument();
        }
        if (result != null && document != null) {
            dependencies = new HashSet();
            document.setUserData(HTMLValidationAdapterFactory.DEPENDENCIES, dependencies, null);
        }
        validate(reporter, file, model);
        if (result != null && document != null) {
            document.setUserData(HTMLValidationAdapterFactory.DEPENDENCIES, null, null);
            result.setDependsOn((IResource[]) dependencies.toArray(new IResource[dependencies.size()]));
        }
    } finally {
        releaseModel(model);
    }
}
Also used : NodeImpl(org.eclipse.wst.xml.core.internal.document.NodeImpl) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Collection(java.util.Collection) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 20 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class URLModelProvider method resolveURI.

/**
 * <code>baseModel</code>: the model containing the link
 * <code>ref</code>: the link URL string
 * <code>resolveCrossProjectLinks</code>: If resolveCrossProjectLinks
 * is set to true, then this method will properly resolve the URI if it is
 * a valid URI pointing to another (appropriate) project.
 */
public static String resolveURI(IStructuredModel baseModel, String ref, boolean resolveCrossProjectLinks) {
    if (baseModel == null)
        return null;
    // for HTML, 'href' attribute value of BASE element
    // should be used, if exists any
    String baseHref = null;
    // of HTML or XHTML
    if (isHTMLFamily(baseModel)) {
        final IDOMModel xmlmodel = (IDOMModel) baseModel;
        final IDOMDocument doc = xmlmodel.getDocument();
        // look for <BASE> w/ href
        // $NON-NLS-1$
        final NodeList nl = doc.getElementsByTagName("BASE");
        if ((nl != null) && (nl.getLength() > 0)) {
            // per each <BASE>
            for (int i = 0; i < nl.getLength(); i++) {
                final Node baseNode = nl.item(i);
                if (baseNode != null) {
                    // get all attrs
                    final NamedNodeMap attrNodes = baseNode.getAttributes();
                    if (attrNodes != null) {
                        // $NON-NLS-1$
                        final Node attrNode = attrNodes.getNamedItem("HREF");
                        if (attrNode != null) {
                            // found href=""
                            final String attrValue = attrNode.getNodeValue();
                            if (attrValue != null) {
                                baseHref = attrValue.trim();
                            }
                        }
                    }
                }
                // what if there are multiple <BASE> tags ??
                if (baseHref != null) {
                    break;
                }
            }
        }
    }
    // get resolver in Model
    final URIResolver resolver = baseModel.getResolver();
    // resolve to absolute url
    final String absurl = (resolver != null) ? ((baseHref != null) ? resolver.getLocationByURI(ref, baseHref, resolveCrossProjectLinks) : resolver.getLocationByURI(ref, resolveCrossProjectLinks)) : null;
    if ((resolver != null) && (absurl == null) && (ref != null) && (ref.trim().length() > 0) && (ref.trim().charAt(0) == '/')) {
        // so that href is a broken and should not create model
        return null;
    }
    if ((absurl != null) && (absurl.length() > 0)) {
        return absurl;
    }
    // maybe ref is at outside of the Project
    // obtain docroot;
    final IContainer container = (resolver != null) ? resolver.getRootLocation() : null;
    String docroot = null;
    if (container != null) {
        IPath containerLocation = container.getLocation();
        if (containerLocation != null) {
            docroot = containerLocation.toString();
        } else if (container.getLocationURI() != null) {
            docroot = container.getLocationURI().toString();
        }
    }
    if (docroot == null) {
        docroot = baseModel.getBaseLocation();
    }
    if (docroot == null) {
        // should not be
        return null;
    }
    // obtain document url
    String modelBaseLocation = baseModel.getBaseLocation();
    if ((modelBaseLocation == null) || (modelBaseLocation.length() == 0)) {
        // fallback...
        modelBaseLocation = baseModel.getId();
    }
    if ((modelBaseLocation == null) || (modelBaseLocation.length() == 0)) {
        // i can't resolve uri !
        return null;
    }
    // resolve url
    URLHelper helper = new URLHelper(PathHelper.getContainingFolderPath(modelBaseLocation), PathHelper.getContainingFolderPath(PathHelper.appendTrailingURLSlash(docroot)));
    return helper.toAbsolute(ref);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IPath(org.eclipse.core.runtime.IPath) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) URIResolver(org.eclipse.wst.sse.core.internal.util.URIResolver) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IContainer(org.eclipse.core.resources.IContainer)

Aggregations

IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)433 Document (org.w3c.dom.Document)123 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)120 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)110 Element (org.w3c.dom.Element)109 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)103 Node (org.w3c.dom.Node)57 IFile (org.eclipse.core.resources.IFile)56 NodeList (org.w3c.dom.NodeList)47 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)45 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)44 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)41 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)41 Text (org.w3c.dom.Text)39 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)35 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)28 IOException (java.io.IOException)26 CoreException (org.eclipse.core.runtime.CoreException)26 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)26 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)25