001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Jean-Marc Orliaguet, Chalmers 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.theme.jsf.filters.widgets; 023 024import org.nuxeo.theme.elements.Element; 025import org.nuxeo.theme.models.Region; 026import org.nuxeo.theme.rendering.RenderingInfo; 027import org.nuxeo.theme.views.AbstractView; 028 029public final class FaceletRegionView extends AbstractView { 030 031 @Override 032 public String render(final RenderingInfo info) { 033 final Region region = (Region) info.getModel(); 034 final StringBuilder s = new StringBuilder(); 035 036 final Element element = info.getElement(); 037 String className = element.getCssClassName(); 038 039 if ("".equals(region.name)) { 040 if (className == null) { 041 className = "nxthemesRegionNotSet"; 042 } 043 s.append("<div class=\"").append(className).append("\">").append("No facelet region name is set...").append( 044 "</div>"); 045 } else { 046 if (className == null) { 047 className = "themeRegion"; 048 } 049 s.append("<div xmlns:ui=\"http://java.sun.com/jsf/facelets\"").append(" class=\"").append(className).append( 050 "\">"); 051 s.append("<ui:insert name=\"").append(region.name).append("\">"); 052 if ("".equals(region.defaultSrc)) { 053 s.append(region.defaultBody); 054 } else { 055 s.append("<ui:include src=\"").append(region.defaultSrc).append("\" />"); 056 } 057 s.append("</ui:insert>"); 058 s.append("</div>"); 059 } 060 return s.toString(); 061 } 062}