private StatefulKnowledgeSession setSessionVariables(
     StatefulKnowledgeSession session, String params) throws Exception {
   StringTokenizer st = new StringTokenizer(params, "|");
   while (st.hasMoreTokens()) {
     StringTokenizer st1 = new StringTokenizer(st.nextToken(), ",");
     while (st1.hasMoreTokens()) {
       String globalVariableName = st1.nextToken();
       String globalVariableType = st1.nextToken();
       if (globalVariableType != null && globalVariableType.length() > 0) {
         Object o = null;
         if (globalVariableType.equalsIgnoreCase("ArrayList")) {
           o = ReflectUtils.getInstance().constructClass(ArrayList.class);
         }
         if (globalVariableType.equalsIgnoreCase("HashSet")) {
           o = ReflectUtils.getInstance().constructClass(HashSet.class);
         }
         if (globalVariableType.equalsIgnoreCase("EXIST")) {
           Field f = getClass().getDeclaredField(globalVariableName);
           System.out.println(f.get(this));
           o = f.get(this);
         }
         session.setGlobal(globalVariableName, o);
       }
     }
   }
   return session;
 }
예제 #2
0
  /**
   * Returns a vector with column names of the dataset, listed in "list". If a column cannot be
   * found or the list is empty the ones from the default list are returned.
   *
   * @param list comma-separated list of attribute names
   * @param defaultList the default list of attribute names
   * @param inst the instances to get the attribute names from
   * @return a vector containing attribute names
   */
  protected Vector determineColumnNames(String list, String defaultList, Instances inst) {
    Vector result;
    Vector atts;
    StringTokenizer tok;
    int i;
    String item;

    // get attribute names
    atts = new Vector();
    for (i = 0; i < inst.numAttributes(); i++) atts.add(inst.attribute(i).name().toLowerCase());

    // process list
    result = new Vector();
    tok = new StringTokenizer(list, ",");
    while (tok.hasMoreTokens()) {
      item = tok.nextToken().toLowerCase();
      if (atts.contains(item)) {
        result.add(item);
      } else {
        result.clear();
        break;
      }
    }

    // do we have to return defaults?
    if (result.size() == 0) {
      tok = new StringTokenizer(defaultList, ",");
      while (tok.hasMoreTokens()) result.add(tok.nextToken().toLowerCase());
    }

    return result;
  }
예제 #3
0
  @Override
  public boolean parse(GameMode gameMode, String value, URI source) {
    final StringTokenizer aTok = new StringTokenizer(value, "\t");

    if (!aTok.hasMoreTokens()) {
      Logging.errorPrint("Empty tag in miscinfo.ACTYPE");

      return false;
    }

    final String acType = aTok.nextToken();

    while (aTok.hasMoreTokens()) {
      final String aString = aTok.nextToken();

      if (aString.startsWith("ADD:")) {
        Collection<ACControl> controls = parseACControl(aString.substring(4));
        if (controls == null) {
          return false;
        }
        gameMode.addACAdds(acType, controls);
      } else if (aString.startsWith("REMOVE:")) {
        Collection<ACControl> controls = parseACControl(aString.substring(7));
        if (controls == null) {
          return false;
        }
        gameMode.addACRemoves(acType, controls);
      } else {
        Logging.errorPrint("Incorrect tag in miscinfo.ACTYPE: " + aString);
        return false;
      }
    }
    return true;
  }
예제 #4
0
 public Connection connect(String url, Properties info) throws SQLException {
   if (ConnectionLogger.isInfoEnabled()) {
     StringBuffer sb = new StringBuffer();
     sb.append("connect to URL ").append(url).append(" with properties: ").append(info.toString());
     ConnectionLogger.info(sb.toString());
   }
   if (!acceptsURL(url)) throw new SQLException("Invalid URL" + url);
   url = "jdbc:" + url.substring(urlPrefix.length());
   StringTokenizer ts = new StringTokenizer(url, ":/;=&?", false);
   String targetDriver = null;
   while (ts.hasMoreTokens()) {
     String s = ts.nextToken();
     logger.debug("s = " + s);
     if (targetDriverParameter.equals(s) && ts.hasMoreTokens()) {
       targetDriver = ts.nextToken();
       break;
     }
   }
   if (targetDriver == null)
     throw new SQLException("Can't find targetDriver parameter in URL: " + url);
   url =
       url.substring(0, url.length() - targetDriver.length() - targetDriverParameter.length() - 2);
   try {
     Class.forName(targetDriver);
     return ConnectionLoggingProxy.wrap(DriverManager.getConnection(url, info));
   } catch (Exception e) {
     ConnectionLogger.error(e.getMessage(), e);
     throw new SQLException(e.getMessage());
   }
 }
