Tuesday, February 25, 2014

Creating a WebCenter Sites Custom Attribute Editor


Sometimes we want to simplify the process of uploading of images associated with assets in WebCenter Sites and the best way to do that is to use specialized editors. We can add brand new editors or we can customize existing out-of-the box editors. Let’s assume that we have an asset that represents a newspaper article in our asset we have a media attribute (an associated image). We want to provide a simpler way for an author to select and add a image for our article.

For that we will create a custom asset editor based on provided IMAGEPICKER.

An attribute editor asset is made up of an XML field that describe the widget it represents. We have a choice for the XML: we can upload an XML file or paste the content of attribute editor XML description into a text field.

In our XML we are specifying values for attributes of PRESENTATIONOBJECT  and IMAGEPICKER element. For the PRESENTATIONOBJECT NAME attribute we are using the name of our editor ”DemoCustomImagePicker” and for
IMAGEPICKER we have:

ASSETTYPENAME with value "Demo_M " is the name of asset type representing the image.
ATTRIBUTETYPENAME with value "Demo_A" is the name of the attribute type used in asset
ATTRIBUTENAME with the value "file" is the name of the attribute type instance representing the binary content.



Second, we have to provide the attribute type for which this editor is provided. We want to allow user to choose an asset (an image asset) so "asset" is selected in the Attribute Type list. 



We are using out-of-the-box IMAGEPICKER, so we don’t have to modify presentationobject.dtd file.

Next we associate the editor with an attribute, in our case with “associatedImage” attribute. We select from the drop-down list “Attribute Editor” our “DemoCustomImagePicker” and save the updated object.



We can test now the editor by editing an asset of type DemoArticle. If we click on the “Browse” button a list of images is displayed and we can drag and drop an image in our Associated Image field. A thumbnail version of the image in media asset “file” attribute is also displayed.







Wednesday, February 5, 2014

Playing Around with WebLogic Maven Plug-In

Packaged with WebLogic 12c wls-maven-plugin let’s you install, start and stop servers, create domain, execute WLST scripts, compile and deploy applications. The plug-in works with Maven 2.x and 3.x.
WebLogic 12c can be downloaded from http://www.oracle.com/technetwork/index.html. Developers version has around  180MB (zip archive).  To install the plugin we need first to extract wls-maven-plugin.jar.pack and pom.xml

$unzip ~/Downloads/wls1212_dev.zip wls12120/wlserver/server/lib/wls-maven-plugin.jar.pack

$unzip ~/Downloads/wls1212_dev.zip wls12120/wlserver/server/lib/pom.xml

Now, let’s unpack the jar file:

$unpack200 -r wls12120/wlserver/server/lib/wls-maven-plugin.jar.pack wls12120/wlserver/server/lib/wls-maven-plugin.jar

Install the plug-in in the local repository

$cd wls12120/wlserver/server/lib/

$mvn install
  
$mvn install:install-file –Dfile=wls-maven-plugin.jar –DpomFile=pom.xml


Modify global or user settings.xml to add the plug-in group id to the default groups. You can find the location of settings.xml by running:

$mvn –X | grep settings


Usually, user settings are located in ~/.m2/settings.xml. For the global configuration file look in the Maven installation directory. For example: ~/apache-maven-3.1.1/conf/ directory/settings.xml.

Add the following lines:

<pluginGroups>
    <pluginGroup>com.oracle.weblogic</pluginGroup>
</pluginGroups>

Launch installation of WebLogic Server:

$mvn wls:install -DartifactLocation=/Users/<your_user_name>/Downloads/wls1212_dev.zip


Set JVM Settings for the WebLogic domain that will be created. This is necessary especially for 64bit JVMs. These settings are modifying the size of initial heap size, max heap size and, very important, perm gen space. You can do that by setting USER_MEM_ARGS environment variable before starting the server:

$export USER_MEM_ARGS="-Xms256m -Xmx=512m -XX:CompileThreshold=800 -XX:PermSize=128m -XX:MaxPermSize=256m"


Create domain:
$mvn wls:create-domain -DdomainHome=./Domains/domain1 -DmiddlewareHome=./Software/wls12120 -Duser=weblogic -Dpassword=welcome1


Start server:
$mvn wls:start-server  -DdomainHome=./Domains/domain1 -DmiddlewareHome=./Software/wls12120

You can stop the server by running:
$mvn wls:stop-server -DdomainHome=./Domains/domain1 -DmiddlewareHome=./Software/wls12120 -Duser=weblogic -Dpassword=welcome1


Let’s create now a JaveEE application and deploy it to the newly created domain. For the application we will use Maven arhchetypes. First the root POM (Project Object Model):

$mvn archetype:generate -Dversion=1.0-SNAPSHOT -DgroupId=com.flaviussana.demo -DartifactId=DemoApp -DarchetypeArtifactId=pom-root -DarchetypeGroupId=org.codehaus.mojo.archetypes

In the DemoApp directory created run to generate the EAR project:

$mvn archetype:generate -Dversion=1.0-SNAPSHOT -DgroupId=com.flaviussana.demo -DartifactId=DemoApp-EAR -DarchetypeArtifactId=ear-javaee6 -DarchetypeGroupId=org.codehaus.mojo.archetypes


Create an EJB mode and a WebApp module:

$mvn archetype:generate -Dversion=1.0-SNAPSHOT -DgroupId=com.flaviussana.demo -DartifactId=DemoApp-EJB -DarchetypeArtifactId=ejb-javaee6 -DarchetypeGroupId=org.codehaus.mojo.archetypes

$mvn archetype:generate -Dversion=1.0-SNAPSHOT -DgroupId=com.flaviussana.demo -DartifactId=DemoApp-WAR -DarchetypeArtifactId=webapp-javaee6 -DarchetypeGroupId=org.codehaus.mojo.archetypes

Set the dependencies in EAR pom.xml:
 <dependencies>
   <dependency>
     <groupId>${project.groupId}</groupId>
     <artifactId>${project.parent.artifactId}-EJB</artifactId>
     <version>${project.version}</version>
     <type>ejb</type>
   </dependency>
   <dependency>
     <groupId>${project.groupId}</groupId>
     <artifactId>${project.parent.artifactId}-WAR</artifactId>
     <version>${project.version}</version>
     <type>war</type>
   </dependency>
</dependencies>


Create a simple EJB Bean:HelloWorldEJB

package com.flaviussana.demo;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

/**
 * Session Bean implementation class HelloWorldEJB
 */
@Stateless
@LocalBean
public class HelloWorldEJB {

    /**
     * Default constructor.
     */
    public HelloWorldEJB() {
        // TODO Auto-generated constructor stub
    }
   
    public String sayHello(String name) {
       return "Hello " + name + "!";
    }

}

Build the application by running “mvn install” in parent project directory then deploy the application by running in DemoApp-EAR:

$mvn wls:deploy -Dname=DemoApp-EAR -DmiddlewareHome=/Users/<your_user_name>/tmp/Oracle/Software/wls12120 -DdomainHome=/Users/<your_user_name>/tmp/Oracle/Domains/domain1


Test the application by going to:



Another interesting feature of the WebLogic Maven plugin is the “wlst” goal that can be used to execute WLST (WebLogic Scripting Tool) scripts. For example you can run to create resources like DataSources or queues:


$mvn wls:wlst –Duser=weblogic –Dpassword=welcome1 –Dfilename=create-resource.py

Thursday, November 28, 2013

Rendering a BLOB Attribute in a Template

There are at least two ways for rendering a BLOB attribute. First, and used quite a lot, implies using WebCenter Sites Asset API and scriptlets added in the JSP page. Second method uses a couple of JSP tags and provides a more elegant solution to the problem of rendering BLOB attributes.

In the following example I am using an asset of type DMedia_C with a blob attribute named "file".


Example:


<%--Load the current image (media) asset --%>
<assetset:setasset name="currentImage" type='<%=ics.GetVar("c") %>' id='<%=ics.GetVar("cid") %>'/>

<%--Get the file attribute - the blob that we want to display  --%>
<assetset:getattributevalues name="currentImage" listvarname="fileList" attribute="file" typename="DContent_A"/>

<blobservice:gettablename varname="blobTable"/>
<blobservice:getidcolumn varname="idColumn"/>
<blobservice:geturlcolumn varname="dataColumn"/>

<render:getbloburl outstr="imageUrl"
blobtable='<%=ics.GetVar("blobTable") %>'
blobcol='<%=ics.GetVar("dataColumn") %>'
blobkey='<%=ics.GetVar("idColumn") %>'
blobwhere='<%=ics.GetList("fileList").getValue("value") %>'/>


<img src='<render:stream variable="imageUrl"/>'/>


Don't forget to add the used tags definition to the page:

<%@ taglib prefix="blobservice" uri="futuretense_cs/blobservice.tld" %>

Friday, November 15, 2013

Starting Oracle WebCenter Sites JSK 11.1.1.8.0 on Mac OS X Maverick

I wanted to install the latest version of Oracle WebCenter Sites JSK (11.1.1.8) on my MacBook Pro with OS X Maverick but I ran into a couple of problems. First during the installation process the installer complained twice that the DISPLAY variable is not set but if you ignore the message and click continue, the installation is completed successfully. Second, the JSK was not starting. This is the solution that I found for making Oracle WebCenter Sites JSK work on Mac OS X

The default location for the installation is:

/Users/<myusername>/Library/Oracle/JSK/11.1.1.8.0.app

A double-click on the application will not start it but with slight modifications of run.sh script the Jump Start Kit can be started.

First set the DISPLAY variable. In my case I set it to:

DISPLAY=":0"

Second, set JAVA_HOME. JAVA_HOME is set to:

JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home"

And third, tools.jar. Even with the CurrentJDK set I still get a warning that I am using a JRE instead of a JDK and the jumpstart kit is not starting.



This problem can be solved by examining the log file. In the logfile.out from the jumpstart directory I see that the problem is caused by missing tools.jar from classpath. I know that I have tools.jar in $JAVA_HOME/lib so the simplest solution is adding a classpath entry for tools.jar in the startup script. There are two lines in the run.sh that are starting the JSK. One that is starting it with arguments and the other one without any parameters. So, I added in the classpath:

$JAVA_HOME/lib/tools.jar 

and the run.sh starts JSK now.


Now, this is my solution and I know that is not the best one. If you find other solutions for this problem please let me know!