Fix for ETHREEOH-1811, ETHREEOH-866 & ETHREEOH-2226: Issue with required field nodes within optional parent node that is a complextype

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@17083 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2009-10-22 10:58:34 +00:00
parent d5fa19de9f
commit fc7c241ce3
4 changed files with 168 additions and 5 deletions

View File

@@ -1283,9 +1283,10 @@ public class Schema2XForms implements Serializable
" occurs " + occurs);
// create the <xforms:bind> element and add it to the model.
boolean isRepeated = occurs.isRepeated() || (occurs.isOptional() && (controlType instanceof XSSimpleTypeDefinition == false));
final Element bindElement =
this.createBind(xformsDocument,
pathToRoot + (occurs.isRepeated() ? "[position() != last()]" : ""));
pathToRoot + (isRepeated ? "[position() != last()]" : ""));
final String bindId = bindElement.getAttributeNS(null, "id");
modelSection.appendChild(bindElement);
@@ -1715,7 +1716,7 @@ public class Schema2XForms implements Serializable
" default instance element for " + elementName +
" at path " + path);
// update the default instance
if (occurs.isRepeated())
if (occurs.isRepeated() || (occurs.isOptional() && (element.getTypeDefinition() instanceof XSSimpleTypeDefinition == false)))
{
LOGGER.debug("adding " + (occurs.minimum + 1) +
" default instance elements for " + elementName +
@@ -1758,7 +1759,8 @@ public class Schema2XForms implements Serializable
{
// add xforms:repeat section if this element re-occurs
if (o.maximum == 1)
if ((o.isOptional() && controlType instanceof XSSimpleTypeDefinition) ||
(o.maximum == 1 && o.minimum == 1))
{
return formSection;
}
@@ -1854,14 +1856,15 @@ public class Schema2XForms implements Serializable
}
// create the <xforms:bind> element and add it to the model.
boolean isRepeated = occurs.isRepeated() || (occurs.isOptional() && (controlType instanceof XSSimpleTypeDefinition == false));
Element bindElement =
this.createBind(xformsDocument, pathToRoot + (occurs.isRepeated() ? "[position() != last()]" : ""));
this.createBind(xformsDocument, pathToRoot + (isRepeated ? "[position() != last()]" : ""));
String bindId = bindElement.getAttributeNS(null, "id");
modelSection.appendChild(bindElement);
bindElement = this.startBindElement(bindElement, schema, controlType, owner, occurs);
// add a group if a repeat !
if (owner instanceof XSElementDeclaration && occurs.maximum != 1)
if (owner instanceof XSElementDeclaration && occurs.isRepeated())
{
final Element groupElement = this.createGroup(xformsDocument,
modelSection,

View File

@@ -72,6 +72,11 @@ public class SchemaUtil
return this.isUnbounded() || this.maximum > 1;
}
public boolean isOptional()
{
return this.minimum == 0 && this.maximum == 1;
}
public boolean isUnbounded()
{
return this.maximum == UNBOUNDED;

View File

@@ -0,0 +1,103 @@
<?xml version="1.0"?>
<!--
* Copyright (C) 2005-2009 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:alf="http://www.alfresco.org"
xmlns:article="http://www.alfresco.org/alfresco/article"
targetNamespace="http://www.alfresco.org/alfresco/article"
elementFormDefault="qualified">
<!-- List of locales (languages) that articles can be created with -->
<xs:simpleType name="localeType">
<xs:restriction base="xs:normalizedString">
<xs:enumeration value="en_US">
<xs:annotation>
<xs:appinfo>
<alf:label>English (US)</alf:label>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="jp_JP">
<xs:annotation>
<xs:appinfo>
<alf:label>Japanese</alf:label>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<!-- Defines the Photo complex type -->
<xs:complexType name="photoType">
<xs:sequence>
<xs:element name="Image" type="xs:anyURI" minOccurs="1" maxOccurs="1"/>
<xs:element name="Caption" type="xs:normalizedString" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<!-- Defines the Article complex type -->
<xs:complexType name="articleType">
<xs:sequence>
<xs:element name="Title" type="xs:normalizedString" minOccurs="1" maxOccurs="1" />
<xs:element name="Language" type="article:localeType" minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<alf:appearance>minimal</alf:appearance>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Keyword" type="xs:normalizedString" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="Body" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="Photo" type="article:photoType" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<!-- Defines the Multi-lingual Article type (a set of Articles) -->
<xs:complexType name="multilingualArticleType">
<xs:sequence>
<xs:element name="MultilingualArticle" type="article:articleType" minOccurs="1" maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<alf:label>Article</alf:label>
</xs:appinfo>
</xs:annotation>
<!-- Note: these constraints aren't verified by Alfresco, but at the very least serve as useful documentation
on what the intended data validity rules are. -->
<xs:unique name="UniqueLanguage">
<xs:selector xpath="article:language" />
<xs:field xpath="." />
</xs:unique>
<xs:unique name="UniqueKeyword">
<xs:selector xpath="article:keyword" />
<xs:field xpath="." />
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
<!-- defines the form for creating an article -->
<xs:element name="article" type="article:multilingualArticleType" />
</xs:schema>

View File

@@ -0,0 +1,52 @@
<?xml version="1.0"?>
<!--
* Copyright (C) 2005-2009 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:alf="http://www.alfresco.org"
xmlns:article="http://www.alfresco.org/alfresco/article"
targetNamespace="http://www.alfresco.org/alfresco/article"
elementFormDefault="qualified">
<!-- Defines the Photo complex type -->
<xs:complexType name="photoType">
<xs:sequence>
<xs:element name="Image" type="xs:normalizedString" minOccurs="1" maxOccurs="1" />
<xs:element name="Caption" type="xs:normalizedString" minOccurs="0" maxOccurs="1" />
<!--<xs:element name="Keywords" type="xs:anyType" minOccurs="0" />-->
</xs:sequence>
</xs:complexType>
<xs:element name="optreq">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:normalizedString" minOccurs="1" maxOccurs="1" />
<xs:element name="title" type="xs:normalizedString" minOccurs="0" maxOccurs="1" />
<xs:element name="keywords" type="xs:normalizedString" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="photo" type="article:photoType" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>