Search in sources :

Example 1 with ICatalogEntry

use of org.eclipse.wst.json.core.schema.catalog.ICatalogEntry in project webtools.sourceediting by eclipse.

the class CatalogSchemastoreReader method readSchemastore.

protected void readSchemastore() {
    File f = getUrl();
    if (f != null) {
        int type = ICatalogEntry.ENTRY_TYPE_SCHEMA;
        JsonValue schemas;
        try {
            InputStreamReader reader = new InputStreamReader(new FileInputStream(f));
            JsonObject json = JsonObject.readFrom(reader);
            schemas = json.get(SCHEMAS);
        } catch (IOException e) {
            Logger.logException(e);
            return;
        }
        if (schemas != null && schemas instanceof JsonArray) {
            JsonArray elements = (JsonArray) schemas;
            Iterator<JsonValue> iter = elements.iterator();
            while (iter.hasNext()) {
                JsonValue value = iter.next();
                if (value instanceof JsonObject) {
                    JsonObject jsonObject = (JsonObject) value;
                    // $NON-NLS-1$
                    JsonValue urlJson = jsonObject.get("url");
                    // $NON-NLS-1$
                    JsonValue fileMatchJson = jsonObject.get("fileMatch");
                    if (urlJson != null && fileMatchJson != null && urlJson.isString() && fileMatchJson.isArray()) {
                        String url = urlJson.asString();
                        JsonArray fileMatchArray = fileMatchJson.asArray();
                        Iterator<JsonValue> fileIter = fileMatchArray.iterator();
                        while (fileIter.hasNext()) {
                            JsonValue fileMatchValue = fileIter.next();
                            if (fileMatchValue.isString()) {
                                String fileMatch = fileMatchValue.asString();
                                ICatalogElement catalogElement = catalog.createCatalogElement(type);
                                if (catalogElement instanceof ICatalogEntry) {
                                    ICatalogEntry entry = (ICatalogEntry) catalogElement;
                                    entry.setKey(fileMatch);
                                    entry.setURI(url);
                                    entry.setId(fileMatch);
                                }
                                catalog.addCatalogElement(catalogElement);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : JsonArray(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonArray) InputStreamReader(java.io.InputStreamReader) JsonValue(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue) JsonObject(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject) ICatalogElement(org.eclipse.wst.json.core.schema.catalog.ICatalogElement) IOException(java.io.IOException) ICatalogEntry(org.eclipse.wst.json.core.schema.catalog.ICatalogEntry) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with ICatalogEntry

use of org.eclipse.wst.json.core.schema.catalog.ICatalogEntry in project webtools.sourceediting by eclipse.

the class CatalogUserCatalogReader method readCatalog.

protected void readCatalog() {
    int type = ICatalogEntry.ENTRY_TYPE_SCHEMA;
    Set<UserEntry> entries = EntryParser.getUserEntries();
    for (UserEntry ue : entries) {
        ICatalogElement catalogElement = catalog.createCatalogElement(type);
        if (catalogElement instanceof ICatalogEntry) {
            ICatalogEntry entry = (ICatalogEntry) catalogElement;
            entry.setKey(ue.getFileMatch());
            entry.setURI(ue.getUrl().toString());
            entry.setId(ue.getFileMatch());
        }
        catalog.addCatalogElement(catalogElement);
    }
}
Also used : ICatalogElement(org.eclipse.wst.json.core.schema.catalog.ICatalogElement) ICatalogEntry(org.eclipse.wst.json.core.schema.catalog.ICatalogEntry)

Example 3 with ICatalogEntry

use of org.eclipse.wst.json.core.schema.catalog.ICatalogEntry in project webtools.sourceediting by eclipse.

the class CatalogContributorRegistryReader method processMappingInfoElements.

private void processMappingInfoElements(IConfigurationElement[] childElementList) {
    if (catalog == null)
        return;
    for (int i = 0; i < childElementList.length; i++) {
        IConfigurationElement childElement = childElementList[i];
        String name = childElement.getName();
        int type = ICatalogEntry.ENTRY_TYPE_SCHEMA;
        String fileMatch = null;
        if (SchemaStoreCatalogConstants.TAG_SCHEMA.equals(name)) {
            fileMatch = childElement.getAttribute(SchemaStoreCatalogConstants.ATTR_SCHEMA_FILEMATCH);
        // fileMatch = childElement
        // .getAttribute(SchemaStoreCatalogConstants.ATTR_SCHEMA_FILEMATCH);
        }
        /*if (SchemaStoreCatalogConstants.TAG_PUBLIC.equals(name)) {
				key = childElement
						.getAttribute(SchemaStoreCatalogConstants.ATTR_PUBLIC_ID);
			} else if (SchemaStoreCatalogConstants.TAG_SYSTEM.equals(name)) {
				key = childElement
						.getAttribute(SchemaStoreCatalogConstants.ATTR_SYSTEM_ID);
				type = ICatalogEntry.ENTRY_TYPE_SYSTEM;
			} else if (SchemaStoreCatalogConstants.TAG_URI.equals(name)) {
				key = childElement
						.getAttribute(SchemaStoreCatalogConstants.ATTR_NAME);
				type = ICatalogEntry.ENTRY_TYPE_URI;
			} else if (SchemaStoreCatalogConstants.TAG_NEXT_CATALOG
					.equals(name)) {
				processNextSchemaCatalogElements(new IConfigurationElement[] { childElement });
				continue;
			}
			if (key == null || key.equals("")) //$NON-NLS-1$
			{
				Logger.log(Logger.ERROR,
						JSONCoreMessages.SchemaCatalog_entry_key_not_set);
				continue;
			}*/
        String entryURI = childElement.getAttribute(// mandatory
        SchemaStoreCatalogConstants.ATTR_SCHEMA_URI);
        if (// $NON-NLS-1$
        entryURI == null || entryURI.equals("")) {
            Logger.log(Logger.ERROR, JSONCoreMessages.Catalog_entry_uri_not_set);
            continue;
        }
        ICatalogElement catalogElement = catalog.createCatalogElement(type);
        if (catalogElement instanceof ICatalogEntry) {
            ICatalogEntry entry = (ICatalogEntry) catalogElement;
            entry.setKey(fileMatch);
            String resolvedPath = resolvePath(entryURI);
            entry.setURI(resolvedPath);
            String id = childElement.getAttribute(// optional
            SchemaStoreCatalogConstants.ATTR_SCHEMA_NAME);
            if (// $NON-NLS-1$
            id != null && !id.equals("")) {
                entry.setId(id);
            }
        }
        // process any other attributes
        for (int j = 0; j < childElement.getAttributeNames().length; j++) {
            String attrName = childElement.getAttributeNames()[j];
        // if (!attrName.equals(SchemaStoreCatalogConstants.ATTR_URI)
        // && !attrName
        // .equals(SchemaStoreCatalogConstants.ATTR_NAME)
        // && !attrName
        // .equals(SchemaStoreCatalogConstants.ATTR_PUBLIC_ID)
        // && !attrName
        // .equals(SchemaStoreCatalogConstants.ATTR_SYSTEM_ID)
        // && !attrName
        // .equals(SchemaStoreCatalogConstants.ATTR_CATALOG)
        // && !attrName
        // .equals(SchemaStoreCatalogConstants.ATTR_ID)
        // && !attrName
        // .equals(SchemaStoreCatalogConstants.ATTR_BASE)) {
        // String attrValue = childElement.getAttribute(attrName);
        // if (attrValue != null && !attrValue.equals("")) //$NON-NLS-1$
        // {
        // schemaCatalogElement.setAttributeValue(attrName,
        // attrValue);
        // }
        // }
        }
        catalog.addCatalogElement(catalogElement);
    }
}
Also used : ICatalogElement(org.eclipse.wst.json.core.schema.catalog.ICatalogElement) ICatalogEntry(org.eclipse.wst.json.core.schema.catalog.ICatalogEntry) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Aggregations

ICatalogElement (org.eclipse.wst.json.core.schema.catalog.ICatalogElement)3 ICatalogEntry (org.eclipse.wst.json.core.schema.catalog.ICatalogEntry)3 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 JsonArray (org.eclipse.json.provisonnal.com.eclipsesource.json.JsonArray)1 JsonObject (org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject)1 JsonValue (org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue)1