first commit
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import net.sf.jasperreports.engine.JRRuntimeException;
|
||||
|
||||
public class DefaultFormatFactory implements FormatFactory {
|
||||
public static final String STANDARD_DATE_FORMAT_DEFAULT = "default";
|
||||
|
||||
public static final String STANDARD_DATE_FORMAT_SHORT = "short";
|
||||
|
||||
public static final String STANDARD_DATE_FORMAT_MEDIUM = "medium";
|
||||
|
||||
public static final String STANDARD_DATE_FORMAT_LONG = "long";
|
||||
|
||||
public static final String STANDARD_DATE_FORMAT_FULL = "full";
|
||||
|
||||
public static final String STANDARD_DATE_FORMAT_HIDE = "hide";
|
||||
|
||||
public static final String STANDARD_DATE_FORMAT_SEPARATOR = ",";
|
||||
|
||||
public DateFormat createDateFormat(String pattern, Locale locale, TimeZone tz) {
|
||||
DateFormat format;
|
||||
int[] dateStyle = null;
|
||||
int[] timeStyle = null;
|
||||
if (pattern != null && pattern.trim().length() > 0) {
|
||||
int sepIdx = pattern.indexOf(",");
|
||||
String dateTok = (sepIdx < 0) ? pattern : pattern.substring(0, sepIdx);
|
||||
dateStyle = getDateStyle(dateTok);
|
||||
if (dateStyle != null)
|
||||
if (sepIdx >= 0) {
|
||||
String timeTok = pattern.substring(sepIdx + ",".length());
|
||||
timeStyle = getDateStyle(timeTok);
|
||||
} else {
|
||||
timeStyle = dateStyle;
|
||||
}
|
||||
}
|
||||
if (dateStyle != null && timeStyle != null) {
|
||||
format = getDateFormat(dateStyle, timeStyle, locale);
|
||||
} else {
|
||||
if (locale == null) {
|
||||
format = DateFormat.getDateTimeInstance(3, 3);
|
||||
} else {
|
||||
format = DateFormat.getDateTimeInstance(3, 3, locale);
|
||||
}
|
||||
if (pattern != null && pattern.trim().length() > 0 && format instanceof SimpleDateFormat)
|
||||
((SimpleDateFormat)format).applyPattern(pattern);
|
||||
}
|
||||
if (tz != null)
|
||||
format.setTimeZone(tz);
|
||||
return format;
|
||||
}
|
||||
|
||||
protected static int[] getDateStyle(String pattern) {
|
||||
if (pattern.equalsIgnoreCase("default"))
|
||||
return new int[] { 2 };
|
||||
if (pattern.equalsIgnoreCase("short"))
|
||||
return new int[] { 3 };
|
||||
if (pattern.equalsIgnoreCase("medium"))
|
||||
return new int[] { 2 };
|
||||
if (pattern.equalsIgnoreCase("long"))
|
||||
return new int[] { 1 };
|
||||
if (pattern.equalsIgnoreCase("full"))
|
||||
return new int[] { 0 };
|
||||
if (pattern.equalsIgnoreCase("hide"))
|
||||
return new int[0];
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static DateFormat getDateFormat(int[] dateStyle, int[] timeStyle, Locale locale) {
|
||||
if (dateStyle.length == 0) {
|
||||
if (timeStyle.length == 0)
|
||||
return new SimpleDateFormat("");
|
||||
return (locale == null) ? DateFormat.getTimeInstance(timeStyle[0]) : DateFormat.getTimeInstance(timeStyle[0], locale);
|
||||
}
|
||||
if (timeStyle.length == 0)
|
||||
return (locale == null) ? DateFormat.getDateInstance(dateStyle[0]) : DateFormat.getDateInstance(dateStyle[0], locale);
|
||||
return (locale == null) ? DateFormat.getDateTimeInstance(dateStyle[0], timeStyle[0]) : DateFormat.getDateTimeInstance(dateStyle[0], timeStyle[0], locale);
|
||||
}
|
||||
|
||||
public NumberFormat createNumberFormat(String pattern, Locale locale) {
|
||||
NumberFormat format = null;
|
||||
if (pattern != null && pattern.trim().length() > 0) {
|
||||
if (locale == null) {
|
||||
format = NumberFormat.getNumberInstance();
|
||||
} else {
|
||||
format = NumberFormat.getNumberInstance(locale);
|
||||
}
|
||||
if (format instanceof DecimalFormat)
|
||||
((DecimalFormat)format).applyPattern(pattern);
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
public static FormatFactory createFormatFactory(String formatFactoryClassName) {
|
||||
FormatFactory formatFactory = null;
|
||||
if (formatFactoryClassName != null) {
|
||||
try {
|
||||
Class formatFactoryClass = JRClassLoader.loadClassForName(formatFactoryClassName);
|
||||
formatFactory = formatFactoryClass.newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new JRRuntimeException("Error loading format factory class : " + formatFactoryClassName, e);
|
||||
} catch (Exception e) {
|
||||
throw new JRRuntimeException("Error creating format factory instance : " + formatFactoryClassName, e);
|
||||
}
|
||||
} else {
|
||||
formatFactory = new DefaultFormatFactory();
|
||||
}
|
||||
return formatFactory;
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface FileResolver {
|
||||
File resolveFile(String paramString);
|
||||
}
|
12
hrmsEjb/net/sf/jasperreports/engine/util/FormatFactory.java
Normal file
12
hrmsEjb/net/sf/jasperreports/engine/util/FormatFactory.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public interface FormatFactory {
|
||||
DateFormat createDateFormat(String paramString, Locale paramLocale, TimeZone paramTimeZone);
|
||||
|
||||
NumberFormat createNumberFormat(String paramString, Locale paramLocale);
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
|
||||
public abstract class JRAbstractImageEncoder implements JRImageEncoder {
|
||||
public byte[] encode(Image image, byte imageType) throws JRException {
|
||||
BufferedImage bi = null;
|
||||
if (image instanceof BufferedImage) {
|
||||
bi = (BufferedImage)image;
|
||||
} else {
|
||||
bi = new BufferedImage(image.getWidth(null), image.getHeight(null), (imageType == 1 || imageType == 3) ? 2 : 1);
|
||||
Graphics g = bi.createGraphics();
|
||||
g.drawImage(image, 0, 0, null);
|
||||
g.dispose();
|
||||
}
|
||||
return encode(bi, imageType);
|
||||
}
|
||||
|
||||
public abstract byte[] encode(BufferedImage paramBufferedImage, byte paramByte) throws JRException;
|
||||
}
|
78
hrmsEjb/net/sf/jasperreports/engine/util/JRBoxUtil.java
Normal file
78
hrmsEjb/net/sf/jasperreports/engine/util/JRBoxUtil.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import net.sf.jasperreports.engine.JRBox;
|
||||
import net.sf.jasperreports.engine.JRLineBox;
|
||||
import net.sf.jasperreports.engine.JRPen;
|
||||
|
||||
public class JRBoxUtil {
|
||||
public static JRLineBox clone(JRLineBox box, boolean keepLeft, boolean keepRight, boolean keepTop, boolean keepBottom, JRLineBox complementaryBox) {
|
||||
JRLineBox clone = box.clone(box.getBoxContainer());
|
||||
if (!keepLeft || box.getLeftPen().getLineWidth().floatValue() <= 0.0F)
|
||||
if (complementaryBox != null) {
|
||||
clone.getLeftPen().setLineWidth(complementaryBox.getLeftPen().getLineWidth());
|
||||
clone.getLeftPen().setLineColor(complementaryBox.getLeftPen().getLineColor());
|
||||
clone.setLeftPadding(complementaryBox.getLeftPadding());
|
||||
} else {
|
||||
clone.getLeftPen().setLineWidth(0.0F);
|
||||
}
|
||||
if (!keepRight || box.getRightPen().getLineWidth().floatValue() <= 0.0F)
|
||||
if (complementaryBox != null) {
|
||||
clone.getRightPen().setLineWidth(complementaryBox.getRightPen().getLineWidth());
|
||||
clone.getRightPen().setLineColor(complementaryBox.getRightPen().getLineColor());
|
||||
clone.setRightPadding(complementaryBox.getRightPadding());
|
||||
} else {
|
||||
clone.getRightPen().setLineWidth(0.0F);
|
||||
}
|
||||
if (!keepTop || box.getTopPen().getLineWidth().floatValue() <= 0.0F)
|
||||
if (complementaryBox != null) {
|
||||
clone.getTopPen().setLineWidth(complementaryBox.getTopPen().getLineWidth());
|
||||
clone.getTopPen().setLineColor(complementaryBox.getTopPen().getLineColor());
|
||||
clone.setTopPadding(complementaryBox.getTopPadding());
|
||||
} else {
|
||||
clone.getTopPen().setLineWidth(0.0F);
|
||||
}
|
||||
if (!keepBottom || box.getBottomPen().getLineWidth().floatValue() <= 0.0F)
|
||||
if (complementaryBox != null) {
|
||||
clone.getBottomPen().setLineWidth(complementaryBox.getBottomPen().getLineWidth());
|
||||
clone.getBottomPen().setLineColor(complementaryBox.getBottomPen().getLineColor());
|
||||
clone.setBottomPadding(complementaryBox.getBottomPadding());
|
||||
} else {
|
||||
clone.getBottomPen().setLineWidth(0.0F);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
public static void reset(JRLineBox box, boolean resetLeft, boolean resetRight, boolean resetTop, boolean resetBottom) {
|
||||
if (resetLeft)
|
||||
box.getLeftPen().setLineWidth(0.0F);
|
||||
if (resetRight)
|
||||
box.getRightPen().setLineWidth(0.0F);
|
||||
if (resetTop)
|
||||
box.getTopPen().setLineWidth(0.0F);
|
||||
if (resetBottom)
|
||||
box.getBottomPen().setLineWidth(0.0F);
|
||||
}
|
||||
|
||||
public static void setToBox(Byte border, Byte topBorder, Byte leftBorder, Byte bottomBorder, Byte rightBorder, Color borderColor, Color topBorderColor, Color leftBorderColor, Color bottomBorderColor, Color rightBorderColor, Integer padding, Integer topPadding, Integer leftPadding, Integer bottomPadding, Integer rightPadding, JRLineBox box) {
|
||||
JRPenUtil.setLinePenFromPen(border, (JRPen)box.getPen());
|
||||
JRPenUtil.setLinePenFromPen(topBorder, (JRPen)box.getTopPen());
|
||||
JRPenUtil.setLinePenFromPen(leftBorder, (JRPen)box.getLeftPen());
|
||||
JRPenUtil.setLinePenFromPen(bottomBorder, (JRPen)box.getBottomPen());
|
||||
JRPenUtil.setLinePenFromPen(rightBorder, (JRPen)box.getRightPen());
|
||||
box.getPen().setLineColor(borderColor);
|
||||
box.getTopPen().setLineColor(topBorderColor);
|
||||
box.getLeftPen().setLineColor(leftBorderColor);
|
||||
box.getBottomPen().setLineColor(bottomBorderColor);
|
||||
box.getRightPen().setLineColor(rightBorderColor);
|
||||
box.setPadding(padding);
|
||||
box.setTopPadding(topPadding);
|
||||
box.setLeftPadding(leftPadding);
|
||||
box.setBottomPadding(bottomPadding);
|
||||
box.setRightPadding(rightPadding);
|
||||
}
|
||||
|
||||
public static void setBoxToLineBox(JRBox box, JRLineBox lineBox) {
|
||||
setToBox(box.getOwnBorder(), box.getOwnTopBorder(), box.getOwnLeftBorder(), box.getOwnBottomBorder(), box.getOwnRightBorder(), box.getOwnBorderColor(), box.getOwnTopBorderColor(), box.getOwnLeftBorderColor(), box.getOwnBottomBorderColor(), box.getOwnRightBorderColor(), box.getOwnPadding(), box.getOwnTopPadding(), box.getOwnLeftPadding(), box.getOwnBottomPadding(), box.getOwnRightPadding(), lineBox);
|
||||
}
|
||||
}
|
170
hrmsEjb/net/sf/jasperreports/engine/util/JRClassLoader.java
Normal file
170
hrmsEjb/net/sf/jasperreports/engine/util/JRClassLoader.java
Normal file
@@ -0,0 +1,170 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
public class JRClassLoader extends ClassLoader {
|
||||
private static ProtectionDomainFactory protectionDomainFactory = null;
|
||||
|
||||
private ProtectionDomain protectionDomain;
|
||||
|
||||
protected static synchronized ProtectionDomainFactory getProtectionDomainFactory() {
|
||||
if (protectionDomainFactory == null)
|
||||
protectionDomainFactory = new SingleProtectionDomainFactory(JRClassLoader.class.getProtectionDomain());
|
||||
return protectionDomainFactory;
|
||||
}
|
||||
|
||||
public static void setProtectionDomain(ProtectionDomain protectionDomain) {
|
||||
SingleProtectionDomainFactory factory = new SingleProtectionDomainFactory(protectionDomain);
|
||||
setProtectionDomainFactory(factory);
|
||||
}
|
||||
|
||||
public static void setProtectionDomainFactory(ProtectionDomainFactory protectionDomainFactory) {
|
||||
JRClassLoader.protectionDomainFactory = protectionDomainFactory;
|
||||
}
|
||||
|
||||
protected JRClassLoader() {}
|
||||
|
||||
protected JRClassLoader(ClassLoader parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public static Class loadClassForName(String className) throws ClassNotFoundException {
|
||||
Class clazz = null;
|
||||
String classRealName = className;
|
||||
ClassNotFoundException initialEx = null;
|
||||
try {
|
||||
clazz = loadClassForRealName(classRealName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
initialEx = e;
|
||||
}
|
||||
int lastDotIndex = 0;
|
||||
while (clazz == null && (lastDotIndex = classRealName.lastIndexOf('.')) > 0) {
|
||||
classRealName = classRealName.substring(0, lastDotIndex) + "$" + classRealName.substring(lastDotIndex + 1);
|
||||
try {
|
||||
clazz = loadClassForRealName(classRealName);
|
||||
} catch (ClassNotFoundException e) {}
|
||||
}
|
||||
if (clazz == null)
|
||||
throw initialEx;
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static Class loadClassForRealName(String className) throws ClassNotFoundException {
|
||||
Class clazz = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader != null)
|
||||
try {
|
||||
clazz = Class.forName(className, true, classLoader);
|
||||
} catch (ClassNotFoundException e) {}
|
||||
if (clazz == null) {
|
||||
classLoader = JRClassLoader.class.getClassLoader();
|
||||
if (classLoader == null) {
|
||||
clazz = Class.forName(className);
|
||||
} else {
|
||||
clazz = Class.forName(className, true, classLoader);
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static Class loadClassFromFile(String className, File file) throws IOException {
|
||||
Class clazz = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader != null)
|
||||
try {
|
||||
clazz = (new JRClassLoader(classLoader)).loadClass(className, file);
|
||||
} catch (NoClassDefFoundError e) {}
|
||||
if (clazz == null) {
|
||||
classLoader = JRClassLoader.class.getClassLoader();
|
||||
if (classLoader == null) {
|
||||
clazz = (new JRClassLoader()).loadClass(className, file);
|
||||
} else {
|
||||
clazz = (new JRClassLoader(classLoader)).loadClass(className, file);
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static Class loadClassFromBytes(String className, byte[] bytecodes) {
|
||||
Class clazz = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader != null)
|
||||
try {
|
||||
clazz = (new JRClassLoader(classLoader)).loadClass(className, bytecodes);
|
||||
} catch (NoClassDefFoundError e) {}
|
||||
if (clazz == null) {
|
||||
classLoader = JRClassLoader.class.getClassLoader();
|
||||
if (classLoader == null) {
|
||||
clazz = (new JRClassLoader()).loadClass(className, bytecodes);
|
||||
} else {
|
||||
clazz = (new JRClassLoader(classLoader)).loadClass(className, bytecodes);
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
protected Class loadClass(String className, File file) throws IOException {
|
||||
FileInputStream fis = null;
|
||||
ByteArrayOutputStream baos = null;
|
||||
byte[] bytecodes = new byte[10000];
|
||||
int ln = 0;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
baos = new ByteArrayOutputStream();
|
||||
while ((ln = fis.read(bytecodes)) > 0)
|
||||
baos.write(bytecodes, 0, ln);
|
||||
baos.flush();
|
||||
} finally {
|
||||
if (baos != null)
|
||||
try {
|
||||
baos.close();
|
||||
} catch (IOException e) {}
|
||||
if (fis != null)
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
return loadClass(className, baos.toByteArray());
|
||||
}
|
||||
|
||||
protected synchronized ProtectionDomain getProtectionDomain() {
|
||||
if (this.protectionDomain == null)
|
||||
this.protectionDomain = getProtectionDomainFactory().getProtectionDomain(this);
|
||||
return this.protectionDomain;
|
||||
}
|
||||
|
||||
protected Class loadClass(String className, byte[] bytecodes) {
|
||||
Class clazz = null;
|
||||
clazz = defineClass(className, bytecodes, 0, bytecodes.length, getProtectionDomain());
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static String getClassRealName(String className) {
|
||||
if (className == null)
|
||||
return null;
|
||||
int arrayDimension = 0;
|
||||
int classNameEnd = className.length();
|
||||
int index = 0;
|
||||
int pos = 0;
|
||||
while (index < classNameEnd && (pos = className.indexOf('[', index)) >= 0) {
|
||||
if (index == 0)
|
||||
classNameEnd = pos;
|
||||
index = pos;
|
||||
arrayDimension++;
|
||||
}
|
||||
if (arrayDimension > 0) {
|
||||
StringBuffer sbuffer = new StringBuffer();
|
||||
for (int i = 0; i < arrayDimension; i++)
|
||||
sbuffer.append('[');
|
||||
sbuffer.append('L');
|
||||
sbuffer.append(className.substring(0, classNameEnd));
|
||||
sbuffer.append(';');
|
||||
return sbuffer.toString();
|
||||
}
|
||||
return className;
|
||||
}
|
||||
}
|
12
hrmsEjb/net/sf/jasperreports/engine/util/JRColorUtil.java
Normal file
12
hrmsEjb/net/sf/jasperreports/engine/util/JRColorUtil.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
public class JRColorUtil {
|
||||
public static final int COLOR_MASK = Integer.parseInt("FFFFFF", 16);
|
||||
|
||||
public static String getColorHexa(Color color) {
|
||||
String hexa = Integer.toHexString(color.getRGB() & COLOR_MASK).toUpperCase();
|
||||
return ("000000" + hexa).substring(hexa.length());
|
||||
}
|
||||
}
|
38
hrmsEjb/net/sf/jasperreports/engine/util/JRDataUtils.java
Normal file
38
hrmsEjb/net/sf/jasperreports/engine/util/JRDataUtils.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class JRDataUtils {
|
||||
public static String getLocaleCode(Locale locale) {
|
||||
return locale.toString();
|
||||
}
|
||||
|
||||
public static Locale getLocale(String code) {
|
||||
String language, country, variant;
|
||||
int firstSep = code.indexOf('_');
|
||||
if (firstSep < 0) {
|
||||
language = code;
|
||||
country = variant = "";
|
||||
} else {
|
||||
language = code.substring(0, firstSep);
|
||||
int secondSep = code.indexOf('_', firstSep + 1);
|
||||
if (secondSep < 0) {
|
||||
country = code.substring(firstSep + 1);
|
||||
variant = "";
|
||||
} else {
|
||||
country = code.substring(firstSep + 1, secondSep);
|
||||
variant = code.substring(secondSep + 1);
|
||||
}
|
||||
}
|
||||
return new Locale(language, country, variant);
|
||||
}
|
||||
|
||||
public static String getTimeZoneId(TimeZone tz) {
|
||||
return tz.getID();
|
||||
}
|
||||
|
||||
public static TimeZone getTimeZone(String id) {
|
||||
return TimeZone.getTimeZone(id);
|
||||
}
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import net.sf.jasperreports.crosstabs.JRCrosstab;
|
||||
import net.sf.jasperreports.engine.JRBreak;
|
||||
import net.sf.jasperreports.engine.JRChart;
|
||||
import net.sf.jasperreports.engine.JRElementGroup;
|
||||
import net.sf.jasperreports.engine.JREllipse;
|
||||
import net.sf.jasperreports.engine.JRFrame;
|
||||
import net.sf.jasperreports.engine.JRImage;
|
||||
import net.sf.jasperreports.engine.JRLine;
|
||||
import net.sf.jasperreports.engine.JRRectangle;
|
||||
import net.sf.jasperreports.engine.JRStaticText;
|
||||
import net.sf.jasperreports.engine.JRSubreport;
|
||||
import net.sf.jasperreports.engine.JRTextField;
|
||||
import net.sf.jasperreports.engine.JRVisitor;
|
||||
|
||||
public abstract class JRDelegationVisitor implements JRVisitor {
|
||||
private final JRVisitor visitor;
|
||||
|
||||
public JRDelegationVisitor(JRVisitor visitor) {
|
||||
this.visitor = visitor;
|
||||
}
|
||||
|
||||
public JRVisitor getVisitor() {
|
||||
return this.visitor;
|
||||
}
|
||||
|
||||
public void visitBreak(JRBreak breakElement) {
|
||||
this.visitor.visitBreak(breakElement);
|
||||
}
|
||||
|
||||
public void visitChart(JRChart chart) {
|
||||
this.visitor.visitChart(chart);
|
||||
}
|
||||
|
||||
public void visitCrosstab(JRCrosstab crosstab) {
|
||||
this.visitor.visitCrosstab(crosstab);
|
||||
}
|
||||
|
||||
public void visitElementGroup(JRElementGroup elementGroup) {
|
||||
this.visitor.visitElementGroup(elementGroup);
|
||||
}
|
||||
|
||||
public void visitEllipse(JREllipse ellipse) {
|
||||
this.visitor.visitEllipse(ellipse);
|
||||
}
|
||||
|
||||
public void visitFrame(JRFrame frame) {
|
||||
this.visitor.visitFrame(frame);
|
||||
}
|
||||
|
||||
public void visitImage(JRImage image) {
|
||||
this.visitor.visitImage(image);
|
||||
}
|
||||
|
||||
public void visitLine(JRLine line) {
|
||||
this.visitor.visitLine(line);
|
||||
}
|
||||
|
||||
public void visitRectangle(JRRectangle rectangle) {
|
||||
this.visitor.visitRectangle(rectangle);
|
||||
}
|
||||
|
||||
public void visitStaticText(JRStaticText staticText) {
|
||||
this.visitor.visitStaticText(staticText);
|
||||
}
|
||||
|
||||
public void visitSubreport(JRSubreport subreport) {
|
||||
this.visitor.visitSubreport(subreport);
|
||||
}
|
||||
|
||||
public void visitTextField(JRTextField textField) {
|
||||
this.visitor.visitTextField(textField);
|
||||
}
|
||||
}
|
115
hrmsEjb/net/sf/jasperreports/engine/util/JRElementsVisitor.java
Normal file
115
hrmsEjb/net/sf/jasperreports/engine/util/JRElementsVisitor.java
Normal file
@@ -0,0 +1,115 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import net.sf.jasperreports.crosstabs.JRCellContents;
|
||||
import net.sf.jasperreports.crosstabs.JRCrosstab;
|
||||
import net.sf.jasperreports.crosstabs.JRCrosstabCell;
|
||||
import net.sf.jasperreports.crosstabs.JRCrosstabColumnGroup;
|
||||
import net.sf.jasperreports.crosstabs.JRCrosstabRowGroup;
|
||||
import net.sf.jasperreports.crosstabs.design.JRDesignCrosstab;
|
||||
import net.sf.jasperreports.engine.JRBand;
|
||||
import net.sf.jasperreports.engine.JRChild;
|
||||
import net.sf.jasperreports.engine.JRElementGroup;
|
||||
import net.sf.jasperreports.engine.JRFrame;
|
||||
import net.sf.jasperreports.engine.JRGroup;
|
||||
import net.sf.jasperreports.engine.JRReport;
|
||||
import net.sf.jasperreports.engine.JRVisitor;
|
||||
|
||||
public class JRElementsVisitor extends JRDelegationVisitor {
|
||||
public static void visitReport(JRReport report, JRVisitor visitor) {
|
||||
JRElementsVisitor reportVisitor = new JRElementsVisitor(visitor);
|
||||
reportVisitor.visitReport(report);
|
||||
}
|
||||
|
||||
public JRElementsVisitor(JRVisitor visitor) {
|
||||
super(visitor);
|
||||
}
|
||||
|
||||
public void visitReport(JRReport report) {
|
||||
visitBand(report.getBackground());
|
||||
visitBand(report.getTitle());
|
||||
visitBand(report.getPageHeader());
|
||||
visitBand(report.getColumnHeader());
|
||||
visitBand(report.getDetail());
|
||||
visitBand(report.getColumnFooter());
|
||||
visitBand(report.getPageFooter());
|
||||
visitBand(report.getLastPageFooter());
|
||||
visitBand(report.getSummary());
|
||||
visitBand(report.getNoData());
|
||||
JRGroup[] groups = report.getGroups();
|
||||
if (groups != null)
|
||||
for (int i = 0; i < groups.length; i++) {
|
||||
JRGroup group = groups[i];
|
||||
visitBand(group.getGroupHeader());
|
||||
visitBand(group.getGroupFooter());
|
||||
}
|
||||
}
|
||||
|
||||
protected void visitBand(JRBand band) {
|
||||
if (band != null)
|
||||
band.visit(this);
|
||||
}
|
||||
|
||||
protected void visitElements(List elements) {
|
||||
if (elements != null)
|
||||
for (Iterator it = elements.iterator(); it.hasNext(); ) {
|
||||
JRChild child = it.next();
|
||||
child.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void visitElementGroup(JRElementGroup elementGroup) {
|
||||
super.visitElementGroup(elementGroup);
|
||||
visitElements(elementGroup.getChildren());
|
||||
}
|
||||
|
||||
public void visitFrame(JRFrame frame) {
|
||||
super.visitFrame(frame);
|
||||
visitElements(frame.getChildren());
|
||||
}
|
||||
|
||||
public void visitCrosstab(JRCrosstab crosstab) {
|
||||
super.visitCrosstab(crosstab);
|
||||
visitCrosstabCell(crosstab.getWhenNoDataCell());
|
||||
visitCrosstabCell(crosstab.getHeaderCell());
|
||||
JRCrosstabRowGroup[] rowGroups = crosstab.getRowGroups();
|
||||
for (int i = 0; i < rowGroups.length; i++) {
|
||||
JRCrosstabRowGroup rowGroup = rowGroups[i];
|
||||
visitCrosstabCell(rowGroup.getHeader());
|
||||
visitCrosstabCell(rowGroup.getTotalHeader());
|
||||
}
|
||||
JRCrosstabColumnGroup[] columnGroups = crosstab.getColumnGroups();
|
||||
for (int j = 0; j < columnGroups.length; j++) {
|
||||
JRCrosstabColumnGroup columnGroup = columnGroups[j];
|
||||
visitCrosstabCell(columnGroup.getHeader());
|
||||
visitCrosstabCell(columnGroup.getTotalHeader());
|
||||
}
|
||||
if (crosstab instanceof JRDesignCrosstab) {
|
||||
List cells = ((JRDesignCrosstab)crosstab).getCellsList();
|
||||
for (Iterator it = cells.iterator(); it.hasNext(); ) {
|
||||
JRCrosstabCell cell = it.next();
|
||||
visitCrosstabCell(cell.getContents());
|
||||
}
|
||||
} else {
|
||||
JRCrosstabCell[][] cells = crosstab.getCells();
|
||||
if (cells != null) {
|
||||
Set cellContents = new HashSet();
|
||||
for (int k = 0; k < cells.length; k++) {
|
||||
for (int m = 0; m < (cells[k]).length; m++) {
|
||||
JRCrosstabCell cell = cells[k][m];
|
||||
if (cell != null && cell.getContents() != null && cellContents.add(cell.getContents()))
|
||||
visitCrosstabCell(cell.getContents());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void visitCrosstabCell(JRCellContents cell) {
|
||||
if (cell != null)
|
||||
visitElements(cell.getChildren());
|
||||
}
|
||||
}
|
43
hrmsEjb/net/sf/jasperreports/engine/util/JRFontUtil.java
Normal file
43
hrmsEjb/net/sf/jasperreports/engine/util/JRFontUtil.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.sf.jasperreports.engine.JRFont;
|
||||
|
||||
public class JRFontUtil {
|
||||
public static Map getNonPdfAttributes(JRFont font) {
|
||||
Map nonPdfAttributes = new HashMap();
|
||||
setNonPdfAttributes(nonPdfAttributes, font);
|
||||
return nonPdfAttributes;
|
||||
}
|
||||
|
||||
public static Map getAttributes(JRFont font) {
|
||||
Map attributes = new HashMap();
|
||||
setAttributes(attributes, font);
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private static Map setNonPdfAttributes(Map attributes, JRFont font) {
|
||||
attributes.put(TextAttribute.FAMILY, font.getFontName());
|
||||
attributes.put(TextAttribute.SIZE, new Float(font.getFontSize()));
|
||||
if (font.isBold())
|
||||
attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
|
||||
if (font.isItalic())
|
||||
attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
|
||||
if (font.isUnderline())
|
||||
attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
||||
if (font.isStrikeThrough())
|
||||
attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public static Map setAttributes(Map attributes, JRFont font) {
|
||||
attributes = setNonPdfAttributes(attributes, font);
|
||||
attributes.put(JRTextAttribute.PDF_FONT_NAME, font.getPdfFontName());
|
||||
attributes.put(JRTextAttribute.PDF_ENCODING, font.getPdfEncoding());
|
||||
if (font.isPdfEmbedded())
|
||||
attributes.put(JRTextAttribute.IS_PDF_EMBEDDED, Boolean.TRUE);
|
||||
return attributes;
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
|
||||
public class JRGraphEnvInitializer {
|
||||
private static boolean isGraphicsEnvironmentInitiliazed = false;
|
||||
|
||||
public static void initializeGraphEnv() throws JRException {
|
||||
if (!isGraphicsEnvironmentInitiliazed) {
|
||||
try {
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
|
||||
} catch (Exception e) {
|
||||
throw new JRException("Error initializing graphic environment.", e);
|
||||
}
|
||||
isGraphicsEnvironmentInitiliazed = true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.Image;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
|
||||
public interface JRImageEncoder {
|
||||
byte[] encode(Image paramImage, byte paramByte) throws JRException;
|
||||
}
|
150
hrmsEjb/net/sf/jasperreports/engine/util/JRImageLoader.java
Normal file
150
hrmsEjb/net/sf/jasperreports/engine/util/JRImageLoader.java
Normal file
@@ -0,0 +1,150 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLStreamHandlerFactory;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.JRRuntimeException;
|
||||
|
||||
public class JRImageLoader {
|
||||
public static final String PROPERTY_IMAGE_READER = "net.sf.jasperreports.image.reader";
|
||||
|
||||
public static final String PROPERTY_IMAGE_ENCODER = "net.sf.jasperreports.image.encoder";
|
||||
|
||||
public static final byte NO_IMAGE = 1;
|
||||
|
||||
public static final byte SUBREPORT_IMAGE = 2;
|
||||
|
||||
public static final byte CHART_IMAGE = 3;
|
||||
|
||||
public static final byte CROSSTAB_IMAGE = 4;
|
||||
|
||||
private static final String str_NO_IMAGE = "net/sf/jasperreports/engine/images/noimage.GIF";
|
||||
|
||||
private static final String str_SUBREPORT_IMAGE = "net/sf/jasperreports/engine/images/subreport.GIF";
|
||||
|
||||
private static final String str_CHART_IMAGE = "net/sf/jasperreports/engine/images/chart.GIF";
|
||||
|
||||
private static final String str_CROSSTAB_IMAGE = "net/sf/jasperreports/engine/images/crosstab.GIF";
|
||||
|
||||
private static Image img_NO_IMAGE = null;
|
||||
|
||||
private static Image img_SUBREPORT_IMAGE = null;
|
||||
|
||||
private static Image img_CHART_IMAGE = null;
|
||||
|
||||
private static Image img_CROSSTAB_IMAGE = null;
|
||||
|
||||
private static JRImageReader imageReader = null;
|
||||
|
||||
private static JRImageEncoder imageEncoder = null;
|
||||
|
||||
static {
|
||||
String readerClassName = JRProperties.getProperty("net.sf.jasperreports.image.reader");
|
||||
if (readerClassName == null) {
|
||||
imageReader = new JRJdk14ImageReader();
|
||||
} else {
|
||||
try {
|
||||
Class clazz = JRClassLoader.loadClassForRealName(readerClassName);
|
||||
imageReader = clazz.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new JRRuntimeException(e);
|
||||
}
|
||||
}
|
||||
String encoderClassName = JRProperties.getProperty("net.sf.jasperreports.image.encoder");
|
||||
if (encoderClassName == null) {
|
||||
imageEncoder = new JRJdk14ImageEncoder();
|
||||
} else {
|
||||
try {
|
||||
Class clazz = JRClassLoader.loadClassForRealName(encoderClassName);
|
||||
imageEncoder = clazz.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new JRRuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] loadImageDataFromFile(File file) throws JRException {
|
||||
return JRLoader.loadBytes(file);
|
||||
}
|
||||
|
||||
public static byte[] loadImageDataFromURL(URL url) throws JRException {
|
||||
return JRLoader.loadBytes(url);
|
||||
}
|
||||
|
||||
public static byte[] loadImageDataFromInputStream(InputStream is) throws JRException {
|
||||
return JRLoader.loadBytes(is);
|
||||
}
|
||||
|
||||
public static byte[] loadImageDataFromLocation(String location) throws JRException {
|
||||
return JRLoader.loadBytesFromLocation(location);
|
||||
}
|
||||
|
||||
public static byte[] loadImageDataFromLocation(String location, ClassLoader classLoader) throws JRException {
|
||||
return JRLoader.loadBytesFromLocation(location, classLoader);
|
||||
}
|
||||
|
||||
public static byte[] loadImageDataFromLocation(String location, ClassLoader classLoader, URLStreamHandlerFactory urlHandlerFactory) throws JRException {
|
||||
return JRLoader.loadBytesFromLocation(location, classLoader, urlHandlerFactory);
|
||||
}
|
||||
|
||||
public static byte[] loadImageDataFromAWTImage(Image image, byte imageType) throws JRException {
|
||||
return imageEncoder.encode(image, imageType);
|
||||
}
|
||||
|
||||
public static byte[] loadImageDataFromAWTImage(BufferedImage bi) throws JRException {
|
||||
return loadImageDataFromAWTImage(bi, (byte)2);
|
||||
}
|
||||
|
||||
public static byte[] loadImageDataFromAWTImage(Image image) throws JRException {
|
||||
return loadImageDataFromAWTImage(image, (byte)2);
|
||||
}
|
||||
|
||||
public static Image getImage(byte index) throws JRException {
|
||||
Image image = null;
|
||||
switch (index) {
|
||||
case 1:
|
||||
if (img_NO_IMAGE == null)
|
||||
img_NO_IMAGE = loadImage("net/sf/jasperreports/engine/images/noimage.GIF");
|
||||
image = img_NO_IMAGE;
|
||||
break;
|
||||
case 2:
|
||||
if (img_SUBREPORT_IMAGE == null)
|
||||
img_SUBREPORT_IMAGE = loadImage("net/sf/jasperreports/engine/images/subreport.GIF");
|
||||
image = img_SUBREPORT_IMAGE;
|
||||
break;
|
||||
case 3:
|
||||
if (img_CHART_IMAGE == null)
|
||||
img_CHART_IMAGE = loadImage("net/sf/jasperreports/engine/images/chart.GIF");
|
||||
image = img_CHART_IMAGE;
|
||||
break;
|
||||
case 4:
|
||||
if (img_CROSSTAB_IMAGE == null)
|
||||
img_CROSSTAB_IMAGE = loadImage("net/sf/jasperreports/engine/images/crosstab.GIF");
|
||||
image = img_CROSSTAB_IMAGE;
|
||||
break;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public static Image loadImage(byte[] bytes) throws JRException {
|
||||
return imageReader.readImage(bytes);
|
||||
}
|
||||
|
||||
protected static Image loadImage(String image) throws JRException {
|
||||
InputStream is;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
URL url = classLoader.getResource(image);
|
||||
if (url == null)
|
||||
classLoader = JRImageLoader.class.getClassLoader();
|
||||
if (classLoader == null) {
|
||||
is = JRImageLoader.class.getResourceAsStream("/" + image);
|
||||
} else {
|
||||
is = classLoader.getResourceAsStream(image);
|
||||
}
|
||||
return imageReader.readImage(JRLoader.loadBytes(is));
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.Image;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
|
||||
public interface JRImageReader {
|
||||
Image readImage(byte[] paramArrayOfbyte) throws JRException;
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
|
||||
public class JRJdk14ImageEncoder extends JRAbstractImageEncoder {
|
||||
public byte[] encode(BufferedImage bi, byte imageType) throws JRException {
|
||||
String formatName = null;
|
||||
switch (imageType) {
|
||||
case 1:
|
||||
formatName = "gif";
|
||||
break;
|
||||
case 3:
|
||||
formatName = "png";
|
||||
break;
|
||||
case 4:
|
||||
formatName = "tiff";
|
||||
break;
|
||||
default:
|
||||
formatName = "jpeg";
|
||||
break;
|
||||
}
|
||||
boolean success = false;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
success = ImageIO.write(bi, formatName, baos);
|
||||
} catch (IOException e) {
|
||||
throw new JRException(e);
|
||||
}
|
||||
if (!success)
|
||||
throw new JRException("No appropriate image writer found for the \"" + formatName + "\" format.");
|
||||
return baos.toByteArray();
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.imageio.ImageIO;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
|
||||
public class JRJdk14ImageReader implements JRImageReader {
|
||||
public Image readImage(byte[] bytes) throws JRException {
|
||||
InputStream bais = new ByteArrayInputStream(bytes);
|
||||
Image image = null;
|
||||
try {
|
||||
image = ImageIO.read(bais);
|
||||
} catch (Exception e) {
|
||||
throw new JRException(e);
|
||||
} finally {
|
||||
try {
|
||||
bais.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
if (image == null)
|
||||
throw new JRException("Image read failed.");
|
||||
return image;
|
||||
}
|
||||
}
|
260
hrmsEjb/net/sf/jasperreports/engine/util/JRLoader.java
Normal file
260
hrmsEjb/net/sf/jasperreports/engine/util/JRLoader.java
Normal file
@@ -0,0 +1,260 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLStreamHandlerFactory;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
|
||||
public class JRLoader {
|
||||
public static Object loadObject(String fileName) throws JRException {
|
||||
return loadObject(new File(fileName));
|
||||
}
|
||||
|
||||
public static Object loadObject(File file) throws JRException {
|
||||
if (!file.exists() || !file.isFile())
|
||||
throw new JRException(new FileNotFoundException(String.valueOf(file)));
|
||||
Object obj = null;
|
||||
FileInputStream fis = null;
|
||||
ObjectInputStream ois = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
BufferedInputStream bufferedIn = new BufferedInputStream(fis);
|
||||
ois = new ObjectInputStream(bufferedIn);
|
||||
obj = ois.readObject();
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Error loading object from file : " + file, e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new JRException("Class not found when loading object from file : " + file, e);
|
||||
} finally {
|
||||
if (ois != null)
|
||||
try {
|
||||
ois.close();
|
||||
} catch (IOException e) {}
|
||||
if (fis != null)
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static Object loadObject(URL url) throws JRException {
|
||||
Object obj = null;
|
||||
InputStream is = null;
|
||||
ObjectInputStream ois = null;
|
||||
try {
|
||||
is = url.openStream();
|
||||
ois = new ObjectInputStream(is);
|
||||
obj = ois.readObject();
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Error loading object from URL : " + url, e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new JRException("Class not found when loading object from URL : " + url, e);
|
||||
} finally {
|
||||
if (ois != null)
|
||||
try {
|
||||
ois.close();
|
||||
} catch (IOException e) {}
|
||||
if (is != null)
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static Object loadObject(InputStream is) throws JRException {
|
||||
Object obj = null;
|
||||
ObjectInputStream ois = null;
|
||||
try {
|
||||
ois = new ObjectInputStream(is);
|
||||
obj = ois.readObject();
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Error loading object from InputStream", e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new JRException("Class not found when loading object from InputStream", e);
|
||||
} finally {
|
||||
if (ois != null)
|
||||
try {
|
||||
ois.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static Object loadObjectFromLocation(String location) throws JRException {
|
||||
return loadObjectFromLocation(location, null, null, null);
|
||||
}
|
||||
|
||||
public static Object loadObjectFromLocation(String location, ClassLoader classLoader) throws JRException {
|
||||
return loadObjectFromLocation(location, classLoader, null, null);
|
||||
}
|
||||
|
||||
public static Object loadObjectFromLocation(String location, ClassLoader classLoader, URLStreamHandlerFactory urlHandlerFactory, FileResolver fileResolver) throws JRException {
|
||||
URL url = JRResourcesUtil.createURL(location, urlHandlerFactory);
|
||||
if (url != null)
|
||||
return loadObject(url);
|
||||
File file = JRResourcesUtil.resolveFile(location, fileResolver);
|
||||
if (file != null)
|
||||
return loadObject(file);
|
||||
url = JRResourcesUtil.findClassLoaderResource(location, classLoader, JRLoader.class);
|
||||
if (url != null)
|
||||
return loadObject(url);
|
||||
throw new JRException("Could not load object from location : " + location);
|
||||
}
|
||||
|
||||
public static byte[] loadBytes(File file) throws JRException {
|
||||
ByteArrayOutputStream baos = null;
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
baos = new ByteArrayOutputStream();
|
||||
byte[] bytes = new byte[10000];
|
||||
int ln = 0;
|
||||
while ((ln = fis.read(bytes)) > 0)
|
||||
baos.write(bytes, 0, ln);
|
||||
baos.flush();
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Error loading byte data : " + file, e);
|
||||
} finally {
|
||||
if (baos != null)
|
||||
try {
|
||||
baos.close();
|
||||
} catch (IOException e) {}
|
||||
if (fis != null)
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] loadBytes(URL url) throws JRException {
|
||||
ByteArrayOutputStream baos = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = url.openStream();
|
||||
baos = new ByteArrayOutputStream();
|
||||
byte[] bytes = new byte[10000];
|
||||
int ln = 0;
|
||||
while ((ln = is.read(bytes)) > 0)
|
||||
baos.write(bytes, 0, ln);
|
||||
baos.flush();
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Error loading byte data : " + url, e);
|
||||
} finally {
|
||||
if (baos != null)
|
||||
try {
|
||||
baos.close();
|
||||
} catch (IOException e) {}
|
||||
if (is != null)
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] loadBytes(InputStream is) throws JRException {
|
||||
ByteArrayOutputStream baos = null;
|
||||
try {
|
||||
baos = new ByteArrayOutputStream();
|
||||
byte[] bytes = new byte[10000];
|
||||
int ln = 0;
|
||||
while ((ln = is.read(bytes)) > 0)
|
||||
baos.write(bytes, 0, ln);
|
||||
baos.flush();
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Error loading byte data from input stream.", e);
|
||||
} finally {
|
||||
if (baos != null)
|
||||
try {
|
||||
baos.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] loadBytesFromLocation(String location) throws JRException {
|
||||
return loadBytesFromLocation(location, null, null, null);
|
||||
}
|
||||
|
||||
public static byte[] loadBytesFromLocation(String location, ClassLoader classLoader) throws JRException {
|
||||
return loadBytesFromLocation(location, classLoader, null, null);
|
||||
}
|
||||
|
||||
public static byte[] loadBytesFromLocation(String location, ClassLoader classLoader, URLStreamHandlerFactory urlHandlerFactory) throws JRException {
|
||||
return loadBytesFromLocation(location, classLoader, urlHandlerFactory, null);
|
||||
}
|
||||
|
||||
public static byte[] loadBytesFromLocation(String location, ClassLoader classLoader, URLStreamHandlerFactory urlHandlerFactory, FileResolver fileResolver) throws JRException {
|
||||
URL url = JRResourcesUtil.createURL(location, urlHandlerFactory);
|
||||
if (url != null)
|
||||
return loadBytes(url);
|
||||
File file = JRResourcesUtil.resolveFile(location, fileResolver);
|
||||
if (file != null)
|
||||
return loadBytes(file);
|
||||
url = JRResourcesUtil.findClassLoaderResource(location, classLoader, JRLoader.class);
|
||||
if (url != null)
|
||||
return loadBytes(url);
|
||||
throw new JRException("Byte data not found at location : " + location);
|
||||
}
|
||||
|
||||
public static InputStream getLocationInputStream(String location) throws JRException {
|
||||
InputStream is = null;
|
||||
is = getResourceInputStream(location);
|
||||
if (is == null)
|
||||
is = getFileInputStream(location);
|
||||
if (is == null)
|
||||
is = getURLInputStream(location);
|
||||
return is;
|
||||
}
|
||||
|
||||
public static InputStream getFileInputStream(String filename) throws JRException {
|
||||
InputStream is = null;
|
||||
File file = new File(filename);
|
||||
if (file.exists() && file.isFile())
|
||||
try {
|
||||
is = new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new JRException("Error opening file " + filename);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
public static InputStream getResourceInputStream(String resource) {
|
||||
InputStream is = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader != null)
|
||||
is = classLoader.getResourceAsStream(resource);
|
||||
if (is == null) {
|
||||
classLoader = JRLoader.class.getClassLoader();
|
||||
if (classLoader != null)
|
||||
is = classLoader.getResourceAsStream(resource);
|
||||
if (is == null)
|
||||
is = JRProperties.class.getResourceAsStream("/" + resource);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
public static InputStream getURLInputStream(String spec) throws JRException {
|
||||
InputStream is = null;
|
||||
try {
|
||||
URL url = new URL(spec);
|
||||
is = url.openStream();
|
||||
} catch (MalformedURLException e) {
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Error opening URL " + spec);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
}
|
61
hrmsEjb/net/sf/jasperreports/engine/util/JRPenUtil.java
Normal file
61
hrmsEjb/net/sf/jasperreports/engine/util/JRPenUtil.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import net.sf.jasperreports.engine.JRPen;
|
||||
|
||||
public class JRPenUtil {
|
||||
public static void setLinePenFromPen(byte pen, JRPen linePen) {
|
||||
setLinePenFromPen(new Byte(pen), linePen);
|
||||
}
|
||||
|
||||
public static void setLinePenFromPen(Byte pen, JRPen linePen) {
|
||||
if (pen != null)
|
||||
switch (pen.byteValue()) {
|
||||
case 5:
|
||||
linePen.setLineWidth(0.5F);
|
||||
linePen.setLineStyle((byte)0);
|
||||
break;
|
||||
case 1:
|
||||
linePen.setLineWidth(1.0F);
|
||||
linePen.setLineStyle((byte)0);
|
||||
break;
|
||||
case 2:
|
||||
linePen.setLineWidth(2.0F);
|
||||
linePen.setLineStyle((byte)0);
|
||||
break;
|
||||
case 3:
|
||||
linePen.setLineWidth(4.0F);
|
||||
linePen.setLineStyle((byte)0);
|
||||
break;
|
||||
case 4:
|
||||
linePen.setLineWidth(1.0F);
|
||||
linePen.setLineStyle((byte)1);
|
||||
break;
|
||||
case 0:
|
||||
linePen.setLineWidth(0.0F);
|
||||
linePen.setLineStyle((byte)0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte getPenFromLinePen(JRPen linePen) {
|
||||
float lineWidth = linePen.getLineWidth().floatValue();
|
||||
if (lineWidth <= 0.0F)
|
||||
return 0;
|
||||
if (0.0F < lineWidth && lineWidth < 1.0F)
|
||||
return 5;
|
||||
if (1.0F <= lineWidth && lineWidth < 2.0F) {
|
||||
if (linePen.getLineStyle().byteValue() == 1)
|
||||
return 4;
|
||||
return 1;
|
||||
}
|
||||
if (2.0F <= lineWidth && lineWidth < 4.0F)
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
public static Byte getOwnPenFromLinePen(JRPen linePen) {
|
||||
if (linePen.getOwnLineWidth() == null && linePen.getOwnLineStyle() == null)
|
||||
return null;
|
||||
return new Byte(getPenFromLinePen(linePen));
|
||||
}
|
||||
}
|
331
hrmsEjb/net/sf/jasperreports/engine/util/JRProperties.java
Normal file
331
hrmsEjb/net/sf/jasperreports/engine/util/JRProperties.java
Normal file
@@ -0,0 +1,331 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.JRPropertiesHolder;
|
||||
import net.sf.jasperreports.engine.JRPropertiesMap;
|
||||
import net.sf.jasperreports.engine.JRRuntimeException;
|
||||
|
||||
public class JRProperties {
|
||||
protected static final String DEFAULT_PROPERTIES_FILE = "jasperreports.properties";
|
||||
|
||||
public static final String PROPERTY_PREFIX = "net.sf.jasperreports.";
|
||||
|
||||
public static final String PROPERTIES_FILE = "net.sf.jasperreports.properties";
|
||||
|
||||
public static final String COMPILER_CLASS = "net.sf.jasperreports.compiler.class";
|
||||
|
||||
public static final String COMPILER_XML_VALIDATION = "net.sf.jasperreports.compiler.xml.validation";
|
||||
|
||||
public static final String COMPILER_KEEP_JAVA_FILE = "net.sf.jasperreports.compiler.keep.java.file";
|
||||
|
||||
public static final String COMPILER_TEMP_DIR = "net.sf.jasperreports.compiler.temp.dir";
|
||||
|
||||
public static final String COMPILER_CLASSPATH = "net.sf.jasperreports.compiler.classpath";
|
||||
|
||||
public static final String EXPORT_XML_VALIDATION = "net.sf.jasperreports.export.xml.validation";
|
||||
|
||||
public static final String PDF_FONT_FILES_PREFIX = "net.sf.jasperreports.export.pdf.font.";
|
||||
|
||||
public static final String PDF_FONT_DIRS_PREFIX = "net.sf.jasperreports.export.pdf.fontdir.";
|
||||
|
||||
public static final String QUERY_EXECUTER_FACTORY_PREFIX = "net.sf.jasperreports.query.executer.factory.";
|
||||
|
||||
public static final String SUBREPORT_RUNNER_FACTORY = "net.sf.jasperreports.subreport.runner.factory";
|
||||
|
||||
public static final String PDF_FORCE_LINEBREAK_POLICY = "net.sf.jasperreports.export.pdf.force.linebreak.policy";
|
||||
|
||||
protected static Properties props;
|
||||
|
||||
protected static Properties savedProps;
|
||||
|
||||
static {
|
||||
initProperties();
|
||||
}
|
||||
|
||||
protected static void initProperties() {
|
||||
try {
|
||||
Properties defaults = getDefaults();
|
||||
String propFile = getSystemProperty("net.sf.jasperreports.properties");
|
||||
if (propFile == null) {
|
||||
props = loadProperties("jasperreports.properties", defaults);
|
||||
if (props == null)
|
||||
props = new Properties(defaults);
|
||||
} else {
|
||||
props = loadProperties(propFile, defaults);
|
||||
if (props == null)
|
||||
throw new JRRuntimeException("Could not load properties file \"" + propFile + "\"");
|
||||
}
|
||||
loadSystemProperties();
|
||||
} catch (JRException e) {
|
||||
throw new JRRuntimeException("Error loading the properties", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void loadSystemProperties() {
|
||||
loadSystemProperty("jasper.reports.compiler.class", "net.sf.jasperreports.compiler.class");
|
||||
loadSystemProperty("jasper.reports.compile.xml.validation", "net.sf.jasperreports.compiler.xml.validation");
|
||||
loadSystemProperty("jasper.reports.export.xml.validation", "net.sf.jasperreports.export.xml.validation");
|
||||
loadSystemProperty("jasper.reports.compile.keep.java.file", "net.sf.jasperreports.compiler.keep.java.file");
|
||||
loadSystemProperty("jasper.reports.compile.temp", "net.sf.jasperreports.compiler.temp.dir");
|
||||
loadSystemProperty("jasper.reports.compile.class.path", "net.sf.jasperreports.compiler.classpath");
|
||||
}
|
||||
|
||||
protected static Properties getDefaults() throws JRException {
|
||||
Properties defaults = new Properties();
|
||||
InputStream is = JRProperties.class.getResourceAsStream("/default.jasperreports.properties");
|
||||
if (is == null)
|
||||
throw new JRException("Default properties file not found.");
|
||||
try {
|
||||
defaults.load(is);
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Failed to load default properties.", e);
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
String userDir = getSystemProperty("user.dir");
|
||||
if (userDir != null)
|
||||
defaults.setProperty("net.sf.jasperreports.compiler.temp.dir", userDir);
|
||||
String classPath = getSystemProperty("java.class.path");
|
||||
if (classPath != null)
|
||||
defaults.setProperty("net.sf.jasperreports.compiler.classpath", classPath);
|
||||
return defaults;
|
||||
}
|
||||
|
||||
protected static String getSystemProperty(String propertyName) {
|
||||
try {
|
||||
return System.getProperty(propertyName);
|
||||
} catch (SecurityException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static void loadSystemProperty(String sysKey, String propKey) {
|
||||
String val = getSystemProperty(sysKey);
|
||||
if (val != null)
|
||||
props.setProperty(propKey, val);
|
||||
}
|
||||
|
||||
public static Properties loadProperties(String name, Properties defaults) throws JRException {
|
||||
Properties properties = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = JRLoader.getLocationInputStream(name);
|
||||
} catch (SecurityException e) {}
|
||||
if (is != null) {
|
||||
properties = new Properties(defaults);
|
||||
try {
|
||||
properties.load(is);
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Failed to load properties file \"" + name + "\"", e);
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
public static String getProperty(String key) {
|
||||
return props.getProperty(key);
|
||||
}
|
||||
|
||||
public static boolean getBooleanProperty(String key) {
|
||||
return asBoolean(props.getProperty(key));
|
||||
}
|
||||
|
||||
public static int getIntegerProperty(String key) {
|
||||
return asInteger(props.getProperty(key));
|
||||
}
|
||||
|
||||
public static boolean asBoolean(String value) {
|
||||
return Boolean.valueOf(value).booleanValue();
|
||||
}
|
||||
|
||||
public static int asInteger(String value) {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
|
||||
public static void setProperty(String key, String value) {
|
||||
props.setProperty(key, value);
|
||||
}
|
||||
|
||||
public static void setProperty(String key, boolean value) {
|
||||
props.setProperty(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public static void backupProperties() {
|
||||
savedProps = (Properties)props.clone();
|
||||
}
|
||||
|
||||
public static void restoreProperties() {
|
||||
if (savedProps != null)
|
||||
try {
|
||||
props.clear();
|
||||
props.putAll(savedProps);
|
||||
} finally {
|
||||
savedProps = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PropertySuffix {
|
||||
protected final String key;
|
||||
|
||||
protected final String suffix;
|
||||
|
||||
protected final String value;
|
||||
|
||||
public PropertySuffix(String key, String suffix, String value) {
|
||||
this.key = key;
|
||||
this.suffix = suffix;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getSuffix() {
|
||||
return this.suffix;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
public static List getProperties(String prefix) {
|
||||
int prefixLength = prefix.length();
|
||||
List values = new ArrayList();
|
||||
for (Enumeration names = props.propertyNames(); names.hasMoreElements(); ) {
|
||||
String name = (String)names.nextElement();
|
||||
if (name.startsWith(prefix)) {
|
||||
String suffix = name.substring(prefixLength);
|
||||
String value = props.getProperty(name);
|
||||
values.add(new PropertySuffix(name, suffix, value));
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static List getProperties(JRPropertiesHolder propertiesHolder, String prefix) {
|
||||
return getProperties(getOwnProperties(propertiesHolder), prefix);
|
||||
}
|
||||
|
||||
public static List getProperties(JRPropertiesMap propertiesMap, String prefix) {
|
||||
int prefixLength = prefix.length();
|
||||
List values = new ArrayList();
|
||||
if (propertiesMap != null) {
|
||||
String[] propertyNames = propertiesMap.getPropertyNames();
|
||||
for (int i = 0; i < propertyNames.length; i++) {
|
||||
String name = propertyNames[i];
|
||||
if (name.startsWith(prefix)) {
|
||||
String suffix = name.substring(prefixLength);
|
||||
String value = propertiesMap.getProperty(name);
|
||||
values.add(new PropertySuffix(name, suffix, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static String getProperty(JRPropertiesHolder propertiesHolder, String key) {
|
||||
String value = null;
|
||||
while (propertiesHolder != null && value == null) {
|
||||
if (propertiesHolder.hasProperties())
|
||||
value = propertiesHolder.getPropertiesMap().getProperty(key);
|
||||
propertiesHolder = propertiesHolder.getParentProperties();
|
||||
}
|
||||
if (value == null)
|
||||
value = props.getProperty(key);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static String getProperty(JRPropertiesMap propertiesMap, String key) {
|
||||
String value = null;
|
||||
if (propertiesMap != null)
|
||||
value = propertiesMap.getProperty(key);
|
||||
if (value == null)
|
||||
value = props.getProperty(key);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static boolean getBooleanProperty(JRPropertiesHolder propertiesHolder, String key, boolean defaultValue) {
|
||||
String value = getProperty(propertiesHolder, key);
|
||||
return (value == null) ? defaultValue : asBoolean(value);
|
||||
}
|
||||
|
||||
public static boolean getBooleanProperty(JRPropertiesMap propertiesMap, String key, boolean defaultValue) {
|
||||
String value = getProperty(propertiesMap, key);
|
||||
return (value == null) ? defaultValue : asBoolean(value);
|
||||
}
|
||||
|
||||
public static int getIntegerProperty(JRPropertiesHolder propertiesHolder, String key, int defaultValue) {
|
||||
String value = getProperty(propertiesHolder, key);
|
||||
return (value == null) ? defaultValue : asInteger(value);
|
||||
}
|
||||
|
||||
public static int getIntegerProperty(JRPropertiesMap propertiesMap, String key, int defaultValue) {
|
||||
String value = getProperty(propertiesMap, key);
|
||||
return (value == null) ? defaultValue : asInteger(value);
|
||||
}
|
||||
|
||||
public static int getIntegerProperty(String key, int defaultValue) {
|
||||
String value = getProperty(key);
|
||||
return (value == null) ? defaultValue : asInteger(value);
|
||||
}
|
||||
|
||||
public static long asLong(String value) {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
|
||||
public static long getLongProperty(String key) {
|
||||
return asLong(props.getProperty(key));
|
||||
}
|
||||
|
||||
public static long getLongProperty(JRPropertiesMap propertiesMap, String key, int defaultValue) {
|
||||
String value = getProperty(propertiesMap, key);
|
||||
return (value == null) ? defaultValue : asLong(value);
|
||||
}
|
||||
|
||||
protected static JRPropertiesMap getOwnProperties(JRPropertiesHolder propertiesHolder) {
|
||||
return propertiesHolder.hasProperties() ? propertiesHolder.getPropertiesMap() : null;
|
||||
}
|
||||
|
||||
public static void transferProperties(JRPropertiesHolder source, JRPropertiesHolder destination, String tranferPropertiesPrefix) {
|
||||
if (!source.hasProperties())
|
||||
return;
|
||||
transfer(source.getPropertiesMap(), destination, tranferPropertiesPrefix);
|
||||
}
|
||||
|
||||
public static void transferProperties(JRPropertiesMap source, JRPropertiesHolder destination, String tranferPropertiesPrefix) {
|
||||
if (source == null || !source.hasProperties())
|
||||
return;
|
||||
transfer(source, destination, tranferPropertiesPrefix);
|
||||
}
|
||||
|
||||
protected static void transfer(JRPropertiesMap source, JRPropertiesHolder destination, String tranferPropertiesPrefix) {
|
||||
List transferPrefixProps = getProperties(tranferPropertiesPrefix);
|
||||
for (Iterator prefixIt = transferPrefixProps.iterator(); prefixIt.hasNext(); ) {
|
||||
PropertySuffix transferPrefixProp = prefixIt.next();
|
||||
String transferPrefix = transferPrefixProp.getValue();
|
||||
if (transferPrefix != null && transferPrefix.length() > 0) {
|
||||
List transferProps = getProperties(source, transferPrefix);
|
||||
for (Iterator propIt = transferProps.iterator(); propIt.hasNext(); ) {
|
||||
PropertySuffix property = propIt.next();
|
||||
String value = property.getValue();
|
||||
destination.getPropertiesMap().setProperty(property.getKey(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
public interface JRQueryChunkHandler {
|
||||
void handleTextChunk(String paramString);
|
||||
|
||||
void handleParameterChunk(String paramString);
|
||||
|
||||
void handleParameterClauseChunk(String paramString);
|
||||
|
||||
void handleClauseChunk(String[] paramArrayOfString);
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.query.JRQueryExecuterFactory;
|
||||
|
||||
public class JRQueryExecuterUtils {
|
||||
private static final JRSingletonCache cache = new JRSingletonCache(JRQueryExecuterFactory.class);
|
||||
|
||||
public static JRQueryExecuterFactory getQueryExecuterFactory(String language) throws JRException {
|
||||
String factoryClassName = JRProperties.getProperty("net.sf.jasperreports.query.executer.factory." + language);
|
||||
if (factoryClassName == null)
|
||||
throw new JRException("No query executer factory class registered for " + language + " queries. " + "Create a propery named " + "net.sf.jasperreports.query.executer.factory." + language + ".");
|
||||
return (JRQueryExecuterFactory)cache.getCachedInstance(factoryClassName);
|
||||
}
|
||||
}
|
168
hrmsEjb/net/sf/jasperreports/engine/util/JRQueryParser.java
Normal file
168
hrmsEjb/net/sf/jasperreports/engine/util/JRQueryParser.java
Normal file
@@ -0,0 +1,168 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
import net.sf.jasperreports.engine.JRQueryChunk;
|
||||
import net.sf.jasperreports.engine.JRRuntimeException;
|
||||
|
||||
public class JRQueryParser {
|
||||
private static final JRQueryParser singleton = new JRQueryParser();
|
||||
|
||||
public static JRQueryParser instance() {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
public void parse(String text, JRQueryChunkHandler chunkHandler) {
|
||||
if (text != null) {
|
||||
StringBuffer textChunk = new StringBuffer();
|
||||
StringTokenizer tkzer = new StringTokenizer(text, "$", true);
|
||||
boolean wasDelim = false;
|
||||
while (tkzer.hasMoreTokens()) {
|
||||
String token = tkzer.nextToken();
|
||||
if (token.equals("$")) {
|
||||
if (wasDelim)
|
||||
textChunk.append("$");
|
||||
wasDelim = true;
|
||||
continue;
|
||||
}
|
||||
if (token.startsWith("P{") && wasDelim) {
|
||||
int end = token.indexOf('}');
|
||||
if (end > 0) {
|
||||
if (textChunk.length() > 0)
|
||||
chunkHandler.handleTextChunk(textChunk.toString());
|
||||
String parameterChunk = token.substring(2, end);
|
||||
chunkHandler.handleParameterChunk(parameterChunk);
|
||||
textChunk = new StringBuffer(token.substring(end + 1));
|
||||
} else {
|
||||
if (wasDelim)
|
||||
textChunk.append("$");
|
||||
textChunk.append(token);
|
||||
}
|
||||
} else if (token.startsWith("P!{") && wasDelim) {
|
||||
int end = token.indexOf('}');
|
||||
if (end > 0) {
|
||||
if (textChunk.length() > 0)
|
||||
chunkHandler.handleTextChunk(textChunk.toString());
|
||||
String parameterClauseChunk = token.substring(3, end);
|
||||
chunkHandler.handleParameterClauseChunk(parameterClauseChunk);
|
||||
textChunk = new StringBuffer(token.substring(end + 1));
|
||||
} else {
|
||||
if (wasDelim)
|
||||
textChunk.append("$");
|
||||
textChunk.append(token);
|
||||
}
|
||||
} else if (token.startsWith("X{") && wasDelim) {
|
||||
int end = token.indexOf('}');
|
||||
if (end > 0) {
|
||||
if (textChunk.length() > 0)
|
||||
chunkHandler.handleTextChunk(textChunk.toString());
|
||||
String clauseChunk = token.substring(2, end);
|
||||
String[] tokens = parseClause(clauseChunk);
|
||||
chunkHandler.handleClauseChunk(tokens);
|
||||
textChunk = new StringBuffer(token.substring(end + 1));
|
||||
} else {
|
||||
if (wasDelim)
|
||||
textChunk.append("$");
|
||||
textChunk.append(token);
|
||||
}
|
||||
} else {
|
||||
if (wasDelim)
|
||||
textChunk.append("$");
|
||||
textChunk.append(token);
|
||||
}
|
||||
wasDelim = false;
|
||||
}
|
||||
if (wasDelim)
|
||||
textChunk.append("$");
|
||||
if (textChunk.length() > 0)
|
||||
chunkHandler.handleTextChunk(textChunk.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected String[] parseClause(String clauseChunk) {
|
||||
List tokens = new ArrayList();
|
||||
boolean wasClauseToken = false;
|
||||
String separator = determineClauseTokenSeparator(clauseChunk);
|
||||
StringTokenizer tokenizer = new StringTokenizer(clauseChunk, separator, true);
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String token = tokenizer.nextToken();
|
||||
if (token.equals(separator)) {
|
||||
if (!wasClauseToken)
|
||||
tokens.add("");
|
||||
wasClauseToken = false;
|
||||
continue;
|
||||
}
|
||||
tokens.add(token);
|
||||
wasClauseToken = true;
|
||||
}
|
||||
if (!wasClauseToken)
|
||||
tokens.add("");
|
||||
return tokens.<String>toArray(new String[tokens.size()]);
|
||||
}
|
||||
|
||||
protected String determineClauseTokenSeparator(String clauseChunk) {
|
||||
String allSeparators = getTokenSeparators();
|
||||
if (allSeparators == null || allSeparators.length() == 0)
|
||||
throw new JRRuntimeException("No token separators configured");
|
||||
int firstSepIdx = 0;
|
||||
int clauseLenght = clauseChunk.length();
|
||||
for (int idx = 0; idx < clauseLenght; idx++) {
|
||||
int sepIdx = allSeparators.indexOf(clauseChunk.charAt(idx));
|
||||
if (sepIdx >= 0) {
|
||||
firstSepIdx = sepIdx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return String.valueOf(allSeparators.charAt(firstSepIdx));
|
||||
}
|
||||
|
||||
protected String getTokenSeparators() {
|
||||
return JRProperties.getProperty("net.sf.jasperreports.query.chunk.token.separators");
|
||||
}
|
||||
|
||||
public String asText(JRQueryChunk[] chunks) {
|
||||
String text = "";
|
||||
if (chunks != null && chunks.length > 0) {
|
||||
StringBuffer sbuffer = new StringBuffer();
|
||||
for (int i = 0; i < chunks.length; i++) {
|
||||
JRQueryChunk queryChunk = chunks[i];
|
||||
switch (queryChunk.getType()) {
|
||||
case 2:
|
||||
sbuffer.append("$P{");
|
||||
sbuffer.append(queryChunk.getText());
|
||||
sbuffer.append("}");
|
||||
break;
|
||||
case 3:
|
||||
sbuffer.append("$P!{");
|
||||
sbuffer.append(queryChunk.getText());
|
||||
sbuffer.append("}");
|
||||
break;
|
||||
case 4:
|
||||
sbuffer.append("$X{");
|
||||
sbuffer.append(queryChunk.getText());
|
||||
sbuffer.append("}");
|
||||
break;
|
||||
default:
|
||||
sbuffer.append(queryChunk.getText());
|
||||
break;
|
||||
}
|
||||
}
|
||||
text = sbuffer.toString();
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public String asClauseText(String[] tokens) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (tokens != null && tokens.length > 0)
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
if (i > 0)
|
||||
sb.append(',');
|
||||
String token = tokens[i];
|
||||
if (token != null)
|
||||
sb.append(token);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
223
hrmsEjb/net/sf/jasperreports/engine/util/JRResourcesUtil.java
Normal file
223
hrmsEjb/net/sf/jasperreports/engine/util/JRResourcesUtil.java
Normal file
@@ -0,0 +1,223 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLStreamHandler;
|
||||
import java.net.URLStreamHandlerFactory;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class JRResourcesUtil {
|
||||
private static FileResolver globalFileResolver;
|
||||
|
||||
private static ThreadLocalStack localFileResolverStack = new ThreadLocalStack();
|
||||
|
||||
private static URLStreamHandlerFactory globalURLHandlerFactory;
|
||||
|
||||
private static ThreadLocalStack localURLHandlerFactoryStack = new ThreadLocalStack();
|
||||
|
||||
private static ClassLoader globalClassLoader;
|
||||
|
||||
private static ThreadLocalStack localClassLoaderStack = new ThreadLocalStack();
|
||||
|
||||
public static URL createURL(String spec, URLStreamHandlerFactory urlHandlerFactory) {
|
||||
URL uRL;
|
||||
URLStreamHandler handler = getURLHandler(spec, urlHandlerFactory);
|
||||
try {
|
||||
if (handler == null) {
|
||||
uRL = new URL(spec);
|
||||
} else {
|
||||
uRL = new URL(null, spec, handler);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
uRL = null;
|
||||
}
|
||||
return uRL;
|
||||
}
|
||||
|
||||
public static URLStreamHandler getURLHandler(String spec, URLStreamHandlerFactory urlHandlerFactory) {
|
||||
urlHandlerFactory = getURLHandlerFactory(urlHandlerFactory);
|
||||
URLStreamHandler handler = null;
|
||||
if (urlHandlerFactory != null) {
|
||||
String protocol = getURLProtocol(spec);
|
||||
if (protocol != null)
|
||||
handler = urlHandlerFactory.createURLStreamHandler(protocol);
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
private static String getURLProtocol(String spec) {
|
||||
String protocol = null;
|
||||
spec = spec.trim();
|
||||
int colon = spec.indexOf(':');
|
||||
if (colon > 0) {
|
||||
String proto = spec.substring(0, colon);
|
||||
if (protocolValid(proto))
|
||||
protocol = proto;
|
||||
}
|
||||
return protocol;
|
||||
}
|
||||
|
||||
private static boolean protocolValid(String protocol) {
|
||||
int length = protocol.length();
|
||||
if (length < 1)
|
||||
return false;
|
||||
if (!Character.isLetter(protocol.charAt(0)))
|
||||
return false;
|
||||
for (int i = 1; i < length; i++) {
|
||||
char c = protocol.charAt(i);
|
||||
if (!Character.isLetterOrDigit(c) && c != '+' && c != '-' && c != '.')
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static FileResolver getFileResolver(FileResolver fileResolver) {
|
||||
if (fileResolver == null) {
|
||||
fileResolver = getThreadFileResolver();
|
||||
if (fileResolver == null)
|
||||
fileResolver = globalFileResolver;
|
||||
}
|
||||
return fileResolver;
|
||||
}
|
||||
|
||||
public static FileResolver getGlobalFileResolver() {
|
||||
return globalFileResolver;
|
||||
}
|
||||
|
||||
public static FileResolver getThreadFileResolver() {
|
||||
return (FileResolver)localFileResolverStack.top();
|
||||
}
|
||||
|
||||
public static void setThreadFileResolver(FileResolver fileResolver) {
|
||||
localFileResolverStack.push(fileResolver);
|
||||
}
|
||||
|
||||
public static void resetThreadFileResolver() {
|
||||
localFileResolverStack.pop();
|
||||
}
|
||||
|
||||
public static void setGlobalFileResolver(FileResolver fileResolver) {
|
||||
globalFileResolver = fileResolver;
|
||||
}
|
||||
|
||||
public static File resolveFile(String location, FileResolver fileResolver) {
|
||||
fileResolver = getFileResolver(fileResolver);
|
||||
if (fileResolver != null)
|
||||
return fileResolver.resolveFile(location);
|
||||
File file = new File(location);
|
||||
if (file.exists() && file.isFile())
|
||||
return file;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static URLStreamHandlerFactory getURLHandlerFactory(URLStreamHandlerFactory urlHandlerFactory) {
|
||||
if (urlHandlerFactory == null) {
|
||||
urlHandlerFactory = getThreadURLStreamHandlerFactory();
|
||||
if (urlHandlerFactory == null)
|
||||
urlHandlerFactory = globalURLHandlerFactory;
|
||||
}
|
||||
return urlHandlerFactory;
|
||||
}
|
||||
|
||||
public static URLStreamHandlerFactory getGlobalURLStreamHandlerFactory() {
|
||||
return globalURLHandlerFactory;
|
||||
}
|
||||
|
||||
public static URLStreamHandlerFactory getThreadURLStreamHandlerFactory() {
|
||||
return (URLStreamHandlerFactory)localURLHandlerFactoryStack.top();
|
||||
}
|
||||
|
||||
public static void setThreadURLHandlerFactory(URLStreamHandlerFactory urlHandlerFactory) {
|
||||
localURLHandlerFactoryStack.push(urlHandlerFactory);
|
||||
}
|
||||
|
||||
public static void resetThreadURLHandlerFactory() {
|
||||
localURLHandlerFactoryStack.pop();
|
||||
}
|
||||
|
||||
public static void setGlobalURLHandlerFactory(URLStreamHandlerFactory urlHandlerFactory) {
|
||||
globalURLHandlerFactory = urlHandlerFactory;
|
||||
}
|
||||
|
||||
public static ClassLoader getClassLoader(ClassLoader classLoader) {
|
||||
if (classLoader == null) {
|
||||
classLoader = getThreadClassLoader();
|
||||
if (classLoader == null)
|
||||
classLoader = globalClassLoader;
|
||||
}
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
public static ClassLoader getGlobalClassLoader() {
|
||||
return globalClassLoader;
|
||||
}
|
||||
|
||||
public static ClassLoader getThreadClassLoader() {
|
||||
return (ClassLoader)localClassLoaderStack.top();
|
||||
}
|
||||
|
||||
public static void setThreadClassLoader(ClassLoader classLoader) {
|
||||
localClassLoaderStack.push(classLoader);
|
||||
}
|
||||
|
||||
public static void resetClassLoader() {
|
||||
localClassLoaderStack.pop();
|
||||
}
|
||||
|
||||
public static void setGlobalClassLoader(ClassLoader classLoader) {
|
||||
globalClassLoader = classLoader;
|
||||
}
|
||||
|
||||
public static URL findClassLoaderResource(String location, ClassLoader classLoader, Class clazz) {
|
||||
classLoader = getClassLoader(classLoader);
|
||||
URL url = null;
|
||||
if (classLoader != null)
|
||||
url = classLoader.getResource(location);
|
||||
if (url == null) {
|
||||
classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader != null)
|
||||
url = classLoader.getResource(location);
|
||||
if (url == null) {
|
||||
classLoader = clazz.getClassLoader();
|
||||
if (classLoader == null) {
|
||||
url = clazz.getResource("/" + location);
|
||||
} else {
|
||||
url = classLoader.getResource(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
public static ResourceBundle loadResourceBundle(String baseName, Locale locale) {
|
||||
return loadResourceBundle(baseName, locale, null);
|
||||
}
|
||||
|
||||
public static ResourceBundle loadResourceBundle(String baseName, Locale locale, ClassLoader classLoader) {
|
||||
ResourceBundle resourceBundle = null;
|
||||
classLoader = getClassLoader(classLoader);
|
||||
if (classLoader != null)
|
||||
try {
|
||||
resourceBundle = ResourceBundle.getBundle(baseName, locale, classLoader);
|
||||
} catch (MissingResourceException e) {}
|
||||
if (resourceBundle == null) {
|
||||
classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader != null)
|
||||
try {
|
||||
resourceBundle = ResourceBundle.getBundle(baseName, locale, classLoader);
|
||||
} catch (MissingResourceException e) {}
|
||||
}
|
||||
if (resourceBundle == null) {
|
||||
classLoader = JRClassLoader.class.getClassLoader();
|
||||
if (classLoader == null) {
|
||||
resourceBundle = ResourceBundle.getBundle(baseName, locale);
|
||||
} else {
|
||||
resourceBundle = ResourceBundle.getBundle(baseName, locale, classLoader);
|
||||
}
|
||||
}
|
||||
return resourceBundle;
|
||||
}
|
||||
}
|
76
hrmsEjb/net/sf/jasperreports/engine/util/JRSaver.java
Normal file
76
hrmsEjb/net/sf/jasperreports/engine/util/JRSaver.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
|
||||
public class JRSaver {
|
||||
public static void saveObject(Object obj, String fileName) throws JRException {
|
||||
saveObject(obj, new File(fileName));
|
||||
}
|
||||
|
||||
public static void saveObject(Object obj, File file) throws JRException {
|
||||
FileOutputStream fos = null;
|
||||
ObjectOutputStream oos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||
oos = new ObjectOutputStream(bos);
|
||||
oos.writeObject(obj);
|
||||
oos.flush();
|
||||
bos.flush();
|
||||
fos.flush();
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Error saving file : " + file, e);
|
||||
} finally {
|
||||
if (oos != null)
|
||||
try {
|
||||
oos.close();
|
||||
} catch (IOException e) {}
|
||||
if (fos != null)
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveObject(Object obj, OutputStream os) throws JRException {
|
||||
ObjectOutputStream oos = null;
|
||||
try {
|
||||
oos = new ObjectOutputStream(os);
|
||||
oos.writeObject(obj);
|
||||
oos.flush();
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Error saving object to OutputStream", e);
|
||||
} finally {
|
||||
if (oos != null)
|
||||
try {
|
||||
oos.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveClassSource(String source, File file) throws JRException {
|
||||
FileWriter fwriter = null;
|
||||
try {
|
||||
fwriter = new FileWriter(file);
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(fwriter);
|
||||
bufferedWriter.write(source);
|
||||
bufferedWriter.flush();
|
||||
fwriter.flush();
|
||||
} catch (IOException e) {
|
||||
throw new JRException("Error saving expressions class file : " + file, e);
|
||||
} finally {
|
||||
if (fwriter != null)
|
||||
try {
|
||||
fwriter.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.util.Map;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import org.apache.commons.collections.ReferenceMap;
|
||||
|
||||
public class JRSingletonCache {
|
||||
private static final Object CONTEXT_KEY_NULL = new Object();
|
||||
|
||||
private final ReferenceMap cache;
|
||||
|
||||
private final Class itf;
|
||||
|
||||
public JRSingletonCache(Class itf) {
|
||||
this.cache = new ReferenceMap(2, 1);
|
||||
this.itf = itf;
|
||||
}
|
||||
|
||||
public synchronized Object getCachedInstance(String className) throws JRException {
|
||||
Map contextCache = getContextInstanceCache();
|
||||
Object instance = contextCache.get(className);
|
||||
if (instance == null) {
|
||||
instance = createInstance(className);
|
||||
contextCache.put(className, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
protected Object createInstance(String className) throws JRException {
|
||||
try {
|
||||
Class clazz = JRClassLoader.loadClassForName(className);
|
||||
if (this.itf != null && !this.itf.isAssignableFrom(clazz))
|
||||
throw new JRException("Class \"" + className + "\" should be compatible with \"" + this.itf.getName() + "\"");
|
||||
return clazz.newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new JRException("Class " + className + " not found.", e);
|
||||
} catch (InstantiationException e) {
|
||||
throw new JRException("Error instantiating class " + className + ".", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new JRException("Error instantiating class " + className + ".", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected Map getContextInstanceCache() {
|
||||
ReferenceMap referenceMap;
|
||||
Object contextKey = getContextKey();
|
||||
Map contextCache = (Map)this.cache.get(contextKey);
|
||||
if (contextCache == null) {
|
||||
referenceMap = new ReferenceMap();
|
||||
this.cache.put(contextKey, referenceMap);
|
||||
}
|
||||
return (Map)referenceMap;
|
||||
}
|
||||
|
||||
protected Object getContextKey() {
|
||||
Object key = Thread.currentThread().getContextClassLoader();
|
||||
if (key == null)
|
||||
key = CONTEXT_KEY_NULL;
|
||||
return key;
|
||||
}
|
||||
}
|
176
hrmsEjb/net/sf/jasperreports/engine/util/JRStringUtil.java
Normal file
176
hrmsEjb/net/sf/jasperreports/engine/util/JRStringUtil.java
Normal file
@@ -0,0 +1,176 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
public class JRStringUtil {
|
||||
public static String replaceCRwithLF(String text) {
|
||||
if (text != null) {
|
||||
int length = text.length();
|
||||
char[] chars = text.toCharArray();
|
||||
int r = 0;
|
||||
boolean dirty = false;
|
||||
for (int i = 0; i < length; i++) {
|
||||
char ch = chars[i];
|
||||
if (ch == '\r') {
|
||||
dirty = true;
|
||||
if (i + 1 < length && chars[i + 1] == '\n') {
|
||||
r++;
|
||||
} else {
|
||||
chars[i - r] = '\n';
|
||||
}
|
||||
} else {
|
||||
chars[i - r] = ch;
|
||||
}
|
||||
}
|
||||
return dirty ? new String(chars, 0, length - r) : text;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String xmlEncode(String text) {
|
||||
int length = text.length();
|
||||
if (text != null && length > 0) {
|
||||
StringBuffer ret = new StringBuffer(length * 12 / 10);
|
||||
int last = 0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = text.charAt(i);
|
||||
switch (c) {
|
||||
case '&':
|
||||
if (last < i)
|
||||
ret.append(text.substring(last, i));
|
||||
last = i + 1;
|
||||
ret.append("&");
|
||||
break;
|
||||
case '>':
|
||||
if (last < i)
|
||||
ret.append(text.substring(last, i));
|
||||
last = i + 1;
|
||||
ret.append(">");
|
||||
break;
|
||||
case '<':
|
||||
if (last < i)
|
||||
ret.append(text.substring(last, i));
|
||||
last = i + 1;
|
||||
ret.append("<");
|
||||
break;
|
||||
case '"':
|
||||
if (last < i)
|
||||
ret.append(text.substring(last, i));
|
||||
last = i + 1;
|
||||
ret.append(""");
|
||||
break;
|
||||
case '\'':
|
||||
if (last < i)
|
||||
ret.append(text.substring(last, i));
|
||||
last = i + 1;
|
||||
ret.append("'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (last < length)
|
||||
ret.append(text.substring(last));
|
||||
return ret.toString();
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public static String htmlEncode(String text) {
|
||||
int length = text.length();
|
||||
if (text != null && length > 0) {
|
||||
StringBuffer ret = new StringBuffer(length * 12 / 10);
|
||||
boolean isEncodeSpace = true;
|
||||
int last = 0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = text.charAt(i);
|
||||
switch (c) {
|
||||
case ' ':
|
||||
if (isEncodeSpace) {
|
||||
if (last < i)
|
||||
ret.append(text.substring(last, i));
|
||||
last = i + 1;
|
||||
ret.append(" ");
|
||||
isEncodeSpace = false;
|
||||
break;
|
||||
}
|
||||
isEncodeSpace = true;
|
||||
break;
|
||||
case '&':
|
||||
if (last < i)
|
||||
ret.append(text.substring(last, i));
|
||||
last = i + 1;
|
||||
ret.append("&");
|
||||
isEncodeSpace = false;
|
||||
break;
|
||||
case '>':
|
||||
if (last < i)
|
||||
ret.append(text.substring(last, i));
|
||||
last = i + 1;
|
||||
ret.append(">");
|
||||
isEncodeSpace = false;
|
||||
break;
|
||||
case '<':
|
||||
if (last < i)
|
||||
ret.append(text.substring(last, i));
|
||||
last = i + 1;
|
||||
ret.append("<");
|
||||
isEncodeSpace = false;
|
||||
break;
|
||||
case '"':
|
||||
if (last < i)
|
||||
ret.append(text.substring(last, i));
|
||||
last = i + 1;
|
||||
ret.append(""");
|
||||
isEncodeSpace = false;
|
||||
break;
|
||||
case '\n':
|
||||
if (last < i)
|
||||
ret.append(text.substring(last, i));
|
||||
last = i + 1;
|
||||
ret.append("<br/>");
|
||||
isEncodeSpace = false;
|
||||
break;
|
||||
default:
|
||||
isEncodeSpace = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (last < length)
|
||||
ret.append(text.substring(last));
|
||||
return ret.toString();
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public static String getLiteral(String name) {
|
||||
if (isValidLiteral(name))
|
||||
return name;
|
||||
StringBuffer buffer = new StringBuffer(name.length() + 5);
|
||||
char[] literalChars = new char[name.length()];
|
||||
name.getChars(0, literalChars.length, literalChars, 0);
|
||||
for (int i = 0; i < literalChars.length; i++) {
|
||||
if (i == 0 && !Character.isJavaIdentifierStart(literalChars[i])) {
|
||||
buffer.append(literalChars[i]);
|
||||
} else if (i != 0 && !Character.isJavaIdentifierPart(literalChars[i])) {
|
||||
buffer.append(literalChars[i]);
|
||||
} else {
|
||||
buffer.append(literalChars[i]);
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private static boolean isValidLiteral(String literal) {
|
||||
boolean result = true;
|
||||
char[] literalChars = new char[literal.length()];
|
||||
literal.getChars(0, literalChars.length, literalChars, 0);
|
||||
for (int i = 0; i < literalChars.length; i++) {
|
||||
if (i == 0 && !Character.isJavaIdentifierStart(literalChars[i])) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
if (i != 0 && !Character.isJavaIdentifierPart(literalChars[i])) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
785
hrmsEjb/net/sf/jasperreports/engine/util/JRStyleResolver.java
Normal file
785
hrmsEjb/net/sf/jasperreports/engine/util/JRStyleResolver.java
Normal file
@@ -0,0 +1,785 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import net.sf.jasperreports.charts.JRCategoryAxisFormat;
|
||||
import net.sf.jasperreports.charts.JRTimeAxisFormat;
|
||||
import net.sf.jasperreports.charts.JRValueAxisFormat;
|
||||
import net.sf.jasperreports.charts.JRXAxisFormat;
|
||||
import net.sf.jasperreports.charts.JRYAxisFormat;
|
||||
import net.sf.jasperreports.engine.JRAlignment;
|
||||
import net.sf.jasperreports.engine.JRChart;
|
||||
import net.sf.jasperreports.engine.JRChartPlot;
|
||||
import net.sf.jasperreports.engine.JRCommonElement;
|
||||
import net.sf.jasperreports.engine.JRCommonGraphicElement;
|
||||
import net.sf.jasperreports.engine.JRCommonImage;
|
||||
import net.sf.jasperreports.engine.JRCommonRectangle;
|
||||
import net.sf.jasperreports.engine.JRCommonText;
|
||||
import net.sf.jasperreports.engine.JRFont;
|
||||
import net.sf.jasperreports.engine.JRLineBox;
|
||||
import net.sf.jasperreports.engine.JRPen;
|
||||
import net.sf.jasperreports.engine.JRStyle;
|
||||
import net.sf.jasperreports.engine.JRStyleContainer;
|
||||
import net.sf.jasperreports.engine.JRTextField;
|
||||
import net.sf.jasperreports.engine.base.JRBoxPen;
|
||||
|
||||
public class JRStyleResolver {
|
||||
private static final Integer INTEGER_ZERO = new Integer(0);
|
||||
|
||||
private static JRFont getBaseFont(JRFont font) {
|
||||
if (font.getReportFont() != null)
|
||||
return (JRFont)font.getReportFont();
|
||||
if (font.getDefaultStyleProvider() != null)
|
||||
return (JRFont)font.getDefaultStyleProvider().getDefaultFont();
|
||||
return null;
|
||||
}
|
||||
|
||||
private static JRStyle getBaseStyle(JRStyleContainer styleContainer) {
|
||||
if (styleContainer != null) {
|
||||
if (styleContainer.getStyle() != null)
|
||||
return styleContainer.getStyle();
|
||||
if (styleContainer.getDefaultStyleProvider() != null)
|
||||
return styleContainer.getDefaultStyleProvider().getDefaultStyle();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte getMode(JRCommonElement element, byte defaultMode) {
|
||||
if (element.getOwnMode() != null)
|
||||
return element.getOwnMode().byteValue();
|
||||
JRStyle style = getBaseStyle((JRStyleContainer)element);
|
||||
if (style != null && style.getMode() != null)
|
||||
return style.getMode().byteValue();
|
||||
return defaultMode;
|
||||
}
|
||||
|
||||
public static Byte getMode(JRStyle style) {
|
||||
if (style.getOwnMode() != null)
|
||||
return style.getOwnMode();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getMode();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Color getForecolor(JRCommonElement element) {
|
||||
if (element.getOwnForecolor() != null)
|
||||
return element.getOwnForecolor();
|
||||
JRStyle style = getBaseStyle((JRStyleContainer)element);
|
||||
if (style != null && style.getForecolor() != null)
|
||||
return style.getForecolor();
|
||||
return Color.black;
|
||||
}
|
||||
|
||||
public static Color getForecolor(JRChartPlot plot) {
|
||||
JRChart chart = plot.getChart();
|
||||
if (chart != null)
|
||||
return getForecolor((JRCommonElement)chart);
|
||||
return Color.black;
|
||||
}
|
||||
|
||||
public static Color getForecolor(JRStyle style) {
|
||||
if (style.getOwnForecolor() != null)
|
||||
return style.getOwnForecolor();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getForecolor();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Color getBackcolor(JRCommonElement element) {
|
||||
if (element.getOwnBackcolor() != null)
|
||||
return element.getOwnBackcolor();
|
||||
JRStyle style = getBaseStyle((JRStyleContainer)element);
|
||||
if (style != null && style.getBackcolor() != null)
|
||||
return style.getBackcolor();
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
public static Color getBackcolor(JRChartPlot plot) {
|
||||
if (plot.getOwnBackcolor() != null)
|
||||
return plot.getOwnBackcolor();
|
||||
JRChart chart = plot.getChart();
|
||||
if (chart != null)
|
||||
return getBackcolor((JRCommonElement)chart);
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
public static Color getBackcolor(JRStyle style) {
|
||||
if (style.getOwnBackcolor() != null)
|
||||
return style.getOwnBackcolor();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getBackcolor();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Float getLineWidth(JRPen pen, Float defaultLineWidth) {
|
||||
if (pen.getOwnLineWidth() != null)
|
||||
return pen.getOwnLineWidth();
|
||||
JRStyle baseStyle = getBaseStyle(pen.getStyleContainer());
|
||||
if (baseStyle != null && baseStyle.getLinePen().getLineWidth() != null)
|
||||
return baseStyle.getLinePen().getLineWidth();
|
||||
return defaultLineWidth;
|
||||
}
|
||||
|
||||
public static Float getLineWidth(JRBoxPen boxPen, Float defaultLineWidth) {
|
||||
if (boxPen.getOwnLineWidth() != null)
|
||||
return boxPen.getOwnLineWidth();
|
||||
if (boxPen.getBox().getPen().getOwnLineWidth() != null)
|
||||
return boxPen.getBox().getPen().getOwnLineWidth();
|
||||
JRStyle baseStyle = getBaseStyle(boxPen.getStyleContainer());
|
||||
if (baseStyle != null && boxPen.getPen(baseStyle.getLineBox()).getLineWidth() != null)
|
||||
return boxPen.getPen(baseStyle.getLineBox()).getLineWidth();
|
||||
return defaultLineWidth;
|
||||
}
|
||||
|
||||
public static Byte getLineStyle(JRPen pen) {
|
||||
if (pen.getOwnLineStyle() != null)
|
||||
return pen.getOwnLineStyle();
|
||||
JRStyle baseStyle = getBaseStyle(pen.getStyleContainer());
|
||||
if (baseStyle != null && baseStyle.getLinePen().getLineStyle() != null)
|
||||
return baseStyle.getLinePen().getLineStyle();
|
||||
return new Byte((byte)0);
|
||||
}
|
||||
|
||||
public static Byte getLineStyle(JRBoxPen boxPen) {
|
||||
if (boxPen.getOwnLineStyle() != null)
|
||||
return boxPen.getOwnLineStyle();
|
||||
if (boxPen.getBox().getPen().getOwnLineStyle() != null)
|
||||
return boxPen.getBox().getPen().getOwnLineStyle();
|
||||
JRStyle baseStyle = getBaseStyle(boxPen.getStyleContainer());
|
||||
if (baseStyle != null && boxPen.getPen(baseStyle.getLineBox()).getLineStyle() != null)
|
||||
return boxPen.getPen(baseStyle.getLineBox()).getLineStyle();
|
||||
return new Byte((byte)0);
|
||||
}
|
||||
|
||||
public static Color getLineColor(JRPen pen, Color defaultColor) {
|
||||
if (pen.getOwnLineColor() != null)
|
||||
return pen.getOwnLineColor();
|
||||
JRStyle baseStyle = getBaseStyle(pen.getStyleContainer());
|
||||
if (baseStyle != null && baseStyle.getLinePen().getLineColor() != null)
|
||||
return baseStyle.getLinePen().getLineColor();
|
||||
return defaultColor;
|
||||
}
|
||||
|
||||
public static Color getLineColor(JRBoxPen boxPen, Color defaultColor) {
|
||||
if (boxPen.getOwnLineColor() != null)
|
||||
return boxPen.getOwnLineColor();
|
||||
if (boxPen.getBox().getPen().getOwnLineColor() != null)
|
||||
return boxPen.getBox().getPen().getOwnLineColor();
|
||||
JRStyle baseStyle = getBaseStyle(boxPen.getStyleContainer());
|
||||
if (baseStyle != null && boxPen.getPen(baseStyle.getLineBox()).getLineColor() != null)
|
||||
return boxPen.getPen(baseStyle.getLineBox()).getLineColor();
|
||||
return defaultColor;
|
||||
}
|
||||
|
||||
public static byte getFill(JRCommonGraphicElement element) {
|
||||
if (element.getOwnFill() != null)
|
||||
return element.getOwnFill().byteValue();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)element);
|
||||
if (baseStyle != null && baseStyle.getFill() != null)
|
||||
return baseStyle.getFill().byteValue();
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static Byte getFill(JRStyle style) {
|
||||
if (style.getOwnFill() != null)
|
||||
return style.getOwnFill();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getFill();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getRadius(JRCommonRectangle rectangle) {
|
||||
if (rectangle.getOwnRadius() != null)
|
||||
return rectangle.getOwnRadius().intValue();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)rectangle);
|
||||
if (baseStyle != null && baseStyle.getRadius() != null)
|
||||
return baseStyle.getRadius().intValue();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static Integer getRadius(JRStyle style) {
|
||||
if (style.getOwnRadius() != null)
|
||||
return style.getOwnRadius();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getRadius();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte getScaleImage(JRCommonImage image) {
|
||||
if (image.getOwnScaleImage() != null)
|
||||
return image.getOwnScaleImage().byteValue();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)image);
|
||||
if (baseStyle != null && baseStyle.getScaleImage() != null)
|
||||
return baseStyle.getScaleImage().byteValue();
|
||||
return 3;
|
||||
}
|
||||
|
||||
public static Byte getScaleImage(JRStyle style) {
|
||||
if (style.getOwnScaleImage() != null)
|
||||
return style.getOwnScaleImage();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getScaleImage();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte getHorizontalAlignment(JRAlignment alignment) {
|
||||
if (alignment.getOwnHorizontalAlignment() != null)
|
||||
return alignment.getOwnHorizontalAlignment().byteValue();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)alignment);
|
||||
if (baseStyle != null && baseStyle.getHorizontalAlignment() != null)
|
||||
return baseStyle.getHorizontalAlignment().byteValue();
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static Byte getHorizontalAlignment(JRStyle style) {
|
||||
if (style.getOwnHorizontalAlignment() != null)
|
||||
return style.getOwnHorizontalAlignment();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null && baseStyle.getHorizontalAlignment() != null)
|
||||
return baseStyle.getHorizontalAlignment();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte getVerticalAlignment(JRAlignment alignment) {
|
||||
if (alignment.getOwnVerticalAlignment() != null)
|
||||
return alignment.getOwnVerticalAlignment().byteValue();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)alignment);
|
||||
if (baseStyle != null && baseStyle.getVerticalAlignment() != null)
|
||||
return baseStyle.getVerticalAlignment().byteValue();
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static Byte getVerticalAlignment(JRStyle style) {
|
||||
if (style.getOwnVerticalAlignment() != null)
|
||||
return style.getOwnVerticalAlignment();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null && baseStyle.getVerticalAlignment() != null)
|
||||
return baseStyle.getVerticalAlignment();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte getRotation(JRCommonText element) {
|
||||
if (element.getOwnRotation() != null)
|
||||
return element.getOwnRotation().byteValue();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)element);
|
||||
if (baseStyle != null && baseStyle.getRotation() != null)
|
||||
return baseStyle.getRotation().byteValue();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static Byte getRotation(JRStyle style) {
|
||||
if (style.getOwnRotation() != null)
|
||||
return style.getOwnRotation();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getRotation();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte getLineSpacing(JRCommonText element) {
|
||||
if (element.getOwnLineSpacing() != null)
|
||||
return element.getOwnLineSpacing().byteValue();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)element);
|
||||
if (baseStyle != null && baseStyle.getLineSpacing() != null)
|
||||
return baseStyle.getLineSpacing().byteValue();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static Byte getLineSpacing(JRStyle style) {
|
||||
if (style.getOwnLineSpacing() != null)
|
||||
return style.getOwnLineSpacing();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getLineSpacing();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getMarkup(JRCommonText element) {
|
||||
if (element.getOwnMarkup() != null)
|
||||
return element.getOwnMarkup();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)element);
|
||||
if (baseStyle != null && baseStyle.getMarkup() != null)
|
||||
return baseStyle.getMarkup();
|
||||
return "none";
|
||||
}
|
||||
|
||||
public static String getMarkup(JRStyle style) {
|
||||
if (style.getOwnMarkup() != null)
|
||||
return style.getOwnMarkup();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getMarkup();
|
||||
return "none";
|
||||
}
|
||||
|
||||
public static String getPattern(JRTextField element) {
|
||||
if (element.getOwnPattern() != null)
|
||||
return element.getOwnPattern();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)element);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getPattern();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getPattern(JRStyle style) {
|
||||
if (style.getOwnPattern() != null)
|
||||
return style.getOwnPattern();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getPattern();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isBlankWhenNull(JRTextField element) {
|
||||
if (element.isOwnBlankWhenNull() != null)
|
||||
return element.isOwnBlankWhenNull().booleanValue();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)element);
|
||||
if (baseStyle != null && baseStyle.isBlankWhenNull() != null)
|
||||
return baseStyle.isBlankWhenNull().booleanValue();
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Boolean isBlankWhenNull(JRStyle style) {
|
||||
if (style.isOwnBlankWhenNull() != null)
|
||||
return style.isOwnBlankWhenNull();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.isBlankWhenNull();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getFontName(JRFont font) {
|
||||
if (font.getOwnFontName() != null)
|
||||
return font.getOwnFontName();
|
||||
JRFont baseFont = getBaseFont(font);
|
||||
if (baseFont != null && baseFont.getFontName() != null)
|
||||
return baseFont.getFontName();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)font);
|
||||
if (baseStyle != null && baseStyle.getFontName() != null)
|
||||
return baseStyle.getFontName();
|
||||
return JRProperties.getProperty("net.sf.jasperreports.default.font.name");
|
||||
}
|
||||
|
||||
public static String getFontName(JRStyle style) {
|
||||
if (style.getOwnFontName() != null)
|
||||
return style.getOwnFontName();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null && baseStyle.getFontName() != null)
|
||||
return baseStyle.getFontName();
|
||||
return JRProperties.getProperty("net.sf.jasperreports.default.font.name");
|
||||
}
|
||||
|
||||
public static boolean isBold(JRFont font) {
|
||||
if (font.isOwnBold() != null)
|
||||
return font.isOwnBold().booleanValue();
|
||||
JRFont baseFont = getBaseFont(font);
|
||||
if (baseFont != null)
|
||||
return baseFont.isBold();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)font);
|
||||
if (baseStyle != null && baseStyle.isBold() != null)
|
||||
return baseStyle.isBold().booleanValue();
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Boolean isBold(JRStyle style) {
|
||||
if (style.isOwnBold() != null)
|
||||
return style.isOwnBold();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.isBold();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isItalic(JRFont font) {
|
||||
if (font.isOwnItalic() != null)
|
||||
return font.isOwnItalic().booleanValue();
|
||||
JRFont baseFont = getBaseFont(font);
|
||||
if (baseFont != null)
|
||||
return baseFont.isItalic();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)font);
|
||||
if (baseStyle != null && baseStyle.isItalic() != null)
|
||||
return baseStyle.isItalic().booleanValue();
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Boolean isItalic(JRStyle style) {
|
||||
if (style.isOwnItalic() != null)
|
||||
return style.isOwnItalic();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.isItalic();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isUnderline(JRFont font) {
|
||||
if (font.isOwnUnderline() != null)
|
||||
return font.isOwnUnderline().booleanValue();
|
||||
JRFont baseFont = getBaseFont(font);
|
||||
if (baseFont != null)
|
||||
return baseFont.isUnderline();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)font);
|
||||
if (baseStyle != null && baseStyle.isUnderline() != null)
|
||||
return baseStyle.isUnderline().booleanValue();
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Boolean isUnderline(JRStyle style) {
|
||||
if (style.isOwnUnderline() != null)
|
||||
return style.isOwnUnderline();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.isUnderline();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isStrikeThrough(JRFont font) {
|
||||
if (font.isOwnStrikeThrough() != null)
|
||||
return font.isOwnStrikeThrough().booleanValue();
|
||||
JRFont baseFont = getBaseFont(font);
|
||||
if (baseFont != null)
|
||||
return baseFont.isStrikeThrough();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)font);
|
||||
if (baseStyle != null && baseStyle.isStrikeThrough() != null)
|
||||
return baseStyle.isStrikeThrough().booleanValue();
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Boolean isStrikeThrough(JRStyle style) {
|
||||
if (style.isOwnStrikeThrough() != null)
|
||||
return style.isOwnStrikeThrough();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.isStrikeThrough();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getFontSize(JRFont font) {
|
||||
if (font.getOwnFontSize() != null)
|
||||
return font.getOwnFontSize().intValue();
|
||||
JRFont baseFont = getBaseFont(font);
|
||||
if (baseFont != null)
|
||||
return baseFont.getFontSize();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)font);
|
||||
if (baseStyle != null && baseStyle.getFontSize() != null)
|
||||
return baseStyle.getFontSize().intValue();
|
||||
return JRProperties.getIntegerProperty("net.sf.jasperreports.default.font.size");
|
||||
}
|
||||
|
||||
public static Integer getFontSize(JRStyle style) {
|
||||
if (style.getOwnFontSize() != null)
|
||||
return style.getOwnFontSize();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.getFontSize();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getPdfFontName(JRFont font) {
|
||||
if (font.getOwnPdfFontName() != null)
|
||||
return font.getOwnPdfFontName();
|
||||
JRFont baseFont = getBaseFont(font);
|
||||
if (baseFont != null && baseFont.getPdfFontName() != null)
|
||||
return baseFont.getPdfFontName();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)font);
|
||||
if (baseStyle != null && baseStyle.getPdfFontName() != null)
|
||||
return baseStyle.getPdfFontName();
|
||||
return JRProperties.getProperty("net.sf.jasperreports.default.pdf.font.name");
|
||||
}
|
||||
|
||||
public static String getPdfFontName(JRStyle style) {
|
||||
if (style.getOwnPdfFontName() != null)
|
||||
return style.getOwnPdfFontName();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null && baseStyle.getPdfFontName() != null)
|
||||
return baseStyle.getPdfFontName();
|
||||
return JRProperties.getProperty("net.sf.jasperreports.default.pdf.font.name");
|
||||
}
|
||||
|
||||
public static String getPdfEncoding(JRFont font) {
|
||||
if (font.getOwnPdfEncoding() != null)
|
||||
return font.getOwnPdfEncoding();
|
||||
JRFont baseFont = getBaseFont(font);
|
||||
if (baseFont != null && baseFont.getPdfEncoding() != null)
|
||||
return baseFont.getPdfEncoding();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)font);
|
||||
if (baseStyle != null && baseStyle.getPdfEncoding() != null)
|
||||
return baseStyle.getPdfEncoding();
|
||||
return JRProperties.getProperty("net.sf.jasperreports.default.pdf.encoding");
|
||||
}
|
||||
|
||||
public static String getPdfEncoding(JRStyle style) {
|
||||
if (style.getOwnPdfEncoding() != null)
|
||||
return style.getOwnPdfEncoding();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null && baseStyle.getPdfEncoding() != null)
|
||||
return baseStyle.getPdfEncoding();
|
||||
return JRProperties.getProperty("net.sf.jasperreports.default.pdf.encoding");
|
||||
}
|
||||
|
||||
public static boolean isPdfEmbedded(JRFont font) {
|
||||
if (font.isOwnPdfEmbedded() != null)
|
||||
return font.isOwnPdfEmbedded().booleanValue();
|
||||
JRFont baseFont = getBaseFont(font);
|
||||
if (baseFont != null)
|
||||
return baseFont.isPdfEmbedded();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)font);
|
||||
if (baseStyle != null && baseStyle.isPdfEmbedded() != null)
|
||||
return baseStyle.isPdfEmbedded().booleanValue();
|
||||
return JRProperties.getBooleanProperty("net.sf.jasperreports.default.pdf.embedded");
|
||||
}
|
||||
|
||||
public static Boolean isPdfEmbedded(JRStyle style) {
|
||||
if (style.isOwnPdfEmbedded() != null)
|
||||
return style.isOwnPdfEmbedded();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)style);
|
||||
if (baseStyle != null)
|
||||
return baseStyle.isPdfEmbedded();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Integer getPadding(JRLineBox box) {
|
||||
if (box.getOwnPadding() != null)
|
||||
return box.getOwnPadding();
|
||||
JRStyle baseStyle = getBaseStyle((JRStyleContainer)box);
|
||||
if (baseStyle != null && baseStyle.getLineBox().getPadding() != null)
|
||||
return baseStyle.getLineBox().getPadding();
|
||||
return INTEGER_ZERO;
|
||||
}
|
||||
|
||||
public static Integer getTopPadding(JRLineBox box) {
|
||||
if (box.getOwnTopPadding() != null)
|
||||
return box.getOwnTopPadding();
|
||||
if (box.getOwnPadding() != null)
|
||||
return box.getOwnPadding();
|
||||
JRStyle style = getBaseStyle((JRStyleContainer)box);
|
||||
if (style != null && style.getLineBox().getTopPadding() != null)
|
||||
return style.getLineBox().getTopPadding();
|
||||
return INTEGER_ZERO;
|
||||
}
|
||||
|
||||
public static Integer getLeftPadding(JRLineBox box) {
|
||||
if (box.getOwnLeftPadding() != null)
|
||||
return box.getOwnLeftPadding();
|
||||
if (box.getOwnPadding() != null)
|
||||
return box.getOwnPadding();
|
||||
JRStyle style = getBaseStyle((JRStyleContainer)box);
|
||||
if (style != null && style.getLineBox().getLeftPadding() != null)
|
||||
return style.getLineBox().getLeftPadding();
|
||||
return INTEGER_ZERO;
|
||||
}
|
||||
|
||||
public static Integer getBottomPadding(JRLineBox box) {
|
||||
if (box.getOwnBottomPadding() != null)
|
||||
return box.getOwnBottomPadding();
|
||||
if (box.getOwnPadding() != null)
|
||||
return box.getOwnPadding();
|
||||
JRStyle style = getBaseStyle((JRStyleContainer)box);
|
||||
if (style != null && style.getLineBox().getBottomPadding() != null)
|
||||
return style.getLineBox().getBottomPadding();
|
||||
return INTEGER_ZERO;
|
||||
}
|
||||
|
||||
public static Integer getRightPadding(JRLineBox box) {
|
||||
if (box.getOwnRightPadding() != null)
|
||||
return box.getOwnRightPadding();
|
||||
if (box.getOwnPadding() != null)
|
||||
return box.getOwnPadding();
|
||||
JRStyle style = getBaseStyle((JRStyleContainer)box);
|
||||
if (style != null && style.getLineBox().getRightPadding() != null)
|
||||
return style.getLineBox().getRightPadding();
|
||||
return INTEGER_ZERO;
|
||||
}
|
||||
|
||||
public static void appendStyle(JRStyle destStyle, JRStyle srcStyle) {
|
||||
if (srcStyle.getOwnMode() != null)
|
||||
destStyle.setMode(srcStyle.getOwnMode());
|
||||
if (srcStyle.getOwnForecolor() != null)
|
||||
destStyle.setForecolor(srcStyle.getOwnForecolor());
|
||||
if (srcStyle.getOwnBackcolor() != null)
|
||||
destStyle.setBackcolor(srcStyle.getOwnBackcolor());
|
||||
appendPen(destStyle.getLinePen(), srcStyle.getLinePen());
|
||||
if (srcStyle.getOwnFill() != null)
|
||||
destStyle.setFill(srcStyle.getOwnFill());
|
||||
if (srcStyle.getOwnRadius() != null)
|
||||
destStyle.setRadius(srcStyle.getOwnRadius());
|
||||
if (srcStyle.getOwnScaleImage() != null)
|
||||
destStyle.setScaleImage(srcStyle.getOwnScaleImage());
|
||||
if (srcStyle.getOwnHorizontalAlignment() != null)
|
||||
destStyle.setHorizontalAlignment(srcStyle.getOwnHorizontalAlignment());
|
||||
if (srcStyle.getOwnVerticalAlignment() != null)
|
||||
destStyle.setVerticalAlignment(srcStyle.getOwnVerticalAlignment());
|
||||
appendBox(destStyle.getLineBox(), srcStyle.getLineBox());
|
||||
if (srcStyle.getOwnRotation() != null)
|
||||
destStyle.setRotation(srcStyle.getOwnRotation());
|
||||
if (srcStyle.getOwnLineSpacing() != null)
|
||||
destStyle.setLineSpacing(srcStyle.getOwnLineSpacing());
|
||||
if (srcStyle.getOwnMarkup() != null)
|
||||
destStyle.setMarkup(srcStyle.getOwnMarkup());
|
||||
if (srcStyle.getOwnPattern() != null)
|
||||
destStyle.setPattern(srcStyle.getOwnPattern());
|
||||
if (srcStyle.getOwnFontName() != null)
|
||||
destStyle.setFontName(srcStyle.getOwnFontName());
|
||||
if (srcStyle.isOwnBold() != null)
|
||||
destStyle.setBold(srcStyle.isOwnBold());
|
||||
if (srcStyle.isOwnItalic() != null)
|
||||
destStyle.setItalic(srcStyle.isOwnItalic());
|
||||
if (srcStyle.isOwnUnderline() != null)
|
||||
destStyle.setUnderline(srcStyle.isOwnUnderline());
|
||||
if (srcStyle.isOwnStrikeThrough() != null)
|
||||
destStyle.setStrikeThrough(srcStyle.isOwnStrikeThrough());
|
||||
if (srcStyle.getOwnFontSize() != null)
|
||||
destStyle.setFontSize(srcStyle.getOwnFontSize());
|
||||
if (srcStyle.getOwnPdfFontName() != null)
|
||||
destStyle.setPdfFontName(srcStyle.getOwnPdfFontName());
|
||||
if (srcStyle.getOwnPdfEncoding() != null)
|
||||
destStyle.setPdfEncoding(srcStyle.getOwnPdfEncoding());
|
||||
if (srcStyle.isOwnPdfEmbedded() != null)
|
||||
destStyle.setPdfEmbedded(srcStyle.isOwnPdfEmbedded());
|
||||
}
|
||||
|
||||
private static void appendPen(JRPen destPen, JRPen srcPen) {
|
||||
if (srcPen.getOwnLineWidth() != null)
|
||||
destPen.setLineWidth(srcPen.getOwnLineWidth());
|
||||
if (srcPen.getOwnLineStyle() != null)
|
||||
destPen.setLineStyle(srcPen.getOwnLineStyle());
|
||||
if (srcPen.getOwnLineColor() != null)
|
||||
destPen.setLineColor(srcPen.getOwnLineColor());
|
||||
}
|
||||
|
||||
private static void appendBox(JRLineBox destBox, JRLineBox srcBox) {
|
||||
appendPen((JRPen)destBox.getPen(), (JRPen)srcBox.getPen());
|
||||
appendPen((JRPen)destBox.getTopPen(), (JRPen)srcBox.getTopPen());
|
||||
appendPen((JRPen)destBox.getLeftPen(), (JRPen)srcBox.getLeftPen());
|
||||
appendPen((JRPen)destBox.getBottomPen(), (JRPen)srcBox.getBottomPen());
|
||||
appendPen((JRPen)destBox.getRightPen(), (JRPen)srcBox.getRightPen());
|
||||
if (srcBox.getOwnPadding() != null)
|
||||
destBox.setPadding(srcBox.getOwnPadding());
|
||||
if (srcBox.getOwnTopPadding() != null)
|
||||
destBox.setTopPadding(srcBox.getOwnTopPadding());
|
||||
if (srcBox.getOwnLeftPadding() != null)
|
||||
destBox.setLeftPadding(srcBox.getOwnLeftPadding());
|
||||
if (srcBox.getOwnBottomPadding() != null)
|
||||
destBox.setBottomPadding(srcBox.getOwnBottomPadding());
|
||||
if (srcBox.getOwnRightPadding() != null)
|
||||
destBox.setRightPadding(srcBox.getOwnRightPadding());
|
||||
}
|
||||
|
||||
public static Color getTitleColor(JRChart chart) {
|
||||
if (chart.getOwnTitleColor() != null)
|
||||
return chart.getOwnTitleColor();
|
||||
return getForecolor((JRCommonElement)chart);
|
||||
}
|
||||
|
||||
public static Color getSubtitleColor(JRChart chart) {
|
||||
if (chart.getOwnSubtitleColor() != null)
|
||||
return chart.getOwnSubtitleColor();
|
||||
return getForecolor((JRCommonElement)chart);
|
||||
}
|
||||
|
||||
public static Color getLegendColor(JRChart chart) {
|
||||
if (chart.getOwnLegendColor() != null)
|
||||
return chart.getOwnLegendColor();
|
||||
return getForecolor((JRCommonElement)chart);
|
||||
}
|
||||
|
||||
public static Color getLegendBackgroundColor(JRChart chart) {
|
||||
if (chart.getOwnLegendBackgroundColor() != null)
|
||||
return chart.getOwnLegendBackgroundColor();
|
||||
return getBackcolor((JRCommonElement)chart);
|
||||
}
|
||||
|
||||
public static Color getCategoryAxisLabelColor(JRCategoryAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnCategoryAxisLabelColor() != null)
|
||||
return axisFormat.getOwnCategoryAxisLabelColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getCategoryAxisTickLabelColor(JRCategoryAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnCategoryAxisTickLabelColor() != null)
|
||||
return axisFormat.getOwnCategoryAxisTickLabelColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getCategoryAxisLineColor(JRCategoryAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnCategoryAxisLineColor() != null)
|
||||
return axisFormat.getOwnCategoryAxisLineColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getValueAxisLabelColor(JRValueAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnValueAxisLabelColor() != null)
|
||||
return axisFormat.getOwnValueAxisLabelColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getValueAxisTickLabelColor(JRValueAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnValueAxisTickLabelColor() != null)
|
||||
return axisFormat.getOwnValueAxisTickLabelColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getValueAxisLineColor(JRValueAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnValueAxisLineColor() != null)
|
||||
return axisFormat.getOwnValueAxisLineColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getXAxisLabelColor(JRXAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnXAxisLabelColor() != null)
|
||||
return axisFormat.getOwnXAxisLabelColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getXAxisTickLabelColor(JRXAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnXAxisTickLabelColor() != null)
|
||||
return axisFormat.getOwnXAxisTickLabelColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getXAxisLineColor(JRXAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnXAxisLineColor() != null)
|
||||
return axisFormat.getOwnXAxisLineColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getYAxisLabelColor(JRYAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnYAxisLabelColor() != null)
|
||||
return axisFormat.getOwnYAxisLabelColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getYAxisTickLabelColor(JRYAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnYAxisTickLabelColor() != null)
|
||||
return axisFormat.getOwnYAxisTickLabelColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getYAxisLineColor(JRYAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnYAxisLineColor() != null)
|
||||
return axisFormat.getOwnYAxisLineColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getTimeAxisLabelColor(JRTimeAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnTimeAxisLabelColor() != null)
|
||||
return axisFormat.getOwnTimeAxisLabelColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getTimeAxisTickLabelColor(JRTimeAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnTimeAxisTickLabelColor() != null)
|
||||
return axisFormat.getOwnTimeAxisTickLabelColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
|
||||
public static Color getTimeAxisLineColor(JRTimeAxisFormat axisFormat, JRChartPlot plot) {
|
||||
if (axisFormat.getOwnTimeAxisLineColor() != null)
|
||||
return axisFormat.getOwnTimeAxisLineColor();
|
||||
return getForecolor(plot);
|
||||
}
|
||||
}
|
100
hrmsEjb/net/sf/jasperreports/engine/util/JRStyledText.java
Normal file
100
hrmsEjb/net/sf/jasperreports/engine/util/JRStyledText.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.AttributedString;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class JRStyledText {
|
||||
private StringBuffer sbuffer = new StringBuffer();
|
||||
|
||||
private List runs = new ArrayList();
|
||||
|
||||
private AttributedString attributedString = null;
|
||||
|
||||
private AttributedString awtAttributedString = null;
|
||||
|
||||
private Map globalAttributes;
|
||||
|
||||
public void append(String text) {
|
||||
this.sbuffer.append(text);
|
||||
this.attributedString = null;
|
||||
this.awtAttributedString = null;
|
||||
}
|
||||
|
||||
public void addRun(Run run) {
|
||||
this.runs.add(run);
|
||||
this.attributedString = null;
|
||||
this.awtAttributedString = null;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return this.sbuffer.length();
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.sbuffer.toString();
|
||||
}
|
||||
|
||||
public AttributedString getAttributedString() {
|
||||
if (this.attributedString == null) {
|
||||
this.attributedString = new AttributedString(this.sbuffer.toString());
|
||||
for (int i = this.runs.size() - 1; i >= 0; i--) {
|
||||
Run run = this.runs.get(i);
|
||||
if (run.startIndex != run.endIndex && run.attributes != null)
|
||||
this.attributedString.addAttributes(run.attributes, run.startIndex, run.endIndex);
|
||||
}
|
||||
}
|
||||
return this.attributedString;
|
||||
}
|
||||
|
||||
public AttributedString getAwtAttributedString() {
|
||||
if (this.awtAttributedString == null) {
|
||||
this.awtAttributedString = new AttributedString(this.sbuffer.toString());
|
||||
for (int i = this.runs.size() - 1; i >= 0; i--) {
|
||||
Run run = this.runs.get(i);
|
||||
if (run.startIndex != run.endIndex && run.attributes != null && !run.attributes.isEmpty()) {
|
||||
Iterator it = run.attributes.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = it.next();
|
||||
AttributedCharacterIterator.Attribute attribute = (AttributedCharacterIterator.Attribute)entry.getKey();
|
||||
if (!(attribute instanceof JRTextAttribute)) {
|
||||
Object value = entry.getValue();
|
||||
this.awtAttributedString.addAttribute(attribute, value, run.startIndex, run.endIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.awtAttributedString;
|
||||
}
|
||||
|
||||
public List getRuns() {
|
||||
return this.runs;
|
||||
}
|
||||
|
||||
public static class Run {
|
||||
public Map attributes = null;
|
||||
|
||||
public int startIndex = 0;
|
||||
|
||||
public int endIndex = 0;
|
||||
|
||||
public Run(Map attributes, int startIndex, int endIndex) {
|
||||
this.attributes = attributes;
|
||||
this.startIndex = startIndex;
|
||||
this.endIndex = endIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public void setGlobalAttributes(Map attributes) {
|
||||
this.globalAttributes = attributes;
|
||||
addRun(new Run(attributes, 0, length()));
|
||||
}
|
||||
|
||||
public Map getGlobalAttributes() {
|
||||
return this.globalAttributes;
|
||||
}
|
||||
}
|
464
hrmsEjb/net/sf/jasperreports/engine/util/JRStyledTextParser.java
Normal file
464
hrmsEjb/net/sf/jasperreports/engine/util/JRStyledTextParser.java
Normal file
@@ -0,0 +1,464 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.AttributedString;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import net.sf.jasperreports.engine.JRRuntimeException;
|
||||
import net.sf.jasperreports.engine.xml.JRXmlConstants;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
public class JRStyledTextParser implements ErrorHandler {
|
||||
private static final String ROOT_START = "<st>";
|
||||
|
||||
private static final String ROOT_END = "</st>";
|
||||
|
||||
private static final String NODE_style = "style";
|
||||
|
||||
private static final String NODE_bold = "b";
|
||||
|
||||
private static final String NODE_italic = "i";
|
||||
|
||||
private static final String NODE_underline = "u";
|
||||
|
||||
private static final String NODE_sup = "sup";
|
||||
|
||||
private static final String NODE_sub = "sub";
|
||||
|
||||
private static final String NODE_font = "font";
|
||||
|
||||
private static final String NODE_br = "br";
|
||||
|
||||
private static final String NODE_li = "li";
|
||||
|
||||
private static final String ATTRIBUTE_fontName = "fontName";
|
||||
|
||||
private static final String ATTRIBUTE_fontFace = "face";
|
||||
|
||||
private static final String ATTRIBUTE_color = "color";
|
||||
|
||||
private static final String ATTRIBUTE_size = "size";
|
||||
|
||||
private static final String ATTRIBUTE_isBold = "isBold";
|
||||
|
||||
private static final String ATTRIBUTE_isItalic = "isItalic";
|
||||
|
||||
private static final String ATTRIBUTE_isUnderline = "isUnderline";
|
||||
|
||||
private static final String ATTRIBUTE_isStrikeThrough = "isStrikeThrough";
|
||||
|
||||
private static final String ATTRIBUTE_forecolor = "forecolor";
|
||||
|
||||
private static final String ATTRIBUTE_backcolor = "backcolor";
|
||||
|
||||
private static final String ATTRIBUTE_pdfFontName = "pdfFontName";
|
||||
|
||||
private static final String ATTRIBUTE_pdfEncoding = "pdfEncoding";
|
||||
|
||||
private static final String ATTRIBUTE_isPdfEmbedded = "isPdfEmbedded";
|
||||
|
||||
private static final String SPACE = " ";
|
||||
|
||||
private static final String EQUAL_QUOTE = "=\"";
|
||||
|
||||
private static final String QUOTE = "\"";
|
||||
|
||||
private static final String SHARP = "#";
|
||||
|
||||
private static final String LESS = "<";
|
||||
|
||||
private static final String LESS_SLASH = "</";
|
||||
|
||||
private static final String GREATER = ">";
|
||||
|
||||
private static final ThreadLocal threadInstances = new ThreadLocal();
|
||||
|
||||
public static JRStyledTextParser getInstance() {
|
||||
JRStyledTextParser instance = null;
|
||||
SoftReference instanceRef = threadInstances.get();
|
||||
if (instanceRef != null)
|
||||
instance = instanceRef.get();
|
||||
if (instance == null) {
|
||||
instance = new JRStyledTextParser();
|
||||
threadInstances.set(new SoftReference(instance));
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private DocumentBuilder documentBuilder = null;
|
||||
|
||||
public JRStyledTextParser() {
|
||||
try {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
this.documentBuilder = factory.newDocumentBuilder();
|
||||
this.documentBuilder.setErrorHandler(this);
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new JRRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public JRStyledText parse(Map attributes, String text) throws SAXException {
|
||||
JRStyledText styledText = new JRStyledText();
|
||||
Document document = null;
|
||||
try {
|
||||
document = this.documentBuilder.parse(new InputSource(new StringReader("<st>" + text + "</st>")));
|
||||
} catch (IOException e) {
|
||||
throw new JRRuntimeException(e);
|
||||
}
|
||||
parseStyle(styledText, document.getDocumentElement());
|
||||
styledText.setGlobalAttributes(attributes);
|
||||
return styledText;
|
||||
}
|
||||
|
||||
public JRStyledText getStyledText(Map parentAttributes, String text, boolean isStyledText) {
|
||||
JRStyledText styledText = null;
|
||||
if (isStyledText)
|
||||
try {
|
||||
styledText = parse(parentAttributes, text);
|
||||
} catch (SAXException e) {}
|
||||
if (styledText == null) {
|
||||
styledText = new JRStyledText();
|
||||
styledText.append(text);
|
||||
styledText.setGlobalAttributes(parentAttributes);
|
||||
}
|
||||
return styledText;
|
||||
}
|
||||
|
||||
public String write(JRStyledText styledText) {
|
||||
return write(styledText.getGlobalAttributes(), styledText.getAttributedString().getIterator(), styledText.getText());
|
||||
}
|
||||
|
||||
public String write(Map parentAttrs, AttributedCharacterIterator iterator, String text) {
|
||||
StringBuffer sbuffer = new StringBuffer();
|
||||
int runLimit = 0;
|
||||
while (runLimit < iterator.getEndIndex() && (runLimit = iterator.getRunLimit()) <= iterator.getEndIndex()) {
|
||||
String chunk = text.substring(iterator.getIndex(), runLimit);
|
||||
Map attrs = iterator.getAttributes();
|
||||
StringBuffer styleBuffer = writeStyleAttributes(parentAttrs, attrs);
|
||||
if (styleBuffer.length() > 0) {
|
||||
sbuffer.append("<");
|
||||
sbuffer.append("style");
|
||||
sbuffer.append(styleBuffer.toString());
|
||||
sbuffer.append(">");
|
||||
writeChunk(sbuffer, parentAttrs, attrs, chunk);
|
||||
sbuffer.append("</");
|
||||
sbuffer.append("style");
|
||||
sbuffer.append(">");
|
||||
} else {
|
||||
writeChunk(sbuffer, parentAttrs, attrs, chunk);
|
||||
}
|
||||
iterator.setIndex(runLimit);
|
||||
}
|
||||
return sbuffer.toString();
|
||||
}
|
||||
|
||||
public String write(JRStyledText styledText, int startIndex, int endIndex) {
|
||||
AttributedCharacterIterator subIterator = (new AttributedString(styledText.getAttributedString().getIterator(), startIndex, endIndex)).getIterator();
|
||||
String subText = styledText.getText().substring(startIndex, endIndex);
|
||||
return write(styledText.getGlobalAttributes(), subIterator, subText);
|
||||
}
|
||||
|
||||
public void writeChunk(StringBuffer sbuffer, Map parentAttrs, Map attrs, String chunk) {
|
||||
Object value = attrs.get(TextAttribute.SUPERSCRIPT);
|
||||
Object oldValue = parentAttrs.get(TextAttribute.SUPERSCRIPT);
|
||||
boolean isSuper = false;
|
||||
boolean isSub = false;
|
||||
if (value != null && !value.equals(oldValue)) {
|
||||
isSuper = TextAttribute.SUPERSCRIPT_SUPER.equals(value);
|
||||
isSub = TextAttribute.SUPERSCRIPT_SUB.equals(value);
|
||||
}
|
||||
if (isSuper || isSub) {
|
||||
String node = isSuper ? "sup" : "sub";
|
||||
sbuffer.append("<");
|
||||
sbuffer.append(node);
|
||||
sbuffer.append(">");
|
||||
sbuffer.append(JRStringUtil.xmlEncode(chunk));
|
||||
sbuffer.append("</");
|
||||
sbuffer.append(node);
|
||||
sbuffer.append(">");
|
||||
} else {
|
||||
sbuffer.append(JRStringUtil.xmlEncode(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
private void parseStyle(JRStyledText styledText, Node parentNode) throws SAXException {
|
||||
NodeList nodeList = parentNode.getChildNodes();
|
||||
int i;
|
||||
label116: for (i = 0; i < nodeList.getLength(); i++) {
|
||||
Node node = nodeList.item(i);
|
||||
if (node.getNodeType() == 3) {
|
||||
styledText.append(node.getNodeValue());
|
||||
} else if (node.getNodeType() == 1 && "style".equals(node.getNodeName())) {
|
||||
NamedNodeMap nodeAttrs = node.getAttributes();
|
||||
Map styleAttrs = new HashMap();
|
||||
if (nodeAttrs.getNamedItem("fontName") != null)
|
||||
styleAttrs.put(TextAttribute.FAMILY, nodeAttrs.getNamedItem("fontName").getNodeValue());
|
||||
if (nodeAttrs.getNamedItem("isBold") != null)
|
||||
styleAttrs.put(TextAttribute.WEIGHT, Boolean.valueOf(nodeAttrs.getNamedItem("isBold").getNodeValue()).booleanValue() ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR);
|
||||
if (nodeAttrs.getNamedItem("isItalic") != null)
|
||||
styleAttrs.put(TextAttribute.POSTURE, Boolean.valueOf(nodeAttrs.getNamedItem("isItalic").getNodeValue()).booleanValue() ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR);
|
||||
if (nodeAttrs.getNamedItem("isUnderline") != null)
|
||||
styleAttrs.put(TextAttribute.UNDERLINE, Boolean.valueOf(nodeAttrs.getNamedItem("isUnderline").getNodeValue()).booleanValue() ? TextAttribute.UNDERLINE_ON : null);
|
||||
if (nodeAttrs.getNamedItem("isStrikeThrough") != null)
|
||||
styleAttrs.put(TextAttribute.STRIKETHROUGH, Boolean.valueOf(nodeAttrs.getNamedItem("isStrikeThrough").getNodeValue()).booleanValue() ? TextAttribute.STRIKETHROUGH_ON : null);
|
||||
if (nodeAttrs.getNamedItem("size") != null)
|
||||
styleAttrs.put(TextAttribute.SIZE, new Float(nodeAttrs.getNamedItem("size").getNodeValue()));
|
||||
if (nodeAttrs.getNamedItem("pdfFontName") != null)
|
||||
styleAttrs.put(JRTextAttribute.PDF_FONT_NAME, nodeAttrs.getNamedItem("pdfFontName").getNodeValue());
|
||||
if (nodeAttrs.getNamedItem("pdfEncoding") != null)
|
||||
styleAttrs.put(JRTextAttribute.PDF_ENCODING, nodeAttrs.getNamedItem("pdfEncoding").getNodeValue());
|
||||
if (nodeAttrs.getNamedItem("isPdfEmbedded") != null)
|
||||
styleAttrs.put(JRTextAttribute.IS_PDF_EMBEDDED, Boolean.valueOf(nodeAttrs.getNamedItem("isPdfEmbedded").getNodeValue()));
|
||||
if (nodeAttrs.getNamedItem("forecolor") != null) {
|
||||
Color color = JRXmlConstants.getColor(nodeAttrs.getNamedItem("forecolor").getNodeValue(), Color.black);
|
||||
styleAttrs.put(TextAttribute.FOREGROUND, color);
|
||||
}
|
||||
if (nodeAttrs.getNamedItem("backcolor") != null) {
|
||||
Color color = JRXmlConstants.getColor(nodeAttrs.getNamedItem("backcolor").getNodeValue(), Color.black);
|
||||
styleAttrs.put(TextAttribute.BACKGROUND, color);
|
||||
}
|
||||
int startIndex = styledText.length();
|
||||
parseStyle(styledText, node);
|
||||
styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
|
||||
} else if (node.getNodeType() == 1 && "b".equalsIgnoreCase(node.getNodeName())) {
|
||||
Map styleAttrs = new HashMap();
|
||||
styleAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
|
||||
int startIndex = styledText.length();
|
||||
parseStyle(styledText, node);
|
||||
styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
|
||||
} else if (node.getNodeType() == 1 && "i".equalsIgnoreCase(node.getNodeName())) {
|
||||
Map styleAttrs = new HashMap();
|
||||
styleAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
|
||||
int startIndex = styledText.length();
|
||||
parseStyle(styledText, node);
|
||||
styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
|
||||
} else if (node.getNodeType() == 1 && "u".equalsIgnoreCase(node.getNodeName())) {
|
||||
Map styleAttrs = new HashMap();
|
||||
styleAttrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
||||
int startIndex = styledText.length();
|
||||
parseStyle(styledText, node);
|
||||
styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
|
||||
} else if (node.getNodeType() == 1 && "sup".equalsIgnoreCase(node.getNodeName())) {
|
||||
Map styleAttrs = new HashMap();
|
||||
styleAttrs.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);
|
||||
int startIndex = styledText.length();
|
||||
parseStyle(styledText, node);
|
||||
styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
|
||||
} else if (node.getNodeType() == 1 && "sub".equalsIgnoreCase(node.getNodeName())) {
|
||||
Map styleAttrs = new HashMap();
|
||||
styleAttrs.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB);
|
||||
int startIndex = styledText.length();
|
||||
parseStyle(styledText, node);
|
||||
styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
|
||||
} else if (node.getNodeType() == 1 && "font".equalsIgnoreCase(node.getNodeName())) {
|
||||
NamedNodeMap nodeAttrs = node.getAttributes();
|
||||
Map styleAttrs = new HashMap();
|
||||
if (nodeAttrs.getNamedItem("face") != null)
|
||||
styleAttrs.put(JRTextAttribute.HTML_FONT_FACE, nodeAttrs.getNamedItem("face").getNodeValue());
|
||||
if (nodeAttrs.getNamedItem("size") != null)
|
||||
styleAttrs.put(TextAttribute.SIZE, new Float(nodeAttrs.getNamedItem("size").getNodeValue()));
|
||||
if (nodeAttrs.getNamedItem("color") != null) {
|
||||
Color color = JRXmlConstants.getColor(nodeAttrs.getNamedItem("color").getNodeValue(), Color.black);
|
||||
styleAttrs.put(TextAttribute.FOREGROUND, color);
|
||||
}
|
||||
if (nodeAttrs.getNamedItem("face") != null) {
|
||||
String[] fontList = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
|
||||
String fontFaces = nodeAttrs.getNamedItem("face").getNodeValue();
|
||||
StringTokenizer t = new StringTokenizer(fontFaces, ",");
|
||||
while (t.hasMoreTokens()) {
|
||||
String face = t.nextToken().trim();
|
||||
for (int j = 0; j < fontList.length; j++) {
|
||||
if (fontList[j].equals(face)) {
|
||||
styleAttrs.put(TextAttribute.FAMILY, face);
|
||||
continue label116;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int startIndex = styledText.length();
|
||||
parseStyle(styledText, node);
|
||||
styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
|
||||
} else if (node.getNodeType() == 1 && "br".equalsIgnoreCase(node.getNodeName())) {
|
||||
styledText.append("\n");
|
||||
int startIndex = styledText.length();
|
||||
resizeRuns(styledText.getRuns(), startIndex, 1);
|
||||
parseStyle(styledText, node);
|
||||
styledText.addRun(new JRStyledText.Run(new HashMap(), startIndex, styledText.length()));
|
||||
if (startIndex < styledText.length()) {
|
||||
styledText.append("\n");
|
||||
resizeRuns(styledText.getRuns(), startIndex, 1);
|
||||
}
|
||||
} else if (node.getNodeType() == 1 && "li".equalsIgnoreCase(node.getNodeName())) {
|
||||
String tmpText = styledText.getText();
|
||||
if (tmpText.length() > 0 && !tmpText.endsWith("\n"))
|
||||
styledText.append("\n");
|
||||
styledText.append(" • ");
|
||||
int startIndex = styledText.length();
|
||||
resizeRuns(styledText.getRuns(), startIndex, 1);
|
||||
parseStyle(styledText, node);
|
||||
styledText.addRun(new JRStyledText.Run(new HashMap(), startIndex, styledText.length()));
|
||||
Node nextNode = node.getNextSibling();
|
||||
String textContent = getFirstTextOccurence(nextNode);
|
||||
if (nextNode != null && (nextNode.getNodeType() != 1 || !"li".equalsIgnoreCase(nextNode.getNodeName())) && (textContent == null || !textContent.startsWith("\n"))) {
|
||||
styledText.append("\n");
|
||||
resizeRuns(styledText.getRuns(), startIndex, 1);
|
||||
}
|
||||
} else if (node.getNodeType() == 1) {
|
||||
String nodeName = "<" + node.getNodeName() + ">";
|
||||
throw new SAXException("Tag " + nodeName + " is not a valid styled text tag.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resizeRuns(List runs, int startIndex, int count) {
|
||||
for (int j = 0; j < runs.size(); j++) {
|
||||
JRStyledText.Run run = runs.get(j);
|
||||
if (run.startIndex <= startIndex && run.endIndex > startIndex - count)
|
||||
run.endIndex += count;
|
||||
}
|
||||
}
|
||||
|
||||
private StringBuffer writeStyleAttributes(Map parentAttrs, Map attrs) {
|
||||
StringBuffer sbuffer = new StringBuffer();
|
||||
Object value = attrs.get(TextAttribute.FAMILY);
|
||||
Object oldValue = parentAttrs.get(TextAttribute.FAMILY);
|
||||
if (value != null && !value.equals(oldValue)) {
|
||||
sbuffer.append(" ");
|
||||
sbuffer.append("fontName");
|
||||
sbuffer.append("=\"");
|
||||
sbuffer.append(value);
|
||||
sbuffer.append("\"");
|
||||
}
|
||||
value = attrs.get(TextAttribute.WEIGHT);
|
||||
oldValue = parentAttrs.get(TextAttribute.WEIGHT);
|
||||
if (value != null && !value.equals(oldValue)) {
|
||||
sbuffer.append(" ");
|
||||
sbuffer.append("isBold");
|
||||
sbuffer.append("=\"");
|
||||
sbuffer.append(value.equals(TextAttribute.WEIGHT_BOLD));
|
||||
sbuffer.append("\"");
|
||||
}
|
||||
value = attrs.get(TextAttribute.POSTURE);
|
||||
oldValue = parentAttrs.get(TextAttribute.POSTURE);
|
||||
if (value != null && !value.equals(oldValue)) {
|
||||
sbuffer.append(" ");
|
||||
sbuffer.append("isItalic");
|
||||
sbuffer.append("=\"");
|
||||
sbuffer.append(value.equals(TextAttribute.POSTURE_OBLIQUE));
|
||||
sbuffer.append("\"");
|
||||
}
|
||||
value = attrs.get(TextAttribute.UNDERLINE);
|
||||
oldValue = parentAttrs.get(TextAttribute.UNDERLINE);
|
||||
if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) {
|
||||
sbuffer.append(" ");
|
||||
sbuffer.append("isUnderline");
|
||||
sbuffer.append("=\"");
|
||||
sbuffer.append((value != null));
|
||||
sbuffer.append("\"");
|
||||
}
|
||||
value = attrs.get(TextAttribute.STRIKETHROUGH);
|
||||
oldValue = parentAttrs.get(TextAttribute.STRIKETHROUGH);
|
||||
if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) {
|
||||
sbuffer.append(" ");
|
||||
sbuffer.append("isStrikeThrough");
|
||||
sbuffer.append("=\"");
|
||||
sbuffer.append((value != null));
|
||||
sbuffer.append("\"");
|
||||
}
|
||||
value = attrs.get(TextAttribute.SIZE);
|
||||
oldValue = parentAttrs.get(TextAttribute.SIZE);
|
||||
if (value != null && !value.equals(oldValue)) {
|
||||
sbuffer.append(" ");
|
||||
sbuffer.append("size");
|
||||
sbuffer.append("=\"");
|
||||
sbuffer.append(((Float)value).intValue());
|
||||
sbuffer.append("\"");
|
||||
}
|
||||
value = attrs.get(JRTextAttribute.PDF_FONT_NAME);
|
||||
oldValue = parentAttrs.get(JRTextAttribute.PDF_FONT_NAME);
|
||||
if (value != null && !value.equals(oldValue)) {
|
||||
sbuffer.append(" ");
|
||||
sbuffer.append("pdfFontName");
|
||||
sbuffer.append("=\"");
|
||||
sbuffer.append(value);
|
||||
sbuffer.append("\"");
|
||||
}
|
||||
value = attrs.get(JRTextAttribute.PDF_ENCODING);
|
||||
oldValue = parentAttrs.get(JRTextAttribute.PDF_ENCODING);
|
||||
if (value != null && !value.equals(oldValue)) {
|
||||
sbuffer.append(" ");
|
||||
sbuffer.append("pdfEncoding");
|
||||
sbuffer.append("=\"");
|
||||
sbuffer.append(value);
|
||||
sbuffer.append("\"");
|
||||
}
|
||||
value = attrs.get(JRTextAttribute.IS_PDF_EMBEDDED);
|
||||
oldValue = parentAttrs.get(JRTextAttribute.IS_PDF_EMBEDDED);
|
||||
if (value != null && !value.equals(oldValue)) {
|
||||
sbuffer.append(" ");
|
||||
sbuffer.append("isPdfEmbedded");
|
||||
sbuffer.append("=\"");
|
||||
sbuffer.append(value);
|
||||
sbuffer.append("\"");
|
||||
}
|
||||
value = attrs.get(TextAttribute.FOREGROUND);
|
||||
oldValue = parentAttrs.get(TextAttribute.FOREGROUND);
|
||||
if (value != null && !value.equals(oldValue)) {
|
||||
sbuffer.append(" ");
|
||||
sbuffer.append("forecolor");
|
||||
sbuffer.append("=\"");
|
||||
sbuffer.append("#");
|
||||
sbuffer.append(JRColorUtil.getColorHexa((Color)value));
|
||||
sbuffer.append("\"");
|
||||
}
|
||||
value = attrs.get(TextAttribute.BACKGROUND);
|
||||
oldValue = parentAttrs.get(TextAttribute.BACKGROUND);
|
||||
if (value != null && !value.equals(oldValue)) {
|
||||
sbuffer.append(" ");
|
||||
sbuffer.append("backcolor");
|
||||
sbuffer.append("=\"");
|
||||
sbuffer.append("#");
|
||||
sbuffer.append(JRColorUtil.getColorHexa((Color)value));
|
||||
sbuffer.append("\"");
|
||||
}
|
||||
return sbuffer;
|
||||
}
|
||||
|
||||
private String getFirstTextOccurence(Node node) {
|
||||
if (node != null) {
|
||||
if (node.getNodeValue() != null)
|
||||
return node.getNodeValue();
|
||||
NodeList nodeList = node.getChildNodes();
|
||||
for (int i = 0; i < nodeList.getLength(); i++) {
|
||||
String firstOccurence = getFirstTextOccurence(nodeList.item(i));
|
||||
if (firstOccurence != null)
|
||||
return firstOccurence;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void error(SAXParseException e) {}
|
||||
|
||||
public void fatalError(SAXParseException e) {}
|
||||
|
||||
public void warning(SAXParseException e) {}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.io.InvalidObjectException;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class JRTextAttribute extends AttributedCharacterIterator.Attribute {
|
||||
private static final long serialVersionUID = 10200L;
|
||||
|
||||
private static final Map instanceMap = new HashMap(4);
|
||||
|
||||
public static JRTextAttribute PDF_FONT_NAME = new JRTextAttribute("PDF_FONT_NAME");
|
||||
|
||||
public static JRTextAttribute PDF_ENCODING = new JRTextAttribute("PDF_ENCODING");
|
||||
|
||||
public static JRTextAttribute IS_PDF_EMBEDDED = new JRTextAttribute("IS_PDF_EMBEDDED");
|
||||
|
||||
public static JRTextAttribute HTML_FONT_FACE = new JRTextAttribute("HTML_FONT_FACE");
|
||||
|
||||
private JRTextAttribute(String name) {
|
||||
super(name);
|
||||
if (getClass() == JRTextAttribute.class)
|
||||
instanceMap.put(name, this);
|
||||
}
|
||||
|
||||
protected Object readResolve() throws InvalidObjectException {
|
||||
if (getClass() != JRTextAttribute.class)
|
||||
throw new InvalidObjectException("Subclass didn't correctly implement readResolve");
|
||||
JRTextAttribute instance = (JRTextAttribute)instanceMap.get(getName());
|
||||
if (instance != null)
|
||||
return instance;
|
||||
throw new InvalidObjectException("Unknown attribute name");
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import net.sf.jasperreports.engine.JRCommonText;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.JRPropertiesHolder;
|
||||
import net.sf.jasperreports.engine.JRRuntimeException;
|
||||
import net.sf.jasperreports.engine.fill.JRTextMeasurer;
|
||||
import net.sf.jasperreports.engine.fill.JRTextMeasurerFactory;
|
||||
|
||||
public class JRTextMeasurerUtil {
|
||||
public static final String PROPERTY_TEXT_MEASURER_FACTORY = "net.sf.jasperreports.text.measurer.factory";
|
||||
|
||||
private static final JRSingletonCache cache = new JRSingletonCache(JRTextMeasurerFactory.class);
|
||||
|
||||
public static JRTextMeasurer createTextMeasurer(JRCommonText text) {
|
||||
JRPropertiesHolder propertiesHolder = (text instanceof JRPropertiesHolder) ? (JRPropertiesHolder)text : null;
|
||||
return createTextMeasurer(text, propertiesHolder);
|
||||
}
|
||||
|
||||
public static JRTextMeasurer createTextMeasurer(JRCommonText text, JRPropertiesHolder propertiesHolder) {
|
||||
JRTextMeasurerFactory factory = getTextMeasurerFactory(propertiesHolder);
|
||||
return factory.createMeasurer(text);
|
||||
}
|
||||
|
||||
public static JRTextMeasurerFactory getTextMeasurerFactory(JRPropertiesHolder propertiesHolder) {
|
||||
String factoryClass = getTextMeasurerFactoryClass(propertiesHolder);
|
||||
try {
|
||||
return (JRTextMeasurerFactory)cache.getCachedInstance(factoryClass);
|
||||
} catch (JRException e) {
|
||||
throw new JRRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected static String getTextMeasurerFactoryClass(JRPropertiesHolder propertiesHolder) {
|
||||
String factory = JRProperties.getProperty(propertiesHolder, "net.sf.jasperreports.text.measurer.factory");
|
||||
String factoryClassProperty = "net.sf.jasperreports.text.measurer.factory." + factory;
|
||||
String factoryClass = JRProperties.getProperty(propertiesHolder, factoryClassProperty);
|
||||
if (factoryClass == null)
|
||||
factoryClass = factory;
|
||||
return factoryClass;
|
||||
}
|
||||
}
|
68
hrmsEjb/net/sf/jasperreports/engine/util/JRTypeSniffer.java
Normal file
68
hrmsEjb/net/sf/jasperreports/engine/util/JRTypeSniffer.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
public class JRTypeSniffer {
|
||||
public static boolean isGIF(byte[] data) {
|
||||
if (data.length < 3)
|
||||
return false;
|
||||
byte[] first = new byte[3];
|
||||
System.arraycopy(data, 0, first, 0, 3);
|
||||
if ((new String(first)).equalsIgnoreCase("GIF"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isJPEG(byte[] data) {
|
||||
if (data.length < 2)
|
||||
return false;
|
||||
if (data[0] == -1 && data[1] == -40)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isPNG(byte[] data) {
|
||||
if (data.length < 8)
|
||||
return false;
|
||||
if (data[0] == -119 && data[1] == 80 && data[2] == 78 && data[3] == 71 && data[4] == 13 && data[5] == 10 && data[6] == 26 && data[7] == 10)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isTIFF(byte[] data) {
|
||||
if (data.length < 2)
|
||||
return false;
|
||||
if ((data[0] == 73 && data[1] == 73) || (data[0] == 77 && data[1] == 77))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static byte getImageType(byte[] data) {
|
||||
if (isGIF(data))
|
||||
return 1;
|
||||
if (isJPEG(data))
|
||||
return 2;
|
||||
if (isPNG(data))
|
||||
return 3;
|
||||
if (isTIFF(data))
|
||||
return 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static String getImageMimeType(byte imageType) {
|
||||
String mimeType = null;
|
||||
switch (imageType) {
|
||||
case 1:
|
||||
mimeType = "image/gif";
|
||||
break;
|
||||
case 2:
|
||||
mimeType = "image/jpeg";
|
||||
break;
|
||||
case 3:
|
||||
mimeType = "image/png";
|
||||
break;
|
||||
case 4:
|
||||
mimeType = "image/tiff";
|
||||
break;
|
||||
}
|
||||
return mimeType;
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import net.sf.jasperreports.crosstabs.JRCrosstab;
|
||||
import net.sf.jasperreports.engine.JRBreak;
|
||||
import net.sf.jasperreports.engine.JRChart;
|
||||
import net.sf.jasperreports.engine.JRElementGroup;
|
||||
import net.sf.jasperreports.engine.JREllipse;
|
||||
import net.sf.jasperreports.engine.JRFrame;
|
||||
import net.sf.jasperreports.engine.JRImage;
|
||||
import net.sf.jasperreports.engine.JRLine;
|
||||
import net.sf.jasperreports.engine.JRRectangle;
|
||||
import net.sf.jasperreports.engine.JRStaticText;
|
||||
import net.sf.jasperreports.engine.JRSubreport;
|
||||
import net.sf.jasperreports.engine.JRTextField;
|
||||
import net.sf.jasperreports.engine.JRVisitor;
|
||||
|
||||
public abstract class JRVisitorSupport implements JRVisitor {
|
||||
public void visitBreak(JRBreak breakElement) {}
|
||||
|
||||
public void visitChart(JRChart chart) {}
|
||||
|
||||
public void visitCrosstab(JRCrosstab crosstab) {}
|
||||
|
||||
public void visitElementGroup(JRElementGroup elementGroup) {}
|
||||
|
||||
public void visitEllipse(JREllipse ellipse) {}
|
||||
|
||||
public void visitFrame(JRFrame frame) {}
|
||||
|
||||
public void visitImage(JRImage image) {}
|
||||
|
||||
public void visitLine(JRLine line) {}
|
||||
|
||||
public void visitRectangle(JRRectangle rectangle) {}
|
||||
|
||||
public void visitStaticText(JRStaticText staticText) {}
|
||||
|
||||
public void visitSubreport(JRSubreport subreport) {}
|
||||
|
||||
public void visitTextField(JRTextField textField) {}
|
||||
}
|
330
hrmsEjb/net/sf/jasperreports/engine/util/JRXmlWriteHelper.java
Normal file
330
hrmsEjb/net/sf/jasperreports/engine/util/JRXmlWriteHelper.java
Normal file
@@ -0,0 +1,330 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.sf.jasperreports.engine.JRExpression;
|
||||
|
||||
public class JRXmlWriteHelper {
|
||||
private final Writer writer;
|
||||
|
||||
private final List indents;
|
||||
|
||||
private int indent;
|
||||
|
||||
private final List elementStack;
|
||||
|
||||
private StringBuffer buffer;
|
||||
|
||||
private StackElement lastElement;
|
||||
|
||||
protected static class Attribute {
|
||||
String name;
|
||||
|
||||
String value;
|
||||
|
||||
Attribute(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class StackElement {
|
||||
String name;
|
||||
|
||||
List atts;
|
||||
|
||||
boolean hasChildren;
|
||||
|
||||
StackElement(String name) {
|
||||
this.name = name;
|
||||
this.atts = new ArrayList();
|
||||
this.hasChildren = false;
|
||||
}
|
||||
|
||||
void addAttribute(String attName, String value) {
|
||||
this.atts.add(new JRXmlWriteHelper.Attribute(attName, value));
|
||||
}
|
||||
}
|
||||
|
||||
public JRXmlWriteHelper(Writer writer) {
|
||||
this.writer = writer;
|
||||
this.indents = new ArrayList();
|
||||
this.indent = 0;
|
||||
this.elementStack = new ArrayList();
|
||||
this.lastElement = null;
|
||||
clearBuffer();
|
||||
}
|
||||
|
||||
public void writeProlog(String encoding) throws IOException {
|
||||
this.writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
|
||||
}
|
||||
|
||||
public void writePublicDoctype(String rootElement, String description, String dtdLocation) throws IOException {
|
||||
this.writer.write("<!DOCTYPE " + rootElement + " PUBLIC \"" + description + "\" \"" + dtdLocation + "\">\n\n");
|
||||
}
|
||||
|
||||
public void startElement(String name) {
|
||||
this.indent++;
|
||||
this.lastElement = new StackElement(name);
|
||||
this.elementStack.add(this.lastElement);
|
||||
}
|
||||
|
||||
protected void writeParents(boolean content) throws IOException {
|
||||
int stackSize = this.elementStack.size();
|
||||
int startWrite = stackSize - 1;
|
||||
while (startWrite >= 0) {
|
||||
StackElement element = this.elementStack.get(startWrite);
|
||||
if (element.hasChildren)
|
||||
break;
|
||||
if (startWrite < stackSize - 1) {
|
||||
element.hasChildren = true;
|
||||
} else {
|
||||
element.hasChildren |= content;
|
||||
}
|
||||
startWrite--;
|
||||
}
|
||||
for (int i = startWrite + 1; i < stackSize; i++) {
|
||||
StackElement element = this.elementStack.get(i);
|
||||
writeElementAttributes(element, i);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeCDATA(String data) throws IOException {
|
||||
if (data != null) {
|
||||
writeParents(true);
|
||||
this.buffer.append(getIndent(this.indent));
|
||||
this.buffer.append("<![CDATA[");
|
||||
this.buffer.append(data);
|
||||
this.buffer.append("]]>\n");
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
public void writeCDATAElement(String name, String data) throws IOException {
|
||||
if (data != null) {
|
||||
writeParents(true);
|
||||
this.buffer.append(getIndent(this.indent));
|
||||
this.buffer.append('<');
|
||||
this.buffer.append(name);
|
||||
this.buffer.append("><![CDATA[");
|
||||
this.buffer.append(data);
|
||||
this.buffer.append("]]></");
|
||||
this.buffer.append(name);
|
||||
this.buffer.append(">\n");
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
public void writeCDATAElement(String name, String data, String attName, String attValue) throws IOException {
|
||||
writeCDATAElement(name, data, attName, attValue);
|
||||
}
|
||||
|
||||
public void writeCDATAElement(String name, String data, String attName, Object attValue) throws IOException {
|
||||
if (data != null) {
|
||||
writeParents(true);
|
||||
this.buffer.append(getIndent(this.indent));
|
||||
this.buffer.append('<');
|
||||
this.buffer.append(name);
|
||||
if (attValue != null) {
|
||||
this.buffer.append(' ');
|
||||
this.buffer.append(attName);
|
||||
this.buffer.append("=\"");
|
||||
this.buffer.append(attValue);
|
||||
this.buffer.append("\"");
|
||||
}
|
||||
this.buffer.append("><![CDATA[");
|
||||
this.buffer.append(data);
|
||||
this.buffer.append("]]></");
|
||||
this.buffer.append(name);
|
||||
this.buffer.append(">\n");
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeElementAttributes(StackElement element, int level) throws IOException {
|
||||
this.buffer.append(getIndent(level));
|
||||
this.buffer.append('<');
|
||||
this.buffer.append(element.name);
|
||||
for (Iterator i = element.atts.iterator(); i.hasNext(); ) {
|
||||
Attribute att = i.next();
|
||||
this.buffer.append(' ');
|
||||
this.buffer.append(att.name);
|
||||
this.buffer.append("=\"");
|
||||
this.buffer.append(att.value);
|
||||
this.buffer.append('"');
|
||||
}
|
||||
if (element.hasChildren) {
|
||||
this.buffer.append(">\n");
|
||||
} else {
|
||||
this.buffer.append("/>\n");
|
||||
}
|
||||
flushBuffer();
|
||||
}
|
||||
|
||||
public void closeElement() throws IOException {
|
||||
closeElement(false);
|
||||
}
|
||||
|
||||
public void closeElement(boolean skipIfEmpty) throws IOException {
|
||||
this.indent--;
|
||||
if (skipIfEmpty && this.lastElement.atts.size() == 0 && !this.lastElement.hasChildren) {
|
||||
clearBuffer();
|
||||
} else {
|
||||
writeParents(false);
|
||||
if (this.lastElement.hasChildren) {
|
||||
this.buffer.append(getIndent(this.indent));
|
||||
this.buffer.append("</");
|
||||
this.buffer.append(this.lastElement.name);
|
||||
this.buffer.append(">\n");
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
||||
this.elementStack.remove(this.indent);
|
||||
this.lastElement = (this.indent > 0) ? this.elementStack.get(this.indent - 1) : null;
|
||||
}
|
||||
|
||||
protected char[] getIndent(int level) {
|
||||
if (level >= this.indents.size())
|
||||
for (int i = this.indents.size(); i <= level; i++) {
|
||||
char[] str = new char[i];
|
||||
Arrays.fill(str, '\t');
|
||||
this.indents.add(str);
|
||||
}
|
||||
return this.indents.get(level);
|
||||
}
|
||||
|
||||
protected void flushBuffer() throws IOException {
|
||||
this.writer.write(this.buffer.toString());
|
||||
clearBuffer();
|
||||
}
|
||||
|
||||
protected void clearBuffer() {
|
||||
this.buffer = new StringBuffer();
|
||||
}
|
||||
|
||||
public void writeExpression(String name, JRExpression expression, boolean writeClass) throws IOException {
|
||||
writeExpression(name, expression, writeClass, null);
|
||||
}
|
||||
|
||||
public void writeExpression(String name, JRExpression expression, boolean writeClass, String defaultClassName) throws IOException {
|
||||
if (expression != null)
|
||||
if (writeClass && (defaultClassName == null || !defaultClassName.equals(expression.getValueClassName()))) {
|
||||
writeCDATAElement(name, expression.getText(), "class", expression.getValueClassName());
|
||||
} else {
|
||||
writeCDATAElement(name, expression.getText());
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeAttribute(String name, String value) {
|
||||
this.lastElement.addAttribute(name, value);
|
||||
}
|
||||
|
||||
public void addAttribute(String name, String value) {
|
||||
if (value != null)
|
||||
writeAttribute(name, value);
|
||||
}
|
||||
|
||||
public void addEncodedAttribute(String name, String value) {
|
||||
if (value != null)
|
||||
writeAttribute(name, JRStringUtil.xmlEncode(value));
|
||||
}
|
||||
|
||||
public void addAttribute(String name, String value, String defaultValue) {
|
||||
if (value != null && !value.equals(defaultValue))
|
||||
writeAttribute(name, value);
|
||||
}
|
||||
|
||||
public void addEncodedAttribute(String name, String value, String defaultValue) {
|
||||
if (value != null && !value.equals(defaultValue))
|
||||
writeAttribute(name, JRStringUtil.xmlEncode(value));
|
||||
}
|
||||
|
||||
public void addAttribute(String name, Object value) {
|
||||
if (value != null)
|
||||
writeAttribute(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void addAttribute(String name, int value) {
|
||||
writeAttribute(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void addAttributePositive(String name, int value) {
|
||||
if (value > 0)
|
||||
writeAttribute(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void addAttribute(String name, float value) {
|
||||
writeAttribute(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void addAttribute(String name, float value, float defaultValue) {
|
||||
if (value != defaultValue)
|
||||
writeAttribute(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void addAttribute(String name, double value) {
|
||||
writeAttribute(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void addAttribute(String name, double value, double defaultValue) {
|
||||
if (value != defaultValue)
|
||||
writeAttribute(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void addAttribute(String name, int value, int defaultValue) {
|
||||
if (value != defaultValue)
|
||||
addAttribute(name, value);
|
||||
}
|
||||
|
||||
public void addAttribute(String name, boolean value) {
|
||||
writeAttribute(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void addAttribute(String name, boolean value, boolean defaultValue) {
|
||||
if (value != defaultValue)
|
||||
addAttribute(name, value);
|
||||
}
|
||||
|
||||
public void addAttribute(String name, Color color) {
|
||||
if (color != null)
|
||||
writeAttribute(name, "#" + JRColorUtil.getColorHexa(color));
|
||||
}
|
||||
|
||||
public void addAttribute(String name, Color value, Color defaultValue) {
|
||||
if (value != null && value.getRGB() != defaultValue.getRGB())
|
||||
addAttribute(name, value);
|
||||
}
|
||||
|
||||
public void addAttribute(String name, byte value, Map xmlValues) {
|
||||
String xmlValue = (String)xmlValues.get(new Byte(value));
|
||||
writeAttribute(name, xmlValue);
|
||||
}
|
||||
|
||||
public void addAttribute(String name, int value, Map xmlValues) {
|
||||
String xmlValue = (String)xmlValues.get(new Integer(value));
|
||||
writeAttribute(name, xmlValue);
|
||||
}
|
||||
|
||||
public void addAttribute(String name, byte value, Map xmlValues, byte defaultValue) {
|
||||
if (value != defaultValue)
|
||||
addAttribute(name, value, xmlValues);
|
||||
}
|
||||
|
||||
public void addAttribute(String name, Object value, Map xmlValues) {
|
||||
if (value != null) {
|
||||
String xmlValue = (String)xmlValues.get(value);
|
||||
writeAttribute(name, xmlValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void addAttribute(String name, Object value, Map xmlValues, Object defaultValue) {
|
||||
if (!value.equals(defaultValue))
|
||||
addAttribute(name, value, xmlValues);
|
||||
}
|
||||
}
|
255
hrmsEjb/net/sf/jasperreports/engine/util/LineBoxWrapper.java
Normal file
255
hrmsEjb/net/sf/jasperreports/engine/util/LineBoxWrapper.java
Normal file
@@ -0,0 +1,255 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.Serializable;
|
||||
import net.sf.jasperreports.engine.JRBox;
|
||||
import net.sf.jasperreports.engine.JRDefaultStyleProvider;
|
||||
import net.sf.jasperreports.engine.JRLineBox;
|
||||
import net.sf.jasperreports.engine.JRPen;
|
||||
import net.sf.jasperreports.engine.JRStyle;
|
||||
|
||||
public class LineBoxWrapper implements JRBox, Serializable {
|
||||
private static final long serialVersionUID = 10200L;
|
||||
|
||||
protected JRLineBox lineBox = null;
|
||||
|
||||
public LineBoxWrapper(JRLineBox lineBox) {
|
||||
this.lineBox = lineBox;
|
||||
}
|
||||
|
||||
public JRDefaultStyleProvider getDefaultStyleProvider() {
|
||||
return this.lineBox.getDefaultStyleProvider();
|
||||
}
|
||||
|
||||
public JRStyle getStyle() {
|
||||
return this.lineBox.getStyle();
|
||||
}
|
||||
|
||||
public String getStyleNameReference() {
|
||||
return this.lineBox.getStyleNameReference();
|
||||
}
|
||||
|
||||
public JRLineBox getLineBox() {
|
||||
return this.lineBox;
|
||||
}
|
||||
|
||||
public byte getBorder() {
|
||||
return JRPenUtil.getPenFromLinePen((JRPen)this.lineBox.getPen());
|
||||
}
|
||||
|
||||
public Byte getOwnBorder() {
|
||||
return JRPenUtil.getOwnPenFromLinePen((JRPen)this.lineBox.getPen());
|
||||
}
|
||||
|
||||
public void setBorder(byte border) {
|
||||
JRPenUtil.setLinePenFromPen(border, (JRPen)this.lineBox.getPen());
|
||||
}
|
||||
|
||||
public void setBorder(Byte border) {
|
||||
JRPenUtil.setLinePenFromPen(border, (JRPen)this.lineBox.getPen());
|
||||
}
|
||||
|
||||
public Color getBorderColor() {
|
||||
return this.lineBox.getPen().getLineColor();
|
||||
}
|
||||
|
||||
public Color getOwnBorderColor() {
|
||||
return this.lineBox.getPen().getOwnLineColor();
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.lineBox.getPen().setLineColor(borderColor);
|
||||
}
|
||||
|
||||
public int getPadding() {
|
||||
return this.lineBox.getPadding().intValue();
|
||||
}
|
||||
|
||||
public Integer getOwnPadding() {
|
||||
return this.lineBox.getOwnPadding();
|
||||
}
|
||||
|
||||
public void setPadding(int padding) {
|
||||
this.lineBox.setPadding(padding);
|
||||
}
|
||||
|
||||
public void setPadding(Integer padding) {
|
||||
this.lineBox.setPadding(padding);
|
||||
}
|
||||
|
||||
public byte getTopBorder() {
|
||||
return JRPenUtil.getPenFromLinePen((JRPen)this.lineBox.getTopPen());
|
||||
}
|
||||
|
||||
public Byte getOwnTopBorder() {
|
||||
return JRPenUtil.getOwnPenFromLinePen((JRPen)this.lineBox.getTopPen());
|
||||
}
|
||||
|
||||
public void setTopBorder(byte topBorder) {
|
||||
JRPenUtil.setLinePenFromPen(topBorder, (JRPen)this.lineBox.getTopPen());
|
||||
}
|
||||
|
||||
public void setTopBorder(Byte topBorder) {
|
||||
JRPenUtil.setLinePenFromPen(topBorder, (JRPen)this.lineBox.getTopPen());
|
||||
}
|
||||
|
||||
public Color getTopBorderColor() {
|
||||
return this.lineBox.getTopPen().getLineColor();
|
||||
}
|
||||
|
||||
public Color getOwnTopBorderColor() {
|
||||
return this.lineBox.getTopPen().getOwnLineColor();
|
||||
}
|
||||
|
||||
public void setTopBorderColor(Color topBorderColor) {
|
||||
this.lineBox.getTopPen().setLineColor(topBorderColor);
|
||||
}
|
||||
|
||||
public int getTopPadding() {
|
||||
return this.lineBox.getTopPadding().intValue();
|
||||
}
|
||||
|
||||
public Integer getOwnTopPadding() {
|
||||
return this.lineBox.getOwnTopPadding();
|
||||
}
|
||||
|
||||
public void setTopPadding(int topPadding) {
|
||||
this.lineBox.setTopPadding(topPadding);
|
||||
}
|
||||
|
||||
public void setTopPadding(Integer topPadding) {
|
||||
this.lineBox.setTopPadding(topPadding);
|
||||
}
|
||||
|
||||
public byte getLeftBorder() {
|
||||
return JRPenUtil.getPenFromLinePen((JRPen)this.lineBox.getLeftPen());
|
||||
}
|
||||
|
||||
public Byte getOwnLeftBorder() {
|
||||
return JRPenUtil.getOwnPenFromLinePen((JRPen)this.lineBox.getLeftPen());
|
||||
}
|
||||
|
||||
public void setLeftBorder(byte leftBorder) {
|
||||
JRPenUtil.setLinePenFromPen(leftBorder, (JRPen)this.lineBox.getLeftPen());
|
||||
}
|
||||
|
||||
public void setLeftBorder(Byte leftBorder) {
|
||||
JRPenUtil.setLinePenFromPen(leftBorder, (JRPen)this.lineBox.getLeftPen());
|
||||
}
|
||||
|
||||
public Color getLeftBorderColor() {
|
||||
return this.lineBox.getLeftPen().getLineColor();
|
||||
}
|
||||
|
||||
public Color getOwnLeftBorderColor() {
|
||||
return this.lineBox.getLeftPen().getOwnLineColor();
|
||||
}
|
||||
|
||||
public void setLeftBorderColor(Color leftBorderColor) {
|
||||
this.lineBox.getLeftPen().setLineColor(leftBorderColor);
|
||||
}
|
||||
|
||||
public int getLeftPadding() {
|
||||
return this.lineBox.getLeftPadding().intValue();
|
||||
}
|
||||
|
||||
public Integer getOwnLeftPadding() {
|
||||
return this.lineBox.getOwnLeftPadding();
|
||||
}
|
||||
|
||||
public void setLeftPadding(int leftPadding) {
|
||||
this.lineBox.setLeftPadding(leftPadding);
|
||||
}
|
||||
|
||||
public void setLeftPadding(Integer leftPadding) {
|
||||
this.lineBox.setLeftPadding(leftPadding);
|
||||
}
|
||||
|
||||
public byte getBottomBorder() {
|
||||
return JRPenUtil.getPenFromLinePen((JRPen)this.lineBox.getBottomPen());
|
||||
}
|
||||
|
||||
public Byte getOwnBottomBorder() {
|
||||
return JRPenUtil.getOwnPenFromLinePen((JRPen)this.lineBox.getBottomPen());
|
||||
}
|
||||
|
||||
public void setBottomBorder(byte bottomBorder) {
|
||||
JRPenUtil.setLinePenFromPen(bottomBorder, (JRPen)this.lineBox.getBottomPen());
|
||||
}
|
||||
|
||||
public void setBottomBorder(Byte bottomBorder) {
|
||||
JRPenUtil.setLinePenFromPen(bottomBorder, (JRPen)this.lineBox.getBottomPen());
|
||||
}
|
||||
|
||||
public Color getBottomBorderColor() {
|
||||
return this.lineBox.getBottomPen().getLineColor();
|
||||
}
|
||||
|
||||
public Color getOwnBottomBorderColor() {
|
||||
return this.lineBox.getBottomPen().getOwnLineColor();
|
||||
}
|
||||
|
||||
public void setBottomBorderColor(Color bottomBorderColor) {
|
||||
this.lineBox.getBottomPen().setLineColor(bottomBorderColor);
|
||||
}
|
||||
|
||||
public int getBottomPadding() {
|
||||
return this.lineBox.getBottomPadding().intValue();
|
||||
}
|
||||
|
||||
public Integer getOwnBottomPadding() {
|
||||
return this.lineBox.getOwnBottomPadding();
|
||||
}
|
||||
|
||||
public void setBottomPadding(int bottomPadding) {
|
||||
this.lineBox.setBottomPadding(bottomPadding);
|
||||
}
|
||||
|
||||
public void setBottomPadding(Integer bottomPadding) {
|
||||
this.lineBox.setBottomPadding(bottomPadding);
|
||||
}
|
||||
|
||||
public byte getRightBorder() {
|
||||
return JRPenUtil.getPenFromLinePen((JRPen)this.lineBox.getRightPen());
|
||||
}
|
||||
|
||||
public Byte getOwnRightBorder() {
|
||||
return JRPenUtil.getOwnPenFromLinePen((JRPen)this.lineBox.getRightPen());
|
||||
}
|
||||
|
||||
public void setRightBorder(byte rightBorder) {
|
||||
JRPenUtil.setLinePenFromPen(rightBorder, (JRPen)this.lineBox.getRightPen());
|
||||
}
|
||||
|
||||
public void setRightBorder(Byte rightBorder) {
|
||||
JRPenUtil.setLinePenFromPen(rightBorder, (JRPen)this.lineBox.getRightPen());
|
||||
}
|
||||
|
||||
public Color getRightBorderColor() {
|
||||
return this.lineBox.getRightPen().getLineColor();
|
||||
}
|
||||
|
||||
public Color getOwnRightBorderColor() {
|
||||
return this.lineBox.getRightPen().getOwnLineColor();
|
||||
}
|
||||
|
||||
public void setRightBorderColor(Color rightBorderColor) {
|
||||
this.lineBox.getRightPen().setLineColor(rightBorderColor);
|
||||
}
|
||||
|
||||
public int getRightPadding() {
|
||||
return this.lineBox.getRightPadding().intValue();
|
||||
}
|
||||
|
||||
public Integer getOwnRightPadding() {
|
||||
return this.lineBox.getOwnRightPadding();
|
||||
}
|
||||
|
||||
public void setRightPadding(int rightPadding) {
|
||||
this.lineBox.setRightPadding(rightPadding);
|
||||
}
|
||||
|
||||
public void setRightPadding(Integer rightPadding) {
|
||||
this.lineBox.setRightPadding(rightPadding);
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
public interface MarkupProcessor {
|
||||
String convert(String paramString);
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
public interface MarkupProcessorFactory {
|
||||
public static final String PROPERTY_MARKUP_PROCESSOR_FACTORY_PREFIX = "net.sf.jasperreports.markup.processor.factory.";
|
||||
|
||||
MarkupProcessor createMarkupProcessor();
|
||||
}
|
45
hrmsEjb/net/sf/jasperreports/engine/util/Pair.java
Normal file
45
hrmsEjb/net/sf/jasperreports/engine/util/Pair.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Pair implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Object o1;
|
||||
|
||||
private final Object o2;
|
||||
|
||||
private final int hash;
|
||||
|
||||
public Pair(Object o1, Object o2) {
|
||||
this.o1 = o1;
|
||||
this.o2 = o2;
|
||||
this.hash = computeHash();
|
||||
}
|
||||
|
||||
private int computeHash() {
|
||||
int hashCode = (this.o1 == null) ? 0 : this.o1.hashCode();
|
||||
hashCode *= 31;
|
||||
hashCode += (this.o2 == null) ? 0 : this.o2.hashCode();
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (o == null || !(o instanceof Pair))
|
||||
return false;
|
||||
Pair p = (Pair)o;
|
||||
if ((p.o1 == null) ? (this.o1 == null) : (this.o1 != null && p.o1.equals(this.o1)))
|
||||
if ((p.o2 == null) ? (this.o2 == null) : (this.o2 != null && p.o2.equals(this.o2)));
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "(" + String.valueOf(this.o1) + ", " + String.valueOf(this.o2) + ")";
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
public interface ProtectionDomainFactory {
|
||||
ProtectionDomain getProtectionDomain(ClassLoader paramClassLoader);
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
public class SingleProtectionDomainFactory implements ProtectionDomainFactory {
|
||||
private final ProtectionDomain protectionDomain;
|
||||
|
||||
public SingleProtectionDomainFactory(ProtectionDomain protectionDomain) {
|
||||
this.protectionDomain = protectionDomain;
|
||||
}
|
||||
|
||||
public ProtectionDomain getProtectionDomain(ClassLoader classloader) {
|
||||
return this.protectionDomain;
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package net.sf.jasperreports.engine.util;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class ThreadLocalStack {
|
||||
private final ThreadLocal threadStack = new ThreadLocal();
|
||||
|
||||
public void push(Object o) {
|
||||
LinkedList stack = this.threadStack.get();
|
||||
if (stack == null) {
|
||||
stack = new LinkedList();
|
||||
this.threadStack.set(stack);
|
||||
}
|
||||
stack.addFirst(o);
|
||||
}
|
||||
|
||||
public Object top() {
|
||||
Object o = null;
|
||||
LinkedList stack = this.threadStack.get();
|
||||
if (stack != null && !stack.isEmpty())
|
||||
o = stack.getFirst();
|
||||
return o;
|
||||
}
|
||||
|
||||
public Object pop() {
|
||||
Object o = null;
|
||||
LinkedList stack = this.threadStack.get();
|
||||
if (stack != null)
|
||||
o = stack.removeFirst();
|
||||
return o;
|
||||
}
|
||||
|
||||
public boolean empty() {
|
||||
LinkedList stack = this.threadStack.get();
|
||||
return (stack == null || stack.isEmpty());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user