Package org.xdams.xmlengine.connection.manager

Examples of org.xdams.xmlengine.connection.manager.ConnectionManager


    this.modelMap = modelMap;
  }

  public void execute() throws Exception {
    XWConnection xwconn = null;
    ConnectionManager connectionManager = new ConnectionManager();
    ConfBean confBean = null;
    String physDoc = MyRequest.getParameter("physDoc", parameterMap);
    UploadBean uploadBean = (UploadBean) modelMap.get("uploadBean");
    List<String> confControl = new ArrayList<String>();
    confControl.add("upload");
    try {
      UserBean userBean = (UserBean) modelMap.get("userBean");
      confBean = (ConfBean) modelMap.get("confBean");
      WorkFlowBean workFlowBean = (WorkFlowBean) modelMap.get("workFlowBean");
      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);
      LoadUploadBean.loadUploadBean(uploadBean, confBean.getTheXMLConfUpload(), modelMap);
      System.out.println(uploadBean);
      // da prendere dentro workflowBean
      String archiveName = workFlowBean.getAlias();
      String domainName = userBean.getAccountRef();
      for (int i = 0; i < uploadBean.getCommandLine().size(); i++) {
        UploadCommandLine uploadCommandLine = uploadBean.getCommandLine().get(i);
        try {
          File fileUploadTempPath = new File(uploadCommandLine.getUploadTempPath());
          if (!(fileUploadTempPath.exists())) {
            fileUploadTempPath.mkdirs();
          }
          File uploadFile = new File(uploadCommandLine.getUploadTempPath() + System.getProperty("file.separator") + CommonUtils.stripPunctuation(FilenameUtils.getBaseName(uploadBean.getName()), '-') + "." + FilenameUtils.getExtension(uploadBean.getName()));

          uploadFile.setReadable(true);
          if (!uploadFile.exists()) {
            uploadBean.getFiledata().transferTo(uploadFile);
          }
        } catch (Exception e) {
          uploadBean.getResultError().append("errore nel copia nella cartella temporanea: " + e.getMessage());
          throw e;
        }

        String numFile = "0001";
        StringBuilder uploadPath = null;
        try {
          // controlli su filesystem se esiste la radice getUploadPath e la sua composizione
          uploadPath = new StringBuilder(uploadCommandLine.getUploadPath().trim());
          if (!uploadPath.toString().endsWith(System.getProperty("file.separator"))) {
            uploadPath.append(System.getProperty("file.separator"));
          }

          uploadPath.append(domainName);
          uploadPath.append(System.getProperty("file.separator"));
          uploadPath.append(archiveName);
          uploadPath.append(System.getProperty("file.separator"));
          uploadPath.append(uploadCommandLine.getUploadNameDir());
          uploadPath.append(System.getProperty("file.separator"));
          // tolgo la punteggiatura
          uploadBean.setIdRecord(CompositionRule.stripPunctuation(uploadBean.getIdRecord(), '\u0000'));
          if (uploadBean.getRenameFile().equalsIgnoreCase("true")) {
            uploadPath.append(CompositionRule.compose(uploadBean.getCompositionRuleDir(), uploadBean.getIdRecord(), System.getProperty("file.separator")));
          }
          File fileUploadPath = new File(uploadPath.toString());
          System.out.println(uploadPath);
          if (!(fileUploadPath.exists())) {
            fileUploadPath.mkdirs();
          } else {
            if (fileUploadPath.listFiles().length == 0) {
              numFile = StringUtils.leftPad("1", 4, "0");
            } else {
              numFile = StringUtils.leftPad("" + (fileUploadPath.listFiles().length + 1), 4, "0");
            }
          }
          if (uploadBean.getRenameFile().equalsIgnoreCase("true") && !uploadBean.getCompositionReplaceName().trim().equals("")) {
            uploadBean.setIdRecord(uploadBean.getIdRecord().replaceAll(uploadBean.getCompositionReplaceName(), ""));
          }
          if (uploadBean.getRenameFile().equalsIgnoreCase("true")) {
            uploadPath.append(CompositionRule.compose(uploadBean.getCompositionRuleFile(), uploadBean.getIdRecord(), "."));
            uploadPath.append(numFile);
            uploadPath.append(".");
            uploadPath.append(org.apache.commons.io.FilenameUtils.getExtension(uploadBean.getName()));
          } else {
            uploadPath.append(uploadBean.getName());
          }

        } catch (Exception e1) {
          throw e1;
        }
        System.out.println("UploadCommand.execute() uploadPath.toString() " + uploadPath.toString());

        // verifico se devo lanciare un comando oppure no
        if (!uploadCommandLine.getCommandLine().trim().equals("") && uploadBean.getUploadType().equalsIgnoreCase("resize")) {
          Map<String, String> valuesMap = new HashMap<String, String>();

          if (CommonUtils.isWindows()) {
            valuesMap.put("imgIn", "\"" + uploadCommandLine.getUploadTempPath() + System.getProperty("file.separator") + CommonUtils.stripPunctuation(FilenameUtils.getBaseName(uploadBean.getName()), '-') + "." + FilenameUtils.getExtension(uploadBean.getName()) + "\"");
            valuesMap.put("imgOut", "\"" + uploadPath.toString() + "\"");
          } else {
            System.out.println("quiiiiiiiii");
            valuesMap.put("imgIn", (uploadCommandLine.getUploadTempPath() + System.getProperty("file.separator") + CommonUtils.stripPunctuation(FilenameUtils.getBaseName(uploadBean.getName()), '-') + "." + FilenameUtils.getExtension(uploadBean.getName())));
            System.out.println("spazi linux" + (uploadCommandLine.getUploadTempPath() + System.getProperty("file.separator") + CommonUtils.stripPunctuation(FilenameUtils.getBaseName(uploadBean.getName()), '-') + "." + FilenameUtils.getExtension(uploadBean.getName())));
            valuesMap.put("imgOut", (uploadPath.toString()));
          }
          StrSubstitutor strSubstitutor = new StrSubstitutor(valuesMap);
          String cmd = strSubstitutor.replace(uploadCommandLine.getCommandLine());
          System.out.println(cmd);
          try {
            Runtime runtime = Runtime.getRuntime();
            Process process = runtime.exec(cmd);
            process.waitFor();
            if (process.exitValue() != 0) {
              InputStream lsOut = process.getErrorStream();
              InputStreamReader r = new InputStreamReader(lsOut);
              BufferedReader in = new BufferedReader(r);
              String line;
              int maxLine = 0;
              while ((line = in.readLine()) != null && maxLine < 10) {
                uploadBean.getResultError().append(line);
                maxLine++;
              }
              in.close();
              r.close();
              lsOut.close();
              System.out.println(uploadBean.getResultError());
            } else {
              String resultName = StringUtils.remove(uploadPath.toString(), uploadCommandLine.getUploadPath());
              resultName = StringUtils.remove(resultName, archiveName);
              // resultName = StringUtils.remove(resultName, domainName);
              resultName = StringUtils.replaceOnce(resultName, domainName, "");
              resultName = StringUtils.remove(resultName, uploadCommandLine.getUploadNameDir());
              resultName = resultName.replaceAll("\\\\", "/");
              resultName = resultName.replaceAll("[/]*(.*)", "/$1");
              if (resultName.endsWith("/")) {
                try {
                  resultName = resultName.substring(0, resultName.length() - 1);
                } catch (Exception e) {
                  uploadBean.getResultError().append(e.getMessage());
                }
              }
              uploadBean.setResult(new StringBuilder(resultName));
              System.out.println("uploadPath resize: " + resultName);
            }
          } catch (Exception e) {
            uploadBean.getResultError().append("errore nel processo di conversione file: " + e.getMessage());
          }
        } else {
          try {
            FileUtils.copyFile(new File(uploadCommandLine.getUploadTempPath() + System.getProperty("file.separator") + CommonUtils.stripPunctuation(FilenameUtils.getBaseName(uploadBean.getName()), '-') + "." + FilenameUtils.getExtension(uploadBean.getName())), new File(uploadPath.toString()));
            System.out.println("uploadPath.toString() " + uploadPath.toString());
            String resultName = StringUtils.remove(uploadPath.toString(), uploadCommandLine.getUploadPath());
            resultName = StringUtils.remove(resultName, archiveName);
            // resultName = StringUtils.remove(resultName, domainName);
            resultName = StringUtils.replaceOnce(resultName, domainName, "");
            resultName = StringUtils.remove(resultName, uploadCommandLine.getUploadNameDir());
            resultName = resultName.replaceAll("\\\\", "/");
            resultName = resultName.replaceAll("[/]*(.*)", "/$1");
            if (resultName.endsWith("/")) {
              try {
                resultName = resultName.substring(0, resultName.length() - 1);
              } catch (Exception e) {
                uploadBean.getResultError().append(e.getMessage());
              }
            }
            uploadBean.setResult(new StringBuilder(resultName));
            System.out.println("uploadPath simple: " + resultName);
          } catch (Exception e) {
            uploadBean.getResultError().append("errore nella copia del file nella cartella di destinazione: " + e.getMessage());
            throw e;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new Exception(e.toString());
    } finally {
      connectionManager.closeConnection(xwconn);
    }
  }
View Full Code Here


    this.modelMap = modelMap;
  }

  public void execute() throws Exception {
    XWConnection xwconn = null;
    ConnectionManager connectionManager = new ConnectionManager();
    ConfBean confBean = null;
    HttpServletRequest request = null;
    try {
      UserBean userBean = (UserBean) modelMap.get("userBean");
      confBean = (ConfBean) modelMap.get("confBean");
      WorkFlowBean workFlowBean = (WorkFlowBean) modelMap.get("workFlowBean");
      String thePne = workFlowBean.getArchive().getPne();
      request = workFlowBean.getRequest();
      MyRequest myRequest = new MyRequest(request);
      if (!(myRequest.getParameter("thePne")).equals("")) {
        thePne = myRequest.getParameter("thePne");
      }
      String[] nomiRequest = MyRequest.ordinaRequest(request, "." + thePne + ".");
      xwconn = connectionManager.getConnection(workFlowBean.getArchive());
      XMLBuilder builder = new XMLBuilder(thePne);
      for (int i = 0; i < nomiRequest.length; i++) {
        boolean isCDATA = false;
        String ilNome = nomiRequest[i].replace('.', '/');
        String ilValore = (request.getParameter(nomiRequest[i])).trim();
        if (ilNome.endsWith("/@cdata")) {
          ilNome = StringUtils.chomp(ilNome, "/@cdata");
          isCDATA = true;
        }
        if (!ilValore.equals("")) {
          if (isCDATA) {
            builder.insertNode(ilNome, ilValore, true);
          } else {
            builder.insertNode(ilNome, ilValore);
          }
        }
      }
      String theXML = builder.getXML("ISO-8859-1", false);
//      System.out.println(theXML);
      xwconn.executeUpdateByDocNumber(XMLCleaner.clearXwXML(theXML, false), Integer.parseInt(request.getParameter("physDoc")));
    } catch (Throwable e) {
      e.printStackTrace();
      throw new Exception(e.toString());
    } finally {
      connectionManager.closeConnection(xwconn);
    }
  }
View Full Code Here

    this.modelMap = modelMap;
  }

  public void execute() throws Exception {
    XWConnection xwconn = null;
    ConnectionManager connectionManager = new ConnectionManager();
    ConfBean confBean = null;
    String physDoc = MyRequest.getParameter("physDoc", parameterMap);
    String pathToView = MyRequest.getParameter("pathToView", parameterMap);
    UploadBean uploadBean = (UploadBean) modelMap.get("uploadBean");
    List<String> confControl = new ArrayList<String>();
    confControl.add("upload");
    try {
      UserBean userBean = (UserBean) modelMap.get("userBean");
      confBean = (ConfBean) modelMap.get("confBean");
      WorkFlowBean workFlowBean = (WorkFlowBean) modelMap.get("workFlowBean");
      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);
      LoadUploadBean.loadUploadBean(uploadBean, confBean.getTheXMLConfUpload(), modelMap);
       if (!pathToView.equals("")) {
        File file = new File(pathToView);
        File[] files = file.listFiles();
        modelMap.put("files", files);
      }else{
        File file = new File(uploadBean.getAssociatePathDir());
        File[] files = file.listFiles();
        modelMap.put("files", files);
      }
     
     
    } catch (Exception e) {
      e.printStackTrace();
      throw new Exception(e.toString());
    } finally {
      connectionManager.closeConnection(xwconn);
    }
  }
