001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/portal/tool/src/java/org/theospi/portfolio/portal/renderer/ToolLinkHandler.java $
003: * $Id:ToolLinkHandler.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.component.html.HtmlOutputLink;
027: import javax.faces.context.FacesContext;
028:
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 16, 2006
040: * Time: 10:28:00 PM
041: * To change this template use File | Settings | File Templates.
042: */
043: public class ToolLinkHandler extends DefaultXmlTagHandler {
044:
045: public ToolLinkHandler(XmlTagFactory factory) {
046: super (factory);
047: }
048:
049: public ComponentWrapper startElement(FacesContext context,
050: ComponentWrapper parent, String uri, String localName,
051: String qName, Attributes attributes) throws IOException {
052: UIViewRoot root = context.getViewRoot();
053: HtmlOutputLink link = (HtmlOutputLink) context.getApplication()
054: .createComponent(HtmlOutputLink.COMPONENT_TYPE);
055: link.setId(root.createUniqueId());
056: parent.getComponent().getChildren().add(link);
057:
058: link.setTarget("_parent");
059: ToolCategoryComponent parentCategoryComponent = findParentCategory(parent);
060: ToolComponent parentComponent = findParentTool(parent);
061:
062: if (parentComponent.getPage() != null) {
063: // Resolve the site_type of the form /portal/category/<siteId>/<categoryKey>/<optionalToolId>
064: String url = parentCategoryComponent.getContext()
065: + "/category/"
066: + parentCategoryComponent.getSiteId()
067: + "/"
068: + parentCategoryComponent.getToolCategory()
069: .getKey() + "/"
070: + parentComponent.getPage().getId();
071: link.setValue(url);
072: }
073: return new ComponentWrapper(parent, link, this );
074: }
075:
076: protected ToolCategoryComponent findParentCategory(
077: ComponentWrapper parent) {
078: UIComponent parentComponent = parent.getComponent();
079: while (!(parentComponent instanceof ToolCategoryComponent)
080: && parentComponent != null) {
081: parentComponent = parentComponent.getParent();
082: }
083: return (ToolCategoryComponent) parentComponent;
084: }
085:
086: protected ToolComponent findParentTool(ComponentWrapper parent) {
087: UIComponent parentComponent = parent.getComponent();
088: while (!(parentComponent instanceof ToolComponent)
089: && parentComponent != null) {
090: parentComponent = parentComponent.getParent();
091: }
092: return (ToolComponent) parentComponent;
093: }
094:
095: public void characters(FacesContext context,
096: ComponentWrapper current, char[] ch, int start, int length)
097: throws IOException {
098: writeCharsToVerbatim(context, current, ch, start, length);
099: }
100:
101: public void endElement(FacesContext context,
102: ComponentWrapper current, String uri, String localName,
103: String qName) throws IOException {
104:
105: }
106:
107: }
|