Back to index

plone3  3.1.7
schema.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU Gefneral Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """ATCT ZConfig schema loader
00020 
00021 """
00022 __author__  = 'Christian Heimes <tiran@cheimes.de>'
00023 __docformat__ = 'restructuredtext'
00024 
00025 import os
00026 
00027 from ZConfig.datatypes import Registry
00028 from ZConfig.loader import SchemaLoader
00029 from Products.ATContentTypes.configuration import datatype
00030 
00031 # schema file
00032 DIR = os.path.dirname(os.path.abspath(__file__))
00033 SCHEMA_FILE_NAME = 'schema.xml'
00034 SCHEMA_FILE = os.path.join(DIR, SCHEMA_FILE_NAME)
00035 
00036 # registry
00037 # ATCT is using its own datatypes registry to add additional
00038 # handlers.
00039 atctRegistry = Registry()
00040 atctRegistry.register('permission', datatype.permission_handler)
00041 atctRegistry.register('identifer_none', datatype.identifier_none)
00042 atctRegistry.register('byte-size-in-mb', datatype.byte_size_in_mb)
00043 atctRegistry.register('image-dimension', datatype.image_dimension)
00044 atctRegistry.register('image-dimension-or-no', datatype.image_dimension_or_no)
00045 atctRegistry.register('pil-algo', datatype.pil_algo)
00046 
00047 # schema
00048 atctSchema = None
00049 def loadSchema(file, registry=atctRegistry, overwrite=False):
00050     """Loads a schema file
00051     
00052     * file
00053       A path to a file
00054     * registry
00055       A ZConfig datatypes registry instance
00056     * overwrite
00057       Overwriting the existing global schema is not possible unless overwrite
00058       is set to true. Useful only for unit testing.
00059     """
00060     global atctSchema
00061     if atctSchema is not None and not overwrite:
00062         raise RuntimeError, 'Schema is already loaded'
00063     schemaLoader = SchemaLoader(registry=registry)
00064     atctSchema = schemaLoader.loadURL(file)
00065     return atctSchema
00066 
00067 loadSchema(SCHEMA_FILE)
00068 
00069 __all__ = ('atctSchema',)