예제 #5
0
 /**
  * @param item the tweet to preprocess
  * @return the tweet after pre-processing
  */
 public String preprocessDocument(String item) {
   String result_fin = "";
   String result = item;
   StringTokenizer st1 = new StringTokenizer(result, " ,?![]");
   while (st1.hasMoreTokens()) {
     String str = st1.nextToken();
     result = removeUrl(str);
     if (!_opt.isRemoveEmoticons()) result = replaceEmoticons(result);
     else result = removeEmoticons(result);
     StringTokenizer st2 = new StringTokenizer(result, ".:#)(_");
     String tmp = "";
     String tmp2 = "";
     while (st2.hasMoreTokens()) {
       tmp = st2.nextToken();
       tmp = recognizeLaugh(tmp);
       tmp2 = tmp2 + " " + removeUsername(tmp);
     }
     result = tmp2;
     result = result.replaceAll("lu+v+", "love");
     result = removeRepeatedCharacters(result);
     // result = removeSymbols(result);
     result_fin = result_fin + result;
   }
   return result_fin;
 }
예제 #6
0
 private void commandKill(StringTokenizer t) throws NoSessionException {
   // ### Should change the way in which thread ids and threadgroup names
   // ### are distinguished.
   if (!t.hasMoreTokens()) {
     env.error("Usage: kill <threadgroup name> or <thread id>");
     return;
   }
   while (t.hasMoreTokens()) {
     String idToken = t.nextToken();
     ThreadReference thread = findThread(idToken);
     if (thread != null) {
       runtime.stopThread(thread);
       env.notice("Thread " + thread.name() + " killed.");
       return;
     } else {
       /* Check for threadgroup name, NOT skipping "system". */
       // ### Should skip "system"?  Classic 'jdb' does this.
       // ### Should deal with possible non-uniqueness of threadgroup names.
       ThreadGroupIterator itg = allThreadGroups();
       while (itg.hasNext()) {
         ThreadGroupReference tg = itg.nextThreadGroup();
         if (tg.name().equals(idToken)) {
           ThreadIterator it = new ThreadIterator(tg);
           while (it.hasNext()) {
             runtime.stopThread(it.nextThread());
           }
           env.notice("Threadgroup " + tg.name() + "killed.");
           return;
         }
       }
       env.failure("\"" + idToken + "\" is not a valid threadgroup or id.");
     }
   }
 }
예제 #7
0
  /**
   * Determines the command denoted by the line.
   *
   * @param line the text as typed in at the console.
   * @return the command represented by the line, or NONE if the line is empty.
   * @throws InvalidCommandException if no recognizable command was found on a non-empty line.
   */
  static Command getCommand(String line) throws InvalidCommandException {
    StringTokenizer tokenizer = new StringTokenizer(line);
    if (!tokenizer.hasMoreTokens()) {
      return NONE;
    }
    String command = tokenizer.nextToken();

    /* Check for a manifest command */
    for (Command c : Command.values()) {
      if (c.manifest && c.name().equalsIgnoreCase(command)) {
        if (!tokenizer.hasMoreTokens()) {
          return c;
        }
        /* Extra token. */
        throw new InvalidCommandException(
            "Unexpected argument: " + tokenizer.nextToken() + " for command: " + command);
      }
    }
    /* A stock update command, token following arg must be a price*/
    if (!tokenizer.hasMoreTokens()) {
      throw new InvalidCommandException("Unknown command: " + command + "\n" + StockQuotes.usage());
    }
    String price = tokenizer.nextToken();

    try {
      Float.parseFloat(price);
      if (tokenizer.hasMoreTokens()) {
        throw new InvalidCommandException("Extraneous argument: " + tokenizer.nextToken());
      }
    } catch (NumberFormatException e) {
      throw new InvalidCommandException("Stock price must be a numeric value, not: " + price);
    }

    return UPDATE;
  }