View Full Code Here

  @RequestMapping(value = "/custom/{archive}/page")
  public String customPage(@ModelAttribute("userBean") UserBean userBean, @ModelAttribute("confBean") ConfBean confBean, @ModelAttribute CustomPageBean customPageBean, @PathVariable String archive, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) throws Exception {
    common(confBean, userBean, archive, modelMap, request, response);
    XWConnection xwconn = null;
    ConnectionManager connectionManager = new ConnectionManager();
    WorkFlowBean workFlowBean = (WorkFlowBean) modelMap.get("workFlowBean");
    List<String> confControl = customPageBean.getConfControl();
    try {
      MultiEditingManager editingManager = new MultiEditingManager(request.getParameterMap(), confBean, userBean, workFlowBean);
      if (customPageBean.getPhysDoc() != null && !customPageBean.getPhysDoc().equals("")) {
        xwconn = connectionManager.getConnection(workFlowBean.getArchive());
        customPageBean.setXmlBuilder(new XMLBuilder(XMLCleaner.clearXwXML(xwconn.getSingleXMLFromNumDoc(Integer.parseInt(customPageBean.getPhysDoc())), true), "ISO-8859-1"));
        editingManager.setTheXML(customPageBean.getXmlBuilder());
      } else {
        editingManager.setTheXML(new XMLBuilder("root"));
      }

      confBean = editingManager.rewriteMultipleConf(confControl);
    } catch (Exception e) {
      throw e;
    } finally {
      connectionManager.closeConnection(xwconn);
    }
    return customPageBean.getPageName();
  }
