@Override public Object getPropertyValue(Object id) { JRDesignGenericElement jrElement = (JRDesignGenericElement) getValue(); if (id.equals(JRDesignGenericElement.PROPERTY_EVALUATION_TIME)) return evaluationTimeD.getEnumValue(jrElement.getEvaluationTimeValue()); if (id.equals(JRDesignGenericElement.PROPERTY_EVALUATION_GROUP_NAME)) return jrElement.getEvaluationGroupName(); JRGenericElementType genericType = jrElement.getGenericType(); if (genericType != null) { if (id.equals(PROPERTY_NAME)) return genericType.getName(); if (id.equals(PROPERTY_NAMESPACE)) return genericType.getNamespace(); } if (id.equals(JRDesignGenericElement.PROPERTY_PARAMETERS)) { if (propertyDTO == null) { propertyDTO = new ParameterDTO(); propertyDTO.setJasperDesign(getJasperDesign()); propertyDTO.setValue(jrElement.getParameters()); } return propertyDTO; } return super.getPropertyValue(id); }
protected static void addGenericElementRules(Digester digester) { String genericElementPattern = "*/" + JRXmlConstants.ELEMENT_genericElement; digester.addFactoryCreate(genericElementPattern, JRGenericElementFactory.class); digester.addSetNext(genericElementPattern, "addElement", JRDesignElement.class.getName()); String genericElementTypePattern = genericElementPattern + "/" + JRXmlConstants.ELEMENT_genericElementType; digester.addFactoryCreate(genericElementTypePattern, JRGenericElementTypeFactory.class); digester.addSetNext(genericElementTypePattern, "setGenericType", JRGenericElementType.class.getName()); String genericElementParameterPattern = genericElementPattern + "/" + JRXmlConstants.ELEMENT_genericElementParameter; digester.addFactoryCreate(genericElementParameterPattern, JRGenericElementParameterFactory.class); digester.addSetNext(genericElementParameterPattern, "addParameter", JRGenericElementParameter.class.getName()); String genericElementParameterExpressionPattern = genericElementParameterPattern + "/" + JRXmlConstants.ELEMENT_genericElementParameter_valueExpression; @SuppressWarnings("deprecation") Class<?> depArbitraryExprFactory = JRExpressionFactory.ArbitraryExpressionFactory.class; digester.addFactoryCreate(genericElementParameterExpressionPattern, depArbitraryExprFactory); digester.addSetNext(genericElementParameterExpressionPattern, "setValueExpression", JRExpression.class.getName()); digester.addCallMethod(genericElementParameterExpressionPattern, "setText", 0); }
@Override public Object createObject(Attributes attrs) throws Exception { String namespace = attrs.getValue(JRXmlConstants.ATTRIBUTE_namespace); String name = attrs.getValue(JRXmlConstants.ATTRIBUTE_name); return new JRGenericElementType(namespace, name); }
/** * * protected XmlNamespace getNamespace() { return JASPERREPORTS_NAMESPACE; } /** * */ public void writeGenericElement( JRGenericElement element, String elementName) { write( "JRDesignGenericElement " + elementName + " = new JRDesignGenericElement(jasperDesign);\n"); write( elementName + ".setEvaluationTime({0});\n", element.getEvaluationTimeValue(), EvaluationTimeEnum.NOW); write( elementName + ".setEvaluationGroup(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(element.getEvaluationGroupName())); writeReportElement( element, elementName); JRGenericElementType printKey = element.getGenericType(); // JRGenericElementType t = new JRGenericElementType(printKey.getNamespace(), printKey.getName()); write( "JRGenericElementType " + elementName + "Type = new JRGenericElementType(\"" + JRStringUtil.escapeJavaStringLiteral(printKey.getNamespace()) + "\", \"" + JRStringUtil.escapeJavaStringLiteral(printKey.getName()) + "\");\n"); write( elementName + ".setGenericType(" + elementName + "Type);\n"); flush();//genericElementType JRGenericElementParameter[] params = element.getParameters(); for (int i = 0; i < params.length; i++) { JRGenericElementParameter param = params[i]; String paramName = elementName + "Parameter" + i; write( "JRDesignGenericElementParameter " + paramName + " = new JRDesignGenericElementParameter();\n"); write( paramName + ".setName(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(param.getName())); write( paramName + ".setSkipWhenEmpty({0});\n", param.isSkipWhenEmpty(), false); writeExpression(param.getValueExpression(), paramName, "ValueExpression"); write( elementName + ".addParameter({0});\n", paramName); flush();//genericElementParameter } flush();//genericElement }
/** * Sets the type of the generic element. * * @param genericType the type of the element. * @see #getGenericType() */ public void setGenericType(JRGenericElementType genericType) { Object old = this.genericType; this.genericType = genericType; getEventSupport().firePropertyChange(PROPERTY_GENERIC_TYPE, old, this.genericType); }
/** * Creates a generic print element template. * * @param origin the origin of the elements that will use the template * @param defaultStyleProvider the style provider to be used for the elements * @param genericType the type of the generic elements */ public JRTemplateGenericElement(JROrigin origin, JRDefaultStyleProvider defaultStyleProvider, JRGenericElementType genericType) { super(origin, defaultStyleProvider); setGenericType(genericType); }
/** * Creates a generic print element template. * * @param origin the origin of the elements that will use the template * @param defaultStyleProvider the style provider to be used for the elements * @param element an element to copy basic elements from * @param genericType the type of the generic elements */ public JRTemplateGenericElement(JROrigin origin, JRDefaultStyleProvider defaultStyleProvider, JRElement element, JRGenericElementType genericType) { super(origin, defaultStyleProvider); setElement(element); setGenericType(genericType); }
@Override public void setPropertyValue(Object id, Object value) { JRDesignGenericElement jrElement = (JRDesignGenericElement) getValue(); JRGenericElementType genericType = jrElement.getGenericType(); if (id.equals(JRDesignGenericElement.PROPERTY_EVALUATION_TIME)) jrElement.setEvaluationTime((EvaluationTimeEnum) evaluationTimeD.getEnumValue(value)); else if (id.equals(JRDesignGenericElement.PROPERTY_EVALUATION_GROUP_NAME)) jrElement.setEvaluationGroupName((String) value); else if (id.equals(JRDesignGenericElement.PROPERTY_PARAMETERS)) { if (value instanceof ParameterDTO) { ParameterDTO v = (ParameterDTO) value; if (jrElement.getParameters() != null) for (JRGenericElementParameter prm : jrElement.getParameters()) jrElement.removeParameter(prm); for (JRGenericElementParameter param : v.getValue()) jrElement.addParameter(param); propertyDTO = v; } // FIXME: in JR rewrite hashCode to work with null values for namespace and name } else if (id.equals(PROPERTY_NAME)) { String namespace = genericType != null ? genericType.getNamespace() : ""; jrElement.setGenericType(new JRGenericElementType(namespace, (String) value)); } else if (id.equals(PROPERTY_NAMESPACE)) { String name = genericType != null ? genericType.getName() : ""; jrElement.setGenericType(new JRGenericElementType((String) value, name)); } super.setPropertyValue(id, value); }
@Override public JRDesignElement createJRElement(JasperDesign jasperDesign) { JRDesignGenericElement el = new JRDesignGenericElement(jasperDesign); el.setGenericType(new JRGenericElementType("namespace", "name")); DefaultManager.INSTANCE.applyDefault(this.getClass(), el); return el; }
@Override public JRDesignElement createReportElement(JasperDesign jd) { JRDesignGenericElement element = new JRDesignGenericElement(jd); JRGenericElementType type = new JRGenericElementType("http://www.somenamespace.com", "someName"); element.setGenericType(type); element.setWidth(300); element.setHeight(200); return element; }
@Override public void setString(String name) { String namespace = ""; if (element.getGenericType() != null) { namespace = element.getGenericType().getNamespace(); } JRGenericElementType type = new JRGenericElementType(namespace,name); element.setGenericType(type); }
@Override public void setString(String namespace) { String name = ""; if (element.getGenericType() != null) { name = element.getGenericType().getName(); } JRGenericElementType type = new JRGenericElementType(namespace,name); element.setGenericType(type); }
@Override public JRGenericElementType getGenericType() { return genericType; }
public void writeGenericElement(JRGenericElement element) throws IOException { if(isNewerVersionOrEqual(JRConstants.VERSION_3_1_0)) { writer.startElement(JRXmlConstants.ELEMENT_genericElement, getNamespace()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_evaluationTime, element.getEvaluationTimeValue(), EvaluationTimeEnum.NOW); if (element.getEvaluationGroupName() != null) { writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_evaluationGroup, element.getEvaluationGroupName()); } writeReportElement(element); writer.startElement(JRXmlConstants.ELEMENT_genericElementType); JRGenericElementType printKey = element.getGenericType(); if (printKey != null) { writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_namespace, printKey.getNamespace()); writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, printKey.getName()); } writer.closeElement();//genericElementType JRGenericElementParameter[] params = element.getParameters(); for (int i = 0; i < params.length; i++) { JRGenericElementParameter param = params[i]; writer.startElement(JRXmlConstants.ELEMENT_genericElementParameter); writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, param.getName()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_skipWhenNull, param.isSkipWhenEmpty(), false); JRExpression valueExpression = param.getValueExpression(); if (valueExpression != null) { writeExpression(JRXmlConstants.ELEMENT_genericElementParameter_valueExpression, valueExpression, true, Object.class.getName()); } writer.closeElement();//genericElementParameter } writer.closeElement();//genericElement } }
protected void verifyGenericElement(JRGenericElement element) { verifyReportElement(element); if (element.getEvaluationTimeValue() == EvaluationTimeEnum.GROUP) { String groupName = element.getEvaluationGroupName(); if (groupName == null) { addBrokenRule("Evaluation group not set for generic element", element); } else { if (!jasperDesign.getGroupsMap().containsKey(groupName)) { addBrokenRule("Generic element evaluation group " + groupName + " not found in report", element); } } } JRGenericElementType type = element.getGenericType(); if (type == null) { addBrokenRule("No type set for generic element", element); } else { if (type.getNamespace() == null) { addBrokenRule("No namespace set for generic element type", type); } if (type.getName() == null) { addBrokenRule("No name set for generic element type", type); } } JRGenericElementParameter[] parameters = element.getParameters(); for (int i = 0; i < parameters.length; i++) { JRGenericElementParameter parameter = parameters[i]; if (parameter.getName() == null) { addBrokenRule("No name set for generic element parameter", parameter); } } }
/** * */ protected void exportGenericElement(JRGenericPrintElement element) throws IOException { GenericElementXmlHandler handler = (GenericElementXmlHandler) GenericElementHandlerEnviroment.getInstance(jasperReportsContext).getElementHandler( element.getGenericType(), getExporterKey()); if (handler != null) { handler.exportElement(exporterContext, element); } else { xmlWriter.startElement(JRXmlConstants.ELEMENT_genericElement); exportReportElement(element); JRGenericElementType genericType = element.getGenericType(); xmlWriter.startElement(JRXmlConstants.ELEMENT_genericElementType); xmlWriter.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_namespace, genericType.getNamespace()); xmlWriter.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, genericType.getName()); xmlWriter.closeElement();//genericElementType Set<String> names = element.getParameterNames(); for (Iterator<String> it = names.iterator(); it.hasNext();) { String name = it.next(); Object value = element.getParameterValue(name); xmlWriter.startElement(JRXmlConstants.ELEMENT_genericElementParameter); xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_name, name); if (value != null) { String valueClass = value.getClass().getName(); // check if there's a builtin serializer for the value boolean builtinSerialization = JRValueStringUtils.hasSerializer(valueClass); if (!builtinSerialization) { // try XML handlers, if none works then default back to the builtin serialization builtinSerialization = !XmlValueHandlerUtils.instance().writeToXml(value, this); } if (builtinSerialization) { String data = JRValueStringUtils.serialize(valueClass, value); xmlWriter.startElement(JRXmlConstants.ELEMENT_genericElementParameterValue); xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_class, valueClass); xmlWriter.writeCDATA(data); xmlWriter.closeElement();//genericElementParameterValue } } xmlWriter.closeElement();//genericElementParameter } xmlWriter.closeElement();//genericElement } }
@Override public JRGenericElementType getGenericType() { return ((JRGenericElement) parent).getGenericType(); }
/** * Returns the generic type specified by the element template. * * @see JRTemplateGenericElement#getGenericType() */ @Override public JRGenericElementType getGenericType() { return ((JRTemplateGenericElement) template).getGenericType(); }
protected JRTemplateGenericElement genericTemplate() { JRGenericElementType type = new JRGenericElementType(JRXmlConstants.JASPERREPORTS_NAMESPACE, "test"); JRTemplateGenericElement template = new JRTemplateGenericElement(null, null, type); return template; }
/** * Returns a handler for a generic print element type and an exporter * key. * * <p> * The method first locates a * {@link GenericElementHandlerBundle handler bundle} that matches the type * namespace, and then uses * {@link GenericElementHandlerBundle#getHandler(String, String)} to * resolve an export handler. * * @param type the generic element type * @param exporterKey the exporter key * @return a generic print element handler * @throws JRRuntimeException if a handler does not exist for the * combination of element type and exporter key */ public GenericElementHandler getElementHandler(JRGenericElementType type, String exporterKey) { Map<String,GenericElementHandlerBundle> handlerBundles = getBundles(); GenericElementHandlerBundle bundle = handlerBundles.get(type.getNamespace()); if (bundle == null) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_HANDLERS_NOT_FOUND_FOR_NAMESPACE, new Object[]{type.getNamespace()}); } return bundle.getHandler(type.getName(), exporterKey); }
/** * Sets the type of this element. * * @param genericType the type of the element * @see #getGenericType() */ public void setGenericType(JRGenericElementType genericType) { this.genericType = genericType; }
/** * Returns the type of the generic elements that use this template. * * @return the type of the generic elements */ public JRGenericElementType getGenericType() { return genericType; }
/** * Sets the type of the generic elements that use this template. * * @param genericType the generic type */ public void setGenericType(JRGenericElementType genericType) { this.genericType = genericType; }