Sitemap

Sunday, July 12, 2015

Generating a Java thread dump

On Windows
https://access.redhat.com/solutions/19170

On Linux
https://access.redhat.com/solutions/18178

Wednesday, July 8, 2015

UCM: Standard Services

checkSecurity
• Takes none or one parameter. If a parameter is given, it will be the name of a ResultSet. The method checks if the logged in user has the appropriate security as specified in the access level of the service to perform the specified action. It checks the security against a specific security group and account (if accounts are enabled) as specified by a revision. This method is used for validating security for actions on a particular content item, e.g. check in, check out, delete, etc.

createResultSetSQL
• Takes no parameters. Given a dataSource, whereClause (as set in local data), the method looks up the data source in the DataSources table and executes the query with the additional where clause. The method will append additional security clauses to any query referencing the Workflow and Revisions table. The environment value MaxQueryRows determines the cut off point for the number of rows returned. The results of the query are placed in the data with the name as specified by the resultName (as set in local data).

doSubService
• Takes one parameter. Given the name of a sub service, will execute it.

loadDefaultInfo
• Takes no parameters. The method will first execute the loadDefaultInfo filter. It then loads environment information, types, formats and accounts. Used for creating check-in and update pages.

loadMetaOptionsLists
• Takes no parameters. The method will first execute the filter loadMetaOptionsLists. It then proceeds to load all options list as referred to in the DocMetaDefinition table.

loadSharedTable
• Takes two parameters. The first parameter is the name of the table to look up in the server's cached tables. The second is the name the table will be given when added to the data. Use this method instead of executing a query, when the data is already cached in the server. This method is primarily used to make a server-cached table available for a template.

loadSharedTableRow
• Takes two parameters. The first parameter is the name of the table to look up in the server's cached tables. The second parameter is an argument specifying a column in the database and a lookup key into the request data. The value for the key in the request data is used to find the row in the cached table. The values of the row are mapped to the local data using the names of the columns as keys. One usage for this function is to retrieve cached information about a specific user.

mapResultSet
• Takes at least three parameters. The first parameter is the name of a select query; the parameters that follow must appear in pairs. The first member of the pair is the column name; the second member is the key that is used to put the row value into local data. The method will execute the specified query and map the specified columns of the first row of the ResultSet to the local data. Use this method in replacement of a Type 5 action, if the service only requires a part of the first row of a ResultSet to be stored.

refreshCache
• Given a list of subjects, this method will do a refresh on each specified subject.

renameValues
• Takes multiple parameters that must appear in pairs. The pairs are made up of two keys. The first key is used to look up a value in the data. The second key is used to store the found value in the local data. If the value is not found, an exception is thrown and the service will abort with an error message.

setConditionVars
• Given a list of condition variables, this method will set them all to true. These values can only be tested in HTML template pages. They are not put into local data.

setLocalValues
• Takes multiple parameters that must appear in name/value pairs. The name/value pairs are placed into the local data.

Sunday, July 5, 2015

Java: Links and Resources

http://www.kodejava.org/

http://esus.com/

http://mindprod.com/jgloss/jgloss.html

http://rosettacode.org/wiki/Category:Java



http://www.leveluplunch.com/java/tutorials/
http://www.java-examples.com/
http://www.java2novice.com/java-collections-and-util/hashmap/
http://kodehelp.com/category/javaj2ee/java7api/java-io/

Java RunTime Environment was not found. Oracle Universal Installer cannot be run



I was having some trouble while uninstalling the Oracle_ECM1 from my Windows system. In such a case, we need to use the command prompt and pass -jreLoc parameter as follows:

C:\Users\sonal_chaudhary>cd C:\Oracle\Oracle_ECM1\oui\bin\
C:\Oracle\Oracle_ECM1\oui\bin>setup.exe -deinstall -ignoreSysPrereqs -jreLoc C:\Java\jre7


Thursday, June 25, 2015

Java: Input and Output streams

java.io package provides I/O classes to manipulate streams. This package supports two types of streams:
1. binary streams which handle binary data. InputStream and OutputStream are high level interfaces for manipulating binary streams.
2. character streams which handle character data. Reader and Writer are high level interfaces for manipulating character streams. In this section, the main focus is on binary streams.

By default, most of the streams read or write one byte at a time. This causes poor I/O performance because it takes lot of time to read/write byte by byte when dealing with large amounts of data. I/O provides Buffered streams to override this byte by byte default behaviors.



import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {

    private static final String SOURCE_FILE = "D:\\test.jar";

    public static void main(String[] args) {
        Main io = new Main();
        try {
            long startTime = System.currentTimeMillis();
            io.readWrite(SOURCE_FILE, "D:\\test1.jar");
            long endTime = System.currentTimeMillis();
            System.out.println("Time taken for reading and writing using default behaviour : " + (endTime - startTime) +
                               " milli seconds");

            long startTime1 = System.currentTimeMillis();
            io.readWriteBuffer(SOURCE_FILE, "D:\\test2.jar");
            long endTime1 = System.currentTimeMillis();
            System.out.println("Time taken for reading and writing using buffered streams : " +
                               (endTime1 - startTime1) + " milli seconds");

            long startTime2 = System.currentTimeMillis();
            io.readWriteArray(SOURCE_FILE, "D:\\test3.jar");
            long endTime2 = System.currentTimeMillis();
            System.out.println("Time taken for reading and writing using custom buffering : " +
                               (endTime2 - startTime2) + " milli seconds");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void readWrite(String fileFrom, String fileTo) throws IOException {
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(fileFrom);
            out = new FileOutputStream(fileTo);
            while (true) {
                int bytedata = in.read();
                if (bytedata == -1)
                    break;
                out.write(bytedata);
            }
        } finally {
            if (in != null)
                in.close();
            if (out != null)
                out.close();
        }
    }

    public static void readWriteBuffer(String fileFrom, String fileTo) throws IOException {
        InputStream inBuffer = null;
        OutputStream outBuffer = null;
        try {
            InputStream in = new FileInputStream(fileFrom);
            inBuffer = new BufferedInputStream(in);
            OutputStream out = new FileOutputStream(fileTo);
            outBuffer = new BufferedOutputStream(out);
            while (true) {
                int bytedata = inBuffer.read();
                if (bytedata == -1)
                    break;
                out.write(bytedata);
            }
        } finally {
            if (inBuffer != null)
                inBuffer.close();
            if (outBuffer != null)
                outBuffer.close();
        }
    }

    public static void readWriteArray(String fileFrom, String fileTo) throws IOException {
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(fileFrom);
            out = new FileOutputStream(fileTo);
            int availableLength = in.available();
            byte[] totalBytes = new byte[availableLength];
            int bytedata = in.read(totalBytes);
            out.write(totalBytes);

        } finally {
            if (in != null)
                in.close();
            if (out != null)
                out.close();
        }
    }
}


OUTPUT
Time taken for reading and writing using default behaviour : 5188 milli seconds
Time taken for reading and writing using buffered streams : 3105 milli seconds
Time taken for reading and writing using custom buffering : 7 milli seconds

Java: Properties Class

A Properties object is a persistent Hashtable that stores key–value pairs of Strings. By "persistent", we mean that the Properties object can be written to an output stream (possibly a file) and read back in through an input stream. A common use of Properties objects in prior versions of Java was to maintain application-configuration data or user preferences for applications.

import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;

import java.util.Properties;
import java.util.Set;

public class PropertiesTest {
    public static void main(String[] args) {
        Properties table = new Properties();

        // set properties
        table.setProperty("color", "blue");
        table.setProperty("width", "200");

        System.out.println("After setting properties");
        listProperties(table);

        // replace property value
        table.setProperty("color", "red");

        System.out.println("After replacing properties");
        listProperties(table);

        saveProperties(table);

        table.clear(); // empty table

        System.out.println("After clearing properties");
        listProperties(table);

        loadProperties(table);

        // get value of property color
        Object value = table.getProperty("color");

        // check if value is in table
        if (value != null)
            System.out.printf("Property color's value is %s%n", value);
        else
            System.out.println("Property color is not in table");
    }

    // save properties to a file

    private static void saveProperties(Properties props) {
        // save contents of table
        try {
            FileOutputStream output = new FileOutputStream("props.dat");
            props.store(output, "Sample Properties"); // save properties
            output.close();
            System.out.println("After saving properties");
            listProperties(props);
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
    }

    // load properties from a file

    private static void loadProperties(Properties props) {
        // load contents of table
        try {
            FileInputStream input = new FileInputStream("props.dat");
            props.load(input); // load properties
            input.close();
            System.out.println("After loading properties");
            listProperties(props);
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
    }

    // output property values

    private static void listProperties(Properties props) {
        Set<object> keys = props.keySet(); // get property names

        // output name/value pairs
        for (Object key : keys)
            System.out.printf("%s\t%s%n", key, props.getProperty((String)key));

        System.out.println();
    }
}


OUTPUT
After setting properties
color blue
width 200

After replacing properties
color red
width 200

After saving properties
color red
width 200

After clearing properties

After loading properties
color red
width 200

Property color's value is red


Java: Apache Ant

build.properties
src.dir=src
classes.dir=classes
main-class=com.mypkg.PortfolioManager
lib.dir=lib
docs.dir=docs
projectName=AntTutorial

build.xml
<?xml version="1.0" encoding="windows-1252" ?>
<!--Ant buildfile generated by Oracle JDeveloper-->
<!--Generated Apr 20, 2015 4:09:46 PM-->
<project xmlns="antlib:org.apache.tools.ant" name="Project" default="all" basedir=".">
  <property file="build.properties"/>

  <target name="clean">
    <delete dir="${classes.dir}"/>
    <delete dir="${docs.dir}"/>
  </target>

  <target name="init">
    <mkdir dir="${classes.dir}"/>
    <!--<mkdir dir="${docs.dir}"/>-->
  </target>

  <path id="classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
  </path>

  <target name="compile" depends="init">
    <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
  </target>

  <!--<target name="docs" depends="compile">
    <javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
       <fileset dir="${src.dir}">
                <include name="**" />
           </fileset>
    </javadoc>
  </target>-->

  <target name="jar" depends="compile">
    <jar destfile="${projectName}.jar" basedir="${classes.dir}">
      <manifest>
        <attribute name="Main-Class" value="${main-class}"/>
      </manifest>
    </jar>
  </target>

  <target name="main" depends="clean,compile,jar"/>
</project>

Download the sample project from the file cabinet: AntTut.zip
More Info: http://www.tutorialspoint.com/ant/index.htm