QNameProvider.java revision 2
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi * Created on May 13, 2004
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi * A class to convert URI's to QNames. Borrowed from SWOOP code.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi * @author Evren Sirin
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi // stores a map of uri -> prefix
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi // initialize it with standard stuff
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi public static boolean isNameStartChar(char ch) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi return (Character.isLetter(ch) || ch == '_');
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi return (isNameStartChar(ch) || Character.isDigit(ch) || ch == '.' || ch == '-');
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi public static int findNameStartIndex(String str) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi boolean foundNameChar = false;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for(int strIndex = strChars.length - 1; strIndex >= 0; strIndex--) {
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi else if(foundNameChar && !isNameChar(letter)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi public static int findLastNameIndex(String str) {
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi for(int strIndex = strChars.length - 1; strIndex >= 0; strIndex--) {
dc421f3aac1f0e516c763dd156629a8ed2a7b4caKATOH Yasufumi public static int findNextNonNameIndex(String str, int startIndex) {
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi for(nameIndex = startIndex; nameIndex < strChars.length; nameIndex++) {
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi protected static String[] splitURI(String uriString) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi //System.out.println("Couldn't find name for "+uriString);
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi //System.out.println("Name starts at beginning");
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi //System.out.println("Uri: "+ uri + " Base: " +base);
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi //System.out.println("Prefix < 0");
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi prefixEnd = findNextNonNameIndex(base, prefixStart + 1);
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi prefix = uriString.substring(prefixStart, prefixEnd);
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi String uri = (String) prefixToUri.remove(prefix);
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi public boolean setMapping(String prefix, String uri) {
38d626f8bee1a2163f221f0c274c289a66bc08d2KATOH Yasufumi //System.out.println("Setting prefix "+prefix+": "+uri);
241c3744ca7e43533f8cf76fb5972d715b473aa7KATOH Yasufumi return false;
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi //System.out.println("Shortform for " + uri);
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi public String shortForm(String uri, boolean default_to_uri) {
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi if(possible_prefix.endsWith(".owl") || possible_prefix.endsWith(".rdf")
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi possible_prefix = possible_prefix.substring(0, possible_prefix
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi if(Character.isLowerCase(possible_prefix.charAt(1)))
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi possible_prefix = Character.toLowerCase(possible_prefix.charAt(0))
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi + possible_prefix.substring(1, possible_prefix.length());
bb8eca54d6e2edfb10742b121cce194af065068bKATOH Yasufumi // Check prefix for uniqueness
bb8eca54d6e2edfb10742b121cce194af065068bKATOH Yasufumi qname = prefix.length() == 0 ? name : prefix + ":" + name;
bb8eca54d6e2edfb10742b121cce194af065068bKATOH Yasufumi throw new IllegalArgumentException("Prefix " + prefix + " is not known!");