grokking the paradigm creating a component

30
006 EMC Corporation. All rights reserved. Grokking the Paradigm Creating a Component Dennis Dawson Principal Technical Writer EMC/Documentum

Upload: charity-mccarty

Post on 03-Jan-2016

36 views

Category:

Documents


3 download

DESCRIPTION

Grokking the Paradigm Creating a Component. Dennis Dawson Principal Technical Writer EMC/Documentum. Creating a Custom Component Lay out the UI Create Java behavior classes Create configuration files. Fifteen Minutes’ Worth of Stuff. Creating a Component. Components are composed of - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Grokking the Paradigm Creating a Component

© 2006 EMC Corporation. All rights reserved.

Grokking the ParadigmCreating a ComponentDennis Dawson

Principal Technical Writer

EMC/Documentum

Page 2: Grokking the Paradigm Creating a Component

Grokking the Paradigm 2© 2006 EMC Corporation. All rights reserved.

Fifteen Minutes’ Worth of Stuff

• Creating a Custom Component– Lay out the UI– Create Java behavior classes – Create configuration files

Page 3: Grokking the Paradigm Creating a Component

Grokking the Paradigm 3© 2006 EMC Corporation. All rights reserved.

Creating a Component

• Components are composed of– The UI Layer (JSP)– Behavior (Java)– Configuration (XML)

• For this example, we’ll create a simple XML editor– We’ll create a new UI, a component configuration and supporting

Java class– We’ll extend the existing edit_file action configuration and extend

its supporting Java class

Page 4: Grokking the Paradigm Creating a Component

Grokking the Paradigm 4© 2006 EMC Corporation. All rights reserved.

No Rules!!

• You can create the parts in any order• I like to start with the UI

– Show it to your users for feedback before you complete the implementation

– Something tangible to look at as you develop the component– Feel like you’ve accomplished something

Page 5: Grokking the Paradigm Creating a Component

Grokking the Paradigm 5© 2006 EMC Corporation. All rights reserved.

Creating a ComponentThe UI Layer

<%@ page contentType = "text/html" %><%@ page errorPage = "/wdk/errorhandler.jsp" %><%@ taglib uri = "/WEB-INF/tlds/dmform_1_0.tld" prefix="dmf" %><dmf:html><dmf:head> <dmf:webform /></dmf:head><dmf:body><dmf:form> <dmf:table><dmf:tr><dmf:td colspan = "2" > <dmf:textarea name = "textXmlData" rows = "30" cols = "150" /> </dmf:td></dmf:tr><dmf:tr><dmf:td> <dmf:button name = "save" label = "Save Changes" onclick = "onClickSaveChanges" /> </dmf:td><dmf:td align = "right" > <dmf:button name = "cancel" label = "Cancel Changes“ onclick = "onClickCancel" /> </dmf:td></dmf:tr></dmf:table></dmf:form></dmf:body></dmf:html>

Page 6: Grokking the Paradigm Creating a Component

Grokking the Paradigm 6© 2006 EMC Corporation. All rights reserved.

Creating a Component – The UI JSP

• The UI consists of a text area for editing, a button to save changes, and a button to cancel changes.

Page 7: Grokking the Paradigm Creating a Component

Grokking the Paradigm 7© 2006 EMC Corporation. All rights reserved.

Creating a Component –Java Behavior Class

• LaunchXMLViewer extends LaunchComponentWithPermitCheck• Here’s the interesting chunk of code

