⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server_xml.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////////  Server_Xml////  NK      02.02.2001////package org.jahia.services.webapps_deployer.orion;import java.io.*;import java.util.*;//import com.sun.xml.tree.*;//import com.sun.xml.parser.Parser;import org.xml.sax.helpers.ParserAdapter;import org.w3c.dom.*;import org.xml.sax.*;import org.jahia.exceptions.*;import org.jahia.utils.*;               // JahiaConsoleimport org.jahia.data.xml.*;            // JahiaXmlDocumentimport org.jahia.utils.xml.*;           // XMLParser/** * Holds Informations about the Orion Server.xml file * We are only interesting to add or remove <application../> * element to deploy or undeploy web apps * * <application-server * 	application-directory="../applications" * 	deployment-directory="../application-deployments"> * * 	<rmi-config path="./rmi.xml" /> * 	<!-- JMS-server config link, uncomment to activate the JMS service --> * 	<!-- <jms-config path="./jms.xml" /> --> * 	<principals path="./principals.xml" /> * 	<log> * 		<file path="../log/server.log" /> * 	</log> * * 	<global-application name="default" path="application.xml" /> *    <application name="Bookmark" path="../applications/Bookmark.ear" /> *    <application name="Jahia" path="../applications/Jahia.ear" /> * * 	<global-web-app-config path="global-web-application.xml" /> * 	<web-site path="./default-web-site.xml" /> * * 	<!-- Compiler, activate this to specify an alternative compiler such * 		as jikes for EJB/JSP compiling. --> * 	<!-- <compiler executable="jikes" classpath="/myjdkdir/jre/lib/rt.jar" /> --> * </application-server> * * * * @author Khue ng * @version 1.0 */public class Server_Xml extends JahiaXmlDocument {   /** The list of <application..></application> elements **/   private Vector m_Applications = new Vector();   /** The list of Application Nodes **/   private Vector m_ApplicationNodes = new Vector();		private final static String CLASS_NAME = " Server_Xml";   /**    * Constructor    *    * @param (String) path, the full path to the server.xml file    */    public Server_Xml (String docPath) throws JahiaException    {      super(docPath);      extractDocumentData();    }   	/**     * Constructor using a gived parser     *      * @param (String) path, the full path to a xml file     * @param (Parser) parser, the parser to use     */	public Server_Xml (String docPath, org.xml.sax.helpers.ParserAdapter parser) 	throws JahiaException {		super(docPath,parser);	}    /**     * Extracts data from the web.xml file. Build the JahiaWebAppsWarPackage object     * to store extracted data     */  	public void extractDocumentData() throws JahiaException {      	JahiaConsole.println(CLASS_NAME," Server_Xml::extractDocumentData started ");       	if (m_XMLDocument == null) {        	throw new JahiaException( "Server_Xml",                                    "Parsed web.xml document is null",                                       JahiaException.ERROR,                                       JahiaException.SERVICE_ERROR);       	}       	if (!m_XMLDocument.hasChildNodes()) {        	throw new JahiaException( "Server_Xml",                                       "Main document node has no children",                                       JahiaException.ERROR,                                       JahiaException.SERVICE_ERROR);       	}      	// get application-server node      	Element        appServNode;      	appServNode = (Element) m_XMLDocument.getDocumentElement();       	if (!appServNode.getNodeName().equalsIgnoreCase("application-server")) {        	throw new JahiaException(  "Invalid XML format",                                        "application-server tag is not present as starting tag in file",                                        JahiaException.ERROR,                                        JahiaException.SERVICE_ERROR);       	}      	JahiaConsole.println(CLASS_NAME,"server.xml file has application-server element");			// get application elements       	Vector appNodes = XMLParser.getChildNodes(appServNode,"application");       	Node nodeItem = null;       	Application_Element appEl = null;       	NamedNodeMap attribs = null;      	String name;      	String path;      	String deployDir;      	String parent;      	String autoStart;       	int size = appNodes.size();       	for ( int i=0 ; i<size ; i++ ){        	nodeItem = (Node)appNodes.get(i);         	JahiaConsole.println(CLASS_NAME,"application element " + nodeItem.getNodeName());         	name       = XMLParser.getAttributeValue(nodeItem,"name");         	path       = XMLParser.getAttributeValue(nodeItem,"path");         	deployDir  = XMLParser.getAttributeValue(nodeItem,"deployment-directory");         	parent     = XMLParser.getAttributeValue(nodeItem,"parent");         	autoStart  = XMLParser.getAttributeValue(nodeItem,"auto-start");         	if ( name != null && path != null ){            	appEl = new Application_Element( name,                                             path,                                             deployDir,                                             parent,                                             autoStart                                           );            	m_Applications.add(appEl);            	m_ApplicationNodes.add(nodeItem);            	JahiaConsole.println(">>"," Application Element name      :" + appEl.getName());            	JahiaConsole.println(">>","                     path      :" + appEl.getPath());            	JahiaConsole.println(">>","                     deployDir :" + appEl.getDeployDir());            	JahiaConsole.println(">>","                     parent    :" + appEl.getParent());            	JahiaConsole.println(">>","                     autoStart :" + appEl.getAutoStart());         	}       	}      	JahiaConsole.println(CLASS_NAME+".extractDocumentData()"," done");   }   /**    * Return the list of Applications Element    *    * @return (Vector) list of Application Elements    */   public Vector getApplications(){      return m_Applications;   }   /**    * Append a new <Application..> Element in the xml file    * Add it in the Application list    *    * @param (Application_Element) appEl    * @return (boolean) true if doesn't exist and added    */   public boolean appendApplication(Application_Element appEl) {      if ( !isDeclared( appEl.getName() ) ){         Element docElNode = (Element) m_XMLDocument.getDocumentElement();         Element newNode = (Element)m_XMLDocument.createElement("application");         XMLParser.setAttribute(newNode, "name",                   appEl.getName());         XMLParser.setAttribute(newNode, "path",                   appEl.getPath());         XMLParser.setAttribute(newNode, "deployment-directory",   appEl.getDeployDir());         XMLParser.setAttribute(newNode, "parent",                 appEl.getParent());         XMLParser.setAttribute(newNode, "auto-start",             appEl.getAutoStart());         if ( m_ApplicationNodes.size()>0 ){         	Node lastAppNode = (Node)m_ApplicationNodes.get( (m_ApplicationNodes.size()-1) );	        docElNode.insertBefore(newNode,lastAppNode);         } else {	        docElNode.appendChild(newNode);		 }		          m_Applications.add(appEl);         m_ApplicationNodes.add(newNode);         return true;      }      return false;   }   /**    * Check if an application already exists in the xml file    *    * @param (String) appName, application name    */   public boolean isDeclared( String name ){      Application_Element appEl = null;      int size = m_Applications.size();      for( int i=0 ; i<size ; i++ ){         appEl =(Application_Element)m_Applications.get(i);         if ( appEl.getName().equals(name) ){            return true;         }      }      return false;   }   /**    * Remove an application Element     *    * @param (String) appName    */   public void removeApplication( String appName ){      Application_Element appEl = null;      int size = m_Applications.size();      for( int i=0 ; i<size ; i++ ){         appEl =(Application_Element)m_Applications.get(i);         if ( appEl.getName().equals(appName) ){		        m_Applications.remove(i);            Element node = (Element)m_ApplicationNodes.get(i);	        Element docElNode = (Element) m_XMLDocument.getDocumentElement();            docElNode.removeChild(node);            m_ApplicationNodes.remove(i);            break;         }      }   }} // end Server_Xml

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -