001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.file.types; 029 030import org.opencms.configuration.CmsConfigurationException; 031import org.opencms.loader.CmsDumpLoader; 032import org.opencms.main.OpenCms; 033 034/** 035 * Resource type descriptor for unknown file types.<p> 036 * 037 * This will be used for file corpses when the resource type is not configured.<p> 038 * 039 * The most common use case is when deleting a module with the resource type definition, 040 * but not the content that uses that resource type definition.<p> 041 * 042 * @since 7.0.0 043 */ 044public class CmsResourceTypeUnknownFile extends A_CmsResourceType { 045 046 /** The type id of this resource type. */ 047 public static final int RESOURCE_TYPE_ID = -1; 048 049 /** The name of this resource type. */ 050 public static final String RESOURCE_TYPE_NAME = "unknown_file"; 051 052 /** Indicates that the static configuration of the resource type has been frozen. */ 053 private static boolean m_staticFrozen; 054 055 /** The static type id of this resource type. */ 056 private static int m_staticTypeId; 057 058 /** The serial version id. */ 059 private static final long serialVersionUID = -2985191622939935673L; 060 061 /** 062 * Default constructor, used to initialize member variables.<p> 063 */ 064 public CmsResourceTypeUnknownFile() { 065 066 super(); 067 m_typeId = RESOURCE_TYPE_ID; 068 m_typeName = RESOURCE_TYPE_NAME; 069 } 070 071 /** 072 * Returns the static type id of this (default) resource type.<p> 073 * 074 * @return the static type id of this (default) resource type 075 */ 076 public static int getStaticTypeId() { 077 078 return m_staticTypeId; 079 } 080 081 /** 082 * Returns the static type name of this (default) resource type.<p> 083 * 084 * @return the static type name of this (default) resource type 085 */ 086 public static String getStaticTypeName() { 087 088 return RESOURCE_TYPE_NAME; 089 } 090 091 /** 092 * @see org.opencms.file.types.I_CmsResourceType#getLoaderId() 093 */ 094 @Override 095 public int getLoaderId() { 096 097 return CmsDumpLoader.RESOURCE_LOADER_ID; 098 } 099 100 /** 101 * @see org.opencms.file.types.A_CmsResourceType#initConfiguration(java.lang.String, java.lang.String, String) 102 */ 103 @Override 104 public void initConfiguration(String name, String id, String className) throws CmsConfigurationException { 105 106 if ((OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) && m_staticFrozen) { 107 // configuration already frozen 108 throw new CmsConfigurationException( 109 Messages.get().container( 110 Messages.ERR_CONFIG_FROZEN_3, 111 this.getClass().getName(), 112 getStaticTypeName(), 113 new Integer(getStaticTypeId()))); 114 } 115 116 if (!RESOURCE_TYPE_NAME.equals(name)) { 117 // default resource type MUST have default name 118 throw new CmsConfigurationException( 119 Messages.get().container( 120 Messages.ERR_INVALID_RESTYPE_CONFIG_NAME_3, 121 this.getClass().getName(), 122 RESOURCE_TYPE_NAME, 123 name)); 124 } 125 126 // freeze the configuration 127 m_staticFrozen = true; 128 129 super.initConfiguration(RESOURCE_TYPE_NAME, id, className); 130 // set static members with values from the configuration 131 m_staticTypeId = m_typeId; 132 } 133}