예제 #8
0
  /**
   * Loads the declarations of the script engines declared in a property set
   *
   * @param props property set containing the configuration
   * @throws ConfigurationException if the scripting languages cannot be loaded
   */
  private void loadScriptingLanguages(Properties props) throws ConfigurationException {
    String strEngineList = loadProperty(props, SCRIPT_ENGINE_LIST_P);

    for (StringTokenizer engineTokenizer = new StringTokenizer(strEngineList);
        engineTokenizer.hasMoreTokens(); ) {
      String engineBaseItem = engineTokenizer.nextToken();
      String engineName = props.getProperty(engineBaseItem + ".name"); // $NON-NLS-1$
      String engineClass = props.getProperty(engineBaseItem + ".class"); // $NON-NLS-1$
      String engineExtProps = props.getProperty(engineBaseItem + ".extensions"); // $NON-NLS-1$
      String[] extArray = null;
      if (engineExtProps != null) {
        List<String> extList = new ArrayList<String>();
        for (StringTokenizer extTokenizer = new StringTokenizer(engineExtProps);
            extTokenizer.hasMoreTokens(); ) {
          String extension = extTokenizer.nextToken();
          ext = extension;
          extList.add(extension);
        }
        extArray = extList.toArray(new String[0]);
      }
      BSFManager.registerScriptingEngine(engineName, engineClass, extArray);
      System.out.println("Script " + engineName + " loaded"); // $NON-NLS-1$ //$NON-NLS-2$
    }

    defaultEngineName = loadProperty(props, DFLT_SCRIPT_ENGINE_P);
  }
 private Map<Integer, String> findComments(GroovyCompilationUnit unit) {
   List<Comment> comments = unit.getModuleNode().getContext().getComments();
   Map<Integer, String> allComments = new HashMap<Integer, String>(comments.size());
   for (Comment comment : comments) {
     StringTokenizer stok = new StringTokenizer(comment.toString());
     String type = null;
     if (stok.hasMoreTokens()) {
       // consume the comment start
       String val = stok.nextToken();
       int typeIndex = val.indexOf("TYPE:");
       if (typeIndex > 0) {
         type = val.substring(typeIndex + "TYPE:".length());
         if (type.length() == 0) {
           type = null;
         }
       }
     }
     String candidate;
     if (stok.hasMoreTokens() && (candidate = stok.nextToken()).startsWith("TYPE:")) {
       // may or may not have a space after the colon
       if (candidate.equals("TYPE:")) {
         if (stok.hasMoreTokens()) {
           type = stok.nextToken();
         }
       } else {
         String[] split = candidate.split("\\:");
         type = split[1];
       }
     }
     if (type != null) {
       allComments.put(comment.sline, type);
     }
   }
   return allComments;
 }
예제 #10
0
  public void paint(Graphics g) {
    m_fm = g.getFontMetrics();

    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

    g.setColor(getForeground());
    g.setFont(getFont());
    m_insets = getInsets();
    int x = m_insets.left;
    int y = m_insets.top + m_fm.getAscent();

    StringTokenizer st = new StringTokenizer(getText(), "\t");
    while (st.hasMoreTokens()) {
      String sNext = st.nextToken();
      g.drawString(sNext, x, y);
      x += m_fm.stringWidth(sNext);

      if (!st.hasMoreTokens()) break;
      int index = 0;
      while (x >= getTab(index)) index++;
      x = getTab(index);
    }
  }
  public Instance createInstance(String line) throws NumberFormatException {
    StringTokenizer st = new StringTokenizer(line, " \t");
    if (!st.hasMoreTokens()) {
      throw new RuntimeException("Lable not Found");
    }
    String labelStr = st.nextToken();
    boolean label = false;
    if (labelStr.equals("+1")) label = true;

    ArrayList<Float> weightslist = new ArrayList<Float>();
    ArrayList<Integer> indiceslist = new ArrayList<Integer>();

    while (st.hasMoreTokens()) {
      String[] kv = spliter.split(st.nextToken());
      if (kv.length != 2) {
        throw new RuntimeException("Cannot parse line " + line);
      }
      indiceslist.add(new Integer(kv[0]));
      weightslist.add(new Float(kv[1]));
    }

    int[] indices = new int[indiceslist.size()];
    float[] weights = new float[weightslist.size()];
    for (int i = 0; i < indices.length; ++i) {
      indices[i] = indiceslist.get(i).intValue();
      weights[i] = weightslist.get(i).floatValue();
    }
    return new Instance(weights, indices, label);
  }
