KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > products > PropertyDetails


1 /*
2  * Created on Sep 13, 2005
3  */

4 package com.openedit.store.products;
5
6 import java.io.Reader JavaDoc;
7 import java.text.SimpleDateFormat JavaDoc;
8 import java.util.ArrayList JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.List JavaDoc;
11
12 import org.dom4j.Element;
13
14 import com.openedit.util.XmlUtil;
15
16 public class PropertyDetails
17 {
18     List JavaDoc fieldDetails;
19     long fieldLastLoaded;
20     
21     public List JavaDoc getDetails()
22     {
23         if (fieldDetails == null)
24         {
25             fieldDetails = new ArrayList JavaDoc();
26         }
27         return fieldDetails;
28     }
29     
30     public void addAllDetails(Reader JavaDoc inDetailsPage)
31     {
32         Element root = new XmlUtil().getXml(inDetailsPage,"UTF-8");
33         for (Iterator JavaDoc 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             //d.setSearchable(Boolean.parseBoolean( element.attributeValue("issearchable") ) );
46
String JavaDoc val = element.attributeValue("editable");
47             if( val != null)
48             {
49                 d.setEditable(Boolean.parseBoolean(val) );
50             }
51             String JavaDoc 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                 //get a formatter
74
String JavaDoc format = element.attributeValue("format");
75                 SimpleDateFormat JavaDoc formater = new SimpleDateFormat JavaDoc(format);
76                 d.setDateFormat(formater);
77             }
78             getDetails().add(d);
79         }
80     }
81     public List JavaDoc findIndexProperties()
82     {
83         List JavaDoc list = new ArrayList JavaDoc(getDetails().size());
84         for (Iterator JavaDoc 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 // public List findSearchProperties()
96
// {
97
// List list = new ArrayList(getDetails().size());
98
//
99
// for (Iterator iter = getDetails().iterator(); iter.hasNext();)
100
// {
101
// Detail d = (Detail) iter.next();
102
//
103
// if ( d.isSearchable() )
104
// {
105
// list.add(d);
106
// }
107
// }
108
// return list;
109
// }
110
//
111

112     public boolean contains(String JavaDoc inKey)
113     {
114         Detail det = getDetail(inKey);
115         
116         return det != null;
117     }
118     public Detail getDetail( String JavaDoc inId)
119     {
120         for (Iterator JavaDoc 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 JavaDoc inName)
133     {
134         for (Iterator JavaDoc 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