localizing xforms codebase. adding javascript hash for string used from js.

multibyte fixes

appearance hints for textareas (full = rich text editor, minimal = plain text)

using xs:string for xforms:textarea
using xs:normalizedString for xforms:input

IMPORTANT:  you will need to recreate all forms in the web project after i check this in.  and for any of your own forms, you need to use xs:normalizedString as the type for textfields.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5028 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2007-02-03 00:01:08 +00:00
parent c971f1f818
commit f6bf4acd5d
24 changed files with 278 additions and 124 deletions

View File

@@ -555,7 +555,9 @@ public class Schema2XForms
final ResourceBundle resourceBundle)
{
if (annotation == null)
{
return null;
}
// write annotation to empty doc
final Document doc = XMLUtil.newDocument();
annotation.writeAnnotation(doc, XSAnnotation.W3C_DOM_DOCUMENT);
@@ -664,7 +666,9 @@ public class Schema2XForms
//remove "@" in nodeset
String name = nodeset.substring(1);
if (name.equals(attributeName))
{
bindId = bind.getAttributeNS(null, "id");
}
}
}
@@ -715,7 +719,6 @@ public class Schema2XForms
? null
: currentAttributeUse.getConstraintValue());
defaultInstanceElement.setAttributeNS(this.targetNamespace,
// XXXarielb - i probably need the prefix here i.e. "alf:" + attributeName
attributeName,
defaultValue);
}
@@ -1013,13 +1016,17 @@ public class Schema2XForms
}
else
{
final SchemaUtil.Occurance o = SchemaUtil.getOccurance(elementDecl);
//create the bind in case it is a repeat
LOGGER.debug("Adding empty bind for control " + controlType +
" type " + typeName +
" nodeset " + pathToRoot);
" nodeset " + pathToRoot +
" occurs " + o);
// create the <xforms:bind> element and add it to the model.
final Element bindElement = this.createBind(xformsDocument, pathToRoot);
final Element bindElement =
this.createBind(xformsDocument,
pathToRoot + (o.isRepeated() ? "[position() != last()]" : ""));
final String bindId = bindElement.getAttributeNS(null, "id");
modelSection.appendChild(bindElement);
@@ -1027,7 +1034,7 @@ public class Schema2XForms
schema,
controlType,
null,
SchemaUtil.getOccurance(elementDecl));
o);
}
return this.addComplexType(xformsDocument,
modelSection,
@@ -1443,7 +1450,7 @@ public class Schema2XForms
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("AddRepeatIfNecessary for multiple element for type " +
controlType.getName() + ", maxOccurs=" + o.maximum);
controlType.getName() + ", maxOccurs = " + o.maximum);
}
final Element repeatSection =
@@ -1688,8 +1695,10 @@ public class Schema2XForms
else
{
formControl = this.createControlForAtomicType(xformsDocument,
(XSSimpleTypeDefinition)controlType,
owner,
caption,
(XSSimpleTypeDefinition)controlType);
resourceBundle);
}
formControl.setAttributeNS(NamespaceConstants.XFORMS_NS,
@@ -1850,19 +1859,22 @@ public class Schema2XForms
final ResourceBundle resourceBundle)
{
// add a group node and recurse
final Element groupElement =
final Element result =
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":group");
this.setXFormsId(groupElement);
groupElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":appearance",
"full");
//groupElement = (Element) formSection.appendChild(groupElement);
formSection.appendChild(groupElement);
groupElement.appendChild(this.createLabel(xformsDocument,
this.createCaption(owner, resourceBundle)));
return groupElement;
this.setXFormsId(result);
final String appearance = this.extractPropertyFromAnnotation(NamespaceService.ALFRESCO_URI,
"appearance",
this.getAnnotation(owner),
resourceBundle);
result.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":appearance",
appearance == null || appearance.length() == 0 ? "full" : appearance);
formSection.appendChild(result);
result.appendChild(this.createLabel(xformsDocument,
this.createCaption(owner, resourceBundle)));
return result;
}
public String createCaption(final String text,
@@ -2003,10 +2015,9 @@ public class Schema2XForms
final Element control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":textarea");
this.setXFormsId(control);
// control.setAttributeNS(Schema2XForms.CHIBA_NS,
// Schema2XForms.CHIBA_PREFIX + "height",
// "3");
control.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":appearance",
"compact");
control.appendChild(this.createLabel(xformsDocument, caption));
return control;
}
@@ -2025,25 +2036,33 @@ public class Schema2XForms
* @param controlType The XML Schema type for which the form control is to be created.
* @return The element for the form control.
*/
public Element createControlForAtomicType(Document xformsDocument,
String caption,
XSSimpleTypeDefinition controlType)
public Element createControlForAtomicType(final Document xformsDocument,
final XSSimpleTypeDefinition controlType,
final XSObject owner,
final String caption,
final ResourceBundle resourceBundle)
{
LOGGER.debug("creating a control for atomic type {name: " + controlType.getName() +
", numeric: " + controlType.getNumeric() +
", bounded: " + controlType.getBounded() +
", finite: " + controlType.getFinite() +
", ordered: " + controlType.getOrdered() +
", final: " + controlType.getFinal() +
", minInc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MININCLUSIVE) +
", maxInc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE) +
", minExc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MINEXCLUSIVE) +
", maxExc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE) +
", fractionDigits: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_FRACTIONDIGITS) +
", builtInTypeName: " + SchemaUtil.getBuiltInTypeName(controlType) +
", builtInType: " + SchemaUtil.getBuiltInType(controlType) +
"}");
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("creating a control for atomic type {name: " + controlType.getName() +
", numeric: " + controlType.getNumeric() +
", bounded: " + controlType.getBounded() +
", finite: " + controlType.getFinite() +
", ordered: " + controlType.getOrdered() +
", final: " + controlType.getFinal() +
", minInc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MININCLUSIVE) +
", maxInc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE) +
", minExc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MINEXCLUSIVE) +
", maxExc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE) +
", fractionDigits: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_FRACTIONDIGITS) +
", builtInTypeName: " + SchemaUtil.getBuiltInTypeName(controlType) +
", builtInType: " + SchemaUtil.getBuiltInType(controlType) +
"}");
}
String appearance = this.extractPropertyFromAnnotation(NamespaceService.ALFRESCO_URI,
"appearance",
this.getAnnotation(owner),
resourceBundle);
Element result = null;
if ("boolean".equals(controlType.getName()))
{
@@ -2056,6 +2075,15 @@ public class Schema2XForms
result.appendChild(item);
}
}
else if ("string".equals(controlType.getName()))
{
result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":textarea");
if (appearance == null || appearance.length() == 0)
{
appearance = "compact";
}
}
else if ("anyURI".equals(controlType.getName()))
{
result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
@@ -2100,10 +2128,21 @@ public class Schema2XForms
{
result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":input");
if ((appearance == null || appearance.length() == 0) &&
SchemaUtil.getBuiltInType(controlType) == XSConstants.NORMALIZEDSTRING_DT)
{
appearance = "full";
}
}
this.setXFormsId(result);
result.appendChild(this.createLabel(xformsDocument, caption));
if (appearance != null && appearance.length() != 0)
{
result.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":appearance",
appearance);
}
return result;
}

