Package se.rupy.sprout

Examples of se.rupy.sprout.Node


        File file = new File();
        Item item = new Item();
        item.path = "file";
        item = save(event, item);

        Node article = article(event, file, item);
        Sprout.redirect(event, "/");
        //Sprout.redirect(event, "/edit?id=" + article.getId());
      }
    }
View Full Code Here


  static Node article(Event event, Node file, Item item) throws Exception {
    Object key = event.session().get("key");
    Article article = Article.get(key);
    String name = File.name(item.name);
    Node old = article.child(FILE, FILE_NAME, name);

    if(old != null) {
      file = old;
      file.setDate(System.currentTimeMillis());
      Article.invalidate(article);
View Full Code Here

          if(article.permit(key) == Article.NO) {
            throw new Exception(Sprout.i18n("You are not authorized!"));
          }
         
          int type = cid > 0 ? COMMENT : PING;
          Node node = article.child(cid > 0 ? cid : pid);
         
          if(event.query().path().equals("/hide")) {
            node.add(Data.cache(type, "HIDE"));
          }
          else {
            node.add(Data.cache(type, "SHOW"));
          }

          //comment.update();
         
          Article.invalidate(article);
View Full Code Here

    if(user == null) {
      return NO;
    }

    try {
      Node node = (Node) child(USER).getFirst();

      if(user.getId() == node.getId()) {
        return USER;
      }
    }
    catch(NoSuchElementException e) {}
View Full Code Here

  int count(int type, short state) throws SQLException {
    Iterator it = child(type).iterator();
    int count = 0;

    while(it.hasNext()) {
      Node node = (Node) it.next();
      Data data = node.meta(state);

      if(data != null && data.getString().equals("SHOW")) {
        count++;
      }
    }
View Full Code Here

    }

    Iterator it = children.iterator();

    while(it.hasNext()) {
      Node child = (Node) it.next();

      switch(child.getType()) {
      case USER: {
        padding(buffer, level + 1);
        buffer.append("<user>" + child.safe(USER_NAME) + "</user>\n");
      } break;
      case COMMENT: {
        Data state = child.meta(COMMENT_STATE);
        boolean show = (state == null ? false : state.getString().equals("SHOW"));
        if(show) {
          Data from = child.meta(COMMENT_IP);

          if(from == null) {
            try {
              from = ((Node) child.child(USER).getFirst()).meta(USER_NAME);
            }
            catch(SQLException e) {
              e.printStackTrace();
            }
          }

          padding(buffer, level + 1);
          buffer.append("<post>\n");
          padding(buffer, level + 2);
          buffer.append("<body>" + child.safe(COMMENT_BODY) + "</body>\n");
          padding(buffer, level + 2);
          buffer.append("<from>" + from.getString() + "</from>\n");
          padding(buffer, level + 2);
          buffer.append("<date>" + child.getDate() + "</date>\n");
          padding(buffer, level + 1);
          buffer.append("</post>\n");
        }
      } break;
      case FILE: {
        padding(buffer, level + 1);
        buffer.append("<file>\n");
        padding(buffer, level + 2);
        buffer.append("<type>" + child.safe(FILE_TYPE) + "</type>\n");
        padding(buffer, level + 2);
        buffer.append("<path>file" + child.path() + "/" + Sprout.clean(child.safe(FILE_NAME)) + "</path>\n");
        padding(buffer, level + 1);
        buffer.append("</file>\n");
      } break;
      case PING: {
        Data state = child.meta(PING_STATE);
        boolean show = (state == null ? false : state.getString().equals("SHOW"));
        if(show) {
          padding(buffer, level + 1);
          buffer.append("<ping>" + Sprout.clean(child.safe(PING_URL)) + "</ping>\n");
        }
      } break;
      }
    }
View Full Code Here

        if(article != null) {
          Iterator it = article.child(PING).iterator();
          boolean found = false;

          while(it.hasNext()) {
            Node ping = (Node) it.next();

            if(ping.meta(PING_URL).getString().equals(from)) {
              found = true;
              System.out.println("Pingback '" + ping.meta(PING_TITLE).getString() + "' allready added!");
              break;
            }
          }

          if(!found) {
            HttpURLConnection conn = (HttpURLConnection) new URL(from).openConnection();
            conn.setRequestMethod("GET");
            int code = conn.getResponseCode();

            if(code == 200) {
              Deploy.pipe(conn.getInputStream(), out);
            } else {
              System.out.println("Code: " + code);
            }

            body = new String(out.toByteArray(), "UTF-8");
            String title = find("title", body);

            if(title.length() > 0 && body.indexOf(to) > -1) {
              Ping ping = new Ping();
              ping.add(PING_TITLE, title);
              ping.add(PING_URL, from);
              ping.add(Data.cache(PING, "SHOW"));
              article.add(ping);

              System.out.println("Pingback '" + title + "' added!");
            }
            else {
View Full Code Here

TOP

Related Classes of se.rupy.sprout.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.