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.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Context;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
* 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.
*
* @author Tim Donohue based on DCInputsReader by Brian S. Hughes
* @version $Revision$
* @see org.dspace.app.util.SubmissionConfig
* @see org.dspace.app.util.SubmissionStepConfig
*/
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 = org.apache.logging.log4j.LogManager.getLogger(SubmissionConfigReader.class);
/**
* The fully qualified pathname of the directory containing the Item Submission Configuration file
*/
private String configDir = DSpaceServicesFactory.getInstance()
.getConfigurationService().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
*
* @throws SubmissionConfigReaderException if servlet error
*/
public SubmissionConfigReader() throws SubmissionConfigReaderException {
buildInputs(configDir + SUBMIT_DEF_FILE_PREFIX + SUBMIT_DEF_FILE_SUFFIX);
}
public void reload() throws SubmissionConfigReaderException {
collectionToSubmissionConfig = null;
stepDefns = null;
submitDefns = null;
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 SubmissionConfigReaderException {
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 SubmissionConfigReaderException(
"Cannot create Item Submission Configuration parser", fe);
} catch (Exception e) {
throw new SubmissionConfigReaderException(
"Error creating Item Submission Configuration: " + e);
}
}
/**
* @return the name of the default submission configuration
*/
public String getDefaultSubmissionConfigName() {
return collectionToSubmissionConfig.get(DEFAULT_COLLECTION);
}
/**
* Returns all the Item Submission process configs with pagination
*
* @param limit max number of SubmissionConfig to return
* @param offset number of SubmissionConfig to skip in the return
* @return the list of SubmissionConfig
*/
public List getAllSubmissionConfigs(Integer limit, Integer offset) {
int idx = 0;
int count = 0;
List subConfigs = new LinkedList();
for (String key : submitDefns.keySet()) {
if (offset == null || idx >= offset) {
count++;
subConfigs.add(getSubmissionConfigByName(key));
}
idx++;
if (count >= limit) {
break;
}
}
return subConfigs;
}
public int countSubmissionConfigs() {
return submitDefns.size();
}
/**
* 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
* @return the SubmissionConfig representing the item submission config
* @throws SubmissionConfigReaderException if no default submission process configuration defined
*/
public SubmissionConfig getSubmissionConfigByCollection(String collectionHandle) {
// 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 IllegalStateException(
"No item submission process configuration designated as 'default' in 'submission-map' section of " +
"'item-submission.xml'.");
}
return getSubmissionConfigByName(submitName);
}
/**
* Returns the Item Submission process config
*
* @param submitName submission process unique name
* @return the SubmissionConfig representing the item submission config
*/
public SubmissionConfig getSubmissionConfigByName(String submitName) {
log.debug("Loading submission process config named '" + submitName
+ "'");
// check mini-cache, and return if match
if (lastSubmissionConfig != null
&& lastSubmissionConfig.getSubmissionName().equals(submitName)) {
log.debug("Found submission process config '" + submitName
+ "' in cache.");
return lastSubmissionConfig;
}
// cache miss - construct new SubmissionConfig
List