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 * Nuxeo - initial API and implementation 018 * 019 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ 020 */ 021 022package org.nuxeo.ecm.platform.types.adapter; 023 024import java.util.LinkedHashMap; 025import java.util.Map; 026 027import org.nuxeo.ecm.core.api.DocumentModel; 028import org.nuxeo.ecm.platform.types.DocumentContentViews; 029import org.nuxeo.ecm.platform.types.SubType; 030import org.nuxeo.ecm.platform.types.Type; 031import org.nuxeo.ecm.platform.types.TypeManager; 032import org.nuxeo.ecm.platform.types.TypeView; 033import org.nuxeo.runtime.api.Framework; 034 035/** 036 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 037 */ 038public class TypeInfoAdapter implements TypeInfo { 039 040 private final Type type; 041 042 public TypeInfoAdapter(DocumentModel doc) { 043 TypeManager mgr = Framework.getService(TypeManager.class); 044 type = mgr.getType(doc.getType()); 045 } 046 047 public String[] getActions() { 048 if (type != null) { 049 return type.getActions(); 050 } 051 return null; 052 } 053 054 public Map<String, SubType> getAllowedSubTypes() { 055 if (type != null) { 056 return type.getAllowedSubTypes(); 057 } 058 059 return null; 060 } 061 062 /** 063 * @deprecated Use {@link #getId} instead. 064 */ 065 @Deprecated 066 public String getCoreType() { 067 if (type != null) { 068 return type.getId(); 069 } 070 071 return null; 072 } 073 074 public String getCreateView() { 075 if (type != null) { 076 return type.getCreateView(); 077 } 078 079 return null; 080 } 081 082 public String getDefaultView() { 083 if (type != null) { 084 return type.getDefaultView(); 085 } 086 087 return null; 088 } 089 090 public String getEditView() { 091 if (type != null) { 092 return type.getEditView(); 093 } 094 095 return null; 096 } 097 098 public String getIcon() { 099 if (type != null) { 100 return type.getIcon(); 101 } 102 103 return null; 104 } 105 106 public String getIconExpanded() { 107 if (type != null) { 108 return type.getIconExpanded(); 109 } 110 111 return null; 112 } 113 114 public String getBigIcon() { 115 if (type != null) { 116 return type.getBigIcon(); 117 } 118 return null; 119 } 120 121 public String getBigIconExpanded() { 122 if (type != null) { 123 return type.getBigIconExpanded(); 124 } 125 return null; 126 } 127 128 public String getId() { 129 if (type != null) { 130 return type.getId(); 131 } 132 133 return null; 134 } 135 136 public String getLabel() { 137 if (type != null) { 138 return type.getLabel(); 139 } 140 141 return null; 142 } 143 144 public String getDescription() { 145 if (type != null) { 146 return type.getDescription(); 147 } 148 149 return null; 150 } 151 152 public String[] getLayouts(String mode) { 153 if (type != null) { 154 return type.getLayouts(mode); 155 } 156 return null; 157 } 158 159 public String[] getLayouts(String mode, String defaultMode) { 160 if (type != null) { 161 return type.getLayouts(mode, defaultMode); 162 } 163 return null; 164 } 165 166 public String getView(String viewId) { 167 if (type != null) { 168 TypeView view = type.getView(viewId); 169 if (view != null) { 170 return view.getValue(); 171 } 172 } 173 return null; 174 } 175 176 public TypeView[] getViews() { 177 if (type != null) { 178 return type.getViews(); 179 } 180 181 return null; 182 } 183 184 public String[] getContentViews(String category) { 185 if (type != null) { 186 return type.getContentViews(category); 187 } 188 return null; 189 } 190 191 @Override 192 public Map<String, String[]> getContentViews() { 193 if (type != null) { 194 Map<String, String[]> res = new LinkedHashMap<String, String[]>(); 195 Map<String, DocumentContentViews> defs = type.getContentViews(); 196 if (defs != null) { 197 for (Map.Entry<String, DocumentContentViews> def : defs.entrySet()) { 198 res.put(def.getKey(), def.getValue().getContentViewNames()); 199 } 200 } 201 return res; 202 } 203 return null; 204 } 205 206 @Override 207 public Map<String, String[]> getContentViewsForExport() { 208 if (type != null) { 209 Map<String, String[]> res = new LinkedHashMap<String, String[]>(); 210 Map<String, DocumentContentViews> defs = type.getContentViews(); 211 if (defs != null) { 212 for (Map.Entry<String, DocumentContentViews> def : defs.entrySet()) { 213 String[] cvsByCat = def.getValue().getContentViewNamesForExport(); 214 if (cvsByCat != null && cvsByCat.length > 0) { 215 res.put(def.getKey(), cvsByCat); 216 } 217 } 218 } 219 return res; 220 } 221 return null; 222 } 223}