Exemplo n.º 1
1
  public void commandAction(Command command, Displayable displayable) {
    if ((displayable == D_MAIN) && D_MAIN.Responds()) {
      if (command == c_exit) {
        exitMIDlet();
      }
      if (command == c_history) {
        switchDisplayable(null, getL_history());
        Stack st = D_MAIN.getEqHS();
        Enumeration en = st.elements();
        l_history.deleteAll();
        while (en.hasMoreElements()) {
          l_history.append((String) en.nextElement(), null);
        }
      }
      if (command == c_tovars) {
        getL_vars().deleteAll();
        StringBuffer sb;
        Enumeration values = D_MAIN.getEqVars().elements();
        Enumeration names = D_MAIN.getEqVars().keys();
        String name;
        Real value;
        while ((values.hasMoreElements()) && (names.hasMoreElements())) {
          name = String.valueOf(names.nextElement());
          value = new Real(String.valueOf((values.nextElement())));
          Real.NumberFormat n = new Real.NumberFormat();
          n.maxwidth = 17;
          n.fse = Real.NumberFormat.FSE_NONE;
          sb = new StringBuffer(value.toString(n));
          if (chartools.contains(sb, 'e')) {
            StringBuffer ev = new StringBuffer();
            for (int i = sb.length() - 1; i > -1; --i) {
              if (sb.charAt(i) == 'e') {
                sb.deleteCharAt(i);
                break;
              }
              ev.append(sb.charAt(i));
              sb.deleteCharAt(i);
            }
            ev.reverse();
            sb.append(" * 10^(" + ev + ")");
            if ((!(sb.equals(new StringBuffer(""))))
                && (!(name.equals("")))
                && (!(sb.equals(new StringBuffer("null"))))
                && (!(name.equals("null")))) {
              l_vars.append(name + " = " + sb.toString(), null);
            }
          } else {
            if ((!(sb.equals(new StringBuffer(""))))
                && (!(name.equals("")))
                && (!(sb.equals(new StringBuffer("null"))))
                && (!(name.equals("null")))) {
              getL_vars().append(name + " = " + sb.toString(), null);
            }
          }
        }
        switchDisplayable(null, getL_vars());
      }
    }
    if (displayable == f_welcome) {
      if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);
      }
    } else if (displayable == form) {
      if (command == c_history) {

      } else if (command == c_tovars) {

      }
    } else if (displayable == l_history) {
      if (command == List.SELECT_COMMAND) {

        l_historyAction();

      } else if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);

      } else if (command == c_insert) {

        if (l_history.size() != 0) {
          StringBuffer sb = new StringBuffer();
          String his = l_history.getString(l_history.getSelectedIndex());
          boolean p_end = false;
          for (int i = 0; i < his.length(); i++) {
            if (his.charAt(i) == '=') {
              break;
            }
            if (p_end) {
              sb.append(his.charAt(i));
            }
            if (his.charAt(i) == ':') {
              p_end = true;
            }
          }
          sb.deleteCharAt(sb.length() - 1);
          D_MAIN.appendDispCont(" " + sb.toString());
        }
        switchDisplayable(null, D_MAIN);
        D_MAIN.repaint();
      }
    } else if (displayable == l_vars) {
      if (command == List.SELECT_COMMAND) {

        l_varsAction();

      } else if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);

      } else if (command == c_delvar) {
        try {
          StringBuffer sb = new StringBuffer();
          String his = l_vars.getString(l_vars.getSelectedIndex());
          for (int i = 0; i < his.length(); i++) {
            if (his.charAt(i) == '=') {
              break;
            }
            sb.append(his.charAt(i));
          }
          D_MAIN.deletevar(sb.toString().trim());
          l_vars.delete(l_vars.getSelectedIndex());
        } catch (error er) {
          switchDisplayable(null, getA_error());
          a_error.setString(er.getMessage());
        }

      } else if (command == c_insert) {
        StringBuffer sb = new StringBuffer();
        String his = l_vars.getString(l_vars.getSelectedIndex());
        for (int i = 0; i < his.length(); i++) {
          if (his.charAt(i) == '=') {
            break;
          }
          sb.append(his.charAt(i));
        }
        D_MAIN.appendDispCont(sb.toString());
        switchDisplayable(null, D_MAIN);

        D_MAIN.repaint();
      }
    }
  }
 // return all grantees: thr_0, thr_1, thr_2 ..., excluding itself
 private static String getAllGrantees() {
   StringBuffer aStr = new StringBuffer("  ");
   Map<String, String> userPasswd =
       (Map<String, String>) SQLBB.getBB().getSharedMap().get(SQLSecurityTest.userPasswdMap);
   for (Map.Entry<String, String> e : userPasswd.entrySet()) {
     if (!e.getKey().equalsIgnoreCase("thr_" + RemoteTestModule.getCurrentThread().getThreadId()))
       aStr.append(e.getKey() + ", ");
   }
   if (aStr.charAt(aStr.length() - 2) == ',') {
     aStr.deleteCharAt(aStr.length() - 2);
   }
   aStr.deleteCharAt(0); // delete the leading space
   return aStr.toString();
 }
 // 从页面中读取参数的设置值,按一定的规则设定好形成一个字符串并返回此字符串
 public static String getParametersFromRequest(HttpServletRequest request) {
   StringBuffer re = new StringBuffer();
   Integer type = Integer.parseInt(request.getParameter("processType"));
   if (type == MRBAYESTYPE) {
     return getParametersFromRequestMrBayes(request);
   }
   Enumeration parameterNames = request.getParameterNames();
   List paraList = new MultipleAlignmentDefaultDAO().getParameterList(type);
   if (paraList == null) {
     return "";
   }
   while (parameterNames.hasMoreElements()) {
     String paraName = (String) parameterNames.nextElement();
     if (paraList.contains(paraName)) {
       String paraValue = (String) request.getParameter(paraName);
       if (!"".equals(paraValue) && null != paraValue) {
         re.append(paraName + SEPERATEPARAMETERANDVALUE + paraValue + SEPERATEPARAMETERS);
       }
     }
   }
   if (re.length() > 0) {
     re.deleteCharAt(re.length() - 1);
   }
   return re.toString();
 }
