KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > content > NodeRevisionDescriptor


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/content/NodeRevisionDescriptor.java,v 1.34.2.4 2004/09/26 14:14:06 luetzkendorf Exp $
3  * $Revision: 1.34.2.4 $
4  * $Date: 2004/09/26 14:14:06 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.content;
25
26 import java.io.Serializable JavaDoc;
27 import java.text.ParseException JavaDoc;
28 import java.text.SimpleDateFormat JavaDoc;
29 import java.util.Date JavaDoc;
30 import java.util.Enumeration JavaDoc;
31 import java.util.Hashtable JavaDoc;
32 import java.util.Locale JavaDoc;
33 import java.util.TimeZone JavaDoc;
34 import java.util.Vector JavaDoc;
35
36 import org.apache.slide.common.ObjectValidationFailedException;
37 import org.apache.slide.util.EmptyEnumeration;
38 import org.apache.slide.util.Messages;
39
40 /**
41  * Node Revision Descriptor class.
42  *
43  * @version $Revision: 1.34.2.4 $
44  */

45 public final class NodeRevisionDescriptor implements Serializable JavaDoc, Cloneable JavaDoc {
46     
47     
48     // -------------------------------------------------------------- Constants
49

50     
51     /**
52      * Creation date.
53      */

54     public static final String JavaDoc CREATION_DATE = "creationdate";
55     public static final String JavaDoc CREATION_USER = "creationuser";
56     public static final String JavaDoc MODIFICATION_DATE = "modificationdate";
57     public static final String JavaDoc MODIFICATION_USER = "modificationuser";
58     
59     
60     /**
61      * Last modification date.
62      */

63     public static final String JavaDoc LAST_MODIFIED = "getlastmodified";
64     
65     
66     /**
67      * Name.
68      */

69     public static final String JavaDoc NAME = "displayname";
70     
71     
72     /**
73      * Type.
74      */

75     public static final String JavaDoc RESOURCE_TYPE = "resourcetype";
76     public static final String JavaDoc TYPE = RESOURCE_TYPE;
77     
78     
79     /**
80      * Source.
81      */

82     public static final String JavaDoc SOURCE = "source";
83     
84     
85     /**
86      * Owner.
87      */

88     public static final String JavaDoc OWNER = "owner";
89     
90     
91     /**
92      * MIME type of the content.
93      */

94     public static final String JavaDoc CONTENT_TYPE = "getcontenttype";
95     
96     
97     /**
98      * Content language.
99      */

100     public static final String JavaDoc CONTENT_LANGUAGE = "getcontentlanguage";
101     
102     
103     /**
104      * Content length.
105      */

106     public static final String JavaDoc CONTENT_LENGTH = "getcontentlength";
107     
108     
109     /**
110      * ETag.
111      */

112     public static final String JavaDoc ETAG = "getetag";
113     
114     
115     /**
116      * Collection type.
117      */

118     public static final String JavaDoc COLLECTION_TYPE = "<collection/>";
119     
120     
121     /**
122      * HTTP date format.
123      */

124     protected static final SimpleDateFormat JavaDoc format =
125         new SimpleDateFormat JavaDoc("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
126     
127     
128     /**
129      * Date formats using for Date parsing.
130      */

131     protected static final SimpleDateFormat JavaDoc formats[] = {
132         new SimpleDateFormat JavaDoc("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
133             new SimpleDateFormat JavaDoc("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US),
134             new SimpleDateFormat JavaDoc("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
135             new SimpleDateFormat JavaDoc("EEE MMMM d HH:mm:ss yyyy", Locale.US),
136             new SimpleDateFormat JavaDoc("yyyy-MM-dd'T'HH:mm:ss'Z'")
137     };
138     
139     
140     /**
141      * Simple date format for the creation date ISO representation (partial).
142      */

143     protected static final SimpleDateFormat JavaDoc creationDateFormat =
144         new SimpleDateFormat JavaDoc("yyyy-MM-dd'T'HH:mm:ss'Z'");
145     
146     
147     static {
148         format.setTimeZone(TimeZone.getTimeZone("GMT"));
149         creationDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
150         for (int i = 0; i < formats.length; i++) {
151             formats[i].setTimeZone(TimeZone.getTimeZone("GMT"));
152         }
153     }
154     
155     
156     // ----------------------------------------------------------- Constructors
157

158     
159     /**
160      * Constructor.
161      */

162     public NodeRevisionDescriptor() {
163         this.properties = new Hashtable JavaDoc();
164         this.labels = new Vector JavaDoc();
165         this.branchName = NodeRevisionDescriptors.MAIN_BRANCH;
166         initDefaultProperties();
167     }
168     
169     
170     /**
171      * Constructor for client applications.
172      */

173     public NodeRevisionDescriptor(long contentLength) {
174         this();
175         setContentLength(contentLength);
176     }
177     
178     
179     /**
180      * Constructor used for retrieval. Can be used by client apps, but it is
181      * mostly useless as number and creationDate fields are ignored during
182      * revision creation.
183      */

184     public NodeRevisionDescriptor(NodeRevisionNumber number, String JavaDoc branchName,
185                                   Vector JavaDoc labels, Hashtable JavaDoc properties) {
186         this();
187         this.number = number;
188         if (branchName != null) {
189             this.branchName = branchName;
190         }
191         this.labels = labels;
192         setProperties(properties);
193     }
194     
195     
196     // ----------------------------------------------------- Instance Variables
197

198     
199     /**
200      * Branch name.
201      */

202     private String JavaDoc branchName;
203     
204     
205     /**
206      * Revision number.
207      */

208     private NodeRevisionNumber number;
209     
210     
211     /**
212      * Revision labels.
213      */

214     private Vector JavaDoc labels;
215     
216     
217     /**
218      * Properties field.
219      */

220     private Hashtable JavaDoc properties;
221
222     /**
223      * Track updated properties
224      */

225     private Hashtable JavaDoc updatedProperties = null;
226     private Hashtable JavaDoc removedProperties = null;
227
228     
229     // ------------------------------------------------------------- Properties
230

231     
232     /**
233      * Branch name accessor.
234      */

235     public String JavaDoc getBranchName() {
236         return this.branchName;
237     }
238     
239     
240     /**
241      * Branch name mutator.
242      */

243     void setBranchName(String JavaDoc branchName) {
244         this.branchName = branchName;
245     }
246     
247     
248     /**
249      * Revision number accessor.
250      */

251     public NodeRevisionNumber getRevisionNumber() {
252         return this.number;
253     }
254     
255     
256     /**
257      * Revision number mutator.
258      */

259     void setRevisionNumber(NodeRevisionNumber number) {
260         this.number = number;
261     }
262     
263     
264     /**
265      * Add new label.
266      */

267     public void addLabel(String JavaDoc label) {
268         this.labels.addElement(label);
269     }
270     
271     
272     /**
273      * Remove a label.
274      */

275     public void removeLabel(String JavaDoc label) {
276         this.labels.removeElement(label);
277     }
278     
279     
280     /**
281      * Remove all labels.
282      */

283     public void removeLabels() {
284         this.labels.removeAllElements();
285     }
286     
287     
288     /**
289      * Remove specified labels.
290      */

291     /* public void removeLabels(Collection c) {
292      this.labels.removeAll(c);
293      }*/

294     
295     
296     /**
297      * Enumerate labels.
298      */

299     public Enumeration JavaDoc enumerateLabels() {
300         return this.labels.elements();
301     }
302     
303     
304     /**
305      * Properties accessor.
306      */

307     Hashtable JavaDoc getProperties() {
308         return this.properties;
309     }
310     
311     
312     /**
313      * Properties mutator.
314      */

315     void setProperties(Hashtable JavaDoc properties) {
316         // FIXME : Do a clean merge
317
this.properties = properties;
318         this.updatedProperties = new Hashtable JavaDoc(properties);
319     }
320     
321     
322     /**
323      * Tests if a property has been set.
324      *
325      * @param name Property name
326      * @return true if the property has been set
327      */

328     public boolean exists(String JavaDoc name) {
329         return exists(name, NodeProperty.DEFAULT_NAMESPACE);
330     }
331     
332     
333     /**
334      * Tests if a property has been set.
335      *
336      * @param name Property name
337      * @return true if the property has been set
338      */

339     public boolean exists(String JavaDoc name, String JavaDoc namespace) {
340         if (name != null)
341             return (properties.get(getNamespacedPropertyName(namespace,name)) != null);
342         else
343             return (false);
344     }
345     
346     
347     /**
348      * Property accessor.
349      *
350      * @param name Property name
351      * @return String property value
352      */

353     public NodeProperty getProperty(String JavaDoc name) {
354         return getProperty(name, NodeProperty.DEFAULT_NAMESPACE);
355     }
356     
357     
358     /**
359      * Property accessor.
360      *
361      * @param name Property name
362      * @param namespace Property namespace
363      * @return String property value
364      */

365     public NodeProperty getProperty(String JavaDoc name, String JavaDoc namespace) {
366         Object JavaDoc result = properties.get(getNamespacedPropertyName(namespace,name));
367         if (result != null) {
368             return (NodeProperty) result;
369         } else {
370             return null;
371         }
372     }
373     
374     
375     /**
376      * Property mutator.
377      *
378      * @param name Property name
379      * @param value Property value
380      */

381     public void setProperty(String JavaDoc name, Object JavaDoc value) {
382         setProperty(new NodeProperty(name, value));
383     }
384     
385     
386     /**
387      * Property mutator.
388      *
389      * @param name Property name
390      * @param value Property value
391      * @param namespace Property value
392      */

393     public void setProperty(String JavaDoc name, String JavaDoc namespace, Object JavaDoc value) {
394         setProperty(new NodeProperty(name, value, namespace));
395     }
396     
397     
398     /**
399      * Property mutatory.
400      *
401      * @param property Property
402      */

403     public void setProperty(NodeProperty property) {
404         String JavaDoc name = getNamespacedPropertyName(property.getNamespace(), property.getName());
405         properties.put(name, property);
406         
407         if (this.updatedProperties == null) this.updatedProperties = new Hashtable JavaDoc();
408         if (this.removedProperties == null) this.removedProperties = new Hashtable JavaDoc();
409         updatedProperties.put(name, property);
410         removedProperties.remove(name);
411     }
412     
413     
414     /**
415      * Remove a property.
416      *
417      * @param property
418      * Property
419      */

420     public void removeProperty(NodeProperty property) {
421         removeProperty(property.getName(), property.getNamespace());
422     }
423     
424     
425     /**
426      * Remove a property.
427      *
428      * @param property Property
429      */

430     public void removeProperty(String JavaDoc property) {
431         removeProperty(property, NodeProperty.DEFAULT_NAMESPACE);
432     }
433     
434     
435     /**
436      * Remove a property.
437      *
438      * @param property Property
439      */

440     public void removeProperty(String JavaDoc property, String JavaDoc nameSpace) {
441         String JavaDoc name = getNamespacedPropertyName(nameSpace, property);
442         NodeProperty nodeProperty = (NodeProperty )properties.remove(name);
443         // check if the property existed before
444
if (nodeProperty != null) {
445             if (this.updatedProperties == null) this.updatedProperties = new Hashtable JavaDoc();
446             if (this.removedProperties == null) this.removedProperties = new Hashtable JavaDoc();
447
448             removedProperties.put(name, nodeProperty);
449             updatedProperties.remove(name);
450         }
451     }
452     
453     
454     /**
455      * Properties names enumerator.
456      *
457      * @return Enumeration of the properties names
458      * @deprecated Replaced by enumeratePropertiesName
459      */

460     public Enumeration JavaDoc getPropertiesNames() {
461         return enumeratePropertiesName();
462     }
463     
464     
465     /**
466      * Properties names enumerator.
467      *
468      * @return Enumeration of the properties names
469      */

470     public Enumeration JavaDoc enumeratePropertiesName() {
471         Vector JavaDoc result = new Vector JavaDoc();
472         Enumeration JavaDoc propertyList = enumerateProperties();
473         while (propertyList.hasMoreElements()) {
474             NodeProperty currentProperty =
475                 (NodeProperty) propertyList.nextElement();
476             result.addElement(currentProperty.getName());
477         }
478         return result.elements();
479     }
480     
481     
482     /**
483      * Properties values enumerator.
484      *
485      * @return Enumeration of the properties values
486      * @deprecated Replaced by enumerate properties
487      */

488     public Enumeration JavaDoc getPropertiesValues() {
489         return enumerateProperties();
490     }
491     
492     
493     /**
494      * Properties values enumerator.
495      *
496      * @return Enumeration of the properties values
497      */

498     public Enumeration JavaDoc enumerateProperties() {
499         return properties.elements();
500     }
501
502     public Enumeration JavaDoc enumerateRemovedProperties() {
503         if (this.removedProperties == null) {
504             return EmptyEnumeration.INSTANCE;
505         } else {
506             return removedProperties.elements();
507         }
508     }
509
510     public Enumeration JavaDoc enumerateUpdatedProperties() {
511         if (this.updatedProperties == null) {
512             return EmptyEnumeration.INSTANCE;
513         } else {
514             return updatedProperties.elements();
515         }
516     }
517
518     public void resetUpdatedProperties() {
519         updatedProperties = null;
520     }
521
522     public void resetRemovedProperties() {
523         removedProperties = null;
524     }
525                                      
526     /**
527      * Checks whether the value of the given property contains the specified
528      * substring.
529      *
530      * @param name the property name
531      * @param substr the substring to check
532      * @return true, if the value of the given property contains the specified
533      * substring
534      */

535     public boolean propertyValueContains( String JavaDoc name, String JavaDoc substr ) {
536         boolean result = false;
537         NodeProperty p = getProperty( name );
538         
539         if( p != null ) {
540             Object JavaDoc v = p.getValue();
541             if( v instanceof String JavaDoc && ((String JavaDoc)v).indexOf(substr) >= 0 )
542                 result = true;
543         }
544         
545         return result;
546     }
547     
548     
549     /**
550      * Checks whether the value of the given property contains the specified
551      * substring.
552      *
553      * @param name the property name
554      * @param namespace the namespace
555      * @param substr the substring to check
556      * @return true, if the value of the given property contains the specified
557      * substring
558      */

559     public boolean propertyValueContains( String JavaDoc name, String JavaDoc namespace, String JavaDoc substr ) {
560         boolean result = false;
561         NodeProperty p = getProperty( name, namespace );
562         
563         if( p != null ) {
564             Object JavaDoc v = p.getValue();
565             if( v instanceof String JavaDoc && ((String JavaDoc)v).indexOf(substr) >= 0 )
566                 result = true;
567         }
568         
569         return result;
570     }
571     
572     
573     /**
574      * Name accessor.
575      *
576      * @return String name
577      */

578     public String JavaDoc getName() {
579         NodeProperty name = getProperty(NAME);
580         if (name == null) {
581             return new String JavaDoc();
582         } else {
583             return (String JavaDoc) name.getValue();
584         }
585     }
586     
587     
588     /**
589      * Name mutator.
590      *
591      * @param name New name
592      */

593     public void setName(String JavaDoc name) {
594         setProperty(NAME, name); // live property, but can be modified
595
}
596     
597     
598     /**
599      * Get the ETAG property (if any).
600      *
601      * @return String
602      */

603     public String JavaDoc getETag() {
604         NodeProperty contentType = getProperty(ETAG);
605         if (contentType == null) {
606             return new String JavaDoc();
607         } else {
608             return (String JavaDoc) contentType.getValue();
609         }
610     }
611     
612     
613     /**
614      * Set ETAG property.
615      *
616      * @param eTag New etag
617      */

618     public void setETag(String JavaDoc eTag) {
619         setProperty(ETAG, eTag); // live property, can not be modified
620
}
621     
622     
623     
624     
625     
626     /**
627      * Get the owner property (if any).
628      *
629      * @return String
630      */

631     public String JavaDoc getOwner() {
632         NodeProperty owner = getProperty(OWNER);
633         if (owner == null) {
634             return new String JavaDoc();
635         } else {
636             return (String JavaDoc) owner.getValue();
637         }
638     }
639     
640     
641     /**
642      * Set owner property.
643      *
644      * @param owner New owner
645      */

646     public void setOwner(String JavaDoc owner) {
647         setProperty(OWNER, owner); // live property, can not be modified
648
}
649     
650     /**
651      * Set owner property.
652      *
653      * @param owner New owner
654      */

655     public void setOwner(String JavaDoc owner, String JavaDoc userpath) {
656         setProperty(OWNER, userpath + "/" + owner); // live property, can not be modified
657
}
658     
659     /**
660      * Get the source property (if any).
661      *
662      * @return String
663      */

664     public String JavaDoc getSource() {
665         NodeProperty source = getProperty(SOURCE);
666         if (source == null) {
667             return new String JavaDoc();
668         } else {
669             return (String JavaDoc) source.getValue();
670         }
671     }
672     
673     
674     /**
675      * Set source property.
676      *
677      * @param source New source
678      */

679     public void setSource(String JavaDoc source) {
680         setProperty(SOURCE, source); // live property, can not be modified
681
}
682     
683     
684     
685     
686     
687     
688     /**
689      * Get the ResourceType property (if any).
690      *
691      * @return String
692      */

693     public String JavaDoc getResourceType() {
694         NodeProperty resourceType = getProperty(RESOURCE_TYPE);
695         if (resourceType == null) {
696             return new String JavaDoc();
697         } else {
698 // return (String) resourceType.getValue();
699
return String.valueOf(resourceType.getValue());
700             
701         }
702     }
703     
704     
705     /**
706      * Set ResourceType property.
707      *
708      * @param resourceType New ResourceType
709      */

710     public void setResourceType(String JavaDoc resourceType) {
711         setProperty(RESOURCE_TYPE, resourceType); // live property, can not be modified
712
}
713     
714     
715     
716     
717     /**
718      * Get the MIME content type of the data (if any).
719      *
720      * @return String
721      */

722     public String JavaDoc getContentType() {
723         NodeProperty contentType = getProperty(CONTENT_TYPE);
724         if (contentType == null) {
725             return new String JavaDoc();
726         } else {
727             return (String JavaDoc) contentType.getValue();
728         }
729     }
730     
731     
732     /**
733      * Content type mutator.
734      *
735      * @param contentType New content type
736      */

737     public void setContentType(String JavaDoc contentType) {
738         setProperty(CONTENT_TYPE, contentType); // live property, can not be modified
739
}
740     
741     
742     /**
743      * Content language accessor.
744      *
745      * @return String content language
746      */

747     public String JavaDoc getContentLanguage() {
748         NodeProperty contentLanguage = getProperty(CONTENT_LANGUAGE);
749         if (contentLanguage == null) {
750             return new String JavaDoc();
751         } else {
752             return (String JavaDoc) contentLanguage.getValue();
753         }
754     }
755     
756     
757     /**
758      * Content language mutator.
759      *
760      * @param contentLanguage New content language
761      */

762     public void setContentLanguage(String JavaDoc contentLanguage) {
763         setProperty(CONTENT_LANGUAGE, contentLanguage); // live property, can not be modified
764
}
765     
766     
767     /**
768      * Creation date accessor.
769      *
770      * @return String creation date
771      */

772     public String JavaDoc getCreationDate() {
773         NodeProperty creationDate = getProperty(CREATION_DATE);
774         if (creationDate == null) {
775             return null;
776         } else {
777             if (creationDate.getValue() instanceof Date JavaDoc) {
778                 return creationDateFormat.format
779                     ((Date JavaDoc) creationDate.getValue());
780             }
781             return creationDate.getValue().toString();
782         }
783     }
784     
785     
786     /**
787      * Modification date accessor.
788      *
789      * @return String modification date
790      */

791     public String JavaDoc getModificationDate() {
792         NodeProperty modificationDate = getProperty(MODIFICATION_DATE);
793         if (modificationDate == null) {
794             return null;
795         } else {
796             if (modificationDate.getValue() instanceof Date JavaDoc) {
797                 return creationDateFormat.format
798                     ((Date JavaDoc) modificationDate.getValue());
799             }
800             return modificationDate.getValue().toString();
801         }
802     }
803     
804     
805     /**
806      * Get the creation user
807      *
808      * @return String
809      */

810     public String JavaDoc getCreationUser() {
811         NodeProperty creationUser = getProperty(CREATION_USER);
812         if (creationUser == null) {
813             return new String JavaDoc();
814         } else {
815             return (String JavaDoc) creationUser.getValue();
816         }
817     }
818     
819     
820     /**
821      * Get the mofications user
822      *
823      * @return String
824      */

825     public String JavaDoc getModificationUser() {
826         NodeProperty modificationUser = getProperty(MODIFICATION_USER);
827         if (modificationUser == null) {
828             return new String JavaDoc();
829         } else {
830             return (String JavaDoc) modificationUser.getValue();
831         }
832     }
833     
834     
835     /**
836      * Creation date accessor.
837      *
838      * @return String creation date
839      */

840     public Date JavaDoc getCreationDateAsDate() {
841         NodeProperty creationDate = getProperty(CREATION_DATE);
842         if (creationDate == null)
843             return null;
844         if (creationDate.getValue() instanceof Date JavaDoc) {
845             return (Date JavaDoc) creationDate.getValue();
846         } else {
847             String JavaDoc creationDateValue = creationDate.getValue().toString();
848             Date JavaDoc result = null;
849             // Parsing the HTTP Date
850
for (int i = 0; (result == null) && (i < formats.length); i++) {
851                 try {
852                     synchronized (formats[i]) {
853                         result = formats[i].parse(creationDateValue);
854                     }
855                 } catch (ParseException JavaDoc e) {
856                     ;
857                 }
858             }
859             return result;
860         }
861     }
862     
863     
864     /**
865      * Creation date mutator.
866      *
867      * @param creationDate New creation date
868      */

869     public void setCreationDate(Date JavaDoc creationDate) {
870         // live property, can not be modified
871
setProperty(CREATION_DATE, creationDateFormat.format(creationDate));
872     }
873      
874     
875     /**
876      * Modification date mutator.
877      *
878      * @param modificationDate New modification date
879      */

880     public void setModificationDate(Date JavaDoc modificationDate) {
881         // live property, can not be modified
882
setProperty(MODIFICATION_DATE, creationDateFormat.format(modificationDate));
883     }
884      
885     
886     /**
887      * Modification date mutator.
888      *
889      * @param modificationDate New modification date
890      */

891     public void setModificationDate(String JavaDoc modificationDate) {
892         // live property, can not be modified
893
setProperty(MODIFICATION_DATE, modificationDate);
894     }
895      
896     
897     /**
898      * Creation user mutator.
899      *
900      * @param creationUser New creation user
901      */

902     public void setCreationUser(String JavaDoc creationUser) {
903         // live property, can not be modified
904
setProperty(CREATION_USER, creationUser);
905     }
906      
907     
908     /**
909      * Modification user mutator.
910      *
911      * @param modificationUser New modification user
912      */

913     public void setModificationUser(String JavaDoc modificationUser) {
914         // live property, can not be modified
915
setProperty(MODIFICATION_USER, modificationUser);
916     }
917     
918     
919     /**
920      * Creation date mutator.
921      *
922      * @param creationDate New creation date
923      */

924     public void setCreationDate(String JavaDoc creationDate) {
925         setProperty(CREATION_DATE, creationDate); // live property, can not be modified
926
}
927     
928     
929     /**
930      * Last modification date accessor.
931      *
932      * @return String last modification date
933      */

934     public String JavaDoc getLastModified() {
935         NodeProperty lastModified = getProperty(LAST_MODIFIED);
936         if (lastModified == null) {
937             return null;
938         } else {
939             if (lastModified.getValue() instanceof Date JavaDoc) {
940                 return format.format((Date JavaDoc) lastModified.getValue());
941             } else {
942                 return lastModified.getValue().toString();
943             }
944         }
945     }
946     
947     
948     /**
949      * Creation date accessor.
950      *
951      * @return String creation date
952      */

953     public Date JavaDoc getLastModifiedAsDate() {
954         NodeProperty lastModified = getProperty(LAST_MODIFIED);
955         if (lastModified == null)
956             return null;
957         if (lastModified.getValue() instanceof Date JavaDoc) {
958             return (Date JavaDoc) lastModified.getValue();
959         } else {
960             String JavaDoc lastModifiedValue = lastModified.getValue().toString();
961             Date JavaDoc result = null;
962             // Parsing the HTTP Date
963
for (int i = 0; (result == null) && (i < formats.length); i++) {
964                 try {
965                     synchronized (formats[i]) {
966                         result = formats[i].parse(lastModifiedValue);
967                     }
968                 } catch (ParseException JavaDoc e) {
969                     ;
970                 }
971             }
972             return result;
973         }
974     }
975     
976     
977     /**
978      * Last modified mutator.
979      *
980      * @param lastModified New last modified date
981      */

982     public void setLastModified(Date JavaDoc lastModified) {
983         // live property, can not be modified
984
setProperty(LAST_MODIFIED, format.format(lastModified));
985     }
986     
987     
988     /**
989      * Last modified mutator.
990      *
991      * @param lastModified New last modified
992      */

993     public void setLastModified(String JavaDoc lastModified) {
994         setProperty(LAST_MODIFIED, lastModified); // live property, can not be modified
995
}
996     
997     
998     /**
999      * Creation length mutator.
1000     *
1001     * @param contentLength New content length
1002     */

1003    public void setContentLength(long contentLength) {
1004        setProperty(CONTENT_LENGTH, new Long JavaDoc(contentLength)); // live property, can not be modified
1005
}
1006    
1007    
1008    /**
1009     * Creation length mutator.
1010     *
1011     * @param contentLength New content length
1012     */

1013    public void setContentLength(String JavaDoc contentLength) {
1014        Long JavaDoc contentLengthValue = null;
1015        try {
1016            contentLengthValue = new Long JavaDoc(contentLength);
1017        } catch (NumberFormatException JavaDoc e) {
1018            // Ignore
1019
}
1020        if (contentLengthValue == null) {
1021            contentLengthValue = new Long JavaDoc(0);
1022        }
1023        setProperty(CONTENT_LENGTH, contentLengthValue); // live property, can not be modified
1024
}
1025    
1026    
1027    /**
1028     * Content length accessor.
1029     *
1030     * @return String
1031     */

1032    public long getContentLength() {
1033        NodeProperty contentLength = getProperty(CONTENT_LENGTH);
1034        if (contentLength == null) {
1035            return -1L;
1036        } else {
1037            if (contentLength.getValue() instanceof Long JavaDoc) {
1038                return ((Long JavaDoc) contentLength.getValue()).longValue();
1039            }
1040            
1041            if (contentLength.getValue() instanceof String JavaDoc) {
1042                return (new Long JavaDoc((String JavaDoc) contentLength.getValue()))
1043                    .longValue();
1044            }
1045            return -1L;
1046        }
1047    }
1048    
1049    
1050    /**
1051     * Set default properties.
1052     */

1053    void setDefaultProperties(Enumeration JavaDoc defaultProperties) {
1054        while (defaultProperties.hasMoreElements()) {
1055            NodeProperty currentProperty =
1056                (NodeProperty) defaultProperties.nextElement();
1057            String JavaDoc name = currentProperty.getName();
1058            String JavaDoc namespace = currentProperty.getNamespace();
1059            NodeProperty lookup = getProperty(name, namespace);
1060            if (lookup == null) {
1061                // Adding property
1062
setProperty(name, namespace, currentProperty.getValue());
1063            }
1064        }
1065    }
1066    
1067    
1068    // -------------------------------------------------------- Private methods
1069

1070    
1071    private void initDefaultProperties() {
1072        
1073        setCreationDate(new Date JavaDoc());
1074// setName("");
1075
// By default, a resource is a collection
1076
setResourceType(COLLECTION_TYPE);
1077        setProperty(SOURCE, ""); // live property, can not be modified
1078
setContentLength(-1);
1079        setLastModified(new Date JavaDoc());
1080        
1081    }
1082    
1083    /**
1084     * Calculate the property name concatenated with the namespace, if available
1085     *
1086     * @param namespace the namespace name, possibly null
1087     * @return propertyName the property name
1088     *
1089     * @return String the property name, including the namespace
1090     */

1091    public String JavaDoc getNamespacedPropertyName(String JavaDoc namespace, String JavaDoc propertyName) {
1092        String JavaDoc result;
1093        if (namespace == null) result = propertyName;
1094        else result = namespace + propertyName;
1095        return result;
1096    }
1097    
1098    
1099    // --------------------------------------------------------- Object Methods
1100

1101    
1102    /**
1103     * Clone.
1104     *
1105     * @return Object clone
1106     */

1107    public NodeRevisionDescriptor cloneObject() {
1108        NodeRevisionDescriptor result = null;
1109        try {
1110            result = (NodeRevisionDescriptor) super.clone();
1111            // Cloning properties
1112
Hashtable JavaDoc propertiesClone = new Hashtable JavaDoc();
1113            Enumeration JavaDoc propertiesList = this.properties.keys();
1114            while (propertiesList.hasMoreElements()) {
1115                Object JavaDoc key = propertiesList.nextElement();
1116                Object JavaDoc value = this.properties.get(key);
1117                propertiesClone.put(key, value);
1118            }
1119            result.properties = propertiesClone;
1120            // Cloning labels
1121
result.labels = (Vector JavaDoc) this.labels.clone();
1122        } catch(CloneNotSupportedException JavaDoc e) {
1123            e.printStackTrace();
1124        }
1125        return result;
1126    }
1127    
1128    
1129    /**
1130     * Equals.
1131     *
1132     * @param obj Object to test
1133     * @return boolean True if the two object are equal :
1134     * <li>obj is of type NodeRevisionDescriptor and is not null</li>
1135     * <li>The two revision numbers are equal</li>
1136     */

1137    public boolean equals(Object JavaDoc obj) {
1138        boolean result = false;
1139        if ((obj != null) && (obj instanceof NodeRevisionDescriptor)) {
1140            NodeRevisionDescriptor revisionDescriptor =
1141                (NodeRevisionDescriptor) obj;
1142            result = this.getRevisionNumber()
1143                .equals(revisionDescriptor.getRevisionNumber());
1144        }
1145        return result;
1146    }
1147    
1148    
1149    /**
1150     * Validate.
1151     */

1152    public void validate() {
1153        
1154        if (branchName == null)
1155            throw new ObjectValidationFailedException
1156                (Messages.message
1157                     (NodeRevisionDescriptor.class.getName() + ".nullBranchName"));
1158        
1159        if (number == null)
1160            throw new ObjectValidationFailedException
1161                (Messages.message
1162                     (NodeRevisionDescriptor.class.getName() + ".nullNumber"));
1163        number.validate();
1164        
1165        if (labels == null)
1166            throw new ObjectValidationFailedException
1167                (Messages.message
1168                     (NodeRevisionDescriptor.class.getName() + ".nullLabels"));
1169        
1170        if (properties == null)
1171            throw new ObjectValidationFailedException
1172                (Messages.message
1173                     (NodeRevisionDescriptor.class.getName() + ".nullProperties"));
1174        Enumeration JavaDoc propertyList = properties.elements();
1175        while (propertyList.hasMoreElements()) {
1176            Object JavaDoc obj = propertyList.nextElement();
1177            if (!(obj instanceof NodeProperty))
1178                throw new ObjectValidationFailedException
1179                    (Messages.message
1180                         (NodeRevisionDescriptor.class.getName()
1181                              + ".invalidPropertyType"));
1182            ((NodeProperty) obj).validate();
1183        }
1184        
1185    }
1186    
1187    
1188}
1189
Popular Tags