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

📄 configurefile.java

📁 陕西电信sp客户端
💻 JAVA
字号:
// ----------------------------------------------------------------------------
// $Source: /cvs/vas2006/webpro2/webpro_java/src/com/onewaveinc/portalman/webpro/configure/ConfigureFile.java,v $
// ----------------------------------------------------------------------------
// Copyright (c) 2002 by Onewave Inc.
// ----------------------------------------------------------------------------
// $Id: ConfigureFile.java,v 1.1.1.1 2006/08/01 05:49:33 zhengx Exp $
// ----------------------------------------------------------------------------
// $Log: ConfigureFile.java,v $
// Revision 1.1.1.1  2006/08/01 05:49:33  zhengx
// no message
//
// Revision 1.1  2006/06/02 03:33:15  wuyan
// *** empty log message ***
//
// Revision 1.1  2005/12/08 10:36:49  like
// no message
//
// Revision 1.1  2003/07/28 06:31:17  zengc
// no message
//
// Revision 1.2  2002/09/02 09:38:37  zengc
// WebPro java Client  V1.2
//
// Revision 1.1  2002/08/09 08:49:17  zengc
// WebPro Configure Tools
//
// ----------------------------------------------------------------------------

package com.onewaveinc.portalman.webpro.configure;

/**
 * <p>Title: PortalMAN SDK API Documentation</p>
 * <p>Description: OneWave Technologies., Inc. PortalMAN Value-add Management Platform 3rd Software Development Kit</p>
 * <p>Copyright: Copyright (c) 2002 </p>
 * <p>Company: OneWave Technologies., Inc.</p>
 * @author 3rd AAA & ICP Integration Developement Team
 * @version 1.5
 */

import java.util.Properties;
import java.util.Vector;
import java.io.*;


public class ConfigureFile {

	private XmlParser xmlParser;
	private String fileName = null;

	/**
	* constructor
	*/
	public ConfigureFile() {
	}

	/**
	* constructor
	* @param filename 为XmlParser的文件对象
	*/
	public ConfigureFile(String filename) throws ConfigureFileException
	{
		fileName = filename;
		xmlParser = new XmlParser(filename);
	}

	/**
	*读取String参数
	*/
	public String readAttrValue(String AttrIdent) throws ConfigureFileException
	{
		String attrValue;
		attrValue = xmlParser.getAttributeValue(AttrIdent) ;
		return attrValue;
	}

	/**
	*读取int参数
	*/
	public int readInt(String AttrIdent) throws ConfigureFileException
	{
		int attrValue = 0;
		try
		{
			String a = xmlParser.getAttributeValue(AttrIdent);
			attrValue = Integer.parseInt(a) ;
		}
		catch(NumberFormatException e)
		{
			throw new ConfigureFileException("XML_TAG_ATTRIBUTE_NOT_INT", e.toString());
		}
		catch(Exception e)
		{
			throw new ConfigureFileException(e.toString());
		}
		return attrValue;
	}

	/**
	*读取bool参数
	*/
	public boolean readBool(String AttrIdent) throws ConfigureFileException
	{
		String abc = xmlParser.getAttributeValue(AttrIdent);
		try{
			if(abc!=null)
			{
			if(abc.equalsIgnoreCase("true") || abc.equalsIgnoreCase("false") )
			{
				boolean attrValue = Boolean.valueOf(abc).booleanValue() ;//xmlParser.getAttributeValue(AttrIdent)
				return attrValue;
			}
			else
				throw new  ConfigureFileException("XML_TAG_ATTRIBUTE_NOT_BOOLEAN",fileName+"/"+AttrIdent);
			//System.out.println("the attribute:\""+AttrIdent+"\" is not a boolean!") ;
			}
			else
				throw new ConfigureFileException("XML_TAG_ATTRIBUTE_IS_NULL",fileName+"/"+AttrIdent);
		}catch(Exception e){
			throw new ConfigureFileException(e.toString());
		}
		//return false;
	}

	/**
	*删除参数,例如attrIdent形式为“Domain.WebServer.EventsEnabled”,其中EventsEnabled为参数名,
	*/
	public void deleteAttr(String attrIdent) throws ConfigureFileException
	{
		xmlParser.removeAttr(attrIdent) ;
	}

	/**
	*删除节点,nodeIdent形式为"Domain.WebServer"
	*/
	public void deleteNode(String nodeIdent) throws ConfigureFileException
	{
		xmlParser.removeNode(nodeIdent) ;
	}

	/**
	*新建一个参数,参数为:新建参数所在的节点位置,参数名,参数值
	*/
	public void addAttr(String nodeIdent,String attrName,String attrValue) throws ConfigureFileException
	{
		xmlParser.addAttr(nodeIdent,attrName,attrValue) ;
	}

