this.modelMap = modelMap;
}
public ManagingBean execute() throws Exception {
XWConnection xwconn = null;
ConnectionManager connectionManager = new ConnectionManager();
ConfBean confBean = null;
ManagingBean managingBean = null;
String physDoc = MyRequest.getParameter("physDoc", parameterMap);
String makeAction = MyRequest.getParameter("makeAction", parameterMap);
String applyTo = MyRequest.getParameter("applyTo", parameterMap);
String selid = MyRequest.getParameter("selid", parameterMap);
String formattedText = MyRequest.getParameter("formattedText", parameterMap);
HttpSession httpSession = null;
String PDFType = ""; // 4 SELEZIONE
// 1 UN DOCUMENTO
// 2 FIGLI DI PRIMO LIVELLO
// 3 TUTTA LA GERARCHIA
List<String> confControl = new ArrayList<String>();
confControl.add("titleManager");
confControl.add("upload");
confControl.add("media");
String PDFXSLType = MyRequest.getParameter("PDFXSLType", parameterMap); // NOME FILE XSL
InputStream xsltInputStream = null;
InputStream xmlInputStream = null;
try {
// ManagingBean esiste in sessione ma io uso uno nuovo per le funzioni di gestione
managingBean = new ManagingBean();
UserBean userBean = (UserBean) modelMap.get("userBean");
confBean = (ConfBean) modelMap.get("confBean");
WorkFlowBean workFlowBean = (WorkFlowBean) modelMap.get("workFlowBean");
httpSession = workFlowBean.getRequest().getSession(false);
xwconn = connectionManager.getConnection(workFlowBean.getArchive());
XMLBuilder theXMLDoc = null;
if (!applyTo.equals("fromQuery")) {
managingBean.setPhysDoc(Integer.parseInt(physDoc));
String docXML = xwconn.getSingleXMLFromNumDoc(managingBean.getPhysDoc());
managingBean.setDocXML(docXML);
theXMLDoc = new XMLBuilder(managingBean.getDocXML(), "ISO-8859-1");
} else {
theXMLDoc = new XMLBuilder("root");
}
MultiEditingManager editingManager = new MultiEditingManager(parameterMap, confBean, userBean, workFlowBean);
editingManager.setTheXML(theXMLDoc);
confBean = editingManager.rewriteMultipleConf(confControl);
XSLDir = findXSLPath(userBean, workFlowBean);
if (XSLDir != null) {
modelMap.put("XSLBeanArrayList", XSLLoader.loadXSL(XSLDir));
} else {
throw new Exception("Impostare pdfPrint.");
}
managingBean.setSelid(selid);
// System.out.println("aaaaaaaaaaaaaaaaa 04");
if (!physDoc.equals("") && makeAction.equals("")) {
managingBean.setDocLowerBrother(xwconn.getNumDocNextBrother(managingBean.getPhysDoc()));
managingBean.setDocUpperBrother(xwconn.getNumDocPreviousBrother(managingBean.getPhysDoc()));
it.highwaytech.db.QueryResult qrHier = xwconn.getQRFromHier(managingBean.getPhysDoc(), true);
managingBean.setNumElementiHier(qrHier.elements);
it.highwaytech.db.QueryResult qrSons = xwconn.getSonsFromNumDoc(managingBean.getPhysDoc());
managingBean.setNumElementiSons(qrSons.elements);
if (!selid.equals("")) {
it.highwaytech.db.QueryResult qr = xwconn.getQRFromSelId(selid);
managingBean.setNumElementi(qr.elements);
}
managingBean.setTitle((xwconn.getTitle(xwconn.connection, xwconn.getTheDb(), managingBean.getPhysDoc())).getTitle());
managingBean.setDispatchView("pdfMenu");
if (httpSession.getAttribute(workFlowBean.getManagingBeanName()) != null) {
ArrayList listDocs = ((ManagingBean) httpSession.getAttribute(workFlowBean.getManagingBeanName())).getListPhysDoc();
if (listDocs != null && listDocs.size() > 0) {
managingBean.setListPhysDoc(listDocs);
}
}
// System.out.println("aaaaaaaaaaaaaaaaa 05");
} else if (!physDoc.equals("") && makeAction.equals("true")) { // DO
String PDFPhrase = null;
String PDFNdoc = null;
ArrayList elementiNum = new ArrayList();
if (applyTo.equals("selected") || applyTo.equals("prevSibling") || applyTo.equals("nextSibling") || applyTo.equals("this")) {
if (applyTo.equals("nextSibling")) {
int theBrother = managingBean.getPhysDoc();
while (theBrother > 0) {
theBrother = xwconn.getNumDocNextBrother(theBrother);
if (theBrother > 0) {
elementiNum.add(new Integer(theBrother));
}
}
} else if (applyTo.equals("prevSibling")) {
int theBrother = managingBean.getPhysDoc();
while (theBrother > 0) {
theBrother = xwconn.getNumDocPreviousBrother(theBrother);
if (theBrother > 0) {
elementiNum.add(new Integer(theBrother));
}
}
} else if (applyTo.equals("this")) {
elementiNum.add(new Integer(physDoc));
} else {// DA SELEZIONE MULTIPLA
elementiNum = ((ManagingBean) httpSession.getAttribute(workFlowBean.getManagingBeanName())).getListPhysDoc();
}
// System.out.println("aaaaaaaaaaaaaaaaa 07");
if (elementiNum.size() > 0) {
String idXpath = MyRequest.getParameter("idXpath", parameterMap);// "/c/@id";
if (idXpath == null) {
throw new Exception("Impostare idXpath");
}
xwconn.setTitleRole("XML," + idXpath);
QueryResult qrTempTo = new QueryResult();
for (int a = 0; a < elementiNum.size(); a++) {
try {
int docCorrente = 0;
try {
docCorrente = ((Integer) elementiNum.get(a)).intValue();
} catch (Exception e) {
docCorrente = (Integer.parseInt((String) elementiNum.get(a)));
}
String idValue = ((xwconn.getTitle(xwconn.connection, xwconn.getTheDb(), docCorrente)).getTitle()).trim();
if (!idValue.equals("")) {
QueryResult qrTempFrom = xwconn.getQRfromPhrase("[XML," + idXpath + "]=\"" + idValue + "\"");
// System.out.println("xdams - [INFO] :::::::: phrase " + "[XML," + idXpath + "]=\"" + idValue + "\"");
// System.out.println("qrTempFrom.elements: " + qrTempFrom.elements);
if (qrTempFrom.elements > 0) {
xwconn.addToQueryResult(qrTempTo, qrTempFrom);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
xwconn.restoreTitleRole();
PDFType = "4";
if (qrTempTo != null && qrTempTo.elements > 0)
PDFPhrase = qrTempTo.id;
}
} else {
// System.out.println("aaaaaaaaaaaaaaaaa 08");
if (applyTo.equals("selid")) {
PDFPhrase = (xwconn.getQRFromSelId(selid)).id;
PDFType = "4";
} else if (applyTo.equals("hier")) {
PDFType = "3";
PDFNdoc = MyRequest.getParameter("physDoc", parameterMap);
} else if (applyTo.equals("single")) {
PDFType = "1";
PDFNdoc = MyRequest.getParameter("physDoc", parameterMap);
} else if (applyTo.equals("sons")) {
PDFType = "2";
PDFNdoc = MyRequest.getParameter("physDoc", parameterMap);
} else if (applyTo.equals("fromQuery")) {
if (MyRequest.getParameter("fromQuery", parameterMap).trim().equals("")) {
throw new Exception("Impostare fromQuery");
}
PDFPhrase = (xwconn.getQRfromPhrase(MyRequest.getParameter("fromQuery", parameterMap), MyRequest.getParameter("sortQuery", parameterMap))).id;
PDFType = "4";
}
}
// System.out.println("aaaaaaaaaaaaaaaaa 09");
managingBean.setExportXML(executePDFPrint(workFlowBean, xwconn, PDFPhrase, PDFNdoc, PDFType, PDFXSLType));
String headerPDF = MyRequest.getParameter("headerPDF", parameterMap).trim();
String footerPDF = MyRequest.getParameter("footerPDF", parameterMap).trim();
String subtitlePDF = MyRequest.getParameter("subtitlePDF", parameterMap).trim();
if (!headerPDF.equals("") || !footerPDF.equals("") || !subtitlePDF.equals("")) {
try {
StringBuffer stringBuffer = new StringBuffer(managingBean.getExportXML());
String stringInsert = "<pdfPrint>" + "<header></header>" + "<footer></footer>" + "<subtitle></subtitle>" + "</pdfPrint>";
stringInsert = StringUtils.replace(stringInsert, "<header></header>", "<header>" + headerPDF + "</header>");
stringInsert = StringUtils.replace(stringInsert, "<footer></footer>", "<footer>" + footerPDF + "</footer>");
stringInsert = StringUtils.replace(stringInsert, "<subtitle></subtitle>", "<subtitle>" + subtitlePDF + "</subtitle>");
// questo indexOf fa cagare
stringBuffer.insert(managingBean.getExportXML().indexOf("\">") + 2, stringInsert);
managingBean.setExportXML(stringBuffer.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
// System.out.println("aaaaaaaaaaaaaaaaa 10 "+managingBean.getExportXML());
ManagingBean sessionMenaging = (ManagingBean) httpSession.getAttribute(workFlowBean.getManagingBeanName());
System.out.println("aaaaaaaaaaaaaaaaa 11");
// sessionMenaging.setListPhysDoc(new ArrayList()); // SVUOTO GLI ELEMENTI SELEZIONATI
if (managingBean.getExportXML() != null && !(managingBean.getExportXML()).equals("")) { // STAMPO PDF
// InputStream
xsltInputStream = new FileInputStream(new File((XSLDir) + "/" + MyRequest.getParameter("PDFXSLType", parameterMap)));
// InputStream
String XMLorigin = managingBean.getExportXML();
if (formattedText.equals("true")) {
// XMLorigin = StringUtils.replace(XMLorigin,"<![CDATA[","");
XMLorigin = XMLorigin.replaceAll("<!\\[CDATA\\[", "");
XMLorigin = XMLorigin.replaceAll("\\]\\]>", "");
XMLorigin = XMLorigin.replaceAll("<em>", "<em>");
XMLorigin = XMLorigin.replaceAll("</em>", "</em>");
XMLorigin = XMLorigin.replaceAll("<br />", "<br />");
XMLorigin = XMLorigin.replaceAll("<strong>", "<strong>");
XMLorigin = XMLorigin.replaceAll("</strong>", "</strong>");
XMLorigin = XMLorigin.replaceAll("&", "&");
XMLorigin = XMLorigin.replaceAll("&amp;", "&");
XMLorigin = XMLorigin.replaceAll("&#", "&#");
}
xmlInputStream = new ByteArrayInputStream(XMLorigin.getBytes("iso-8859-1"));
String mimeConstant = MimeConstants.MIME_PDF;
String contentType = "pdf";
String extension = "pdf";
if (MyRequest.getParameter("PrintType", parameterMap).equals("") || MyRequest.getParameter("PrintType", parameterMap).equals("pdf")) {
mimeConstant = MimeConstants.MIME_PDF;
contentType = "application/pdf";
extension = "pdf";
} else if (MyRequest.getParameter("PrintType", parameterMap).equals("rtf")) {
mimeConstant = MimeConstants.MIME_RTF;
contentType = "application/rtf";
extension = "rtf";
} else if (MyRequest.getParameter("PrintType", parameterMap).equals("jpg")) {
mimeConstant = MimeConstants.MIME_JPEG;
contentType = "image/jpeg";
extension = "jpg";
} else if (MyRequest.getParameter("PrintType", parameterMap).equals("eps")) {
mimeConstant = MimeConstants.MIME_EPS;
contentType = "application/postscript";
extension = "eps";
} else if (MyRequest.getParameter("PrintType", parameterMap).equals("tif")) {
mimeConstant = MimeConstants.MIME_TIFF;
contentType = "image/tiff";
extension = "tif";
} else if (MyRequest.getParameter("PrintType", parameterMap).equals("svg")) {
mimeConstant = MimeConstants.MIME_SVG;
contentType = "image/svg+xml";
extension = "svg";
} else if (MyRequest.getParameter("PrintType", parameterMap).equals("csv")) {
mimeConstant = MimeConstants.MIME_PLAIN_TEXT;
contentType = "text/csv";
extension = "csv";
} else if (MyRequest.getParameter("PrintType", parameterMap).equals("html")) {
mimeConstant = MimeConstants.MIME_PLAIN_TEXT;
contentType = "text/html";
extension = "html";
}
// Systemem.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbb 02");
// Systemem.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbb "+xmlInputStream);
// Systemem.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbb "+xsltInputStream);
// Systemem.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbb "+contentType);
// Systemem.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbb "+mimeConstant);
// Systemem.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbb 02");
managingBean.setDispatchView(null);
convert(xmlInputStream, xsltInputStream, workFlowBean, contentType, mimeConstant, extension);
}
}
modelMap.put("managingBean", managingBean);
} catch (Exception e) {
e.printStackTrace();
modelMap.put("managingBean", null);
throw new Exception(e.toString());
} finally {
if (xsltInputStream != null) {
xsltInputStream.close();
}
if (xmlInputStream != null) {
xmlInputStream.close();
}
connectionManager.closeConnection(xwconn);
}
return managingBean;
}