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