You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2002/04/04 10:38:45 UTC
cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/util PropertyHelper.java
juergen 02/04/04 00:38:45
Modified: src/webdav/server/org/apache/slide/webdav/util
PropertyHelper.java
Log:
Added utility methods addHrefToProperty() and removeHrefFromProperty().
(ralf)
Revision Changes Path
1.10 +77 -3 jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyHelper.java
Index: PropertyHelper.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyHelper.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PropertyHelper.java 28 Mar 2002 06:12:13 -0000 1.9
+++ PropertyHelper.java 4 Apr 2002 08:38:45 -0000 1.10
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyHelper.java,v 1.9 2002/03/28 06:12:13 jericho Exp $
- * $Revision: 1.9 $
- * $Date: 2002/03/28 06:12:13 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyHelper.java,v 1.10 2002/04/04 08:38:45 juergen Exp $
+ * $Revision: 1.10 $
+ * $Date: 2002/04/04 08:38:45 $
*
* ====================================================================
*
@@ -865,5 +865,79 @@
return buffer.toString();
}
+
+
+ /**
+ * Adds the given <code>uri</code> as a <code><href></code> element
+ * to the value of the property (specified by the <code>propertyName</code>)
+ * of the given NodeRevisionDescriptor (if not already contained).
+ *
+ * @param revisionDescriptor the NodeRevisionDescriptor for which to
+ * update the property.
+ * @param propertyName the name of the property to add the uri to.
+ * @param uri the uri to add as a <code><href></code> element.
+ *
+ * @throws JDOMException if parsing the property failed.
+ */
+ public static void addHrefToProperty(NodeRevisionDescriptor revisionDescriptor, String propertyName, String uri) throws JDOMException {
+
+ NodeProperty property = revisionDescriptor.getProperty(propertyName);
+ if (property == null) {
+ property = new NodeProperty(propertyName, null);
+ }
+ XMLValue xmlValue = new XMLValue((String)property.getValue());
+ Iterator iterator = xmlValue.iterator();
+ boolean alreadyContained = false;
+ Element element = null;
+ while (iterator.hasNext() && !alreadyContained) {
+ element = (Element)iterator.next();
+ if (element.getName().equals(E_HREF) && element.getText().equals(uri)) {
+ alreadyContained = true;
+ }
+ }
+ if (!alreadyContained) {
+ element = new Element(E_HREF);
+ element.setText(uri);
+ xmlValue.add(element);
+ }
+ revisionDescriptor.setProperty(propertyName, xmlValue.toString());
+ }
+
+ /**
+ * Removes the <code><href></code> element with the given <code>uri</code>
+ * from the value of the property (specified by the <code>propertyName</code>)
+ * of the given NodeRevisionDescriptor (if contained).
+ *
+ * @param revisionDescriptor the NodeRevisionDescriptor for which to
+ * update the property.
+ * @param propertyName the name of the property to remove the uri from.
+ * @param uri the uri of the <code><href></code> element
+ * to remove.
+ *
+ * @throws JDOMException if parsing the property failed.
+ */
+ public static void removeHrefFromProperty(NodeRevisionDescriptor revisionDescriptor, String propertyName, String uri) throws JDOMException {
+
+ NodeProperty property = revisionDescriptor.getProperty(propertyName);
+ if (property != null) {
+
+ XMLValue xmlValue = new XMLValue((String)property.getValue());
+ Iterator iterator = xmlValue.iterator();
+ boolean found = false;
+ Element element = null;
+ while (iterator.hasNext() && !found) {
+ element = (Element)iterator.next();
+ if (element.getName().equals(E_HREF) && element.getText().equals(uri)) {
+ found = true;
+ iterator.remove();
+ }
+ }
+ if (found) {
+ revisionDescriptor.setProperty(propertyName, xmlValue.toString());
+ }
+ }
+ }
+
+
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>