001/* 002 * (C) Copyright 2010 Nuxeo SA (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 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.types; 018 019import java.io.Serializable; 020import java.util.ArrayList; 021import java.util.List; 022 023import org.nuxeo.common.xmap.annotation.XNode; 024import org.nuxeo.common.xmap.annotation.XNodeList; 025import org.nuxeo.common.xmap.annotation.XObject; 026 027/** 028 * Content view descriptor put on document types. 029 * 030 * @author Anahide Tchertchian 031 * @since 5.4 032 */ 033@XObject("contentViews") 034public class DocumentContentViews implements Serializable { 035 036 private static final long serialVersionUID = 1L; 037 038 @XNode("@append") 039 boolean append = false; 040 041 @XNodeList(value = "contentView", type = DocumentContentView[].class, componentType = DocumentContentView.class) 042 DocumentContentView[] contentViews = new DocumentContentView[0]; 043 044 public DocumentContentView[] getContentViews() { 045 return contentViews; 046 } 047 048 public boolean getAppend() { 049 return append; 050 } 051 052 public String[] getContentViewNames() { 053 if (contentViews != null) { 054 String[] res = new String[contentViews.length]; 055 for (int i = 0; i < contentViews.length; i++) { 056 res[i] = contentViews[i].getContentViewName(); 057 } 058 return res; 059 } 060 return null; 061 } 062 063 public String[] getContentViewNamesForExport() { 064 List<String> res = new ArrayList<String>(); 065 if (contentViews != null) { 066 for (DocumentContentView contentView : contentViews) { 067 if (contentView.getShowInExportView()) { 068 res.add(contentView.getContentViewName()); 069 } 070 } 071 } 072 return res.toArray(new String[] {}); 073 } 074 075 /** 076 * Clone to handle hot reload 077 * 078 * @since 5.6 079 */ 080 @Override 081 public DocumentContentViews clone() { 082 DocumentContentViews clone = new DocumentContentViews(); 083 clone.append = getAppend(); 084 DocumentContentView[] cvs = getContentViews(); 085 if (cvs != null) { 086 DocumentContentView[] ccvs = new DocumentContentView[cvs.length]; 087 for (int i = 0; i < cvs.length; i++) { 088 ccvs[i] = cvs[i].clone(); 089 } 090 clone.contentViews = ccvs; 091 } 092 return clone; 093 } 094 095}