Exemplo n.º 4
0
    /**
     * Create a Transferable to use as the source for a data transfer.
     *
     * @param c The component holding the data to be transfered. This argument is provided to enable
     *     sharing of TransferHandlers by multiple components.
     * @return The representation of the data to be transfered.
     */
    protected Transferable createTransferable(JComponent c) {
      Object[] values = null;
      if (c instanceof JList) {
        values = ((JList) c).getSelectedValues();
      } else if (c instanceof JTable) {
        JTable table = (JTable) c;
        int[] rows = table.getSelectedRows();
        if (rows != null) {
          values = new Object[rows.length];
          for (int i = 0; i < rows.length; i++) {
            values[i] = table.getValueAt(rows[i], 0);
          }
        }
      }
      if (values == null || values.length == 0) {
        return null;
      }

      StringBuffer plainBuf = new StringBuffer();
      StringBuffer htmlBuf = new StringBuffer();

      htmlBuf.append("<html>\n<body>\n<ul>\n");

      for (Object obj : values) {
        String val = ((obj == null) ? "" : obj.toString());
        plainBuf.append(val + "\n");
        htmlBuf.append("  <li>" + val + "\n");
      }

      // remove the last newline
      plainBuf.deleteCharAt(plainBuf.length() - 1);
      htmlBuf.append("</ul>\n</body>\n</html>");

      return new FileTransferable(plainBuf.toString(), htmlBuf.toString(), values);
    }
  public String toString() {
    StringBuffer b = new StringBuffer();
    b.append("ID:" + id);
    b.append("\tName:" + name);
    b.append("\tSex:" + sex + "\n");
    b.append("\tAffected:" + affection + "\n");

    if (mother == null) {
      b.append("\tMother: null");
    } else {
      b.append("\tMother:" + mother.id);
    }

    if (father == null) {
      b.append("\tFather: null");
    } else {
      b.append("\tFather:" + father.id);
    }

    b.append("\tChildren:");
    Vector<PelicanPerson> children = getChildren();
    if (children.size() > 0) {
      Iterator<PelicanPerson> it = children.iterator();
      while (it.hasNext()) {
        PelicanPerson p = it.next();
        b.append(p.id + ",");
      }
      b.deleteCharAt(b.length() - 1);
    } else {
      b.append("none");
    }
    b.append("\n");
    return b.toString();
  }
 // return optionally any insert, delete, trigger, select [col list], update [col list]
 private String getPrivilegeLists(String tableName) {
   StringBuffer aStr = new StringBuffer("  ");
   for (int i = 0; i < tablePriv.length; i++) {
     if (SQLTest.random.nextBoolean()) {
       aStr.append(tablePriv[i]); // insert delete etc
       if (i > 2) {
         aStr.append(getColumnLists(tableName)); // column list for the table
       } // may include column list
       aStr.append(", ");
     }
   }
   if (aStr.charAt(aStr.length() - 2) == ',') {
     aStr.deleteCharAt(aStr.length() - 2);
   }
   aStr.deleteCharAt(0); // delete the leading space
   return aStr.toString();
 }
 // returns column list: column-id, column-id ...
 private String getColumnLists(String tableName) {
   List<String> colNames = (List<String>) tableCols.get(tableName);
   StringBuffer aStr = new StringBuffer("  ");
   for (int i = 0; i < colNames.size(); i++) {
     if (SQLTest.random.nextBoolean()) {
       aStr.append(colNames.get(i) + ", ");
     }
   }
   if (aStr.charAt(aStr.length() - 2) == ',') {
     aStr.deleteCharAt(aStr.length() - 2);
   }
   aStr.deleteCharAt(0); // delete the leading space
   if (aStr.length() != 1) {
     aStr.insert(1, '(');
     aStr.append(')');
   } // has column
   return aStr.toString();
 }
 /**
  * Helper method that converts a string string array {"string1"," string2",..."stringN"} to a
  * string in the form "string1,string2,... stringN".
  */
 public static String convertStringArraytoString(String[] array) {
   if (array == null || array.length == 0) return ""; // $NON-NLS-1$
   StringBuffer sb = new StringBuffer();
   for (int i = 0; i < array.length; i++) {
     sb.append(array[i]);
     sb.append(PROJECT_SEPARATOR);
   }
   sb.deleteCharAt(sb.length() - 1);
   return sb.toString();
 }
  // any number of users excluding itself
  private static String getGrantees(int num) {
    StringBuffer aStr = new StringBuffer("  ");
    Map<String, String> userPasswd =
        (Map<String, String>) SQLBB.getBB().getSharedMap().get(SQLSecurityTest.userPasswdMap);
    userPasswd.remove("thr_" + RemoteTestModule.getCurrentThread().getThreadId());
    String[] users = new String[userPasswd.size()];
    userPasswd.keySet().toArray(users);
    int i = 0;
    while (i < num) {
      int x = SQLTest.random.nextInt(users.length);
      aStr.append(users[x] + ", ");
      i++;
    }

    if (aStr.charAt(aStr.length() - 2) == ',') {
      aStr.deleteCharAt(aStr.length() - 2);
    }
    aStr.deleteCharAt(0); // delete the leading space
    return aStr.toString();
  }
