001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.types.adapter; 021 022import java.util.LinkedHashMap; 023import java.util.Map; 024 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.platform.types.DocumentContentViews; 027import org.nuxeo.ecm.platform.types.SubType; 028import org.nuxeo.ecm.platform.types.Type; 029import org.nuxeo.ecm.platform.types.TypeManager; 030import org.nuxeo.ecm.platform.types.TypeView; 031import org.nuxeo.runtime.api.Framework; 032 033/** 034 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 035 */ 036public class TypeInfoAdapter implements TypeInfo { 037 038 private final Type type; 039 040 public TypeInfoAdapter(DocumentModel doc) { 041 TypeManager mgr = Framework.getService(TypeManager.class); 042 type = mgr.getType(doc.getType()); 043 } 044 045 public String[] getActions() { 046 if (type != null) { 047 return type.getActions(); 048 } 049 return null; 050 } 051 052 public Map<String, SubType> getAllowedSubTypes() { 053 if (type != null) { 054 return type.getAllowedSubTypes(); 055 } 056 057 return null; 058 } 059 060 /** 061 * @deprecated Use {@link #getId} instead. 062 */ 063 @Deprecated 064 public String getCoreType() { 065 if (type != null) { 066 return type.getId(); 067 } 068 069 return null; 070 } 071 072 public String getCreateView() { 073 if (type != null) { 074 return type.getCreateView(); 075 } 076 077 return null; 078 } 079 080 public String getDefaultView() { 081 if (type != null) { 082 return type.getDefaultView(); 083 } 084 085 return null; 086 } 087 088 public String getEditView() { 089 if (type != null) { 090 return type.getEditView(); 091 } 092 093 return null; 094 } 095 096 public String getIcon() { 097 if (type != null) { 098 return type.getIcon(); 099 } 100 101 return null; 102 } 103 104 public String getIconExpanded() { 105 if (type != null) { 106 return type.getIconExpanded(); 107 } 108 109 return null; 110 } 111 112 public String getBigIcon() { 113 if (type != null) { 114 return type.getBigIcon(); 115 } 116 return null; 117 } 118 119 public String getBigIconExpanded() { 120 if (type != null) { 121 return type.getBigIconExpanded(); 122 } 123 return null; 124 } 125 126 public String getId() { 127 if (type != null) { 128 return type.getId(); 129 } 130 131 return null; 132 } 133 134 public String getLabel() { 135 if (type != null) { 136 return type.getLabel(); 137 } 138 139 return null; 140 } 141 142 public String getDescription() { 143 if (type != null) { 144 return type.getDescription(); 145 } 146 147 return null; 148 } 149 150 public String[] getLayouts(String mode) { 151 if (type != null) { 152 return type.getLayouts(mode); 153 } 154 return null; 155 } 156 157 public String[] getLayouts(String mode, String defaultMode) { 158 if (type != null) { 159 return type.getLayouts(mode, defaultMode); 160 } 161 return null; 162 } 163 164 public String getView(String viewId) { 165 if (type != null) { 166 TypeView view = type.getView(viewId); 167 if (view != null) { 168 return view.getValue(); 169 } 170 } 171 return null; 172 } 173 174 public TypeView[] getViews() { 175 if (type != null) { 176 return type.getViews(); 177 } 178 179 return null; 180 } 181 182 public String[] getContentViews(String category) { 183 if (type != null) { 184 return type.getContentViews(category); 185 } 186 return null; 187 } 188 189 @Override 190 public Map<String, String[]> getContentViews() { 191 if (type != null) { 192 Map<String, String[]> res = new LinkedHashMap<String, String[]>(); 193 Map<String, DocumentContentViews> defs = type.getContentViews(); 194 if (defs != null) { 195 for (Map.Entry<String, DocumentContentViews> def : defs.entrySet()) { 196 res.put(def.getKey(), def.getValue().getContentViewNames()); 197 } 198 } 199 return res; 200 } 201 return null; 202 } 203 204 @Override 205 public Map<String, String[]> getContentViewsForExport() { 206 if (type != null) { 207 Map<String, String[]> res = new LinkedHashMap<String, String[]>(); 208 Map<String, DocumentContentViews> defs = type.getContentViews(); 209 if (defs != null) { 210 for (Map.Entry<String, DocumentContentViews> def : defs.entrySet()) { 211 String[] cvsByCat = def.getValue().getContentViewNamesForExport(); 212 if (cvsByCat != null && cvsByCat.length > 0) { 213 res.put(def.getKey(), cvsByCat); 214 } 215 } 216 } 217 return res; 218 } 219 return null; 220 } 221}