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

📄 translationhandler.java

📁 Java写的ERP系统
💻 JAVA
字号:
/******************************************************************************
 * The contents of this file are subject to the   Compiere License  Version 1.1
 * ("License"); You may not use this file except in compliance with the License
 * You may obtain a copy of the License at http://www.compiere.org/license.html
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is                  Compiere  ERP & CRM  Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.install;

import java.sql.*;
import java.util.*;

import org.xml.sax.helpers.*;
import org.xml.sax.*;

import org.compiere.util.*;

/**
 *	SAX Handler for parsing Translation
 *
 * 	@author 	Jorg Janke
 * 	@version 	$Id: TranslationHandler.java,v 1.2 2003/01/06 03:01:01 jjanke Exp $
 */
public class TranslationHandler extends DefaultHandler
{
	/**
	 * 	Translation Handler
	 */
	public TranslationHandler ()
	{
	}	//	TranslationHandler

	/** Language						*/
	private String			m_AD_Language = null;
	/** Is Base Language				*/
	private boolean			m_isBaseLanguage = false;
	/** Table							*/
	private String			m_TableName = null;
	/** Update SQL						*/
	private String			m_updateSQL = null;
	/** Current ID						*/
	private String			m_curID = null;
	/** Current ColumnName				*/
	private String			m_curColumnName = null;
	/** Current Value					*/
	private StringBuffer	m_curValue = null;
	/**	SQL								*/
	private StringBuffer	m_sql = null;

	private Timestamp		m_time = new Timestamp(System.currentTimeMillis());
	private int				m_updateCount = 0;

	/*************************************************************************/

	/**
	 * 	Receive notification of the start of an element.
	 *
	 * 	@param uri namespace
	 * 	@param localName simple name
	 * 	@param qName qualified name
	 * 	@param attributes attributes
	 * 	@throws org.xml.sax.SAXException
	 */
	public void startElement(String uri, String localName, String qName, Attributes attributes)
		throws org.xml.sax.SAXException
	{
	//	Log.trace(Log.l6_Database, "TranslationHandler.startElement", qName);	// + " - " + uri + " - " + localName);
		if (qName.equals(Translation.XML_TAG))
		{
			m_AD_Language = attributes.getValue(Translation.XML_ATTRIBUTE_LANGUAGE);
			m_isBaseLanguage = Language.isBaseLanguage(m_AD_Language);
			m_TableName = attributes.getValue(Translation.XML_ATTRIBUTE_TABLE);
			m_updateSQL = "UPDATE " + m_TableName;
			if (!m_isBaseLanguage)
				m_updateSQL += "_Trl";
			m_updateSQL += " SET ";
			Log.trace(Log.l6_Database, "AD_Language=" + m_AD_Language + ", base=" + m_isBaseLanguage, "TableName=" + m_TableName);
		}
		else if (qName.equals(Translation.XML_ROW_TAG))
		{
			m_curID = attributes.getValue(Translation.XML_ROW_ATTRIBUTE_ID);
		//	Log.trace(9, "ID=" + m_curID);
			m_sql = new StringBuffer();
		}
		else if (qName.equals(Translation.XML_VALUE_TAG))
		{
			m_curColumnName = attributes.getValue(Translation.XML_VALUE_ATTRIBUTE_COLUMN);
		//	Log.trace(9, "ColumnName=" + m_curColName);
		}
		else
			Log.trace(Log.l6_Database, "UNKNOWN TAG " + qName);
		m_curValue = new StringBuffer();
	}	//	startElement

	/**
	 *	Receive notification of character data inside an element.
	 *
	 * 	@param ch buffer
	 * 	@param start start
	 * 	@param length length
	 * 	@throws SAXException
	 */
	public void characters (char ch[], int start, int length)
		throws SAXException
	{
		m_curValue.append(ch, start, length);
	//	Log.trace(Log.l6_Database+1, "TranslationHandler.characters", m_curValue.toString());
	}	//	characters

	/**
	 *	Receive notification of the end of an element.
	 * 	@param uri namespace
	 * 	@param localName simple name
	 * 	@param qName qualified name
	 * 	@throws SAXException
	 */
	public void endElement (String uri, String localName, String qName)
		throws SAXException
	{
	//	Log.trace(Log.l6_Database+1, "TranslationHandler.endElement", qName);
		if (qName.equals(Translation.XML_TAG))
		{
		}
		else if (qName.equals(Translation.XML_ROW_TAG))
		{
			//	Set section
			if (m_sql.length() > 0)
				m_sql.append(",");
			m_sql.append("Updated=").append(DB.TO_DATE(m_time, false));
			if (!m_isBaseLanguage)
				m_sql.append(",IsTranslated='Y'");
			//	Where section
			m_sql.append(" WHERE ")
				.append(m_TableName).append("_ID=").append(m_curID);
			if (!m_isBaseLanguage)
				m_sql.append(" AND AD_Language='").append(m_AD_Language).append("'");
			//	Update section
			m_sql.insert(0, m_updateSQL);
			//
			int no = DB.executeUpdate(m_sql.toString());
			if (no == 1)
			{
				Log.trace(9, m_sql.toString());
				m_updateCount++;
			}
			else
				Log.error("TranslationHandler.endElement #=" + no + " (Should be 1) " + m_sql.toString());
		}
		else if (qName.equals(Translation.XML_VALUE_TAG))
		{
			if (m_sql.length() > 0)
				m_sql.append(",");
			m_sql.append(m_curColumnName).append("=").append(DB.TO_STRING(m_curValue.toString()));
		}
	}	//	endElement


	/**
	 * 	Get Number of updates
	 * 	@return update count
	 */
	public int getUpdateCount()
	{
		return m_updateCount;
	}	//	getUpdateCount

}	//	TranslationHandler

⌨️ 快捷键说明

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