Package net.bican.wordpress.configuration

Examples of net.bican.wordpress.configuration.WpCliConfiguration


      options.addOption("co", "commentoffset", true,
          "Comment offset # (for --getcomments)");
      options.addOption("cm", "commentnumber", true,
          "Comment # (for --getcomments)");
      try {
        WpCliConfiguration config = new WpCliConfiguration(args, options,
            Main.class);
        if (config.hasOption("help")) {
          showHelp(options);
        } else if ((!config.hasOption("url")) || (!config.hasOption("user"))
            || (!config.hasOption("pass"))) {
          System.err.println("Specify --user, --pass and --url");
        } else {
          try {
            Wordpress wp = new Wordpress(config.getOptionValue("user"),
                config.getOptionValue("pass"), config.getOptionValue("url"));
            if (config.hasOption("authors")) {
              printList(wp.getAuthors(), Author.class, true);
            } else if (config.hasOption("categories")) {
              printList(wp.getCategories(), Category.class, true);
            } else if (config.hasOption("deletecategory")) {
              Integer category_id = Integer.valueOf(config
                  .getOptionValue("deletecategory"));
              int r = wp.deleteCategory(category_id);
              System.out.println(r);
            } else if (config.hasOption("newcategory")) {
              String slug = config.getOptionValue("slug");
              Integer parentId = getInteger("parentid", config);
              if (slug == null)
                slug = "";
              if (parentId == null)
                parentId = 0;
              System.out.println(wp.newCategory(
                  config.getOptionValue("newcategory"), slug, parentId));
            } else if (config.hasOption("pages")) {
              printList(wp.getPages(), Page.class, false);
            } else if (config.hasOption("pagelist")) {
              printList(wp.getPageList(), PageDefinition.class, false);
            } else if (config.hasOption("page")) {
              printItem(wp.getPage(getInteger("page", config)), Page.class);
            } else if (config.hasOption("userinfo")) {
              printItem(wp.getUserInfo(), User.class);
            } else if (config.hasOption("recentposts")) {
              printList(wp.getRecentPosts(getInteger("recentposts", config)),
                  Page.class, false);
            } else if (config.hasOption("getpost")) {
              printItem(wp.getPost(getInteger("getpost", config)), Page.class);
            } else if (config.hasOption("supportedmethods")) {
              printList(wp.supportedMethods(), String.class, false);
            } else if (config.hasOption("supportedfilters")) {
              printList(wp.supportedTextFilters(), String.class, false);
            } else if (config.hasOption("newpage")) {
              if (!config.hasOption("publish")) {
                showHelp(options);
              } else {
                System.out.println(wp.newPage(
                    Page.fromFile(new File(config.getOptionValue("newpage"))),
                    config.getOptionValue("publish")));
              }
            } else if (config.hasOption("editpage")) {
              edit(options, config, wp, "editpage", true);
            } else if (config.hasOption("editpost")) {
              edit(options, config, wp, "editpost", false);
            } else if (config.hasOption("deletepage")) {
              delete(options, config, wp, "deletepage", true);
            } else if (config.hasOption("deletepost")) {
              delete(options, config, wp, "deletepost", false);
            } else if (config.hasOption("newpost")) {
              if (!config.hasOption("publish")) {
                showHelp(options);
              } else {
                System.out.println(wp.newPost(
                    Page.fromFile(new File(config.getOptionValue("newpost"))),
                    Boolean.valueOf(config.getOptionValue("publish"))));
              }
            } else if (config.hasOption("newmedia")) {
              String fileName = config.getOptionValue("newmedia");
              File file = new File(fileName);
              String mimeType = new MimetypesFileTypeMap().getContentType(file);
              Boolean overwrite = Boolean.FALSE;
              if (config.hasOption("overwrite"))
                overwrite = Boolean.TRUE;
              MediaObject result = wp.newMediaObject(mimeType, file, overwrite);
              if (result != null) {
                System.out.println(result);
              }
            } else if (config.hasOption("supportedstatus")) {
              System.out.println("Recognized status values for posts:");
              printList(wp.getPostStatusList(), PostAndPageStatus.class, true);
              System.out.println("\nRecognized status values for pages:");
              printList(wp.getPageStatusList(), PostAndPageStatus.class, true);
            } else if (config.hasOption("commentstatus")) {
              showCommentStatus(wp);
            } else if (config.hasOption("commentcount")) {
              showCommentCount(config, wp);
            } else if (config.hasOption("newcomment")) {
              editComment(wp, config.getOptionValue("newcomment"), "newcomment");
            } else if (config.hasOption("editcomment")) {
              editComment(wp, config.getOptionValue("editcomment"),
                  "editcomment");
            } else if (config.hasOption("deletecomment")) {
              System.err.println(Integer.valueOf(config
                  .getOptionValue("deletecomment")));
              deleteComment(wp,
                  Integer.valueOf(config.getOptionValue("deletecomment")));
            } else if (config.hasOption("getcomment")) {
              printComment(wp,
                  Integer.valueOf(config.getOptionValue("getcomment")));
            } else if (config.hasOption("getcomments")) {
              Integer postID = Integer.valueOf(config
                  .getOptionValue("getcomments"));
              String commentStatus = config.getOptionValue("commentstatus");
              Integer commentOffset;
              try {
                commentOffset = Integer.valueOf(config
                    .getOptionValue("commentoffset"));
              } catch (NumberFormatException e) {
                commentOffset = null;
              }
              Integer commentNumber;
              try {
                commentNumber = Integer.valueOf(config
                    .getOptionValue("commentnumber"));
              } catch (Exception e) {
                commentNumber = null;
              }
              printComments(wp, postID, commentStatus, commentOffset,
                  commentNumber);
            } else {
              showHelp(options);
            }
          } catch (MalformedURLException e) {
            System.err.println("URL \"" + config.getOptionValue("url")
                + "\" is invalid, reason is: " + e.getLocalizedMessage());
          } catch (IOException e) {
            System.err.println("Can't read from file, reason is: "
                + e.getLocalizedMessage());
          } catch (InvalidPostFormatException e) {
View Full Code Here

TOP

Related Classes of net.bican.wordpress.configuration.WpCliConfiguration

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.