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

📄 applicationconfiguration.java

📁 一个用java编写的服务器,对于学习网络编程的人来说是个很好的例子
💻 JAVA
字号:
/*
 * This file is part of the QuickServer library 
 * Copyright (C) 2003-2005 QuickServer.org
 *
 * Use, modification, copying and distribution of this software is subject to
 * the terms and conditions of the GNU Lesser General Public License. 
 * You should have received a copy of the GNU LGP License along with this 
 * library; if not, you can download a copy from <http://www.quickserver.org/>.
 *
 * For questions, suggestions, bug-reports, enhancement-requests etc.
 * visit http://www.quickserver.org
 *
 */

package org.quickserver.util.xmlreader;

import java.util.*;

/**
 * This class encapsulate the Application Configuration.
 * The example xml is <pre>
 &lt;quickserver&gt;
	....
	&lt;application-configuration&gt;
		&lt;property&gt;
			&lt;property-name&gt;FTP_ROOT&lt;/property-name&gt;
			&lt;property-value&gt;c:\&lt;/property-value&gt;
		&lt;/property&gt;
		&lt;property&gt;
			&lt;property-name&gt;Server Name&lt;/property-name&gt;
			&lt;property-value&gt;My Server&lt;/property-value&gt;
		&lt;/property&gt;
	&lt;/application-configuration&gt;
	....
&lt;/quickserver&gt;
</pre>
 * @author Akshathkumar Shetty
 * @since 1.3.2
 */
public class ApplicationConfiguration extends HashMap {
	private String promptType = "gui";//OR console

	/**
	 * Sets the PromptType.
	 * XML Tag: &lt;prompt-type&gt;true&lt;/prompt-typ&gt;
	 * Allowed values = <code>gui</code> | <code>console</code>
 	 * @see #getPromptType
	 * @since 1.4.5
	 */
	public void setPromptType(String promptType) {
		if(promptType!=null && promptType.equals("")==false)
			if(promptType.equals("gui") || promptType.equals("console"))
				this.promptType = promptType;
	}
	/**
	 * Returns the PromptType
	 * @see #setPromptType
	 * @since 1.4.5
	 */
	public String getPromptType() {
		return promptType;
	}

	/**
	 * Addes the {@link Property} passed to the HashMap
	 */
	public void addProperty(Property property) {
		put(property.getName(), property.getValue());
	}

	/**
	 * Finds if any {@link Property} is present.
	 * @return <code>null</code> if no Property was found.
	 */
	public Property findProperty(String name) {
		String temp = (String) get(name);
		if(temp!=null) {
			return new Property(name, temp);
		} else {
			return null;
		}
	}

	/**
	 * Returns XML config of this class.
	 */
	public String toXML(String pad) {
		if(pad==null) pad="";
		StringBuffer sb = new StringBuffer();
		sb.append(pad+"<application-configuration>\n");
		
		sb.append(pad+"\t<prompt-type>"+getPromptType()+"</prompt-type>");

		Iterator iterator = keySet().iterator();
		while(iterator.hasNext()) {
			String key = (String) iterator.next();
			String value = (String) get(key);
			sb.append(pad+"\t<property>");
			sb.append(pad+"\t\t<property-name>"+key+"</property-name>\n");
			sb.append(pad+"\t\t<property-value>"+value+"</property-value>\n");
			sb.append(pad+"\t</property>\n");
		}
		sb.append(pad+"</application-configuration>\n");
		return sb.toString();
	}
}

⌨️ 快捷键说明

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