Exemplo n.º 10
0
 public String next() {
   ListEntry listEntry = entries.next();
   StringBuffer line = new StringBuffer();
   for (String tag : listEntry.getCustomElements().getTags()) {
     line.append("\"").append(listEntry.getCustomElements().getValue(tag)).append("\"");
     line.append(",");
   }
   if (line.length() > 0) {
     line.deleteCharAt(line.length() - 1);
   }
   return line.toString();
 }
Exemplo n.º 11
0
  boolean removeFromLine(int x, int y) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.deleteCharAt(x - 1);
      // setLine
      vectorLines.setElementAt(currentLine, y);
      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in removeFromLine()");
      return false;
    }
  }
Exemplo n.º 12
0
  /**
   * 把map转换成string类型
   * #month#=01&#date#=01&#hour#=12&#minute#=11&#opertion#=?&#amount#&#balance#&#telephone#
   *
   * @param m
   * @return
   */
  public static Map mapToHponeMsg(Map m) {
    Map rm = new HashMap();
    if (!StringUtil.isNotEmptyMap(m)) {
      return null;
    }
    StringBuffer sb = new StringBuffer();
    Set keys = m.keySet();
    for (Object o : keys) {
      sb.append("#").append(o.toString()).append("#=").append(m.get(o.toString())).append("&");
    }
    sb.deleteCharAt(sb.toString().length() - 1);

    rm.put("tpl_value", sb.toString());
    return rm;
  }
  @SuppressWarnings("StringBufferMayBeStringBuilder")
  public HBaseOperations(
      String tableName, List<String> ColumnFamilies, List<String> zookeeperIPs, int zkPort) {
    conf = HBaseConfiguration.create();

    StringBuffer zookeeperIP = new StringBuffer();

    for (String zookeeper : zookeeperIPs) {
      zookeeperIP.append(zookeeper).append(',');
    }
    zookeeperIP.deleteCharAt(zookeeperIP.length() - 1);
    System.out.println(zookeeperIP.toString());
    conf.set("hbase.zookeeper.quorum", zookeeperIP.toString());
    conf.setInt("hbase.zookeeper.property.clientPort", zkPort);
    conf.set("zookeeper.znode.parent", "/hbase-unsecure");

    createTable(tableName, ColumnFamilies);

    try {
      hTable = new HTable(conf, tableName);
    } catch (IOException e) {
      System.out.println("Error occurred while creating instance of HTable class:" + e);
    }
  }
