Search in sources :

Example 1 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.

the class CMDocumentForBuddySystem method getElements.

/*
	 * @see CMDocument#getElements()
	 */
public CMNamedNodeMap getElements() {
    if (elements != null)
        return elements;
    CMDocument cmdoc = getSelf();
    if (cmdoc == null)
        return null;
    elements = new Elements(cmdoc.getElements(), isXHTML);
    return elements;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)

Example 2 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument 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 3 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.

the class XHTMLAssociationProvider method getXHTMLCMDocument.

/**
 * @param publicId
 * @param systemId
 * @return
 */
public CMDocument getXHTMLCMDocument(String publicId, String systemId) {
    if (idResolver == null)
        return null;
    String grammerURI = null;
    if (USE_QUICK_CACHE) {
        /*
			 * In parsing a document, we get many identical requests to this
			 * method, so instead of looking up (resolving) grammerURI each
			 * time, we'll just return previously cached one. Probably not
			 * worth have a more complex cache than that.
			 */
        if (cached && sameAs(fCachedPublicID, publicId) && sameAs(fCachedSystemID, systemId)) {
            grammerURI = fCachedGrammerURI;
        } else {
            grammerURI = idResolver.resolve(null, publicId, systemId);
            fCachedGrammerURI = grammerURI;
            fCachedPublicID = publicId;
            fCachedSystemID = systemId;
            cached = true;
        }
    } else {
        grammerURI = idResolver.resolve(null, publicId, systemId);
    }
    if (grammerURI == null)
        return null;
    CMDocument cmDocument = null;
    if (CACHE_FIXED_DOCUMENTS) {
        Reference ref = (Reference) fFixedCMDocuments.get(publicId);
        if (ref != null) {
            cmDocument = (CMDocument) ref.get();
            if (cmDocument != null) {
                return cmDocument;
            }
        }
    }
    /*
		 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=88896
		 * 
		 * We once called the deprecated 2 argument form of getCMDocument.
		 * 
		 * CMDocument cmDocument = documentManager.getCMDocument(publicId,
		 * grammerURI);
		 * 
		 * which eventually resulted in empty string for type, which I don't
		 * think the infrastructure handles any longer. So, I deleted
		 * deprecated methods, and switched to null for type argument.
		 * 
		 * 'null' means to "create based on uri".
		 * 
		 * FYI, 'dtd' would mean load only those registered as dtd's
		 * 
		 * CMDocument cmDocument = documentManager.getCMDocument(publicId,
		 * grammerURI); CMDocument cmDocument =
		 * documentManager.getCMDocument(publicId, grammerURI, "dtd");
		 */
    synchronized (grammerURI) {
        cmDocument = documentManager.getCMDocument(publicId, grammerURI, null);
    }
    if (CACHE_FIXED_DOCUMENTS && getFixedPublicIDs().contains(publicId)) {
        fFixedCMDocuments.put(publicId, new SoftReference(cmDocument));
    }
    return cmDocument;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) SoftReference(java.lang.ref.SoftReference) Reference(java.lang.ref.Reference) SoftReference(java.lang.ref.SoftReference)

Example 4 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.

the class CMDocumentManagerImpl method loadCMDocument.

protected CMDocument loadCMDocument(final String publicId, final String resolvedURI, final String type, boolean async) {
    CMDocument result = null;
    // System.out.println("about to build CMDocument(" + publicId + ", " + unresolvedURI + " = " + resolvedURI + ")");
    if (async) {
        cmDocumentCache.setStatus(resolvedURI, CMDocumentCache.STATUS_LOADING);
        // Thread thread = new Thread(new AsyncBuildOperation(publicId, resolvedURI, type));
        // thread.start();
        Job job = new Job(XMLCoreMessages.loading + resolvedURI) {

            public boolean belongsTo(Object family) {
                boolean result = (family == CMDocumentManager.class);
                return result;
            }

            protected IStatus run(IProgressMonitor monitor) {
                try {
                    buildCMDocument(publicId, resolvedURI, type);
                } catch (Exception e) {
                    Logger.logException(MessageFormat.format(XMLCoreMessages.CMDocument_load_exception, new Object[] { resolvedURI, publicId }), e);
                }
                return Status.OK_STATUS;
            }
        };
        job.schedule();
    } else {
        result = buildCMDocument(publicId, resolvedURI, type);
    }
    return result;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager) Job(org.eclipse.core.runtime.jobs.Job)

