001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/portal/tool/src/java/org/theospi/portfolio/portal/renderer/RoleHandler.java $
003: * $Id:RoleHandler.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.portal.renderer;
021:
022: import java.io.IOException;
023:
024: import javax.faces.component.UIComponent;
025: import javax.faces.component.UIViewRoot;
026: import javax.faces.context.FacesContext;
027:
028: import org.theospi.jsf.impl.DefaultXmlTagHandler;
029: import org.theospi.jsf.intf.ComponentWrapper;
030: import org.theospi.jsf.intf.XmlTagFactory;
031: import org.theospi.portfolio.portal.component.ToolCategoryComponent;
032: import org.theospi.portfolio.portal.component.ToolComponent;
033: import org.xml.sax.Attributes;
034:
035: /**
036: * Created by IntelliJ IDEA.
037: * User: John Ellis
038: * Date: Feb 16, 2006
039: * Time: 4:53:00 PM
040: * To change this template use File | Settings | File Templates.
041: */
042: public class RoleHandler extends DefaultXmlTagHandler {
043:
044: private ToolCategoryRenderer toolCategoryRenderer;
045:
046: public RoleHandler(XmlTagFactory factory) {
047: super (factory);
048: toolCategoryRenderer = (ToolCategoryRenderer) factory;
049: }
050:
051: public ComponentWrapper startElement(FacesContext context,
052: ComponentWrapper parent, String uri, String localName,
053: String qName, Attributes attributes) throws IOException {
054: UIViewRoot root = context.getViewRoot();
055: ToolComponent container = (ToolComponent) context
056: .getApplication().createComponent(
057: ToolComponent.COMPONENT_TYPE);
058: container.setId(root.createUniqueId());
059: parent.getComponent().getChildren().add(container);
060:
061: String roleId = attributes.getValue("role");
062: ToolCategoryComponent parentComponent = findParent(parent);
063: String siteId = parentComponent.getSiteId();
064:
065: container.setRendered(getToolCategoryRenderer()
066: .getPortalManager().isUserInRole(roleId, siteId));
067:
068: return new ComponentWrapper(parent, container, this );
069: }
070:
071: protected ToolCategoryComponent findParent(ComponentWrapper parent) {
072: UIComponent parentComponent = parent.getComponent();
073: while (!(parentComponent instanceof ToolCategoryComponent)
074: && parentComponent != null) {
075: parentComponent = parentComponent.getParent();
076: }
077: return (ToolCategoryComponent) parentComponent;
078: }
079:
080: public void endElement(FacesContext context,
081: ComponentWrapper current, String uri, String localName,
082: String qName) throws IOException {
083: }
084:
085: public void characters(FacesContext context,
086: ComponentWrapper current, char[] ch, int start, int length)
087: throws IOException {
088: writeCharsToVerbatim(context, current, ch, start, length);
089: }
090:
091: public ToolCategoryRenderer getToolCategoryRenderer() {
092: return toolCategoryRenderer;
093: }
094:
095: public void setToolCategoryRenderer(
096: ToolCategoryRenderer toolCategoryRenderer) {
097: this.toolCategoryRenderer = toolCategoryRenderer;
098: }
099:
100: }
|