Exemplo n.º 14
0
  public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
      throws SAXException {
    // if (!qName.equals("TOKEN") && !qName.equals("BLOCK") &&
    // !qName.equals("TEXT"))
    // System.out.println(qName);

    if (qName.equals("TEXT")) {
      blabla.append("\n");
      LayoutToken token = new LayoutToken();
      token.setText("\n");
      block.addToken(token);
      accumulator.setLength(0);
      tokenizations.add("\n");
    } else if (qName.equals("METADATA")) {
      accumulator.setLength(0);
    } else if (qName.equals("TOKEN")) {
      String tok0 = TextUtilities.clean(getText());

      if (block.getStartToken() == -1) {
        block.setStartToken(tokenizations.size());
      }

      if (tok0.length() > 0) {
        StringTokenizer st = new StringTokenizer(tok0, TextUtilities.fullPunctuations, true);
        boolean diaresis = false;
        boolean accent = false;
        boolean keepLast = false;
        while (st.hasMoreTokens()) {

          diaresis = false;
          accent = false;
          keepLast = false;

          String tok = st.nextToken();
          if (tok.length() > 0) {

            LayoutToken token = new LayoutToken();

            if ((previousToken != null)
                && (tok != null)
                && (previousToken.length() > 0)
                && (tok.length() > 0)
                && blabla.length() > 0) {

              Character leftChar = previousTok.getText().charAt(previousTok.getText().length() - 1);
              Character rightChar = tok.charAt(0);

              ModifierClass leftClass = classifyChar(leftChar);
              ModifierClass rightClass = classifyChar(rightChar);
              ModifierClass modifierClass = ModifierClass.NOT_A_MODIFIER;

              if (leftClass != ModifierClass.NOT_A_MODIFIER
                  || rightClass != ModifierClass.NOT_A_MODIFIER) {
                Character baseChar = null;
                Character modifierChar = null;

                if (leftClass != ModifierClass.NOT_A_MODIFIER) {
                  if (rightClass != ModifierClass.NOT_A_MODIFIER) {
                    // assert false;
                    // keeping characters, but setting class
                    // to not a modifier
                    baseChar = leftChar;
                    modifierChar = rightChar;
                    modifierClass = ModifierClass.NOT_A_MODIFIER;
                  } else {
                    baseChar = rightChar;
                    modifierChar = leftChar;
                    modifierClass = leftClass;
                  }
                } else {
                  baseChar = leftChar;
                  modifierChar = rightChar;
                  modifierClass = rightClass;
                }

                String updatedChar = modifyCharacter(baseChar, modifierChar);

                tokenizations.remove(tokenizations.size() - 1);
                if (tokenizations.size() > 0) {
                  tokenizations.remove(tokenizations.size() - 1);
                }

                blabla.deleteCharAt(blabla.length() - 1);
                if (blabla.length() > 0) {
                  blabla.deleteCharAt(blabla.length() - 1);
                }

                removeLastCharacterIfPresent(previousTok);

                if (updatedChar != null) {
                  blabla.append(updatedChar);
                  previousTok.setText(previousTok.getText() + updatedChar);
                }

                blabla.append(tok.substring(1, tok.length()));
                previousTok.setText(previousTok.getText() + tok.substring(1, tok.length()));
                tokenizations.add(previousTok.getText());

                diaresis =
                    (modifierClass == ModifierClass.DIAERESIS
                        || modifierClass == ModifierClass.NORDIC_RING
                        || modifierClass == ModifierClass.CZECH_CARON
                        || modifierClass == ModifierClass.TILDE
                        || modifierClass == ModifierClass.CEDILLA);

                accent =
                    (modifierClass == ModifierClass.ACUTE_ACCENT
                        || modifierClass == ModifierClass.CIRCUMFLEX
                        || modifierClass == ModifierClass.GRAVE_ACCENT);

                if (rightClass != ModifierClass.NOT_A_MODIFIER) {
                  tok = ""; // resetting current token as it
                  // is a single-item
                }
              }
            }

            if (tok != null) {
              // actually in certain cases, the extracted string under token can be a chunk of text
              // with separators that need to be preserved
              // tok = tok.replace(" ", "");
            }

            if ((!diaresis) && (!accent)) {
              // blabla.append(" ");
              blabla.append(tok);
              token.setText(tok);

              tokenizations.add(tok);
            } else {
              tok = "";
              keepLast = true;
            }

            /*
             * StringTokenizer st0 = new StringTokenizer(tok0,
             * TextUtilities.fullPunctuations, true);
             * while(st0.hasMoreTokens()) { String tok =
             * st0.nextToken(); tokenizations.add(tok); }
             * tokenizations.add(" ");
             */

            /*
             * boolean punct1 = false; boolean punct2 = false;
             * boolean punct3 = false; String content = null; int i
             * = 0; for(; i<TextUtilities.punctuations.length();
             * i++) { if (tok.length() > 0) { if
             * (tok.charAt(tok.length()-1) ==
             * TextUtilities.punctuations.charAt(i)) { punct1 =
             * true; content = tok.substring(0, tok.length()-1); if
             * (tok.length() > 1) { int j = 0; for(;
             * j<TextUtilities.punctuations.length(); j++) { if
             * (tok.charAt(tok.length()-2) ==
             * TextUtilities.punctuations.charAt(j)) { punct3 =
             * true; content = tok.substring(0, tok.length()-2); } }
             * } break; } } } if (tok.length() > 0) { if (
             * (tok.startsWith("(")) && (tok.length() > 1) ) { if
             * ((punct3) && (tok.length() > 2)) content =
             * tok.substring(1, tok.length()-2); else if (punct1)
             * content = tok.substring(1, tok.length()-1); else
             * content = tok.substring(1, tok.length()); punct2 =
             * true; token.setText("("); } else if (
             * (tok.startsWith("[")) && (tok.length() > 1) ) { if
             * ((punct3) && (tok.length() > 2)) content =
             * tok.substring(1, tok.length()-2); else if (punct1)
             * content = tok.substring(1, tok.length()-1); else
             * content = tok.substring(1, tok.length()); punct2 =
             * true; token.setText("["); } else if (
             * (tok.startsWith("\"")) && (tok.length() > 1) ) { if
             * ((punct3) && (tok.length() > 2)) content =
             * tok.substring(1, tok.length()-2); else if (punct1)
             * content = tok.substring(1, tok.length()-1); else
             * content = tok.substring(1, tok.length()); punct2 =
             * true; token.setText("\""); } }
             */
            if (currentRotation) currentFontSize = currentFontSize / 2;

            /*
             * if (punct2) { if (currentFont != null)
             * token.setFont(currentFont.toLowerCase()); else
             * token.setFont("default");
             * token.setItalic(currentItalic);
             * token.setBold(currentBold);
             * token.setRotation(currentRotation);
             * token.setColorFont(colorFont); token.setX(currentX);
             * token.setY(currentY); token.setWidth(currentWidth);
             * token.setHeight(currentHeight);
             * token.setFontSize(currentFontSize);
             * block.addToken(token);
             *
             * token = new LayoutToken(); token.setText(content); }
             * if (punct1) { token.setText(content); if (currentFont
             * != null) token.setFont(currentFont.toLowerCase());
             * else token.setFont("default");
             * token.setItalic(currentItalic);
             * token.setBold(currentBold);
             * token.setRotation(currentRotation);
             * token.setColorFont(colorFont); token.setX(currentX);
             * token.setY(currentY); token.setWidth(currentWidth);
             * token.setHeight(currentHeight);
             * token.setFontSize(currentFontSize);
             * block.addToken(token);
             *
             * if (punct3) { token = new LayoutToken();
             * token.setText(""+tok.charAt(tok.length()-2)); if
             * (currentFont != null)
             * token.setFont(currentFont.toLowerCase()); else
             * token.setFont("default");
             * token.setItalic(currentItalic);
             * token.setBold(currentBold);
             * token.setRotation(currentRotation);
             * token.setColorFont(colorFont); token.setX(currentX);
             * token.setY(currentY); token.setWidth(currentWidth);
             * token.setHeight(currentHeight);
             * token.setFontSize(currentFontSize);
             * block.addToken(token); }
             *
             * token = new LayoutToken();
             * token.setText(""+tok.charAt(tok.length()-1)); }
             */
            if (currentFont != null) token.setFont(currentFont.toLowerCase());
            else token.setFont("default");
            token.setItalic(currentItalic);
            token.setBold(currentBold);
            token.setRotation(currentRotation);
            token.setColorFont(colorFont);
            token.setX(currentX);
            token.setY(currentY);
            token.setWidth(currentWidth);
            token.setHeight(currentHeight);
            token.setFontSize(currentFontSize);

            if (!diaresis && !accent) {
              block.addToken(token);
            }

            if (block.getFont() == null) {
              if (currentFont != null) block.setFont(currentFont.toLowerCase());
              else token.setFont("default");
            }
            if (nbTokens == 0) {
              block.setItalic(currentItalic);
              block.setBold(currentBold);
            }
            if (block.getColorFont() == null) block.setColorFont(colorFont);
            if (block.getX() == 0.0) block.setX(currentX);
            if (block.getY() == 0.0) block.setY(currentY);
            if (block.getWidth() == 0.0) block.setWidth(currentWidth);
            if (block.getHeight() == 0.0) block.setHeight(currentHeight);
            if (block.getFontSize() == 0.0) block.setFontSize(currentFontSize);

            if (!diaresis && !accent) {
              previousToken = tok;
              previousTok = token;
            } else {
              previousToken = previousTok.getText();
            }

            nbTokens++;
            accumulator.setLength(0);
          }
        }
        if (tokenizations.size() > 0) {
          String justBefore = tokenizations.get(tokenizations.size() - 1);
          if (!justBefore.endsWith("-")) {
            tokenizations.add(" ");
            blabla.append(" ");
          }
        }
      }
      block.setEndToken(tokenizations.size());
    } else if (qName.equals("PAGE")) {
      // page marker are usefull to detect headers (same first line(s)
      // appearing on each page)
      if (block != null) {
        blabla.append("\n");
        tokenizations.add("\n");
        block.setText(blabla.toString());
        block.setNbTokens(nbTokens);
        doc.addBlock(block);
      }
      Block block0 = new Block();
      block0.setText("@PAGE\n");
      block0.setNbTokens(0);
      block0.setPage(currentPage);
      doc.addBlock(block0);
      block = new Block();
      block.setPage(currentPage);
      blabla = new StringBuffer();
      nbTokens = 0;
      // blabla.append("\n@block\n");
      tokenizations.add("\n");
    } else if (qName.equals("IMAGE")) {
      if (block != null) {
        blabla.append("\n");
        block.setText(blabla.toString());
        block.setNbTokens(nbTokens);
        doc.addBlock(block);
      }
      block = new Block();
      block.setPage(currentPage);
      blabla = new StringBuffer();
      if (images.size() > 0) {
        blabla.append("@IMAGE " + images.get(images.size() - 1) + "\n");
      }
      block.setText(blabla.toString());
      block.setNbTokens(nbTokens);
      if (block.getX() == 0.0) block.setX(currentX);
      if (block.getY() == 0.0) block.setY(currentY);
      if (block.getWidth() == 0.0) block.setWidth(currentWidth);
      if (block.getHeight() == 0.0) block.setHeight(currentHeight);
      doc.addBlock(block);
      blabla = new StringBuffer();
      nbTokens = 0;
      block = new Block();
      block.setPage(currentPage);
    }
    /*
     * else if (qName.equals("VECTORIALIMAGES")) { if (block != null) {
     * blabla.append("\n"); block.setText(blabla.toString());
     * block.setNbTokens(nbTokens); doc.addBlock(block); } block = new
     * Block(); block.setPage(currentPage); blabla = new StringBuffer();
     * blabla.append("@IMAGE " + "vectorial \n");
     * block.setText(blabla.toString()); block.setNbTokens(nbTokens); if
     * (block.getX() == 0.0) block.setX(currentX); if (block.getY() == 0.0)
     * block.setY(currentY); if (block.getWidth() == 0.0)
     * block.setWidth(currentWidth); if (block.getHeight() == 0.0)
     * block.setHeight(currentHeight); doc.addBlock(block); blabla = new
     * StringBuffer(); nbTokens = 0; block = new Block();
     * block.setPage(currentPage); }
     */
    else if (qName.equals("BLOCK")) {
      blabla.append("\n");
      tokenizations.add("\n");
      block.setText(blabla.toString());
      block.setNbTokens(nbTokens);

      block.setWidth(currentX - block.getX() + currentWidth);
      block.setHeight(currentY - block.getY() + currentHeight);

      doc.addBlock(block);
      // blabla = new StringBuffer();
      nbTokens = 0;
      block = null;
    } else if (qName.equals("xi:include")) {
      if (block != null) {
        blabla.append("\n");
        block.setText(blabla.toString());
        block.setNbTokens(nbTokens);
        doc.addBlock(block);
      }
      block = new Block();
      block.setPage(currentPage);
      blabla = new StringBuffer();
      blabla.append("@IMAGE " + images.get(images.size() - 1) + "\n");
      block.setText(blabla.toString());
      block.setNbTokens(nbTokens);
      doc.addBlock(block);
      blabla = new StringBuffer();
      nbTokens = 0;
      block = new Block();
      block.setPage(currentPage);
    }

    /*
     * else if (qName.equals("DOCUMENT")) {
     * System.out.println(blabla.toString()); }
     */

  }
