How to retrieve posts from WordPress using Java

One way is to use the xml-rpc api. WordPress blogs have an xml-rpc API (which you need to enable on the WordPress blog under “Settings – Writing”. Since WordPress 3.5, XML-RPC is enabled by default). You will also need to create a user on the blog, which you give at least read access, and for which you include the credentials in your app. From then on, you can do xml-rpc calls to your WordPress blog(s).

Note that you can only use the xml-rpc api when you have a user with read access. If you do not have the credentials of a user with read access, you can’t get the posts using the xml-rpc api. Fetching the rss feed and parsing the rss feed with some java lib would probably be your best bet then check http://www.vogella.com/articles/RSSFeed/article.html on how to read an rss feed using Java.

Also, the official WordPress Android app is open source. Instructions to get it are at:http://android.wordpress.org/development/ You could use this source code as a starting point and adapt it to your needs.

Continue reading

How to Attach Java source files with Eclipse IDE

In Eclipse, go to Window -> Preferences -> Java -> Installed JREs -> Add and choose the JDK you have in your system.

Eclipse will now list the JARs found in the dialog box. There, select the rt.jar and choose Source Attachment. Select External location and click External File. Go to the folder were Java JDK is installed. There you’ll fine the src.zip file. Select it and click ok.

Counts the number of matching brackets in Java

    /**
     * Counts the number of matching brackets: {}.
     *
     * @param message the string to examine
     * @return the number of matching brackets
     */

    private int countBrackets(final String message) {
        boolean openBracket = false;
        int count = 0;
        for (final Character ch : message.toCharArray()) {
            if (openBracket == true && ch.equals('}')) {
                openBracket = false;
                count++;
            }
            if (ch.equals('{')) {
                openBracket = true;
            }
        }
        return count;
    }

Java Annotation

An annotation, in the Java computer programming language, is a form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and packages may be annotated. Unlike Javadoc tags, Java annotations can be reflective in that they can be embedded in class files generated by the compiler and may be retained by the Java VM to be made retrievable at run-time. It is possible to create meta-annotations out of the existing ones in Java. Example of Built-in annotations:
Continue reading