	/**
	*新建一个节点,参数为:新建节点所在的父节点位置,节点名
	*/
	public void addNode(String parentNodeIdent,String nodeName) throws ConfigureFileException
	{
		xmlParser.addNode(parentNodeIdent,nodeName) ;
	}

	/**
	*读取节点,返回节点中所有的参数,并保存在Properties对象中,
	*注意:取的时候直接properties.getProperty("AttributeName"),不要带节点名。
	*例如:Properties properties = configureFile.getNodeProperties("Domain.Application") ;
	*      System.out.println(properties2.getProperty("Path")) ;//原来是Domain.Application.Path
	*/
	public Properties getNodeProperties(String nodeIdent) throws ConfigureFileException
	{
		Properties properties = xmlParser.getNodeProperties(nodeIdent) ;
		return properties;
	}

	/**
	*得到文件中所有的attributes,并且这些attr保存在Properties对象中
	*/
	public Properties getAllProperties()
	{
		Properties properties = xmlParser.getAllProperties() ;
		return properties;
	}

	/*
	//修改节点的TagName,参数为:节点的标识(形式是Domain.WebServer),新的节点名
	public void modifyNodeName(String nodeIdent,String newNodeTagName)
	{
	}
	*/

	/**
	*修改String类型的参数的值
	*/
	public void modifyAttrValue(String AttrIdent,String newAttrValue) throws ConfigureFileException
	{
		xmlParser.modifyAttr(AttrIdent,newAttrValue) ;
	}

	/**
	*修改int类型的参数的值
	*/
	public void modifyIntAttr(String AttrIdent,int newAttrValue) throws ConfigureFileException
	{
		String newattrvalue = (new Integer(newAttrValue)).toString() ;
		xmlParser.modifyAttr(AttrIdent,newattrvalue) ;
	}

	/**
	*修改boolean类型的参数的值
	*/
	public void modifyBoolAttr(String AttrIdent,boolean newAttrValue) throws ConfigureFileException
	{
		String newattrvalue = (new Boolean(newAttrValue)).toString() ;
		xmlParser.modifyAttr(AttrIdent,newattrvalue) ;
	}

	/**
	*检查node是否存在,存在返回true,不存在返回false
	*/
	public boolean nodeExist(String nodeIdent) throws ConfigureFileException
	{
		return xmlParser.nodeExist(nodeIdent);
	}

	/**
	*检查参数是否存在,存在返回true,不存在返回false
	*@param   attrIndent  attribute identification
	*/
	public boolean attrExist(String attrIdent) throws ConfigureFileException
	{
		return xmlParser.attrExist(attrIdent);
	}

	/**
	*根据encoding来保存到指定的文件中
	*/
	public void saveAs(String fileName,String encoding)
	{
		xmlParser.saveAs(fileName, encoding) ;
	}

	/**
	*根据指定的encoding来保存文件
	*/
	public void save(String encoding)
	{
		xmlParser.save(encoding) ;
	}

	/**
	*存为默认的GBK编码的文件
	*/
	public void save() throws ConfigureFileException
	{
		xmlParser.save() ;
	}

	/**
	* 得到指定节点的下一层节点的tagName
	*/
	public String[] getChildNodeTagName(String nodeUri) throws ConfigureFileException
	{
		String[] childNodeTagName = xmlParser.getChildNodeTagName(nodeUri) ;
		return childNodeTagName;
	}

	/**
	* 使xml文件中的<Include FileName="xxx.xml">替换成xxx.xml的文件内容,
	* 并且以xxx这个文件名作为相应的根节点
	*/
	public void makeInclude() throws ConfigureFileException
	{
		xmlParser.makeInclude() ;
	}

	/**
	* 根据xml文件中某一个指定节点下的直接子节点中某一个attr的value,
	* 得到该value所在节点的tagName。
	* @ param nodeUri 是指定的节点
	* @ param value 是子节点中某一String型attr的value
	*/
	public String getAttrsTagName(String nodeUri,String value) throws ConfigureFileException
	{
		return xmlParser.getAttrsTagName(nodeUri,value);
	}

	/**
	* 根据xml文件中某一个指定节点下的直接子节点中某一个attr的value,
	* 得到该value所在节点的tagName。
	* @ param nodeUri 是指定的节点
	* @ param value 是子节点中某一int型attr的value
	*/
	public String getAttrsTagName(String nodeUri,int value) throws ConfigureFileException
	{
		String sValue = new Integer(value).toString();
		return xmlParser.getAttrsTagName(nodeUri,sValue);
	}

	public Properties getTagNameAndValue(String aTagName){
		return xmlParser.getChildNode(aTagName);
	}

	public Vector getAllAttrsProperties(String nodeUri) throws ConfigureFileException{
		return xmlParser.getAllAttributesByNodeList(nodeUri);
	}

}

⌨️ 快捷键说明

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