Moving to root below branch label

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2005-12-08 07:13:07 +00:00
commit d051d1153c
920 changed files with 98871 additions and 0 deletions

View File

@@ -0,0 +1,299 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.ui.repo.renderer;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.renderer.BaseRenderer;
import org.alfresco.web.ui.repo.component.UIMultiValueEditor;
import org.alfresco.web.ui.repo.component.UIMultiValueEditor.MultiValueEditorEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Renders the MultiValueEditor component as a list of options that can be
* removed using a Remove button
*
* @author gavinc
*/
public class MultiValueListEditorRenderer extends BaseRenderer
{
private static Log logger = LogFactory.getLog(MultiValueListEditorRenderer.class);
/** I18N message strings */
private final static String MSG_REMOVE = "remove";
private final static String MSG_SELECT_BUTTON = "select_button";
private final static String MSG_ADD_TO_LIST_BUTTON = "add_to_list_button";
private boolean highlightedRow;
// ------------------------------------------------------------------------------
// Renderer implemenation
/**
* @see javax.faces.render.Renderer#decode(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void decode(FacesContext context, UIComponent component)
{
Map requestMap = context.getExternalContext().getRequestParameterMap();
Map valuesMap = context.getExternalContext().getRequestParameterValuesMap();
String fieldId = getHiddenFieldName(component);
String value = (String)requestMap.get(fieldId);
int action = UIMultiValueEditor.ACTION_NONE;
int removeIndex = -1;
if (value != null && value.length() != 0)
{
// break up the action into it's parts
int sepIdx = value.indexOf(UIMultiValueEditor.ACTION_SEPARATOR);
if (sepIdx != -1)
{
action = Integer.parseInt(value.substring(0, sepIdx));
removeIndex = Integer.parseInt(value.substring(sepIdx+1));
}
else
{
action = Integer.parseInt(value);
}
}
if (action != UIMultiValueEditor.ACTION_NONE)
{
MultiValueEditorEvent event = new MultiValueEditorEvent(component, action, removeIndex);
component.queueEvent(event);
}
super.decode(context, component);
}
/**
* @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
if (component.isRendered() == false)
{
return;
}
// reset the highlighted row flag
this.highlightedRow = false;
if (component instanceof UIMultiValueEditor)
{
ResponseWriter out = context.getResponseWriter();
Map attrs = component.getAttributes();
String clientId = component.getClientId(context);
UIMultiValueEditor editor = (UIMultiValueEditor)component;
// start outer table
out.write("<table border='0' cellspacing='4' cellpadding='4' class='selector'");
this.outputAttribute(out, attrs.get("style"), "style");
this.outputAttribute(out, attrs.get("styleClass"), "styleClass");
out.write(">");
// show the select an item message
out.write("<tr><td>");
out.write("1. ");
out.write(editor.getSelectItemMsg());
out.write("</td></tr>");
if (editor.getAddingNewItem())
{
out.write("<tr><td style='padding-left:8px'>");
}
else
{
out.write("<tr><td style='padding-left:8px;'><input type='submit' value='");
out.write(Application.getMessage(context, MSG_SELECT_BUTTON));
out.write("' onclick=\"");
out.write(generateFormSubmit(context, component, Integer.toString(UIMultiValueEditor.ACTION_SELECT)));
out.write("\"/></td></tr>");
}
}
}
/**
* @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
if (component instanceof UIMultiValueEditor)
{
ResponseWriter out = context.getResponseWriter();
UIMultiValueEditor editor = (UIMultiValueEditor)component;
// get hold of the node service
NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
if (editor.getAddingNewItem())
{
out.write("</td></tr>");
}
// show the add to list button but only if something has been selected
out.write("<tr><td>2. <input type='submit'");
if (editor.getAddingNewItem() == false && editor.getLastItemAdded() != null ||
editor.getLastItemAdded() == null)
{
out.write(" disabled='true'");
}
out.write(" value='");
out.write(Application.getMessage(context, MSG_ADD_TO_LIST_BUTTON));
out.write("' onclick=\"");
out.write(generateFormSubmit(context, component, Integer.toString(UIMultiValueEditor.ACTION_ADD)));
out.write("\"/></td></tr>");
out.write("<tr><td style='padding-top:8px'>");
out.write(editor.getSelectedItemsMsg());
out.write("</td></tr>");
// show the current items
out.write("<tr><td><table cellspacing='0' cellpadding='2' border='0' class='selectedItems'>");
out.write("<tr><td colspan='2' class='selectedItemsHeader'>");
out.write(Application.getMessage(context, "name"));
out.write("</td></tr>");
List currentItems = (List)editor.getValue();
if (currentItems != null && currentItems.size() > 0)
{
for (int x = 0; x < currentItems.size(); x++)
{
Object obj = currentItems.get(x);
if (obj != null)
{
if (obj instanceof NodeRef)
{
if (nodeService.exists((NodeRef)obj))
{
renderExistingItem(context, component, out, nodeService, x, obj);
}
else
{
// remove invalid NodeRefs from the list
currentItems.remove(x);
}
}
else
{
renderExistingItem(context, component, out, nodeService, x, obj);
}
}
}
}
else
{
out.write("<tr><td class='selectedItemsRow'>");
out.write(editor.getNoSelectedItemsMsg());
out.write("</td></tr>");
}
// close tables
out.write("</table></td></tr></table>");
}
}
/**
* Renders an existing item with a remove button
*
* @param context FacesContext
* @param component The UIComponent
* @param out Writer to write output to
* @param nodeService The NodeService
* @param key The key of the item
* @param value The item's value
* @throws IOException
*/
protected void renderExistingItem(FacesContext context, UIComponent component, ResponseWriter out,
NodeService nodeService, int index, Object value) throws IOException
{
out.write("<tr><td class='");
if (this.highlightedRow)
{
out.write("selectedItemsRowAlt");
}
else
{
out.write("selectedItemsRow");
}
out.write("'>");
if (value instanceof NodeRef)
{
out.write(Repository.getNameForNode(nodeService, (NodeRef)value));
}
else
{
out.write(value.toString());
}
out.write("&nbsp;&nbsp;");
out.write("</td><td class='");
if (this.highlightedRow)
{
out.write("selectedItemsRowAlt");
}
else
{
out.write("selectedItemsRow");
}
out.write("'><a href='#' title='");
out.write(Application.getMessage(context, MSG_REMOVE));
out.write("' onclick=\"");
out.write(generateFormSubmit(context, component, UIMultiValueEditor.ACTION_REMOVE + UIMultiValueEditor.ACTION_SEPARATOR + index));
out.write("\"><img src='");
out.write(context.getExternalContext().getRequestContextPath());
out.write("/images/icons/delete.gif' border='0' width='13' height='16'/></a>");
this.highlightedRow = !this.highlightedRow;
}
/**
* We use a hidden field per picker instance on the page.
*
* @return hidden field name
*/
private String getHiddenFieldName(UIComponent component)
{
return component.getClientId(FacesContext.getCurrentInstance());
}
/**
* Generate FORM submit JavaScript for the specified action
*
* @param context FacesContext
* @param component The UIComponent
* @param action Action string
*
* @return FORM submit JavaScript
*/
private String generateFormSubmit(FacesContext context, UIComponent component, String action)
{
return Utils.generateFormSubmit(context, component, getHiddenFieldName(component), action);
}
}

