1 package org.nextime.ion.backoffice.bean; 2 3 import java.io.InputStream ; 4 import java.util.StringTokenizer ; 5 import java.util.Vector ; 6 7 import org.apache.struts.digester.Digester; 8 import org.nextime.ion.framework.business.TypePublication; 9 10 public class TypeBean { 11 12 protected String _name; 13 protected String _template; 14 protected String _description; 15 protected Vector _properties = new Vector (); 16 protected Vector _publicationsTypes = new Vector (); 17 18 protected static Vector _types = new Vector (); 19 20 public String getName() { 21 return _name; 22 } 23 24 public String getTemplate() { 25 return _template; 26 } 27 28 protected static TypeBean getBean(String template) { 29 for (int i = 0; i < _types.size(); i++) { 30 if (((TypeBean) _types.get(i)).getTemplate().equals(template)) { 31 return (TypeBean) _types.get(i); 32 } 33 } 34 return null; 35 } 36 37 public String getDescription() { 38 return _description; 39 } 40 41 public Vector getPublicationTypes() { 42 try { 43 if (_publicationsTypes.contains("*")) { 44 Vector r = new Vector (); 45 Vector rt = TypePublication.listAll(); 46 for (int i = 0; i < rt.size(); i++) { 47 r.add(((TypePublication) rt.get(i)).getId()); 48 } 49 return r; 50 } 51 } catch (Exception e) { 52 e.printStackTrace(); 53 } 54 return _publicationsTypes; 55 } 56 57 public void setPublicationTypes(String types) { 58 StringTokenizer tokenizer = new StringTokenizer (types, ", "); 59 while (tokenizer.hasMoreTokens()) { 60 _publicationsTypes.add(tokenizer.nextToken()); 61 } 62 } 63 64 public void setDescription(String description) { 65 _description = description; 66 } 67 68 public void setName(String name) { 69 _name = name; 70 } 71 72 public void setTemplate(String template) { 73 _template = template; 74 } 75 76 public Vector getProperties() { 77 return _properties; 78 } 79 80 public PropertyBean getProperty(String name) { 81 for (int i = 0; i < _properties.size(); i++) { 82 PropertyBean p = (PropertyBean) _properties.get(i); 83 if (name.equals(p.getName())) { 84 return p; 85 } 86 } 87 return null; 88 } 89 90 public int getPropertiesNumber() { 91 return _properties.size(); 92 } 93 94 public void addProperty(PropertyBean p) { 95 _properties.add(p); 96 } 97 98 public Vector getItems() { 99 return _types; 100 } 101 102 public static void addBean(TypeBean bean) { 103 _types.add(bean); 104 } 105 106 protected static TypeBean parse(InputStream in) throws Exception { 107 TypeBean bean = new TypeBean(); 108 Digester digester = new Digester(); 109 digester.push(bean); 110 digester.setValidating(false); 111 digester.addObjectCreate( 112 "templates-description/template", 113 "org.nextime.ion.backoffice.bean.TypeBean"); 114 digester.addSetProperties("templates-description/template"); 115 digester.addSetNext("templates-description/template", "addBean"); 116 digester.addCallMethod( 117 "templates-description/template/description", 118 "setDescription", 119 0); 120 digester.addCallMethod( 121 "templates-description/template/publication-types", 122 "setPublicationTypes", 123 0); 124 digester.addObjectCreate( 125 "templates-description/template/property", 126 "org.nextime.ion.backoffice.bean.PropertyBean"); 127 digester.addSetProperties("templates-description/template/property"); 128 digester.addSetTop( 129 "templates-description/template/property", 130 "setSectionType"); 131 digester.parse(in); 132 return bean; 133 } 134 } 135 | Popular Tags |