300 likes | 423 Vues
Discover the process of creating a custom component in EMC Documentum focusing on user interface (UI) development, Java behavior classes, and configuration files. This guide walks you through creating a simple XML editor, showcasing how to design the UI using JSP, implement functionality in Java, and configure actions in XML. Learn about the integration of different layers—UI, behavior, and configuration—while emphasizing the importance of user feedback throughout the development process. This comprehensive tutorial offers essential insights for technical writers and developers alike.
E N D
Grokking the ParadigmCreating 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 Grokking the Paradigm
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 Grokking the Paradigm
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 Grokking the Paradigm
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> Grokking the Paradigm
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. Grokking the Paradigm
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); } Grokking the Paradigm
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> Grokking the Paradigm
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; Grokking the Paradigm
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; Grokking the Paradigm
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; Grokking the Paradigm
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; Grokking the Paradigm
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; Grokking the Paradigm
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; Grokking the Paradigm
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"; Grokking the Paradigm
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(); } } } Grokking the Paradigm
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; } Grokking the Paradigm
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); } Grokking the Paradigm
Creating a Component – The Java Behavior Class public void onClickSaveChanges(Control control, ArgumentList args) { saveXmlData(); } } Grokking the Paradigm
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(); } } Grokking the Paradigm
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(); } } Grokking the Paradigm
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(); } } Grokking the Paradigm
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(); } } Grokking the Paradigm
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(); } } Grokking the Paradigm
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(); } } Grokking the Paradigm
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(); } Grokking the Paradigm
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> Grokking the Paradigm
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 Grokking the Paradigm
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 Grokking the Paradigm
Clarifications/comments?Please send them to:dawson_dennis@emc.comWDK Questions? Please visit:http://developer.emc.com/developer/