View Full Code Here

    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);// myRequest.getParameter("physDoc");
    String makeAction = MyRequest.getParameter("makeAction", parameterMap); // myRequest.getParameter("makeAction");
    String applyTo = MyRequest.getParameter("applyTo", parameterMap); // myRequest.getParameter("applyTo");
    String selid = MyRequest.getParameter("selid", parameterMap); // myRequest.getParameter("selid");
    String whichTo = MyRequest.getParameter("whichTo", parameterMap); // myRequest.getParameter("whichTo");
    boolean menuFlag = true;
    HttpSession httpSession = null;
    List<String> confControl = new ArrayList<String>();
    confControl.add("titleManager");
    confControl.add("docEdit");
    try {
      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());
      MultiEditingManager editingManager = new MultiEditingManager(parameterMap, confBean, userBean, workFlowBean);
      editingManager.setTheXML(new XMLBuilder(xwconn.getSingleXMLFromNumDoc(Integer.parseInt(physDoc)), "ISO-8859-1"));
      confBean = editingManager.rewriteMultipleConf(confControl);
      if (httpSession.getAttribute(workFlowBean.getManagingBeanName()) != null) {
        managingBean = ((ManagingBean) httpSession.getAttribute(workFlowBean.getManagingBeanName()));
      } else {
        managingBean = new ManagingBean();
      }
      // mi serve per contare i successi e no
      managingBean.setDocSuccessi(0);
      managingBean.setDocErrori(0);

      managingBean.setPhysDoc(Integer.parseInt(physDoc));
      managingBean.setTitle((xwconn.getTitle(xwconn.connection, xwconn.getTheDb(), managingBean.getPhysDoc())).getTitle());

      it.highwaytech.db.QueryResult qr = null;
      if (!selid.equals("")) {
        qr = xwconn.getQRFromSelId(selid);
        managingBean.setNumElementi(qr.elements);
      }

      if (!whichTo.equals("") && whichTo.equals("selected")) {
        // eseguo il taglia multiplo come figlio
        if (managingBean != null && managingBean.getListPhysDoc().size() > 0 && makeAction != null && makeAction.equals("true") && applyTo != null && applyTo.equals("cut_as_son")) {
          menuFlag = false;
          ArrayList arrayList = managingBean.getListPhysDoc();
          for (int i = 0; i < arrayList.size(); i++) {
            try {
              int physDocToCut = Integer.parseInt((String) arrayList.get(i));
              xwconn.cut_paste(physDocToCut, Integer.parseInt(physDoc), it.highwaytech.broker.ServerCommand.navigarel_FIGLIOPADRE);
              managingBean.setDocSuccessi(managingBean.getDocSuccessi() + 1);
            } catch (Exception e) {
              managingBean.addErrorMsg("Errore in Sposta per il documento  " + arrayList.get(i) + " " + e.getMessage());
              managingBean.setDocErrori(managingBean.getDocErrori() + 1);
            }
          }
          managingBean.setDispatchView("multiMoveResult");
        }
        // eseguo il taglia multiplo come fratello precedente
        if (managingBean != null && managingBean.getListPhysDoc().size() > 0 && makeAction != null && makeAction.equals("true") && applyTo != null && applyTo.equals("cut_as_before")) {
          menuFlag = false;
          ArrayList arrayList = managingBean.getListPhysDoc();
          for (int i = 0; i < arrayList.size(); i++) {
            try {
              int physDocToCut = Integer.parseInt((String) arrayList.get(i));
              xwconn.cut_paste(physDocToCut, Integer.parseInt(physDoc), it.highwaytech.broker.ServerCommand.navigarel_MINOREMAGGIORE);
              managingBean.setDocSuccessi(managingBean.getDocSuccessi() + 1);
            } catch (Exception e) {
              managingBean.addErrorMsg("Errore in Sposta per il documento  " + arrayList.get(i) + " " + e.getMessage());
              managingBean.setDocErrori(managingBean.getDocErrori() + 1);
            }
          }
          managingBean.setDispatchView("multiMoveResult");
        }
        // eseguo il taglia multiplo come fratello successivo
        if (managingBean != null && managingBean.getListPhysDoc().size() > 0 && makeAction != null && makeAction.equals("true") && applyTo != null && applyTo.equals("cut_as_after")) {
          menuFlag = false;
          ArrayList arrayList = managingBean.getListPhysDoc();
          for (int i = arrayList.size() - 1; i >= 0; i--) {
            // for (int i = 0; i < arrayList.size(); i++) {
            try {
              int physDocToCut = Integer.parseInt((String) arrayList.get(i));
              xwconn.cut_paste(physDocToCut, Integer.parseInt(physDoc), it.highwaytech.broker.ServerCommand.navigarel_MAGGIOREMINORE);
              managingBean.setDocSuccessi(managingBean.getDocSuccessi() + 1);
            } catch (Exception e) {
              managingBean.addErrorMsg("Errore in Sposta per il documento  " + arrayList.get(i) + " " + e.getMessage());
              managingBean.setDocErrori(managingBean.getDocErrori() + 1);
            }
          }
          managingBean.setDispatchView("multiMoveResult");
        }
      } else if (!whichTo.equals("") && whichTo.equals("selid")) {

        if (managingBean != null && managingBean.getNumElementi() > 0 && makeAction != null && makeAction.equals("true") && applyTo != null && applyTo.equals("cut_as_son") && qr != null) {
          menuFlag = false;
          // ArrayList arrayList = managingBean.getListPhysDoc();
          for (int i = 0; i < qr.elements; i++) {
            int physDocToCut = -1;
            try {
              physDocToCut = xwconn.getNumDocFromQRElement(qr, i);// Integer.parseInt((String) arrayList.get(i));
              if (physDocToCut != Integer.parseInt(physDoc)) {
                xwconn.cut_paste(physDocToCut, Integer.parseInt(physDoc), it.highwaytech.broker.ServerCommand.navigarel_FIGLIOPADRE);
                managingBean.setDocSuccessi(managingBean.getDocSuccessi() + 1);
              }

            } catch (Exception e) {
              managingBean.addErrorMsg("Errore in Sposta per il documento  " + physDocToCut + " " + e.getMessage());
              managingBean.setDocErrori(managingBean.getDocErrori() + 1);
            }
          }
          managingBean.setDispatchView("multiMoveResult");
        }
        // eseguo il taglia multiplo come fratello precedente
        if (managingBean != null && managingBean.getNumElementi() > 0 && makeAction != null && makeAction.equals("true") && applyTo != null && applyTo.equals("cut_as_before") && qr != null) {
          menuFlag = false;
          managingBean.setDispatchView("multiMoveResult");
        }
        // eseguo il taglia multiplo come fratello successivo
        if (managingBean != null && managingBean.getNumElementi() > 0 && makeAction != null && makeAction.equals("true") && applyTo != null && applyTo.equals("cut_as_after") && qr != null) {
          menuFlag = false;
          managingBean.setDispatchView("multiMoveResult");
        }

      }

      // se e false allora il jspDispatch e gia stato settato per la risposta
      if (menuFlag) {
        managingBean.setDispatchView("multiMoveMenu");
      }
      managingBean.setNumElementi(managingBean.getDocErrori() + managingBean.getDocSuccessi());
      modelMap.put("confBean", confBean);
      modelMap.put("managingBean", managingBean);
    } catch (Exception e) {
      modelMap.put("confBean", confBean);
      modelMap.put("managingBean", managingBean);
      throw new Exception(e.toString());
    } finally {
      connectionManager.closeConnection(xwconn);
    }
    return managingBean;
  }
