Search in sources :

Example 6 with INextCatalog

use of org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog in project webtools.sourceediting by eclipse.

the class CatalogReaderTest method testReadCatalog.

/*
	 * Class under test for void read(ICatalog, String)
	 */
public void testReadCatalog() throws Exception {
    // read catalog
    String catalogFile = "/data/catalog1.xml";
    URL catalogUrl = TestPlugin.getDefault().getBundle().getEntry(catalogFile);
    assertNotNull(catalogUrl);
    URL base = FileLocator.resolve(catalogUrl);
    Catalog catalog = (Catalog) getCatalog("catalog1", base.toString());
    // CatalogReader.read(catalog, catalogFilePath);
    assertNotNull(catalog);
    // test main catalog - catalog1.xml
    // assertEquals("cat1", catalog.getId());
    assertEquals(3, catalog.getCatalogEntries().length);
    // test public entries
    List entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_PUBLIC);
    assertEquals(1, entries.size());
    ICatalogEntry entry = (ICatalogEntry) entries.get(0);
    // String resolvedURI = URIHelper.makeAbsolute(base, "./Invoice/Invoice.dtd");
    assertEquals(getFileLocation("/data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("InvoiceId_test", entry.getKey());
    assertEquals("http://webURL", entry.getAttributeValue("webURL"));
    // test system entries
    entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_SYSTEM);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("/data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("Invoice.dtd", entry.getKey());
    assertEquals("yes", entry.getAttributeValue("chached"));
    assertEquals("value1", entry.getAttributeValue("property"));
    // test uri entries
    entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_URI);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("/data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("http://www.test.com/Invoice.dtd", entry.getKey());
    assertEquals("no", entry.getAttributeValue("chached"));
    assertEquals("value2", entry.getAttributeValue("property"));
    // test next catalog - catalog2.xml
    INextCatalog[] nextCatalogEntries = catalog.getNextCatalogs();
    assertEquals(1, nextCatalogEntries.length);
    INextCatalog nextCatalogEntry = (INextCatalog) nextCatalogEntries[0];
    assertNotNull(nextCatalogEntry);
    // String catalogRefId = nextCatalogEntry.getCatalogRefId();
    // assertEquals("nextCatalog1", catalogRefId);
    // resolvedURI = URIHelper.makeAbsolute(base, "catalog2.xml");
    assertEquals("catalog2.xml", nextCatalogEntry.getCatalogLocation());
    ICatalog nextCatalog = nextCatalogEntry.getReferencedCatalog();
    assertNotNull(nextCatalog);
    assertEquals(4, nextCatalog.getCatalogEntries().length);
    // test public entries
    entries = CatalogTest.getCatalogEntries(nextCatalog, ICatalogEntry.ENTRY_TYPE_PUBLIC);
    assertEquals(2, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    // resolvedURI = URIHelper.makeAbsolute(nextCatalog.getBase(), "./PublicationCatalogue/Catalogue.xsd");
    assertEquals(getFileLocation("/data/PublicationCatalogue/Catalogue.xsd"), entry.getURI());
    assertEquals("http://www.eclipse.org/webtools/Catalogue_001", entry.getKey());
    // test public entry from a group
    entry = (ICatalogEntry) entries.get(1);
    // resolvedURI = URIHelper.makeAbsolute(nextCatalog.getBase(), "./PublicationCatalogue/Catalogue.xsd");
    assertEquals(getFileLocation("/data/PublicationCatalogue/Catalogue.xsd"), entry.getURI());
    assertEquals("http://www.eclipse.org/webtools/Catalogue_002", entry.getKey());
    // test system entries
    entries = CatalogTest.getCatalogEntries(nextCatalog, ICatalogEntry.ENTRY_TYPE_SYSTEM);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("/data/PublicationCatalogue/Catalogue.xsd"), entry.getURI());
    assertEquals("Catalogue.xsd", entry.getKey());
    // test uri entries
    entries = CatalogTest.getCatalogEntries(nextCatalog, ICatalogEntry.ENTRY_TYPE_URI);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals("http://www.eclipse.org/webtools/Catalogue/Catalogue.xsd", entry.getURI());
    assertEquals("http://www.eclipse.org/webtools/Catalogue.xsd", entry.getKey());
}
Also used : INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) List(java.util.List) ICatalogEntry(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog) URL(java.net.URL) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) Catalog(org.eclipse.wst.xml.core.internal.catalog.Catalog) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Example 7 with INextCatalog

use of org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog in project webtools.sourceediting by eclipse.

the class CatalogWriterTest method testWrite.

public final void testWrite() throws Exception {
    // read catalog
    String catalogFile = "/data/catalog1.xml";
    URL catalogUrl = TestPlugin.getDefault().getBundle().getEntry(catalogFile);
    assertNotNull(catalogUrl);
    URL resolvedURL = FileLocator.resolve(catalogUrl);
    Catalog testCatalog = (Catalog) getCatalog("catalog1", resolvedURL.toString());
    assertNotNull(testCatalog);
    testCatalog.setBase(resolvedURL.toString());
    // CatalogReader.read(testCatalog, resolvedURL.getFile());
    assertNotNull(testCatalog);
    // write catalog
    URL resultsFolder = TestPlugin.getDefault().getBundle().getEntry("/");
    IPath path = new Path(FileLocator.resolve(resultsFolder).getFile());
    String resultCatalogFile = path.append("/catalog1.xml").toFile().toURI().toString();
    testCatalog.setLocation(resultCatalogFile);
    // write catalog
    testCatalog.save();
    // read catalog file from the saved location and test its content
    Catalog catalog = (Catalog) getCatalog("catalog2", testCatalog.getLocation());
    assertNotNull(catalog);
    // test saved catalog - catalog1.xml
    assertEquals(3, catalog.getCatalogEntries().length);
    // test public entries
    List entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_PUBLIC);
    assertEquals(1, entries.size());
    ICatalogEntry entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("InvoiceId_test", entry.getKey());
    assertEquals("http://webURL", entry.getAttributeValue("webURL"));
    // test system entries
    entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_SYSTEM);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("Invoice.dtd", entry.getKey());
    assertEquals("yes", entry.getAttributeValue("chached"));
    assertEquals("value1", entry.getAttributeValue("property"));
    // test uri entries
    entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_URI);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("http://www.test.com/Invoice.dtd", entry.getKey());
    assertEquals("no", entry.getAttributeValue("chached"));
    assertEquals("value2", entry.getAttributeValue("property"));
    // test next catalog - catalog2.xml
    INextCatalog[] nextCatalogEntries = catalog.getNextCatalogs();
    assertEquals(1, nextCatalogEntries.length);
    INextCatalog nextCatalogEntry = (INextCatalog) nextCatalogEntries[0];
    assertNotNull(nextCatalogEntry);
    assertEquals("catalog2.xml", nextCatalogEntry.getCatalogLocation());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) List(java.util.List) ICatalogEntry(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry) URL(java.net.URL) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) Catalog(org.eclipse.wst.xml.core.internal.catalog.Catalog)

Example 8 with INextCatalog

use of org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog in project webtools.sourceediting by eclipse.

the class CatalogContributorRegistryReaderTest method testReadRegistry.

