boolean validateOnly)
throws Exception {
// initialize
MessageBroker msgBroker = extractMessageBroker();
Schema schema = null;
// find the metadata editor form
UIViewRoot root = getContextBroker().extractViewRoot();
UIComponent editorForm = root.findComponent("mdEditor");
if (editorForm == null) {
String sMsg = "Programming error: The mdEditor form connot be located.";
throw new SchemaException(sMsg);
}
// determine the currently open schema
String sOpenSchemaKey = getOpenSchemaKey();
if (sOpenSchemaKey.length() == 0) {
String sMsg = "Programming error: The openSchemaKey was not specified.";
throw new SchemaException(sMsg);
} else {
MetadataDocument document = new MetadataDocument();
schema = document.prepareForCreate(context,sOpenSchemaKey);
}
// un-bind editor values, validate the input
UiContext uiContext = new UiContext();
schema.unBind(uiContext,editorForm);
try {
if (!asDraft) schema.validate();
} catch (ValidationException e) {
for (ValidationError error: e.getValidationErrors()) {
if (error.getSection() != null) {
if (!error.getSection().getOpen()) {
error.getSection().forceOpen(editorForm);
}
}
}
throw e;
}
// update the document
Document dom = schema.loadTemplate();
schema.update(dom);
String sXml = XmlIoUtil.domToString(dom);
getLogger().finer("Updated template xml:\n"+sXml);
// prepare the publisher
getSelectablePublishers().setSelectedKey(getOnBehalfOf());