this.parameterMap = parameterMap;
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");