[Bedework-commit] rpiutil r186 - in trunk/src/edu/rpi/sss/util/xml:
. tagdefs
svnadmin at bedework.org
svnadmin at bedework.org
Fri Sep 3 16:14:59 EDT 2010
Author: douglm
Date: 2010-09-03 16:14:58 -0400 (Fri, 03 Sep 2010)
New Revision: 186
Added:
trunk/src/edu/rpi/sss/util/xml/tagdefs/CalWSTags.java
trunk/src/edu/rpi/sss/util/xml/tagdefs/CalWSXrdDefs.java
trunk/src/edu/rpi/sss/util/xml/tagdefs/XrdTags.java
trunk/src/edu/rpi/sss/util/xml/tagdefs/XsiTags.java
Modified:
trunk/src/edu/rpi/sss/util/xml/XmlEmit.java
Log:
Changes to support ACCEPT header on GET
* Will enable fetching of calendars and address books when targeting collections
* Will be used by new web service to get XRD objects
Changes to XmlEmit to support better abbreviating of namespaces and better handling of default namespace. Also changes to handle some new xrd needs.
CalDAV server has partial support for CalWS - supports GET of XRD object.
Modified: trunk/src/edu/rpi/sss/util/xml/XmlEmit.java
===================================================================
--- trunk/src/edu/rpi/sss/util/xml/XmlEmit.java 2010-08-10 04:16:27 UTC (rev 185)
+++ trunk/src/edu/rpi/sss/util/xml/XmlEmit.java 2010-09-03 20:14:58 UTC (rev 186)
@@ -43,15 +43,45 @@
private boolean noHeaders = false;
+ /**
+ * @author douglm
+ */
+ public static class NameSpace {
+ String ns;
+
+ String abbrev;
+
+ /**
+ * @param ns
+ * @param abbrev
+ */
+ public NameSpace(final String ns, final String abbrev) {
+ this.ns = ns;
+ this.abbrev = abbrev;
+ }
+
+ @Override
+ public int hashCode() {
+ return ns.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ NameSpace that = (NameSpace)o;
+ return ns.equals(that.ns);
+ }
+ }
+
/** We need to map the namespaces onto a set of reasonable abbreviations
* for the generated xml. New set created each request
*/
- private HashMap<String, String> nsMap;
+ private HashMap<String, NameSpace> nsMap;
+
+ private int nsIndex;
+
private boolean noDefaultns;
private String defaultNs;
- private int nsIndex;
-
/** The following allow us to tidy up the output a little.
*/
int indent;
@@ -73,8 +103,8 @@
* @param noDefaultns boolean true if we don't have a default namespace
*/
public XmlEmit(final boolean noHeaders, final boolean noDefaultns) {
- nsMap = new HashMap<String, String>();
- nsIndex = 0;
+ nsMap = new HashMap<String, NameSpace>();
+
this.noHeaders = noHeaders;
this.noDefaultns = noDefaultns;
}
@@ -149,11 +179,25 @@
/**
* @param tag
+ * @param attrName
+ * @param attrVal
* @throws IOException
*/
+ public void openTagNoNewline(final QName tag,
+ final String attrName,
+ final String attrVal) throws IOException {
+ blanks();
+ openTagSameLine(tag, attrName, attrVal);
+ indent += 2;
+ }
+
+ /**
+ * @param tag
+ * @throws IOException
+ */
public void openTagSameLine(final QName tag) throws IOException {
lb();
- tagname(tag);
+ emitQName(tag);
rb();
}
@@ -167,7 +211,7 @@
final String attrName,
final String attrVal) throws IOException {
lb();
- tagname(tag);
+ emitQName(tag);
attribute(attrName, attrVal);
rb();
}
@@ -206,7 +250,7 @@
public void closeTagSameLine(final QName tag) throws IOException {
lb();
wtr.write("/");
- tagname(tag);
+ emitQName(tag);
rb();
}
@@ -230,6 +274,17 @@
startTagSameLine(tag);
}
+ /** Start tag ready for attributes and indent
+ *
+ * @param tag
+ * @throws IOException
+ */
+ public void startTagIndent(final QName tag) throws IOException {
+ blanks();
+ startTagSameLine(tag);
+ indent += 2;
+ }
+
/** Add an attribute
*
* @param attrName
@@ -243,6 +298,25 @@
quote(attrVal);
}
+ /** Add an attribute
+ *
+ * @param attr
+ * @param attrVal
+ * @throws IOException
+ */
+ public void attribute(final QName attr, final String attrVal) throws IOException {
+ wtr.write(" ");
+
+ emitQName(attr);
+
+ wtr.write("=");
+ quote(attrVal);
+
+ if (!noHeaders && mustEmitNS) {
+ emitNs();
+ }
+ }
+
/** End a tag
*
* @throws IOException
@@ -266,7 +340,7 @@
*/
public void emptyTagSameLine(final QName tag) throws IOException {
lb();
- tagname(tag);
+ emitQName(tag);
wtr.write("/");
rb();
}
@@ -277,7 +351,7 @@
*/
public void startTagSameLine(final QName tag) throws IOException {
lb();
- tagname(tag);
+ emitQName(tag);
}
private void quote(final String val) throws IOException {
@@ -415,7 +489,8 @@
* @param tagVal
* @throws IOException
*/
- public void propertyTagVal(final QName tag, final QName tagVal) throws IOException {
+ public void propertyTagVal(final QName tag,
+ final QName tagVal) throws IOException {
blanks();
openTagSameLine(tag);
emptyTagSameLine(tagVal);
@@ -433,26 +508,53 @@
/** Called before we start to emit any tags.
*
* @param val
+ * @param makeDefaultNs - true => make this the default
+ * @throws IOException
*/
- public void addNs(final String val) {
- if (nsMap.get(val) != null) {
- return;
+ public void addNs(final NameSpace val,
+ final boolean makeDefaultNs) throws IOException {
+ if (val.abbrev == null) {
+ val.abbrev = "ns" + nsIndex;
+ nsIndex++;
}
- String ns = "ns" + nsIndex;
- if ((nsIndex == 0) && !noDefaultns) {
- defaultNs = ns;
+ for (NameSpace ns: nsMap.values()) {
+ if (val.equals(ns)) {
+ continue;
+ }
+
+ if (val.abbrev.equals(ns.abbrev)) {
+ throw new IOException("Duplicate namespace alias for " + val.ns);
+ }
}
- nsMap.put(val, ns);
- nsIndex++;
+
+ nsMap.put(val.ns, val);
+
+ if (makeDefaultNs && !noDefaultns) {
+ defaultNs = val.ns;
+ }
}
/**
* @param ns
+ * @return NameSpace if present
+ */
+ public NameSpace getNameSpace(final String ns) {
+ return nsMap.get(ns);
+ }
+
+ /**
+ * @param ns
* @return namespace abrev
*/
public String getNsAbbrev(final String ns) {
- return nsMap.get(ns);
+ NameSpace n = nsMap.get(ns);
+
+ if (n == null) {
+ return null;
+ }
+
+ return n.abbrev;
}
/** Write a new line
@@ -469,13 +571,13 @@
* @param tag
* @throws IOException
*/
- private void tagname(final QName tag) throws IOException {
+ private void emitQName(final QName tag) throws IOException {
String ns = tag.getNamespaceURI();
- if (ns != null) {
+ if ((ns != null) && !ns.equals(defaultNs)) {
String abbr = getNsAbbrev(ns);
- if ((abbr != null) && (!abbr.equals(defaultNs))) {
+ if (abbr != null) {
wtr.write(abbr);
wtr.write(":");
}
@@ -484,25 +586,34 @@
wtr.write(tag.getLocalPart());
if (!noHeaders && mustEmitNS) {
- /* First tag so emit the name space declarations.
- */
- for (String nsp: nsMap.keySet()) {
- wtr.write(" xmlns");
+ emitNs();
+ }
+ }
- String abbr = getNsAbbrev(nsp);
+ private void emitNs() throws IOException {
+ /* First tag so emit the name space declarations.
+ */
+ String delim = "";
- if ((abbr != null) && (!abbr.equals(defaultNs))) {
- wtr.write(":");
- wtr.write(abbr);
- }
+ for (String nsp: nsMap.keySet()) {
+ wtr.write(delim);
+ delim = "\n ";
- wtr.write("=\"");
- wtr.write(nsp);
- wtr.write("\"");
+ wtr.write(" xmlns");
+
+ String abbr = getNsAbbrev(nsp);
+
+ if ((abbr != null) && !nsp.equals(defaultNs)) {
+ wtr.write(":");
+ wtr.write(abbr);
}
- mustEmitNS = false;
+ wtr.write("=\"");
+ wtr.write(nsp);
+ wtr.write("\"");
}
+
+ mustEmitNS = false;
}
/* Write out the xml header
Added: trunk/src/edu/rpi/sss/util/xml/tagdefs/CalWSTags.java
===================================================================
--- trunk/src/edu/rpi/sss/util/xml/tagdefs/CalWSTags.java (rev 0)
+++ trunk/src/edu/rpi/sss/util/xml/tagdefs/CalWSTags.java 2010-09-03 20:14:58 UTC (rev 186)
@@ -0,0 +1,84 @@
+/* **********************************************************************
+ Copyright 2010 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+package edu.rpi.sss.util.xml.tagdefs;
+
+import javax.xml.namespace.QName;
+
+/** Define CalWS tags for XMlEmit.
+ *
+ * @see "http://docs.oasis-open.org/xri/xrd/v1.0/xrd-1.0.html"
+ *
+ * @author Mike Douglass douglm - rpi.edu
+ */
+public class CalWSTags {
+ /** */
+ public static final String namespace = "http://docs.oasis-open.org/ns/wscal/calws";
+
+ /** */
+ public static final QName afterMaxDateTime = new QName(namespace, "after-max-date-time");
+
+ /** */
+ public static final QName beforeMinDateTime = new QName(namespace, "before-min-date-time");
+
+ /** */
+ public static final QName description = new QName(namespace, "description");
+
+ /** */
+ public static final QName error = new QName(namespace, "error");
+
+ /** */
+ public static final QName exceedsMaxResourceSize = new QName(namespace, "exceeds-max-resource-size");
+
+ /** */
+ public static final QName href = new QName(namespace, "href");
+
+ /** */
+ public static final QName invalidCalendarCollectionLocation = new QName(namespace, "invalid-calendar-collection-location");
+
+ /** */
+ public static final QName invalidCalendarData = new QName(namespace, "invalid-calendar-data");
+
+ /** */
+ public static final QName invalidCalendarObjectResource = new QName(namespace, "invalid-calendar-object-resource");
+
+ /** */
+ public static final QName notCalendarData = new QName(namespace, "not-calendar-data");
+
+ /** */
+ public static final QName targetExists = new QName(namespace, "target-exists");
+
+ /** */
+ public static final QName tooManyAttendeesPerInstance = new QName(namespace, "too-many-attendees-per-instance");
+
+ /** */
+ public static final QName tooManyInstances = new QName(namespace, "too-many-instances");
+
+ /** */
+ public static final QName uidConflict = new QName(namespace, "uid-conflict");
+
+ /** */
+ public static final QName unsupportedCalendarComponent = new QName(namespace, "unsupported-calendar-component");
+}
Added: trunk/src/edu/rpi/sss/util/xml/tagdefs/CalWSXrdDefs.java
===================================================================
--- trunk/src/edu/rpi/sss/util/xml/tagdefs/CalWSXrdDefs.java (rev 0)
+++ trunk/src/edu/rpi/sss/util/xml/tagdefs/CalWSXrdDefs.java 2010-09-03 20:14:58 UTC (rev 186)
@@ -0,0 +1,123 @@
+/* **********************************************************************
+ Copyright 2010 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+package edu.rpi.sss.util.xml.tagdefs;
+
+
+/** Define CalWS xrd link reltypes and property types for XMlEmit.
+ *
+ * @see "http://docs.oasis-open.org/xri/xrd/v1.0/xrd-1.0.html"
+ *
+ * @author Mike Douglass douglm - rpi.edu
+ */
+public class CalWSXrdDefs {
+ /** */
+ public static final String namespace = "http://docs.oasis-open.org/ns/wscal/calws";
+
+ /* ====================================================================
+ * Property types
+ * ==================================================================== */
+
+ /** property */
+ public static final String supportedFeatures = namespace + "/" +
+ "supported-features";
+
+ //public static final String supportedFeatures = namespace + "/" +
+ // "calendarFreeBusySet";
+
+ /** property */
+ public static final String maxAttendeesPerInstance = namespace + "/" +
+ "max-attendees-per-instance";
+
+ /** property */
+ public static final String maxDateTime = namespace + "/" +
+ "max-date-time";
+
+ /** property */
+ public static final String maxInstances = namespace + "/" +
+ "max-instances";
+
+ /** property */
+ public static final String maxResourceSize = namespace + "/" +
+ "max-resource-size";
+
+ /** property */
+ public static final String minDateTime = namespace + "/" +
+ "min-date-time";
+
+ /* ====================================================================
+ * Link relations
+ * ==================================================================== */
+
+ /** Link */
+ public static final String childCollection = namespace + "/" + "child-collection";
+
+ /** Link */
+ public static final String currentPrincipalFreebusy = namespace + "/" +
+ "current-principal-freebusy";
+
+ /** Link */
+ public static final String principalFreebusy = namespace + "/" + "principal-freebusy";
+
+ /** Link */
+ public static final String principalHome = namespace + "/" + "principal-home";
+
+ /** Link */
+ public static final String timezoneService = namespace + "/" + "timezone-service";
+
+ /* ====================================================================
+ * Link Properties
+ * ==================================================================== */
+
+ /** Link property */
+ public static final String calendarCollection = namespace + "/" + "calendar-collection";
+
+ /** Link property */
+ public static final String collection = namespace + "/" + "collection";
+
+ /** Link property */
+ public static final String created = namespace + "/" + "created";
+
+ /** Link property */
+ public static final String description = namespace + "/" + "description";
+
+ /** Link property */
+ public static final String displayname = namespace + "/" + "displayname";
+
+ /** Link property */
+ public static final String inbox = namespace + "/" + "inbox";
+
+ /** Link property */
+ public static final String lastModified = namespace + "/" + "last-modified";
+
+ /** Link property */
+ public static final String outbox = namespace + "/" + "outbox";
+
+ /** Link property */
+ public static final String owner = namespace + "/" + "owner";
+
+ /** Link property */
+ public static final String timezone = namespace + "/" + "timezone";
+}
Added: trunk/src/edu/rpi/sss/util/xml/tagdefs/XrdTags.java
===================================================================
--- trunk/src/edu/rpi/sss/util/xml/tagdefs/XrdTags.java (rev 0)
+++ trunk/src/edu/rpi/sss/util/xml/tagdefs/XrdTags.java 2010-09-03 20:14:58 UTC (rev 186)
@@ -0,0 +1,60 @@
+/* **********************************************************************
+ Copyright 2005 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+package edu.rpi.sss.util.xml.tagdefs;
+
+import javax.xml.namespace.QName;
+
+/** Define XRD tags for XMlEmit.
+ *
+ * @see "http://docs.oasis-open.org/xri/xrd/v1.0/xrd-1.0.html"
+ *
+ * @author Mike Douglass douglm - rpi.edu
+ */
+public class XrdTags {
+ /** */
+ public static final String namespace = "http://docs.oasis-open.org/ns/xri/xrd-1.0";
+
+ /** */
+ public static final QName alias = new QName(namespace, "Alias");
+
+ /** */
+ public static final QName expires = new QName(namespace, "Expires");
+
+ /** */
+ public static final QName link = new QName(namespace, "Link");
+
+ /** */
+ public static final QName property = new QName(namespace, "Property");
+
+ /** */
+ public static final QName subject = new QName(namespace, "Subject");
+
+ /** */
+ public static final QName title = new QName(namespace, "Title");
+
+ /** */
+ public static final QName xrd = new QName(namespace, "XRD");
+}
Added: trunk/src/edu/rpi/sss/util/xml/tagdefs/XsiTags.java
===================================================================
--- trunk/src/edu/rpi/sss/util/xml/tagdefs/XsiTags.java (rev 0)
+++ trunk/src/edu/rpi/sss/util/xml/tagdefs/XsiTags.java 2010-09-03 20:14:58 UTC (rev 186)
@@ -0,0 +1,42 @@
+/* **********************************************************************
+ Copyright 2005 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+package edu.rpi.sss.util.xml.tagdefs;
+
+import javax.xml.namespace.QName;
+
+/** Define XRD tags for XMlEmit.
+ *
+ * @see "http://docs.oasis-open.org/xri/xrd/v1.0/xrd-1.0.html"
+ *
+ * @author Mike Douglass douglm - rpi.edu
+ */
+public class XsiTags {
+ /** */
+ public static final String namespace = "http://www.w3.org/2001/XMLSchema-instance";
+
+ /** */
+ public static final QName nil = new QName(namespace, "nil");
+}
More information about the Bedework-commit
mailing list