mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
- beginning to respect fixed values from xsd
- fixing bug with default values for select widgets - some more unit tests for repeating items, and xsd attributes - parsing xsd when creating the form and presenting a combobox with element names that are possible root tag names - ensuring that there can't be multiple output methods that output the same extension - moving createxmlcontenttype to createformwizard in wcm where it belongs. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4112 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -226,7 +226,7 @@
|
||||
</wizard>
|
||||
|
||||
<!-- Definition of the Create XML Type wizard -->
|
||||
<wizard name="createForm" managed-bean="CreateXmlContentTypeWizard"
|
||||
<wizard name="createForm" managed-bean="CreateFormWizard"
|
||||
title-id="create_form_title" description-id="create_form_desc"
|
||||
icon="/images/icons/new_content_large.gif">
|
||||
<step name="details" title-id="details" description-id="create_form_step1_desc">
|
||||
|
@@ -14,13 +14,14 @@
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.bean.content;
|
||||
package org.alfresco.web.bean.wcm;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
@@ -31,6 +32,7 @@ import javax.faces.model.DataModel;
|
||||
import javax.faces.model.ListDataModel;
|
||||
import javax.faces.model.SelectItem;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.WCMModel;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
@@ -41,17 +43,19 @@ import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.bean.FileUploadBean;
|
||||
import org.alfresco.web.bean.wizard.BaseWizardBean;
|
||||
import org.alfresco.web.templating.xforms.SchemaFormBuilder;
|
||||
import org.alfresco.web.templating.TemplatingService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.apache.xerces.xs.*;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
* Bean implementation for the "Create XML Form" dialog
|
||||
*
|
||||
* @author arielb
|
||||
*/
|
||||
public class CreateXmlContentTypeWizard extends BaseWizardBean
|
||||
public class CreateFormWizard extends BaseWizardBean
|
||||
{
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -103,7 +107,7 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private final static Log LOGGER =
|
||||
LogFactory.getLog(CreateXmlContentTypeWizard.class);
|
||||
LogFactory.getLog(CreateFormWizard.class);
|
||||
|
||||
private String schemaRootTagName;
|
||||
private String templateName;
|
||||
@@ -262,6 +266,15 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean
|
||||
*/
|
||||
public void addSelectedTemplateOutputMethod(ActionEvent event)
|
||||
{
|
||||
for (TemplateOutputMethodData tomd : this.templateOutputMethods)
|
||||
{
|
||||
if (tomd.getFileExtension().equals(this.fileExtension))
|
||||
{
|
||||
throw new AlfrescoRuntimeException("template output method with extension " + this.fileExtension +
|
||||
" already exists");
|
||||
}
|
||||
}
|
||||
|
||||
final TemplateOutputMethodData data =
|
||||
new TemplateOutputMethodData(this.getTemplateOutputMethodFileName(),
|
||||
this.getTemplateOutputMethodFile(),
|
||||
@@ -421,13 +434,42 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the root tag name to use when processing the schema.
|
||||
* Returns the root tag name to use when processing the schema.
|
||||
*/
|
||||
public String getSchemaRootTagName()
|
||||
{
|
||||
return (this.schemaRootTagName == null && this.getSchemaFileName() != null
|
||||
? this.getSchemaFileName().replaceAll("([^\\.])\\..+", "$1")
|
||||
: this.schemaRootTagName);
|
||||
return this.schemaRootTagName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the possible root tag names for use with the schema based on
|
||||
* the element declarations it defines.
|
||||
*/
|
||||
public List<SelectItem> getSchemaRootTagNameChoices()
|
||||
{
|
||||
final List<SelectItem> result = new LinkedList<SelectItem>();
|
||||
if (this.getSchemaFile() != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
final TemplatingService ts = TemplatingService.getInstance();
|
||||
final Document d = ts.parseXML(this.getSchemaFile());
|
||||
final XSModel xsm = SchemaFormBuilder.loadSchema(d);
|
||||
final XSNamedMap elementsMap = xsm.getComponents(XSConstants.ELEMENT_DECLARATION);
|
||||
for (int i = 0; i < elementsMap.getLength(); i++)
|
||||
{
|
||||
final XSElementDeclaration e = (XSElementDeclaration)elementsMap.item(i);
|
||||
result.add(new SelectItem(e.getName(), e.getName()));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
final String msg = "unable to parse " + this.getSchemaFileName();
|
||||
this.removeUploadedSchemaFile();
|
||||
throw new AlfrescoRuntimeException(msg, e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
@@ -2260,8 +2260,8 @@ public class SchemaFormBuilder
|
||||
bindElement.setAttributeNS(XFORMS_NS,
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset",
|
||||
pathToRoot);
|
||||
bindElement = (Element)modelSection.appendChild(bindElement);
|
||||
bindElement = startBindElement(bindElement, schema, controlType, o);
|
||||
modelSection.appendChild(bindElement);
|
||||
bindElement = this.startBindElement(bindElement, schema, controlType, owner, o);
|
||||
|
||||
// add a group if a repeat !
|
||||
if (owner instanceof XSElementDeclaration && o.maximum != 1)
|
||||
@@ -3331,6 +3331,7 @@ public class SchemaFormBuilder
|
||||
public Element startBindElement(final Element bindElement,
|
||||
final XSModel schema,
|
||||
final XSTypeDefinition controlType,
|
||||
final XSObject owner,
|
||||
final Occurs o)
|
||||
{
|
||||
// START WORKAROUND
|
||||
@@ -3350,10 +3351,22 @@ public class SchemaFormBuilder
|
||||
typeName);
|
||||
}
|
||||
|
||||
final short constraintType =
|
||||
(owner instanceof XSElementDeclaration
|
||||
? ((XSElementDeclaration)owner).getConstraintType()
|
||||
: (owner instanceof XSAttributeDeclaration
|
||||
? ((XSAttributeDeclaration)owner).getConstraintType()
|
||||
: (owner instanceof XSAttributeUse
|
||||
? ((XSAttributeUse)owner).getConstraintType()
|
||||
: XSConstants.VC_NONE)));
|
||||
|
||||
bindElement.setAttributeNS(XFORMS_NS,
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "readonly",
|
||||
(constraintType == XSConstants.VC_FIXED) + "()");
|
||||
|
||||
bindElement.setAttributeNS(XFORMS_NS,
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "required",
|
||||
o.minimum == 0 ? "false()" : "true()");
|
||||
|
||||
(o.minimum != 0) + "()");
|
||||
|
||||
//no more minOccurs & maxOccurs element: add a constraint if maxOccurs>1:
|
||||
//count(.) <= maxOccurs && count(.) >= minOccurs
|
||||
@@ -3451,7 +3464,8 @@ public class SchemaFormBuilder
|
||||
return elementName;
|
||||
}
|
||||
|
||||
private XSModel loadSchema(final Document schemaDocument)
|
||||
//XXXarielb factor out to a utility method...
|
||||
public static XSModel loadSchema(final Document schemaDocument)
|
||||
throws FormBuilderException
|
||||
{
|
||||
try
|
||||
|
@@ -23,7 +23,7 @@
|
||||
</xs:sequence>
|
||||
<xs:attribute name="name" type="xs:string"/>
|
||||
<xs:attribute name="artist" type="xs:string"/>
|
||||
<xs:attribute name="genre" type="genre"/>
|
||||
<xs:attribute name="genre" type="genre" default="classical"/>
|
||||
<xs:attribute name="year" type="xs:gYear"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
elementFormDefault="qualified">
|
||||
<xs:simpleType name="attribute-choices" >
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="string1"/>
|
||||
<xs:enumeration value="string2"/>
|
||||
<xs:enumeration value="string3-is-the-default"/>
|
||||
<xs:enumeration value="string4"/>
|
||||
<xs:enumeration value="string5"/>
|
||||
<xs:enumeration value="string6"/>
|
||||
<xs:enumeration value="string7"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:element name="attributes">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="element_string_no_default"
|
||||
type="xs:string"
|
||||
minOccurs="1"
|
||||
maxOccurs="1"/>
|
||||
<xs:element name="element_string_with_default"
|
||||
type="xs:string"
|
||||
minOccurs="1"
|
||||
maxOccurs="1"
|
||||
default="default string value"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="required_string_no_default"
|
||||
type="xs:string"
|
||||
use="required"/>
|
||||
<xs:attribute name="optional_string_no_default"
|
||||
type="xs:string"
|
||||
use="optional"/>
|
||||
<xs:attribute name="required_string_with_default"
|
||||
type="xs:string"
|
||||
use="required"
|
||||
default="default string value"/>
|
||||
<xs:attribute name="optional_string_with_default"
|
||||
type="xs:string"
|
||||
use="optional"
|
||||
default="default string value"/>
|
||||
<xs:attribute name="fixed_string"
|
||||
type="xs:string"
|
||||
use="optional"
|
||||
fixed="fixed string value"/>
|
||||
<xs:attribute name="required_choices_no_default"
|
||||
type="attribute-choices"
|
||||
use="required"/>
|
||||
<xs:attribute name="optional_choices_no_default"
|
||||
type="attribute-choices"
|
||||
use="optional"/>
|
||||
<xs:attribute name="required_choices_with_default"
|
||||
type="attribute-choices"
|
||||
use="required"
|
||||
default="string3-is-the-default"/>
|
||||
<xs:attribute name="optional_choices_with_default"
|
||||
type="attribute-choices"
|
||||
use="optional"
|
||||
default="string3-is-the-default"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
elementFormDefault="qualified">
|
||||
<xs:complexType name="complex-type" >
|
||||
<xs:sequence>
|
||||
<xs:element name="string" type="xs:string"/>
|
||||
<xs:element name="string2" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:element name="form-1">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="form_1_string" type="xs:string" default="form1"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="form-2">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="form_2_string" type="xs:string" default="form2"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="form-3">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="form_3_complex_type" type="complex-type" default="form2"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
elementFormDefault="qualified">
|
||||
<xs:complexType name="multi-input">
|
||||
<xs:sequence>
|
||||
<xs:element name="string" type="xs:string"/>
|
||||
<xs:element name="int" type="xs:int"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:element name="repeat-multi-simple">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="zero-to-inf-single" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="zero-to-inf-multi" type="multi-input" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
@@ -2065,8 +2065,8 @@
|
||||
<description>
|
||||
The bean that backs up the Create XML Content Type Wizard
|
||||
</description>
|
||||
<managed-bean-name>CreateXmlContentTypeWizard</managed-bean-name>
|
||||
<managed-bean-class>org.alfresco.web.bean.content.CreateXmlContentTypeWizard</managed-bean-class>
|
||||
<managed-bean-name>CreateFormWizard</managed-bean-name>
|
||||
<managed-bean-class>org.alfresco.web.bean.wcm.CreateFormWizard</managed-bean-class>
|
||||
<managed-bean-scope>session</managed-bean-scope>
|
||||
<managed-property>
|
||||
<property-name>nodeService</property-name>
|
||||
|
@@ -29,7 +29,6 @@
|
||||
org.alfresco.web.templating.*" %>
|
||||
<%@ page import="java.io.*" %>
|
||||
<%@ page import="org.alfresco.web.app.Application" %>
|
||||
<%@ page import="org.alfresco.web.bean.content.CreateXmlContentTypeWizard" %>
|
||||
<%@ page import="org.alfresco.web.templating.*" %>
|
||||
<%@ page import="org.w3c.dom.Document" %>
|
||||
<%
|
||||
|
@@ -98,8 +98,10 @@ if (upload == null || upload.getFile() == null)
|
||||
<h:graphicImage id="graphic_image_root_tag_name"
|
||||
value="/images/icons/required_field.gif" alt="Required Field" />
|
||||
<h:outputText id="output_text_root_tag_name" value="#{msg.schema_root_tag_name}:"/>
|
||||
<h:inputText id="schema-root-tag-name" value="#{WizardManager.bean.schemaRootTagName}"
|
||||
maxlength="1024" size="35"/>
|
||||
<h:selectOneMenu id="schema-root-tag-name"
|
||||
value="#{WizardManager.bean.schemaRootTagName}">
|
||||
<f:selectItems value="#{WizardManager.bean.schemaRootTagNameChoices}"/>
|
||||
</h:selectOneMenu>
|
||||
<h:graphicImage id="graphic_image_name" value="/images/icons/required_field.gif" alt="Required Field" />
|
||||
<h:outputText id="output_text_name" value="#{msg.name}:"/>
|
||||
<h:inputText id="file-name" value="#{WizardManager.bean.templateName}"
|
||||
|
@@ -1,36 +0,0 @@
|
||||
<%--
|
||||
Copyright (C) 2005 Alfresco, Inc.
|
||||
|
||||
Licensed under the Mozilla Public License version 1.1
|
||||
with a permitted attribution clause. You may obtain a
|
||||
copy of the License at
|
||||
|
||||
http://www.alfresco.org/legal/license.txt
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
either express or implied. See the License for the specific
|
||||
language governing permissions and limitations under the
|
||||
License.
|
||||
--%>
|
||||
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
|
||||
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
|
||||
<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %>
|
||||
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>
|
||||
<%@ page import="java.io.*" %>
|
||||
<%@ page import="org.alfresco.web.app.Application" %>
|
||||
<%@ page import="org.alfresco.web.bean.content.CreateXmlContentTypeWizard" %>
|
||||
<%@ page import="org.alfresco.web.templating.*" %>
|
||||
<%@ page import="org.w3c.dom.Document" %>
|
||||
<%
|
||||
CreateXmlContentTypeWizard wiz = (CreateXmlContentTypeWizard)
|
||||
Application.getWizardManager().getBean();
|
||||
TemplateType tt = wiz.getTemplateType();
|
||||
TemplateInputMethod tim = tt.getInputMethods().get(0);
|
||||
final InstanceData instanceData = new InstanceData() {
|
||||
public Document getContent() { return null; }
|
||||
public void setContent(Document d) { }
|
||||
};
|
||||
tim.generate(instanceData, tt, out);
|
||||
%>
|
@@ -1,8 +1,6 @@
|
||||
dojo.require("dojo.widget.DebugConsole");
|
||||
dojo.require("dojo.widget.DatePicker");
|
||||
dojo.require("dojo.widget.Button");
|
||||
dojo.require("dojo.widget.validate");
|
||||
dojo.require("dojo.widget.Spinner");
|
||||
dojo.require("dojo.lfx.html");
|
||||
dojo.hostenv.writeIncludes();
|
||||
|
||||
@@ -99,8 +97,12 @@ dojo.declare("alfresco.xforms.Widget",
|
||||
isRequired: function()
|
||||
{
|
||||
var binding = this._getBinding();
|
||||
var required = binding && binding.required == "true()";
|
||||
return required;
|
||||
return binding && binding.required == "true()";
|
||||
},
|
||||
isReadonly: function()
|
||||
{
|
||||
var binding = this._getBinding();
|
||||
return binding && binding.readonly == "true()";
|
||||
},
|
||||
getInitialValue: function()
|
||||
{
|
||||
@@ -274,7 +276,15 @@ dojo.declare("alfresco.xforms.TextField",
|
||||
// value: initial_value
|
||||
// },
|
||||
// this.domNode);
|
||||
if (this.isReadonly())
|
||||
{
|
||||
this.widget.setAttribute("readonly", this.isReadonly());
|
||||
this.widget.setAttribute("disabled", this.isReadonly());
|
||||
}
|
||||
else
|
||||
{
|
||||
dojo.event.connect(this.widget, "onkeyup", this, this._widget_keyUpHandler);
|
||||
}
|
||||
},
|
||||
getValue: function()
|
||||
{
|
||||
@@ -387,7 +397,7 @@ dojo.declare("alfresco.xforms.Select",
|
||||
if (initial_value.indexOf(values[i].value) != -1)
|
||||
{
|
||||
this._selectedValues.push(values[i].value);
|
||||
checkbox.setAttribute("checked", "true");
|
||||
checkbox.checked = true;
|
||||
}
|
||||
dojo.event.connect(checkbox, "onclick", this, this._checkbox_clickHandler);
|
||||
this.widget.appendChild(checkbox);
|
||||
@@ -408,7 +418,7 @@ dojo.declare("alfresco.xforms.Select",
|
||||
if (initial_value.indexOf(values[i].value) != -1)
|
||||
{
|
||||
this._selectedValues.push(values[i].value);
|
||||
option.setAttribute("selected", "true");
|
||||
option.selected = true;
|
||||
}
|
||||
this.widget.appendChild(option);
|
||||
}
|
||||
@@ -479,7 +489,7 @@ dojo.declare("alfresco.xforms.Select1",
|
||||
if (values[i].value == initial_value)
|
||||
{
|
||||
this._selectedValue = initial_value;
|
||||
radio.setAttribute("checked", "true");
|
||||
radio.checked = true;
|
||||
}
|
||||
dojo.event.connect(radio, "onclick", this, this._radio_clickHandler);
|
||||
}
|
||||
@@ -499,7 +509,7 @@ dojo.declare("alfresco.xforms.Select1",
|
||||
if (values[i].value == initial_value)
|
||||
{
|
||||
this._selectedValue = initial_value;
|
||||
option.setAttribute("selected", "true");
|
||||
option.selected = true;
|
||||
}
|
||||
}
|
||||
dojo.event.connect(this.widget, "onchange", this, this._combobox_changeHandler);
|
||||
@@ -1232,8 +1242,10 @@ dojo.declare("alfresco.xforms.XForm",
|
||||
{
|
||||
var id = bind.childNodes[i].getAttribute("id");
|
||||
dojo.debug("loading binding " + id);
|
||||
result[id] = {
|
||||
result[id] =
|
||||
{
|
||||
id: bind.childNodes[i].getAttribute("id"),
|
||||
readonly: bind.childNodes[i].getAttribute("xforms:readonly"),
|
||||
required: bind.childNodes[i].getAttribute("xforms:required"),
|
||||
nodeset: bind.childNodes[i].getAttribute("xforms:nodeset"),
|
||||
type: bind.childNodes[i].getAttribute("xforms:type"),
|
||||
|
Reference in New Issue
Block a user