public void map(
      Object unused,
      Text line,
      OutputCollector<LongWritable, PostingSongArrayWritable> output,
      Reporter reporter)
      throws IOException {

    StringTokenizer str = new StringTokenizer(line.toString(), " |\t");

    if (nRatings == 0) {
      userId = Long.parseLong(str.nextToken());
      nRatings = Integer.parseInt(str.nextToken());
      songsRatings.clear();
      totalRate = 0;
    } else {
      long songId = Long.parseLong(str.nextToken());
      int rate = Integer.parseInt(str.nextToken());
      songsRatings.add(new PostingSong(songId, rate));
      totalRate += rate;
      nRatings--;
      if (nRatings == 0) {
        nRatings = songsRatings.size();
        songsValue.setArray(songsRatings);
        output.collect(userIdKey, songsValue);
        nRatings = 0;
      }
    }
  }
Ejemplo n.º 2
0
  public String classify(String cps) {
    // cps contains a list of context predicates

    String modelLabel = "";
    int i;

    intCps.clear();

    StringTokenizer strTok = new StringTokenizer(cps, " \t\r\n");
    int count = strTok.countTokens();

    for (i = 0; i < count; i++) {
      String cpStr = strTok.nextToken();
      Integer cpInt = (Integer) data.cpStr2Int.get(cpStr);
      if (cpInt != null) {
        intCps.add(cpInt);
      }
    }

    Observation obsr = new Observation(intCps);

    // classify
    inference.classify(obsr);

    String lbStr = (String) data.lbInt2Str.get(new Integer(obsr.modelLabel));
    if (lbStr != null) {
      modelLabel = lbStr;
    }

    return modelLabel;
  }
Ejemplo n.º 3
0
 private boolean funcLocMixVeloOk(ccr.app.Context ctx1, ccr.app.Context ctx2) {
   java.lang.String v1 = (java.lang.String) ctx1.get(Context.FLD_OBJECT);
   java.lang.String v2 = (java.lang.String) ctx1.get(Context.FLD_TIMESTAMP);
   java.lang.String v3 = (java.lang.String) ctx2.get(Context.FLD_OBJECT);
   java.lang.String v4 = (java.lang.String) ctx2.get(Context.FLD_TIMESTAMP);
   if (v1 == null || v2 == null || v3 == null || v4 == null) {
     return false;
   }
   java.util.StringTokenizer st = new java.util.StringTokenizer(v1);
   double x1 = Double.parseDouble(st.nextToken());
   double y1 = Double.parseDouble(st.nextToken());
   st = new java.util.StringTokenizer(v3);
   double x2 = Double.parseDouble(st.nextToken());
   double y2 = Double.parseDouble(st.nextToken());
   double dist = Coordinates.calDist(x1, y1, x2, y2);
   long t = TimeFormat.convert(v4) - TimeFormat.convert(v2) - STAY_TIME;
   boolean result = false;
   double vmin = (VELOCITY * ((double) t / 1000) - 2 * ERR) / ((double) t / 1000);
   double vmax = (VELOCITY * ((double) t / 1000) + 2 * ERR) / ((double) t / 1000);
   double ve = dist / ((double) t / 1000);
   if (ve >= vmin && ve <= vmax) {
     result = true;
   }
   return result;
 }
Ejemplo n.º 4
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;
  }
Ejemplo n.º 5
0
  private boolean funcLocMixVeloOk(Context ctx1, Context ctx2) { // boolean function 4

    String v1 = (String) ctx1.get(Context.FLD_OBJECT);
    String v2 = (String) ctx1.get(Context.FLD_TIMESTAMP);
    String v3 = (String) ctx2.get(Context.FLD_OBJECT);
    String v4 = (String) ctx2.get(Context.FLD_TIMESTAMP);
    if (v1 == null || v2 == null || v3 == null || v4 == null) {
      return false;
    }

    StringTokenizer st = new StringTokenizer(v1);
    double x1 = Double.parseDouble(st.nextToken());
    double y1 = Double.parseDouble(st.nextToken());
    st = new StringTokenizer(v3);
    double x2 = Double.parseDouble(st.nextToken());
    double y2 = Double.parseDouble(st.nextToken());
    double dist = Coordinates.calDist(x1, y1, x2, y2);
    long t = TimeFormat.convert(v4) - TimeFormat.convert(v2) - STAY_TIME; // Different here

    // The velocity should be between vmin and vmax
    boolean result = false;
    double vmin = (VELOCITY * ((double) t / 1000) - 2 * ERR) / ((double) t / 1000);
    double vmax = (VELOCITY * ((double) t / 1000) + 2 * ERR) / ((double) t / 1000);
    double ve = dist / ((double) t / 1000);
    if (ve >= vmin && ve <= vmax) {
      result = true;
    }

    return result;
  }
Ejemplo n.º 6
0
 /**
  * Forwards the received message to the list of users defined in the property
  * <b>xmpp.forward.admins</b>. The property may include bare JIDs or just usernames separated by
  * commas or white spaces. When using bare JIDs the target user may belong to a remote server.
  *
  * <p>If the property <b>xmpp.forward.admins</b> was not defined then the message will be sent to
  * all the users allowed to enter the admin console.
  *
  * @param packet the message to forward.
  */
 private void sendMessageToAdmins(Message packet) {
   String jids = JiveGlobals.getProperty("xmpp.forward.admins");
   if (jids != null && jids.trim().length() > 0) {
     // Forward the message to the users specified in the "xmpp.forward.admins" property
     StringTokenizer tokenizer = new StringTokenizer(jids, ", ");
     while (tokenizer.hasMoreTokens()) {
       String username = tokenizer.nextToken();
       Message forward = packet.createCopy();
       if (username.contains("@")) {
         // Use the specified bare JID address as the target address
         forward.setTo(username);
       } else {
         forward.setTo(username + "@" + serverName);
       }
       route(forward);
     }
   } else {
     // Forward the message to the users allowed to log into the admin console
     for (JID jid : XMPPServer.getInstance().getAdmins()) {
       Message forward = packet.createCopy();
       forward.setTo(jid);
       route(forward);
     }
   }
 }
Ejemplo n.º 7
0
 /**
  * Разделить строку на подстроки в соответствии с разделителями заданными 2-м параметром. Сами
  * разделители тоже будут входить в выходной массив.
  *
  * @param str - Исходная строка
  * @param delim - Список разделителей
  * @return - список подстрок
  */
 public static ArrayList<String> aTokenDelimList(String str, String delim) {
   StringTokenizer strtok = new StringTokenizer(str, delim, true);
   int count = strtok.countTokens();
   ArrayList<String> result = new ArrayList<String>();
   for (int i = 1; i <= count; i++) result.add(strtok.nextToken());
   return result;
 }
Ejemplo n.º 8
0
  @Override
  protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    boolean first = true;

    while (tok.hasMoreTokens()) {
      String tokString = tok.nextToken();
      if (Constants.LST_DOT_CLEAR.equals(tokString)) {
        if (!first) {
          return new ParseResult.Fail(
              "  Non-sensical "
                  + getTokenName()
                  + ": .CLEAR was not the first list item: "
                  + value);
        }
        context.obj.removeList(race, ListKey.RACESUBTYPE);
      } else if (tokString.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
        String clearText = tokString.substring(7);
        context
            .getObjectContext()
            .removeFromList(race, ListKey.RACESUBTYPE, RaceSubType.getConstant(clearText));
      } else {
        context
            .getObjectContext()
            .addToList(race, ListKey.RACESUBTYPE, RaceSubType.getConstant(tokString));
      }
      first = false;
    }
    return ParseResult.SUCCESS;
  }
Ejemplo n.º 9
0
  private void updateVpInfo() {

    String key;
    String vps;
    for (int j = 0; j < keys.size(); j++) {
      key = (String) keys.get(j);
      vps = (String) vpInfo.get(j);
      if (vps == null || vps.length() <= 0 || vps.equals("all")) {
        for (int i = 0; i < nviews; i++) {
          tp_paneInfo[i].put(key, "yes");
        }
      } else {
        for (int i = 0; i < nviews; i++) tp_paneInfo[i].put(key, "no");
        StringTokenizer tok = new StringTokenizer(vps, " ,\n");
        while (tok.hasMoreTokens()) {
          int vp = Integer.valueOf(tok.nextToken()).intValue();
          vp--;
          if (vp >= 0 && vp < nviews) {
            tp_paneInfo[vp].remove(key);
            tp_paneInfo[vp].put(key, "yes");
          }
        }
      }
    }
  }
Ejemplo n.º 10
0
 public String next() throws Exception {
   if (!tokenizer.hasMoreTokens()) {
     tokenizer = new StringTokenizer(reader.readLine().trim());
     return next();
   }
   return tokenizer.nextToken();
 }
Ejemplo n.º 11
0
 private static void dumpConfig(Configuration conf, StringBuilder sb) {
   Iterator<Map.Entry<String, String>> configIter = conf.iterator();
   List<Map.Entry<String, String>> configVals = new ArrayList<>();
   while (configIter.hasNext()) {
     configVals.add(configIter.next());
   }
   Collections.sort(
       configVals,
       new Comparator<Map.Entry<String, String>>() {
         @Override
         public int compare(Map.Entry<String, String> ent, Map.Entry<String, String> ent2) {
           return ent.getKey().compareTo(ent2.getKey());
         }
       });
   for (Map.Entry<String, String> entry : configVals) {
     // use get() to make sure variable substitution works
     if (entry.getKey().toLowerCase().contains("path")) {
       StringTokenizer st = new StringTokenizer(conf.get(entry.getKey()), File.pathSeparator);
       sb.append(entry.getKey()).append("=\n");
       while (st.hasMoreTokens()) {
         sb.append("    ").append(st.nextToken()).append(File.pathSeparator).append('\n');
       }
     } else {
       sb.append(entry.getKey()).append('=').append(conf.get(entry.getKey())).append('\n');
     }
   }
 }
Ejemplo n.º 12
0
 public int numTokens() throws Exception {
   if (!tokenizer.hasMoreTokens()) {
     tokenizer = new StringTokenizer(reader.readLine().trim());
     return numTokens();
   }
   return tokenizer.countTokens();
 }
Ejemplo n.º 13
0
  static {
    SerializerFactory factory;
    String list;
    StringTokenizer token;
    String className;

    // The default factories are always registered first,
    // any factory specified in the properties file and supporting
    // the same method will override the default factory.
    factory = new SerializerFactoryImpl(Method.XML);
    registerSerializerFactory(factory);
    factory = new SerializerFactoryImpl(Method.HTML);
    registerSerializerFactory(factory);
    factory = new SerializerFactoryImpl(Method.XHTML);
    registerSerializerFactory(factory);
    factory = new SerializerFactoryImpl(Method.TEXT);
    registerSerializerFactory(factory);

    list = System.getProperty(FactoriesProperty);
    if (list != null) {
      token = new StringTokenizer(list, " ;,:");
      while (token.hasMoreTokens()) {
        className = token.nextToken();
        try {
          factory =
              (SerializerFactory)
                  ObjectFactory.newInstance(
                      className, SerializerFactory.class.getClassLoader(), true);
          if (_factories.containsKey(factory.getSupportedMethod()))
            _factories.put(factory.getSupportedMethod(), factory);
        } catch (Exception except) {
        }
      }
    }
  }
Ejemplo n.º 14
0
  /**
   * evaluates the 'Set-Cookie'-Header of a HTTP response
   *
   * @param name key of a cookie value
   * @param conn URLConnection
   * @return cookie value referenced by the key. null if key not found
   * @throws IOException
   */
  private static String getCookie(String name, URLConnection conn) {

    for (int i = 0; ; i++) {
      String headerName = conn.getHeaderFieldKey(i);
      String headerValue = conn.getHeaderField(i);

      if (headerName == null && headerValue == null) {
        // No more headers
        break;
      }
      if (headerName != null && headerName.equals("Set-Cookie")) {
        if (headerValue.startsWith(name)) {
          // several key-value-pairs are separated by ';'
          StringTokenizer st = new StringTokenizer(headerValue, "; ");
          while (st.hasMoreElements()) {
            String token = st.nextToken();
            if (token.startsWith(name)) {
              return token;
            }
          }
        }
      }
    }
    return null;
  }
Ejemplo n.º 15
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;
  }
Ejemplo n.º 16
0
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    int cases = 1;
    while (true) {
      st = new StringTokenizer(in.readLine());
      n = Integer.parseInt(st.nextToken());
      m = Integer.parseInt(st.nextToken());
      if (n == 0 && m == 0) break;
      a = new int[n];
      b = new int[m];
      dp = new int[n + 1][m + 1];
      st = new StringTokenizer(in.readLine());
      for (int i = 0; i < n; i++) {
        a[i] = Integer.parseInt(st.nextToken());
        Arrays.fill(dp[i], -1);
      }
      Arrays.fill(dp[n], -1);
      st = new StringTokenizer(in.readLine());
      for (int i = 0; i < m; i++) b[i] = Integer.parseInt(st.nextToken());

      System.out.println("Twin Towers #" + cases);
      System.out.println("Number of Tiles : " + LCS(0, 0));
      System.out.println();
      cases++;
    }
    in.close();
    System.exit(0);
  }
 /**
  * main method
  *
  * <p>This uses the system properties:
  *
  * <ul>
  *   <li><code>rjava.path</code> : path of the rJava package
  *   <li><code>rjava.lib</code> : lib sub directory of the rJava package
  *   <li><code>main.class</code> : main class to "boot", assumes Main if not specified
  *   <li><code>rjava.class.path</code> : set of paths to populate the initiate the class path
  * </ul>
  *
  * <p>and boots the "main" method of the specified <code>main.class</code>, passing the args down
  * to the booted class
  *
  * <p>This makes sure R and rJava are known by the class loader
  */
 public static void main(String[] args) {
   String rJavaPath = System.getProperty("rjava.path");
   if (rJavaPath == null) {
     System.err.println("ERROR: rjava.path is not set");
     System.exit(2);
   }
   String rJavaLib = System.getProperty("rjava.lib");
   if (rJavaLib == null) { // it is not really used so far, just for rJava.so, so we can guess
     rJavaLib = rJavaPath + File.separator + "libs";
   }
   RJavaClassLoader cl = new RJavaClassLoader(u2w(rJavaPath), u2w(rJavaLib));
   String mainClass = System.getProperty("main.class");
   if (mainClass == null || mainClass.length() < 1) {
     System.err.println("WARNING: main.class not specified, assuming 'Main'");
     mainClass = "Main";
   }
   String classPath = System.getProperty("rjava.class.path");
   if (classPath != null) {
     StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator);
     while (st.hasMoreTokens()) {
       String dirname = u2w(st.nextToken());
       cl.addClassPath(dirname);
     }
   }
   try {
     cl.bootClass(mainClass, "main", args);
   } catch (Exception ex) {
     System.err.println("ERROR: while running main method: " + ex);
     ex.printStackTrace();
   }
 }
Ejemplo n.º 18
0
  /** @param args */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    PrefixTree tree = new PrefixTree();
    try {
      BufferedReader reader = new BufferedReader(new FileReader("company code.txt"));
      String line = reader.readLine();

      while (line != null) {
        StringTokenizer tokenizer = new StringTokenizer(line);
        String code = tokenizer.nextToken();
        tree.insert(code.toLowerCase() + "$");
        line = reader.readLine();
      }

      ArrayList<String> result = tree.search_prefix("a");
      for (int i = 0; i < result.size(); i++) {
        System.out.println(result.get(i));
      }

      reader.close();
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
    }
  }
Ejemplo n.º 19
0
  /**
   * Read all cineplex
   *
   * @return
   * @throws IOException
   */
  public static ArrayList<Cineplex> readCineplex() throws IOException {
    ArrayList stringArray = (ArrayList) read("data/cineplexes.txt");
    ArrayList alr = new ArrayList(); // to store data

    for (int i = 0; i < stringArray.size(); i++) {
      String st = (String) stringArray.get(i);
      // get individual 'fields' of the string separated by SEPARATOR
      StringTokenizer star = new StringTokenizer(st, SEPARATOR); // pass
      // in
      // the
      // string
      // to
      // the
      // string
      // tokenizer
      // using
      // delimiter
      // "|"

      int cineplexId = Integer.parseInt(star.nextToken().trim());
      String cineplexName = star.nextToken().trim();

      Cineplex u = new Cineplex(cineplexId, cineplexName);
      // add to list
      alr.add(u);
    }
    return alr;
  }
Ejemplo n.º 20
0
  public static String[] lineParse(String line) {
    StringTokenizer st = new StringTokenizer(line, ",", true);

    ArrayList<String> fieldList = new ArrayList<String>();
    String[] ss = new String[st.countTokens()];
    String preField = ",";
    for (int i = 0; i < ss.length; i++) {
      String field = st.nextToken();
      if (StringUtils.equals(preField, ",") && StringUtils.equals(field, ",")) {
        fieldList.add("");
        preField = field;
      } else if (StringUtils.equals(preField, ",") && !StringUtils.equals(field, ",")) {
        fieldList.add(field);
        preField = field;
      } else if (!StringUtils.equals(preField, ",") && StringUtils.equals(field, ",")) {
        preField = field;
        continue;
      }
    }
    if (StringUtils.equals(preField, ",")) {
      fieldList.add("");
    }

    return fieldList.toArray(new String[fieldList.size()]);
  }
Ejemplo n.º 21
0
  public static void main(String[] args) throws IOException, FileNotFoundException {
    FileReader file = new FileReader("chalice.in");
    BufferedReader reader = new BufferedReader(file);

    int cases =
        Integer.parseInt(reader.readLine()); // Input the number of cases and store it in cases
    for (int i = 0; i < cases; i++) { // Loop through all the cases
      int weight =
          Integer.parseInt(
              reader.readLine()); // Input the weight of the accused and store it in weight

      int geese =
          Integer.parseInt(reader.readLine()); // Input the number of geese and store it in geese
      int sum = 0; // Stores the total weight of the flock of geese
      StringTokenizer tokens =
          new StringTokenizer(
              reader.readLine()); // Read in the line with the weight of the geese and tokenize it
      for (int j = 0; j < geese; j++) { // Loop through all the geese
        sum +=
            Integer.parseInt(
                tokens.nextToken()); // Add the weight of one goose to the weight of the flock
      }

      System.out.print("Trial #" + (i + 1) + ": "); // Output trial number

      // Based on weight comparison output whether she is or isn't a witch
      if (weight <= sum) System.out.println("SHE'S A WITCH! BURN HER!");
      else System.out.println("She's not a witch. BURN HER ANYWAY!");
    }
  }
 protected void loadComponents(Bundle bundle, RuntimeContext ctx) throws Exception {
   String list = getComponentsList(bundle);
   String name = bundle.getSymbolicName();
   log.debug("Bundle: " + name + " components: " + list);
   if (list == null) {
     return;
   }
   StringTokenizer tok = new StringTokenizer(list, ", \t\n\r\f");
   while (tok.hasMoreTokens()) {
     String path = tok.nextToken();
     URL url = bundle.getEntry(path);
     log.debug("Loading component for: " + name + " path: " + path + " url: " + url);
     if (url != null) {
       try {
         ctx.deploy(url);
       } catch (Exception e) {
         // just log error to know where is the cause of the
         // exception
         log.error("Error deploying resource: " + url);
         Framework.handleDevError(e);
         throw e;
       }
     } else {
       String message = "Unknown component '" + path + "' referenced by bundle '" + name + "'";
       log.error(message + ". Check the MANIFEST.MF");
       Framework.handleDevError(null);
       warnings.add(message);
     }
   }
 }
Ejemplo n.º 23
0
  private Coordinates toCoordinates(Context ctx) {

    StringTokenizer st = new StringTokenizer((String) ctx.get(Context.FLD_OBJECT));
    double x = Double.parseDouble(st.nextToken());
    double y = Double.parseDouble(st.nextToken());
    return new Coordinates(x, y);
  }
Ejemplo n.º 24
0
  /** Saves to file. */
  private void saveFile() {
    String sep = System.getProperty("file.separator");

    try {
      File file = chooser.getSelectedFile();
      PrintWriter bfr = new PrintWriter(new FileWriter(file));

      StringTokenizer stok = new StringTokenizer(content.getText(), "\n\n");

      while (stok.hasMoreTokens()) {
        bfr.println(stok.nextToken());
      }

      bfr.flush();
      bfr.close();

    } catch (IOException ioe) {
      String msg = ioe.getMessage();
      JOptionPane.showMessageDialog(
          content,
          "An error occurred while saving data attributes. \nMessage: " + msg,
          "Error Saving data attributes",
          JOptionPane.WARNING_MESSAGE);
    }
  }
Ejemplo n.º 25
0
  public String nextToken() throws IOException {
    while (st == null || !st.hasMoreTokens()) {
      st = new StringTokenizer(br.readLine());
    }

    return st.nextToken();
  }
Ejemplo n.º 26
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());
      }
    }
Ejemplo n.º 27
0
  public void execute(Session session, String line, PrintStream out, PrintStream err) {
    // Parse command line.
    StringTokenizer st = new StringTokenizer(line, " ");

    // Ignore the command name.
    st.nextToken();

    // Check for optional argument.
    String property = null;
    if (st.countTokens() >= 1) {
      property = st.nextToken().trim();
    }

    try {
      if (session.getAttribute(Activator.CURRENT) == null) {
        throw new Exception("No configuration open currently");
      }
      Dictionary dict = (Dictionary) session.getAttribute(Activator.EDITED);
      if (dict == null) {
        Configuration cfg = (Configuration) session.getAttribute(Activator.CURRENT);
        dict = cfg.getProperties();
        session.setAttribute(Activator.EDITED, dict);
      }
      Object oldValue = dict.remove(property);
      if (oldValue == null) {
        throw new Exception("No property named " + property + " in current configuration.");
      }
    } catch (Exception e) {
      out.println("Unset failed. Details:");
      String reason = e.getMessage();
      out.println(reason == null ? "<unknown>: " + e.toString() : reason);
    }
  }
Ejemplo n.º 28
0
 /**
  * Given the parameters for copying doc-files, check for errors.
  *
  * @param configuration The configuration of the current doclet.
  * @param path The relative path to the directory to be copied.
  * @param dirName The original directory name to copy from.
  */
 private static boolean checkCopyDocFilesErrors(
     Configuration configuration, String path, String dirName) {
   if ((configuration.sourcepath == null || configuration.sourcepath.length() == 0)
       && (configuration.destDirName == null || configuration.destDirName.length() == 0)) {
     // The destination path and source path are definitely equal.
     return true;
   }
   File sourcePath, destPath = new File(configuration.destDirName);
   StringTokenizer pathTokens =
       new StringTokenizer(
           configuration.sourcepath == null ? "" : configuration.sourcepath, File.pathSeparator);
   // Check if the destination path is equal to the source path.  If yes,
   // do not copy doc-file directories.
   while (pathTokens.hasMoreTokens()) {
     sourcePath = new File(pathTokens.nextToken());
     if (destPath.equals(sourcePath)) {
       return true;
     }
   }
   // Make sure the doc-file being copied exists.
   File srcdir = new File(path + dirName);
   if (!srcdir.exists()) {
     return true;
   }
   return false;
 }
Ejemplo n.º 29
0
 private ccr.app.Coordinates toCoordinates(ccr.app.Context ctx) {
   java.util.StringTokenizer st =
       new java.util.StringTokenizer((java.lang.String) ctx.get(Context.FLD_OBJECT));
   double x = Double.parseDouble(st.nextToken());
   double y = Double.parseDouble(st.nextToken());
   return new ccr.app.Coordinates(x, y);
 }
Ejemplo n.º 30
0
  /**
   * Reads and stores the mime type setting corresponding to a file extension, by reading text from
   * an InputStream. If a mime type setting already exists when this method is run, the mime type
   * value is replaced with the newer one.
   *
   * @param is
   * @throws IOException
   */
  public void loadAndReplaceMimetypes(InputStream is) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String line = null;

    while ((line = br.readLine()) != null) {
      line = line.trim();

      if (line.startsWith("#") || line.length() == 0) {
        // Ignore comments and empty lines.
      } else {
        StringTokenizer st = new StringTokenizer(line, " \t");
        if (st.countTokens() > 1) {
          String mimetype = st.nextToken();
          while (st.hasMoreTokens()) {
            String extension = st.nextToken();
            extensionToMimetypeMap.put(extension, mimetype);
            if (log.isDebugEnabled()) {
              log.debug(
                  "Setting mime type for extension '" + extension + "' to '" + mimetype + "'");
            }
          }
        } else {
          if (log.isDebugEnabled()) {
            log.debug("Ignoring mimetype with no associated file extensions: '" + line + "'");
          }
        }
      }
    }
  }