protected void setStatementMultiParameter(int parameterIndex, String parameterName, int valueIndex, Object value, JRPropertiesHolder properties) throws SQLException { if (value == null) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_MULTI_PARAMETERS_CANNOT_CONTAIN_NULL_VALUES, (Object[])null); } Class<?> type = value.getClass(); if (log.isDebugEnabled()) { log.debug("Parameter #" + parameterIndex + " (" + parameterName + "[" + valueIndex + "] of type " + type.getName() + "): " + value); } setStatementParameter(parameterIndex, type, value, properties); }
/** * Returns the text measurer factory given a set of properties. * * @param propertiesHolder the properties holder * @return the text measurer factory */ public JRTextMeasurerFactory getFactory(JRPropertiesHolder propertiesHolder) { String factoryClass = getTextMeasurerFactoryClass(propertiesHolder); try { @SuppressWarnings("deprecation") net.sf.jasperreports.engine.fill.JRTextMeasurerFactory factory = cache.getCachedInstance(factoryClass); if (factory instanceof JRTextMeasurerFactory) { return (JRTextMeasurerFactory)factory; } return new WrappingTextMeasurerFactory(factory); } catch (JRException e) { throw new JRRuntimeException(e); } }
/** * * */ private void writeProperties( JRPropertiesHolder propertiesHolder, String propertiesHolderName) { if (propertiesHolder.hasProperties()) { JRPropertiesMap propertiesMap = propertiesHolder.getPropertiesMap(); String[] propertyNames = propertiesMap.getPropertyNames(); if (propertyNames != null && propertyNames.length > 0) { write( "//properties\n"); for(int i = 0; i < propertyNames.length; i++) { String value = propertiesMap.getProperty(propertyNames[i]); if (value != null) { write( propertiesHolderName + ".setProperty(\"" + propertyNames[i] + "\", \"" + JRStringUtil.escapeJavaStringLiteral(value) + "\");\n"); } } write("\n"); } flush(); } }
/** * */ public BarcodeImageProducer getProducer(JRPropertiesHolder propertiesHolder) { String producerProperty = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(propertiesHolder, BarcodeImageProducer.PROPERTY_IMAGE_PRODUCER); String producerClass = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(propertiesHolder, BarcodeImageProducer.PROPERTY_PREFIX_IMAGE_PRODUCER + producerProperty); if (producerClass == null) { producerClass = producerProperty; } try { return imageProducerCache.getCachedInstance(producerClass); } catch (JRException e) { throw new JRRuntimeException(e); } }
/** * */ public QRCodeImageProducer getQRCodeProducer(JRPropertiesHolder propertiesHolder) { String producerProperty = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(propertiesHolder, BarcodeImageProducer.PROPERTY_IMAGE_PRODUCER); String producerClass = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(propertiesHolder, QRCodeImageProducer.PROPERTY_PREFIX_QRCODE_PRODUCER + producerProperty); if (producerClass == null) { producerClass = producerProperty; } try { return qrCodeProducerCache.getCachedInstance(producerClass); } catch (JRException e) { throw new JRRuntimeException(e); } }
@SuppressWarnings("unchecked") public JRPropertiesMapProperty(JRPropertiesHolder holder) { super( "properties", JRPropertiesMap.class, I18n.getString("JRPropertiesMapProperty.Property.Properties"),I18n.getString("JRPropertiesMapProperty.Property.Propertiesdetail"), true,true); setValue("canEditAsText", Boolean.FALSE); this.propertiesHolder = holder; if (holder instanceof JasperDesign) { setValue("reportProperties", Boolean.TRUE); setValue("hintType", com.jaspersoft.ireport.designer.sheet.editors.JRPropertyDialog.SCOPE_REPORT); } else if(holder instanceof JRTextField) { setValue("hintType", com.jaspersoft.ireport.designer.sheet.editors.JRPropertyDialog.SCOPE_TEXT_ELEMENT); } else if(holder instanceof JRElement) { setValue("hintType", com.jaspersoft.ireport.designer.sheet.editors.JRPropertyDialog.SCOPE_ELEMENT); } }
protected void setTimestamp(int parameterIndex, Object parameterValue, JRPropertiesHolder properties) throws SQLException { if (parameterValue == null) { statement.setNull(parameterIndex, Types.TIMESTAMP); } else { Calendar cal = getParameterCalendar(properties); if (log.isDebugEnabled()) { log.debug("setting timestamp parameter " + parameterIndex + " as " + parameterValue + " (" + ((java.sql.Timestamp) parameterValue).getTime() + ")" + " with calendar " + cal); } if (cal == null) { statement.setTimestamp(parameterIndex, (java.sql.Timestamp) parameterValue); } else { statement.setTimestamp(parameterIndex, (java.sql.Timestamp) parameterValue, cal); } } }
protected void setTime(int parameterIndex, Object parameterValue, JRPropertiesHolder properties) throws SQLException { if (parameterValue == null) { statement.setNull(parameterIndex, Types.TIME); } else { Calendar cal = getParameterCalendar(properties); if (log.isDebugEnabled()) { log.debug("setting time parameter " + parameterIndex + " as " + parameterValue + " (" + ((java.sql.Time) parameterValue).getTime() + ")" + " with calendar " + cal); } if (cal == null) { statement.setTime(parameterIndex, (java.sql.Time) parameterValue); } else { statement.setTime(parameterIndex, (java.sql.Time) parameterValue, cal); } } }
protected void setDate(int parameterIndex, Object parameterValue, JRPropertiesHolder properties) throws SQLException { if (parameterValue == null) { statement.setNull(parameterIndex, Types.DATE); } else { Calendar cal = getParameterCalendar(properties); if (log.isDebugEnabled()) { log.debug("setting date parameter " + parameterIndex + " as " + parameterValue + " (" + ((java.util.Date) parameterValue).getTime() + ")" + " with calendar " + cal); } if (cal == null) { statement.setDate(parameterIndex, new java.sql.Date(((java.util.Date)parameterValue).getTime())); } else { statement.setDate(parameterIndex, new java.sql.Date(((java.util.Date)parameterValue).getTime()), cal); } } }
protected Calendar getParameterCalendar(JRPropertiesHolder properties) { TimeZone tz; if (parametersTimeZoneOverride) { // if we have a parameter, use it tz = parametersTimeZone; } else { if (properties.hasProperties() && properties.getPropertiesMap().containsProperty( JRJdbcQueryExecuterFactory.PROPERTY_TIME_ZONE)) { // read the parameter level property String timezoneId = getPropertiesUtil().getProperty(properties, JRJdbcQueryExecuterFactory.PROPERTY_TIME_ZONE); if (log.isDebugEnabled()) { log.debug("parameter timezone property " + timezoneId); } tz = resolveTimeZone(timezoneId); } else { // dataset/default property tz = parametersTimeZone; } } // using default JVM locale for the calendar Calendar cal = tz == null ? null : Calendar.getInstance(tz); return cal; }
public void writeProperties(JRPropertiesHolder propertiesHolder) throws IOException { if (propertiesHolder.hasProperties()) { JRPropertiesMap propertiesMap = propertiesHolder.getPropertiesMap(); String[] propertyNames = propertiesMap.getPropertyNames(); if (propertyNames != null && propertyNames.length > 0) { for(int i = 0; i < propertyNames.length; i++) { String propertyName = propertyNames[i]; if (isPropertyToWrite(propertiesHolder, propertyName)) { writer.startElement(JRXmlConstants.ELEMENT_property, getNamespace()); writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, propertyName); String value = propertiesMap.getProperty(propertyName); if (value != null) { String encodedValue = JRStringUtil.encodeXmlAttribute(value); if ( isNewerVersionOrEqual(JRConstants.VERSION_6_4_0) && encodedValue.length() != value.length() ) { writer.writeCDATA(value); } else { writer.addAttribute(JRXmlConstants.ATTRIBUTE_value, encodedValue); } } writer.closeElement(); } } } } }
protected boolean isPropertyToWrite(JRPropertiesHolder propertiesHolder, String propertyName) { // currently the properties holder does not matter, we just look at the property name boolean toWrite = true; for (Pattern pattern : excludePropertiesPattern) { if (pattern.matcher(propertyName).matches()) { // excluding toWrite = false; break; } } return toWrite; }
@Override public Object createObject(Attributes atts) { JRPropertiesHolder propertiesHolder = (JRPropertiesHolder) digester.peek(); String name = atts.getValue(JRXmlConstants.ATTRIBUTE_name); String value = atts.getValue(JRXmlConstants.ATTRIBUTE_value); propertiesHolder.getPropertiesMap().setProperty(name, value); return new JRPropertyObject(propertiesHolder, name); }
@Override public void begin(String namespace, String name, Attributes attributes) { JRPropertiesHolder propertiesHolder = (JRPropertiesHolder) digester.peek(); String key = attributes.getValue(JRXmlConstants.ATTRIBUTE_name); String value = attributes.getValue(JRXmlConstants.ATTRIBUTE_value); propertiesHolder.getPropertiesMap().setProperty(key, value); }
protected String getTextMeasurerFactoryClass(JRPropertiesHolder propertiesHolder) { String factory = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(propertiesHolder, PROPERTY_TEXT_MEASURER_FACTORY); String factoryClassProperty = PROPERTY_TEXT_MEASURER_FACTORY + '.' + factory; String factoryClass = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(propertiesHolder, factoryClassProperty); if (factoryClass == null) { factoryClass = factory; } return factoryClass; }
public DelegatePropertiesHolder( JRPropertiesHolder propertiesHolder, JRPropertiesHolder parentProperties ) { this.propertiesHolder = propertiesHolder; this.parentProperties = parentProperties; }
@Override public JRPropertiesHolder getParentProperties() { return parentProperties == null ? (propertiesHolder == null ? null : propertiesHolder.getParentProperties()) : parentProperties; }
protected void exportProperties(JRPropertiesHolder propertiesHolder) throws IOException { if (propertiesHolder.hasProperties()) { JRPropertiesMap propertiesMap = propertiesHolder.getPropertiesMap(); String[] propertyNames = propertiesMap.getPropertyNames(); if (propertyNames != null && propertyNames.length > 0) { for(int i = 0; i < propertyNames.length; i++) { xmlWriter.startElement(JRXmlConstants.ELEMENT_property); xmlWriter.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, propertyNames[i]); String value = propertiesMap.getProperty(propertyNames[i]); if (value != null) { String encodedValue = JRStringUtil.encodeXmlAttribute(value); if ( isNewerVersionOrEqual(JRConstants.VERSION_6_4_0) && encodedValue.length() != value.length() ) { xmlWriter.writeCDATA(value); } else { xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_value, encodedValue); } } xmlWriter.closeElement(); } } } }
/** * */ public TextMeasurer(JasperReportsContext jasperReportsContext, JRCommonText textElement) { this.jasperReportsContext = jasperReportsContext; this.textElement = textElement; this.propertiesHolder = textElement instanceof JRPropertiesHolder ? (JRPropertiesHolder) textElement : null;//FIXMENOW all elements are now properties holders, so interfaces might be rearranged if (textElement.getDefaultStyleProvider() instanceof JRPropertiesHolder) { this.propertiesHolder = new DelegatePropertiesHolder( propertiesHolder, (JRPropertiesHolder)textElement.getDefaultStyleProvider() ); } if (textElement instanceof DynamicPropertiesHolder) { this.dynamicPropertiesHolder = (DynamicPropertiesHolder) textElement; // we can check this from the beginning this.hasDynamicIgnoreMissingFontProp = this.dynamicPropertiesHolder.hasDynamicProperty( JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT); this.hasDynamicSaveLineBreakOffsetsProp = this.dynamicPropertiesHolder.hasDynamicProperty( JRTextElement.PROPERTY_SAVE_LINE_BREAKS); } // read static property values JRPropertiesUtil propertiesUtil = JRPropertiesUtil.getInstance(jasperReportsContext); defaultIgnoreMissingFont = propertiesUtil.getBooleanProperty(propertiesHolder, JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT, false); defaultSaveLineBreakOffsets = propertiesUtil.getBooleanProperty(propertiesHolder, JRTextElement.PROPERTY_SAVE_LINE_BREAKS, false); Context measureContext = new Context(); simpleLineWrapper = new SimpleTextLineWrapper(); simpleLineWrapper.init(measureContext); complextLineWrapper = new ComplexTextLineWrapper(); complextLineWrapper.init(measureContext); }
/** * */ protected Object getPropertyValue(Method method, JRPropertiesHolder propertiesHolder) { Object value = null; ExporterProperty exporterProperty = method.getAnnotation(ExporterProperty.class); if (exporterProperty != null) { value = getPropertyValue(jasperReportsContext, propertiesHolder, exporterProperty, method.getReturnType()); } return value; }
public void createCommands(JasperDesign jDesign, JRPropertiesHolder[] pholder, JSSCompoundCommand c, List<ColumnCell> cells) { for (ColumnCell ccell : cells) { if (ccell.cell == null) continue; pholder[0] = ccell.cell; pholder[1] = ccell.column; ILayout layout = LayoutManager.getLayout(pholder, jDesign, null); Rectangle r = ccell.getBounds(); Dimension d = new Dimension(r.width, r.height); c.add(new LayoutCommand(ccell.cell, layout, d)); } }
/** * Read from the jrelement the local value of the measure unit * * @return the key of a local measure unit */ private String getLocalValue() { Object node = section.getElement().getValue(); if ((node instanceof JRPropertiesHolder) && isLocalPersistent) { return ((JRPropertiesHolder) node).getPropertiesMap().getProperty( LOCAL_MESURE_UNIT.concat(pDescriptor.getId().toString())); } else return null; }
private void setLocalValue(String newLocal) { localValue = newLocal; Object node = section.getElement().getValue(); if ((node instanceof JRPropertiesHolder) && isLocalPersistent) { ((JRPropertiesHolder) node).getPropertiesMap().setProperty( LOCAL_MESURE_UNIT.concat(pDescriptor.getId().toString()), newLocal); } }
@Override public void setData(APropertyNode pnode, Object value) { defaultValue = MReport.getMeasureUnit(jConfig, jConfig.getJasperDesign()); if (pnode.getValue() instanceof JRPropertiesHolder) defaultValue = PHolderUtil.getUnit((JRPropertiesHolder) pnode.getValue(), pDescriptor.getId().toString(), defaultValue); Number n = (Number) value; setDataNumber(n); }
public static Properties getProperities(ANode parent) { try { // JasperDesign jd = parent.getJasperDesign(); // String pcallout = jd.getProperty(MCallout.PROP_CALLOUT); JRPropertiesHolder pholder = getPropertiesHolder(parent); String pcallout = pholder.getPropertiesMap().getProperty(MCallout.PROP_CALLOUT); if (pcallout != null) { pcallout = pcallout.replaceAll("callouts.", "\ncallouts."); return FileUtils.load(pcallout); } } catch (IOException e) { e.printStackTrace(); } return new Properties(); }
private static JRPropertiesHolder getPropertiesHolder(ANode parent) { JRPropertiesHolder pholder = null; if (parent instanceof IContainerLayout) { JRPropertiesHolder[] pholders = ((IContainerLayout) parent).getPropertyHolder(); if (pholders != null) pholder = pholders[pholders.length - 1]; } if (pholder == null) pholder = parent.getJasperDesign(); return pholder; }
public Command getBandResizeCommand(MBand mband, JasperDesign jDesign) { JRDesignBand band = mband.getValue(); int w = jDesign.getPageWidth() - jDesign.getLeftMargin() - jDesign.getRightMargin(); // Check if the size is valid int maxHeight = BandResizeTracker.getMaxBandHeight(band, jDesign); if (band.getHeight() > maxHeight) { band.setHeight(maxHeight - 1); } Dimension d = new Dimension(w, band.getHeight()); ILayout layout = LayoutManager.getLayout(new JRPropertiesHolder[] { band }, jDesign, null); return new LayoutCommand(band, layout, d); }
@Override public void execute() { if (jrGroup != null && jrGroup.getChildren() != null) { elementPosition = jrGroup.getChildren().indexOf(jrElement); if (jrGroup instanceof JRDesignElementGroup) { ((JRDesignElementGroup) jrGroup).removeElement(jrElement); } else if (jrGroup instanceof JRDesignFrame) { ((JRDesignFrame) jrGroup).removeElement(jrElement); } if (jrGroup instanceof JRPropertiesHolder) { String uuid = null; if (jrGroup instanceof JRBaseElement) uuid = ((JRBaseElement) jrGroup).getUUID().toString(); Dimension d = new Dimension(0, 0); if (jrGroup instanceof JRCommonElement) { JRCommonElement jce = (JRCommonElement) jrGroup; // Commented for back-compatibility in 3.6. // Replaced with the following line. // d.setSize(jce.getWidth(), jce.getHeight()); d.setSize(new Dimension(jce.getWidth(), jce.getHeight())); } if (jrGroup instanceof JRDesignBand) { int w = jDesign.getPageWidth() - jDesign.getLeftMargin() - jDesign.getRightMargin(); // Commented for back-compatibility in 3.6. // Replaced with the following line. // d.setSize(w, ((JRDesignBand) jrGroup).getHeight()); d.setSize(new Dimension(w, ((JRDesignBand) jrGroup).getHeight())); } if (lCmd == null) { ILayout layout = LayoutManager.getLayout(pholder, jDesign, uuid); lCmd = new LayoutCommand(jrGroup, layout, d); lCmd.execute(); } } } }
@Override public void execute() { if (jrElement != null) { oldBounds = new Rectangle(jrElement.getX(), jrElement.getY(), jrElement.getWidth(), jrElement.getHeight()); // check position, // if top-left corner outside the bottom bar bands, move to bottom band // if bottom-left corner outside the top bar, move to top band int y = jrElement.getY() + newBounds.y - parentBounds.y; int x = jrElement.getX() + newBounds.x - parentBounds.x; jrElement.setX(x); jrElement.setY(y); jrElement.setWidth(newBounds.width); jrElement.setHeight(newBounds.height); if (destValue instanceof JRPropertiesHolder && jrGroup != null) { String uuid = null; if (destValue instanceof JRBaseElement) uuid = ((JRBaseElement) destValue).getUUID().toString(); if (destValue instanceof JRCommonElement) { JRCommonElement jce = (JRCommonElement) destValue; // Commented for back-compatibility in 3.6. // Replaced with the following line. // d.setSize(jce.getWidth(), jce.getHeight()); d.setSize(new Dimension(jce.getWidth(), jce.getHeight())); } if (destValue instanceof JRDesignBand) { int w = jrDesign.getPageWidth() - jrDesign.getLeftMargin() - jrDesign.getRightMargin(); d = new Dimension(w, ((JRDesignBand) destValue).getHeight()); } if (lCmd == null) { ILayout layout = LayoutManager.getLayout(pholder, jrDesign, uuid); lCmd = new LayoutCommand(jrGroup, layout, d); } lCmd.execute(); } } }
@Override public JRPropertiesHolder getParentProperties() { return null; }
/** * */ public JRPropertyObject(JRPropertiesHolder propertiesHolder, String propertyName) { this.propertiesHolder = propertiesHolder; this.propertyName = propertyName; }