Package org.im4java.core

Examples of org.im4java.core.CommandException


        else
          alias = aliasMulti;
        if (theArch != null)
          xwconn = connectionManager.getConnection(ServiceUser.getArchive(userBean, theArch));
        else
          throw new CommandException("Errore theArch = null");
        Vector result = null;
        // System.out.println("orienattion = "+orientation);
        try {
          String num_docs = MyRequest.getParameter("num_docs", parameterMap);
          // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>num_docs = "+num_docs);
          if (!MyRequest.getParameter("num_docs", parameterMap).equals("") && !num_docs.trim().equals("")) {
            if (vocabolario_phrase != null && vocabolario_phrase.indexOf("[?sel]") == -1) {
              if (vocabolario_phrase != null && !vocabolario_phrase.trim().equals("")) {
                vocabolario_phrase += " AND (";
              } else {
                vocabolario_phrase = "(";
              }
              StringTokenizer stringTokenizer3 = new StringTokenizer(num_docs, ";");
              while (stringTokenizer3.hasMoreTokens()) {
                try {
                  int num_doc = Integer.parseInt(stringTokenizer3.nextToken());
                  String selId = xwconn.getSelectionIdFormHier(num_doc);

                  vocabolario_phrase += " [?sel]=\"" + selId + "\" or";
                } catch (Exception e1) {
                  e1.printStackTrace();
                }
              }
              if (vocabolario_phrase.endsWith("or")) {
                vocabolario_phrase = vocabolario_phrase.substring(0, vocabolario_phrase.lastIndexOf("or"));
              }
              vocabolario_phrase += ")";
            }
          }
          // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>vocabolario_phrase = "+vocabolario_phrase);
          if (vocabolario_phrase != null && !vocabolario_phrase.trim().equals("")) {
            System.out.println(vocabolario_phrase);
            // result = xwconn.getFilteredKeys(vocabolario_phrase.replace('\'', '"'), alias, totResult, orientation, startParam,part);
            result = xwconn.getFilteredKeys(vocabolario_phrase.replace('\'', '"'), alias, totResult, orientation, startParam, 1, xwconn.getTotNumDoc(), "", "frequenze|spettrale");
            if (result.size() < totResult && orientation.equalsIgnoreCase("down") && multi) {
              // System.out.println("ne devo prendere di pi�");
              Key key = (Key) result.elementAt(result.size() - 1);
              // Vector toAdd=xwconn.getFilteredKeys(vocabolario_phrase.replace('\'', '"'), alias, totResult-result.size(), "up", key.key.toString(),part);
              Vector toAdd = xwconn.getFilteredKeys(vocabolario_phrase.replace('\'', '"'), alias, totResult - result.size(), "up", key.key.toString(), 1, xwconn.getTotNumDoc(), "", "frequenze|spettrale");
              for (int i = 1; i < toAdd.size(); i++) {
                result.addElement(toAdd.elementAt(i));
              }
            }
          } else {
            System.out.println("STO IN SINGLEKEY QUANTOVALE startParam:" + startParam);
            result = xwconn.getSingleKeys(alias, totResult, orientation, startParam, part);
            if (result.size() < totResult && orientation.equalsIgnoreCase("down") && multi) {
              // System.out.println("ne devo prendere di pi�");
              Key key = (Key) result.elementAt(result.size() - 1);
              // System.out.println("parto dalla chiave "+key.key.toString());
              Vector toAdd = xwconn.getSingleKeys(alias, totResult - result.size(), "up", key.key.toString(), part);
              // System.out.println("e ne aggiungo "+toAdd.size());
              for (int i = 1; i < toAdd.size(); i++) {
                result.addElement(toAdd.elementAt(i));
              }
            }
          }
          totNum += xwconn.getTotNumDoc();

        } catch (Exception exception) {
        }
        if (result != null && result.size() != 0) {
          // System.out.println(theArch+" result.size() = "+result.size());
          for (int i = 0; i < result.size(); i++) {
            Key key = (Key) result.elementAt(i);
            originalList.add(key);
            // System.out.println(">>>>>>>>>>>> ="+key.key.toString());
            if (vocabolarioMap.get(key.toString()) != null) {
              Key oldKey = (Key) vocabolarioMap.get(key.toString());
              oldKey.frequence = oldKey.frequence + key.frequence;
              vocabolarioMap.put(key.toString(), oldKey);
            } else {
              vocabolarioMap.put(key.toString(), key);
            }
          }
        }
      }

      // for (Enumeration enumeration = vocabolarioMap.keys(); enumeration.hasMoreElements(); vocabolarioList.addElement(vocabolarioMap.get(enumeration.nextElement())))
      // ;

      for (Entry<String, Key> entry : vocabolarioMap.entrySet()) {
        vocabolarioList.add(vocabolarioMap.get(entry.getKey()));
      }
      List<String> newResult = new ArrayList<String>();
      // System.out.println("vocabolarioList.size() = "+vocabolarioList.size());
      for (int i = 0; i < vocabolarioList.size(); i++) {
        Key key = (Key) vocabolarioList.get(i);
        String keyFreq = key.key.toString() + "~" + Integer.toString(key.frequence);
        newResult.add(keyFreq);
      }
      String vocFirst = "";
      String vocLast = "";
      try {
        vocFirst = ((Key) originalList.get(0)).key.toString();
        vocLast = ((Key) originalList.get(originalList.size() - 1)).key.toString();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      Object objs[] = newResult.toArray();
      // Arrays.sort(objs);
      // Arrays.sort(objs,Collator.getInstance(Locale.ITALIAN));
      Arrays.sort(objs, new XWComparator());
      // newResult.removeAllElements();
      newResult.clear();
      Map<String, Integer> summKeys = new TreeMap<String, Integer>();
      for (int i = 0; i < objs.length; i++) {
        String keyString = (String) objs[i];
        String sKey = keyString.substring(0, keyString.indexOf("~"));
        String sFrequence = keyString.substring(keyString.indexOf("~") + 1, keyString.length());
        int laFrequenza = Integer.parseInt(sFrequence);
        if (summKeys.get(sKey) != null) {
          summKeys.put(sKey, new Integer(((Integer) summKeys.get(sKey)).intValue() + laFrequenza));
        } else {
          summKeys.put(sKey, new Integer(laFrequenza));
        }
      }
      // String keyH;
      // for (Enumeration enumeration2 = summKeys.keys(); enumeration2.hasMoreElements(); newResult.add(keyH + "~" + ((Integer) summKeys.get(keyH)).toString()))
      // keyH = (String) enumeration2.nextElement();

      for (Entry<String, Integer> entry : summKeys.entrySet()) {
        String keyH = entry.getKey();
        newResult.add(keyH + "~" + ((Integer) summKeys.get(keyH)).toString());
      }
      objs = newResult.toArray();
      // Arrays.sort(objs);
      // Arrays.sort(objs,Collator.getInstance(Locale.ITALIAN));
      Arrays.sort(objs, new XWComparator());
      // newResult.removeAllElements();
      newResult.clear();

      List<Key> newResultKey = new ArrayList<Key>();
      // newResult = new ArrayList<String>();
      // System.out.println("objs.length = "+objs.length);
      if (orientation.equalsIgnoreCase("up") || !multi) {
        // System.out.println("avanti");
        for (int i = 0; i < objs.length; i++) {
          String keyString = (String) objs[i];
          String sKey = keyString.substring(0, keyString.indexOf("~"));
          String sFrequence = keyString.substring(keyString.indexOf("~") + 1, keyString.length());
          int laFrequenza = Integer.parseInt(sFrequence);
          Key key = new Key(sKey, laFrequenza);
          newResultKey.add(key);
          if (i == totResult - 1)
            break;
        }
      } else {

        if (objs.length >= totResult) {
          // System.out.println("indietro toto result"+totResult +" partendo da "+(objs.length-totResult));
          int start = 0;
          int end = objs.length;
          for (int i = 0; i < objs.length; i++) {
            String keyString = (String) objs[i];
            String sKey = keyString.substring(0, keyString.indexOf("~"));
            // System.out.println("sKey = |" + sKey +"| lo comparo con startParam = |"+ startParam+"|");
            if (sKey.trim().equalsIgnoreCase(startParam.trim())) {
              end = i + 1;
              if (i - totResult >= 0) {
                start = i - (totResult - 1);
              } else {
                end = totResult;
              }
              // System.out.println("ok sono uguali sKey e startParam");
              break;
            }
          }
          if (start < 0) {
            start = 0;
            end = start + totResult;
          }
          for (int i = start; i < end; i++) {
            // for(int i = objs.length-totResult; i < objs.length; i++){
            String keyString = (String) objs[i];
            String sKey = keyString.substring(0, keyString.indexOf("~"));
            System.out.println("le chiavi risultanti sono = " + sKey);
            String sFrequence = keyString.substring(keyString.indexOf("~") + 1, keyString.length());
            int laFrequenza = Integer.parseInt(sFrequence);
            Key key = new Key(sKey, laFrequenza);
            newResultKey.add(key);

          }
        }

      }

      String previous = "no";

      if (vocabolario_phrase != null && !vocabolario_phrase.trim().equals("")) {
        if (isFirstKey(theArchs, aliasMulti, ((Key) newResultKey.get(0)).key.toString(), startParam, vocabolario_phrase.trim().replace('\'', '"'), part)) {
          workFlowBean.getRequest().setAttribute("vocabolario_previous", previous);
          workFlowBean.getRequest().setAttribute("vocabolario_previous_string", vocFirst);
          // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>precedente no");
        } else {
          // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>precedente si");
        }
      } else {
        // System.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
        if (isFirstKey(theArchs, aliasMulti, ((Key) newResultKey.get(0)).key.toString(), startParam, null, part)) {
          // if(isFirstKey(theArchs, aliasMulti, startParam,null,part)){
          workFlowBean.getRequest().setAttribute("vocabolario_previous", previous);
          workFlowBean.getRequest().setAttribute("vocabolario_previous_string", vocFirst);
          // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>precedente no");
        } else {
          // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>precedente si");
        }
      }
      vocabolarioList = newResultKey;
      String next = "";
      if (vocabolarioList.size() >= totResult)
        next = ((Key) vocabolarioList.get(vocabolarioList.size() - 1)).key.toString();
      workFlowBean.getRequest().setAttribute("vocabolario_next", next);
      workFlowBean.getRequest().setAttribute("vocabolario_next_string", vocLast);
    } catch (ArrayIndexOutOfBoundsException e) {
      System.out.println(e.getMessage());
    } catch (CommandException e) {
      System.out.println(e.getMessage());
    } catch (Exception e) {
      System.out.println(e.getMessage());
    } finally {
      try {
        if (xwconn != null && !xwconn.isClosed())
          xwconn.close();
      } catch (XWException e1) {
        throw new CommandException(e1.toString());
      }
    }
    workFlowBean.getRequest().setAttribute("totNum", Integer.toString(totNum));
    workFlowBean.getRequest().setAttribute("vocabolario_phrase", vocabolario_phrase);
    // req.setAttribute("vocabolario_return_id", req.getParameter("vocabolario_return_id"));
View Full Code Here


            alias = aliasMulti;
          if (theArch != null)
            xwconn = connectionManager.getConnection(ServiceUser.getArchive(userBean, theArch));

          else
            throw new CommandException("Errore theArch = null");
          Vector first = null;
          if (filter == null)
            first = xwconn.getSingleKeys(alias, 2, "down", "", part);
          else
            // first = xwconn.getFilteredKeys(filter,alias, 2, "down", "",part);
View Full Code Here

TOP

Related Classes of org.im4java.core.CommandException

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.