예제 #12
0
  /**
   * Reads the shape specification as defined in the class javadocs. If the first character is a
   * letter but it doesn't complete out "Circle" or "CIRCLE" then this method returns null, offering
   * the caller the opportunity to potentially try additional parsing. If the first character is not
   * a letter then it's assumed to be a point or rectangle. If that doesn't work out then an {@link
   * org.locationtech.spatial4j.exception.InvalidShapeException} is thrown.
   */
  public static Shape readShapeOrNull(String str, SpatialContext ctx) throws InvalidShapeException {
    if (str == null || str.length() == 0) {
      throw new InvalidShapeException(str);
    }

    if (Character.isLetter(str.charAt(0))) {
      if (str.startsWith("Circle(") || str.startsWith("CIRCLE(")) {
        int idx = str.lastIndexOf(')');
        if (idx > 0) {
          String body = str.substring("Circle(".length(), idx);
          StringTokenizer st = new StringTokenizer(body, " ");
          String token = st.nextToken();
          Point pt;
          if (token.indexOf(',') != -1) {
            pt = readLatCommaLonPoint(token, ctx);
          } else {
            double x = Double.parseDouble(token);
            double y = Double.parseDouble(st.nextToken());
            pt = ctx.makePoint(x, y);
          }
          Double d = null;

          String arg = st.nextToken();
          idx = arg.indexOf('=');
          if (idx > 0) {
            String k = arg.substring(0, idx);
            if (k.equals("d") || k.equals("distance")) {
              d = Double.parseDouble(arg.substring(idx + 1));
            } else {
              throw new InvalidShapeException("unknown arg: " + k + " :: " + str);
            }
          } else {
            d = Double.parseDouble(arg);
          }
          if (st.hasMoreTokens()) {
            throw new InvalidShapeException("Extra arguments: " + st.nextToken() + " :: " + str);
          }
          if (d == null) {
            throw new InvalidShapeException("Missing Distance: " + str);
          }
          // NOTE: we are assuming the units of 'd' is the same as that of the spatial context.
          return ctx.makeCircle(pt, d);
        }
      }
      return null; // caller has opportunity to try other parsing
    }

    if (str.indexOf(',') != -1) return readLatCommaLonPoint(str, ctx);
    StringTokenizer st = new StringTokenizer(str, " ");
    double p0 = Double.parseDouble(st.nextToken());
    double p1 = Double.parseDouble(st.nextToken());
    if (st.hasMoreTokens()) {
      double p2 = Double.parseDouble(st.nextToken());
      double p3 = Double.parseDouble(st.nextToken());
      if (st.hasMoreTokens())
        throw new InvalidShapeException("Only 4 numbers supported (rect) but found more: " + str);
      return ctx.makeRectangle(p0, p2, p1, p3);
    }
    return ctx.makePoint(p0, p1);
  }
 public static Table build(String content) {
   Table table = new Table();
   StringTokenizer tokenizer = new StringTokenizer(content, "|\n", true);
   String lastToken = null;
   while (tokenizer.hasMoreTokens()) {
     String token = tokenizer.nextToken();
     String linkToken = "";
     if (token.indexOf('[') != -1 && token.indexOf(']') == -1) {
       while (token.indexOf(']') == -1 && tokenizer.hasMoreTokens()) {
         linkToken += token;
         token = tokenizer.nextToken();
       }
       token = linkToken + token;
     }
     if ("\n".equals(token)) {
       // Handles "\n" - "|\n"
       if (null == lastToken || "|".equals(lastToken)) {
         table.addCell(" ");
       }
       table.newRow();
     } else if (!"|".equals(token)) {
       table.addCell(token);
     } else if (null == lastToken || "|".equals(lastToken)) {
       // Handles "|" "||"
       table.addCell(" ");
     }
     lastToken = token;
   }
   return table;
 }
예제 #14
0
  /**
   * Methode, um aus einer IP-Adresse und einer Subnetzmaske eine Netzwerkkennung als String zu
   * erzeugen. Bsp.: 192.168.2.6 und 255.255.255.0 wird zu 192.168.2.0
   */
  private String berechneNetzkennung(String ipAdresse, String netzmaske) {
    Main.debug.println(
        "INVOKED ("
            + this.hashCode()
            + ") "
            + getClass()
            + " (Weiterleitungstabelle), berechneNetzkennung("
            + ipAdresse
            + ","
            + netzmaske
            + ")");
    int[] adresse, maske, netzkennung;
    StringTokenizer tokenizer;

    tokenizer = new StringTokenizer(ipAdresse, ".");
    adresse = new int[4];
    for (int i = 0; i < adresse.length && tokenizer.hasMoreTokens(); i++) {
      adresse[i] = Integer.parseInt(tokenizer.nextToken());
    }
    tokenizer = new StringTokenizer(netzmaske, ".");
    maske = new int[4];
    for (int i = 0; i < maske.length && tokenizer.hasMoreTokens(); i++) {
      maske[i] = Integer.parseInt(tokenizer.nextToken());
    }

    netzkennung = new int[4];
    for (int i = 0; i < 4; i++) {
      netzkennung[i] = adresse[i] & maske[i];
    }

    return netzkennung[0] + "." + netzkennung[1] + "." + netzkennung[2] + "." + netzkennung[3];
  }