Example 5 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.

the class InferredGrammarBuildingCMDocumentLoader method handleElementNS.

public void handleElementNS(Element element) {
    CMDocument parentInferredCMDocument = inferredCMDocument;
    CMElementDeclaration parentInferredCMElementDeclaration = inferredCMElementDeclaration;
    inferredCMDocument = null;
    inferredCMElementDeclaration = null;
    // by adding the element to the namespaceTable, handleGrammar() will get called for any schema references
    if (element.getParentNode() != document) {
        namespaceTable.addElement(element);
    }
    String prefix = element.getPrefix();
    String uri = namespaceTable.getURIForPrefix(prefix);
    if (uri == null && element.getParentNode() == document) {
        // when this is the root element
        // we need to add an implied "no namespace schema location"
        // $NON-NLS-1$
        uri = "ommitted-namespace";
        // $NON-NLS-1$
        namespaceTable.addNamespaceInfo(prefix, uri, "");
    }
    // here's where we update the inferred grammar if required
    // 
    boolean createCMElementDeclaration = true;
    boolean isLocal = (uri == null && prefix == null);
    if (isLocal) {
        if (parentInferredCMDocument == null) {
            // this is a local element... and the parent is not inferred (e.g) it has a known grammar
            // so we don't need to create an element declaration for this element
            createCMElementDeclaration = false;
        } else {
            if (uri == null) {
                // $NON-NLS-1$
                uri = "ommitted-namespace";
            }
        }
    }
    if (createCMElementDeclaration) {
        if (isLocal) {
            inferredCMDocument = parentInferredCMDocument;
            inferredCMElementDeclaration = inferredGrammarFactory.createCMElementDeclaration(inferredCMDocument, element, true);
        } else {
            boolean createCMDocument = false;
            // $NON-NLS-1$
            String cacheKey = "inferred-document" + uri;
            inferredCMDocument = (CMDocument) createdCMDocumentTable.get(cacheKey);
            if (inferredCMDocument == null) {
                // we don't have an inferred document for this uri yet... let's see of we need one
                int status = cmDocumentManager.getCMDocumentStatus(uri);
                if (status == CMDocumentCache.STATUS_NOT_LOADED || status == CMDocumentCache.STATUS_ERROR) {
                    // the cache does not contain a 'proper' CMDocument for this uri
                    // so we need to create an inferred one
                    createCMDocument = true;
                }
            }
            if (createCMDocument) {
                // System.out.println("encountered element {" + element.getNodeName() + "} ... creating inferred CMDocument for " + uri);
                inferredCMDocument = inferredGrammarFactory.createCMDocument(uri);
                // $NON-NLS-1$ //$NON-NLS-2$
                cmDocumentManager.addCMDocument(uri, "", cacheKey, "XSD", inferredCMDocument);
                createdCMDocumentTable.put(cacheKey, inferredCMDocument);
            }
            if (inferredCMDocument != null) {
                inferredCMElementDeclaration = inferredGrammarFactory.createCMElementDeclaration(inferredCMDocument, element, false);
            }
        }
        if (parentInferredCMElementDeclaration != null) {
            inferredGrammarFactory.createCMContent(parentInferredCMDocument, parentInferredCMElementDeclaration, inferredCMDocument, inferredCMElementDeclaration, isLocal, uri);
        }
    }
    visitChildNodes(element);
    // reset the 'current' state to inital values
    inferredCMElementDeclaration = parentInferredCMElementDeclaration;
    inferredCMDocument = parentInferredCMDocument;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)

Aggregations

CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)83 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)33 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)26 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)20 List (java.util.List)15 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)14 Document (org.w3c.dom.Document)12 Element (org.w3c.dom.Element)11 ArrayList (java.util.ArrayList)10 Path (org.eclipse.core.runtime.Path)8 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)8 JSPCMDocument (org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument)7 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 URL (java.net.URL)6 TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)6 Node (org.w3c.dom.Node)6 NodeList (org.w3c.dom.NodeList)6 Iterator (java.util.Iterator)5 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)5