001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS <http://nuxeo.com> and others 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Jean-Marc Orliaguet, Chalmers 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.theme.html.filters.style; 016 017import java.util.List; 018 019import org.nuxeo.theme.elements.Element; 020import org.nuxeo.theme.elements.ElementFormatter; 021import org.nuxeo.theme.formats.Format; 022import org.nuxeo.theme.formats.styles.Style; 023import org.nuxeo.theme.formats.widgets.Widget; 024import org.nuxeo.theme.html.CSSUtils; 025import org.nuxeo.theme.rendering.RenderingInfo; 026import org.nuxeo.theme.themes.ThemeManager; 027import org.nuxeo.theme.views.AbstractView; 028 029public class DefaultStyleView extends AbstractView { 030 031 @Override 032 public String render(final RenderingInfo info) { 033 034 final Style style = (Style) info.getFormat(); 035 final StringBuilder sb = new StringBuilder(); 036 037 // add inherited styles first 038 final List<Format> ancestors = ThemeManager.listAncestorFormatsOf(style); 039 for (Format ancestor : ancestors) { 040 sb.insert(0, String.format("%s ", CSSUtils.computeCssClassName((Style) ancestor))); 041 } 042 sb.append(CSSUtils.computeCssClassName(style)); 043 044 // get the widget view name 045 final Element element = info.getElement(); 046 final Widget widget = (Widget) ElementFormatter.getFormatFor(element, "widget"); 047 if (widget != null) { 048 final String className = CSSUtils.toUpperCamelCase(widget.getName()); 049 sb.append(className); 050 } 051 052 return CSSUtils.insertCssClass(info.getMarkup(), sb.toString()); 053 } 054}