1 20 package org.jahia.data.templates; 21 22 23 import java.util.Vector ; 24 25 import org.jahia.data.xml.JahiaXmlDocument; 26 import org.jahia.exceptions.JahiaException; 27 import org.jahia.utils.xml.XMLParser; 28 import org.w3c.dom.Element ; 29 import org.w3c.dom.Node ; 30 31 32 51 public class Templates_Xml extends JahiaXmlDocument { 52 53 54 private String m_Name =""; 55 56 private String m_RootFolder; 57 58 private String m_ClassesFile; 59 60 private String m_Provider; 61 62 private String m_Thumbnail; 63 65 private Vector m_Templates = new Vector (); 66 67 private static final String TPML_TAG = "tpml"; 68 private static final String CLASSES_FILE_ENTRY = "jahiatemplates/"; 69 70 75 public Templates_Xml (String docPath) throws JahiaException 76 { 77 super(docPath); 78 } 79 80 81 85 public void extractDocumentData() throws JahiaException { 86 87 89 if (m_XMLDocument == null) { 90 91 throw new JahiaException( "Templates_Xml", 92 "Parsed Templates.xml document is null", 93 JahiaException.ERROR_SEVERITY, 94 JahiaException.SERVICE_ERROR); 95 } 96 97 98 if (!m_XMLDocument.hasChildNodes()) { 99 100 throw new JahiaException( "Templates_Xml", 101 "Main document node has no children", 102 JahiaException.ERROR_SEVERITY, 103 JahiaException.SERVICE_ERROR); 104 } 105 106 107 Element docElNode = (Element ) m_XMLDocument.getDocumentElement(); 109 110 if (!docElNode.getNodeName().equalsIgnoreCase(TPML_TAG)) { 111 112 throw new JahiaException( "Invalid XML format", 113 "tpml tag is not present as starting tag in file", 114 JahiaException.ERROR_SEVERITY, 115 JahiaException.SERVICE_ERROR); 116 } 117 118 119 m_Name = XMLParser.getParameterValue(docElNode,"package-name"); 121 122 124 m_RootFolder = XMLParser.getParameterValue(docElNode,"root-folder"); 126 127 129 m_ClassesFile = XMLParser.getParameterValue(docElNode,"classes-file"); 131 132 134 m_Provider = XMLParser.getParameterValue(docElNode,"provider"); 136 137 139 m_Thumbnail = XMLParser.getParameterValue(docElNode,"thumbnail"); 141 142 144 Vector nodesList = XMLParser.getChildNodes(docElNode,"template"); 146 int size = nodesList.size(); 147 if ( size>0 ){ 148 149 150 Node nodeItem = null; 151 String templateName = ""; 152 String templateFile = ""; 153 String templateDisplayName = ""; 154 155 Node currNode = null; 156 157 for ( int i=0 ; i<size ; i++ ){ 158 nodeItem = (Node )nodesList.get(i); 159 160 templateName = XMLParser.getParameterValue(nodeItem,"name"); 161 162 templateFile = XMLParser.getParameterValue(nodeItem,"filename"); 163 164 templateDisplayName = XMLParser.getParameterValue(nodeItem,"display-name"); 165 if ( templateDisplayName.length()<=0 ){ 166 templateDisplayName = templateName; 167 } 168 169 boolean visible = true; 170 171 String val = XMLParser.getAttributeValue(nodeItem,"visible"); 172 if ( val != null ){ 173 visible = ( Integer.parseInt(val) == 1 ); 174 } 175 176 boolean isHomePage = false; 177 val = XMLParser.getAttributeValue(nodeItem,"homepage"); 178 if ( val != null ){ 179 isHomePage = ( Integer.parseInt(val) == 1 ); 180 } 181 182 183 if ( (templateName != null) && (templateName.length()>0) && 184 (templateFile != null) && (templateFile.length()>0) && 185 (templateDisplayName != null) && (templateDisplayName.length()>0) ){ 186 187 JahiaTemplateDef template = new JahiaTemplateDef( 188 templateName, 189 templateFile, 190 templateDisplayName, 191 visible, 192 isHomePage 193 ); 194 195 m_Templates.add(template); 199 200 } 201 } 202 } 203 204 } 206 207 208 213 public String getPackageName(){ 214 215 return m_Name; 216 } 217 218 219 223 public void setPackageName(String name){ 224 225 m_Name = name; 226 } 227 228 233 public String getRootFolder(){ 234 235 return m_RootFolder; 236 } 237 238 239 243 public void setRootFolder(String rootFolder){ 244 245 m_RootFolder = rootFolder; 246 } 247 248 249 254 public String getClassesFile(){ 255 256 return m_ClassesFile; 257 } 258 259 260 264 public void setClassesFile(String filename){ 265 266 m_ClassesFile = filename; 267 } 268 269 270 275 public String getProvider(){ 276 277 return m_Provider; 278 } 279 280 281 285 public void setProvider(String val){ 286 287 m_Provider = val; 288 } 289 290 291 296 public String getThumbnail(){ 297 298 return m_Thumbnail; 299 } 300 301 302 306 public void setThumbnail(String val){ 307 308 m_Thumbnail = val; 309 } 310 311 312 317 public Vector getTemplates(){ 318 319 return m_Templates; 320 321 } 322 323 324 325 326 } | Popular Tags |