--- java/classes/org/w3c/rdf/Element.java 1998/12/15 17:00:44 1.9 +++ java/classes/org/w3c/rdf/Element.java 1999/04/26 14:51:26 1.10 @@ -3,6 +3,9 @@ * and children. * * $Log: Element.java,v $ + * Revision 1.10 1999/04/26 14:51:26 jsaarela + * URI resolution improved. + * * Revision 1.9 1998/12/15 17:00:44 jsaarela * New distribution release V1.7 on 15-Dec-98. * @@ -32,6 +35,7 @@ */ package org.w3c.rdf; +import java.net.URL; import java.util.*; import java.io.*; import org.xml.sax.AttributeList; @@ -42,9 +46,12 @@ public class Element private String m_sName = null; private Hashtable m_attributes = new Hashtable(); private Vector m_children = new Vector(); + private String m_sResource = null; private String m_sID = null; private String m_sBagID = null; - private Hashtable m_nodes = new Hashtable (); + private String m_sAbout = null; + private String m_sAboutEach = null; + private String m_sAboutEachPrefix = null; private Vector m_vTargets = new Vector (); private boolean m_bDone = false; private String m_sPrefix = null; @@ -128,10 +135,26 @@ public class Element return (Element)m_vTargets.elementAt(0); } + public void resource (String sResource) { + m_sResource = sResource; + } + + public void resource (String sResource, String sContext) { + m_sResource = makeAbsolute (sResource, sContext); + } + + public String resource () { + return m_sResource; + } + public void ID (String sID) { m_sID = sID; } + public void ID (String sID, String sContext) { + m_sID = makeAbsolute (sID, sContext); + } + public String ID () { return m_sID; } @@ -140,10 +163,51 @@ public class Element m_sBagID = sBagID; } + + public void bagID (String sBagID, String sContext) { + m_sBagID = makeAbsolute (sBagID, sContext); + } + public String bagID () { return m_sBagID; } + public void about (String sAbout) { + m_sAbout = sAbout; + } + + public void about (String sAbout, String sContext) { + m_sAbout = makeAbsolute (sAbout, sContext); + } + + public String about () { + return m_sAbout; + } + + public void aboutEach (String sAboutEach) { + m_sAboutEach = sAboutEach; + } + + public void aboutEach (String sAboutEach, String sContext) { + m_sAboutEach = makeAbsolute (sAboutEach, sContext); + } + + public String aboutEach () { + return m_sAboutEach; + } + + public void aboutEachPrefix (String sAboutEachPrefix) { + m_sAboutEachPrefix = sAboutEachPrefix; + } + + public void aboutEachPrefix (String sAboutEachPrefix, String sContext) { + m_sAboutEachPrefix = makeAbsolute (sAboutEachPrefix, sContext); + } + + public String aboutEachPrefix () { + return m_sAboutEachPrefix; + } + public void linearize (int indent, PrintStream ps) { for (int x = 0; x < indent; x++) { ps.print (" "); @@ -172,4 +236,57 @@ public class Element public void done (boolean b) { m_bDone = b; } + + /** + * Private methods for this class only + */ + + private String makeAbsolute (String sURI, String context) { + String sResult = new String (); + if (sURI != null && + context != null) { + + /** + * If sURI has .. then it indicates relative URI which + * we must make absolute + */ + if (sURI.startsWith ("..")) { + try { + URL absoluteURL = new URL (new URL(context), sURI); + sResult = absoluteURL.toString(); + } catch(Exception e) { + System.err.println("RDF Resource - cannot combine " + + context + " with " +sURI); + } + } else { + /** + * If sURI is an absolute URI, don't bother + * with it + */ + try { + URL absoluteURL = new URL (sURI); + sResult = absoluteURL.toString(); + + } catch(Exception e) { + /** + * Well, the sURI wasn't absolute either, + * try making absolute with the context + */ + if (sURI.indexOf ('/') > -1) { + try { + URL absoluteURL = new URL (new URL(context), sURI); + sResult = absoluteURL.toString(); + } catch (Exception e2) { + sResult = context + "#" + sURI; + } + } else { + sResult = context + "#" + sURI; + } + } + } + return sResult; + } else { + return sURI; + } + } }