View File

@@ -0,0 +1,280 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.ui.repo.renderer;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.renderer.BaseRenderer;
import org.alfresco.web.ui.repo.component.UINodeDescendants;
/**
* @author Kevin Roast
*/
public class NodeDescendantsLinkRenderer extends BaseRenderer
{
// ------------------------------------------------------------------------------
// Renderer implementation
/**
* @see javax.faces.render.Renderer#decode(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void decode(FacesContext context, UIComponent component)
{
Map requestMap = context.getExternalContext().getRequestParameterMap();
String fieldId = getHiddenFieldName(context, component);
String value = (String)requestMap.get(fieldId);
// we encoded the value to start with our Id
if (value != null && value.startsWith(component.getClientId(context) + NamingContainer.SEPARATOR_CHAR))
{
value = value.substring(component.getClientId(context).length() + 1);
// found a new selected value for this component
// queue an event to represent the change
int separatorIndex = value.indexOf(NamingContainer.SEPARATOR_CHAR);
String selectedNodeId = value.substring(0, separatorIndex);
boolean isParent = Boolean.parseBoolean(value.substring(separatorIndex + 1));
NodeService service = getNodeService(context);
NodeRef ref = new NodeRef(Repository.getStoreRef(), selectedNodeId);
UINodeDescendants.NodeSelectedEvent event = new UINodeDescendants.NodeSelectedEvent(component, ref, isParent);
component.queueEvent(event);
}
}
/**
* @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
// always check for this flag - as per the spec
if (component.isRendered() == true)
{
Writer out = context.getResponseWriter();
UINodeDescendants control = (UINodeDescendants)component;
// make sure we have a NodeRef from the 'value' property ValueBinding
Object val = control.getValue();
if (val instanceof NodeRef == false)
{
throw new IllegalArgumentException("UINodeDescendants component 'value' property must resolve to a NodeRef!");
}
NodeRef parentRef = (NodeRef)val;
// use Spring JSF integration to get the node service bean
NodeService service = getNodeService(context);
DictionaryService dd = getDictionaryService(context);
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
// TODO: need a comparator to sort node refs (based on childref qname)
// as currently the list is returned in a random order per request!
String separator = (String)component.getAttributes().get("separator");
if (separator == null)
{
separator = DEFAULT_SEPARATOR;
}
// calculate the number of displayed child refs
if (service.exists(parentRef) == true)
{
List<ChildAssociationRef> childRefs = service.getChildAssocs(parentRef);
List<ChildAssociationRef> refs = new ArrayList<ChildAssociationRef>(childRefs.size());
for (int index=0; index<childRefs.size(); index++)
{
ChildAssociationRef ref = childRefs.get(index);
QName type = service.getType(ref.getChildRef());
TypeDefinition typeDef = dd.getType(type);
if (typeDef != null && dd.isSubClass(type, ContentModel.TYPE_FOLDER) &&
dd.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false)
{
refs.add(ref);
}
}
// walk each child ref and output a descendant link control for each item
int total = 0;
int maximum = refs.size() > control.getMaxChildren() ? control.getMaxChildren() : refs.size();
for (int index=0; index<maximum; index++)
{
ChildAssociationRef ref = refs.get(index);
QName type = service.getType(ref.getChildRef());
TypeDefinition typeDef = dd.getType(type);
if (typeDef != null && dd.isSubClass(type, ContentModel.TYPE_FOLDER) &&
dd.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false)
{
// output separator if appropriate
if (total > 0)
{
out.write( separator );
}
out.write(renderDescendant(context, control, ref, false));
total++;
}
}
// do we need to render ellipses to indicate more items than the maximum
if (control.getShowEllipses() == true && refs.size() > maximum)
{
out.write( separator );
// TODO: is this the correct way to get the information we need?
// e.g. primary parent may not be the correct path? how do we make sure we find
// the correct parent and more importantly the correct Display Name value!
out.write( renderDescendant(context, control, service.getPrimaryParent(parentRef), true) );
}
}
tx.commit();
}
catch (Throwable err)
{
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
throw new RuntimeException(err);
}
}
}
/**
* Render a descendant as a clickable link
*
* @param context FacesContext
* @param control UINodeDescendants to get attributes from
* @param childRef The ChildAssocRef of the child to render an HTML link for
* @param ellipses Whether to render the label of this descendant as a ellipses i.e. "..."
*
* @return HTML for a descendant link
*/
private String renderDescendant(FacesContext context, UINodeDescendants control, ChildAssociationRef childRef, boolean ellipses)
{
StringBuilder buf = new StringBuilder(256);
buf.append("<a href='#' onclick=\"");
// build an HTML param that contains the client Id of this control, followed by the node Id
// followed by whether this is the parent node not a decendant (ellipses clicked)
String param = control.getClientId(context) + NamingContainer.SEPARATOR_CHAR +
childRef.getChildRef().getId() + NamingContainer.SEPARATOR_CHAR +
Boolean.toString(ellipses);
buf.append(Utils.generateFormSubmit(context, control, getHiddenFieldName(context, control), param));
buf.append('"');
Map attrs = control.getAttributes();
if (attrs.get("style") != null)
{
buf.append(" style=\"")
.append(attrs.get("style"))
.append('"');
}
if (attrs.get("styleClass") != null)
{
buf.append(" class=")
.append(attrs.get("styleClass"));
}
buf.append('>');
if (ellipses == false)
{
// label is the name of the child node assoc
String name = Repository.getNameForNode(getNodeService(context), childRef.getChildRef());
buf.append(Utils.encode(name));
}
else
{
// TODO: allow the ellipses string to be set as component property?
buf.append("...");
}
buf.append("</a>");
return buf.toString();
}
// ------------------------------------------------------------------------------
// Private helpers
/**
* Get the hidden field name for this node descendant component.
* Build a shared field name from the parent form name and the string "ndec".
*
* @return hidden field name shared by all node descendant components within the Form.
*/
private static String getHiddenFieldName(FacesContext context, UIComponent component)
{
return Utils.getParentForm(context, component).getClientId(context) + NamingContainer.SEPARATOR_CHAR + "ndec";
}
/**
* Use Spring JSF integration to return the Node Service bean instance
*
* @param context FacesContext
*
* @return Node Service bean instance or throws exception if not found
*/
private static NodeService getNodeService(FacesContext context)
{
NodeService service = Repository.getServiceRegistry(context).getNodeService();
if (service == null)
{
throw new IllegalStateException("Unable to obtain NodeService bean reference.");
}
return service;
}
/**
* Use Spring JSF integration to return the Dictionary Service bean instance
*
* @param context FacesContext
*
* @return Dictionary Service bean instance or throws exception if not found
*/
private static DictionaryService getDictionaryService(FacesContext context)
{
DictionaryService service = Repository.getServiceRegistry(context).getDictionaryService();
if (service == null)
{
throw new IllegalStateException("Unable to obtain DictionaryService bean reference.");
}
return service;
}
private static final String DEFAULT_SEPARATOR = " | ";
}

