KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > util > MetaDataUtil


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.util;
14
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.core.MetaData;
17
18 import java.util.Date JavaDoc;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24
25 /**
26  * @author Sameer Charles
27  * @version $Revision: 6341 $ ($Author: philipp $)
28  */

29 public class MetaDataUtil {
30
31     /**
32      * Logger.
33      */

34     private static Logger log = LoggerFactory.getLogger(MetaDataUtil.class);
35
36     private Content content;
37
38     public MetaDataUtil(Content c) {
39         this.setContent(c);
40     }
41
42     public void setContent(Content c) {
43         this.content = c;
44     }
45
46     public Content getContent() {
47         return this.content;
48     }
49
50     public String JavaDoc getPropertyValueString(String JavaDoc propertyName) {
51         return getPropertyValueString(propertyName, null);
52     }
53
54     /**
55      * <p/> Returns the representation of the value as a String:
56      * </p>
57      * @return String
58      */

59     public String JavaDoc getPropertyValueString(String JavaDoc propertyName, String JavaDoc dateFormat) {
60         try {
61             if (propertyName.equals(MetaData.CREATION_DATE)
62                 || propertyName.equals(MetaData.LAST_MODIFIED)
63                 || propertyName.equals(MetaData.LAST_ACTION)) {
64                 Date JavaDoc date = this.getContent().getMetaData().getDateProperty(propertyName).getTime();
65                 return new DateUtil().getFormattedDate(date, dateFormat);
66             }
67             else if (propertyName.equals(MetaData.ACTIVATED)) {
68                 return Boolean.toString(this.getContent().getMetaData().getBooleanProperty(propertyName));
69             }
70             else {
71                 return this.getContent().getMetaData().getStringProperty(propertyName);
72             }
73         }
74         catch (Exception JavaDoc e) {
75             if (log.isDebugEnabled()) {
76                 log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
77
}
78         }
79         return StringUtils.EMPTY;
80     }
81 }
82
Popular Tags