예제 #15
0
    public void map(
        LongWritable key,
        Text value,
        OutputCollector<IntWritable, HITSNode> output,
        Reporter reporter)
        throws IOException {

      ArrayListOfIntsWritable links = new ArrayListOfIntsWritable();
      String line = ((Text) value).toString();
      StringTokenizer itr = new StringTokenizer(line);
      if (itr.hasMoreTokens()) {
        int curr = Integer.parseInt(itr.nextToken());
        if (stopList.contains(curr)) {
          return;
        }
        valOut.setAdjacencyList(links);
        valOut.setHARank((float) 1.0);
        valOut.setType(HITSNode.TYPE_AUTH_COMPLETE);
      }
      while (itr.hasMoreTokens()) {
        keyOut.set(Integer.parseInt(itr.nextToken()));
        valOut.setNodeId(keyOut.get());
        // System.out.println(keyOut.toString() + ", " +
        // valOut.toString());
        if (!(stopList.contains(keyOut.get()))) {
          output.collect(keyOut, valOut);
        }
      }
      // emit mentioned mentioner -> mentioned (mentioners) in links
      // emit mentioner mentioned -> mentioner (mentions) outlinks
      // emit mentioned a
      // emit mentioner 1
    }
예제 #16
0
    private FSTree buildTree(Collection<AbsFile> l) {
      FSTree tree = new FSTree(null);
      FSTree root = tree.getDir("absolute");
      root.setParent(root);

      for (AbsFile f : l) {
        String path = f.getPath();
        boolean absolute = path.startsWith("/");

        FSTree crt = absolute ? tree.getDir("absolute") : tree.getDir("relative");

        StringTokenizer st = new StringTokenizer(path, "/", false);
        while (st.hasMoreTokens()) {
          String token = st.nextToken();

          if (!st.hasMoreTokens()) {
            // file
            crt.addFile(token);
          } else if (token.equals("..")) {
            crt = crt.getParent();
          } else if (token.equals(".")) {
            // skip
          } else {
            crt = crt.getDir(token);
          }
        }
      }
      return tree;
    }
예제 #17
0
  public synchronized String create(String path, byte[] data, long time, long ephemeralOwner)
      throws MWZooKeeperException {

    StringTokenizer st = new StringTokenizer(path, "/");

    MWTreeNode cur = root;
    String str = null;
    while (st.hasMoreTokens()) {
      str = st.nextToken();
      if (cur.children.containsKey(str)) {
        if (!st.hasMoreTokens()) {
          throw new MWZooKeeperException("Ordner " + str + " schon vorhanden (" + path + ")!");
        } else {
          cur = cur.children.get(str);
        }
      } else if (st.hasMoreTokens()) {
        throw new MWZooKeeperException(
            "Ueberordner " + str + " existiert noch nicht (" + path + ")!");
      }
    }

    MWTreeNode node = new MWTreeNode(data, time);
    node.ephemeralOwner = ephemeralOwner;
    cur.children.put(str, node);

    return path;
  }
예제 #18
0
  protected void readProblemLine() throws IOException, ParseFormatException {

    String line = in.readLine();

    if (line == null) {
      throw new ParseFormatException(
          "premature end of file: <p cnf ...> expected  on line " + in.getLineNumber());
    }
    StringTokenizer stk = new StringTokenizer(line);

    if (!(stk.hasMoreTokens()
        && stk.nextToken().equals("p")
        && stk.hasMoreTokens()
        && stk.nextToken().equals(formatString))) {
      throw new ParseFormatException(
          "problem line expected (p cnf ...) on line " + in.getLineNumber());
    }

    // reads the max var id
    nbOfVars = Integer.parseInt(stk.nextToken());
    assert nbOfVars > 0;

    // reads the number of clauses
    expectedNbOfConstr = Integer.parseInt(stk.nextToken());
    assert expectedNbOfConstr > 0;
  }
