1 13 package info.magnolia.cms.util; 14 15 import info.magnolia.cms.core.NodeData; 16 17 import java.util.Date ; 18 19 import javax.jcr.PropertyType; 20 21 import org.apache.commons.lang.StringUtils; 22 import org.apache.log4j.Logger; 23 24 25 29 public class NodeDataUtil { 30 31 34 private static Logger log = Logger.getLogger(NodeDataUtil.class); 35 36 NodeData nodeData; 37 38 public NodeDataUtil(NodeData nodeData) { 39 this.setNodeData(nodeData); 40 } 41 42 public void setNodeData(NodeData nodeData) { 43 this.nodeData = nodeData; 44 } 45 46 public NodeData getNodeData() { 47 return this.nodeData; 48 } 49 50 56 public String getValueString() { 57 return getValueString(null); 58 } 59 60 66 public String getValueString(String dateFormat) { 67 try { 68 NodeData nodeData = this.getNodeData(); 69 switch (nodeData.getType()) { 70 case (PropertyType.STRING): 71 return nodeData.getString(); 72 case (PropertyType.DOUBLE): 73 return Double.toString(nodeData.getDouble()); 74 case (PropertyType.LONG): 75 return Long.toString(nodeData.getLong()); 76 case (PropertyType.BOOLEAN): 77 return Boolean.toString(nodeData.getBoolean()); 78 case (PropertyType.DATE): 79 Date valueDate = nodeData.getDate().getTime(); 80 return new DateUtil().getFormattedDate(valueDate, dateFormat); 81 case (PropertyType.BINARY): 82 default: 84 return StringUtils.EMPTY; 85 } 86 } 87 catch (Exception e) { 88 log.debug("Exception caught: " + e.getMessage(), e); } 90 return StringUtils.EMPTY; 91 } 92 93 public String getTypeName(int type) { 94 95 switch (type) { 96 case PropertyType.STRING: 97 return PropertyType.TYPENAME_STRING; 98 case PropertyType.BOOLEAN: 99 return PropertyType.TYPENAME_BOOLEAN; 100 case PropertyType.DATE: 101 return PropertyType.TYPENAME_DATE; 102 case PropertyType.LONG: 103 return PropertyType.TYPENAME_LONG; 104 case PropertyType.DOUBLE: 105 return PropertyType.TYPENAME_DOUBLE; 106 case PropertyType.BINARY: 107 return PropertyType.TYPENAME_BINARY; 108 default: 109 return StringUtils.EMPTY; 110 } 111 112 } 113 } 114 | Popular Tags |