{
// check what submit button was pressed in User Interface
String buttonPressed = Util.getSubmitButton(request, NEXT_BUTTON);
// get the item and current page
Item item = subInfo.getSubmissionItem().getItem();
int currentPage = getCurrentPage(request);
// lookup applicable inputs
Collection c = subInfo.getSubmissionItem().getCollection();
DCInput[] inputs = null;
try
{
inputs = inputsReader.getInputs(c.getHandle()).getPageRows(
currentPage - 1,
subInfo.getSubmissionItem().hasMultipleTitles(),
subInfo.getSubmissionItem().isPublishedBefore());
}
catch (DCInputsReaderException e)
{
throw new ServletException(e);
}
// Step 1:
// clear out all item metadata defined on this page
for (int i = 0; i < inputs.length; i++)
{
if (!inputs[i]
.isVisible(subInfo.isInWorkflow() ? DCInput.WORKFLOW_SCOPE
: DCInput.SUBMISSION_SCOPE))
{
continue;
}
String qualifier = inputs[i].getQualifier();
if (qualifier == null
&& inputs[i].getInputType().equals("qualdrop_value"))
{
qualifier = Item.ANY;
}
item.clearMetadata(inputs[i].getSchema(), inputs[i].getElement(),
qualifier, Item.ANY);
}
// Clear required-field errors first since missing authority
// values can add them too.
clearErrorFields(request);
// Step 2:
// now update the item metadata.
String fieldName;
boolean moreInput = false;
for (int j = 0; j < inputs.length; j++)
{
if (!inputs[j]
.isVisible(subInfo.isInWorkflow() ? DCInput.WORKFLOW_SCOPE
: DCInput.SUBMISSION_SCOPE))
{
continue;
}
String element = inputs[j].getElement();
String qualifier = inputs[j].getQualifier();
String schema = inputs[j].getSchema();
if (qualifier != null && !qualifier.equals(Item.ANY))
{
fieldName = schema + "_" + element + '_' + qualifier;
}
else
{
fieldName = schema + "_" + element;
}
String fieldKey = MetadataAuthorityManager.makeFieldKey(schema, element, qualifier);
ChoiceAuthorityManager cmgr = ChoiceAuthorityManager.getManager();
String inputType = inputs[j].getInputType();
if (inputType.equals("name"))
{
readNames(request, item, schema, element, qualifier, inputs[j]
.getRepeatable());
}
else if (inputType.equals("date"))
{
readDate(request, item, schema, element, qualifier);
}
// choice-controlled input with "select" presentation type is
// always rendered as a dropdown menu
else if (inputType.equals("dropdown") || inputType.equals("list") ||
(cmgr.isChoicesConfigured(fieldKey) &&
"select".equals(cmgr.getPresentation(fieldKey))))
{
String[] vals = request.getParameterValues(fieldName);
if (vals != null)
{
for (int z = 0; z < vals.length; z++)
{
if (!vals[z].equals(""))
{
item.addMetadata(schema, element, qualifier, LANGUAGE_QUALIFIER,
vals[z]);
}
}
}
}
else if (inputType.equals("series"))
{
readSeriesNumbers(request, item, schema, element, qualifier,
inputs[j].getRepeatable());
}
else if (inputType.equals("qualdrop_value"))
{
List quals = getRepeatedParameter(request, schema + "_"
+ element, schema + "_" + element + "_qualifier");
List vals = getRepeatedParameter(request, schema + "_"
+ element, schema + "_" + element + "_value");
for (int z = 0; z < vals.size(); z++)
{
String thisQual = (String) quals.get(z);
if ("".equals(thisQual))
{
thisQual = null;
}
String thisVal = (String) vals.get(z);
if (!buttonPressed.equals("submit_" + schema + "_"
+ element + "_remove_" + z)
&& !thisVal.equals(""))
{
item.addMetadata(schema, element, thisQual, null,
thisVal);
}
}
}
else if ((inputType.equals("onebox"))
|| (inputType.equals("twobox"))
|| (inputType.equals("textarea")))
{
readText(request, item, schema, element, qualifier, inputs[j]
.getRepeatable(), LANGUAGE_QUALIFIER);
}
else
{
throw new ServletException("Field " + fieldName
+ " has an unknown input type: " + inputType);
}
// determine if more input fields were requested
if (!moreInput
&& buttonPressed.equals("submit_" + fieldName + "_add"))
{
subInfo.setMoreBoxesFor(fieldName);
subInfo.setJumpToField(fieldName);
moreInput = true;
}
// was XMLUI's "remove" button pushed?
else if (buttonPressed.equals("submit_" + fieldName + "_delete"))
{
subInfo.setJumpToField(fieldName);
}
}
// Step 3:
// Check to see if any fields are missing
// Only check for required fields if user clicked the "next", the "previous" or the "progress bar" button
if (buttonPressed.equals(NEXT_BUTTON)
|| buttonPressed.startsWith(PROGRESS_BAR_PREFIX)
|| buttonPressed.equals(PREVIOUS_BUTTON)
|| buttonPressed.equals(CANCEL_BUTTON))
{
for (int i = 0; i < inputs.length; i++)
{
DCValue[] values = item.getMetadata(inputs[i].getSchema(),
inputs[i].getElement(), inputs[i].getQualifier(), Item.ANY);
if (inputs[i].isRequired() && values.length == 0)
{
// since this field is missing add to list of error fields