Java tutorial
/** * PureInfo Quake * @(#)SRM2RPMSImporter.java 1.0 2005-9-20 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.srm.srm2rpms; import java.util.Date; import java.util.List; import org.apache.log4j.Logger; import org.dom4j.Element; import com.pureinfo.force.exception.PureException; import com.pureinfo.force.io.ClassResourceUtil; import com.pureinfo.force.lang.DateTimeUtil; import com.pureinfo.force.xml.XMLUtil; import com.pureinfo.importer.Importer; /** * <P> * Created on 2005-9-20 17:50:43 <BR> * Last modified on 2005-9-20 * </P> * SRM2RPMSImporter: run importer * * @author Why * @version 1.0, 2005-9-20 * @since Quake 1.0 */ public class SRM2RPMSImporter { //logger private final static Logger logger = Logger.getLogger(SRM2RPMSImporter.class.getName()); /** * Memo: rwsk */ /** * Runs to export SRM data to RPMS * * @param _sItemFlags * flags of the data item to export. * @throws PureException * if failed. */ public static void run(String _sItemFlags) throws PureException { Date today = new Date(); int nYear = DateTimeUtil.get(today, DateTimeUtil.YEAR) - 1 + DateTimeUtil.get(today, DateTimeUtil.MONTH) / 11; logger.debug("Year=" + nYear + ", ItemFlags=" + _sItemFlags); String sConfigPath = ClassResourceUtil.mapFullPath("com/pureinfo/srm/srm2rpms/mapping/", true); String sIndexFile = sConfigPath + "index.srm.xml"; Element xml = XMLUtil.fileToElement(sIndexFile); List list = xml.elements("exporter"); Importer importer = null; try { importer = new Importer("Local", "Export"); String sConfigFile; String sFlag; for (int i = 0; i < list.size(); i++) { sConfigFile = ((Element) list.get(i)).attributeValue("config"); if (_sItemFlags != null) { sFlag = sConfigFile.substring(0, 2); if (_sItemFlags.indexOf(sFlag) < 0) continue; // skip } // else importer.config(sConfigPath + sConfigFile, nYear); importer.run(); } } finally { list.clear(); if (importer != null) importer.clear(); } } public static void main(String[] args) throws PureException { run((args == null || args.length == 0) ? null : args[0]); } }