def _transform_jrxml_duplicate(dups, element, level): result = {} if (tag_name(element.tag) == 'property' and element.get('name').find(PROPERTY_KEY) == 0): dup_spec = element.get('name')[len(PROPERTY_KEY):] dup_id, prop_name = dup_spec.split('.') result.setdefault(dup_id, []).append( PropertySpecification(name=prop_name, value=element.get('value'), origin=element)) for child_element in element.iterchildren(): sub_result = _transform_jrxml_duplicate(dups, child_element, level + 1) for dup_id, prop_list in sub_result.iteritems(): parent_prop_list = result.setdefault(dup_id, []) for prop in prop_list: parent_prop_list.append(prop) if result and tag_name(element.tag) != 'property': _remove_dup_properties(element, result.itervalues()) if tag_name(element.tag) in DUPLICABLE_ELEMENTS: dups.extend(_duplicate(element, result)) result = {} return result
def transform_jrxml_dont_underline_leading_space(jrxml, jrxml_opts): if not jrxml_opts.dont_underline_leading_space: return effective_markup_dict = get_effective_markup_dict(jrxml) root = jrxml.getroot() install_side_effect_var(root) for candidate_element in root.xpath('//jr:textField|//jr:staticText', namespaces=JRXML_NS): (processing_strategy, style_name) = get_processing_strategy(candidate_element, effective_markup_dict) if processing_strategy is PROCESSING_STRATEGIES['N/A']: continue if tag_name(candidate_element.tag) == 'staticText': candidate_element = staticText_to_textFieldExpression( candidate_element) text_field = candidate_element process_text_field( processing_strategy, text_field, style_name and effective_markup_dict[style_name] or None)
def transform_jrxml_dont_underline_leading_space(jrxml, jrxml_opts): if not jrxml_opts.dont_underline_leading_space: return effective_markup_dict = get_effective_markup_dict(jrxml) root = jrxml.getroot() install_side_effect_var(root) for candidate_element in root.xpath('//jr:textField|//jr:staticText', namespaces=JRXML_NS): (processing_strategy, style_name) = get_processing_strategy(candidate_element, effective_markup_dict) if processing_strategy is PROCESSING_STRATEGIES['N/A']: continue if tag_name(candidate_element.tag) == 'staticText': candidate_element = staticText_to_textFieldExpression(candidate_element) text_field = candidate_element process_text_field(processing_strategy, text_field, style_name and effective_markup_dict[style_name] or None)
def _validate_cell_contents(props): if len(props) == 0: return if len(filter(lambda el: tag_name(el.getparent().getparent().tag) != 'frame', props)) != 0: raise Exception('unframed cell content') if len(set(map(lambda el: el.getparent().get('style', None), props))) != 1: raise Exception('ununiform style') if len(set(map(lambda el: el.getparent().get('x'), props))) != 1: raise Exception('ununiform x') if len(set(map(lambda el: el.getparent().get('y'), props))) != 1: raise Exception('ununiform y') if len(set(map(lambda el: el.getparent().get('width'), props))) != 1: raise Exception('ununiform width') if len(set(map(lambda el: el.getparent().get('height'), props))) != 1: raise Exception('ununiform height')
def _set_prop_printWhenExpression(element, value): if tag_name(element.tag) not in ELEMENTS_HAVING_PRINT_WHEN_EXPRESSION: raise Exception("printWhenExpression cannot be set on %s" % tag_name(element.tag)) xpath_expr = "./jr:printWhenExpression" print_when_expr_parent = element if tag_name(element.tag) in ELEMENTS_HAVING_REPORT_ELEMENT: xpath_expr = xpath_expr[:2] + "jr:reportElement/" + xpath_expr[2:] print_when_expr_parent = element.xpath("./jr:reportElement", namespaces=JRXML_NS)[0] print_when_exprs = element.xpath(xpath_expr, namespaces=JRXML_NS) if len(print_when_exprs) == 0: print_when_expr = etree.SubElement(print_when_expr_parent, JR + "printWhenExpression") else: print_when_expr = print_when_exprs[0] print_when_expr.text = etree.CDATA(value)
def _set_prop_printWhenExpression(element, value): if tag_name(element.tag) not in ELEMENTS_HAVING_PRINT_WHEN_EXPRESSION: raise Exception('printWhenExpression cannot be set on %s' % tag_name(element.tag)) xpath_expr = './jr:printWhenExpression' print_when_expr_parent = element if tag_name(element.tag) in ELEMENTS_HAVING_REPORT_ELEMENT: xpath_expr = xpath_expr[:2] + 'jr:reportElement/' + xpath_expr[2:] print_when_expr_parent = element.xpath('./jr:reportElement', namespaces=JRXML_NS)[0] print_when_exprs = element.xpath(xpath_expr, namespaces=JRXML_NS) if len(print_when_exprs) == 0: print_when_expr = etree.SubElement(print_when_expr_parent, JR + 'printWhenExpression') else: print_when_expr = print_when_exprs[0] print_when_expr.text = etree.CDATA(value)
def _duplicate(element, dup_specs): duplicates = [] for dup_id, prop_list in dup_specs.iteritems(): dup = deepcopy(element) duplicates.append((element.getparent(), dup)) for prop in prop_list: if prop.name in _available_property_setters: _available_property_setters[prop.name](dup, prop.value) else: raise Exception( "Don't know how to set property '%s' on %s" " (please develop _cjr_transformer_duplicate_prop_setter_%s.py)" % (prop.name, tag_name(element.tag), prop.name)) return duplicates
def _transform_jrxml_duplicate(dups, element, level): result = {} if tag_name(element.tag) == "property" and element.get("name").find(PROPERTY_KEY) == 0: dup_spec = element.get("name")[len(PROPERTY_KEY) :] dup_id, prop_name = dup_spec.split(".") result.setdefault(dup_id, []).append( PropertySpecification(name=prop_name, value=element.get("value"), origin=element) ) for child_element in element.iterchildren(): sub_result = _transform_jrxml_duplicate(dups, child_element, level + 1) for dup_id, prop_list in sub_result.iteritems(): parent_prop_list = result.setdefault(dup_id, []) for prop in prop_list: parent_prop_list.append(prop) if result and tag_name(element.tag) != "property": _remove_dup_properties(element, result.itervalues()) if tag_name(element.tag) in DUPLICABLE_ELEMENTS: dups.extend(_duplicate(element, result)) result = {} return result
def _duplicate(element, dup_specs): duplicates = [] for dup_id, prop_list in dup_specs.iteritems(): dup = deepcopy(element) duplicates.append((element.getparent(), dup)) for prop in prop_list: if prop.name in _available_property_setters: _available_property_setters[prop.name](dup, prop.value) else: raise Exception( "Don't know how to set property '%s' on %s" " (please develop _cjr_transformer_duplicate_prop_setter_%s.py)" % (prop.name, tag_name(element.tag), prop.name) ) return duplicates
def _validate_cell_contents(props): if len(props) == 0: return if len( filter( lambda el: tag_name(el.getparent().getparent().tag) != 'frame', props)) != 0: raise Exception('unframed cell content') if len(set(map(lambda el: el.getparent().get('style', None), props))) != 1: raise Exception('ununiform style') if len(set(map(lambda el: el.getparent().get('x'), props))) != 1: raise Exception('ununiform x') if len(set(map(lambda el: el.getparent().get('y'), props))) != 1: raise Exception('ununiform y') if len(set(map(lambda el: el.getparent().get('width'), props))) != 1: raise Exception('ununiform width') if len(set(map(lambda el: el.getparent().get('height'), props))) != 1: raise Exception('ununiform height')
def _set_prop_isStretchWithOverflow(element, value): if tag_name(element.tag) != 'textField': raise Exception('isStretchWithOverflow can only be applied to textField') element.set('isStretchWithOverflow', value)
def _set_prop_isStretchWithOverflow(element, value): if tag_name(element.tag) != 'textField': raise Exception( 'isStretchWithOverflow can only be applied to textField') element.set('isStretchWithOverflow', value)