All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.xava.jasperReport.jsp Maven / Gradle / Ivy

There is a newer version: 7.4.3
Show newest version
<%=""%>



<%-- 
If you modify this file please past the manual tests in 
OpenXavaTest/src/org/openxava/test/tests/PrettyPrintingTest.txt  
--%>

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<%@ page import="java.util.List" %> 
<%@ page import="java.util.Collection" %> 
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Locale" %>
<%@ page import="org.openxava.util.XavaResources" %>
<%@ page import="org.openxava.util.Primitives" %>
<%@ page import="org.openxava.util.Strings" %>
<%@ page import="org.openxava.util.Is" %>
<%@ page import="org.openxava.tab.meta.MetaTab" %>
<%@ page import="org.openxava.tab.Tab"%> 
<%@ page import="org.openxava.component.MetaComponent" %>
<%@ page import="org.openxava.model.meta.MetaModel" %>
<%@ page import="org.openxava.model.meta.MetaProperty" %>
<%@ page import="org.openxava.util.XSystem"%>
<%@ page import="org.openxava.util.XavaPreferences"%>

<%!
private static int EXTRA_WIDTH = 15; 
private static int MAX_CHARACTERS_PER_ROW = 122;   // If you modify these
private static int WIDE_CHARACTERS_PER_ROW = 104; // values please verify
private static int MEDIUM_CHARACTERS_PER_ROW = 63; // if the tests in PrettyPrintingTest
private static int NARROW_CHARACTERS_PER_ROW = 44; // pass for the 4 branch of the if below

private int [] parseWidths(String widths, Integer columnCountLimit) { 
	String [] tokens = widths.split("[\\[\\], ]+");		
	int size = columnCountLimit == null?tokens.length - 1:columnCountLimit.intValue(); 
	int [] result = new int[size];
	for (int i=0; i 20 && widths[i] > widthForBig) widths[i] = widthForBig;
		total += widths[i];
	}		
	if (total > MAX_CHARACTERS_PER_ROW) {
		metaProperties.remove(metaProperties.size() - 1);
		widths = org.apache.commons.lang.ArrayUtils.remove(originalWidths, originalWidths.length - 1);
		return tightenWidths(metaProperties, widths);
	}
	return widths;
}

private String getAlign(MetaProperty p) throws Exception {
	String align = "Left";
	if (p.isNumber() && !p.hasValidValues()) align = "Right";
	else if (p.getType().equals(boolean.class)) align = "Center";
	return align;
}

private List getMetaProperties(Tab tab, Integer columnCountLimit) { 
	if (columnCountLimit == null) return new java.util.ArrayList(tab.getMetaProperties()); 
	List result = new java.util.ArrayList(); 
	int c = 0;
	for (MetaProperty p: tab.getMetaProperties()) {
		if (++c > columnCountLimit) break; 
		result.add(p);
	}
	return result;
}
%>

<%
Tab tab = (Tab) request.getSession().getAttribute("xava_reportTab");
String reportName = Strings.change(tab.getModelName(), ".", "_"); 
Collection totalProperties = tab.getTotalPropertiesNames();  
int totalRecords = (tab.getSelectedKeys().length == 0) ? tab.getTotalSize() : tab.getSelectedKeys().length;
String language = request.getParameter("language");
if (language == null) language = org.openxava.util.Locales.getCurrent().getDisplayLanguage();
language = language == null?request.getLocale().getDisplayLanguage():language;
Locale locale = new Locale(language, "");
String scolumnCountLimit = request.getParameter("columnCountLimit");
Integer columnCountLimit = scolumnCountLimit == null?null:Integer.parseInt(scolumnCountLimit);
List metaProperties = getMetaProperties(tab, columnCountLimit);
int columnsSeparation = 10;
int [] widths = parseWidths(request.getParameter("widths"), columnCountLimit); 
int totalWidth = adjustWithsToLabels(metaProperties, widths, locale); 
int letterWidth;
int letterSize;
int lineHeight; 
int pageWidth;
int pageHeight;
int columnWidth;
String orientation = null;