public boolean execute( String strAction,IConfigElement config, ArgumentList args, Context context, Component component, java.util.Map map) { ... if((strContentType.indexOf(m_strXMLContentType) == -1) && (strContentType.indexOf(m_strXSLContentType) == -1)) { return (super.execute( strAction, config,args,context,component,map) ); } else { component.setComponentNested( "xmlviewer",args,component.getContext(),null); }

Page 8: Grokking the Paradigm Creating a Component

Grokking the Paradigm 8© 2006 EMC Corporation. All rights reserved.

Creating a Component -Configuring the Action

• We need to extend dm_sysobject_actions.xml

• We’ll modify the editfile action to point to our new Java class

<?xml ... <action id = "editfile“ extends= "editfile:/webcomponent/config/actions/dm_sysobject_actions.xml" > ... <execution class = "com.documentum.custom.action.LaunchXMLViewer" > <permit>version_permit</permit> <component>edit</component> <container>editcontainer</container> </execution> </action>

Page 9: Grokking the Paradigm Creating a Component

Grokking the Paradigm 9© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

• Let’s pick the XMLViewer class apart a section at a time, starting with the import statements

package com.documentum.custom.library;

import com.documentum.web.common.ArgumentList;

import com.documentum.web.form.Control;

import com.documentum.web.form.control.TextArea;

import com.documentum.web.formext.component.Component;

import com.documentum.fc.client.IDfSession;

import com.documentum.fc.client.IDfSysObject;

import com.documentum.fc.common.DfId;

import com.documentum.fc.common.DfException;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

Page 10: Grokking the Paradigm Creating a Component

Grokking the Paradigm 10© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

• Let’s pick the behavior class apart a section at a time, starting with the import statements

package com.documentum.custom.library;

import com.documentum.web.common.ArgumentList;

import com.documentum.web.form.Control;

import com.documentum.web.form.control.TextArea;

import com.documentum.web.formext.component.Component;

import com.documentum.fc.client.IDfSession;

import com.documentum.fc.client.IDfSysObject;

import com.documentum.fc.common.DfId;

import com.documentum.fc.common.DfException;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

Page 11: Grokking the Paradigm Creating a Component

Grokking the Paradigm 11© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

• Let’s pick the behavior class apart a section at a time, starting with the import statements

package com.documentum.custom.library;

import com.documentum.web.common.ArgumentList;

import com.documentum.web.form.Control;

import com.documentum.web.form.control.TextArea;

import com.documentum.web.formext.component.Component;

import com.documentum.fc.client.IDfSession;

import com.documentum.fc.client.IDfSysObject;

import com.documentum.fc.common.DfId;

import com.documentum.fc.common.DfException;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

Page 12: Grokking the Paradigm Creating a Component

Grokking the Paradigm 12© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

• Let’s pick the behavior class apart a section at a time, starting with the import statements

package com.documentum.custom.library;

import com.documentum.web.common.ArgumentList;

import com.documentum.web.form.Control;

import com.documentum.web.form.control.TextArea;

import com.documentum.web.formext.component.Component;

import com.documentum.fc.client.IDfSession;

import com.documentum.fc.client.IDfSysObject;

import com.documentum.fc.common.DfId;

import com.documentum.fc.common.DfException;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

Page 13: Grokking the Paradigm Creating a Component

Grokking the Paradigm 13© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

• Let’s pick the behavior class apart a section at a time, starting with the import statements

package com.documentum.custom.library;

import com.documentum.web.common.ArgumentList;

import com.documentum.web.form.Control;

import com.documentum.web.form.control.TextArea;

import com.documentum.web.formext.component.Component;

import com.documentum.fc.client.IDfSession;

import com.documentum.fc.client.IDfSysObject;

import com.documentum.fc.common.DfId;

import com.documentum.fc.common.DfException;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

Page 14: Grokking the Paradigm Creating a Component

Grokking the Paradigm 14© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

• Let’s pick the behavior class apart a section at a time, starting with the import statements

package com.documentum.custom.library;

import com.documentum.web.common.ArgumentList;

import com.documentum.web.form.Control;

import com.documentum.web.form.control.TextArea;

import com.documentum.web.formext.component.Component;

import com.documentum.fc.client.IDfSession;

import com.documentum.fc.client.IDfSysObject;

import com.documentum.fc.common.DfId;

import com.documentum.fc.common.DfException;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

Page 15: Grokking the Paradigm Creating a Component

Grokking the Paradigm 15© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

• In my examples, I put my variable definitions at the top of the file for readability, but they usually show up at the end of most Java files.

public class XMLViewer extends Component{ private String m_strObjectId = null; private IDfSysObject m_sysObjectXmlDoc = null; private String m_strXmlData = null; private IDfSession m_docbaseSession = null; private static final String m_strXMLContentType = "xml";

Page 16: Grokking the Paradigm Creating a Component

Grokking the Paradigm 16© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

• The initialization routine initializes the XML content, and, if successful, displays it in the text area

public void onInit(ArgumentList args)

{

super.onInit(args);

m_strObjectId = args.get("objectId");

if(m_strObjectId != null)

{

m_docbaseSession = getDfSession()

if(initXMLContent())

{

displayXmlData();

}

}

}

Page 17: Grokking the Paradigm Creating a Component

Grokking the Paradigm 17© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

This method reads the XML content into the m_strXmlData variable:

private boolean initXMLContent() {...

String contentType = m_sysObjectXmlDoc.getContentType();

if( m_sysObjectXmlDoc.isCheckedOut())

{

String lockOwner = m_sysObjectXmlDoc.getLockOwner();

String currentUser = getCurrentLoginUsername();

if(! currentUser.equals(lockOwner)) return false;

}

ByteArrayInputStream xmlData = m_sysObjectXmlDoc.getContent();

byte byteXmlData[] = new byte[xmlData.available() + 3];

xmlData.read(byteXmlData,0,xmlData.available());

m_strXmlData = new String(byteXmlData);

return true;

}

Page 18: Grokking the Paradigm Creating a Component

Grokking the Paradigm 18© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

The second piece to instantiation is actually displaying the XML data

private void displayXmlData() { TextArea textArea = (TextArea)

getControl("textXmlData"); if(textArea == null) { textArea = (TextArea) createControl("textXmlData",TextArea.class); } textArea.setValue(m_strXmlData); }

Page 19: Grokking the Paradigm Creating a Component

Grokking the Paradigm 19© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

public void onClickSaveChanges(Control control,

ArgumentList args)

{

saveXmlData();

}

}

Page 20: Grokking the Paradigm Creating a Component

Grokking the Paradigm 20© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

private void saveXmlData() {

if(m_sysObjectXmlDoc.isCheckedOut())

{

TextArea textArea = (TextArea) getControl("textXmlData");

m_strXmlData = textArea.getValue();

ByteArrayOutputStream outputStream =

new ByteArrayOutputStream();

outputStream.write(m_strXmlData.getBytes());

m_sysObjectXmlDoc.setContent(outputStream);

m_sysObjectXmlDoc.checkin(false,"");

setComponentReturn();

} else {

setComponentReturn();

}

}

Page 21: Grokking the Paradigm Creating a Component

Grokking the Paradigm 21© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

private void saveXmlData() {

if(m_sysObjectXmlDoc.isCheckedOut())

{

TextArea textArea = (TextArea) getControl("textXmlData");

m_strXmlData = textArea.getValue();

ByteArrayOutputStream outputStream =

new ByteArrayOutputStream();

outputStream.write(m_strXmlData.getBytes());

m_sysObjectXmlDoc.setContent(outputStream);

m_sysObjectXmlDoc.checkin(false,"");

setComponentReturn();

} else {

setComponentReturn();

}

}

Page 22: Grokking the Paradigm Creating a Component

Grokking the Paradigm 22© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

private void saveXmlData() {

if(m_sysObjectXmlDoc.isCheckedOut())

{

TextArea textArea = (TextArea) getControl("textXmlData");

m_strXmlData = textArea.getValue();

ByteArrayOutputStream outputStream =

new ByteArrayOutputStream();

outputStream.write(m_strXmlData.getBytes());

m_sysObjectXmlDoc.setContent(outputStream);

m_sysObjectXmlDoc.checkin(false,"");

setComponentReturn();

} else {

setComponentReturn();

}

}

Page 23: Grokking the Paradigm Creating a Component

Grokking the Paradigm 23© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

private void saveXmlData() {

if(m_sysObjectXmlDoc.isCheckedOut())

{

TextArea textArea = (TextArea) getControl("textXmlData");

m_strXmlData = textArea.getValue();

ByteArrayOutputStream outputStream =

new ByteArrayOutputStream();

outputStream.write(m_strXmlData.getBytes());

m_sysObjectXmlDoc.setContent(outputStream);

m_sysObjectXmlDoc.checkin(false,"");

setComponentReturn();

} else {

setComponentReturn();

}

}

Page 24: Grokking the Paradigm Creating a Component

Grokking the Paradigm 24© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

private void saveXmlData() {

if(m_sysObjectXmlDoc.isCheckedOut())

{

TextArea textArea = (TextArea) getControl("textXmlData");

m_strXmlData = textArea.getValue();

ByteArrayOutputStream outputStream =

new ByteArrayOutputStream();

outputStream.write(m_strXmlData.getBytes());

m_sysObjectXmlDoc.setContent(outputStream);

m_sysObjectXmlDoc.checkin(false,"");

setComponentReturn();

} else {

setComponentReturn();

}

}

Page 25: Grokking the Paradigm Creating a Component

Grokking the Paradigm 25© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

private void saveXmlData() {

if(m_sysObjectXmlDoc.isCheckedOut())

{

TextArea textArea = (TextArea) getControl("textXmlData");

m_strXmlData = textArea.getValue();

ByteArrayOutputStream outputStream =

new ByteArrayOutputStream();

outputStream.write(m_strXmlData.getBytes());

m_sysObjectXmlDoc.setContent(outputStream);

m_sysObjectXmlDoc.checkin(false,"");

setComponentReturn();

} else {

setComponentReturn();

}

}

Page 26: Grokking the Paradigm Creating a Component

Grokking the Paradigm 26© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Java Behavior Class

public void onClickCancel(Control control, ArgumentList args)

{

try

{

if(m_sysObjectXmlDoc.isCheckedOut())

{

m_sysObjectXmlDoc.cancelCheckout();

}

}

catch(DfException dfe)

{

dfe.printStackTrace();

}

setComponentReturn();

}

Page 27: Grokking the Paradigm Creating a Component

Grokking the Paradigm 27© 2006 EMC Corporation. All rights reserved.

Creating a Component – The Component Configuration File

• We create a component definition in an XML configuration file.

• This is the “glue” that associates the UI with the Java behavior class

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>

<config version="1.0">

<scope type = "dm_document" >

<component id = "xmlviewer" >

<params>

<param name = "objectId" required = "true" />

</params>

<pages>

<start>/custom/library/xmlViewer.jsp</start>

</pages>

<class>com.documentum.custom.library.XMLViewer</class>

</component>

</scope>

</config>

Page 28: Grokking the Paradigm Creating a Component

Grokking the Paradigm 28© 2006 EMC Corporation. All rights reserved.

Creating a Component – Deploying the Component

• After creating all of these files and compiling the Java classes, you deploy the files to the following locations:

/webtop/custom/library/xmlViewer.jsp

/webtop/custom/config/edit_action.xml

/webtop/custom/config/xmlviewer_component.xml

/webtop/WEB-INF/classes/com/documentum/custom/action/ LaunchXMLViewer.class

/webtop/WEB-INF/classes/com/documentum/custom/library/ XMLViewer.class

Page 29: Grokking the Paradigm Creating a Component

Grokking the Paradigm 29© 2006 EMC Corporation. All rights reserved.

Multiplicitas Componatis Res Simplex

• Taken as a whole, Webtop and WDK-based applications are intricate, multifaceted feats of programming

• When you focus on any one element of the application, it’s easy to follow the logic and duplicate its behavior

• Once you grok the paradigm, enhancing and customizing complex applications becomes a series of simple steps

Page 30: Grokking the Paradigm Creating a Component

© 2006 EMC Corporation. All rights reserved.

Clarifications/comments?Please send them to:

[email protected]

WDK Questions? Please visit:http://developer.emc.com/developer/