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

📄 web_app_xml.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////////  NK      29.01.2001////package org.jahia.data.webapps;import java.io.*;import java.util.*;import java.util.zip.*;import org.xml.sax.helpers.ParserAdapter;import org.w3c.dom.*;import org.jahia.exceptions.*;import org.jahia.utils.zip.*;               // JahiaarHandlerimport org.jahia.utils.*;                   // JahiaCmdExecimport org.jahia.utils.xml.*;               // JahiaConsole, XMLParserimport org.jahia.data.xml.*;                // JahiaXmlDocumentimport org.jahia.data.webapps.*;            // Security_Role/** * Holds Informations about the Web Component deployment descriptors file * web.xml * * @author Khue ng * @version 1.0 */public class Web_App_Xml extends JahiaXmlDocument {	/** The Servlet Type WebApp **/   	private static final int SERVLET_TYPE = 1;   	   	/** The JSP Type WebApp **/   	private static final int JSP_TYPE = 2;	/** The Display Name  **/   	private String m_DisplayName;   	   	/** The desc **/   	private String m_desc;   	   	/**    	 * The list of Servlet     * @associates Servlet_Element     */   	private Vector m_Servlets = new Vector();   	/** The hashMap of servlet mapping, keyed with the pattern used to map a servlet **/    private HashMap m_ServletMappings = new HashMap();		   	   	/** The list of security-role **/    private Vector m_Roles = new Vector();			   	/** The list of Welcome files **/    private Vector m_WelcomeFiles = new Vector();			    /**     * Constructor     *     * @param (String) path, the full path to the application.xml file     */	public Web_App_Xml (String docPath) throws JahiaException    {      super(docPath);	}   	/**     * Constructor using a gived parser     *      * @param (String) path, the full path to a xml file     * @param (Parser) parser, the parser to use     */	public Web_App_Xml (String docPath, org.xml.sax.helpers.ParserAdapter parser) 	throws JahiaException {		super(docPath,parser);	}	//--------------------------------------------------------------------------    /**     * Extracts data from the web.xml file.	 *     */	public void extractDocumentData() throws JahiaException {		if (m_XMLDocument == null) {          throw new JahiaException( "Web_App_Xml",                                    "Parsed web.xml document is null",                                       JahiaException.ERROR,                                       JahiaException.CONFIG_ERROR);       	}       	if (!m_XMLDocument.hasChildNodes()) {        	throw new JahiaException( "Web_App_Xml",                                       "Main document node has no children",                                        JahiaException.ERROR,                                        JahiaException.CONFIG_ERROR);       	}		// get web-app node	    Element        webAppNode;      	webAppNode = (Element) m_XMLDocument.getDocumentElement();       	if (!webAppNode.getNodeName().equalsIgnoreCase("web-app")) {        	throw new JahiaException(  "Invalid XML format",                                        "web-app tag is not present as starting tag in file",                                        JahiaException.ERROR,                                        JahiaException.CONFIG_ERROR);       	}			  	// get the webapp display name	  	Node displayNameNode = XMLParser.nextChildOfTag(webAppNode,"display-name");		if ( displayNameNode != null ){	  		m_DisplayName = displayNameNode.getFirstChild().getNodeValue().trim();		}						m_Servlets = getServlets(webAppNode);		m_ServletMappings = getServletMappings(webAppNode);		m_Roles = getRoles(webAppNode);		m_WelcomeFiles = getWelcomeFiles(webAppNode);	}	    /**     * Return the Display Name     *     * @return (String) the display name of the Application     */   	public String getDisplayName(){      	return m_DisplayName;   	}    /**     * Set the DisplayName     * @param (String) the display name of the webApp     */   	protected void setDisplayName(String name){      	m_DisplayName = name;   	}    /**     * Return the servlets list     *     * @return (Vector) the list of servlets     */   	public Vector getServlets(){      	return m_Servlets;   	}    /**     * Return the map of servlet mapping     *     * @return (HashMap) the map of servlets mapping     */   	public HashMap getServletMappings(){      	return m_ServletMappings;   	}    /**     * Return the welcome files list     *     * @return (Vector) the list of welcome files     */   	public Vector getWelcomeFiles(){      	return m_WelcomeFiles;   	}	/**	 * return the vector of roles	 *	 * @return (Vector) the roles	 */	public Vector getRoles(){		return m_Roles;	}   	/**     * Return the Web App desc     *     * @return (String) the desc     */   	public String getdesc(){      	return m_desc;   	}   	/**     * Set the desc     * @param (String) the desc     */   	protected void setdesc(String descr){      	m_desc = descr;   	}	//--------------------------------------------------------------------------	/**	 * extract the list of roles	 *	 */	private Vector getRoles(Node parentNode) throws JahiaException {				Vector nodesList = XMLParser.getChildNodes(parentNode,"security-role");      	Vector roles = new Vector();      	      	int size = nodesList.size();      	if ( size>0 ){			Node nodeItem = null;    		String name   = "";         	String descr  = "";         	Node childNode = null;		 		 	Security_Role role = null;		  	         	for ( int i=0 ; i<size ; i++ ){								name = "";            	nodeItem = (Node)nodesList.get(i);	            childNode = XMLParser.nextChildOfTag(nodeItem,"role-name");    	        if (childNode != null ){        	       name = childNode.getFirstChild().getNodeValue().trim();            	}            	childNode = XMLParser.nextChildOfTag(nodeItem,"desc");            	if (childNode != null ){               		descr = childNode.getFirstChild().getNodeValue().trim();            	}                        	if ( descr == null ){             		descr = "";            	}            				if ( name != null && (name.length()>0) ) {					role = new Security_Role(name, descr);					//System.out.println(" found role : name = " + role.getName() );							roles.add(role);				}			}		}		return roles;	}			//--------------------------------------------------------------------------	/**	 * Extract the list of servlets	 */		private Vector getServlets(Node parentNode) throws JahiaException {		      	Vector servlets = new Vector();      	      	// build the servlets list      	Vector nodesList = XMLParser.getChildNodes(parentNode,"servlet");        int size = nodesList.size();      	if ( size>0 ){        	Node nodeItem = null;         	String displayName   = "";         	String servletName   = "";         	String descr         = "";         	String servletsrc = "";         	int servletType      = 1;         	Node childNode = null;         	for ( int i=0 ; i<size ; i++ ){            	nodeItem = (Node)nodesList.get(i);            	childNode = XMLParser.nextChildOfTag(nodeItem,"servlet-name");            	if (childNode != null ){               		servletName = childNode.getFirstChild().getNodeValue().trim();            	}            	childNode = XMLParser.nextChildOfTag(nodeItem,"display-name");            	if (childNode != null ){               		displayName = childNode.getFirstChild().getNodeValue().trim();            	} else {               		displayName = servletName;            	}            	childNode = XMLParser.nextChildOfTag(nodeItem,"desc");            	if (childNode != null ){               		descr = childNode.getFirstChild().getNodeValue().trim();            	}            	if ( XMLParser.nextChildOfTag(nodeItem,"servlet-class") != null ) {               		servletsrc = XMLParser.nextChildOfTag(nodeItem,"servlet-class").getFirstChild().getNodeValue().trim();               		servletType = SERVLET_TYPE;            	} else {               		servletsrc = XMLParser.nextChildOfTag(nodeItem,"jsp-file").getFirstChild().getNodeValue().trim();               		servletType = JSP_TYPE;            	}            	if ( descr == null ){               		descr = "";            	}            	if ( (displayName != null) && (displayName.length()>0) &&                	(servletName != null) && (servletName.length()>0) &&                 	(servletsrc != null) && (servletsrc.length()>0) ){              		Servlet_Element servlet = new Servlet_Element(                                                               		servletName,                                                               		displayName,                                                                	descr,                                                                	servletsrc,                                                                	servletType,                                                                	i + 1                                                              		);               		//JahiaConsole.println(">>"," servlet    name           :" + servlet.getName());               		//JahiaConsole.println(">>","            display name   :" + servlet.getDisplayName());               		//JahiaConsole.println(">>","            descr          :" + servlet.getdesc());               		//JahiaConsole.println(">>","            servlet source :" + servlet.getSource());               		//JahiaConsole.println(">>","            servletType    :" + servlet.getType());               		//JahiaConsole.println(">>","            servletNumber  :" + servlet.getNumber());	               	servlets.add(servlet);				}         	}      	}      	return servlets;	}	//--------------------------------------------------------------------------	/**	 * Extract the list of welcome files	 */		private Vector getWelcomeFiles(Node parentNode) throws JahiaException {		Vector results = new Vector();				// get the welcome-file-list element	  	Node welcomeFileListNode = XMLParser.nextChildOfTag(parentNode,"welcome-file-list");		if ( welcomeFileListNode == null ){	  		return results;		}		Vector nodesList = XMLParser.getChildNodes(welcomeFileListNode,"welcome-file");      	      	int size = nodesList.size();      	if ( size>0 ){			Node nodeItem = null;    		String filename = "";		  	         	for ( int i=0 ; i<size ; i++ ){				            	nodeItem = (Node)nodesList.get(i);		  		filename = nodeItem.getFirstChild().getNodeValue().trim();            				if ( filename != null && (filename.length()>0) ) {					results.add(filename);				}			}		}		return results;	}		//--------------------------------------------------------------------------	/**	 * Extract a map of servlet mapping.	 */		private HashMap getServletMappings(Node parentNode) throws JahiaException {		HashMap hash = new HashMap();		Vector nodesList = XMLParser.getChildNodes(parentNode,"servlet-mapping");      	      	int size = nodesList.size();      	if ( size>0 ){			Node nodeItem = null;    		String servletName  = "";         	String urlPattern  = "";         	Node childNode = null;		          	for ( int i=0 ; i<size ; i++ ){								servletName = "";				urlPattern = "";				            	nodeItem = (Node)nodesList.get(i);	            childNode = XMLParser.nextChildOfTag(nodeItem,"servlet-name");    	        if (childNode != null ){        	       servletName = childNode.getFirstChild().getNodeValue().trim();            	}            	childNode = XMLParser.nextChildOfTag(nodeItem,"url-pattern");            	if (childNode != null ){               		urlPattern = childNode.getFirstChild().getNodeValue().trim();            	}            				if ( servletName != null && (servletName.length()>0)					 && urlPattern != null && (urlPattern.length()>0) ) {					hash.put(urlPattern,servletName);				}			}		}		return hash;	}} // end Web_App_Xml

⌨️ 快捷键说明

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