Search in sources :

Example 6 with ICatalogEntry

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

the class CommonAddNamespacesDialog method addCatalogMapToList.

protected void addCatalogMapToList(ICatalog catalog, List list) {
    ICatalogEntry[] entries = catalog.getCatalogEntries();
    for (int i = 0; i < entries.length; i++) {
        ICatalogEntry entry = entries[i];
        if ((entry.getEntryType() == ICatalogEntry.ENTRY_TYPE_PUBLIC) && entry.getURI().endsWith(".xsd")) {
            // $NON-NLS-1$
            if (!isAlreadyDeclared(entry.getKey())) {
                // $NON-NLS-1$
                NamespaceInfo namespaceInfo = new NamespaceInfo(entry.getKey(), "xx", null);
                list.add(namespaceInfo);
            }
        }
    }
}
Also used : ICatalogEntry(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 7 with ICatalogEntry

use of org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry 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 ICatalogEntry

use of org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry 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 ICatalogEntry

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

the class SelectXMLCatalogIdDialog method buttonPressed.

protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        ISelection selection = panel.getTableViewer().getSelection();
        Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null;
        if (selectedObject instanceof ICatalogEntry) {
            ICatalogEntry mappingInfo = (ICatalogEntry) selectedObject;
            publicId = mappingInfo.getKey();
            systemId = computeDefaultSystemId(mappingInfo);
        }
    }
    super.buttonPressed(buttonId);
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICatalogEntry(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry)

Example 10 with ICatalogEntry

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

Aggregations

ICatalogEntry (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry)19 INextCatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog)10 ICatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)9 List (java.util.List)8 Catalog (org.eclipse.wst.xml.core.internal.catalog.Catalog)4 URL (java.net.URL)3 ISelection (org.eclipse.jface.viewers.ISelection)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 ArrayList (java.util.ArrayList)2 ICatalogElement (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement)2 File (java.io.File)1 SoftReference (java.lang.ref.SoftReference)1 HashMap (java.util.HashMap)1 Vector (java.util.Vector)1 IFile (org.eclipse.core.resources.IFile)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1