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.ui; 016 017import java.io.IOException; 018import java.util.Map; 019 020import org.apache.commons.logging.Log; 021import org.apache.commons.logging.LogFactory; 022import org.nuxeo.theme.Manager; 023import org.nuxeo.theme.Utils; 024import org.nuxeo.theme.resources.ResourceType; 025import org.nuxeo.theme.types.TypeFamily; 026 027public class MVCElement { 028 029 private static final Log log = LogFactory.getLog(MVCElement.class); 030 031 public static String render(Map<String, String> params) { 032 StringBuilder sb = new StringBuilder(); 033 034 String resource = params.get("resource"); 035 String url = params.get("url"); 036 String body = params.get("body"); 037 String className = params.get("className"); 038 039 sb.append(String.format("<ins class=\"%s\">", className)); 040 041 /* insert the content from a file source */ 042 if (null != resource) { 043 ResourceType resourceType = (ResourceType) Manager.getTypeRegistry().lookup(TypeFamily.RESOURCE, resource); 044 if (resourceType == null) { 045 log.warn("Could not find resource: " + resource); 046 } else { 047 try { 048 sb.append(Utils.readResourceAsString(resourceType.getPath())); 049 } catch (IOException e) { 050 log.warn("Could not find resource: " + resource); 051 } 052 } 053 } 054 055 /* get the content from a url */ 056 if (null != url) { 057 sb.append(String.format(" cite=%s", url)); 058 } 059 060 /* get the content from the body */ 061 if (null != body) { 062 sb.append(body); 063 } 064 065 sb.append("</ins>"); 066 067 return sb.toString(); 068 } 069 070}