|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.xml.CmsXmlContentDefinition
public class CmsXmlContentDefinition
Describes the structure definition of an XML content object.
Nested Class Summary | |
---|---|
static class |
CmsXmlContentDefinition.SequenceType
Enumeration of possible sequence types in a content definition. |
Field Summary | |
---|---|
static String |
XSD_ATTRIBUTE_DEFAULT
Constant for the XML schema attribute "mapto". |
static String |
XSD_ATTRIBUTE_ELEMENT_FORM_DEFAULT
Constant for the XML schema attribute "elementFormDefault". |
static String |
XSD_ATTRIBUTE_MAX_OCCURS
Constant for the XML schema attribute "maxOccurs". |
static String |
XSD_ATTRIBUTE_MIN_OCCURS
Constant for the XML schema attribute "minOccurs". |
static String |
XSD_ATTRIBUTE_NAME
Constant for the XML schema attribute "name". |
static String |
XSD_ATTRIBUTE_SCHEMA_LOCATION
Constant for the XML schema attribute "schemaLocation". |
static String |
XSD_ATTRIBUTE_TYPE
Constant for the XML schema attribute "type". |
static String |
XSD_ATTRIBUTE_USE
Constant for the XML schema attribute "use". |
static String |
XSD_ATTRIBUTE_VALUE_LANGUAGE
Constant for the XML schema attribute value "language". |
static String |
XSD_ATTRIBUTE_VALUE_ONE
Constant for the XML schema attribute value "1". |
static String |
XSD_ATTRIBUTE_VALUE_OPTIONAL
Constant for the XML schema attribute value "optional". |
static String |
XSD_ATTRIBUTE_VALUE_QUALIFIED
Constant for the XML schema attribute value "qualified". |
static String |
XSD_ATTRIBUTE_VALUE_REQUIRED
Constant for the XML schema attribute value "required". |
static String |
XSD_ATTRIBUTE_VALUE_UNBOUNDED
Constant for the XML schema attribute value "unbounded". |
static String |
XSD_ATTRIBUTE_VALUE_ZERO
Constant for the XML schema attribute value "0". |
static String |
XSD_INCLUDE_OPENCMS
The opencms default type definition include. |
static Namespace |
XSD_NAMESPACE
The schema definition namespace. |
static QName |
XSD_NODE_ANNOTATION
Constant for the "annotation" node in the XML schema namespace. |
static QName |
XSD_NODE_APPINFO
Constant for the "appinfo" node in the XML schema namespace. |
static QName |
XSD_NODE_ATTRIBUTE
Constant for the "attribute" node in the XML schema namespace. |
static QName |
XSD_NODE_CHOICE
Constant for the "choice" node in the XML schema namespace. |
static QName |
XSD_NODE_COMPLEXTYPE
Constant for the "complexType" node in the XML schema namespace. |
static QName |
XSD_NODE_ELEMENT
Constant for the "element" node in the XML schema namespace. |
static QName |
XSD_NODE_INCLUDE
Constant for the "include" node in the XML schema namespace. |
static QName |
XSD_NODE_SCHEMA
Constant for the "schema" node in the XML schema namespace. |
static QName |
XSD_NODE_SEQUENCE
Constant for the "sequence" node in the XML schema namespace. |
Constructor Summary | |
---|---|
protected |
CmsXmlContentDefinition()
Required empty constructor for clone operation. |
|
CmsXmlContentDefinition(String innerName,
String schemaLocation)
Creates a new XML content definition. |
|
CmsXmlContentDefinition(String outerName,
String innerName,
String schemaLocation)
Creates a new XML content definition. |
Method Summary | |
---|---|
Element |
addDefaultXml(CmsObject cms,
I_CmsXmlDocument document,
Element root,
Locale locale)
Adds the missing default XML according to this content definition to the given document element. |
void |
addInclude(CmsXmlContentDefinition nestedSchema)
Adds a nested (included) XML content definition. |
void |
addType(I_CmsXmlSchemaType type)
Adds the given content type. |
Object |
clone()
Creates a clone of this XML content definition. |
Element |
createDefaultXml(CmsObject cms,
I_CmsXmlDocument document,
Element root,
Locale locale)
Generates the default XML content for this content definition, and append it to the given root element. |
Document |
createDocument(CmsObject cms,
I_CmsXmlDocument document,
Locale locale)
Generates a valid XML document according to the XML schema of this content definition. |
Element |
createLocale(CmsObject cms,
I_CmsXmlDocument document,
Element root,
Locale locale)
Generates a valid locale (language) element for the XML schema of this content definition. |
protected static String |
createTypeName(String name)
Creates the name of the type attribute from the given content name. |
boolean |
equals(Object obj)
|
void |
freeze()
Freezes this content definition, making all internal data structures unmodifiable. |
int |
getChoiceMaxOccurs()
Returns the maxOccurs value for the choice in case this is a xsd:choice content definition. |
static CmsXmlContentDefinition |
getContentDefinitionForResource(CmsObject cms,
CmsResource resource)
Factory method that returns the XML content definition instance for a given resource. |
static CmsXmlContentDefinition |
getContentDefinitionForType(CmsObject cms,
String typeName)
Reads the content definition which is configured for a resource type. |
I_CmsXmlContentHandler |
getContentHandler()
Returns the selected XML content handler for this XML content definition. |
static I_CmsXmlContentHandler |
getContentHandlerForResource(CmsObject cms,
CmsResource resource)
Returns a content handler instance for the given resource. |
Set<CmsXmlContentDefinition> |
getIncludes()
Returns the set of nested (included) XML content definitions. |
String |
getInnerName()
Returns the inner element name of this content definition. |
String |
getOuterName()
Returns the outer element name of this content definition. |
Document |
getSchema()
Generates an XML schema for the content definition. |
String |
getSchemaLocation()
Returns the location from which the XML schema was read (XML system id). |
I_CmsXmlSchemaType |
getSchemaType(String elementPath)
Returns the schema type for the given element name, or null if no
node is defined with this name. |
Set<String> |
getSchemaTypes()
Returns the internal set of schema type names. |
CmsXmlContentDefinition.SequenceType |
getSequenceType()
Returns the sequence type of this content definition. |
String |
getTypeName()
Returns the main type name of this XML content definition. |
List<I_CmsXmlSchemaType> |
getTypeSequence()
Returns the type sequence, contains instances of I_CmsXmlSchemaType . |
int |
hashCode()
|
protected void |
setInnerName(String innerName)
Sets the inner element name to use for the content definition. |
protected void |
setOuterName(String outerName)
Sets the outer element name to use for the content definition. |
static CmsXmlContentDefinition |
unmarshal(byte[] xmlData,
String schemaLocation,
EntityResolver resolver)
Factory method to unmarshal (read) a XML content definition instance from a byte array that contains XML data. |
static CmsXmlContentDefinition |
unmarshal(CmsObject cms,
String resourcename)
Factory method to unmarshal (read) a XML content definition instance from the OpenCms VFS resource name. |
static CmsXmlContentDefinition |
unmarshal(Document document,
String schemaLocation)
Factory method to unmarshal (read) a XML content definition instance from a XML document. |
static CmsXmlContentDefinition |
unmarshal(InputSource source,
String schemaLocation,
EntityResolver resolver)
Factory method to unmarshal (read) a XML content definition instance from a XML InputSource. |
static CmsXmlContentDefinition |
unmarshal(String schemaLocation,
EntityResolver resolver)
Factory method to unmarshal (read) a XML content definition instance from a given XML schema location. |
static CmsXmlContentDefinition |
unmarshal(String xmlData,
String schemaLocation,
EntityResolver resolver)
Factory method to unmarshal (read) a XML content definition instance from a String that contains XML data. |
protected static String |
validateAttribute(Element element,
String attributeName,
String requiredValue)
Validates if a given attribute exists at the given element with an (optional) specified value. |
protected static void |
validateAttributesExists(Element element,
String[] requiredAttributes,
String[] optionalAttributes)
Validates if a given element has exactly the required attributes set. |
protected static org.opencms.xml.CmsXmlComplexTypeSequence |
validateComplexTypeSequence(Element element,
Set<CmsXmlContentDefinition> includes)
Validates the given element as a complex type sequence. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String XSD_ATTRIBUTE_DEFAULT
public static final String XSD_ATTRIBUTE_ELEMENT_FORM_DEFAULT
public static final String XSD_ATTRIBUTE_MAX_OCCURS
public static final String XSD_ATTRIBUTE_MIN_OCCURS
public static final String XSD_ATTRIBUTE_NAME
public static final String XSD_ATTRIBUTE_SCHEMA_LOCATION
public static final String XSD_ATTRIBUTE_TYPE
public static final String XSD_ATTRIBUTE_USE
public static final String XSD_ATTRIBUTE_VALUE_LANGUAGE
public static final String XSD_ATTRIBUTE_VALUE_ONE
public static final String XSD_ATTRIBUTE_VALUE_OPTIONAL
public static final String XSD_ATTRIBUTE_VALUE_QUALIFIED
public static final String XSD_ATTRIBUTE_VALUE_REQUIRED
public static final String XSD_ATTRIBUTE_VALUE_UNBOUNDED
public static final String XSD_ATTRIBUTE_VALUE_ZERO
public static final String XSD_INCLUDE_OPENCMS
public static final Namespace XSD_NAMESPACE
public static final QName XSD_NODE_ANNOTATION
public static final QName XSD_NODE_APPINFO
public static final QName XSD_NODE_ATTRIBUTE
public static final QName XSD_NODE_CHOICE
public static final QName XSD_NODE_COMPLEXTYPE
public static final QName XSD_NODE_ELEMENT
public static final QName XSD_NODE_INCLUDE
public static final QName XSD_NODE_SCHEMA
public static final QName XSD_NODE_SEQUENCE
Constructor Detail |
---|
public CmsXmlContentDefinition(String innerName, String schemaLocation)
innerName
- the inner element name to use for the content definitonschemaLocation
- the location from which the XML schema was read (system id)public CmsXmlContentDefinition(String outerName, String innerName, String schemaLocation)
outerName
- the outer element name to use for the content definitioninnerName
- the inner element name to use for the content definitionschemaLocation
- the location from which the XML schema was read (system id)protected CmsXmlContentDefinition()
Method Detail |
---|
public static CmsXmlContentDefinition getContentDefinitionForResource(CmsObject cms, CmsResource resource) throws CmsException
cms
- the cms-objectresource
- the resource
CmsException
- if something goes wrongpublic static CmsXmlContentDefinition getContentDefinitionForType(CmsObject cms, String typeName) throws CmsException
cms
- the current CMS contexttypeName
- the type name
CmsException
- if something goes wrongpublic static I_CmsXmlContentHandler getContentHandlerForResource(CmsObject cms, CmsResource resource) throws CmsException
cms
- the cms-objectresource
- the resource
CmsException
- if something goes wrongpublic static CmsXmlContentDefinition unmarshal(byte[] xmlData, String schemaLocation, EntityResolver resolver) throws CmsXmlException
xmlData
- the XML data in a byte arrayschemaLocation
- the location from which the XML schema was read (system id)resolver
- the XML entity resolver to use
CmsXmlException
- if something goes wrongpublic static CmsXmlContentDefinition unmarshal(CmsObject cms, String resourcename) throws CmsXmlException
cms
- the current users CmsObjectresourcename
- the resource name to unmarshal the XML content definition from
CmsXmlException
- if something goes wrongpublic static CmsXmlContentDefinition unmarshal(Document document, String schemaLocation) throws CmsXmlException
This method does additional validation to ensure the document has the required XML structure for a OpenCms content definition schema.
document
- the XML document to generate a XML content definition fromschemaLocation
- the location from which the XML schema was read (system id)
CmsXmlException
- if something goes wrongpublic static CmsXmlContentDefinition unmarshal(InputSource source, String schemaLocation, EntityResolver resolver) throws CmsXmlException
source
- the XML InputSource to useschemaLocation
- the location from which the XML schema was read (system id)resolver
- the XML entity resolver to use
CmsXmlException
- if something goes wrongpublic static CmsXmlContentDefinition unmarshal(String schemaLocation, EntityResolver resolver) throws CmsXmlException, SAXException, IOException
The XML content definition data to unmarshal will be read from the provided schema location using an XML InputSource.
schemaLocation
- the location from which to read the XML schema (system id)resolver
- the XML entity resolver to use
CmsXmlException
- if something goes wrong
SAXException
- if the XML schema location could not be converted to an XML InputSource
IOException
- if the XML schema location could not be converted to an XML InputSourcepublic static CmsXmlContentDefinition unmarshal(String xmlData, String schemaLocation, EntityResolver resolver) throws CmsXmlException
xmlData
- the XML data in a StringschemaLocation
- the location from which the XML schema was read (system id)resolver
- the XML entity resolver to use
CmsXmlException
- if something goes wrongprotected static String createTypeName(String name)
name
- the name to use
protected static String validateAttribute(Element element, String attributeName, String requiredValue) throws CmsXmlException
If the required value is not null
, the attribute must have exactly this
value set.
If no value is required, some simple validation is performed on the attribute value, like a check that the value does not have leading or trailing white spaces.
element
- the element to validateattributeName
- the attribute to check forrequiredValue
- the required value of the attribute, or null
if any value is allowed
CmsXmlException
- if the element does not have the required attribute set, or if the validation failsprotected static void validateAttributesExists(Element element, String[] requiredAttributes, String[] optionalAttributes) throws CmsXmlException
element
- the element to validaterequiredAttributes
- the list of required attributesoptionalAttributes
- the list of optional attributes
CmsXmlException
- if the validation failsprotected static org.opencms.xml.CmsXmlComplexTypeSequence validateComplexTypeSequence(Element element, Set<CmsXmlContentDefinition> includes) throws CmsXmlException
element
- the element to validateincludes
- the XML schema includes
CmsXmlException
- if the validation failspublic Element addDefaultXml(CmsObject cms, I_CmsXmlDocument document, Element root, Locale locale)
In case the root element already contains sub nodes, only missing sub nodes are added.
cms
- the current users OpenCms contextdocument
- the document where the XML is added in (required for default XML generation)root
- the root node to add the missing XML forlocale
- the locale to add the XML for
public void addInclude(CmsXmlContentDefinition nestedSchema)
nestedSchema
- the nested (included) XML content definition to addpublic void addType(I_CmsXmlSchemaType type) throws CmsXmlException
type
- the content type to add
CmsXmlException
- in case an unregistered type is addedpublic Object clone()
clone
in class Object
public Element createDefaultXml(CmsObject cms, I_CmsXmlDocument document, Element root, Locale locale)
Please note: The default values for the annotations are read from the content definition of the given document. For a nested content definitions, this means that all defaults are set in the annotations of the "outer" or "main" content definition.
cms
- the current users OpenCms contextdocument
- the OpenCms XML document the XML is created forroot
- the node of the document where to append the generated XML tolocale
- the locale to create the default element in the document with
public Document createDocument(CmsObject cms, I_CmsXmlDocument document, Locale locale)
cms
- the current users OpenCms contextdocument
- the OpenCms XML document the XML is created forlocale
- the locale to create the default element in the document with
public Element createLocale(CmsObject cms, I_CmsXmlDocument document, Element root, Locale locale)
cms
- the current users OpenCms contextdocument
- the OpenCms XML document the XML is created forroot
- the root node of the document where to append the locale tolocale
- the locale to create the default element in the document with
public boolean equals(Object obj)
equals
in class Object
Object.equals(java.lang.Object)
public void freeze()
This is required to prevent modification of a cached content definition.
public int getChoiceMaxOccurs()
xsd:choice
content definition.
This content definition is a xsd:choice
sequence if the returned value is larger then 0.
xsd:choice
content definitionpublic I_CmsXmlContentHandler getContentHandler()
If no specific XML content handler was provided in the "appinfo" node of the
XML schema, the default XML content handler
is used.CmsDefaultXmlContentHandler
public Set<CmsXmlContentDefinition> getIncludes()
public String getInnerName()
public String getOuterName()
public Document getSchema()
public String getSchemaLocation()
public I_CmsXmlSchemaType getSchemaType(String elementPath)
null
if no
node is defined with this name.
elementPath
- the element xpath to look up the type for
null
if no
node is defined with this namepublic Set<String> getSchemaTypes()
public CmsXmlContentDefinition.SequenceType getSequenceType()
public String getTypeName()
public List<I_CmsXmlSchemaType> getTypeSequence()
I_CmsXmlSchemaType
.
I_CmsXmlSchemaType
public int hashCode()
hashCode
in class Object
Object.hashCode()
protected void setInnerName(String innerName)
innerName
- the inner element name to setprotected void setOuterName(String outerName)
outerName
- the outer element name to set
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |