Search in sources :

Example 1 with ICatalog

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

the class GlobalCMDocumentCache method getSystemCatalogEntries.

private static synchronized HashMap getSystemCatalogEntries() {
    HashMap systemCatalogURIs = new HashMap();
    ICatalog systemCatalog = null;
    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.SYSTEM_CATALOG_ID.equals(referencedCatalog.getId())) {
                systemCatalog = referencedCatalog;
            }
        }
    }
    if (systemCatalog != null) {
        ICatalogEntry[] catalogEntries = systemCatalog.getCatalogEntries();
        for (int i = 0; i < catalogEntries.length; i++) {
            systemCatalogURIs.put(catalogEntries[i].getURI(), new SoftReference(null));
        }
    }
    return systemCatalogURIs;
}
Also used : SoftReference(java.lang.ref.SoftReference) HashMap(java.util.HashMap) 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 2 with ICatalog

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

the class SelectXMLCatalogIdPanel method createTableViewer.

protected XMLCatalogTableViewer createTableViewer(Composite parent) {
    String[] headings = new String[2];
    headings[0] = XMLUIMessages._UI_LABEL_KEY;
    headings[1] = XMLUIMessages._UI_LABEL_URI;
    XMLCatalogTableViewer theTableViewer = new XMLCatalogTableViewer(parent, headings) {

        protected void addXMLCatalogEntries(List list, ICatalogEntry[] entries) {
            for (int i = 0; i < entries.length; i++) {
                ICatalogEntry entry = entries[i];
                if (catalogEntryType == 0) {
                    list.add(entry);
                } else if (catalogEntryType == entry.getEntryType()) {
                    list.add(entry);
                }
            }
        }

        public Collection getXMLCatalogEntries() {
            List result = null;
            if ((fXmlCatalog == null) || doTableSizeHack) {
                // this lets us create a table with an initial height of
                // 10 rows
                // otherwise we get stuck with 0 row heigh table... that's
                // too small
                doTableSizeHack = false;
                result = new Vector();
                for (int i = 0; i < 6; i++) {
                    // $NON-NLS-1$
                    result.add("");
                }
            } else {
                result = new Vector();
                processCatalog(result, fXmlCatalog);
            }
            return result;
        }

        private void processCatalog(List result, ICatalog catalog) {
            addXMLCatalogEntries(result, catalog.getCatalogEntries());
            INextCatalog[] nextCatalogs = catalog.getNextCatalogs();
            for (int i = 0; i < nextCatalogs.length; i++) {
                ICatalog nextCatalog = nextCatalogs[i].getReferencedCatalog();
                if (nextCatalog != null) {
                    processCatalog(result, nextCatalog);
                }
            }
        }
    };
    return theTableViewer;
}
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) Vector(java.util.Vector) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Example 3 with ICatalog

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

the class AdvancedOptionsDialog method invokeImportDialog.

protected void invokeImportDialog() {
    SelectSingleFileDialog dialog = new SelectSingleFileDialog(getShell(), null, true);
    // $NON-NLS-1$ //$NON-NLS-2$
    String[] extensions = { ".xmlcatalog", ".xml" };
    dialog.addFilterExtensions(extensions);
    dialog.create();
    dialog.getShell().setText(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_TITLE);
    dialog.setTitle(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_HEADING);
    dialog.setMessage(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_MESSAGE);
    dialog.setBlockOnOpen(true);
    int rc = dialog.open();
    if (rc == Window.OK) {
        IFile file = dialog.getFile();
        if (file != null) {
            String fileName = file.getLocation().toFile().toURI().toString();
            try {
                CatalogSet tempResourceSet = new CatalogSet();
                // $NON-NLS-1$
                ICatalog newCatalog = tempResourceSet.lookupOrCreateCatalog("temp", fileName);
                workingUserCatalog.addEntriesFromCatalog(newCatalog);
            } catch (Exception e) {
            // TODO... give error message
            }
        }
        close();
    }
}
Also used : SelectSingleFileDialog(org.eclipse.wst.common.ui.internal.dialogs.SelectSingleFileDialog) IFile(org.eclipse.core.resources.IFile) CatalogSet(org.eclipse.wst.xml.core.internal.catalog.CatalogSet) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Example 4 with ICatalog

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

the class CatalogReaderTest method testReadComplexCatalog.

/*
	 * Class under test for void read(ICatalog, String)
	 */
public void testReadComplexCatalog() throws Exception {
    // read catalog
    String catalogFile = "/data/delegateAndRewrite/catalog11.xml";
    URL catalogUrl = TestPlugin.getDefault().getBundle().getEntry(catalogFile);
    assertNotNull(catalogUrl);
    URL base = FileLocator.resolve(catalogUrl);
    Catalog catalog = (Catalog) getCatalog("catalog11", base.toString());
    // CatalogReader.read(catalog, catalogFilePath);
    assertNotNull(catalog);
    // test main catalog - catalog1.xml
    // assertEquals("cat1", catalog.getId());
    assertEquals(13, catalog.getCatalogElements().length);
    // test public entries
    assertEquals(2, CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_PUBLIC).size());
    // test system entries
    assertEquals(2, CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_SYSTEM).size());
    // test uri entries
    assertEquals(1, CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_URI).size());
    // test next catalog - catalog2.xml
    INextCatalog[] nextCatalogEntries = catalog.getNextCatalogs();
    assertEquals(1, nextCatalogEntries.length);
    INextCatalog nextCatalogEntry = (INextCatalog) nextCatalogEntries[0];
    assertNotNull(nextCatalogEntry);
    assertEquals("catalog.xml", nextCatalogEntry.getCatalogLocation());
}
Also used : INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) 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 5 with ICatalog

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

Aggregations

ICatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)32 INextCatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog)14 ICatalogEntry (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry)8 List (java.util.List)6 IDelegateCatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.IDelegateCatalog)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 Composite (org.eclipse.swt.widgets.Composite)2 Catalog (org.eclipse.wst.xml.core.internal.catalog.Catalog)2 CatalogSet (org.eclipse.wst.xml.core.internal.catalog.CatalogSet)2 IRewriteEntry (org.eclipse.wst.xml.core.internal.catalog.provisional.IRewriteEntry)2 ISuffixEntry (org.eclipse.wst.xml.core.internal.catalog.provisional.ISuffixEntry)2 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)2 ContentModelManager (org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager)2 NodeList (org.w3c.dom.NodeList)2