View Full Code Here

  }

  public ManagingBean execute() throws Exception {
    XWConnection xwconn = null;
    ConnectionManager connectionManager = new ConnectionManager();
    ConfBean confBean = null;
    ManagingBean managingBean = null;
    String physDoc = MyRequest.getParameter("physDoc", parameterMap); // myRequest.getParameter("physDoc");
    String makeAction = MyRequest.getParameter("makeAction", parameterMap); // myRequest.getParameter("makeAction");
    String theValue = MyRequest.getParameter("theValue", parameterMap); // myRequest.getParameter("theValue");
    String theXpath = MyRequest.getParameter("theXpath", parameterMap); // myRequest.getParameter("theXpath");
    String applyTo = MyRequest.getParameter("applyTo", parameterMap); // myRequest.getParameter("applyTo");
    String selid = MyRequest.getParameter("selid", parameterMap); // myRequest.getParameter("selid");
    HttpSession httpSession = null;
    List<String> confControl = new ArrayList<String>();
    confControl.add("titleManager");
    confControl.add("valoriControllati");
    confControl.add("docEdit");
    try {
      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());
      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("")) {
        managingBean.setPhysDoc(Integer.parseInt(physDoc));
        managingBean.setDocLowerBrother(xwconn.getNumDocNextBrother(managingBean.getPhysDoc()));
        managingBean.setDocUpperBrother(xwconn.getNumDocPreviousBrother(managingBean.getPhysDoc()));
        it.highwaytech.db.QueryResult qrSons = xwconn.getSonsFromNumDoc(managingBean.getPhysDoc());
        managingBean.setNumElementiSons(qrSons.elements);
        it.highwaytech.db.QueryResult qrHier = xwconn.getQRFromHier(managingBean.getPhysDoc(), false);
        managingBean.setNumElementiHier(qrHier.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.setDocXML(xwconn.getSingleXMLFromNumDoc(managingBean.getPhysDoc()));
        managingBean.setDispatchView("multiModMenu");
        if (httpSession.getAttribute(workFlowBean.getManagingBeanName()) != null) {
          ArrayList listDocs = ((ManagingBean) httpSession.getAttribute(workFlowBean.getManagingBeanName())).getListPhysDoc();
          if (listDocs != null && listDocs.size() > 0) {
            managingBean.setListPhysDoc(listDocs);
          }
        }

      } else if (!physDoc.equals("") && makeAction.equals("true")) { // DO
        managingBean.setPhysDoc(Integer.parseInt(physDoc));
        ArrayList elementiNum = ExtractDocument.extractDocument(httpSession, xwconn, managingBean, workFlowBean, applyTo, selid);
        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;
        SharpIncrementTool sharpIncrementTool = new SharpIncrementTool();
        for (int i = 0; i < totElementi; i++) {
          int docCorrente = 0;
          try {
            docCorrente = ((Integer) elementiNum.get(i)).intValue();
          } catch (Exception e) {
            docCorrente = (Integer.parseInt((String) elementiNum.get(i)));
          }
          try {
            // gestire con framework
            String docXML = xwconn.getSingleXMLFromNumDoc(docCorrente);
            XMLBuilder xmlBuilder = new XMLBuilder(docXML, "ISO-8859-1");
            String ilValore = theValue;
            String ilNome = theXpath;
            // if (ilValore.indexOf("[#") > 0 && ilValore.indexOf("#]") > 0 && totElementi > 1) {
            if ((ilValore.indexOf("[#") != -1) && (ilValore.indexOf("#]") > 0) && (totElementi > 1)) {
              ilValore = sharpIncrementTool.incrementValue(ilNome, ilValore);
            }
            xmlBuilder.insertValueAt(ilNome, ilValore);
            xwconn.executeUpdateByDocNumber(xmlBuilder.getXML("ISO-8859-1", false), docCorrente);
            processati++;
          } catch (Exception e) {
            managingBean.addErrorMsg(e.getMessage());
            errori++;
          }
        }
        managingBean.setDocSuccessi(processati);
        managingBean.setDocErrori(errori);
      }

      modelMap.put("confBean", confBean);
      modelMap.put("managingBean", managingBean);
    } catch (Exception e) {
      e.printStackTrace();
      modelMap.put("confBean", confBean);
      modelMap.put("managingBean", managingBean);
      throw new Exception(e.toString());
    } finally {
      connectionManager.closeConnection(xwconn);
    }

    return managingBean;
  }