예제 #19
0
  private void commandStop(StringTokenizer t) throws NoSessionException {
    String token;

    if (!t.hasMoreTokens()) {
      listEventRequests();
    } else {
      token = t.nextToken();
      // Ignore optional "at" or "in" token.
      // Allowed for backward compatibility.
      if (token.equals("at") || token.equals("in")) {
        if (t.hasMoreTokens()) {
          token = t.nextToken();
        } else {
          env.error("Missing breakpoint specification.");
          return;
        }
      }
      BreakpointSpec bpSpec = parseBreakpointSpec(token);
      if (bpSpec != null) {
        // ### Add sanity-checks for deferred breakpoint.
        runtime.install(bpSpec);
      } else {
        env.error("Ill-formed breakpoint specification.");
      }
    }
  }
예제 #20
0
 @Override
 protected ParseResult parseTokenWithSeparator(
     LoadContext context, FactSetDefinition def, String value) {
   StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE);
   String fileType = aTok.nextToken();
   if (!aTok.hasMoreTokens()) {
     return new ParseResult.Fail(
         getTokenName() + " expects 2 PIPE separated values, found 1 in: " + value, context);
   }
   String identifier = aTok.nextToken();
   if (aTok.hasMoreTokens()) {
     return new ParseResult.Fail(
         getTokenName() + " expects 3 PIPE separated values, found too many in: " + value,
         context);
   }
   Class<? extends Loadable> cl;
   if ("GLOBAL".equals(fileType)) {
     cl = CDOMObject.class;
   } else {
     cl = StringPClassUtil.getClassFor(fileType);
     if (cl == null) {
       throw new IllegalArgumentException(
           "Invalid Data Definition Location (no class): " + fileType);
     }
   }
   def.setUsableLocation(cl);
   def.setFactSetName(identifier);
   return ParseResult.SUCCESS;
 }
  /*
   * Read frequency in transxchange specific format
   */
  static int readTransxchangeFrequency(String inString) {
    int freq = 0;

    inString = inString.substring(2, inString.length()); // Skip "PT"
    if (inString.indexOf('H') > 0) { // Hours
      StringTokenizer st = new StringTokenizer(inString, "H");
      int i = 0;
      while (st.hasMoreTokens() && i < 1) {
        freq = Integer.parseInt(st.nextToken()) * 60 * 60;
        i++;
      }
      inString = inString.substring(inString.indexOf('H') + 1, inString.length());
    }
    if (inString.indexOf('M') > 0) { // Minutes
      StringTokenizer st = new StringTokenizer(inString, "M");
      int i = 0;
      while (st.hasMoreTokens() && i < 1) {
        freq += Integer.parseInt(st.nextToken()) * 60;
        i++;
      }
      inString = inString.substring(inString.indexOf('M') + 1, inString.length());
    }
    if (inString.indexOf('S') > 0) { // Seconds
      StringTokenizer st = new StringTokenizer(inString, "S");
      int i = 0;
      while (st.hasMoreTokens() && i < 1) {
        freq += Integer.parseInt(st.nextToken());
        i++;
      }
    }
    return freq;
  }
예제 #22
0
  /**
   * Get a list of jars that should be removed when updating or removing a plugin. Jars that are
   * shared by other currently installed plugins are not remove
   *
   * @param allPlugins
   */
  private HashMap getJarsToRemove(Vector allPlugins) {

    // Now determine what other jars should be removed as well
    HashMap removeJars = new HashMap();
    for (Enumeration e = allPlugins.elements(); e.hasMoreElements(); ) {
      Plugin p = (Plugin) e.nextElement();
      Properties pr = manager.getPluginProperties(p);
      String rs = pr.getProperty(PluginManager.PLUGIN_RESOURCE);
      removeJars.put(rs, rs);
      String jars = pr.getProperty(PluginManager.PLUGIN_JARS, "");
      StringTokenizer st = new StringTokenizer(jars, ",");
      while (st.hasMoreTokens()) {
        String jar = st.nextToken();
        removeJars.put(jar, new File(manager.getPluginDirectory(), jar).getAbsolutePath());
      }
    }

    // If any plugins that are not being removed require any of the jars
    // that are going to be removed, dont remove them
    for (Enumeration e = manager.plugins(); e.hasMoreElements(); ) {
      Plugin p = (Plugin) e.nextElement();
      if (allPlugins.indexOf(p) == -1) {
        Properties pr = manager.getPluginProperties(p);
        String jars = pr.getProperty(PluginManager.PLUGIN_JARS, "");
        StringTokenizer st = new StringTokenizer(jars, ",");
        while (st.hasMoreTokens()) {
          String jar = st.nextToken();
          if (removeJars.containsKey(jar)) removeJars.remove(jar);
        }
      }
    }

    return removeJars;
  }