if (totalWidth > WIDE_CHARACTERS_PER_ROW) {
	if (totalWidth > MAX_CHARACTERS_PER_ROW) tightenWidths(metaProperties, widths);
	else expandWidths(metaProperties, widths, MAX_CHARACTERS_PER_ROW, locale); 
	orientation="Landscape";
	letterWidth = 4;
	letterSize = 7;
	lineHeight = 8; 
	pageWidth=842;
	pageHeight=595;
	columnWidth=780;	
}
else if (totalWidth > MEDIUM_CHARACTERS_PER_ROW) {
	expandWidths(metaProperties, widths, WIDE_CHARACTERS_PER_ROW, locale); 
	orientation="Landscape";
	letterWidth = 5;  
	letterSize=8;
	lineHeight = 10;
	pageWidth=842;
	pageHeight=595;
	columnWidth=780;	
} 
else if (totalWidth > NARROW_CHARACTERS_PER_ROW) {
	expandWidths(metaProperties, widths, MEDIUM_CHARACTERS_PER_ROW, locale); 
	orientation="Portrait";
	letterWidth = 5; 
	letterSize=8;
	lineHeight = 10;
	pageWidth=595;
	pageHeight=842;
	columnWidth=535;
}
else {
	expandWidths(metaProperties, widths, NARROW_CHARACTERS_PER_ROW, locale);
	orientation="Portrait";
	letterWidth = 10;
	letterSize = 12;
	lineHeight = 15;
	pageWidth=595;
	pageHeight=842;
	columnWidth=535;
}

int rowsInHeader = calculateRowsInHeader(metaProperties, widths, locale);
%>

	
		 
	<%
	String fontName="DejaVu Sans";
	String pdfEncoding="Identity-H";
	int totalRecordsWidth = columnWidth - 150;
	%>	
	
	
		

		
	
	
	<%	 
	for (Iterator it = metaProperties.iterator(); it.hasNext();) {
		MetaProperty p = (MetaProperty) it.next();				
		if (totalProperties.contains(p.getQualifiedName())) {				 
	%>
	 	
	<%
		}
	}
	%>	
		
	<%		 
	int detailHeight = lineHeight; 
	for (Iterator it = metaProperties.iterator(); it.hasNext();) {
		MetaProperty p = (MetaProperty) it.next();
		String type = "java.lang.String";
		if (p.isCompatibleWith(byte[].class)) {
			type = "java.io.InputStream"; 
			detailHeight = 32;
		}
	%>
	" class="<%=type%>"/>
	<%
	}
	%>	
		
			
		
		
			
			
		
		
			<band height="25"  isSplitAllowed="true" >

				<textField>
					<reportElement
						mode="Transparent"
						x="0"
						y="0"
						width="200"
						height="25"
						forecolor="#000000"
						backcolor="#FFFFFF"
						positionType="FixRelativeToTop"
						isPrintRepeatedValues="true"
						isRemoveLineWhenBlank="false"
						isPrintInFirstWholeBand="false"
						isPrintWhenDetailOverflows="false"/>
					<textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single">
						<font reportFont="Arial_Normal" size="8"/>
					</textElement>
					<textFieldExpression class="java.lang.String">$P{Organization}</textFieldExpression>					
				</textField>
						
				<textField>
					<reportElement
						mode="Transparent"
						x="5"
						y="5"
						width="<%=columnWidth%>"
						height="20"
						forecolor="#000000"
						backcolor="#FFFFFF"
						positionType="FixRelativeToTop"
						isPrintRepeatedValues="true"
						isRemoveLineWhenBlank="false"
						isPrintInFirstWholeBand="false"
						isPrintWhenDetailOverflows="false"/>
					<textElement textAlignment="Center" verticalAlignment="Top" lineSpacing="Single">
						<font reportFont="Arial_Normal" size="15"/>
					</textElement>
					<textFieldExpression class="java.lang.String">$P{Title}</textFieldExpression>					
				</textField>
				
				<textField>
					<reportElement
						mode="Transparent"
						x="<%=totalRecordsWidth%>"
						y="0"
						width="150"
						height="25"
						forecolor="#000000"
						backcolor="#FFFFFF"
						positionType="FixRelativeToTop"
						isPrintRepeatedValues="false"
						isRemoveLineWhenBlank="false"
						isPrintInFirstWholeBand="false"
						isPrintWhenDetailOverflows="false"/>
					<textElement textAlignment="Right" verticalAlignment="Top" lineSpacing="Single">
						<font reportFont="Arial_Normal" size="8"/>
					</textElement>
					<textFieldExpression><![CDATA["<%=XavaResources.getString(request, "record_count")%>" + ": <%=totalRecords%>"]]></textFieldExpression>
				</textField>
				

				<line direction="TopDown">
					<reportElement
						mode="Opaque"
						x="0"
						y="23"
						width="<%=columnWidth%>"
						height="0"
						forecolor="#000000"
						backcolor="#FFFFFF"
						positionType="FixRelativeToTop"
						isPrintRepeatedValues="true"
						isRemoveLineWhenBlank="false"
						isPrintInFirstWholeBand="false"
						isPrintWhenDetailOverflows="false"/>
					<graphicElement stretchType="NoStretch" pen="1Point" fill="Solid" />
				</line>

				<!-- Top line
				<line direction="TopDown">
					<reportElement
						mode="Opaque"
						x="0"
						y="3"
						width="<%=columnWidth%>"
						height="0"
						forecolor="#000000"
						backcolor="#FFFFFF"
						positionType="FixRelativeToTop"
						isPrintRepeatedValues="true"
						isRemoveLineWhenBlank="false"
						isPrintInFirstWholeBand="false"
						isPrintWhenDetailOverflows="false"/>
					<graphicElement stretchType="NoStretch" pen="1Point" fill="Solid" />
				</line>
				-->
			</band>
		
		
			
			
		
		<% 
		int headerHeight = rowsInHeader * lineHeight + 8; 
		%>
		
			
				
					
					
				
				
					
					
				
				
					
					
				
