public class ColumnFooter extends AbstractBandContainer {


	public ColumnFooter() {
		super("columnFooter");
	}

} public class ColumnHeader extends AbstractBandContainer {


	public ColumnHeader() {
		super("columnHeader");
	}

} public class DesignDocument extends XMLDocument {
	
	private static final String NAME = "jasperReport";
	
	private static final String ATTRIBUTE_NAME = "name"; //NMTOKEN #REQUIRED
	private static final String ATTRIBUTE_COLUMN_COUNT = "columnCount"; //NMTOKEN "1"
	
	private static final String ATTRIBUTE_PRINT_ORDER = "printOrder"; //(Vertical | Horizontal) "Vertical"
	private static final String VALUE_PRINT_ORDER_VERTICAL = "Vertical";
	private static final String VALUE_PRINT_ORDER_HORIZONTAL = "Horizontal";
	
	private static final String ATTRIBUTE_PAGE_WIDTH = "pageWidth"; //NMTOKEN "595"
	private static final String ATTRIBUTE_PAGE_HEIGHT = "pageHeight"; //NMTOKEN "842"
	
	private static final String ATTRIBUTE_ORIENTATION = "orientation"; //(Portrait | Landscape) "Portrait"
	private static final String VALUE_ORIENTATION_PORTRAIT = "Portrait";
	private static final String VALUE_ORIENTATION_LANDSCAPE = "Landscape";
	
	private static final String ATTRIBUTE_WHEN_NO_DATA_TYPE = "whenNoDataType"; //(NoPages | BlankPage | AllSectionsNoDetail) "NoPages"
	private static final String VALUE_WHEN_NO_DATA_TYPE_NOPAGES = "NoPages";
	private static final String VALUE_WHEN_NO_DATA_TYPE_BLANK_PAGE = "BlankPage";
	private static final String VALUE_WHEN_NO_DATA_TYPE_ALL_SECTION_NO_DETAIL = "AllSectionsNoDetail";
	
	private static final String ATTRIBUTE_COLUMN_WIDTH = "columnWidth"; //NMTOKEN "555"
	private static final String ATTRIBUTE_COLUMN_SPACING = "columnSpacing"; //NMTOKEN "0"
	private static final String ATTRIBUTE_LEFT_MARGIN = "leftMargin"; //NMTOKEN "20"
	private static final String ATTRIBUTE_RIGHT_MARGIN = "rightMargin"; //NMTOKEN "20"
	private static final String ATTRIBUTE_TOP_MARGIN = "topMargin"; //NMTOKEN "30"
	private static final String ATTRIBUTE_BOTTOM_MARGIN = "bottomMargin"; //NMTOKEN "30"
	private static final String ATTRIBUTE_IS_TITLE_NEW_PAGE = "isTitleNewPage"; //(true | false) "false"	
	private static final String ATTRIBUTE_IS_SUMMARY_NEW_PAGE = "isSummaryNewPage"; //(true | false) "false"
	private Vector _parameters = null;
	private Vector _fields = new Vector();
	private Title _title=null;
	private PageHeader _pageHeader=null;
	private ColumnHeader _columnHeader=null;
	private Detail _detail=null;
	private ColumnFooter _columnFooter=null;
	private PageFooter _pageFooter=null;
	private Summary _summary=null;
	
	

	private XMLElement _rootElement=null;
	/**
	 * @param element
	 */
	private DesignDocument(XMLElement element) {
		super(element);
		DocType docType = new DocType(NAME,"-//JasperReports//DTD Report Design//EN","http://jasperreports.sourceforge.net/dtds/jasperreport.dtd");
		this.setDocType(docType);
	}
	
	public DesignDocument(String name){
		this(new XMLElement(NAME));
		setReportName(name);
	}

	
	public XMLElement getRootElement() {
		if (this._rootElement == null) {
			this._rootElement = super.getRootElement();
		}

		return this._rootElement;
	}
	
	public void setRootElement(XMLElement element) {
		this._rootElement = element;
		super.setRootElement(element);
	}
	
	
	//Adders
	
	public void addParameter(Parameter parm){
		if(this._parameters == null){
			this._parameters = new Vector();
		}
		this._parameters.add(parm);
		//this.getRootElement().addContent(parm);
	}
	
	public void addParameter(String name, Class classType, boolean isForPrompting){
		Parameter parameter = new Parameter(name);
		parameter.setClassType(classType);
		parameter.setIsForPrompting(isForPrompting);
		addParameter(parameter);
	}
	
	public void addParameter(String name, Class classType){
		Parameter parameter = new Parameter(name);
		parameter.setClassType(classType);
		addParameter(parameter);
	}
	
	public void addParameter(String name){
		Parameter parameter = new Parameter(name);
		addParameter(parameter);
	}
	
	public void addParameter(String name, boolean isForPrompting){
		Parameter parameter = new Parameter(name);
		parameter.setIsForPrompting(isForPrompting);
		addParameter(parameter);
	}
	
	
	public void addField(Field field){
		this._fields.add(field);
		//this.getRootElement().addContent(field);
	}
	
	public void addField(String name, String className) {
		Field field = new Field(name);
		field.setClassType(className);
		addField(field);
	}
	
	public void addField(String name, Class classType){
		Field field = new Field(name);
		field.setClassType(classType);
		addField(field);
	}
	
	public void addField(String name){
		addField(new Field(name));
	}
	
	public void addObjectField(String name){
		addField(name,java.lang.Object.class);
	}
	
	public void addBooleanField(String name){
		addField(name,java.lang.Boolean.class);
	}
	
	public void addByteField(String name){
		addField(name,java.lang.Byte.class);
	}
	
	public void addDateField(String name){
		addField(name,java.util.Date.class);
	}
	
	public void addTimestampField(String name){
		addField(name,java.sql.Timestamp.class);
	}
	
	public void addTimeField(String name){
		addField(name,java.sql.Time.class);
	}
	
	public void addDoubleField(String name){
		addField(name,java.lang.Double.class);
	}
	
	public void addFloadField(String name){
		addField(name,java.lang.Float.class);
	}
	
	public void addIntegerField(String name){
		addField(name,java.lang.Integer.class);
	}
	
	public void addInputStreamField(String name){
		addField(name,java.io.InputStream.class);
	}
	
	public void addLongField(String name){
		addField(name,java.lang.Long.class);
	}
	
	public void addShortField(String name){
		addField(name,java.lang.Short.class);
	}
	
	public void addBigDecimalField(String name){
		addField(name,java.math.BigDecimal.class);
	}
	
	
	
	// Setters 
	public void setTitle(Title title){
		if(this._title != null){
			this.getRootElement().removeContent(this._title);
		}
		this._title=title;
		//this.getRootElement().addContent(_title);
	}
	
	public void setPageHeader(PageHeader pageHeader){
		if(this._pageHeader != null){
			this.getRootElement().removeContent(this._pageHeader);
		}
		this._pageHeader=pageHeader;
		//this.getRootElement().addContent(_pageHeader);
	}
	
	public void setColumnHeader(ColumnHeader columnHeader){
		if(this._columnHeader != null){
			this.getRootElement().removeContent(this._columnHeader);
		}
		this._columnHeader=columnHeader;
		//this.getRootElement().addContent(_columnHeader);
	}
	
	public void setDetail(Detail detail){
		if(this._detail != null){
			this.getRootElement().removeContent(this._detail);
		}
		this._detail=detail;
		//this.getRootElement().addContent(_detail);
	}
	
	public void setColumnFooter(ColumnFooter columnFooter){
		if(this._columnFooter != null){
			this.getRootElement().removeContent(this._columnFooter);
		}
		this._columnFooter=columnFooter;
		//this.getRootElement().addContent(_columnFooter);
	}
	
	public void setPageFooter(PageFooter pageFooter){
		if(this._pageFooter != null){
			this.getRootElement().removeContent(this._pageFooter);
		}
		this._pageFooter=pageFooter;
		//this.getRootElement().addContent(_pageFooter);
	}
	
	public void setSummary(Summary summary){
		if(this._summary != null){
			this.getRootElement().removeContent(this._summary);
		}
		this._summary=summary;
		//this.getRootElement().addContent(_summary);
	}
	
	public void setReportName(String name){
		this.getRootElement().setAttribute(ATTRIBUTE_NAME,name);
	}
	
	public void setColumnCount(int count){
		this.getRootElement().setAttribute(ATTRIBUTE_COLUMN_COUNT,Integer.toString(count));
	}
	
	public void setPrintOrderVertical(){
		this.getRootElement().setAttribute(ATTRIBUTE_PRINT_ORDER,VALUE_PRINT_ORDER_VERTICAL);
	}
	
	public void setPrintOrderHorizontal(){
		this.getRootElement().setAttribute(ATTRIBUTE_PRINT_ORDER,VALUE_PRINT_ORDER_HORIZONTAL);
	}
	
	public void setPageWidth(int width){
		this.getRootElement().setAttribute(ATTRIBUTE_PAGE_WIDTH,Integer.toString(width));
	}
	
	public void setPageHeight(int height){
		this.getRootElement().setAttribute(ATTRIBUTE_PAGE_HEIGHT,Integer.toString(height));
	}
	
	public void setOrientationLandscape(){
		this.getRootElement().setAttribute(ATTRIBUTE_ORIENTATION,VALUE_ORIENTATION_LANDSCAPE);
	}
	
	public void setOrientationPortrait(){
		this.getRootElement().setAttribute(ATTRIBUTE_ORIENTATION,VALUE_ORIENTATION_PORTRAIT);
	}
	
	public void setColumnWidth(int width){
		this.getRootElement().setAttribute(ATTRIBUTE_COLUMN_WIDTH,Integer.toString(width));
	}
	
	public void setColumnSpacing(int spacing){
		this.getRootElement().setAttribute(ATTRIBUTE_COLUMN_SPACING,Integer.toString(spacing));
	}
	
	public void setLeftMargin(int lMargin){
		this.getRootElement().setAttribute(ATTRIBUTE_LEFT_MARGIN,Integer.toString(lMargin));
	}
	
	public void setRightMargin(int rMargin){
		this.getRootElement().setAttribute(ATTRIBUTE_RIGHT_MARGIN,Integer.toString(rMargin));
	}
	
	public void setTopMargin(int tMargin){
		this.getRootElement().setAttribute(ATTRIBUTE_TOP_MARGIN,Integer.toString(tMargin));
	}
	
	public void setBottomMargin(int bMargin){
		this.getRootElement().setAttribute(ATTRIBUTE_BOTTOM_MARGIN,Integer.toString(bMargin));
	}
	
	public void setIsTitleNewPage(boolean value){
		this.getRootElement().setAttribute(ATTRIBUTE_IS_TITLE_NEW_PAGE,String.valueOf(value));
	}
	
	public void setIsSummaryNewPage(boolean value){
		this.getRootElement().setAttribute(ATTRIBUTE_IS_SUMMARY_NEW_PAGE,String.valueOf(value));
	}
	
	private void setWhenNoDataType(String value){
		this.getRootElement().setAttribute(ATTRIBUTE_WHEN_NO_DATA_TYPE,value);
	}
	
	public void setWhenNoDataTypeAsNoPages(){
		setWhenNoDataType(VALUE_WHEN_NO_DATA_TYPE_NOPAGES);
	}
	
	public void setWhenNoDataTypeAsBlankPage(){
		setWhenNoDataType(VALUE_WHEN_NO_DATA_TYPE_BLANK_PAGE);
	}
	
	public void setWhenNoDataTypeAsAllSectionNoDetail(){
		setWhenNoDataType(VALUE_WHEN_NO_DATA_TYPE_ALL_SECTION_NO_DETAIL);
	}
		
	
	
	//Getters
	
	/**
	 * @return
	 */
	public ColumnFooter getColumnFooter() {
		return this._columnFooter;
	}

	/**
	 * @return
	 */
	public ColumnHeader getColumnHeader() {
		return this._columnHeader;
	}

	/**
	 * @return
	 */
	public Detail getDetail() {
		return this._detail;
	}

	/**
	 * @return
	 */
	public PageFooter getPageFooter() {
		return this._pageFooter;
	}

	/**
	 * @return
	 */
	public PageHeader getPageHeader() {
		return this._pageHeader;
	}

	/**
	 * @return
	 */
	public Summary getSummary() {
		return this._summary;
	}

	/**
	 * @return
	 */
	public Title getTitle() {
		return this._title;
	}
	
	
	
	
	
	public File writeToFile(String path)throws IOException{
		BufferedOutputStream outputStream = null;
		File auxiliaryFile = null;
		auxiliaryFile = new File(path);
		
		//	TODO remove check  TMP
		//if(auxiliaryFile != null && !auxiliaryFile.exists()){
			try {
	//			boolean dirsCreated = auxiliaryFile.mkdirs();
	//			System.out.println("Directories were created: "+dirsCreated);
				outputStream = new BufferedOutputStream(new FileOutputStream(auxiliaryFile));
			}
			catch (FileNotFoundException ex)  {
				System.err.println("[XMLData] problem creating file. Message is: "+ex.getMessage());
				ex.printStackTrace(System.err);
				throw new IOException("xml file could not be stored");
			}
		
		
		
			// now we have an output stream of the auxiliary file
			// write to the xml file
			XMLOutput xmlOutput = new XMLOutput("  ", true);
			xmlOutput.setLineSeparator(System.getProperty("line.separator"));
			xmlOutput.setTextNormalize(true);
			//xmlOutput.setEncoding("ISO8859_1");
			//xmlOutput.setEncoding("iso-8859-1");
			//xmlOutput.setEncoding("UTF-8");
	
			try {
				xmlOutput.output(this, outputStream);
			}
			catch (IOException ex) {
				System.err.println("[XMLData] problem writing to file. Message is: "+ex.getMessage());
				ex.printStackTrace(System.err);
				outputStream.close();
				throw new IOException("xml file could not be stored");
			}
			outputStream.close();
			// writing finished
		
		//}
				
		return auxiliaryFile;

	}
	
	
	/**
	 * @param file, to get File from this class use writeToFile(String path)
	 * @return 
	 * @throws IOException
	 * @see DesignDocument#writeToFile(String path)
	 */
	public InputStream getInputstream(File file) throws IOException{
		BufferedInputStream inputStream = null;
		try {
			inputStream = new BufferedInputStream(new FileInputStream(file));
		}
		catch (FileNotFoundException ex)  {
			System.err.println("[XMLData] problem reading file. Message is: "+ex.getMessage());
			ex.printStackTrace(System.err);
			throw new IOException("xml file could not be stored");
		}
		return inputStream;
	}
	
	
	/**
	 * 
	 * 
	 * @param tmpPath, path on the disk where File is stored before geting Inputstream from it
	 * @return
	 * @throws IOException
	 * @see DesignDocument#writeToFile(String path)
	 * @see InputStream getInputstream(File file)
	 */
	public InputStream getInputstream(String tmpPath) throws IOException{
		
		
		return getInputstream(writeToFile(tmpPath));
	}
	
	
	
	/**
	 * Use this method to close the document before writing it to file
	 */
	public void close(){
		Iterator iter = this._parameters.iterator();
		while (iter.hasNext()) {
			Parameter element = (Parameter)iter.next();
			this.getRootElement().addContent(element);
		}
		
		Iterator iter2 = this._fields.iterator();
		while (iter2.hasNext()) {
			Field element = (Field)iter2.next();
			this.getRootElement().addContent(element);
		}
		
		if(this._title != null){
			this.getRootElement().addContent(this._title);
		}
		
		if(this._pageHeader != null){
			this.getRootElement().addContent(this._pageHeader);
		}
		
		if(this._columnHeader != null){
			this.getRootElement().addContent(this._columnHeader);
		}
		
		if(this._detail != null){
			this.getRootElement().addContent(this._detail);
		}
		
		if(this._columnFooter != null){
			this.getRootElement().addContent(this._columnFooter);
		}
		
		if(this._pageFooter != null){
			this.getRootElement().addContent(this._pageFooter);
		}
		
		if(this._summary != null){
			this.getRootElement().addContent(this._summary);
		}
	}
	
//	public List getParameters(){
//		if(_parameters == null){
//			_parameters = new Vector();
//			Iterator iter = getRootElement().getContent().iterator();
//			while (iter.hasNext()) {
//				XMLElement element = (XMLElement)iter.next();
//				if(element.getName().equals(Parameter.ELEMENT_NAME)){
//					Parameter prm = new Parameter();
//					//Vantar að geta búið til parameter klasa út frá XMLElement
//				}
//					
//			}
//		}
//		return _parameters;
//	}
	

} public class Detail extends AbstractBandContainer {


	public Detail() {
		super("detail");
	}

} public class Font extends XMLElement {
	
//	reportFont NMTOKEN #IMPLIED
//	fontName CDATA #IMPLIED
	private static final String ATTRIBUTE_SIZE = "size"; // NMTOKEN #IMPLIED
	private static final String ATTRIBUTE_IS_BOLD = "isBold"; // (true | false) #IMPLIED
//	isItalic (true | false) #IMPLIED
	private static final String ATTRIBUTE_IS_UNDERLINE = "isUnderline"; // (true | false) #IMPLIED
//	isStrikeThrough (true | false) #IMPLIED
//	pdfFontName CDATA #IMPLIED
//	pdfEncoding CDATA #IMPLIED
//	isPdfEmbedded (true | false) #IMPLIED

	
	public Font() {
		super("font");
	}
	
	public void setIsUnderline(boolean value){
		this.setAttribute(ATTRIBUTE_IS_UNDERLINE, String.valueOf(value));
	}
	
	public void setIsBold(boolean value){
		this.setAttribute(ATTRIBUTE_IS_BOLD, String.valueOf(value));
	}
	
	public void setFontSize(int size){
		this.setAttribute(ATTRIBUTE_SIZE,String.valueOf(size));
	}

} public class PageFooter extends AbstractBandContainer {


	public PageFooter() {
		super("pageFooter");
	}

} public class PageHeader extends AbstractBandContainer {


	public PageHeader() {
		super("pageHeader");
	}

} public class ReportElement extends XMLElement {
	
	
	//key NMTOKEN #IMPLIED
	private static final String ATTRIBUTE_POSITION_TYPE = "positionType"; // (Float | FixRelativeToTop | FixRelativeToBottom) "FixRelativeToTop"
	private static final String VALUE_POSITION_TYPE_FLOAT = "Float";
	private static final String VALUE_POSITION_TYPE_FIX_RELATIVE_TO_TOP = "FixRelativeToTop";
	private static final String VALUE_POSITION_TYPE_FIX_RELATIVE_TO_BOTTOM = "FixRelativeToBottom";
	
	private static final String ATTRIBUTE_IS_PRINT_REPEATED_VALUES = "isPrintRepeatedValues"; // (true | false) "true"
	//mode (Opaque | Transparent) #IMPLIED
	private static final String ATTRIBUTE_X = "x"; // NMTOKEN #REQUIRED
	private static final String ATTRIBUTE_Y = "y"; // NMTOKEN #REQUIRED
	private static final String ATTRIBUTE_WIDTH = "width"; // NMTOKEN #REQUIRED
	private static final String ATTRIBUTE_HEIGHT = "height"; // NMTOKEN #REQUIRED
	private static final String ATTRIBUTE_IS_REMOVE_LINE_WHEN_BLANK = "isRemoveLineWhenBlank"; // (true | false) "false"
	private static final String ATTRIBUTE_IS_PRINT_IN_FIRST_WHOLE_BAND = "isPrintInFirstWholeBand"; // (true | false) "false"
	private static final String ATTRIBUTE_IS_PRINT_WHEN_DETAIL_OVERFLOWS = "isPrintWhenDetailOverflows"; // (true | false) "false"
	//printWhenGroupChanges CDATA #IMPLIED
	//forecolor CDATA #IMPLIED
	//backcolor CDATA #IMPLIED

	/**
	 * @param name
	 */
	public ReportElement(int x, int y, int width, int height) {
		super("reportElement");
		setXCoordinate(x);
		setYCoordinate(y);
		setWidth(width);
		setHeight(height);
	}
	
	public void setXCoordinate(int x){
		this.setAttribute(ATTRIBUTE_X,Integer.toString(x));
	}
	
	public void setYCoordinate(int y){
		this.setAttribute(ATTRIBUTE_Y,Integer.toString(y));
	}
	
	public void setWidth(int width){
		this.setAttribute(ATTRIBUTE_WIDTH,Integer.toString(width));
	}
	
	public void setHeight(int height){
		this.setAttribute(ATTRIBUTE_HEIGHT,Integer.toString(height));
	}
	
	
	public void setPositionTypeAsFloat(){
		this.setAttribute(ATTRIBUTE_POSITION_TYPE, VALUE_POSITION_TYPE_FLOAT);
	}
	
	public void setPositionTypeAsFixRelativeToTop(){
		this.setAttribute(ATTRIBUTE_POSITION_TYPE, VALUE_POSITION_TYPE_FIX_RELATIVE_TO_TOP);
	}
	
	public void setPositionTypeAsFixRelativeToBottom(){
		this.setAttribute(ATTRIBUTE_POSITION_TYPE, VALUE_POSITION_TYPE_FIX_RELATIVE_TO_BOTTOM);
	}
	
	public void setIsPrintRepeatedValues(boolean value){
		this.setAttribute(ATTRIBUTE_IS_PRINT_REPEATED_VALUES,String.valueOf(value));
	}
	
	public void setIsRemoveLineWhenBlank(boolean value){
		this.setAttribute(ATTRIBUTE_IS_REMOVE_LINE_WHEN_BLANK,String.valueOf(value));
	}
	
	public void setIsPrintInFirstWholeBand(boolean value){
		this.setAttribute(ATTRIBUTE_IS_PRINT_IN_FIRST_WHOLE_BAND,String.valueOf(value));
	}
	
	public void setIsPrintWhenDetailOverflows(boolean value){
		this.setAttribute(ATTRIBUTE_IS_PRINT_WHEN_DETAIL_OVERFLOWS,String.valueOf(value));
	}
} public class StaticText extends XMLElement {

	public StaticText() {
		super("staticText");
	}

} public class Summary extends AbstractBandContainer {


	public Summary() {
		super("summary");
	}

} public class Text extends XMLElement {

	/**
	 * @param name
	 */
	public Text(String text) {
		super("text");
		this.addContent(new XMLCDATA(text));
	}

} public class TextElement extends XMLElement {

	private static final String ATTRIBUTE_TEXT_ALIGNMENT = "textAlignment"; // (Left | Center | Right | Justified) "Left"
	private static final String VALUE_TEXT_ALIGNMENT_LEFT = "Left";
	private static final String VALUE_TEXT_ALIGNMENT_CENTER = "Center";
	private static final String VALUE_TEXT_ALIGNMENT_RIGHT = "Right";
	private static final String VALUE_TEXT_ALIGNMENT_JUSTIFIED = "Justified";
	
	private static final String ATTRIBUTE_VERTICAL_ALIGNMENT = "verticalAlignment"; // (Top | Middle | Bottom) "Top"
	private static final String VALUE_VERTICAL_ALIGNMENT_TOP ="Top";
	private static final String VALUE_VERTICAL_ALIGNMENT_MIDDLE = "Middle";
	private static final String VALUE_VERTICAL_ALIGNMENT_BOTTOM = "Bottom";
	
	private static final String ATTRIBUTE_LINE_SPACING = "lineSpacing"; // (Single | 1_1_2 | Double) "Single"
	private static final String VALUE_LINE_SPACING_SINGLE = "Single";
	private static final String VALUE_LINE_SPACING_ONE_AND_A_HALF = "1_1_2";
	private static final String VALUE_LINE_SPACING_DOUBLE = "Double";
	
	public TextElement() {
		super("textElement");
	}

	private void setTextAlignment(String align){
		this.setAttribute(ATTRIBUTE_TEXT_ALIGNMENT,align);
	}
	
	private void setVerticalAlignment(String vAlign){
		this.setAttribute(ATTRIBUTE_VERTICAL_ALIGNMENT,vAlign);
	}
	
	private void setLineSpacing(String spacing){
		this.setAttribute(ATTRIBUTE_LINE_SPACING,spacing);
	}
	
	public void setTextAlignmentAsLeft(){
		this.setTextAlignment(VALUE_TEXT_ALIGNMENT_LEFT);
	}
	
	public void setTextAlignmentAsCenter(){
		this.setTextAlignment(VALUE_TEXT_ALIGNMENT_CENTER);
	}
	
	public void setTextAlignmentAsRight(){
		this.setTextAlignment(VALUE_TEXT_ALIGNMENT_RIGHT);
	}
	
	public void setTextAlignmentAsJustified(){
		this.setTextAlignment(VALUE_TEXT_ALIGNMENT_JUSTIFIED);
	}
	
	public void setVerticalAlignmentAsTop(){
		this.setVerticalAlignment(VALUE_VERTICAL_ALIGNMENT_TOP);
	}
	
	public void setVerticalAlignmentAsMiddle(){
		this.setVerticalAlignment(VALUE_VERTICAL_ALIGNMENT_MIDDLE);
	}
	
	public void setVerticalAlignmentAsBottom(){
		this.setVerticalAlignment(VALUE_VERTICAL_ALIGNMENT_BOTTOM);
	}
	
	public void setLineSpacingAsSingle(){
		this.setLineSpacing(VALUE_LINE_SPACING_SINGLE);
	}
	
	public void setLineSpacingAsOneAndAHalf(){
		this.setLineSpacing(VALUE_LINE_SPACING_ONE_AND_A_HALF);
	}
	
	public void setLineSpacingAsDouble(){
		this.setLineSpacing(VALUE_LINE_SPACING_DOUBLE);
	}

} public class TextField extends XMLElement {
	
	private static final String ATTRIBUTE_IS_STRETCH_WITH_OVERFLOW = "isStretchWithOverflow"; // (true | false) "false"
	
	private static final String ATTRIBUTE_EVALUATION_TIME = "evaluationTime"; // (Now | Report | Page | Column | Group) "Now"
	private static final String VALUE_EVALUATION_TIME_NOW = "Now";
	private static final String VALUE_EVALUATION_TIME_REPORT = "Report"; 
	private static final String VALUE_EVALUATION_TIME_PAGE = "Page";
	private static final String VALUE_EVALUATION_TIME_COLUMN = "Column";
	private static final String VALUE_EVALUATION_TIME_GROUP = "Group";
	
	//evaluationGroup CDATA #IMPLIED
	//pattern CDATA #IMPLIED
	
	private static final String ATTRIBUTE_IS_BLANK_WHEN_NULL = "isBlankWhenNull"; // (true | false) "false"
	
	private static final String ATTRIBUTE_HYPERLINK_TYPE = "hyperlinkType"; // (None | Reference | LocalAnchor | LocalPage | RemoteAnchor | RemotePage) "None"
	private static final String VALUE_HYPERLINK_TYPE_NONE = "None";
	private static final String VALUE_HYPERLINK_TYPE_REFERENCE = "Reference";
	private static final String VALUE_HYPERLINK_TYPE_LOCAL_ANCHOR = "LocalAnchor";
	private static final String VALUE_HYPERLINK_TYPE_LOCAL_PAGE = "LocalPage";
	private static final String VALUE_HYPERLINK_TYPE_REMOTE_ANCHOR = "RemoteAnchor";
	private static final String VALUE_HYPERLINK_TYPE_REMOTE_PAGE = "RemotePage";
	
	/**
	 * @param name
	 */
	public TextField() {
		super("textField");
	}
	
	public void setIsStretchWithOverflow(boolean value){
		this.setAttribute(ATTRIBUTE_IS_STRETCH_WITH_OVERFLOW, String.valueOf(value));
	}
	
	public void setEvaluationTimeAsNow(){
		this.setAttribute(ATTRIBUTE_EVALUATION_TIME, VALUE_EVALUATION_TIME_NOW);
	}
	
	public void setEvaluationTimeAsReport(){
		this.setAttribute(ATTRIBUTE_EVALUATION_TIME, VALUE_EVALUATION_TIME_REPORT);
	}

	public void setEvaluationTimeAsPage(){
		this.setAttribute(ATTRIBUTE_EVALUATION_TIME, VALUE_EVALUATION_TIME_PAGE);
	}

	public void setEvaluationTimeAsColumn(){
		this.setAttribute(ATTRIBUTE_EVALUATION_TIME, VALUE_EVALUATION_TIME_COLUMN);
	}

	public void setEvaluationTimeAsGroup(){
		this.setAttribute(ATTRIBUTE_EVALUATION_TIME, VALUE_EVALUATION_TIME_GROUP);
	}
	
	public void setIsBlankWhenNull(boolean value){
		this.setAttribute(ATTRIBUTE_IS_BLANK_WHEN_NULL, String.valueOf(value));
	}

	public void setHyperlinkTypeAsNone(){
		this.setAttribute(ATTRIBUTE_HYPERLINK_TYPE, VALUE_HYPERLINK_TYPE_NONE);
	}
	
	public void setHyperlinkTypeAsReference(){
		this.setAttribute(ATTRIBUTE_HYPERLINK_TYPE, VALUE_HYPERLINK_TYPE_REFERENCE);
	}

	public void setHyperlinkTypeAsLocalAnchor(){
		this.setAttribute(ATTRIBUTE_HYPERLINK_TYPE, VALUE_HYPERLINK_TYPE_LOCAL_ANCHOR);
	}

	public void setHyperlinkTypeAsLocalPage(){
		this.setAttribute(ATTRIBUTE_HYPERLINK_TYPE, VALUE_HYPERLINK_TYPE_LOCAL_PAGE);
	}

	public void setHyperlinkTypeAsRemoteAnchor(){
		this.setAttribute(ATTRIBUTE_HYPERLINK_TYPE, VALUE_HYPERLINK_TYPE_REMOTE_ANCHOR);
	}
	
	public void setHyperlinkTypeAsRemotePage(){
		this.setAttribute(ATTRIBUTE_HYPERLINK_TYPE, VALUE_HYPERLINK_TYPE_REMOTE_PAGE);
	}

} public class TextFieldExpression extends XMLElement {
	
	private static final String ATTRIBUTE_CLASS = "class"; // (java.lang.Boolean | java.lang.Byte | java.util.Date | java.sql.Timestamp | java.sql.Time | java.lang.Double | java.lang.Float | java.lang.Integer | java.lang.Long | java.lang.Short | java.math.BigDecimal | java.lang.String) "java.lang.String"

	

	public TextFieldExpression() {
		super("textFieldExpression");
	}
	
	public void setClassType(Class c){
		setAttribute(ATTRIBUTE_CLASS,c.getName());
	}
	
	public void setClassType(String c){
		setAttribute(ATTRIBUTE_CLASS,c);
	}
	
	public void addParameter(String prmName){
		XMLCDATA cData = new XMLCDATA("$P{"+prmName+"}");
		this.addContent(cData);
	}
	
	public void addField(String fieldName){
		XMLCDATA cData = new XMLCDATA("$F{"+fieldName+"}");
		this.addContent(cData);
	}
	
	public void addVariable(String var){
		XMLCDATA cData = new XMLCDATA("$V{"+var+"}");
		this.addContent(cData);
	}
	
} public class Title extends AbstractBandContainer {


	public Title() {
		super("title");
	}

}
import java.io.IOException;
import java.io.InputStream;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperManager;
import net.sf.jasperreports.engine.design.JasperDesign;
import com.idega.block.datareport.business.jasperdesignxml.ColumnFooter;
import com.idega.block.datareport.business.jasperdesignxml.ColumnHeader;
import com.idega.block.datareport.business.jasperdesignxml.DesignDocument;
import com.idega.block.datareport.business.jasperdesignxml.Detail;
import com.idega.block.datareport.business.jasperdesignxml.Font;
import com.idega.block.datareport.business.jasperdesignxml.PageFooter;
import com.idega.block.datareport.business.jasperdesignxml.PageHeader;
import com.idega.block.datareport.business.jasperdesignxml.ReportElement;
import com.idega.block.datareport.business.jasperdesignxml.StaticText;
import com.idega.block.datareport.business.jasperdesignxml.Summary;
import com.idega.block.datareport.business.jasperdesignxml.Text;
import com.idega.block.datareport.business.jasperdesignxml.TextElement;
import com.idega.block.datareport.business.jasperdesignxml.TextField;
import com.idega.block.datareport.business.jasperdesignxml.TextFieldExpression;
import com.idega.block.datareport.business.jasperdesignxml.Title;
import com.idega.idegaweb.IWApplicationContext;
import com.idega.idegaweb.IWCacheManager;
import com.idega.idegaweb.IWMainApplication;
import com.idega.idegaweb.UnavailableIWContext;
import com.idega.presentation.IWContext;
import com.idega.util.FileUtil;
	}
	

	/**
	 *
	 */
	private void initializeDocument(String name) {
		this._designDoc = new DesignDocument(name);
	
		// set A 4 paper size
		this._designDoc.setPageWidth(PAGE_WIDTH_PORTRAIT_A4);
		this._designDoc.setPageHeight(PAGE_HEIGHT_PORTRAIT_A4);
		this._designDoc.setColumnWidth(540);
		this._designDoc.setColumnSpacing(15);
		this._designDoc.setLeftMargin(PAGE_LEFT_MARGIN);
		this._designDoc.setRightMargin(PAGE_RIGHT_MARGIN);
		this._designDoc.setTopMargin(PAGE_TOP_MARGIN);
		this._designDoc.setBottomMargin(PAGE_BOTTOM_MARGIN);
		this._designDoc.setColumnCount(1);
		this._designDoc.setPrintOrderVertical();
		this._designDoc.setOrientationPortrait();
		this._designDoc.setWhenNoDataTypeAsAllSectionNoDetail();
		this._designDoc.setIsTitleNewPage(false);
		this._designDoc.setIsSummaryNewPage(false);
	
	
		this._designDoc.addParameter(PRM_REPORT_NAME,String.class,true);
		if (this.showDate) {
			this._designDoc.addParameter(PRM_DATE, String.class, true);
		}
		if (this.showUser) {
			this._designDoc.addParameter(PRM_USER, String.class, true);
		}
	
	}

	/**
	 * 
	 */
	private void createTitle() {
		Title title = new Title();
		title.setHeight(this._reportTitleHeight);
		//title.setIsSplitAllowed(true);
			TextField tField1 = new TextField();
			tField1.setIsBlankWhenNull(true);
			tField1.setIsStretchWithOverflow(true);
			tField1.setEvaluationTimeAsNow();
			tField1.setHyperlinkTypeAsNone();
				ReportElement rElement = new ReportElement(0,0,500,this._reportTitleHeight);
				rElement.setPositionTypeAsFixRelativeToTop();
				rElement.setIsPrintRepeatedValues(true);
				rElement.setIsRemoveLineWhenBlank(false);
				rElement.setIsPrintInFirstWholeBand(false);
				rElement.setIsPrintWhenDetailOverflows(false);
			tField1.addContent(rElement);
				TextElement tElement = new TextElement();
				tElement.setTextAlignmentAsCenter();
				tElement.setVerticalAlignmentAsTop();
				tElement.setLineSpacingAsSingle();
					Font tElementFont = new Font();
					tElementFont.setFontSize(FONT_SIZE_TITLE);
					tElementFont.setIsBold(true);
				tElement.addContent(tElementFont);
			tField1.addContent(tElement);
				TextFieldExpression tfExpression = new TextFieldExpression();
				tfExpression.setClassType(String.class);
				tfExpression.addParameter(PRM_REPORT_NAME);	
			tField1.addContent(tfExpression);
		title.addContent(tField1);
	
		this._designDoc.setTitle(title);
	}

	/**
	 * 
	 */
	private void createPageHeader() {
		PageHeader pHeader = new PageHeader();
		pHeader.setHeight(this._pageHeaderHeight);
		//pHeader.setIsSplitAllowed(true);
		this._designDoc.setPageHeader(pHeader);		
	}
	
	/**
	 * 
	 */
	private void createColumnHeader() {
		ColumnHeader colHeader = new ColumnHeader();
		colHeader.setHeight(this._columnHeaderHeight);
		//colHeader.setIsSplitAllowed(true);
		this._designDoc.setColumnHeader(colHeader);
	}
	
	/**
	 * 
	 */
	private void createDetail() {
		Detail detail = new Detail();
		detail.setHeight(this._detailHeight);
		//detail.setIsSplitAllowed(true);
		this._designDoc.setDetail(detail);
	}
	
	/**
	 * 
	 */
	private void createColumnFooter() {
		ColumnFooter colFooter = new ColumnFooter();
		colFooter.setHeight(0);
		//colFooter.setIsSplitAllowed(true);
		this._designDoc.setColumnFooter(colFooter);	
	}
	
	/**
	 * 
	 */
	private void createPageFooter() {
		PageFooter pFooter = new PageFooter();
		pFooter.setHeight(60);
		//pFooter.setIsSplitAllowed(true);
			StaticText sText = new StaticText();