Java Code Examples for net.sf.jasperreports.engine.JasperPrint#getStylesMap()

The following examples show how to use net.sf.jasperreports.engine.JasperPrint#getStylesMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JRPrintStyleFactory.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void setParentStyle(JRDesignStyle currentStyle, String parentStyleName)
{
	JRPrintXmlLoader printXmlLoader = (JRPrintXmlLoader) digester.peek(digester.getCount() - 1);
	JasperPrint jasperPrint = (JasperPrint) digester.peek(digester.getCount() - 2);
	Map<String,JRStyle> stylesMap = jasperPrint.getStylesMap();

	if (!stylesMap.containsKey(parentStyleName))
	{
		printXmlLoader.addError(
			new JRRuntimeException(
				EXCEPTION_MESSAGE_KEY_UNKNOWN_REPORT_STYLE,
				new Object[]{parentStyleName}
			)
		);
	}
	
	JRStyle parent = stylesMap.get(parentStyleName);
	currentStyle.setParentStyle(parent);
}
 
Example 2
Source File: JRPrintElementFactory.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Object createObject(Attributes atts)
{
	JRPrintXmlLoader printXmlLoader = (JRPrintXmlLoader)digester.peek(digester.getCount() - 1);
	JasperPrint jasperPrint = (JasperPrint)digester.peek(digester.getCount() - 2);
	JRBasePrintElement element = (JRBasePrintElement)digester.peek();

	String key = atts.getValue(JRXmlConstants.ATTRIBUTE_key);
	if (key != null)
	{
		element.setKey(key);
	}
	
	ModeEnum mode = ModeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_mode));
	if (mode != null)
	{
		element.setMode(mode);
	}
	
	String uuid = atts.getValue(JRXmlConstants.ATTRIBUTE_uuid);
	if (uuid != null)
	{
		element.setUUID(UUID.fromString(uuid));
	}

	String x = atts.getValue(JRXmlConstants.ATTRIBUTE_x);
	if (x != null && x.length() > 0)
	{
		element.setX(Integer.parseInt(x));
	}

	String y = atts.getValue(JRXmlConstants.ATTRIBUTE_y);
	if (y != null && y.length() > 0)
	{
		element.setY(Integer.parseInt(y));
	}

	String width = atts.getValue(JRXmlConstants.ATTRIBUTE_width);
	if (width != null && width.length() > 0)
	{
		element.setWidth(Integer.parseInt(width));
	}

	String height = atts.getValue(JRXmlConstants.ATTRIBUTE_height);
	if (height != null && height.length() > 0)
	{
		element.setHeight(Integer.parseInt(height));
	}

	String forecolor = atts.getValue(JRXmlConstants.ATTRIBUTE_forecolor);
	if (forecolor != null && forecolor.length() > 0)
	{
		element.setForecolor(JRColorUtil.getColor(forecolor, null));
	}

	String backcolor = atts.getValue(JRXmlConstants.ATTRIBUTE_backcolor);
	if (backcolor != null && backcolor.length() > 0)
	{
		element.setBackcolor(JRColorUtil.getColor(backcolor, null));
	}

	String styleName = atts.getValue(JRXmlConstants.ATTRIBUTE_style);
	if (styleName != null)
	{
		Map<String,JRStyle> stylesMap = jasperPrint.getStylesMap();

		if ( !stylesMap.containsKey(styleName) )
		{
			printXmlLoader.addError(
				new JRRuntimeException(
					EXCEPTION_MESSAGE_KEY_UNKNOWN_REPORT_STYLE,
					new Object[]{styleName}
				)
			);
		}

		element.setStyle(stylesMap.get(styleName));
	}

	String origin = atts.getValue(JRXmlConstants.ATTRIBUTE_origin); 
	if (origin != null && origin.length() > 0)
	{
		element.setOrigin(jasperPrint.getOriginsList().get(Integer.parseInt(origin)));
	}
	
	String elementId = atts.getValue(JRXmlConstants.ATTRIBUTE_srcId);
	if (elementId != null && elementId.length() > 0)
	{
		element.setSourceElementId(Integer.parseInt(elementId));
	}
	
	String printId = atts.getValue(JRXmlConstants.ATTRIBUTE_printId);
	if (printId != null && printId.length() > 0)
	{
		element.setPrintElementId(Integer.parseInt(printId));
	}

	return element;
}
 
Example 3
Source File: JRPrintFontFactory.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Object createObject(Attributes atts)
{
	JRPrintText element = (JRPrintText) digester.peek();
	JRPrintXmlLoader printXmlLoader = (JRPrintXmlLoader)digester.peek(digester.getCount() - 1);
	JasperPrint jasperPrint = (JasperPrint)digester.peek(digester.getCount() - 2);

	if (
		element.getStyle() == null
		&& element.getStyleNameReference() == null
		)
	{
		String styleName = atts.getValue(JRXmlConstants.ATTRIBUTE_reportFont);
		if (styleName != null)
		{
			Map<String,JRStyle> stylesMap = jasperPrint.getStylesMap();

			if (!stylesMap.containsKey(styleName))
			{
				printXmlLoader.addError(					
					new JRRuntimeException(
						EXCEPTION_MESSAGE_KEY_UNKNOWN_REPORT_STYLE,
						new Object[]{styleName}
					)
				);
			}

			element.setStyle(stylesMap.get(styleName));
		}
	}

	if (atts.getValue(JRXmlConstants.ATTRIBUTE_fontName) != null)
	{
		element.setFontName(atts.getValue(JRXmlConstants.ATTRIBUTE_fontName));
	}
	if (atts.getValue(JRXmlConstants.ATTRIBUTE_isBold) != null)
	{
		element.setBold(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isBold)));
	}
	if (atts.getValue(JRXmlConstants.ATTRIBUTE_isItalic) != null)
	{
		element.setItalic(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isItalic)));
	}
	if (atts.getValue(JRXmlConstants.ATTRIBUTE_isUnderline) != null)
	{
		element.setUnderline(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isUnderline)));
	}
	if (atts.getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough) != null)
	{
		element.setStrikeThrough(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough)));
	}
	if (atts.getValue(JRXmlConstants.ATTRIBUTE_size) != null)
	{
		element.setFontSize(Float.parseFloat(atts.getValue(JRXmlConstants.ATTRIBUTE_size)));
	}
	if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfFontName) != null)
	{
		element.setPdfFontName(atts.getValue(JRXmlConstants.ATTRIBUTE_pdfFontName));
	}
	if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding) != null)
	{
		element.setPdfEncoding(atts.getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding));
	}
	if (atts.getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded) != null)
	{
		element.setPdfEmbedded(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded)));
	}
	return element;
}