1 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 ; 19 20 import org.apache.commons.lang.StringUtils; 21 import org.slf4j.Logger; 22 import org.slf4j.LoggerFactory; 23 24 25 29 public class MetaDataUtil { 30 31 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 getPropertyValueString(String propertyName) { 51 return getPropertyValueString(propertyName, null); 52 } 53 54 59 public String getPropertyValueString(String propertyName, String dateFormat) { 60 try { 61 if (propertyName.equals(MetaData.CREATION_DATE) 62 || propertyName.equals(MetaData.LAST_MODIFIED) 63 || propertyName.equals(MetaData.LAST_ACTION)) { 64 Date 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 e) { 75 if (log.isDebugEnabled()) { 76 log.debug("Exception caught: " + e.getMessage(), e); } 78 } 79 return StringUtils.EMPTY; 80 } 81 } 82 | Popular Tags |