public final void testReadRegistry() throws Exception {
    assertNotNull(defaultCatalog);
    assertEquals(XMLCorePlugin.DEFAULT_CATALOG_ID, defaultCatalog.getId());
    assertEquals(2, defaultCatalog.getNextCatalogs().length);
    String pluginId = TestPlugin.getDefault().getBundle().getSymbolicName();
    // test system entries
    assertNotNull(systemCatalog);
    List entries = CatalogTest.getCatalogEntries(systemCatalog, ICatalogEntry.ENTRY_TYPE_SYSTEM);
    for (int i = 0; i < entries.size(); i++) {
        ICatalogEntry entry = (ICatalogEntry) entries.get(i);
        if ("testSystemId".equals(entry.getId())) {
            String resolvedURI = resolvePath(pluginId, "data/Personal/personal.dtd");
            assertEquals(resolvedURI, entry.getURI());
            assertEquals("http://personal/personal.dtd", entry.getKey());
        }
    }
    // test public entries
    entries = CatalogTest.getCatalogEntries(systemCatalog, ICatalogEntry.ENTRY_TYPE_PUBLIC);
    for (int i = 0; i < entries.size(); i++) {
        ICatalogEntry entry = (ICatalogEntry) entries.get(i);
        if ("testPublicId1".equals(entry.getId())) {
            String resolvedURI = resolvePath(pluginId, "data/Invoice/Invoice.dtd");
            assertEquals(resolvedURI, entry.getURI());
            assertEquals("InvoiceId_test", entry.getKey());
            // test user defined attributes
            assertEquals("http://org.eclipse.wst.xml.example/Invoice.dtd", entry.getAttributeValue("webURL"));
        } else if ("testMappingInfo".equals(entry.getId())) {
            String resolvedURI = resolvePath(pluginId, "platform:/plugin/org.eclipse.xsd/cache/www.w3.org/2001/XMLSchema.xsd");
            assertEquals(resolvedURI, entry.getURI());
            assertEquals("http://www.w3.org/2001/XMLSchema1", entry.getKey());
        }
    }
    // test uri entries
    entries = CatalogTest.getCatalogEntries(systemCatalog, ICatalogEntry.ENTRY_TYPE_URI);
    for (int i = 0; i < entries.size(); i++) {
        ICatalogEntry entry = (ICatalogEntry) entries.get(i);
        if ("testURIId1".equals(entry.getId())) {
            String resolvedURI = resolvePath(pluginId, "data/example/example.xsd");
            assertEquals(resolvedURI, entry.getURI());
            assertEquals("http://apache.org/xml/xcatalog/example", entry.getKey());
        } else if ("testURIId2".equals(entry.getId())) {
            String resolvedURI = resolvePath(pluginId, "platform:/plugin/org.eclipse.xsd/cache/www.w3.org/2001/XMLSchema.xsd");
            assertEquals(resolvedURI, entry.getURI());
            assertEquals("http://www.w3.org/2001/XMLSchema", entry.getKey());
        } else if ("testURIId3".equals(entry.getId())) {
            String resolvedURI = resolvePath(pluginId, "jar:platform:/plugin/org.eclipse.wst.xml.catalog.tests/data/schemas.jar!/data/catalog.xsd");
            assertEquals(resolvedURI, entry.getURI());
            assertEquals("http://oasis.names.tc.entity.xmlns.xml.catalog", entry.getKey());
        }
    }
    // test tested catalog
    INextCatalog[] nextCatalogEntries = systemCatalog.getNextCatalogs();
    for (int i = 0; i < nextCatalogEntries.length; i++) {
        INextCatalog nextCatalogEntry = (INextCatalog) nextCatalogEntries[i];
        if ("testNestedCatalog".equals(nextCatalogEntry.getId())) {
            String resolvedURI = resolvePath(pluginId, "data/catalog1.xml");
            assertEquals(resolvedURI, nextCatalogEntry.getCatalogLocation());
            ICatalog nextCatalog = nextCatalogEntry.getReferencedCatalog();
            assertNotNull(nextCatalog);
            assertEquals(3, nextCatalog.getCatalogEntries().length);
            // test public entries
            entries = CatalogTest.getCatalogEntries(nextCatalog, ICatalogEntry.ENTRY_TYPE_PUBLIC);
            assertEquals(1, entries.size());
            ICatalogEntry entry = (ICatalogEntry) entries.get(0);
            // URI uri = URIHelper.getURIForFilePath(resolvedURI);
            // resolvedURI = URIHelper.makeAbsolute(uri.toURL(), "./Invoice/Invoice.dtd");
            assertEquals(getFileLocation("data/Invoice/Invoice.dtd"), entry.getURI());
            assertEquals("InvoiceId_test", entry.getKey());
            // test system entries
            entries = CatalogTest.getCatalogEntries(nextCatalog, ICatalogEntry.ENTRY_TYPE_SYSTEM);
            assertEquals(1, entries.size());
            entry = (ICatalogEntry) entries.get(0);
            assertEquals(getFileLocation("data/Invoice/Invoice.dtd"), entry.getURI());
            assertEquals("Invoice.dtd", entry.getKey());
            // test uri entries
            entries = CatalogTest.getCatalogEntries(nextCatalog, ICatalogEntry.ENTRY_TYPE_URI);
            assertEquals(1, entries.size());
            entry = (ICatalogEntry) entries.get(0);
            assertEquals(getFileLocation("data/Invoice/Invoice.dtd"), entry.getURI());
            assertEquals("http://www.test.com/Invoice.dtd", entry.getKey());
        }
    }
}
Also used : INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) List(java.util.List) ICatalogEntry(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Example 9 with INextCatalog

use of org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog in project webtools.sourceediting by eclipse.

the class XMLHyperlinkDetector method getCatalogEntry.

/**
 * @param uriString
 * @return
 */
private ICatalogEntry getCatalogEntry(String uriString) {
    ICatalog defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
    if (defaultCatalog != null) {
        // Process default catalog
        ICatalogEntry[] entries = defaultCatalog.getCatalogEntries();
        for (int entry = 0; entry < entries.length; entry++) {
            if (uriString.equals(entries[entry].getKey()) || uriString.equals(entries[entry].getURI())) {
                return entries[entry];
            }
        }
        // Process declared OASIS nextCatalogs catalog
        INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs();
        for (int nextCatalog = 0; nextCatalog < nextCatalogs.length; nextCatalog++) {
            ICatalog catalog = nextCatalogs[nextCatalog].getReferencedCatalog();
            ICatalogEntry[] entries2 = catalog.getCatalogEntries();
            for (int entry = 0; entry < entries2.length; entry++) {
                if (uriString.equals(entries2[entry].getKey()) || uriString.equals(entries2[entry].getURI()))
                    return entries2[entry];
            }
        }
    }
    return null;
}
Also used : INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) ICatalogEntry(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Example 10 with INextCatalog

use of org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog in project webtools.sourceediting by eclipse.

the class CommonAddNamespacesDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    addNamespacesControl = new CommonAddNamespacesControl(dialogArea, SWT.NONE, resourceLocation);
    List list = new ArrayList();
    addBuiltInNamespaces(list);
    ICatalog defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
    INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs();
    for (int i = 0; i < nextCatalogs.length; i++) {
        INextCatalog catalog = nextCatalogs[i];
        ICatalog referencedCatalog = catalog.getReferencedCatalog();
        if (referencedCatalog != null) {
            if (XMLCorePlugin.USER_CATALOG_ID.equals(referencedCatalog.getId())) {
                ICatalog userCatalog = referencedCatalog;
                addCatalogMapToList(userCatalog, list);
            } else if (XMLCorePlugin.SYSTEM_CATALOG_ID.equals(referencedCatalog.getId())) {
                ICatalog systemCatalog = referencedCatalog;
                addCatalogMapToList(systemCatalog, list);
            }
        }
    }
    computeAddablePrefixes(list, existingNamespaces);
    addNamespacesControl.setNamespaceInfoList(list);
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ArrayList(java.util.ArrayList) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) ArrayList(java.util.ArrayList) List(java.util.List) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Aggregations

INextCatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog)17 ICatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)13 ICatalogEntry (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry)9 List (java.util.List)6 URL (java.net.URL)4 Catalog (org.eclipse.wst.xml.core.internal.catalog.Catalog)4 ArrayList (java.util.ArrayList)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 SoftReference (java.lang.ref.SoftReference)1 HashMap (java.util.HashMap)1 Vector (java.util.Vector)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 Composite (org.eclipse.swt.widgets.Composite)1 ICatalogElement (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1