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.html.filters.style; 023 024import java.util.List; 025 026import org.nuxeo.theme.elements.Element; 027import org.nuxeo.theme.elements.ElementFormatter; 028import org.nuxeo.theme.formats.Format; 029import org.nuxeo.theme.formats.styles.Style; 030import org.nuxeo.theme.formats.widgets.Widget; 031import org.nuxeo.theme.html.CSSUtils; 032import org.nuxeo.theme.rendering.RenderingInfo; 033import org.nuxeo.theme.themes.ThemeManager; 034import org.nuxeo.theme.views.AbstractView; 035 036public class DefaultStyleView extends AbstractView { 037 038 @Override 039 public String render(final RenderingInfo info) { 040 041 final Style style = (Style) info.getFormat(); 042 final StringBuilder sb = new StringBuilder(); 043 044 // add inherited styles first 045 final List<Format> ancestors = ThemeManager.listAncestorFormatsOf(style); 046 for (Format ancestor : ancestors) { 047 sb.insert(0, String.format("%s ", CSSUtils.computeCssClassName((Style) ancestor))); 048 } 049 sb.append(CSSUtils.computeCssClassName(style)); 050 051 // get the widget view name 052 final Element element = info.getElement(); 053 final Widget widget = (Widget) ElementFormatter.getFormatFor(element, "widget"); 054 if (widget != null) { 055 final String className = CSSUtils.toUpperCamelCase(widget.getName()); 056 sb.append(className); 057 } 058 059 return CSSUtils.insertCssClass(info.getMarkup(), sb.toString()); 060 } 061}