Search in sources :

Example 1 with IDelegateCatalog

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

the class TestCatalogRetrivalAndModelCreation method testCatalog11DelegateSystem.

public void testCatalog11DelegateSystem() throws MalformedURLException, IOException {
    ICatalog xmlCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
    IDelegateCatalog systemDelegate = (IDelegateCatalog) xmlCatalog.createCatalogElement(IDelegateCatalog.DELEGATE_TYPE_SYSTEM);
    File delegateCat = makeTempFile("delegateSystem", "<catalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\">\r\n" + "    <system systemId=\"http://funky.org/dog\" uri=\"file:///funky-dog.dtd\"/>\r\n" + "    <systemSuffix systemIdSuffix=\"/cat.dtd\" uri=\"file:///smellycat.xsd\"/>\r\n" + "    <rewriteSystem systemIdStartString=\"http://funky.org/parrots/\" rewritePrefix=\"file:///dtds/parrots/\"/>\r\n" + "</catalog>");
    systemDelegate.setStartString("http://funky.org/");
    systemDelegate.setCatalogLocation(delegateCat.toURI().toString());
    xmlCatalog.addCatalogElement(systemDelegate);
    try {
        assertEquals("try systemId entry", "file:///funky-dog.dtd", xmlCatalog.resolveSystem("http://funky.org/dog"));
        assertEquals("try systemSuffix entry", "file:///smellycat.xsd", xmlCatalog.resolveSystem("http://funky.org/some/cat.dtd"));
        assertEquals("try rewriteSystem entry", "file:///dtds/parrots/macaw.xsd", xmlCatalog.resolveSystem("http://funky.org/parrots/macaw.xsd"));
    } finally {
        xmlCatalog.removeCatalogElement(systemDelegate);
    }
    delegateCat.delete();
}
Also used : ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog) IDelegateCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.IDelegateCatalog) File(java.io.File)

Example 2 with IDelegateCatalog

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

the class TestCatalogRetrivalAndModelCreation method testCatalog11DelegateUri.

public void testCatalog11DelegateUri() throws MalformedURLException, IOException {
    ICatalog xmlCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
    IDelegateCatalog uriDelegate = (IDelegateCatalog) xmlCatalog.createCatalogElement(IDelegateCatalog.DELEGATE_TYPE_URI);
    File delegateCat = makeTempFile("delegateUri", "<catalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\">\r\n" + "    <uri name=\"urn:funky:dog\" uri=\"file:///funky-dog.dtd\"/>\r\n" + "    <uriSuffix uriSuffix=\":cat\" uri=\"file:///smellycat.dtd\"/>\r\n" + "    <rewriteURI uriStartString=\"urn:funky:fish:\" rewritePrefix=\"file:///dtds/\"/>\r\n" + "</catalog>");
    uriDelegate.setStartString("urn:funky:");
    uriDelegate.setCatalogLocation(delegateCat.toURI().toString());
    xmlCatalog.addCatalogElement(uriDelegate);
    try {
        assertEquals("uri entry", "file:///funky-dog.dtd", xmlCatalog.resolveURI("urn:funky:dog"));
        assertEquals("uriSuffix entry", "file:///smellycat.dtd", xmlCatalog.resolveURI("urn:funky:where-is-my:cat"));
        assertEquals("rewriteUri entry", "file:///dtds/parrot.dtd", xmlCatalog.resolveURI("urn:funky:fish:parrot.dtd"));
    } finally {
        xmlCatalog.removeCatalogElement(uriDelegate);
    }
    delegateCat.delete();
}
Also used : ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog) IDelegateCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.IDelegateCatalog) File(java.io.File)

Example 3 with IDelegateCatalog

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

the class CatalogWriter method processDelegateCatalogs.

private void processDelegateCatalogs(ICatalog catalog, Element parent) {
    IDelegateCatalog[] delegateCatalogs = catalog.getDelegateCatalogs();
    for (int i = 0; i < delegateCatalogs.length; i++) {
        IDelegateCatalog entry = delegateCatalogs[i];
        String prefixString = entry.getStartString();
        String catalogLocation = entry.getCatalogLocation();
        Element childElement = null;
        switch(entry.getEntryType()) {
            case IDelegateCatalog.DELEGATE_TYPE_PUBLIC:
                childElement = parent.getOwnerDocument().createElement(OASISCatalogConstants.TAG_DELEGATE_PUBLIC);
                if (childElement != null) {
                    childElement.setAttribute(OASISCatalogConstants.ATTR_PUBLIC_ID_START_STRING, prefixString);
                    childElement.setAttribute(OASISCatalogConstants.ATTR_CATALOG, catalogLocation);
                }
                break;
            case IDelegateCatalog.DELEGATE_TYPE_SYSTEM:
                childElement = parent.getOwnerDocument().createElement(OASISCatalogConstants.TAG_DELEGATE_SYSTEM);
                if (childElement != null) {
                    childElement.setAttribute(OASISCatalogConstants.ATTR_SYSTEM_ID_START_STRING, prefixString);
                    childElement.setAttribute(OASISCatalogConstants.ATTR_CATALOG, catalogLocation);
                }
                break;
            case IDelegateCatalog.DELEGATE_TYPE_URI:
                childElement = parent.getOwnerDocument().createElement(OASISCatalogConstants.TAG_DELEGATE_URI);
                if (childElement != null) {
                    childElement.setAttribute(OASISCatalogConstants.ATTR_URI_START_STRING, prefixString);
                    childElement.setAttribute(OASISCatalogConstants.ATTR_CATALOG, catalogLocation);
                }
                break;
            default:
                break;
        }
        if (childElement != null) {
            setAttributes(entry, childElement);
            parent.appendChild(childElement);
        }
    }
}
Also used : Element(org.w3c.dom.Element) ICatalogElement(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement) IDelegateCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.IDelegateCatalog)

Example 4 with IDelegateCatalog

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

the class TestCatalogRetrivalAndModelCreation method testCatalog11DelegatePublic.

public void testCatalog11DelegatePublic() throws MalformedURLException, IOException {
    ICatalog xmlCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
    IDelegateCatalog publicDelegate = (IDelegateCatalog) xmlCatalog.createCatalogElement(IDelegateCatalog.DELEGATE_TYPE_PUBLIC);
    // Ironically, we don't use WTP's Resolver when loading the catalog XML.
    // Adding <!DOCTYPE catalog PUBLIC "-//OASIS//DTD XML Catalogs V1.1//EN" "http://www.example.org/dtd/catalog.dtd">
    // to the catalog below will make the loading fail...
    File delegateCat = makeTempFile("delegatePublic", "<catalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\"\r\n" + "       prefer=\"public\">\r\n" + "    <public publicId=\"-//Example//an example V1.0.0//EN\"\r\n" + "            uri=\"file:///example.dtd\"/>\r\n" + "</catalog>");
    publicDelegate.setStartString("-//Example//");
    publicDelegate.setCatalogLocation(delegateCat.toURI().toString());
    xmlCatalog.addCatalogElement(publicDelegate);
    try {
        String resolved = xmlCatalog.resolvePublic("-//Example//an example V1.0.0//EN", "example.dtd");
        assertEquals("file:///example.dtd", resolved);
    } finally {
        xmlCatalog.removeCatalogElement(publicDelegate);
    }
    delegateCat.delete();
}
Also used : ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog) IDelegateCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.IDelegateCatalog) File(java.io.File)

Aggregations

IDelegateCatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.IDelegateCatalog)4 File (java.io.File)3 ICatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)3 ICatalogElement (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement)1 Element (org.w3c.dom.Element)1