Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.util;
import java.io.File;
import java.util.*;
import javax.servlet.ServletException;
import org.xml.sax.SAXException;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import org.apache.log4j.Logger;
import org.dspace.core.ConfigurationManager;
/**
* Item Submission configuration generator for DSpace. Reads and parses the
* installed submission process configuration file, item-submission.xml, from
* the configuration directory. This submission process definition details the
* ordering of the steps (and number of steps) that occur during the Item
* Submission Process. There may be multiple Item Submission processes defined,
* where each definition is assigned a unique name.
*
* The file also specifies which collections use which Item Submission process.
* At a minimum, the definitions file must define a default mapping from the
* placeholder collection # to the distinguished submission process 'default'.
* Any collections that use a custom submission process are listed paired with
* the name of the item submission process they use.
*
* @see org.dspace.app.util.SubmissionConfig
* @see org.dspace.app.util.SubmissionStepConfig
*
* @author Tim Donohue based on DCInputsReader by Brian S. Hughes
* @version $Revision: 5844 $
*/
public class SubmissionConfigReader
{
/**
* The ID of the default collection. Will never be the ID of a named
* collection
*/
public static final String DEFAULT_COLLECTION = "default";
/** Prefix of the item submission definition XML file */
static final String SUBMIT_DEF_FILE_PREFIX = "item-submission";
/** Suffix of the item submission definition XML file */
static final String SUBMIT_DEF_FILE_SUFFIX = ".xml";
/** log4j logger */
private static Logger log = Logger.getLogger(SubmissionConfigReader.class);
/** The fully qualified pathname of the directory containing the Item Submission Configuration file */
private String configDir = ConfigurationManager.getProperty("dspace.dir")
+ File.separator + "config" + File.separator;
/**
* Hashmap which stores which submission process configuration is used by
* which collection, computed from the item submission config file
* (specifically, the 'submission-map' tag)
*/
private Map collectionToSubmissionConfig = null;
/**
* Reference to the global submission step definitions defined in the
* "step-definitions" section
*/
private Map> stepDefns = null;
/**
* Reference to the item submission definitions defined in the
* "submission-definitions" section
*/
private Map>> submitDefns = null;
/**
* Mini-cache of last SubmissionConfig object requested (so that we don't
* always reload from scratch)
*/
private SubmissionConfig lastSubmissionConfig = null;
/**
* Load Submission Configuration from the
* item-submission.xml configuration file
*/
public SubmissionConfigReader() throws ServletException
{
buildInputs(configDir + SUBMIT_DEF_FILE_PREFIX + SUBMIT_DEF_FILE_SUFFIX);
}
/**
* Parse an XML encoded item submission configuration file.
*
* Creates two main hashmaps:
*
*
Hashmap of Collection to Submission definition mappings -
* defines which Submission process a particular collection uses
*
Hashmap of all Submission definitions. List of all valid
* Submision Processes by name.
*
*/
private void buildInputs(String fileName) throws ServletException
{
collectionToSubmissionConfig = new HashMap();
submitDefns = new HashMap>>();
String uri = "file:" + new File(fileName).getAbsolutePath();
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder db = factory.newDocumentBuilder();
Document doc = db.parse(uri);
doNodes(doc);
}
catch (FactoryConfigurationError fe)
{
throw new ServletException(
"Cannot create Item Submission Configuration parser", fe);
}
catch (Exception e)
{
throw new ServletException(
"Error creating Item Submission Configuration: " + e);
}
}
/**
* Returns the Item Submission process config used for a particular
* collection, or the default if none is defined for the collection
*
* @param collectionHandle
* collection's unique Handle
* @param isWorkflow
* whether or not we are loading the submission process for a
* workflow
* @return the SubmissionConfig representing the item submission config
*
* @throws ServletException
* if no default submission process configuration defined
*/
public SubmissionConfig getSubmissionConfig(String collectionHandle,
boolean isWorkflow) throws ServletException
{
// get the name of the submission process config for this collection
String submitName = collectionToSubmissionConfig
.get(collectionHandle);
if (submitName == null)
{
submitName = collectionToSubmissionConfig
.get(DEFAULT_COLLECTION);
}
if (submitName == null)
{
throw new ServletException(
"No item submission process configuration designated as 'default' in 'submission-map' section of 'item-submission.xml'.");
}
log.debug("Loading submission process config named '" + submitName
+ "'");
// check mini-cache, and return if match
if (lastSubmissionConfig != null
&& lastSubmissionConfig.getSubmissionName().equals(submitName)
&& lastSubmissionConfig.isWorkflow() == isWorkflow)
{
log.debug("Found submission process config '" + submitName
+ "' in cache.");
return lastSubmissionConfig;
}
// cache miss - construct new SubmissionConfig
List