View File

@@ -0,0 +1,329 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.ui.repo.renderer;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.transaction.UserTransaction;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.renderer.BaseRenderer;
import org.alfresco.web.ui.repo.component.UINodeDescendants;
import org.alfresco.web.ui.repo.component.UINodePath;
/**
* @author Kevin Roast
*/
public class NodePathLinkRenderer extends BaseRenderer
{
// ------------------------------------------------------------------------------
// Renderer implementation
/**
* @see javax.faces.render.Renderer#decode(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void decode(FacesContext context, UIComponent component)
{
Map requestMap = context.getExternalContext().getRequestParameterMap();
String fieldId = getHiddenFieldName(context, component);
String value = (String)requestMap.get(fieldId);
// we encoded the value to start with our Id
if (value != null && value.startsWith(component.getClientId(context) + NamingContainer.SEPARATOR_CHAR))
{
// found a new selected value for this component
// queue an event to represent the change
String selectedNodeId = value.substring(component.getClientId(context).length() + 1);
NodeRef ref = new NodeRef(Repository.getStoreRef(), selectedNodeId);
UINodePath.PathElementEvent event = new UINodePath.PathElementEvent(component, ref);
component.queueEvent(event);
}
}
/**
* @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
// always check for this flag - as per the spec
if (component.isRendered() == false)
{
return;
}
Writer out = context.getResponseWriter();
// make sure we have a NodeRef or Path from the 'value' property ValueBinding
Path path = null;
NodeRef nodeRef = null;
Object val = ((UINodePath)component).getValue();
if (val instanceof NodeRef == true)
{
nodeRef = (NodeRef)val;
}
else if (val instanceof Path == true)
{
path = (Path)val;
}
else
{
throw new IllegalArgumentException("UINodePath component 'value' property must resolve to a NodeRef or Path!");
}
boolean isBreadcrumb = false;
Boolean breadcrumb = (Boolean)component.getAttributes().get("breadcrumb");
if (breadcrumb != null)
{
isBreadcrumb = breadcrumb.booleanValue();
}
boolean isDisabled = false;
Boolean disabled = (Boolean)component.getAttributes().get("disabled");
if (disabled != null)
{
isDisabled = disabled.booleanValue();
}
boolean showLeaf = false;
Boolean showLeafBool = (Boolean)component.getAttributes().get("showLeaf");
if (showLeafBool != null)
{
showLeaf = showLeafBool.booleanValue();
}
// use Spring JSF integration to get the node service bean
NodeService service = getNodeService(context);
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
if (path == null)
{
path = service.getPath(nodeRef);
}
if (isBreadcrumb == false || isDisabled == true)
{
out.write(buildPathAsSingular(context, component, path, showLeaf, isDisabled));
}
else
{
out.write(buildPathAsBreadcrumb(context, component, path, showLeaf));
}
tx.commit();
}
catch (InvalidNodeRefException refErr)
{
// this error simple means we cannot output the path
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
}
catch (AccessDeniedException accessErr)
{
// this error simple means we cannot output the path
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
}
catch (Throwable err)
{
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
throw new RuntimeException(err);
}
}
/**
* Return the path with each element as a single clickable link e.g. breadcrumb style
*
* @param context FacesContext
* @param component UIComponent to get display attribute from
* @param path Node Path to use
*
* @return the path with each individual element clickable
*/
private String buildPathAsBreadcrumb(FacesContext context, UIComponent component, Path path, boolean showLeaf)
{
StringBuilder buf = new StringBuilder(1024);
int size = (showLeaf ? path.size() : path.size() - 1);
for (int i=0; i<size; i++)
{
Path.Element element = path.get(i);
String elementString = null;
if (element instanceof Path.ChildAssocElement)
{
ChildAssociationRef elementRef = ((Path.ChildAssocElement)element).getRef();
if (elementRef.getParentRef() != null)
{
String name = Repository.getNameForNode(getNodeService(context), elementRef.getChildRef());
elementString = renderPathElement(context, component, elementRef.getChildRef(), name);
}
}
else
{
elementString = element.getElementString();
}
if (elementString != null)
{
buf.append("/");
buf.append(elementString);
}
}
return buf.toString();
}
/**
* Return the path with the entire path as a single clickable link
*
* @param context FacesContext
* @param component UIComponent to get display attribute from
* @param path Node Path to use
*
* @return the entire path as a single clickable link
*/
private String buildPathAsSingular(FacesContext context, UIComponent component, Path path, boolean showLeaf, boolean disabled)
{
StringBuilder buf = new StringBuilder(512);
NodeRef lastElementRef = null;
int size = (showLeaf ? path.size() : path.size() - 1);
for (int i=0; i<size; i++)
{
Path.Element element = path.get(i);
String elementString = null;
if (element instanceof Path.ChildAssocElement)
{
ChildAssociationRef elementRef = ((Path.ChildAssocElement)element).getRef();
if (elementRef.getParentRef() != null)
{
elementString = Repository.getNameForNode(getNodeService(context), elementRef.getChildRef());
}
if (i == path.size() - 2)
{
lastElementRef = elementRef.getChildRef();
}
}
else
{
elementString = element.getElementString();
}
if (elementString != null)
{
buf.append("/");
buf.append(elementString);
}
}
if (disabled == false)
{
return renderPathElement(context, component, lastElementRef, buf.toString());
}
else
{
return buf.toString();
}
}
/**
* Render a path element as a clickable link
*
* @param context FacesContext
* @param control UIComponent to get attributes from
* @param nodeRef NodeRef of the path element
* @param label Display label to output with this link
*
* @return HTML for a descendant link
*/
private String renderPathElement(FacesContext context, UIComponent control, NodeRef nodeRef, String label)
{
StringBuilder buf = new StringBuilder(256);
buf.append("<a href='#' onclick=\"");
// build an HTML param that contains the client Id of this control, followed by the node Id
String param = control.getClientId(context) + NamingContainer.SEPARATOR_CHAR + nodeRef.getId();
buf.append(Utils.generateFormSubmit(context, control, getHiddenFieldName(context, control), param));
buf.append('"');
Map attrs = control.getAttributes();
if (attrs.get("style") != null)
{
buf.append(" style=\"")
.append(attrs.get("style"))
.append('"');
}
if (attrs.get("styleClass") != null)
{
buf.append(" class=")
.append(attrs.get("styleClass"));
}
buf.append('>');
buf.append(Utils.encode(label));
buf.append("</a>");
return buf.toString();
}
// ------------------------------------------------------------------------------
// Private helpers
/**
* Get the hidden field name for this node path component.
* Build a shared field name from the parent form name and the string "npath".
*
* @return hidden field name shared by all node path components within the Form.
*/
private static String getHiddenFieldName(FacesContext context, UIComponent component)
{
return Utils.getParentForm(context, component).getClientId(context) + NamingContainer.SEPARATOR_CHAR + "npath";
}
/**
* Use Spring JSF integration to return the node service bean instance
*
* @param context FacesContext
*
* @return node service bean instance or throws runtime exception if not found
*/
private static NodeService getNodeService(FacesContext context)
{
NodeService service = Repository.getServiceRegistry(context).getNodeService();
if (service == null)
{
throw new IllegalStateException("Unable to obtain NodeService bean reference.");
}
return service;
}
}