<% 
int x = 0;
int i = 0;
for (Iterator it = metaProperties.iterator(); it.hasNext(); i++) {			
	MetaProperty p = (MetaProperty) it.next();
	int width=widths[i]*letterWidth + EXTRA_WIDTH; 		
%>
				
					
					
						
					
					<% String label = ""; %>
					<%=label%>					
				
<%
	x+=(width+columnsSeparation);
}
%>				
			
		
		
		
			
				
										
					
				
<% 
x = 0;
i = 0;
for (Iterator it = metaProperties.iterator(); it.hasNext(); i++) {			
	MetaProperty p = (MetaProperty) it.next();	
	int width=widths[i]*letterWidth + EXTRA_WIDTH;
	if (p.isCompatibleWith(byte[].class)) { 
%>	
				
    				
    				$F{<%=Strings.change(p.getQualifiedName(), ".", "_")%>}
					
<%
	}
	else {
%>								
				
					
					
						
					
					$F{<%=Strings.change(p.getQualifiedName(), ".", "_")%>}
				
<%
	} 
	x+=(width+columnsSeparation);
}
%>				
			
		
		
			
									
					
					
						
					
				<%
				String iniPageLabel = "";
				%>
				<%=iniPageLabel%> + $V{PAGE_NUMBER} + <%=endPageLabel%>
				
									
					
						
					
				
				
				
					
					
				
									
					
						
					
				
					
				
				
			
		
		
			
				
										
					
				
<% 
x = 0;
i = 0;
for (Iterator it = metaProperties.iterator(); it.hasNext(); i++) {			
	MetaProperty p = (MetaProperty) it.next();	
	int width=widths[i]*letterWidth + EXTRA_WIDTH;
	if (totalProperties.contains(p.getQualifiedName())) { 
%>								
									
					
						
					
					$P{<%=p.getQualifiedName()%>__TOTAL__}
				
<%
	} 			
	x+=(width+columnsSeparation);
}
%>