Add create calendar utility
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 14 Jan 2011 08:02:39 +0000 (08:02 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 14 Jan 2011 08:02:39 +0000 (08:02 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4027 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java

index d879c64fb287a7672ac317353eb3603978884944..b7dfdffc3d81e0e4c686f240848606b34595cf26 100644 (file)
 
 package org.argeo.jcr;
 
+import java.text.DateFormat;
+import java.text.ParseException;
 import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.StringTokenizer;
 
 import javax.jcr.NamespaceRegistry;
@@ -124,12 +128,28 @@ public class JcrUtils {
 
        }
 
+       /** Converts in one call a string into a gregorian calendar. */
+       public static Calendar parseCalendar(DateFormat dateFormat, String value) {
+               try {
+                       Date date = dateFormat.parse(value);
+                       Calendar calendar = new GregorianCalendar();
+                       calendar.setTime(date);
+                       return calendar;
+               } catch (ParseException e) {
+                       throw new ArgeoException("Cannot parse " + value
+                                       + " with date format " + dateFormat, e);
+               }
+
+       }
+
+       /** Converts the FQDN of an host into a path (converts '.' into '/'). */
        public static String hostAsPath(String host) {
                // TODO : inverse order of the elements (to have org/argeo/test IO
                // test/argeo/org
                return host.replace('.', '/');
        }
 
+       /** The last element of a path. */
        public static String lastPathElement(String path) {
                if (path.charAt(path.length() - 1) == '/')
                        throw new ArgeoException("Path " + path + " cannot end with '/'");
@@ -191,6 +211,10 @@ public class JcrUtils {
                }
        }
 
+       /**
+        * Safe and repository implementation independent registration of a
+        * namespace.
+        */
        public static void registerNamespaceSafely(Session session, String prefix,
                        String uri) {
                try {
@@ -201,6 +225,10 @@ public class JcrUtils {
                }
        }
 
+       /**
+        * Safe and repository implementation independent registration of a
+        * namespace.
+        */
        public static void registerNamespaceSafely(NamespaceRegistry nr,
                        String prefix, String uri) {
                try {