1 28 package net.sf.jasperreports.engine.xml; 29 30 import net.sf.jasperreports.engine.JasperPrint; 31 import net.sf.jasperreports.engine.base.JRBasePrintText; 32 33 import org.xml.sax.Attributes ; 34 35 36 40 public class JRPrintTextFactory extends JRBaseFactory 41 { 42 43 44 47 private static final String ATTRIBUTE_textAlignment = "textAlignment"; 48 private static final String ATTRIBUTE_verticalAlignment = "verticalAlignment"; 49 private static final String ATTRIBUTE_rotation = "rotation"; 50 private static final String ATTRIBUTE_runDirection = "runDirection"; 51 private static final String ATTRIBUTE_textHeight = "textHeight"; 52 private static final String ATTRIBUTE_lineSpacing = "lineSpacing"; 53 private static final String ATTRIBUTE_isStyledText = "isStyledText"; 54 private static final String ATTRIBUTE_lineSpacingFactor = "lineSpacingFactor"; 55 private static final String ATTRIBUTE_leadingOffset = "leadingOffset"; 56 private static final String ATTRIBUTE_hyperlinkType = "hyperlinkType"; 57 private static final String ATTRIBUTE_hyperlinkTarget = "hyperlinkTarget"; 58 private static final String ATTRIBUTE_anchorName = "anchorName"; 59 private static final String ATTRIBUTE_hyperlinkReference = "hyperlinkReference"; 60 private static final String ATTRIBUTE_hyperlinkAnchor = "hyperlinkAnchor"; 61 private static final String ATTRIBUTE_hyperlinkPage = "hyperlinkPage"; 62 public static final String ATTRIBUTE_hyperlinkTooltip = "hyperlinkTooltip"; 63 private static final String ATTRIBUTE_bookmarkLevel = "bookmarkLevel"; 64 public static final String ATTRIBUTE_valueClass = "valueClass"; 65 public static final String ATTRIBUTE_pattern = "pattern"; 66 public static final String ATTRIBUTE_formatFactoryClass = "formatFactoryClass"; 67 public static final String ATTRIBUTE_locale = "locale"; 68 public static final String ATTRIBUTE_timezone = "timezone"; 69 70 71 74 public Object createObject(Attributes atts) 75 { 76 JasperPrint jasperPrint = (JasperPrint)digester.peek(digester.getCount() - 2); 77 78 JRBasePrintText text = new JRBasePrintText(jasperPrint.getDefaultStyleProvider()); 79 80 Byte horizontalAlignment = (Byte )JRXmlConstants.getHorizontalAlignMap().get(atts.getValue(ATTRIBUTE_textAlignment)); 81 if (horizontalAlignment != null) 82 { 83 text.setHorizontalAlignment(horizontalAlignment); 84 } 85 86 Byte verticalAlignment = (Byte )JRXmlConstants.getVerticalAlignMap().get(atts.getValue(ATTRIBUTE_verticalAlignment)); 87 if (verticalAlignment != null) 88 { 89 text.setVerticalAlignment(verticalAlignment); 90 } 91 92 Byte rotation = (Byte )JRXmlConstants.getRotationMap().get(atts.getValue(ATTRIBUTE_rotation)); 93 if (rotation != null) 94 { 95 text.setRotation(rotation); 96 } 97 98 Byte runDirection = (Byte )JRXmlConstants.getRunDirectionMap().get(atts.getValue(ATTRIBUTE_runDirection)); 99 if (runDirection != null) 100 { 101 text.setRunDirection(runDirection.byteValue()); 102 } 103 104 String textHeight = atts.getValue(ATTRIBUTE_textHeight); 105 if (textHeight != null && textHeight.length() > 0) 106 { 107 text.setTextHeight(Float.parseFloat(textHeight)); 108 } 109 110 Byte lineSpacing = (Byte )JRXmlConstants.getLineSpacingMap().get(atts.getValue(ATTRIBUTE_lineSpacing)); 111 if (lineSpacing != null) 112 { 113 text.setLineSpacing(lineSpacing); 114 } 115 116 String isStyledText = atts.getValue(ATTRIBUTE_isStyledText); 117 if (isStyledText != null && isStyledText.length() > 0) 118 { 119 text.setStyledText(Boolean.valueOf(isStyledText)); 120 } 121 122 String lineSpacingFactor = atts.getValue(ATTRIBUTE_lineSpacingFactor); 123 if (lineSpacingFactor != null && lineSpacingFactor.length() > 0) 124 { 125 text.setLineSpacingFactor(Float.parseFloat(lineSpacingFactor)); 126 } 127 128 String leadingOffset = atts.getValue(ATTRIBUTE_leadingOffset); 129 if (leadingOffset != null && leadingOffset.length() > 0) 130 { 131 text.setLeadingOffset(Float.parseFloat(leadingOffset)); 132 } 133 134 String hyperlinkType = atts.getValue(ATTRIBUTE_hyperlinkType); 135 if (hyperlinkType != null) 136 { 137 text.setLinkType(hyperlinkType); 138 } 139 140 Byte hyperlinkTarget = (Byte )JRXmlConstants.getHyperlinkTargetMap().get(atts.getValue(ATTRIBUTE_hyperlinkTarget)); 141 if (hyperlinkTarget != null) 142 { 143 text.setHyperlinkTarget(hyperlinkTarget.byteValue()); 144 } 145 146 text.setAnchorName(atts.getValue(ATTRIBUTE_anchorName)); 147 text.setHyperlinkReference(atts.getValue(ATTRIBUTE_hyperlinkReference)); 148 text.setHyperlinkAnchor(atts.getValue(ATTRIBUTE_hyperlinkAnchor)); 149 150 String hyperlinkPage = atts.getValue(ATTRIBUTE_hyperlinkPage); 151 if (hyperlinkPage != null) 152 { 153 text.setHyperlinkPage(new Integer (hyperlinkPage)); 154 } 155 156 text.setHyperlinkTooltip(atts.getValue(ATTRIBUTE_hyperlinkTooltip)); 157 158 String bookmarkLevelAttr = atts.getValue(ATTRIBUTE_bookmarkLevel); 159 if (bookmarkLevelAttr != null) 160 { 161 text.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr)); 162 } 163 164 String valueClass = atts.getValue(ATTRIBUTE_valueClass); 165 if (valueClass != null) 166 { 167 text.setValueClassName(valueClass); 168 } 169 170 String pattern = atts.getValue(ATTRIBUTE_pattern); 171 if (pattern != null) 172 { 173 text.setPattern(pattern); 174 } 175 176 String formatFactoryClass = atts.getValue(ATTRIBUTE_formatFactoryClass); 177 if (formatFactoryClass != null) 178 { 179 text.setFormatFactoryClass(formatFactoryClass); 180 } 181 182 String locale = atts.getValue(ATTRIBUTE_locale); 183 if (locale != null) 184 { 185 text.setLocaleCode(locale); 186 } 187 188 String timezone = atts.getValue(ATTRIBUTE_timezone); 189 if (timezone != null) 190 { 191 text.setTimeZoneId(timezone); 192 } 193 194 return text; 195 } 196 197 198 } 199 | Popular Tags |