1 25 package org.snipsnap.snip.storage; 26 27 import org.dom4j.Element; 28 import org.radeox.util.logging.Logger; 29 30 import java.sql.Timestamp ; 31 import java.util.HashMap ; 32 import java.util.Iterator ; 33 import java.util.Map ; 34 35 public class SerializerSupport { 36 37 42 public Map getElementMap(Element el) { 43 Map elements = new HashMap (); 44 Iterator childIterator = el.elementIterator(); 45 while (childIterator.hasNext()) { 46 Element element = (Element) childIterator.next(); 47 if (element.isTextOnly()) { 48 elements.put(element.getName(), notNull(element.getText())); 49 } else { 50 elements.put(element.getName(), element); 51 } 52 } 53 return elements; 54 } 55 56 61 protected Timestamp getTimestamp(String value) { 62 if(null != value && !"".equals(value)) { 63 try { 64 return new Timestamp (Long.parseLong(value)); 65 } catch (NumberFormatException e) { 66 Logger.warn("SerializerSupport: timestamp value invalid: "+value); 67 } 68 } 69 return null; 70 } 71 72 77 protected String getStringTimestamp(Timestamp ts) { 78 if(null != ts) { 79 return "" + ts.getTime(); 80 } 81 return ""; 82 } 83 84 89 protected String notNull(String str) { 90 return str == null ? "" : str; 91 } 92 93 99 protected String notNull(Object obj) { 100 return obj == null ? "" : obj.toString(); 101 } 102 103 } 104 | Popular Tags |