View Full Code Here

    this.modelMap = modelMap;
  }

  public void execute() throws Exception {
    XWConnection xwconn = null;
    ConnectionManager connectionManager = new ConnectionManager();
    ConfBean confBean = null;
    QueryResult queryResult = null;
    HttpSession httpSession = null;
    String titleRole = "";
    List<String> confControl = new ArrayList<String>();
    confControl.add("titleManager");
    confControl.add("valoriControllati");
    confControl.add("media");
    confControl.add("query");
    try {
      UserBean userBean = (UserBean) modelMap.get("userBean");
      confBean = (ConfBean) modelMap.get("confBean");
      WorkFlowBean workFlowBean = (WorkFlowBean) modelMap.get("workFlowBean");
      httpSession = workFlowBean.getRequest().getSession(false);

      MultiEditingManager editingManager = new MultiEditingManager(parameterMap, confBean, userBean, workFlowBean);
      editingManager.setTheXML(new XMLBuilder("root"));
      confBean = editingManager.rewriteMultipleConf(confControl);

      // mettere queryBean
      System.out.println("QueryParserCommand.execute() workFlowBean.getAlias() " + workFlowBean.getAlias());
      System.out.println("QueryParserCommand.execute() aReq.getParameter(\"fromId\") " + workFlowBean.getRequest().getParameter("fromId") + "aaaaaaa");

      xwconn = connectionManager.getConnection(workFlowBean.getArchive());

      XMLBuilder builder = confBean.getTheXMLConfTitle();
      titleRole = builder.valoreNodo("/root/titleManager/sezione[@name='title']/titleRole/text()", false);
      System.out.println("QueryParserCommand.execute()" + titleRole);
      try {
        if (!titleRole.trim().equals("")) {
          xwconn.setTitleRole(titleRole);
        }
      } catch (Exception e) {
        System.out.println(" ---- ERROR ---- QueryParserCommand (xwconn.setTitleRole(titleRole)), title to parse: " + titleRole);
        xwconn.restoreTitleRole();
      }

      if (MyRequest.getParameter("fromId", parameterMap).equals("")) {
        FindDocumentCommand findDocumentCommand = null;
        try {
          findDocumentCommand = new FindDocumentCommand(parameterMap, modelMap);
          queryResult = findDocumentCommand.execute(workFlowBean, xwconn);
          // mi setto il selid per le operazioni di raffinamento
          workFlowBean.getRequest().setAttribute("qrId", queryResult.id);
          QueryBean queryBean = new QueryBean();
          queryBean.setDb(workFlowBean.getAlias());
          System.out.println("findDocumentCommand.getLaFrase() " + findDocumentCommand.getLaFrase());
          queryBean.setQuery(findDocumentCommand.getLaFrase());
          queryBean.setTot(String.valueOf(queryResult.elements));

          if (httpSession.getAttribute(workFlowBean.getQueryBeanName()) == null) {
            ArrayList arrQueryBean = new ArrayList();
            arrQueryBean.add(queryBean);
            httpSession.setAttribute(workFlowBean.getQueryBeanName(), arrQueryBean);
          } else {
            ArrayList arrQueryBean = (ArrayList) httpSession.getAttribute(workFlowBean.getQueryBeanName());
            boolean insert = true;
            int indexQr = 0;
            for (int i = 0; i < arrQueryBean.size(); i++) {
              QueryBean ilBean = (QueryBean) arrQueryBean.get(i);
              if (ilBean.getQuery().equals(queryBean.getQuery())) {
                insert = false;
                arrQueryBean.remove(i);
                arrQueryBean.add(queryBean);
                break;
              }
            }
            if (insert) {
              arrQueryBean.add(queryBean);
              httpSession.setAttribute(workFlowBean.getQueryBeanName(), arrQueryBean);
            }
          }
        } catch (Exception e) {
          queryResult = new QueryResult();
          workFlowBean.getRequest().setAttribute("qrId", queryResult.id);
        }
        System.out.println("QueryParserCommand.execute() " + findDocumentCommand.getLaFrase());
      } else {
        queryResult = xwconn.getQRFromSelId(MyRequest.getParameter("qrId", parameterMap));
        workFlowBean.getRequest().setAttribute("qrId", queryResult.id);
      }

      PagingTool pagingTool = new PagingTool(parameterMap, modelMap);
      pagingTool.pagingTitleBean(queryResult, xwconn);
    } catch (Exception e) {
      e.printStackTrace();
      throw new Exception(e.toString());
    } finally {
      if (!titleRole.trim().equals("")) {
        try {
          xwconn.restoreTitleRole();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
      modelMap.put("confBean", confBean);
      connectionManager.closeConnection(xwconn);
    }
  }
View Full Code Here

    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("&lt;em&gt;", "<em>");
            XMLorigin = XMLorigin.replaceAll("&lt;/em&gt;", "</em>");
            XMLorigin = XMLorigin.replaceAll("&lt;br /&gt;", "<br />");
            XMLorigin = XMLorigin.replaceAll("&lt;strong&gt;", "<strong>");
            XMLorigin = XMLorigin.replaceAll("&lt;/strong&gt;", "</strong>");
            XMLorigin = XMLorigin.replaceAll("&", "&amp;");
            XMLorigin = XMLorigin.replaceAll("&amp;amp;", "&amp;");
            XMLorigin = XMLorigin.replaceAll("&amp;#", "&#");
          }

          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;
  }