Exemplo n.º 15
0
  public int run(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

    if (args.length != 2) {
      System.out.println("Usage: FeatureMatching ID <inputName.jpeg/inputName.jpg>");
      System.exit(1);
    }

    SimpleDateFormat sdf = new SimpleDateFormat("", Locale.US);
    sdf.applyPattern("yyyy-MM-dd_HH-mm-ss");
    String time = sdf.format(new Date());

    Job job = Job.getInstance();

    ID = "/" + args[0];
    String filename = args[1];
    filename = filename.toLowerCase();
    System.out.println("current filename:" + filename);

    // Detect illegal username (if the username dir doesn't exist)
    File userPath = new File(LOCAL_USER_DIR + ID);
    if (!userPath.exists()) {
      System.out.println("Unauthorized username!!!\nExiting......");
      System.exit(1);
    }
    // Preprocess the input image.jpg from local dir: /local.../user/ID/input/image.jpg
    // Save the features to local dir: hdfs://.../user/ID/input/image.jpg
    extractQueryFeatures2HDFS(filename, job);

    // Add the feature file to the hdfs cache
    String featureFileName = filename.substring(0, filename.lastIndexOf(".")) + ".json";
    //        job.addCacheFile(new Path(HDFS_HOME + USER + ID + INPUT + "/" +
    // featureFileName).toUri());
    job.getConfiguration()
        .set("featureFilePath", HDFS_HOME + USER + ID + INPUT + "/" + featureFileName);

    // Check the file type. Only support jpeg/jpg type images
    String type = filename.substring(args[1].lastIndexOf("."));
    if (!(type.equals(".jpg") || type.equals(".jpeg"))) {
      System.out.println("Image type not supported!!!\nExiting");
      System.exit(1);
    }

    // Input: hdfs://.../features/
    // The feature dir is a location of all features extracted from the database
    String inputPathStr = HDFS_HOME + FEATURES;
    // Output: hdfs://.../user/ID/output/
    String outputPathStr = HDFS_HOME + USER + ID + OUTPUT + "/" + time;

    job.setInputFormatClass(KeyValueTextInputFormat.class);
    //        job.setOutputFormatClass(TextOutputFormat.class);

    // Get the lists of all feature files: /.../features/data/part-*
    FileSystem fs = FileSystem.get(job.getConfiguration());
    FileStatus[] statuses = fs.listStatus(new Path(inputPathStr));
    StringBuffer sb = new StringBuffer();
    for (FileStatus fileStatus : statuses) {
      sb.append(fileStatus.getPath() + ",");
    }
    sb.deleteCharAt(sb.lastIndexOf(","));

    job.setJarByClass(FeatureMatching.class);
    job.setMapperClass(FeatureMatchMapper.class);
    job.setReducerClass(FeatureMatchReducer.class);

    // only need one reducer to collect the result
    job.setNumReduceTasks(1);

    job.setMapOutputKeyClass(IntWritable.class);
    job.setMapOutputValueClass(Text.class);

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(DoubleWritable.class);

    // Input a directory, so need the recursive input
    FileInputFormat.setInputDirRecursive(job, true);
    // Set the PathFilter, to omit _SUCCESS files
    // (This is not working correctly, as the PathFilter class is an interface rather than a class.
    // But the 2nd arg asks me to extend the PathFilter)
    //        FileInputFormat.setInputPathFilter(job, MyPathFilter.class);
    //
    //        FileInputFormat.setInputPaths(job, new Path(inputPathStr));
    FileInputFormat.setInputPaths(job, sb.toString());
    FileOutputFormat.setOutputPath(job, new Path(outputPathStr));

    boolean success = job.waitForCompletion(true);
    return success ? 0 : 1;
  }
  public void reduce(
      Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter)
      throws IOException {
    List<String[]> _temp = new ArrayList<String[]>();
    int count = 0;
    while (values.hasNext()) {
      Text _out = values.next();
      String[] tokens = StringUtils.splitPreserveAllTokens(_out.toString(), TAB);
      _temp.add(tokens);
      if (count++ > 100000) break;
    }

    if (count > 10000) {
      Set<String> ipSet = new HashSet<String>();
      for (int posI = 0; posI < _temp.size(); posI++) {
        String[] array = _temp.get(posI);
        if (array == null) continue;

        String mid = array[2];
        String ip = array[3];
        ipSet.add(ip);
      }
      output.collect(
          key, Utils.mergeKey(String.valueOf(ipSet.size()), StringUtils.join(ipSet, '|')));
      return;
    }

    /**
     * ·Ö×éËã·¨ FOREACH ALL_DATA IF IN INDEX THEN UPDATE INDEX AND INSERT DATA ELSE FOREACH SUB_DATA
     * MAKE INDEX AND SET FIND'S DATA AS NULL
     */
    // List<List<String[]>> dataList = new ArrayList<List<String[]>>();
    List<StringBuffer> indexList = new ArrayList<StringBuffer>();
    Set<String> ipSet = new HashSet<String>();
    boolean muliHost = false;
    for (int posI = 0; posI < _temp.size(); posI++) {
      String[] array = _temp.get(posI);
      if (array == null) continue;

      String mid = array[2];
      String ip = array[3];
      ipSet.add(ip);
      boolean hasIndex = false;
      for (int i = 0; i < indexList.size(); i++) {
        StringBuffer index = indexList.get(i);
        if (index.indexOf("|" + mid + "|") >= 0 || index.indexOf("|" + ip + "|") >= 0) {
          if (index.indexOf("|" + mid + "|") < 0) {
            index.append('|').append(mid).append('|');
          }

          if (index.indexOf("|" + ip + "|") < 0) {
            index.append('|').append(ip).append('|');
          }
          // dataList.get(i).add(array);
          hasIndex = true;
          break;
        }
      }
      if (!hasIndex) {
        StringBuffer index = new StringBuffer("|" + mid + "|" + ip + "|");
        // List<String[]> _tmp = new ArrayList<String[]>();
        // _tmp.add(array);
        for (int k = posI + 1; k < _temp.size(); k++) {
          String[] _newArray = _temp.get(k);
          if (_newArray == null) {
            continue;
          }
          String _mid = _newArray[2];
          String _ip = _newArray[3];
          if (index.indexOf("|" + _mid + "|") >= 0 || index.indexOf("|" + _ip + "|") >= 0) {
            if (index.indexOf("|" + _mid + "|") < 0) {
              index.append('|').append(_mid).append('|');
            }

            if (index.indexOf("|" + _ip + "|") < 0) {
              index.append('|').append(_ip).append('|');
            }
            // _tmp.add(_newArray);
            _temp.set(k, null);
          }
        }
        indexList.add(index);
        // dataList.add(_tmp);
      }
    }
    //        for(String[] _array : _temp){
    //            output.collect(key,Utils.mergeKey(_array[1],_array[2],_array[3],_array[4]));
    //        }

    StringBuffer allIndex = new StringBuffer();
    for (StringBuffer index : indexList) {
      allIndex.append(index).append(';');
    }
    if (allIndex.length() > 0) {
      allIndex.deleteCharAt(allIndex.length() - 1);
    }
    output.collect(
        key, Utils.mergeKey(String.valueOf(indexList.size()), StringUtils.join(ipSet, '|')));
  }
