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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations