Exemplo n.º 1
0
 private static void tryResUrls(Picture picture) {
   String hi_res = "";
   String url = picture.media_url.toString();
   for (String ending : Main.endings) {
     try {
       hi_res = url.replace(url.substring(url.lastIndexOf("_"), url.lastIndexOf(".")), ending);
       URL hi_url = new URL(hi_res);
       File hi_name = Helper.extractMediaFileNameFromURL(hi_url);
       if (hi_name.equals(picture.media_name)) {
         picture.hi_url = hi_url;
         picture.hi_name = hi_name;
         picture.downloaded_hi = true;
         break;
       } else {
         boolean success = Helper.downloadFileFromURLToFileInTemp(hi_url, hi_name);
         if (success) {
           picture.hi_url = hi_url;
           picture.hi_name = hi_name;
           picture.downloaded_hi = true;
           Helper.moveTempImageToStore(hi_name, new File(Main.blogdir, picture.md5_id));
           break;
         }
       }
     } catch (MalformedURLException ex) {
       Main.error(String.format("Attempted hi res url %s is a malformed URL.", hi_res));
     }
   }
 }
Exemplo n.º 2
0
 protected static void reset() {
   Helper.removeDirectoryIfItExists(Helper.temp);
   Helper.removeDirectoryIfItExists(blogdir);
   Main.post_post_hash.clear();
   Main.pic_pic_hash.clear();
   Main.pic_post_hash.clear();
   Main.dup_post_list.clear();
 }
Exemplo n.º 3
0
  private static void PlayFakeGame() {
    Game game = new Game();
    game.add("Andreas");
    game.add("Kjersti");
    game.add("Kim");

    boolean gameIsRunning = true;

    while (gameIsRunning) {
      game.roll(_helper.throwDice());

      if (_helper.answer()) gameIsRunning = game.wasCorrectlyAnswered();
      else gameIsRunning = game.wrongAnswer();
    }
    System.out.println("-------------------");
  }
  /** INTERNAL: */
  public String toString() {
    StringWriter writer = new StringWriter();
    writer.write(Helper.getShortClassName(getClass()));
    writer.write("(");

    for (int index = 0; index < getFields().size(); index++) {
      writer.write(Helper.cr());
      writer.write("\t");
      writer.write(String.valueOf((getFields().elementAt(index))));
      writer.write(" => ");
      writer.write(String.valueOf((getValues().elementAt(index))));
    }
    writer.write(")");

    return writer.toString();
  }
 /** Return the string for logging purposes. */
 public String getLogString(Accessor accessor) {
   StringWriter writer = new StringWriter();
   writer.write("Executing ");
   writer.write(toString());
   writer.write(Helper.cr());
   writer.write("\tspec => ");
   writer.write(String.valueOf(getInteractionSpec()));
   writer.write(Helper.cr());
   writer.write("\tproperties => ");
   writer.write(String.valueOf(getProperties()));
   writer.write(Helper.cr());
   writer.write("\txml => ");
   Element dom = createInputDOM((EISAccessor) accessor);
   EISDOMRecord record = new EISDOMRecord(dom);
   record.transformToWriter(writer);
   return writer.toString();
 }
Exemplo n.º 6
0
 public static void save() {
   Main.status("Saving databases.");
   File file = new File(blogdir, "picpic.db");
   List<Object> objects = new ArrayList<>();
   objects.add(Main.post_post_hash);
   Helper.saveObjectToFile(file, objects);
   Main.status("Done saving databases.");
 }
Exemplo n.º 7
0
 public String toString() {
   StringWriter writer = new StringWriter();
   writer.write(Helper.getShortClassName(getClass()));
   writer.write("(");
   writer.write(getValue().toString());
   writer.write(")");
   return writer.toString();
 }
Exemplo n.º 8
0
 private static void handlePost(Post post) {
   Main.post_post_hash.put(post, post);
   for (Picture picture : post.pictures) {
     Helper.downloadFileFromURLToFileInTemp(picture.thumb_url, picture.thumb_name);
     picture.md5_id = Helper.createMD5FromFileInTemp(picture.thumb_name);
     Helper.moveTempImageToStore(picture.thumb_name, new File(Main.blogdir, picture.md5_id));
     if (!Main.pic_pic_hash.containsKey(picture)) {
       Main.pic_pic_hash.put(picture, picture);
       Main.pic_post_hash.put(picture, post);
       Helper.downloadFileFromURLToFileInTemp(picture.media_url, picture.media_name);
       Helper.moveTempImageToStore(picture.media_name, new File(Main.blogdir, picture.md5_id));
     } else {
       if (!post.equals(Main.pic_post_hash.get(picture))) {
         dup_post_list.put(post, Main.pic_post_hash.get(picture));
       }
     }
   }
 }
 public String toString() {
   if (isInstantiated()) {
     return "{" + getValue() + "}";
   } else {
     return "{"
         + Helper.getShortClassName(getClass())
         + ": "
         + ToStringLocalization.buildMessage("not_instantiated", (Object[]) null)
         + "}";
   }
 }
Exemplo n.º 10
0
 public static void main(String[] args) throws Exception {
   ScriptEngineManager manager = new ScriptEngineManager();
   ScriptEngine jsengine = Helper.getJsEngine(manager);
   if (jsengine == null) {
     System.out.println("Warning: No js engine found; test vacuously passes.");
     return;
   }
   String langVersion = jsengine.getFactory().getLanguageVersion();
   if (!langVersion.equals(JS_LANG_VERSION)) {
     throw new RuntimeException("Expected JavaScript version is " + JS_LANG_VERSION);
   }
   String engineVersion = jsengine.getFactory().getEngineVersion();
   if (!engineVersion.equals(JS_ENGINE_VERSION)) {
     throw new RuntimeException("Expected Rhino version is " + JS_ENGINE_VERSION);
   }
 }
Exemplo n.º 11
0
 public static void load() {
   Main.status("Loading databases.");
   File file = new File(blogdir, "picpic.db");
   List<Object> objects = Helper.loadObjectFromFile(file);
   if (objects == null || objects.size() != 1) {
     Main.error("Unable to load database files so creating new database.");
     reset();
   } else {
     Main.post_post_hash = (HashMap<Post, Post>) objects.get(0);
     Main.pic_pic_hash.clear();
     Main.pic_post_hash.clear();
     Main.dup_post_list.clear();
     Main.setupPosts();
   }
   Main.status("Done loading databases.");
 }
Exemplo n.º 12
0
 public static void main(String[] args) throws Exception {
   System.out.println("\nTest7\n");
   File file = new File(System.getProperty("test.src", "."), "Test7.js");
   Reader r = new FileReader(file);
   ScriptEngineManager m = new ScriptEngineManager();
   ScriptEngine eng = Helper.getJsEngine(m);
   if (eng == null) {
     System.out.println("Warning: No js engine found; test vacuously passes.");
     return;
   }
   eng.put("filename", file.getAbsolutePath());
   eng.eval(r);
   String str = (String) eng.get("firstLine");
   // do not change first line in Test7.js -- we check it here!
   if (!str.equals("//this is the first line of Test7.js")) {
     throw new RuntimeException("unexpected first line");
   }
 }
Exemplo n.º 13
0
 /** PUBLIC: Print all of the connection information. */
 public String toString() {
   StringWriter stringWriter = new StringWriter();
   PrintWriter writer = new PrintWriter(stringWriter);
   writer.write(Helper.getShortClassName(getClass()));
   writer.println("(");
   writer.println(
       "\t"
           + ToStringLocalization.buildMessage("platform", (Object[]) null)
           + "=> "
           + getDatasourcePlatform());
   if (!shouldUseExternalConnectionPooling()) {
     writer.println(
         "\t"
             + ToStringLocalization.buildMessage("user_name", (Object[]) null)
             + "=> \""
             + getUserName()
             + "\"");
   }
   writer.print("\t");
   getConnector().toString(writer);
   writer.write(")");
   return stringWriter.toString();
 }
  public String find() {

    String back = "";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Connection con = Helper.getConnection();
    String qq =
        "select r.id,r.asset_id,r.asset_num,r.type,  "
            + " date_format(date,'%m/%d/%Y'),r.location_id,r.weight,r.description "
            + " from recycled_items r ";
    String qw = "";
    if (con == null) {
      back = "Could not connect to DB";
      addError(back);
      return back;
    }
    try {
      if (!location_id.equals("")) {
        if (!qw.equals("")) qw += " and ";
        qw += " r.location_id = ? ";
      }
      if (!asset_id.equals("")) {
        if (!qw.equals("")) qw += " and ";
        qw += " r.asset_id = ? ";
      }
      if (!type.equals("")) {
        if (!qw.equals("")) qw += " and ";
        qw += " r.type = ? ";
      }
      if (!date_from.equals("")) {
        if (!qw.equals("")) qw += " and ";
        qw += " r.date >= str_to_date('" + date_from + "','%m/%d/%Y')";
      }
      if (!date_to.equals("")) {
        if (!qw.equals("")) qw += " and ";
        qw += " r.date <= str_to_date('" + date_to + "','%m/%d/%Y')";
      }
      if (!qw.equals("")) {
        qq = qq + " where " + qw;
      }
      qq = qq + " order by r.date DESC " + limit;
      if (debug) {
        logger.debug(qq);
      }
      pstmt = con.prepareStatement(qq);
      int jj = 1;
      if (!location_id.equals("")) {
        pstmt.setString(jj++, location_id);
      }
      if (!asset_id.equals("")) {
        pstmt.setString(jj++, asset_id);
      }
      if (!type.equals("")) {
        pstmt.setString(jj++, type);
      }
      rs = pstmt.executeQuery();
      while (rs.next()) {
        if (recycledItems == null) recycledItems = new ArrayList<RecycledItem>();
        RecycledItem one =
            new RecycledItem(
                debug,
                rs.getString(1),
                rs.getString(2),
                rs.getString(3),
                rs.getString(4),
                rs.getString(5),
                rs.getString(6),
                rs.getString(7),
                rs.getString(8));
        recycledItems.add(one);
      }
    } catch (Exception ex) {
      back += ex + " : " + qq;
      logger.error(back);
      addError(back);
    } finally {
      Helper.databaseDisconnect(con, pstmt, rs);
    }
    return back;
  }
 public String toString() {
   return Helper.getShortClassName(getClass()) + "(" + getFullName() + ")";
 }