Exemplo n.º 17
0
  public CommentsCollection parse(final InputStream in, final String charsetName)
      throws IOException, UnsupportedEncodingException {
    boolean lastWasASlashR = false;
    BufferedReader br = new BufferedReader(new InputStreamReader(in, charsetName));
    CommentsCollection comments = new CommentsCollection();
    int r;

    Deque prevTwoChars = new LinkedList<Character>(Arrays.asList('z', 'z'));

    State state = State.CODE;
    LineComment currentLineComment = null;
    BlockComment currentBlockComment = null;
    StringBuffer currentContent = null;

    int currLine = 1;
    int currCol = 1;

    while ((r = br.read()) != -1) {
      char c = (char) r;
      if (c == '\r') {
        lastWasASlashR = true;
      } else if (c == '\n' && lastWasASlashR) {
        lastWasASlashR = false;
        continue;
      } else {
        lastWasASlashR = false;
      }
      switch (state) {
        case CODE:
          if (prevTwoChars.peekLast().equals('/') && c == '/') {
            currentLineComment = new LineComment();
            currentLineComment.setBeginLine(currLine);
            currentLineComment.setBeginColumn(currCol - 1);
            state = State.IN_LINE_COMMENT;
            currentContent = new StringBuffer();
          } else if (prevTwoChars.peekLast().equals('/') && c == '*') {
            currentBlockComment = new BlockComment();
            currentBlockComment.setBeginLine(currLine);
            currentBlockComment.setBeginColumn(currCol - 1);
            state = State.IN_BLOCK_COMMENT;
            currentContent = new StringBuffer();
          } else if (c == '"') {
            state = State.IN_STRING;
          } else {
            // nothing to do
          }
          break;
        case IN_LINE_COMMENT:
          if (c == '\n' || c == '\r') {
            currentLineComment.setContent(currentContent.toString());
            currentLineComment.setEndLine(currLine);
            currentLineComment.setEndColumn(currCol);
            comments.addComment(currentLineComment);
            state = State.CODE;
          } else {
            currentContent.append(c);
          }
          break;
        case IN_BLOCK_COMMENT:
          if (prevTwoChars.peekLast().equals('*')
              && c == '/'
              && !prevTwoChars.peekFirst().equals('/')) {

            // delete last character
            String content =
                currentContent.deleteCharAt(currentContent.toString().length() - 1).toString();

            if (content.startsWith("*")) {
              JavadocComment javadocComment = new JavadocComment();
              javadocComment.setContent(content.substring(1));
              javadocComment.setBeginLine(currentBlockComment.getBeginLine());
              javadocComment.setBeginColumn(currentBlockComment.getBeginColumn());
              javadocComment.setEndLine(currLine);
              javadocComment.setEndColumn(currCol + 1);
              comments.addComment(javadocComment);
            } else {
              currentBlockComment.setContent(content);
              currentBlockComment.setEndLine(currLine);
              currentBlockComment.setEndColumn(currCol + 1);
              comments.addComment(currentBlockComment);
            }
            state = State.CODE;
          } else {
            currentContent.append(c == '\r' ? '\n' : c);
          }
          break;
        case IN_STRING:
          if (!prevTwoChars.peekLast().equals('\\') && c == '"') {
            state = State.CODE;
          }
          break;
        default:
          throw new RuntimeException("Unexpected");
      }
      switch (c) {
        case '\n':
        case '\r':
          currLine += 1;
          currCol = 1;
          break;
        case '\t':
          currCol += COLUMNS_PER_TAB;
          break;
        default:
          currCol += 1;
      }
      prevTwoChars.remove();
      prevTwoChars.add(c);
    }

    if (state == State.IN_LINE_COMMENT) {
      currentLineComment.setContent(currentContent.toString());
      currentLineComment.setEndLine(currLine);
      currentLineComment.setEndColumn(currCol);
      comments.addComment(currentLineComment);
    }

    return comments;
  }