WorkFlowBean workFlowBean = (WorkFlowBean) modelMap.get("workFlowBean");
httpSession = workFlowBean.getRequest().getSession(false);
xwconn = connectionManager.getConnection(workFlowBean.getArchive());
MultiEditingManager editingManager = new MultiEditingManager(parameterMap, confBean, userBean, workFlowBean);
editingManager.setTheXML(new XMLBuilder(xwconn.getSingleXMLFromNumDoc(Integer.parseInt(physDoc)), "ISO-8859-1"));
confBean = editingManager.rewriteMultipleConf(confControl);
managingBean.setSelid(selid);
if (!physDoc.equals("") && makeAction.equals("true")) { // DO
managingBean.setPhysDoc(Integer.parseInt(physDoc));
ArrayList elementiNum = new ArrayList();
if (applyTo.equals("selected") || applyTo.equals("prevSibling") || applyTo.equals("nextSibling")) {
if (applyTo.equals("nextSibling")) {
int theBrother = managingBean.getPhysDoc();
RenumberUtils.Renumber rn = RenumberUtils.getSiblingRenumber(theValue, 1);
while (theBrother > 0) {
theBrother = xwconn.getNumDocNextBrother(theBrother);
if (theBrother > 0) {
Object[] value = new Object[2];
value[0] = new Integer(theBrother);
value[1] = rn.renumber();
elementiNum.add(value);
}
}
} else if (applyTo.equals("prevSibling")) {
int theBrother = managingBean.getPhysDoc();
RenumberUtils.Renumber rn = RenumberUtils.getSiblingRenumber(theValue, -1, Integer.parseInt(numZeri));
while (theBrother > 0) {
theBrother = xwconn.getNumDocPreviousBrother(theBrother);
if (theBrother > 0) {
Object[] value = new Object[2];
value[0] = new Integer(theBrother);
value[1] = rn.renumber();
// elementiNum.add(new Integer(theBrother));
elementiNum.add(value);
}
}
} else {// DA SELEZIONE MULTIPLA
RenumberUtils.Renumber rn = RenumberUtils.getSiblingRenumber(theValue, 1, Integer.parseInt(numZeri));
ArrayList elementiNumTemp = ((ManagingBean) httpSession.getAttribute(workFlowBean.getManagingBeanName())).getListPhysDoc();
for (int i = 0; i < elementiNumTemp.size(); i++) {
Object[] value = new Object[2];
value[0] = (Integer) (elementiNumTemp.get(i));
value[1] = rn.renumber();
elementiNum.add(value);
}
}
} else {
it.highwaytech.db.QueryResult qr = null;
if (applyTo.equals("selid")) {
qr = xwconn.getQRFromSelId(selid);
RenumberUtils.Renumber rn = RenumberUtils.getSiblingRenumber(theValue, 1, Integer.parseInt(numZeri));
for (int z = 0; z < qr.elements; z++) {
int theNumber = xwconn.getNumDocFromQRElement(qr, z);
Object[] value = new Object[2];
value[0] = new Integer(theNumber);
value[1] = rn.renumber();
elementiNum.add(value);
}
} else if (applyTo.equals("sons")) {
qr = xwconn.getSonsFromNumDoc(managingBean.getPhysDoc());
RenumberUtils.Renumber rn = RenumberUtils.getSonsRenumber(theValue, Integer.parseInt(numZeri));
for (int z = 0; z < qr.elements; z++) {
int theNumber = xwconn.getNumDocFromQRElement(qr, z);
Object[] value = new Object[2];
value[0] = new Integer(theNumber);
value[1] = rn.renumber();
elementiNum.add(value);
}
} else if (applyTo.equals("hier")) {
RenumberUtils.Renumber rn = RenumberUtils.getHierRenumber(theValue, Integer.parseInt(numZeri));
qr = xwconn.getQRFromHier(managingBean.getPhysDoc(), true);
for (int i = 0; i < qr.elements; i++) {
int theNumber = xwconn.getNumDocFromQRElement(qr, i);
int tmpLevel = (xwconn.getHierPath(theNumber)).depth();
System.out.println("MultiModRenumberCommand.execute() " + tmpLevel);
Object[] value = new Object[2];
value[0] = new Integer(theNumber);
value[1] = rn.renumber(tmpLevel, countBlock);
elementiNum.add(value);
}
}
}
managingBean.setNumElementi(elementiNum.size());
managingBean.setTitle((xwconn.getTitle(xwconn.connection, xwconn.getTheDb(), Integer.parseInt(physDoc))).getTitle());
managingBean.setDispatchView("multiModResult");
int totElementi = elementiNum.size();
int processati = 0;
int errori = 0;
// HashMap laMappa = new HashMap();
for (int i = 0; i < totElementi; i++) {
int docCorrente = 0;
try {
docCorrente = ((Integer) (((Object[]) elementiNum.get(i))[0])).intValue();
} catch (Exception e) {
docCorrente = (Integer.parseInt((String) elementiNum.get(i)));
}
try {
String docXML = xwconn.getSingleXMLFromNumDoc(docCorrente);
XMLBuilder xmlBuilder = new XMLBuilder(docXML, "ISO-8859-1");
String codiceGenerato = ((String) (((Object[]) elementiNum.get(i))[1]));
xmlBuilder.insertValueAt(codiceId, codiceGenerato);
xwconn.executeUpdateByDocNumber(xmlBuilder.getXML("ISO-8859-1"), docCorrente);
processati++;
} catch (Exception e) {
managingBean.addErrorMsg(e.getMessage());
errori++;
}