View File

@@ -0,0 +1,113 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.ui.repo.renderer.property;
import java.io.IOException;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.renderer.BaseRenderer;
import org.alfresco.web.ui.repo.component.property.UIAssociation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Renderer for the UIAssociation component
*
* @author gavinc
*/
public class AssociationRenderer extends BaseRenderer
{
private static Log logger = LogFactory.getLog(AssociationRenderer.class);
/**
* @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
if (component.isRendered() == false)
{
return;
}
// NOTE: we close off the first <td> generated by the property sheet's grid renderer
context.getResponseWriter().write("</td>");
}
/**
* @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeChildren(FacesContext context, UIComponent component) throws IOException
{
if (component.isRendered() == false)
{
return;
}
UIAssociation association = (UIAssociation)component;
ResponseWriter out = context.getResponseWriter();
// make sure there are exactly 2 child components
int count = association.getChildCount();
if (count == 2)
{
// get the label and the control
List<UIComponent> kids = association.getChildren();
UIComponent label = kids.get(0);
UIComponent control = kids.get(1);
// place a style class on the label column if necessary
String labelStylceClass = (String)association.getParent().getAttributes().get("labelStyleClass");
out.write("</td><td");
if (labelStylceClass != null)
{
outputAttribute(out, labelStylceClass, "class");
}
// close the <td>
out.write(">");
// encode the label
Utils.encodeRecursive(context, label);
// encode the control
context.getResponseWriter().write("</td><td>");
Utils.encodeRecursive(context, control);
// NOTE: we'll allow the property sheet's grid renderer close off the last <td>
}
}
/**
* @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
// we don't need to do anything in here
}
/**
* @see javax.faces.render.Renderer#getRendersChildren()
*/
public boolean getRendersChildren()
{
return true;
}
}

