📄 report.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 *//* * Report.java * * Created on 11 June 2003, 17:05 */package crms.report;import java.util.*;import java.text.*;import java.io.*;import org.apache.log4j.Logger;/** * * @author Administrator */public class Report { public static int ORIENTATION_PORTRAIT = 0; public static int ORIENTATION_LANDSCAPE = 1; private String heading = null; private String subHeading = null; private String user = null; private Date runDate = new Date(); private StringBuffer content = null; private int orientation = ORIENTATION_PORTRAIT; public static SimpleDateFormat df = new SimpleDateFormat("d MMMM yyyy, h:mm a"); public static String TAG_ROOT = "entry-list"; public static String TAG_ENTRY = "entry"; public static Logger logger = Logger.getLogger(Report.class); public int columnWidths[]; public String columnHeadings[]; public void setHeading(String heading) { this.heading = heading; } public String getHeading() { return heading; } public void setSubHeading(String subHeading) { this.subHeading = subHeading; } public String getSubHeading() { return subHeading; } public void setUser(String user) { this.user = user; } public String getUser() { return user; } public Date getRunDate() { return runDate; } public void setOrientation(int or) { this.orientation = or; } public int getOrientation() { return orientation; } /** * Sets the XML content of this report (what is ultimately converted * to a PDF file... */ public void setContent(StringBuffer xml) { content = xml; } public StringBuffer getContent() { return content; } public void setColumnHeadings( String[] headings) { this.columnHeadings = headings; } public void setColumnWidths(int[] widths) { this.columnWidths = widths; } public ByteArrayInputStream getInputStream() { StringBuffer pre = new StringBuffer(); // Insert required xml before the content. pre.append("<?xml version=\"1.0\" ?>\n"); pre.append("<report>\n"); pre.append(" <heading>" + getHeading() + "</heading>\n"); pre.append(" <sub-heading>" + getHeading() + "</sub-heading>\n"); pre.append(" <date>" + df.format(getRunDate()) + "</date>\n"); pre.append(" <column-defs>\n"); for (int i=0; i < columnWidths.length; i++) { int percentage = columnWidths[i]; float maxWidth = 18; // Portrait Width if (getOrientation() == ORIENTATION_LANDSCAPE) { maxWidth = 26.7f; // Lanscape Width } float cm = (float) percentage/100 * maxWidth; NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(1); nf.setMinimumIntegerDigits(1); pre.append(" <column-def width=\"" + nf.format(cm) + "\"/>\n"); } pre.append(" </column-defs>\n"); pre.append(" <headers>\n"); for (int i=0; i < columnHeadings.length; i++) { pre.append(" <header name=\"" + columnHeadings[i] + "\"/>\n"); } pre.append(" </headers>\n"); content.insert(0, pre.toString()); // Close the root tag content.append("</report>\n"); logger.debug("XML:\n" + content.toString()); // Return the complete buffer contents ByteArrayInputStream in = new ByteArrayInputStream(content.toString().getBytes()); return in; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -