Search in sources :

Example 31 with IDOMDocument

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

the class HTMLValidator method validate.

private HTMLValidationResult validate(IReporter reporter, IFile file, IDOMModel model) {
    if (file == null || model == null)
        // error
        return null;
    IDOMDocument document = model.getDocument();
    if (document == null)
        // error
        return null;
    if (!hasHTMLFeature(document))
        // ignore
        return null;
    INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance();
    ValidationAdapter adapter = (ValidationAdapter) factory.adapt(document);
    if (adapter == null)
        // error
        return null;
    HTMLValidationReporter rep = getReporter(reporter, file, model);
    rep.clear();
    adapter.setReporter(rep);
    adapter.validate(document);
    return rep.getResult();
}
Also used : ValidationAdapter(org.eclipse.wst.sse.core.internal.validate.ValidationAdapter) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) INodeAdapterFactory(org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory)

Example 32 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument 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)

Example 33 with IDOMDocument

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

the class StructuredAutoEditStrategyHTML method isXHTML.

/**
 * Is the node part of an XHTML document
 * @param node
 * @return
 */
private boolean isXHTML(Node node) {
    Document doc = node.getOwnerDocument();
    if (!(doc instanceof IDOMDocument))
        return false;
    String typeid = ((IDOMDocument) doc).getDocumentTypeId();
    if (typeid != null) {
        HTMLDocumentTypeEntry entry = HTMLDocumentTypeRegistry.getInstance().getEntry(typeid);
        return (entry != null && entry.isXMLType());
    }
    return false;
}
Also used : HTMLDocumentTypeEntry(org.eclipse.wst.html.core.internal.document.HTMLDocumentTypeEntry) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IDocument(org.eclipse.jface.text.IDocument) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 34 with IDOMDocument

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

the class HTMLModelQueryCMProvider method getCorrespondingCMDocument.

/**
 * Returns the CMDocument that corresponds to the DOM Node. or null if no
 * CMDocument is appropriate for the DOM Node.
 */
public CMDocument getCorrespondingCMDocument(Node node) {
    IDOMDocument owner = getOwnerXMLDocument(node);
    if (owner == null)
        return null;
    String pid = getPublicId(owner);
    // no PID, always return the currently-supported HTML version
    if (pid == null || "".equals(pid)) {
        return staticHTML5;
    }
    HTMLDocumentTypeEntry entry = doctypeRegistry.getEntry(pid);
    if (entry == null)
        return staticHTML;
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=151000 - use internal content model
    if (entry.useInternalModel()) {
        if (pid != null && pid.equals(HTMLDocumentTypeRegistry.CHTML_PUBLIC_ID)) {
            return staticCHTML;
        }
        return staticHTML;
    }
    pid = entry.getPublicId();
    String sid = entry.getSystemId();
    CMDocument dtdcm = xhtmlassoc.getXHTMLCMDocument(pid, sid);
    if (dtdcm == null) {
        if (pid != null && pid.equals(HTMLDocumentTypeRegistry.CHTML_PUBLIC_ID)) {
            return staticCHTML;
        }
        return staticHTML;
    }
    String grammarURI = xhtmlassoc.getCachedGrammerURI();
    CMDocument buddycm = (CMDocument) buddyCache.get(grammarURI);
    if (buddycm != null)
        return buddycm;
    buddycm = new CMDocumentForBuddySystem(dtdcm, entry.isXMLType());
    buddyCache.put(grammarURI, buddycm);
    return buddycm;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) HTMLDocumentTypeEntry(org.eclipse.wst.html.core.internal.document.HTMLDocumentTypeEntry) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 35 with IDOMDocument

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

the class SyntaxValidator method getInfo.

private void getInfo(ElementInfo info) {
    info.decl = CMUtil.getDeclaration(info.target);
    info.startTag = info.target.getStartStructuredDocumentRegion();
    info.endTag = info.target.getEndStructuredDocumentRegion();
    Document doc = info.target.getOwnerDocument();
    if (!(doc instanceof IDOMDocument))
        return;
    String typeid = ((IDOMDocument) doc).getDocumentTypeId();
    if (typeid != null) {
        if (typeid.trim().length() != 0) {
            HTMLDocumentTypeEntry entry = HTMLDocumentTypeRegistry.getInstance().getEntry(typeid);
            info.isXHTML = (entry != null && entry.isXMLType());
        } else {
            info.isXHTML = getXMLTarget(doc);
            info.isXHTML5 = info.isXHTML;
        }
    }
}
Also used : HTMLDocumentTypeEntry(org.eclipse.wst.html.core.internal.document.HTMLDocumentTypeEntry) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Aggregations

IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)176 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)109 IFile (org.eclipse.core.resources.IFile)48 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)39 Element (org.w3c.dom.Element)39 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)33 NodeList (org.w3c.dom.NodeList)27 IStatus (org.eclipse.core.runtime.IStatus)23 Node (org.w3c.dom.Node)21 CoreException (org.eclipse.core.runtime.CoreException)15 ArrayList (java.util.ArrayList)14 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)14 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)14 Document (org.w3c.dom.Document)14 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 IOException (java.io.IOException)11 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)11 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)10 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)9