@Override public String getNamespace(String prefix) { NamespacePrefixProvider npp = cache; return npp == null ? null : npp.getNamespace(prefix); }
@Override public String getPrefix(String namespace) { NamespacePrefixProvider npp = cache; return npp == null ? null : npp.getPrefix(namespace); } @Override
@Override public List<String> getPrefixes(String namespace) { NamespacePrefixProvider npp = cache; return npp == null ? null : npp.getPrefixes(namespace); } }
String fieldUri = nps.getFullName(value); if(fieldUri == null){ throw new IllegalArgumentException("The prefix '" + NamespaceMappingUtils.getPrefix(value)+"' is unknown (not mapped to an " + "namespace) by the Stanbol Namespace Prefix Mapping Service. Please " + "change the configuration to use the full URI instead of '"+value+"'!"); } else if(NamespaceMappingUtils.getPrefix(value) != null){ throw new IllegalArgumentException("'{prefix}:{localname}' configurations " + "such as '"+value+"' are only supported if the NamespacePrefixService is "
/** * @param entry * @return */ private String getUri(String entry) { String uri; String nsPrefix = NamespaceMappingUtils.getPrefix(entry); if(nsPrefix != null){ String ns = nsPrefixProvider.getNamespace(nsPrefix); if(ns == null){ throw new IllegalArgumentException("Unable to resolve namesoace prefix used by '" +entry+"' by using the NamespacePrefixService!"); } uri = new StringBuilder(ns).append(entry,nsPrefix.length()+1, entry.length()).toString(); } else { uri = entry; } return uri; }
@Override public String getFullName(String shortNameOrUri) { String prefix = NamespaceMappingUtils.getPrefix(shortNameOrUri); if(prefix != null){ String namespace = getNamespace(prefix); if(namespace != null){ return namespace+shortNameOrUri.substring(prefix.length()+1); } else { //no mapping return null return null; } } else { //not a shortName ... return the parsed return shortNameOrUri; } }
private static List<String> parseMappings(String[] parts, int start, NamespacePrefixService nps) { ArrayList<String> mappings = new ArrayList<String>(parts.length-start); for(int i=start;i<parts.length;i++){ if(!parts[i].isEmpty()){ //needed to remove two spaces in a row try { mappings.add(NamespaceMappingUtils.getConfiguredUri(nps, parts[i])); } catch (IllegalArgumentException e) { log.warn("Unable to parse mapping because of unkown namespace prefix in "+parts[i],e); } } } return mappings; }
private String createPrefix(Map<String,String> prefixMap) { String defaultPrefix; do { // as long an prefix is not any of the default prefixes or one of the prefixes defined by // NamespaceEnum defaultNsPrefixNumber++; defaultPrefix = DEFAULT_NS_PREFIX_STRING + defaultNsPrefixNumber; } while (prefixMap.containsKey(defaultPrefix) || NamespaceEnum.forPrefix(defaultPrefix) != null || (nsPrefixService != null && nsPrefixService.getNamespace(defaultPrefix) != null)); return defaultPrefix; }
@Override public String getShortName(String uri) { String namespace = NamespaceMappingUtils.getNamespace(uri); if(namespace != null){ String prefix = getPrefix(namespace); if(prefix != null){ return prefix+uri.substring(namespace.length()); } //else no mapping -> return the full URI } //no namespace -> return the full URI return uri; }
String fieldUri = nps.getFullName(value); if(fieldUri == null){ throw new IllegalArgumentException("The prefix '" + NamespaceMappingUtils.getPrefix(value)+"' is unknown (not mapped to an " + "namespace) by the Stanbol Namespace Prefix Mapping Service. Please " + "change the configuration to use the full URI instead of '"+value+"'!"); } else if(NamespaceMappingUtils.getPrefix(value) != null){ throw new IllegalArgumentException("'{prefix}:{localname}' configurations " + "such as '"+value+"' are only supported if the NamespacePrefixService is "
/** * @param entry * @return */ private String getUri(String entry) { String uri; String nsPrefix = NamespaceMappingUtils.getPrefix(entry); if(nsPrefix != null){ String ns = nsPrefixProvider.getNamespace(nsPrefix); if(ns == null){ throw new IllegalArgumentException("Unable to resolve namesoace prefix used by '" +entry+"' by using the NamespacePrefixService!"); } uri = new StringBuilder(ns).append(entry,nsPrefix.length()+1, entry.length()).toString(); } else { uri = entry; } return uri; }
@Override public String getFullName(String shortNameOrUri) { String prefix = NamespaceMappingUtils.getPrefix(shortNameOrUri); if(prefix != null){ String namespace = getNamespace(prefix); if(namespace != null){ return namespace+shortNameOrUri.substring(prefix.length()+1); } else { //no mapping return null return null; } } else { //not a shortName ... return the parsed return shortNameOrUri; } }
@Override public String getNamespace(String prefix) { NamespacePrefixProvider npp = cache; return npp == null ? null : npp.getNamespace(prefix); }
@Override public List<String> getPrefixes(String namespace) { NamespacePrefixProvider npp = cache; return npp == null ? null : npp.getPrefixes(namespace); } }
private String createPrefix(Map<String,String> prefixMap) { String defaultPrefix; do { // as long an prefix is not any of the default prefixes or one of the prefixes defined by // NamespaceEnum defaultNsPrefixNumber++; defaultPrefix = DEFAULT_NS_PREFIX_STRING + defaultNsPrefixNumber; } while (prefixMap.containsKey(defaultPrefix) || NamespaceEnum.forPrefix(defaultPrefix) != null || (nsPrefixService != null && nsPrefixService.getNamespace(defaultPrefix) != null)); return defaultPrefix; }
@Override public String getShortName(String uri) { String namespace = NamespaceMappingUtils.getNamespace(uri); if(namespace != null){ String prefix = getPrefix(namespace); if(prefix != null){ return prefix+uri.substring(namespace.length()); } //else no mapping -> return the full URI } //no namespace -> return the full URI return uri; }
@Override public String getPrefix(String namespace) { NamespacePrefixProvider npp = cache; return npp == null ? null : npp.getPrefix(namespace); } @Override
String fieldUri = nps.getFullName(value); if(fieldUri == null){ throw new ConfigurationException(property, "The prefix '" + NamespaceMappingUtils.getPrefix(value)+"' is unknown (not mapped to an " + "namespace) by the Stanbol Namespace Prefix Mapping Service. Please " + "change the configuration to use the full URI instead of '"+value+"'!"); } else if(NamespaceMappingUtils.getPrefix(value) != null){ throw new ConfigurationException(property, "'{prefix}:{localname}' configurations " + "such as '"+value+"' are only supported if the NamespacePrefixService is "
String fieldUri = nps.getFullName(value); if(fieldUri == null){ throw new ConfigurationException(property, "The prefix '" + NamespaceMappingUtils.getPrefix(value)+"' is unknown (not mapped to an " + "namespace) by the Stanbol Namespace Prefix Mapping Service. Please " + "change the configuration to use the full URI instead of '"+value+"'!"); } else if(NamespaceMappingUtils.getPrefix(value) != null){ throw new ConfigurationException(property, "'{prefix}:{localname}' configurations " + "such as '"+value+"' are only supported if the NamespacePrefixService is "
/** * Parses a Value from a JSON Object by reading the 'id' and 'name' keys * @param jValue * @return The value or <code>null</code> if the parsed json object does not * contain the required information. */ private static ReconcileValue parseValueFromV(Object jValue, NamespacePrefixService nsPrefixService) { if(jValue == null){ return null; } String id = ((JSONObject)jValue).optString("id"); if(id != null){ id = nsPrefixService.getFullName(id); if(id == null){ log.warn("Unknown prefix '{}' used by 'id' of element {} -> will use NULL as id", NamespaceMappingUtils.getPrefix(id),jValue.toString()); } } String value = ((JSONObject)jValue).optString("name"); return value != null ? new ReconcileValue(id,value) : null; }