%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.net.URL,
java.util.*,
java.text.SimpleDateFormat,
java.io.PrintWriter,
java.util.StringTokenizer,
com.plumtree.remote.portlet.*,
com.plumtree.remote.prc.*,
com.plumtree.remote.prc.content.*,
com.plumtree.remote.prc.content.dataentrytemplate.*,
com.plumtree.remote.prc.content.folder.*,
com.plumtree.remote.prc.content.property.*,
com.plumtree.remote.prc.content.selectionlist.*,
com.plumtree.remote.prc.content.item.*"
%>
<%
PrintWriter jspOut = response.getWriter();
IPortletContext portletContext = null;
IRemoteSession remoteSession = null;
IDataEntryTemplate dataEntryTemplate = null;
try
{
portletContext = PortletContextFactory.createPortletContext(request, response);
remoteSession = portletContext.getRemotePortalSession();
//Get the content factory.
IContentFactory contentFactory = remoteSession.getContentFactory();
//Get the folder containing the data entry template.
IFolder folder = retrieveContentFolder(contentFactory);
//Get the data entry template
dataEntryTemplate = retrieveDET(contentFactory, folder);
Map parameterMap = request.getParameterMap();
String[] contentItemTest = (String[])parameterMap.get("Content Item Name");
if(null != contentItemTest && contentItemTest.length > 0)
{
//If we got the content item name in the request parameters we'll assume
//this request was from the create content item button. So we'll handle it first.
handleCreateButtonClick(remoteSession, dataEntryTemplate, jspOut, parameterMap);
}
}
catch(Exception ex)
{
jspOut.println("Exception: " + ex.getMessage() + "
");
}
%>
<%!
/**
* Gets the Content Server folder used to store the Content
* Server objects for our application.
*
* In this sample, we will create a new folder. In your * real application you would likely have created the folder * already and will need to query for it here. */ private static IFolder retrieveContentFolder(IContentFactory factory) throws Exception { // Get a folder manager for working with Content Server folders. IFolderManager folderManager = factory.getFolderManager(); //Check to see if the folder has already been created IFolder subFolder = folderManager.getFolderByPath("/Java Web Example - DET"); if(subFolder == null) { //If the folder is not there we will create our own folder for the sample // Get a reference to the root folder. It always exists. IFolder rootFolder = folderManager.getRootFolder(); // Create a new folder subFolder = folderManager.createFolder(rootFolder, "Java Web Example - DET"); subFolder.store(); } return subFolder; } /** * Gets the DET that defines what fields are present in each * customer support incident. *
* In this sample, we will create a new DET. In your real * application, this method would probably query an already * existing DET. */ private static IDataEntryTemplate retrieveDET(IContentFactory factory, IFolder folder) throws Exception { // // A Data Entry Template object is a collection of // property objects. Each property object represents // a field in the records associated with the DET. // // This sample uses all of the classes of properties // available in Content Server. Each customer support // incidents will have: // (integer) Incident ID // (boolean) If the incident has been resolved // (float) Incident severity rating // (date) Date the incident was opened // (text line) Customer name // (item reference) Link to other content item representing the customer // (selection list) The product the incident was reported in // (text block) Reported problem // (file) Logs of problem // (image) Screen shot of problem // // Get manager objects needed for creating a DET. IDataEntryTemplateManager detManager = factory.getDataEntryTemplateManager(); // Check to see if the data entry template already exists IDataEntryTemplate det = detManager.getDataEntryTemplate(folder, "Support Incident Data Entry Template"); if(det != null) { return det; } IPropertyManager propertyManager = factory.getPropertyManager(); ISelectionListManager slManager = factory.getSelectionListManager(); // Create a DET object. det = detManager.createDataEntryTemplate(folder, "Support Incident Data Entry Template"); // Add an integer property. IIntegerProperty incident = propertyManager.createIntegerProperty("Incident ID", "The ticket number for this incident."); det.addProperty(incident); // Add a boolean property IBooleanProperty resolved = propertyManager.createBooleanProperty("Resolved", "True if the incident has been closed; false if it is still open."); det.addProperty(resolved); // Add a float property. IDoubleProperty severity = propertyManager.createDoubleProperty("Severity", "Percentage stating how severe the incident is."); det.addProperty(severity); // Add a date property. IDateProperty opened = propertyManager.createDateProperty("Date Opened", "The date and time the incident was reported."); det.addProperty(opened); // Add a text line property. // Text lines are brief strings without newline characters. // Use the text block property for storing longer strings. ITextLineProperty customerName = propertyManager.createTextLineProperty("Customer Name", "The name of the customer."); det.addProperty(customerName); // Add an item reference property. // An item reference links to another content item. The // content item does not have to be associated with the // same DET. For example, we will link to a fictional // content item representing the customer that is having // the support problem; which would be associated with // a DET representing customers. // // Not shown is the item collection property. It is // similar to the item reference property, but links to // multiple content items. IItemReferenceProperty customerData = propertyManager.createItemReferenceProperty("Customer Information", "Links to information about the customer such as the contact and their phone number."); det.addProperty(customerData); // Add a selection list property. // A selection list is a defined set of choices of which // one may be selected. This can be visualized as a // drop down box. //Check to see if the selection list already exists ISelectionList selectionList = null; ISelectionList[] selectionLists = slManager.getSelectionLists(folder); for(int i = 0; i < selectionLists.length; i++) { if(selectionLists[i].getName().equals("Products Selection List")) { selectionList = selectionLists[i]; break; } } if(selectionList == null) { String[] listValues = {"Portal", "Search Server", "Collaboration Server", "Content Server", "Analytics"}; selectionList = slManager.createSelectionList(folder, "Products Selection List", listValues); selectionList.store(); } ISelectionListProperty products = propertyManager.createSelectionListProperty("Product", "The product which the support incident is opened against", selectionList); det.addProperty(products); // Add a text block property. // Text block properties are used to store long strings // that can span many lines. For short strings contained // on only one line, use the text line property instead. ITextBlockProperty description = propertyManager.createTextBlockProperty("Incident Description", "A writeup summarizing the problem the customer is experiencing."); det.addProperty(description); // Add a file property. IFileProperty log = propertyManager.createFileProperty("Log File", "A log file taken while the problem occurred."); det.addProperty(log); // Add an image property. IImageProperty screenShot = propertyManager.createImageProperty("Screen Shot", "A screen shot of the problem."); det.addProperty(screenShot); // Actually store the DET and all the properties associated with it. det.store(); return det; } // Create all the controls for a given Data Entry Template. The type of // control depends on the type of property. private String renderDataEntryTemplate(IDataEntryTemplate dataEntryTemplate) throws Exception { if(dataEntryTemplate == null) return ""; StringBuffer buf = new StringBuffer(); //create new table buf.append("