1 20 package org.jahia.services.webapps_deployer.orion; 21 22 23 import org.jahia.data.xml.JahiaXmlDocument; 24 import org.jahia.exceptions.JahiaException; 25 import org.jahia.utils.xml.XMLParser; 26 import org.w3c.dom.Element ; 27 import org.w3c.dom.NamedNodeMap ; 28 import org.w3c.dom.Node ; 29 30 import java.util.Vector ; 31 32 33 52 public class Default_Web_Site_Xml extends JahiaXmlDocument { 53 54 55 private Vector m_WebApps = new Vector (); 56 57 private Vector m_WebAppNodes = new Vector (); 58 59 private static org.apache.log4j.Logger logger = 60 org.apache.log4j.Logger.getLogger (Default_Web_Site_Xml.class); 61 62 67 public Default_Web_Site_Xml (String docPath) throws JahiaException { 68 super (docPath); 69 extractDocumentData (); 70 71 } 72 73 74 80 public Default_Web_Site_Xml (String docPath, org.xml.sax.helpers.ParserAdapter parser) 81 throws JahiaException { 82 super (docPath, parser); 83 } 84 85 86 89 public void extractDocumentData () throws JahiaException { 90 91 logger.info (" started "); 92 93 if (m_XMLDocument == null) { 94 95 throw new JahiaException ("Default_Web_Site_Xml", 96 "Parsed default-web-site.xml document is null", 97 JahiaException.ERROR_SEVERITY, 98 JahiaException.SERVICE_ERROR); 99 } 100 101 102 if (!m_XMLDocument.hasChildNodes ()) { 103 104 throw new JahiaException ("Default_Web_Site_Xml", 105 "Main document node has no children", 106 JahiaException.ERROR_SEVERITY, 107 JahiaException.SERVICE_ERROR); 108 } 109 110 111 Element docElNode = (Element ) m_XMLDocument.getDocumentElement (); 113 114 if (!docElNode.getNodeName ().equalsIgnoreCase ("web-site")) { 115 116 throw new JahiaException ("Invalid XML format", 117 "web-site tag is not present as starting tag in file", 118 JahiaException.ERROR_SEVERITY, 119 JahiaException.SERVICE_ERROR); 120 } 121 122 logger.debug ("default-web-site.xml file has web-site element"); 123 124 Vector appNodes = XMLParser.getChildNodes (docElNode, "web-app"); 126 Node nodeItem = null; 127 Web_App_Element appEl = null; 128 NamedNodeMap attribs = null; 129 130 String application; 131 String root; 132 String name; 133 String loadOnStartup; 134 String maxInactivityTime; 135 String shared; 136 137 int size = appNodes.size (); 138 139 for (int i = 0; i < size; i++) { 140 141 nodeItem = (Node ) appNodes.get (i); 142 143 logger.debug ("web app element " + nodeItem.getNodeName ()); 144 145 application = XMLParser.getAttributeValue (nodeItem, "application"); 146 loadOnStartup = XMLParser.getAttributeValue (nodeItem, "load-on-startup"); 147 maxInactivityTime = XMLParser.getAttributeValue (nodeItem, "max-inactivity-time"); 148 name = XMLParser.getAttributeValue (nodeItem, "name"); 149 root = XMLParser.getAttributeValue (nodeItem, "root"); 150 shared = XMLParser.getAttributeValue (nodeItem, "shared"); 151 152 if (application != null && root != null && name != null) { 153 154 appEl = new Web_App_Element ( 155 application, 156 root, 157 name, 158 loadOnStartup, 159 shared, 160 maxInactivityTime 161 ); 162 163 m_WebApps.add (appEl); 164 m_WebAppNodes.add (nodeItem); 165 166 logger.debug (" Web App application :" + appEl.getApplication ()); 167 logger.debug (" root :" + appEl.getRoot ()); 168 logger.debug (" name :" + appEl.getName ()); 169 logger.debug (" loadOnStratup :" + appEl.getLoadOnStartup ()); 170 logger.debug (" shared :" + appEl.getShared ()); 171 logger.debug (" maxInactivityTime :" + appEl.getMaxInactivityTime ()); 172 } 173 174 } 175 176 logger.debug (" extraction done"); 177 } 178 179 180 185 public Vector getWebApps () { 186 187 return m_WebApps; 188 189 } 190 191 192 198 public boolean addWebApp (Web_App_Element appEl) { 199 200 201 if (!isDeclared (appEl.getApplication (), appEl.getName ())) { 202 203 204 Element docElNode = (Element ) m_XMLDocument.getDocumentElement (); 205 206 Element newNode = (Element ) m_XMLDocument.createElement ("web-app"); 207 208 XMLParser.setAttribute (newNode, "application", appEl.getApplication ()); 209 XMLParser.setAttribute (newNode, "root", appEl.getRoot ()); 210 XMLParser.setAttribute (newNode, "name", appEl.getName ()); 211 XMLParser.setAttribute (newNode, "loadOnStartup", appEl.getLoadOnStartup ()); 212 XMLParser.setAttribute (newNode, "shared", appEl.getShared ()); 213 XMLParser.setAttribute (newNode, "maxInactivityTime", 214 appEl.getMaxInactivityTime ()); 215 216 if (m_WebAppNodes.size () > 0) { 217 Node lastAppNode = (Node ) m_WebAppNodes.get ((m_WebAppNodes.size () - 1)); 218 docElNode.insertBefore (newNode, lastAppNode); 219 } else { 220 docElNode.appendChild (newNode); 221 } 222 m_WebApps.add (appEl); 223 m_WebAppNodes.add (newNode); 224 return true; 225 } 226 return false; 227 228 } 229 230 231 237 public boolean isDeclared (String appName, String webAppName) { 238 239 Web_App_Element webApp = null; 240 int size = m_WebApps.size (); 241 for (int i = 0; i < size; i++) { 242 webApp = (Web_App_Element) m_WebApps.get (i); 243 if (webApp.getApplication ().equals (appName) && webApp.getName ().equals ( 244 webAppName)) { 245 return true; 246 } 247 } 248 249 return false; 250 } 251 252 253 } | Popular Tags |