View File

@@ -17,6 +17,7 @@
package org.alfresco.web.forms.xforms;
import java.io.*;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
@@ -28,6 +29,7 @@ import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.FacesHelper;
import org.chiba.xml.ns.NamespaceConstants;
import org.chiba.xml.xforms.exception.XFormsException;
@@ -46,7 +48,7 @@ public class XFormsProcessor
{ "alfresco", NamespaceService.ALFRESCO_URI, NamespaceService.ALFRESCO_PREFIX }
};
private final String[] JS_SCRIPTS =
private final static String[] JS_SCRIPTS =
{
"/scripts/tiny_mce/" + (LOGGER.isDebugEnabled()
? "tiny_mce_src.js"
@@ -59,6 +61,18 @@ public class XFormsProcessor
};
private final static String[] BUNDLE_KEYS =
{
"validation_provide_values_for_required_fields",
"idle",
"loading",
"add_content",
"go_up",
"cancel",
"upload",
"path"
};
public XFormsProcessor()
{
}
@@ -139,6 +153,17 @@ public class XFormsProcessor
append(ns[0].toUpperCase()).
append("_PREFIX = '").append(ns[2]).append("';\n");
}
final ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
js.append("alfresco_xforms_constants.resources = {\n");
for (String k : BUNDLE_KEYS)
{
js.append(k).
append(": '").
append(bundle.getString(k)).
append("'").
append(k.equals(BUNDLE_KEYS[BUNDLE_KEYS.length - 1]) ? "\n}" : ",\n");
}
e.appendChild(result.createTextNode(js.toString()));
div.appendChild(e);