.xml正向反向取值(之六)

FileListener类,续:
private void println() throws IOException
	{
		String line;
		StringBuffer buf = new StringBuffer();
		
		FileInputStream in = new FileInputStream(enumerateFiles.get(currentEnumFilePath).getEnumFile());
		
		java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(in));
		
		while((line = reader.readLine()) != null)
		{
			buf.append(line).append("\n");
		}
		
		logger.info(buf.toString());
	}
	
	public Properties getProperties()
	{
		return prop;
	}
	
	public Element getElement()
	{
		return element;
	}

	public boolean isFileFlag() {
		return fileFlag;
	}

	public String getFileName()
	{
		return file.getName();
	}
	
    public String getPath()
    {
        return file.getPath();
    }
    
    public String getTransferValue(String key)
    {	
    	//由 Type + OriginallyValue + value 或 Type + TransferAttr + value组成。 
    	String[] keys = key.split("\\|\\|");
    	//没有传Value 是返回null
    	if (keys.length == 2) return null;
    	
    	String transferValue=keys[2];
    	
    	XMLParserHelper helper = new XMLParserHelper();
    	for(String s : enumerateFiles.keySet()){
    		Element TransferAttrs = helper.getElement(enumerateFiles.get(s).getEnumElement(),null,keys[0]);
        	if (TransferAttrs == null)
        	{
    	    	//logger.warn("Cannot found the xml properties [" + keys[0] + "]");
    	    	//return keys[2];
        		continue;
        	}
        	
        	for(int i = 0; i < TransferAttrs.getChildCount(); i++)
        	{
        		Element transfer = TransferAttrs.getElement(i);
        		
        		if (transfer == null) continue;
        		
        		String orig_str = helper.getText(transfer, XMLParserHelper.ORIGINALL_VALUE);
        		String tran_str = helper.getText(transfer, XMLParserHelper.TRANSFER_VALUE);
        		
        		if (XMLParserHelper.ORIGINALL_VALUE.equals(keys[1]) && keys[2].equals(orig_str))
        		{
        			transferValue=tran_str;
        			return transferValue;
        		}
        		else if (XMLParserHelper.TRANSFER_VALUE.equals(keys[1]) && keys[2].equals(tran_str))
        		{
        			transferValue=orig_str;
        			return transferValue;
        		}
        	}
    	}
    	logger.warn("Cannot found the value ["+keys[2]+ "] by node[" + keys[0] + " in xml file]");
    	return transferValue;
    }
    //设置所有的枚举文件的信息
    public String setEnumInfo(String filePath){
		//是否是ListenerFile5的值:/var/mqsi/config/enumerateTemplet.xml
		if(PatternEnumerateFile.isXMLFile(filePath)){
			//var-->config目录下的所有枚举文件     初始化enumPaths
			if(enumPaths.size()<=0){
				enumPaths=PatternEnumerateFile.getEnumPaths(filePath);
				for(String s : enumPaths){
					enumerateFiles.put(s, new EnumerateFile(s));
					//设置当前枚举路径
					currentEnumFilePath=s;
					//设置枚举根节点
					loadXml();
				}
			}
			if(enumPaths!=null&&enumPaths.size()>0){
				currentEnumFilePath=enumPaths.get(0);
				filePath=enumPaths.get(0);
			}
		}
		return filePath;
    }
}

你可能感兴趣的:(xml)