예제 #23
0
 /**
  * 按照从左到右顺序来分解表达式,得到需要解析的元素名称, 还有该元素对应的解析模型
  *
  * @param expr 需要分解的表达式
  * @return 得到需要解析的元素名称,还有该元素对应的解析模型
  */
 private static Map<String, ParserModel> parseMapPath(String expr) {
   // 先按照/分割字符串
   StringTokenizer tokenizer = new StringTokenizer(expr, BACKLASH);
   // 初始化一个map用来存放分解出来的值
   Map<String, ParserModel> mapPath = new HashMap<String, ParserModel>();
   while (tokenizer.hasMoreTokens()) {
     String onePath = tokenizer.nextToken();
     if (tokenizer.hasMoreTokens()) {
       // 还有下一个值,说明这不是最后一个元素
       // 按照现在的语法,属性必然在最后,因此也不是属性
       setParsePath(false, onePath, false, mapPath);
     } else {
       // 说明到最后了
       int dotIndex = onePath.indexOf(DOT);
       if (dotIndex > 0) {
         // 说明是要获取属性的值,那就按照"."来分割,前面的就是元素名字,后面的是属性的名字
         String eleName = onePath.substring(0, dotIndex);
         String propName = onePath.substring(dotIndex + 1);
         // 设置属性前面的那个元素,自然不是最后一个,也不是属性
         setParsePath(false, eleName, false, mapPath);
         // 设置属性,按照现在的语法定义,属性只能是最后一个
         setParsePath(true, propName, true, mapPath);
       } else {
         // 说明是取元素的值,而且是最后一个元素的值
         setParsePath(true, onePath, false, mapPath);
       }
       break;
     }
   }
   return mapPath;
 }
예제 #24
0
  /**
   * Create and return the details for a history line.
   *
   * @param details
   * @return
   */
  public String changeDetails() {
    String the_details = "";

    StringTokenizer tokens = new StringTokenizer(this.change_details, "|");
    while (tokens.hasMoreTokens()) {
      String token = tokens.nextToken().trim();
      int i = 0;

      StringTokenizer tokens2 = new StringTokenizer(token, ";");
      while (tokens2.hasMoreTokens()) {
        String token2 = tokens2.nextToken().trim();
        token2 = Util.encodeTagAndNull(token2);
        i++;

        if (i == 1) {
          the_details = the_details + "<tr>" + "	<td>" + "		<b>" + token2 + ":</b>" + "	</td>";
        }
        if (i == 2) {
          the_details = the_details + "	<td>" + "		" + token2 + "	</td>";
        }
        if (i == 3) {
          the_details = the_details + "	<td>" + "		" + token2 + "	</td>" + "</tr>";
        }
      } // end inner tokenizer for deteils on eg. location
    } // end outher tokenizer on the list of changes for a container.

    return the_details;
  }
예제 #25
0
    protected void buildPanel(String strPath) {
      BufferedReader reader = WFileUtil.openReadFile(strPath);
      String strLine;

      if (reader == null) return;

      try {
        while ((strLine = reader.readLine()) != null) {
          if (strLine.startsWith("#") || strLine.startsWith("%") || strLine.startsWith("@"))
            continue;

          StringTokenizer sTokLine = new StringTokenizer(strLine, ":");

          // first token is the label e.g. Password Length
          if (sTokLine.hasMoreTokens()) {
            createLabel(sTokLine.nextToken(), this);
          }

          // second token is the value
          String strValue = sTokLine.hasMoreTokens() ? sTokLine.nextToken() : "";
          if (strValue.equalsIgnoreCase("yes") || strValue.equalsIgnoreCase("no"))
            createChkBox(strValue, this);
          else createTxf(strValue, this);
        }
      } catch (Exception e) {
        Messages.writeStackTrace(e);
        // e.printStackTrace();
        Messages.postDebug(e.toString());
      }
    }
  /** UTF8 encode the Request Parameters skipping the '&' and '=' characters */
  protected String encodeParams(String params) {
    StringBuffer buffer = new StringBuffer();

    if (params != null && params.length() > 0) {
      StringTokenizer st1 = new StringTokenizer(params, "&");

      while (st1.hasMoreTokens()) {
        StringTokenizer st2 = new StringTokenizer(st1.nextToken(), "=");

        try {
          if (st2.hasMoreTokens()) {
            // encode and append the name part
            buffer.append(URLEncoder.encode(st2.nextToken(), CCI18N.UTF8_ENCODING));
          }

          // encode and append the value part
          if (st2.hasMoreTokens()) {
            buffer
                .append("=")
                .append(URLEncoder.encode(st2.nextToken(), CCI18N.UTF8_ENCODING))
                .append("&amp;");
          }
        } catch (UnsupportedEncodingException uee) {
        }
      } // end while
    } // end if params

    return buffer.toString();
  }
