001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/portal/tool/src/java/org/theospi/portfolio/portal/renderer/ToolHandler.java $
003: * $Id:ToolHandler.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.sakaiproject.site.api.SitePage;
029: import org.theospi.jsf.impl.DefaultXmlTagHandler;
030: import org.theospi.jsf.intf.ComponentWrapper;
031: import org.theospi.jsf.intf.XmlTagFactory;
032: import org.theospi.portfolio.portal.component.ToolCategoryComponent;
033: import org.theospi.portfolio.portal.component.ToolComponent;
034: import org.xml.sax.Attributes;
035:
036: /**
037: * Created by IntelliJ IDEA.
038: * User: John Ellis
039: * Date: Feb 17, 2006
040: * Time: 9:47:10 AM
041: * To change this template use File | Settings | File Templates.
042: */
043: public class ToolHandler extends DefaultXmlTagHandler {
044:
045: private ToolCategoryRenderer toolCategoryRenderer;
046:
047: public ToolHandler(XmlTagFactory factory) {
048: super (factory);
049: this .toolCategoryRenderer = (ToolCategoryRenderer) factory;
050: }
051:
052: public ComponentWrapper startElement(FacesContext context,
053: ComponentWrapper parent, String uri, String localName,
054: String qName, Attributes attributes) throws IOException {
055: UIViewRoot root = context.getViewRoot();
056: ToolComponent container = (ToolComponent) context
057: .getApplication().createComponent(
058: ToolComponent.COMPONENT_TYPE);
059: container.setId(root.createUniqueId());
060: parent.getComponent().getChildren().add(container);
061:
062: String toolId = attributes.getValue("id");
063: ToolCategoryComponent parentComponent = findParent(parent);
064:
065: SitePage page = getToolCategoryRenderer().getPortalManager()
066: .getPage(toolId, parentComponent.getSiteId());
067:
068: container.setPage(page);
069:
070: container.setRendered(getToolCategoryRenderer()
071: .getPortalManager().isAvailable(toolId,
072: parentComponent.getSiteId()));
073:
074: return new ComponentWrapper(parent, container, this );
075: }
076:
077: public void characters(FacesContext context,
078: ComponentWrapper current, char[] ch, int start, int length)
079: throws IOException {
080: writeCharsToVerbatim(context, current, ch, start, length);
081: }
082:
083: public void endElement(FacesContext context,
084: ComponentWrapper current, String uri, String localName,
085: String qName) throws IOException {
086:
087: }
088:
089: public ToolCategoryRenderer getToolCategoryRenderer() {
090: return toolCategoryRenderer;
091: }
092:
093: public void setToolCategoryRenderer(
094: ToolCategoryRenderer toolCategoryRenderer) {
095: this .toolCategoryRenderer = toolCategoryRenderer;
096: }
097:
098: protected ToolCategoryComponent findParent(ComponentWrapper parent) {
099: UIComponent parentComponent = parent.getComponent();
100: while (!(parentComponent instanceof ToolCategoryComponent)
101: && parentComponent != null) {
102: parentComponent = parentComponent.getParent();
103: }
104: return (ToolCategoryComponent) parentComponent;
105: }
106:
107: }
|