1 4 package com.openedit.store.products; 5 6 import java.io.Reader ; 7 import java.text.SimpleDateFormat ; 8 import java.util.ArrayList ; 9 import java.util.Iterator ; 10 import java.util.List ; 11 12 import org.dom4j.Element; 13 14 import com.openedit.util.XmlUtil; 15 16 public class PropertyDetails 17 { 18 List fieldDetails; 19 long fieldLastLoaded; 20 21 public List getDetails() 22 { 23 if (fieldDetails == null) 24 { 25 fieldDetails = new ArrayList (); 26 } 27 return fieldDetails; 28 } 29 30 public void addAllDetails(Reader inDetailsPage) 31 { 32 Element root = new XmlUtil().getXml(inDetailsPage,"UTF-8"); 33 for (Iterator iter = root.elementIterator("property"); iter.hasNext();) 34 { 35 Element element = (Element) iter.next(); 36 Detail d = new Detail(); 37 d.setId(element.attributeValue("id")); 38 d.setExternalId(element.attributeValue("externalid")); 39 d.setIndex(Boolean.parseBoolean( element.attributeValue("index") ) ); 40 d.setText(element.getTextTrim()); 41 d.setBoolean(Boolean.parseBoolean( element.attributeValue("boolean") ) ); 42 d.setKeyword(Boolean.parseBoolean( element.attributeValue("keyword") ) ); 43 d.setStored(Boolean.parseBoolean( element.attributeValue("stored") ) ); 44 d.setIsDate(Boolean.parseBoolean( element.attributeValue("date") ) ); 45 String val = element.attributeValue("editable"); 47 if( val != null) 48 { 49 d.setEditable(Boolean.parseBoolean(val) ); 50 } 51 String type = element.attributeValue("type"); 52 if( type != null ) 53 { 54 if( type.equalsIgnoreCase("image")) 55 { 56 d.setImage(true); 57 } 58 else if( type.equalsIgnoreCase("date")) 59 { 60 d.setIsDate(true); 61 } 62 else if( type.equalsIgnoreCase("list")) 63 { 64 d.setList(true); 65 } 66 else if( type.equalsIgnoreCase("number")) 67 { 68 d.setNumber(true); 69 } 70 } 71 if ( d.isDate() ) 72 { 73 String format = element.attributeValue("format"); 75 SimpleDateFormat formater = new SimpleDateFormat (format); 76 d.setDateFormat(formater); 77 } 78 getDetails().add(d); 79 } 80 } 81 public List findIndexProperties() 82 { 83 List list = new ArrayList (getDetails().size()); 84 for (Iterator iter = getDetails().iterator(); iter.hasNext();) 85 { 86 Detail d = (Detail) iter.next(); 87 if ( d.isIndex() ) 88 { 89 list.add(d); 90 } 91 } 92 return list; 93 } 94 95 112 public boolean contains(String inKey) 113 { 114 Detail det = getDetail(inKey); 115 116 return det != null; 117 } 118 public Detail getDetail( String inId) 119 { 120 for (Iterator iter = getDetails().iterator(); iter.hasNext();) 121 { 122 Detail detail = (Detail) iter.next(); 123 124 if ( inId.equals( detail.getId() )) 125 { 126 return detail; 127 } 128 } 129 return null; 130 } 131 132 public Detail getDetailByExternalId(String inName) 133 { 134 for (Iterator iter = getDetails().iterator(); iter.hasNext();) 135 { 136 Detail detail = (Detail) iter.next(); 137 if ( inName.equals( detail.getExternalId() )) 138 { 139 return detail; 140 } 141 } 142 return null; 143 } 144 145 public long getLastLoaded() 146 { 147 return fieldLastLoaded; 148 } 149 150 public void setLastLoaded(long inLastLoaded) 151 { 152 fieldLastLoaded = inLastLoaded; 153 } 154 } 155 | Popular Tags |