예제 #27
0
 public Object get(String key) {
   if (this.myKey.equals(key)) {
     return this;
   } else if (this.children.containsKey(key)) {
     return this.children.get(key);
   } else if (key.startsWith(this.myKey)) {
     String smallKey = StringUtils.minus(key, this.myKey + ".");
     StringTokenizer tokenizer = new StringTokenizer(smallKey, ".");
     BundleContent bcont = this;
     while (tokenizer.hasMoreTokens()) {
       String token = tokenizer.nextToken();
       if (bcont.children.containsKey(token)) {
         bcont = bcont.children.get(token);
       } else {
         return "!" + key + "!";
       }
     }
     return bcont;
   } else {
     StringTokenizer tokenizer = new StringTokenizer(key, ".");
     if (tokenizer.hasMoreTokens()) {
       String token = tokenizer.nextToken();
       if (this.children.containsKey(token)) {
         return this.children.get(token);
       } else {
         return "!" + key + "!";
       }
     } else {
       return "!" + key + "!";
     }
   }
 }
예제 #28
0
 public CommandResponse doSlave(CommandRequest request) throws ImproperUsageException {
   if (!request.hasArgument()) {
     throw new ImproperUsageException();
   }
   boolean showMore = false;
   StringTokenizer arguments = new StringTokenizer(request.getArgument());
   String slaveName = arguments.nextToken();
   if (arguments.hasMoreTokens()) {
     if (arguments.nextToken().equalsIgnoreCase("more")) {
       showMore = true;
     } else {
       throw new ImproperUsageException();
     }
   }
   if (arguments.hasMoreTokens()) {
     throw new ImproperUsageException();
   }
   CommandResponse response = StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK");
   try {
     RemoteSlave rslave =
         GlobalContext.getGlobalContext().getSlaveManager().getRemoteSlave(slaveName);
     response = addSlaveStatus(request, response, showMore, rslave);
   } catch (ObjectNotFoundException e) {
     ReplacerEnvironment env = new ReplacerEnvironment();
     env.add("slavename", slaveName);
     response.addComment(
         request
             .getSession()
             .jprintf(_bundle, _keyPrefix + "slave.notfound", env, request.getUser()));
   }
   return response;
 }
예제 #29
0
  // Read from file
  public void readFile(String fileName) {
    // TODO Auto-generated method stub

    try {
      FileReader frStream = new FileReader(fileName);
      BufferedReader brStream = new BufferedReader(frStream);
      String inputLine;
      int i = 0;
      Vector<Object> currentRow = new Vector<Object>();
      while ((inputLine = brStream.readLine()) != null) {
        // Ignore the file comment
        if (inputLine.startsWith("#")) continue;

        // Extract the column name
        if (inputLine.startsWith("$")) {
          StringTokenizer st1 = new StringTokenizer(inputLine.substring(1), " ");

          while (st1.hasMoreTokens()) colName.addElement(st1.nextToken());
        } else
        // Extract data and put into the row records
        {
          StringTokenizer st1 = new StringTokenizer(inputLine, " ");
          currentRow = new Vector<Object>();
          while (st1.hasMoreTokens()) currentRow.addElement(st1.nextToken());
          data.addElement(currentRow);
        }
      }

      brStream.close();
    } catch (IOException ex) {
      System.out.println("Error in readFile method! " + ex);
    }
  }
예제 #30
0
  /**
   * Method parse.
   *
   * @param mlsxEntry
   */
  private void parse(String mlsxEntry) {

    StringTokenizer tokenizer = new StringTokenizer(mlsxEntry, ";");

    while (tokenizer.hasMoreTokens()) {

      String token = tokenizer.nextToken();

      if (tokenizer.hasMoreTokens()) {

        // next fact
        String fact = token;
        logger.debug("fact: " + fact);
        int equalSign = fact.indexOf('=');
        String factName = fact.substring(0, equalSign).trim().toLowerCase();
        String factValue = fact.substring(equalSign + 1, fact.length());

        facts.put(factName, factValue);

      } else {

        // name: trim leading space
        this.fileName = token.substring(1, token.length());
        logger.debug("name: " + fileName);
      }
    }
  }