Search in sources :

Example 76 with CMDocument

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

the class GlobalCMDocumentCacheTest method testGlobalCMDocumentCacheDisabled.

/*
	 * Test description:
	 *  - Disable global cache.
	 *  - Schema GlobalCMDocumentCacheTestSchema.xsd is contributed to the system catalog.
	 *  - Load documents "GlobalCMDocumentCacheTest1.xml" and "GlobalCMDocumentCacheTest1.xml".
	 *  - Verify that the associated CMDocuments are different (not cached).
	 *  - Load documents "document1.xml" and "document2.xml".  (local schema, not in catalog).  
	 *  - Verify that the associated CMDocuments are different (not cached, as the schema is not in system catalog).
	 */
public void testGlobalCMDocumentCacheDisabled() {
    // Ensure the global cache is disabled.
    setGlobalCacheEnabled(false);
    // Load "web1.xml" and "web2.xml"
    // $NON-NLS-1$
    CMDocument globalCMDocumentCacheTest_1 = getCMDocumentFromXMLFile(PROJECT_NAME + "/GlobalCMDocumentCacheTest1.xml");
    // $NON-NLS-1$
    CMDocument globalCMDocumentCacheTest_2 = getCMDocumentFromXMLFile(PROJECT_NAME + "/GlobalCMDocumentCacheTest2.xml");
    // Ensure CMDocuments are different.
    assertNotSame(globalCMDocumentCacheTest_1, globalCMDocumentCacheTest_2);
    // Load "document1.xml" and "document2.xml"
    // $NON-NLS-1$
    CMDocument localCMDocument_1 = getCMDocumentFromXMLFile(PROJECT_NAME + "/document1.xml");
    // $NON-NLS-1$
    CMDocument localCMDocument_2 = getCMDocumentFromXMLFile(PROJECT_NAME + "/document2.xml");
    // Ensure CMDocuments are different.
    assertNotSame(localCMDocument_1, localCMDocument_2);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)

Example 77 with CMDocument

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

the class TestCatalogRetrivalAndModelCreation method doCMTest.

private void doCMTest(String EXPECTED_PUBLICID) throws MalformedURLException, IOException {
    ICatalog xmlCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
    String resolved = xmlCatalog.resolvePublic(EXPECTED_PUBLICID, null);
    ContentModelManager contentModelManager = ContentModelManager.getInstance();
    CMDocument contentModel = contentModelManager.createCMDocument(resolved, null);
    assertNotNull("expected to create content model for " + EXPECTED_PUBLICID, contentModel);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog) ContentModelManager(org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager)

Example 78 with CMDocument

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

the class TestCatalogRetrivalAndModelCreation method doCM_directURITest.

private void doCM_directURITest(String EXPECTED_URI) throws MalformedURLException, IOException {
    ContentModelManager contentModelManager = ContentModelManager.getInstance();
    CMDocument contentModel = contentModelManager.createCMDocument(EXPECTED_URI, null);
    assertNotNull("expected to create content model for " + EXPECTED_URI, contentModel);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) ContentModelManager(org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager)

Example 79 with CMDocument

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

the class TLDCMDocumentManager method loadTaglib.

/**
 * Loads the taglib from the specified URI. It must point to a valid
 * taglib descriptor to work.
 */
protected CMDocument loadTaglib(String uri) {
    CMDocument document = null;
    IPath currentPath = getCurrentParserPath();
    if (currentPath != null) {
        ITaglibRecord record = TaglibIndex.resolve(currentPath.toString(), uri, false);
        if (record != null) {
            document = getCMDocumentBuilder().createCMDocument(record);
        } else {
            /* Not a very-often used code path (we hope) */
            IPath currentBaseLocation = getCurrentBaseLocation();
            if (currentBaseLocation != null) {
                String location = URIResolverPlugin.createResolver().resolve(currentBaseLocation.toString(), null, uri);
                if (location != null) {
                    if (_debug) {
                        // $NON-NLS-2$//$NON-NLS-1$
                        System.out.println("Loading tags from " + uri + " at " + location);
                    }
                    document = getCMDocumentBuilder().createCMDocument(location);
                }
            }
        }
    }
    return document;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IPath(org.eclipse.core.runtime.IPath) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord)

Example 80 with CMDocument

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

the class TLDCMDocumentManager method getCMDocument.

/**
 * Return the CMDocument at the uri (cached)
 */
protected CMDocument getCMDocument(String uri) {
    if (uri == null || uri.length() == 0)
        return null;
    String reference = uri;
    Object cacheKey = getCacheKey(reference);
    if (cacheKey == null)
        return null;
    CMDocument doc = (CMDocument) getDocuments().get(cacheKey);
    if (doc == null) {
        long lastModified = getModificationStamp(reference);
        /*
			 * If hasn't been moved into the local table, do so and increment
			 * the count. A local URI reference can be different depending on
			 * the file from which it was referenced. Use a computed key to
			 * keep them straight.
			 */
        Object o = getSharedDocumentCache().get(cacheKey);
        if (o != null) {
            if (o instanceof TLDCacheEntry) {
                TLDCacheEntry entry = (TLDCacheEntry) o;
                if (_debugCache) {
                    System.out.println("TLDCMDocument cache hit on " + cacheKey);
                }
                if (entry != null && entry.modificationStamp != IResource.NULL_STAMP && entry.modificationStamp >= lastModified) {
                    doc = entry.document;
                    entry.referenceCount++;
                } else {
                    getSharedDocumentCache().remove(cacheKey);
                }
            } else if (o instanceof Reference) {
                TLDCacheEntry entry = (TLDCacheEntry) ((Reference) o).get();
                if (entry != null) {
                    if (entry.modificationStamp != IResource.NULL_STAMP && entry.modificationStamp >= lastModified) {
                        doc = entry.document;
                        entry.referenceCount = 1;
                        getSharedDocumentCache().put(cacheKey, entry);
                    }
                } else {
                    getSharedDocumentCache().remove(cacheKey);
                }
            }
        }
        /* No document was found cached, create a new one and share it */
        if (doc == null) {
            if (_debugCache) {
                System.out.println("TLDCMDocument cache miss on " + cacheKey);
            }
            CMDocument document = loadTaglib(reference);
            if (document != null) {
                TLDCacheEntry entry = new TLDCacheEntry();
                doc = entry.document = document;
                entry.referenceCount = 1;
                entry.modificationStamp = lastModified;
                getSharedDocumentCache().put(cacheKey, entry);
            }
        }
        if (doc != null) {
            getDocuments().put(cacheKey, doc);
        }
    }
    return doc;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Reference(java.lang.ref.Reference) SoftReference(java.lang.ref.SoftReference)

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