use of org.eclipse.wst.json.core.schema.catalog.ICatalogElement 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);
}
}
}
}
}
}
}
}
use of org.eclipse.wst.json.core.schema.catalog.ICatalogElement 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);
}
}
use of org.eclipse.wst.json.core.schema.catalog.ICatalogElement in project webtools.sourceediting by eclipse.
the class Catalog method addEntriesFromCatalog.
public void addEntriesFromCatalog(ICatalog catalog) {
try {
setNotificationEnabled(false);
if (catalog != null) {
ICatalogElement[] entries = ((Catalog) catalog).getCatalogElements();
for (int i = 0; i < entries.length; i++) {
CatalogElement clone = (CatalogElement) ((CatalogElement) entries[i]).clone();
addCatalogElement(clone);
}
} else {
Logger.log(Logger.ERROR, // $NON-NLS-1$
"argument was null in Catalog.addEntriesFromCatalog");
}
} finally {
setNotificationEnabled(true);
}
internalResolver = null;
notifyChanged();
}
use of org.eclipse.wst.json.core.schema.catalog.ICatalogElement 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);
}
}
use of org.eclipse.wst.json.core.schema.catalog.ICatalogElement in project webtools.sourceediting by eclipse.
the class Catalog method getCatalogElements.
private List getCatalogElements(int type) {
List result = new ArrayList();
ICatalogElement[] elements = (ICatalogElement[]) catalogElements.toArray(new ICatalogElement[catalogElements.size()]);
for (int i = 0; i < elements.length; i++) {
ICatalogElement element = elements[i];
if (element.getType() == type) {
result.add(element);
}
}
return result;
}
Aggregations