<commit_before>package com.foc.web.modules.business;

import com.foc.business.printing.PrnLayout;
import com.foc.business.printing.gui.PrintingAction;
import com.vaadin.server.DownloadStream;
import com.vaadin.server.StreamResource;

public class PrnLayout_BrowserWindowOpenerStreamResource extends StreamResource {

	private PrintingAction printingAction = null;
	private PrnLayout      prnLayout      = null;
	private boolean        wordDoc        = false;
	
	public PrnLayout_BrowserWindowOpenerStreamResource(PrnLayout prnLayout, PrintingAction printingaction) {
		this(prnLayout, printingaction, false);
	}
	
	public PrnLayout_BrowserWindowOpenerStreamResource(PrnLayout prnLayout, PrintingAction printingAction, boolean wordDoc) {
		super(null, "printnig_"+System.currentTimeMillis()+ (wordDoc ? ".docx" : ".pdf"));
		this.prnLayout = prnLayout;
		this.printingAction = printingAction;
		this.wordDoc = wordDoc;
		setCacheTime(1);
	}
	
	public void dispose(){
		printingAction = null;
		prnLayout = null;
	}
	
	protected boolean isWithLogo() {
		return true;
	}
	
	public PrintingAction getPrintingAction() {
		return printingAction;
	}
	
	@Override
	public DownloadStream getStream() {
		DownloadStream downloadStream = null;
		if(getPrintingAction() != null && getPrintingAction().getLauncher() != null){
			if(prnLayout != null){
				
//				if(this.prnLayout_Table.getPrintLogoCheckBox() != null){
//				  boolean withLogo = this.prnLayout_Table.getPrintLogoCheckBox().getValue();
//				  this.prnLayout_Table.getPrintingAction().getLauncher().setWithLogo(withLogo);
//				}
				
			  getPrintingAction().getLauncher().setWithLogo(isWithLogo());
				getPrintingAction().setLaunchedAutomatically(false);
				
				byte[] bytes = null;
				if(wordDoc){
					bytes = getPrintingAction().getLauncher().printWordDocument(prnLayout);
				}else{
					bytes = getPrintingAction().getLauncher().web_FillReport(prnLayout, prnLayout.getFileName());
				}
				if(bytes != null){
					if(wordDoc){
						setMIMEType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
					}else{
						setMIMEType("application/pdf");
					}
		  		setStreamSource(new FStreamSource(bytes));
				}
				downloadStream = super.getStream();
			}
		}
		return downloadStream;
	}

	public PrnLayout getPrnLayout() {
		return prnLayout;
	}

	public void setPrnLayout(PrnLayout prnLayout) {
		this.prnLayout = prnLayout;
	}

	public boolean isWordDoc() {
		return wordDoc;
	}<commit_msg>Bug correction: when downlloading a WORD document created from Jaspper report the extension in .pdf<commit_after>package com.foc.web.modules.business;

import com.foc.business.printing.PrnLayout;
import com.foc.business.printing.gui.PrintingAction;
import com.vaadin.server.DownloadStream;
import com.vaadin.server.StreamResource;

public class PrnLayout_BrowserWindowOpenerStreamResource extends StreamResource {

	private PrintingAction printingAction = null;
	private PrnLayout      prnLayout      = null;
	private boolean        wordDoc        = false;
	
	public PrnLayout_BrowserWindowOpenerStreamResource(PrnLayout prnLayout, PrintingAction printingaction) {
		this(prnLayout, printingaction, false);
	}
	
	public PrnLayout_BrowserWindowOpenerStreamResource(PrnLayout prnLayout, PrintingAction printingAction, boolean wordDoc) {
//		super(null, "printnig_"+System.currentTimeMillis()+ (wordDoc ? ".docx" : ".pdf"));
		super(null, "printnig_"+System.currentTimeMillis());
		this.prnLayout = prnLayout;
		this.printingAction = printingAction;
		this.wordDoc = wordDoc;
		setCacheTime(1);
	}
	
	public void dispose(){
		printingAction = null;
		prnLayout = null;
	}
	
	protected boolean isWithLogo() {
		return true;
	}
	
	public PrintingAction getPrintingAction() {
		return printingAction;
	}
	
	@Override
	public DownloadStream getStream() {
		DownloadStream downloadStream = null;
		if(getPrintingAction() != null && getPrintingAction().getLauncher() != null){
			if(prnLayout != null){
				
//				if(this.prnLayout_Table.getPrintLogoCheckBox() != null){
//				  boolean withLogo = this.prnLayout_Table.getPrintLogoCheckBox().getValue();
//				  this.prnLayout_Table.getPrintingAction().getLauncher().setWithLogo(withLogo);
//				}
				
			  getPrintingAction().getLauncher().setWithLogo(isWithLogo());
				getPrintingAction().setLaunchedAutomatically(false);
				
				byte[] bytes = null;
				if(wordDoc){
					if(getFilename() != null && !getFilename().endsWith(".docx")) setFilename(getFilename()+".docx");
					bytes = getPrintingAction().getLauncher().printWordDocument(prnLayout);
				}else{
					if(getFilename() != null && !getFilename().endsWith(".pdf")) setFilename(getFilename()+".pdf");
					bytes = getPrintingAction().getLauncher().web_FillReport(prnLayout, prnLayout.getFileName());
				}
				if(bytes != null){
					if(wordDoc){
						setMIMEType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
					}else{
						setMIMEType("application/pdf");
					}
		  		setStreamSource(new FStreamSource(bytes));
				}
				downloadStream = super.getStream();
			}
		}
		return downloadStream;
	}

	public PrnLayout getPrnLayout() {
		return prnLayout;
	}

	public void setPrnLayout(PrnLayout prnLayout) {
		this.prnLayout = prnLayout;
	}

	public boolean isWordDoc() {
		return wordDoc;
	}
{'fraction_non_alphanumeric': 0.11640610284422678, 'fraction_numerical': 0.00037671877943115466, 'mean_word_length': 4.537017726798749, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4159122', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1660, 'n_words': 284}