View Full Code Here

  }

  public void execute() throws Exception, SQLException {
    XWConnection xwconn = null;
    List<String> titleList = new ArrayList<String>();
    ConnectionManager connectionManager = new ConnectionManager();
     WorkFlowBean workFlowBean = null;
    Titles titlesPage = new Titles();
    LookupBean lookupBean = null;
    try {

       workFlowBean = (WorkFlowBean) modelMap.get("workFlowBean");
      lookupBean = (LookupBean) modelMap.get("lookupBean");
      xwconn = connectionManager.getConnection(workFlowBean.getArchiveLookup());
      QueryResult qr = null;
      String startPage = "";
      String keyCountQuery = MyRequest.getParameter("inputPerPage", "10", parameterMap);
      System.out.println("keyCountQuery keyCountQuery " + keyCountQuery);
      System.out.println("ENTRATO QUI " + (String) modelMap.get("selId"));
      System.out.println("ENTRATO selId " + MyRequest.getParameter("selId", parameterMap));

      if (!(MyRequest.getParameter("selId", parameterMap).trim()).equals("")) {
        qr = xwconn.getQRFromSelId(MyRequest.getParameter("selId", parameterMap));
        System.out.println("Lookup.execute()1111" + qr);
      } else {
        // System.out.println("ENTRATO QUA " + getQrSelId());
        qr = find(xwconn, "singoloTermine", keyCountQuery, lookupBean);
        System.out.println("Lookup.execute()2222" + qr);
      }
      System.out.println("Lookup.execute() " + qr);
      if (!MyRequest.getParameter("flagXML", parameterMap).equals("true")) {
        if (!lookupBean.getInputTitleRule().trim().equals("")) {
          xwconn.setTitleRule(xwconn.connection, workFlowBean.getArchiveLookup().getAlias(), lookupBean.getInputTitleRule());
        }
        System.out.println("Lookup.execute()333333" + qr);
        int totElements = qr.elements;
        // setQrSelId(qr.id);
        // System.out.println("PIPPETTO " + qr.elements + " FINE");
        if (!MyRequest.getParameter("startPage", parameterMap).equals("")) {
          startPage = MyRequest.getParameter("startPage", parameterMap);
        }
        if (startPage.equals("")) {
          titlesPage.setPages(Integer.parseInt(keyCountQuery), totElements);
        } else {
          titlesPage.setPages(Integer.parseInt(keyCountQuery), totElements, Integer.parseInt(startPage));
        }
        int ilPrimo = titlesPage.getFirstElement() - 1;
        for (int x = 0; x < Integer.parseInt(keyCountQuery); x++) {
          if (x + ilPrimo < totElements) {
            Title titolo = xwconn.getTitle(xwconn.connection, workFlowBean.getArchiveLookup().getAlias(), qr, x + ilPrimo);
            System.out.println(titolo.getTitle());
            titleList.add(titolo.getTitle());
          }
        }
        System.out.println("Lookup.execute()44444" + qr);
        modelMap.put("selId", qr.id);
        System.out.println("Lookup.execute()6666666" + qr);
      } else if (MyRequest.getParameter("flagXML", parameterMap).equals("true")) {
        lookupBean.setInputTitleRule("");
        int totElements = qr.elements;
        // setQrSelId(qr.id);
        System.out.println("PIPPETTO " + qr.elements + " FINE");
        if (!MyRequest.getParameter("startPage", parameterMap).equals("")) {
          startPage = MyRequest.getParameter("startPage", parameterMap);
        }

        if (startPage.equals("")) {
          titlesPage.setPages(Integer.parseInt(keyCountQuery), totElements);
        } else {
          titlesPage.setPages(Integer.parseInt(keyCountQuery), totElements, Integer.parseInt(startPage));
        }
        int ilPrimo = titlesPage.getFirstElement() - 1;
        StringBuffer buffer = new StringBuffer();
        for (int x = 0; x < Integer.parseInt(keyCountQuery); x++) {
          if (x + ilPrimo < totElements) {
            int numDoc = xwconn.getNumDocFromQRElement(qr, x + ilPrimo);
            String strXml = xwconn.getSingleXMLFromQr(qr, x + ilPrimo, false);
            try {
              titleList.add(strXml);
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
        modelMap.put("selId", qr.id);
      }

    } catch (Exception e) {
      e.printStackTrace();
      throw new Exception(e.toString());
    } finally {
      modelMap.put("titleList", titleList);
      modelMap.put("titlesPage", titlesPage);
      try {
        if (!lookupBean.getInputTitleRule().trim().equals("")) {
          xwconn.restoreTitleRule(xwconn.connection, workFlowBean.getArchiveLookup().getAlias());
        }
        connectionManager.closeConnection(xwconn);
      } catch (Exception e1) {
        throw new Exception(e1.toString());
      }
    }
  }
View Full Code Here

    this.modelMap = modelMap;
  }

  public AjaxBean execute() throws Exception {
    XWConnection xwconn = null;
    ConnectionManager connectionManager = new ConnectionManager();
    ConfBean confBean = null;
    WorkFlowBean workFlowBean = null;
    AjaxBean ajaxBean = new AjaxBean();
    String valori = "";
    List<String> confControl = new ArrayList<String>();
    confControl.add("titleManager");
    confControl.add("query");
    try {
      String physDoc = MyRequest.getParameter("numDoc", req.getParameterMap());
      UserBean userBean = (UserBean) modelMap.get("userBean");
      confBean = (ConfBean) modelMap.get("confBean");
      workFlowBean = (WorkFlowBean) modelMap.get("workFlowBean");

      xwconn = connectionManager.getConnection(workFlowBean.getArchive());
      MultiEditingManager editingManager = new MultiEditingManager(req.getParameterMap(), confBean, userBean, workFlowBean);
      editingManager.setTheXML(new XMLBuilder(xwconn.getSingleXMLFromNumDoc(Integer.parseInt(physDoc)), "ISO-8859-1"));
      confBean = editingManager.rewriteMultipleConf(confControl);

      if (MyRequest.getParameter("calcButtons", req.getParameterMap()).equals("true")) {
        calcolaBottoni(xwconn, ajaxBean, physDoc);
        return ajaxBean;
      }
      QueryResult qr = xwconn.getQRFromHier(Integer.parseInt(physDoc), false);
      String extraQuery = confBean.getTheXMLConfQuery().valoreNodoNoEscape("/root/infoDoc/element[@type='extraQuery']/text()");
      // System.out.println("AjaxDocInfoCommand.execute() extraQuery " + extraQuery);
      if (!extraQuery.equals("")) {
        try {
          // System.out.println("AjaxDocInfoCommand.execute() extraQuery " + "([?SEL]=\"" + qr.id + "\") " + extraQuery);
          qr = xwconn.getQRfromPhrase("([?SEL]=\"" + qr.id + "\") " + extraQuery);
        } catch (Exception e) {
          System.out.println("ERRORE IN AjaxDocInfoCommand extraQuery " + "([?SEL]=\"" + qr.id + "\") " + extraQuery);
          System.out.println("ERRORE IN AjaxDocInfoCommand error " + e.getMessage());
        }

      }

      // ELEMENTI INFERIORI COLLEGATI
      if (qr.elements > 0) { /* se ha dei figli */
        valori += "<li>Elementi inferiori collegati: <strong>" + qr.elements + "</strong></li>";
        // QueryResult queryResult = xwconn.getQRFromHier(Integer.parseInt(physDoc),false);
        // // ELEMENTI INFERIORI COLLEGATI
        // if (queryResult.elements > 0) { /* se ha dei figli */
        // valori += "<li>Elementi figli di primo livello: <strong>" + queryResult.elements + "</strong></li>";
        // }
      }

      int numDocFather = xwconn.getNumDocFather(Integer.parseInt(physDoc));

      if (numDocFather > 0) {
        // POSIZIONE NEL RAMO
        int numDocSon = xwconn.getNumDocFirstSon(numDocFather);
        int count = 0;
        while (numDocSon != Integer.parseInt(physDoc)) {
          ++count;
          numDocSon = xwconn.getNumDocNextBrother(numDocSon);
        }
        valori += "<li>Posizione all'interno del ramo: <strong>" + (count + 1) + "</strong></li>";

        // LIVELLO DI PROFONDITA
        int depthLevel = 1;

        while ((numDocFather = xwconn.getNumDocFather(numDocFather)) > 0) {
          ++depthLevel;
        }

        valori += "<li>Livello di profondit&agrave;: <strong>" + depthLevel + "</strong></li>";
      }

      if (qr.elements > 0) { /*
                   * se ha dei figli CALCOLO ESTREMI CRONOLOGICI
                   */
        try {
          TitleManager titleManager = new TitleManager(confBean.getTheXMLConfTitle());
          String normalDatePath = confBean.getTheXMLConfQuery().valoreNodoNoEscape("/root/infoDoc/element[@type='normalDatePath']/text()");
          if (normalDatePath.equals("")) {
            normalDatePath = "/c/did/unittitle/unitdate";
          }
          String laSel = qr.id;
          String ilMaggiore = "";
          String ilMinore = "";
          String laFrase = "([?SEL]=\"" + laSel + "\") and not ([XML," + normalDatePath + "]=\"s.d.\")";
          String ordinamento = "";
          qr = xwconn.selectQR(laFrase);
          laSel = qr.id;
          java.util.Vector chiaviFrom = xwconn.selectFilteredKey(qr, "XML," + normalDatePath + "/#from", qr.elements, "down", "0");
          java.util.Vector chiaviTo = xwconn.selectFilteredKey(qr, "XML," + normalDatePath + "/#to", qr.elements, "up", "0");
          // System.out.println("chiaviFromchiaviFromchiaviFromchiaviFrom
          // "+chiaviFrom);
          // System.out.println("chiaviTochiaviTochiaviTochiaviTochiaviTo
          // "+chiaviTo);
          for (int i = 0; i < chiaviFrom.size(); i++) {
            Key key = (Key) chiaviFrom.elementAt(i);
            ilMinore = key.key.toString();
            if (!ilMinore.equals("00000000")) {
              break;
            }
          }

          for (int i = 0; i < chiaviTo.size(); i++) {
            Key key = (Key) chiaviTo.elementAt(i);
            ilMaggiore = key.key.toString();
          }

          laFrase = "([?SEL]=\"" + laSel + "\") and ([XML," + normalDatePath + "/#from]=\"" + ilMinore + "\")";
          ordinamento = "XML(xpart:" + normalDatePath + "/@normal)";
          qr = xwconn.selectQR(laFrase, ordinamento, it.highwaytech.broker.ServerCommand.find_SORT, -1);

          for (int i = 0; i < qr.elements; i++) {
            it.highwaytech.db.Title ilTitolo = xwconn.getTitle(xwconn.connection, xwconn.getTheDb(), qr, i);
            String ilTitoloString = ilTitolo.getTitle();
            String laData = titleManager.defaultParsedTitle(ilTitoloString, "dataTitle");
            if (!(laData.trim()).equals("")) {
              ilMinore = titleManager.defaultParsedTitle(ilTitoloString, "defaultTitle");
              break;
            }
          }

          laFrase = "([?SEL]=\"" + laSel + "\") and ([XML," + normalDatePath + "/#to]=\"" + ilMaggiore + "\")";
          ordinamento = "xml(xpart:" + normalDatePath + "/@normal)";
          qr = xwconn.selectQR(laFrase, ordinamento, it.highwaytech.broker.ServerCommand.find_SORT, -1);

          it.highwaytech.db.Title ilTitolo = xwconn.getTitle(xwconn.connection, xwconn.getTheDb(), qr, qr.elements - 1);
          String ilTitoloString = ilTitolo.getTitle();

          String laData = titleManager.defaultParsedTitle(ilTitoloString, "dataTitle");
          if (!(laData.trim()).equals("")) {
            ilMaggiore = titleManager.defaultParsedTitle(ilTitoloString, "defaultTitle");
          }

          if (!ilMinore.trim().equals("")) {
            valori += "<li>Elemento collegato con data minore: <strong>" + ilMinore + "</strong></li>";
          }
          if (!ilMaggiore.trim().equals("")) {
            valori += "<li>Elemento collegato con data maggiore: <strong>" + ilMaggiore + "</strong></li>";
          }

        } catch (Exception e) {
          // e.printStackTrace();
        }
      }
      ajaxBean.setStrXmlOutput("<ul>" + valori + "</ul>");
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("ECCOLO");
      ajaxBean.setStrXmlOutput("<ul><li>attenzione e avvenuto un errore (" + e.getMessage() + ")</li></ul>");
    } finally {
      connectionManager.closeConnection(xwconn);
    }

    return ajaxBean;
  }
View Full Code Here

TOP

Related Classes of org.xdams.xmlengine.connection.manager.ConnectionManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.