View File

@@ -0,0 +1,113 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.ui.repo.renderer.property;
import java.io.IOException;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.renderer.BaseRenderer;
import org.alfresco.web.ui.repo.component.property.UIChildAssociation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Renderer for the UIChildAssociation component
*
* @author gavinc
*/
public class ChildAssociationRenderer extends BaseRenderer
{
private static Log logger = LogFactory.getLog(ChildAssociationRenderer.class);
/**
* @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
if (component.isRendered() == false)
{
return;
}
// NOTE: we close off the first <td> generated by the property sheet's grid renderer
context.getResponseWriter().write("</td>");
}
/**
* @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeChildren(FacesContext context, UIComponent component) throws IOException
{
if (component.isRendered() == false)
{
return;
}
UIChildAssociation association = (UIChildAssociation)component;
ResponseWriter out = context.getResponseWriter();
// make sure there are exactly 2 child components
int count = association.getChildCount();
if (count == 2)
{
// get the label and the control
List<UIComponent> kids = association.getChildren();
UIComponent label = kids.get(0);
UIComponent control = kids.get(1);
// place a style class on the label column if necessary
String labelStylceClass = (String)association.getParent().getAttributes().get("labelStyleClass");
out.write("</td><td");
if (labelStylceClass != null)
{
outputAttribute(out, labelStylceClass, "class");
}
// close the <td>
out.write(">");
// encode the label
Utils.encodeRecursive(context, label);
// encode the control
context.getResponseWriter().write("</td><td>");
Utils.encodeRecursive(context, control);
// NOTE: we'll allow the property sheet's grid renderer close off the last <td>
}
}
/**
* @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
// we don't need to do anything in here
}
/**
* @see javax.faces.render.Renderer#getRendersChildren()
*/
public boolean getRendersChildren()
{
return true;
}
}

View File

@@ -0,0 +1,114 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.ui.repo.renderer.property;
import java.io.IOException;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.renderer.BaseRenderer;
import org.alfresco.web.ui.repo.component.property.UIProperty;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Renderer for the UIProperty component
*
* @author gavinc
*/
public class PropertyRenderer extends BaseRenderer
{
private static Log logger = LogFactory.getLog(PropertyRenderer.class);
/**
* @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
if (component.isRendered() == false)
{
return;
}
// NOTE: we close off the first <td> generated by the property sheet's grid renderer
context.getResponseWriter().write("</td>");
}
/**
* @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeChildren(FacesContext context, UIComponent component) throws IOException
{
if (component.isRendered() == false)
{
return;
}
UIProperty property = (UIProperty)component;
ResponseWriter out = context.getResponseWriter();
// make sure there are exactly 2 child components
int count = property.getChildCount();
if (count == 2)
{
// get the label and the control
List<UIComponent> kids = property.getChildren();
UIComponent label = kids.get(0);
UIComponent control = kids.get(1);
// place a style class on the label column if necessary
String labelStylceClass = (String)property.getParent().getAttributes().get("labelStyleClass");
out.write("</td><td");
if (labelStylceClass != null)
{
outputAttribute(out, labelStylceClass, "class");
}
// close the <td>
out.write(">");
// encode the label
Utils.encodeRecursive(context, label);
// encode the control
out.write("</td><td>");
Utils.encodeRecursive(context, control);
// NOTE: we'll allow the property sheet's grid renderer close off the last <td>
}
}
/**
* @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
// we don't need to do anything in here
}
/**
* @see javax.faces.render.Renderer#getRendersChildren()
*/
public boolean getRendersChildren()
{
return true;
}
}