📄 reportfactory.java
字号:
/* CRMS, customer relationship management system Copyright (C) 2003 Service To Youth Council This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information contact the SYC ICT department on GPL@syc.net.au 98 Kermode Street North Adelaide South Australia SA 5006 +61 (0)8 8367 0755 *//* * ReportFactory.java * * Created on 14 June 2003, 13:14 */package crms.report;import java.io.*;import crms.vo.*;import org.w3c.dom.*;import crms.util.*;import java.util.*;import org.apache.log4j.Logger;/** * * @author Administrator */public class ReportFactory { public static Logger logger = Logger.getLogger(ReportFactory.class); private static ReportFactory instance = null; private static String reportConfigPath = null; private static ArrayList reportConfigs = new ArrayList(); private static boolean reloadFiles = true; /** Creates a new instance of ReportFactory */ private ReportFactory() { loadReports(); } public static ReportFactory getInstance() { if (instance == null) { instance = new ReportFactory(); } return instance; } public static ReportFactory getInstance(String configPath, boolean reloadFiles) { reportConfigPath = configPath; reloadFiles = reloadFiles; return getInstance(); } public void loadReports() { reportConfigs = new ArrayList(); File configPath = new File(reportConfigPath); logger.debug("Locating report config files at: " + configPath.getPath()); File[] reportFiles = configPath.listFiles(new FileFilter() { public boolean accept(File f) { return f.getName().endsWith(".xml"); } }); if (reportFiles == null) { return; } for (int i=0; i < reportFiles.length; i++) { File reportFile = reportFiles[i]; ReportConfig config = getConfigFromFile(reportFile); reportConfigs.add(config); } } public ReportConfig getConfigFromFile(File f) { logger.debug("Report File: " + f.getName()); StringBuffer buf = getFileContents(f); Document doc = XMLUtil.createDocument(buf); Node configNode = XMLUtil.getNode("report", doc.getDocumentElement()); ReportConfig config = ReportConfig.createFromNode(configNode); logger.debug("Created report config for " + config.getKey() + " with " + config.getColumnCount() + " columns.."); config.setFilePath(f.getPath()); return config; } public StringBuffer getFileContents(File f) { StringBuffer buf = new StringBuffer(); try { BufferedReader in = new BufferedReader(new FileReader(f)); String data = in.readLine(); while (data != null) { buf.append(data); data = in.readLine(); } } catch (Exception ex) { ex.printStackTrace(); } return buf; } public int getReportConfigCount() { return reportConfigs.size(); } public ReportConfig getReportConfig(int i) { return (ReportConfig) reportConfigs.get(i); } public List getReports() { return reportConfigs; } public ReportConfig getReportConfigByKey(String key) { for (int i=0; i < getReportConfigCount(); i++) { ReportConfig config = getReportConfig(i); if (config.getKey().toLowerCase().equals(key)) { if (reloadFiles) { logger.debug("Reloading report config from file: " + config.getFilePath()); File f = new File(config.getFilePath()); config = getConfigFromFile(f); } return config; } } return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -