diff --git a/dspace-api/src/main/java/org/dspace/app/mediafilter/MediaFilterCLITool.java b/dspace-api/src/main/java/org/dspace/app/mediafilter/MediaFilterCLITool.java index 2effda618d..9af43c7e7e 100644 --- a/dspace-api/src/main/java/org/dspace/app/mediafilter/MediaFilterCLITool.java +++ b/dspace-api/src/main/java/org/dspace/app/mediafilter/MediaFilterCLITool.java @@ -14,11 +14,15 @@ import org.dspace.content.Collection; import org.dspace.content.Community; import org.dspace.content.DSpaceObject; import org.dspace.content.Item; -import org.dspace.core.*; +import org.dspace.core.Constants; +import org.dspace.core.Context; +import org.dspace.core.SelfNamedPlugin; +import org.dspace.core.factory.CoreServiceFactory; import org.dspace.handle.factory.HandleServiceFactory; import java.util.*; -import org.dspace.core.factory.CoreServiceFactory; +import org.apache.commons.lang.ArrayUtils; +import org.dspace.services.factory.DSpaceServicesFactory; /** * MediaFilterManager is the class that invokes the media/format filters over the @@ -40,7 +44,6 @@ public class MediaFilterCLITool { //suffix (in dspace.cfg) for input formats supported by each filter private static final String INPUT_FORMATS_SUFFIX = "inputFormats"; - public static void main(String[] argv) throws Exception { // set headless for non-gui workstations @@ -162,8 +165,7 @@ public class MediaFilterCLITool { else { //retrieve list of all enabled media filter plugins! - String enabledPlugins = ConfigurationManager.getProperty(MEDIA_FILTER_PLUGINS_KEY); - filterNames = enabledPlugins.split(",\\s*"); + filterNames = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty(MEDIA_FILTER_PLUGINS_KEY); } MediaFilterService mediaFilterService = MediaFilterServiceFactory.getInstance().getMediaFilterService(); @@ -210,13 +212,14 @@ public class MediaFilterCLITool { // filter...inputFormats //For other MediaFilters, format of key is: // filter..inputFormats - String formats = ConfigurationManager.getProperty( + String[] formats = + DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty( FILTER_PREFIX + "." + filterClassName + (pluginName!=null ? "." + pluginName : "") + "." + INPUT_FORMATS_SUFFIX); //add to internal map of filters to supported formats - if (formats != null) + if (ArrayUtils.isNotEmpty(formats)) { //For SelfNamedPlugins, map key is: // @@ -224,7 +227,7 @@ public class MediaFilterCLITool { // filterFormats.put(filterClassName + (pluginName!=null ? MediaFilterService.FILTER_PLUGIN_SEPARATOR + pluginName : ""), - Arrays.asList(formats.split(",[\\s]*"))); + Arrays.asList(formats)); } }//end if filter!=null }//end for diff --git a/dspace-api/src/main/java/org/dspace/app/sitemap/GenerateSitemaps.java b/dspace-api/src/main/java/org/dspace/app/sitemap/GenerateSitemaps.java index 961392f0d4..6f455d4c7f 100644 --- a/dspace-api/src/main/java/org/dspace/app/sitemap/GenerateSitemaps.java +++ b/dspace-api/src/main/java/org/dspace/app/sitemap/GenerateSitemaps.java @@ -28,6 +28,7 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.PosixParser; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.ArrayUtils; import org.apache.log4j.Logger; import org.dspace.content.Collection; import org.dspace.content.Community; @@ -36,9 +37,10 @@ import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.CollectionService; import org.dspace.content.service.CommunityService; import org.dspace.content.service.ItemService; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Context; import org.dspace.core.LogManager; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; /** * Command-line utility for generating HTML and Sitemaps.org protocol Sitemaps. @@ -54,6 +56,7 @@ public class GenerateSitemaps private static final CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService(); private static final CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService(); private static final ItemService itemService = ContentServiceFactory.getInstance().getItemService(); + private static final ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); public static void main(String[] args) throws Exception { @@ -157,14 +160,14 @@ public class GenerateSitemaps public static void generateSitemaps(boolean makeHTMLMap, boolean makeSitemapOrg) throws SQLException, IOException { - String sitemapStem = ConfigurationManager.getProperty("dspace.url") + String sitemapStem = configurationService.getProperty("dspace.url") + "/sitemap"; - String htmlMapStem = ConfigurationManager.getProperty("dspace.url") + String htmlMapStem = configurationService.getProperty("dspace.url") + "/htmlmap"; - String handleURLStem = ConfigurationManager.getProperty("dspace.url") + String handleURLStem = configurationService.getProperty("dspace.url") + "/handle/"; - File outputDir = new File(ConfigurationManager.getProperty("sitemap.dir")); + File outputDir = new File(configurationService.getProperty("sitemap.dir")); if (!outputDir.exists() && !outputDir.mkdir()) { log.error("Unable to create output directory"); @@ -264,17 +267,10 @@ public class GenerateSitemaps public static void pingConfiguredSearchEngines() throws UnsupportedEncodingException { - String engineURLProp = ConfigurationManager - .getProperty("sitemap.engineurls"); - String engineURLs[] = null; - - if (engineURLProp != null) - { - engineURLs = engineURLProp.trim().split("\\s*,\\s*"); - } - - if (engineURLProp == null || engineURLs == null - || engineURLs.length == 0 || engineURLs[0].trim().equals("")) + String[] engineURLs = configurationService + .getArrayProperty("sitemap.engineurls"); + + if (ArrayUtils.isEmpty(engineURLs)) { log.warn("No search engine URLs configured to ping"); return; @@ -309,17 +305,17 @@ public class GenerateSitemaps throws MalformedURLException, UnsupportedEncodingException { // Set up HTTP proxy - if ((StringUtils.isNotBlank(ConfigurationManager.getProperty("http.proxy.host"))) - && (StringUtils.isNotBlank(ConfigurationManager.getProperty("http.proxy.port")))) + if ((StringUtils.isNotBlank(configurationService.getProperty("http.proxy.host"))) + && (StringUtils.isNotBlank(configurationService.getProperty("http.proxy.port")))) { System.setProperty("proxySet", "true"); - System.setProperty("proxyHost", ConfigurationManager + System.setProperty("proxyHost", configurationService .getProperty("http.proxy.host")); - System.getProperty("proxyPort", ConfigurationManager + System.getProperty("proxyPort", configurationService .getProperty("http.proxy.port")); } - String sitemapURL = ConfigurationManager.getProperty("dspace.url") + String sitemapURL = configurationService.getProperty("dspace.url") + "/sitemap"; URL url = new URL(engineURL + URLEncoder.encode(sitemapURL, "UTF-8")); diff --git a/dspace-api/src/main/java/org/dspace/app/util/SyndicationFeed.java b/dspace-api/src/main/java/org/dspace/app/util/SyndicationFeed.java index 933e596a7e..f2ac96cc5b 100644 --- a/dspace-api/src/main/java/org/dspace/app/util/SyndicationFeed.java +++ b/dspace-api/src/main/java/org/dspace/app/util/SyndicationFeed.java @@ -50,6 +50,8 @@ import com.sun.syndication.io.SyndFeedOutput; import com.sun.syndication.io.FeedException; import org.apache.log4j.Logger; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; /** * Invoke ROME library to assemble a generic model of a syndication @@ -83,38 +85,43 @@ public class SyndicationFeed protected String defaultTitleField = "dc.title"; protected String defaultAuthorField = "dc.contributor.author"; protected String defaultDateField = "dc.date.issued"; - private static String defaultDescriptionFields = "dc.description.abstract, dc.description, dc.title.alternative, dc.title"; + private static final String[] defaultDescriptionFields = new String[]{"dc.description.abstract", "dc.description", "dc.title.alternative", "dc.title"}; protected String defaultExternalMedia = "dc.source.uri"; + private final ConfigurationService configurationService = + DSpaceServicesFactory.getInstance().getConfigurationService(); + // metadata field for Item title in entry: - protected String titleField = - getDefaultedConfiguration("webui.feed.item.title", defaultTitleField); + protected String titleField = + configurationService.getProperty("webui.feed.item.title", defaultTitleField); // metadata field for Item publication date in entry: - protected String dateField = - getDefaultedConfiguration("webui.feed.item.date", defaultDateField); + protected String dateField = + configurationService.getProperty("webui.feed.item.date", defaultDateField); // metadata field for Item description in entry: - private static String descriptionFields[] = - getDefaultedConfiguration("webui.feed.item.description", defaultDescriptionFields).split("\\s*,\\s*"); - - protected String authorField = - getDefaultedConfiguration("webui.feed.item.author", defaultAuthorField); + private static final String descriptionFields[] = + DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("webui.feed.item.description", defaultDescriptionFields); + + protected String authorField = + configurationService.getProperty("webui.feed.item.author", defaultAuthorField); // metadata field for Podcast external media source url - protected String externalSourceField = getDefaultedConfiguration("webui.feed.podcast.sourceuri", defaultExternalMedia); + protected String externalSourceField = + configurationService.getProperty("webui.feed.podcast.sourceuri", defaultExternalMedia); // metadata field for Item dc:creator field in entry's DCModule (no default) - protected String dcCreatorField = ConfigurationManager.getProperty("webui.feed.item.dc.creator"); + protected String dcCreatorField = configurationService.getProperty("webui.feed.item.dc.creator"); // metadata field for Item dc:date field in entry's DCModule (no default) - protected String dcDateField = ConfigurationManager.getProperty("webui.feed.item.dc.date"); + protected String dcDateField = configurationService.getProperty("webui.feed.item.dc.date"); // metadata field for Item dc:author field in entry's DCModule (no default) - protected String dcDescriptionField = ConfigurationManager.getProperty("webui.feed.item.dc.description"); + protected String dcDescriptionField = configurationService.getProperty("webui.feed.item.dc.description"); // List of available mimetypes that we'll add to podcast feed. Multiple values separated by commas - protected String podcastableMIMETypes = getDefaultedConfiguration("webui.feed.podcast.mimetypes", "audio/x-mpeg"); + protected String[] podcastableMIMETypes = + configurationService.getArrayProperty("webui.feed.podcast.mimetypes", new String[]{"audio/x-mpeg"}); // -------- Instance variables: @@ -374,7 +381,7 @@ public class SyndicationFeed List bits = bunds.get(0).getBitstreams(); for (Bitstream bit : bits) { String mime = bit.getFormat(context).getMIMEType(); - if (podcastableMIMETypes.contains(mime)) { + if (ArrayUtils.contains(podcastableMIMETypes,mime)) { SyndEnclosure enc = new SyndEnclosureImpl(); enc.setType(bit.getFormat(context).getMIMEType()); enc.setLength(bit.getSize()); diff --git a/dspace-api/src/main/java/org/dspace/authenticate/IPAuthentication.java b/dspace-api/src/main/java/org/dspace/authenticate/IPAuthentication.java index 0eac2aeef9..5ac947b720 100644 --- a/dspace-api/src/main/java/org/dspace/authenticate/IPAuthentication.java +++ b/dspace-api/src/main/java/org/dspace/authenticate/IPAuthentication.java @@ -93,7 +93,7 @@ public class IPAuthentication implements AuthenticationMethod if (nameParts.length == 2) { - addMatchers(nameParts[1], DSpaceServicesFactory.getInstance().getConfigurationService().getProperty(propName)); + addMatchers(nameParts[1], DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty(propName)); } else { @@ -111,11 +111,9 @@ public class IPAuthentication implements AuthenticationMethod * @param ipRanges * IP ranges */ - protected void addMatchers(String groupName, String ipRanges) + protected void addMatchers(String groupName, String[] ipRanges) { - String[] ranges = ipRanges.split("\\s*,\\s*"); - - for (String entry : ranges) + for (String entry : ipRanges) { try { diff --git a/dspace-api/src/main/java/org/dspace/authenticate/X509Authentication.java b/dspace-api/src/main/java/org/dspace/authenticate/X509Authentication.java index 49b8cf192f..2a99fc8047 100644 --- a/dspace-api/src/main/java/org/dspace/authenticate/X509Authentication.java +++ b/dspace-api/src/main/java/org/dspace/authenticate/X509Authentication.java @@ -30,11 +30,11 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.commons.collections.ListUtils; +import org.apache.commons.lang.ArrayUtils; import org.apache.log4j.Logger; import org.dspace.authenticate.factory.AuthenticateServiceFactory; import org.dspace.authenticate.service.AuthenticationService; import org.dspace.authorize.AuthorizeException; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Context; import org.dspace.core.LogManager; import org.dspace.eperson.EPerson; @@ -42,6 +42,8 @@ import org.dspace.eperson.Group; import org.dspace.eperson.factory.EPersonServiceFactory; import org.dspace.eperson.service.EPersonService; import org.dspace.eperson.service.GroupService; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; /** * Implicit authentication method that gets credentials from the X.509 client @@ -118,6 +120,8 @@ public class X509Authentication implements AuthenticationMethod protected AuthenticationService authenticationService = AuthenticateServiceFactory.getInstance().getAuthenticationService(); protected EPersonService ePersonService = EPersonServiceFactory.getInstance().getEPersonService(); protected GroupService groupService = EPersonServiceFactory.getInstance().getGroupService(); + protected ConfigurationService configurationService = + DSpaceServicesFactory.getInstance().getConfigurationService(); /** @@ -127,21 +131,23 @@ public class X509Authentication implements AuthenticationMethod */ static { + ConfigurationService configurationService = + DSpaceServicesFactory.getInstance().getConfigurationService(); /* * allow identification of alternative entry points for certificate * authentication when selected by the user rather than implicitly. */ - loginPageTitle = ConfigurationManager - .getProperty("authentication-x509", "chooser.title.key"); - loginPageURL = ConfigurationManager - .getProperty("authentication-x509", "chooser.uri"); + loginPageTitle = configurationService + .getProperty("authentication-x509.chooser.title.key"); + loginPageURL = configurationService + .getProperty("authentication-x509.chooser.uri"); - String keystorePath = ConfigurationManager - .getProperty("authentication-x509", "keystore.path"); - String keystorePassword = ConfigurationManager - .getProperty("authentication-x509", "keystore.password"); - String caCertPath = ConfigurationManager - .getProperty("authentication-x509", "ca.cert"); + String keystorePath = configurationService + .getProperty("authentication-x509.keystore.path"); + String keystorePassword = configurationService + .getProperty("authentication-x509.keystore.password"); + String caCertPath = configurationService + .getProperty("authentication-x509.ca.cert"); // First look for keystore full of trusted certs. if (keystorePath != null) @@ -386,8 +392,8 @@ public class X509Authentication implements AuthenticationMethod public boolean canSelfRegister(Context context, HttpServletRequest request, String username) throws SQLException { - return ConfigurationManager - .getBooleanProperty("authentication-x509", "autoregister"); + return configurationService + .getBooleanProperty("authentication-x509.autoregister"); } /** @@ -428,17 +434,14 @@ public class X509Authentication implements AuthenticationMethod { List groupNames = new ArrayList(); - String x509GroupConfig = null; - x509GroupConfig = ConfigurationManager - .getProperty("authentication-x509", "groups"); + String[] groups = configurationService + .getArrayProperty("authentication-x509.groups"); - if (null != x509GroupConfig && !"".equals(x509GroupConfig)) + if(ArrayUtils.isNotEmpty(groups)) { - String[] groups = x509GroupConfig.split("\\s*,\\s*"); - - for (int i = 0; i < groups.length; i++) + for (String group : groups) { - groupNames.add(groups[i].trim()); + groupNames.add(group.trim()); } } diff --git a/dspace-api/src/main/java/org/dspace/content/packager/AbstractMETSDisseminator.java b/dspace-api/src/main/java/org/dspace/content/packager/AbstractMETSDisseminator.java index 7ab6c31855..a80ba481b3 100644 --- a/dspace-api/src/main/java/org/dspace/content/packager/AbstractMETSDisseminator.java +++ b/dspace-api/src/main/java/org/dspace/content/packager/AbstractMETSDisseminator.java @@ -69,7 +69,6 @@ import org.dspace.content.crosswalk.StreamDisseminationCrosswalk; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.BitstreamService; import org.dspace.content.service.SiteService; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.core.LogManager; @@ -78,6 +77,8 @@ import org.dspace.core.factory.CoreServiceFactory; import org.dspace.core.service.PluginService; import org.dspace.license.factory.LicenseServiceFactory; import org.dspace.license.service.CreativeCommonsService; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import org.jdom.Element; import org.jdom.Namespace; import org.jdom.output.Format; @@ -128,6 +129,7 @@ public abstract class AbstractMETSDisseminator protected final BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService(); protected final SiteService siteService = ContentServiceFactory.getInstance().getSiteService(); protected final CreativeCommonsService creativeCommonsService = LicenseServiceFactory.getInstance().getCreativeCommonsService(); + protected final ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); // for gensym() protected int idCounter = 1; @@ -1498,7 +1500,7 @@ public abstract class AbstractMETSDisseminator } if (handle != null) { - return ConfigurationManager + return configurationService .getProperty("dspace.url") + "/bitstream/" + handle @@ -1510,7 +1512,7 @@ public abstract class AbstractMETSDisseminator else { //no Handle assigned, so persistent(-ish) URI for bitstream is // Format: {site-base-url}/retrieve/{bitstream-internal-id} - return ConfigurationManager + return configurationService .getProperty("dspace.url") + "/retrieve/" + String.valueOf(bitstream.getID()); diff --git a/dspace-api/src/main/java/org/dspace/content/packager/DSpaceAIPDisseminator.java b/dspace-api/src/main/java/org/dspace/content/packager/DSpaceAIPDisseminator.java index f470b411fe..05bcdbd071 100644 --- a/dspace-api/src/main/java/org/dspace/content/packager/DSpaceAIPDisseminator.java +++ b/dspace-api/src/main/java/org/dspace/content/packager/DSpaceAIPDisseminator.java @@ -25,7 +25,6 @@ import org.dspace.content.Collection; import org.dspace.content.Community; import org.dspace.content.crosswalk.CrosswalkException; import org.dspace.core.Constants; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Context; import edu.harvard.hul.ois.mets.Agent; @@ -41,7 +40,10 @@ import edu.harvard.hul.ois.mets.Type; import edu.harvard.hul.ois.mets.helper.MetsException; import edu.harvard.hul.ois.mets.helper.PCData; import java.util.Date; +import org.apache.commons.lang.ArrayUtils; import org.dspace.core.Utils; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; /** * Subclass of the METS packager framework to disseminate a DSpace @@ -117,6 +119,10 @@ public class DSpaceAIPDisseminator extends AbstractMETSDisseminator protected List filterBundles = new ArrayList(); // Whether 'filterBundles' specifies an exclusion list (default) or inclusion list. protected boolean excludeBundles = true; + + protected ConfigurationService configurationService = + DSpaceServicesFactory.getInstance().getConfigurationService(); + @Override public void disseminate(Context context, DSpaceObject dso, @@ -257,17 +263,14 @@ public class DSpaceAIPDisseminator extends AbstractMETSDisseminator public String [] getDmdTypes(Context context, DSpaceObject dso, PackageParameters params) throws SQLException, IOException, AuthorizeException { - String dmdTypes = ConfigurationManager.getProperty("aip.disseminate.dmd"); - if (dmdTypes == null) + String[] dmdTypes = configurationService.getArrayProperty("aip.disseminate.dmd"); + if (ArrayUtils.isEmpty(dmdTypes)) { - String result[] = new String[2]; - result[0] = "MODS"; - result[1] = "DIM"; - return result; + return new String[] { "MODS","DIM"}; } else { - return dmdTypes.split("\\s*,\\s*"); + return dmdTypes; } } @@ -289,14 +292,12 @@ public class DSpaceAIPDisseminator extends AbstractMETSDisseminator public String[] getTechMdTypes(Context context, DSpaceObject dso, PackageParameters params) throws SQLException, IOException, AuthorizeException { - String techTypes = ConfigurationManager.getProperty("aip.disseminate.techMD"); - if (techTypes == null) + String[] techTypes = configurationService.getArrayProperty("aip.disseminate.techMD"); + if (ArrayUtils.isEmpty(techTypes)) { if (dso.getType() == Constants.BITSTREAM) { - String result[] = new String[1]; - result[0] = "PREMIS"; - return result; + return new String[]{"PREMIS"}; } else { @@ -305,7 +306,7 @@ public class DSpaceAIPDisseminator extends AbstractMETSDisseminator } else { - return techTypes.split("\\s*,\\s*"); + return techTypes; } } @@ -331,16 +332,14 @@ public class DSpaceAIPDisseminator extends AbstractMETSDisseminator public String[] getSourceMdTypes(Context context, DSpaceObject dso, PackageParameters params) throws SQLException, IOException, AuthorizeException { - String sourceTypes = ConfigurationManager.getProperty("aip.disseminate.sourceMD"); - if (sourceTypes == null) + String[] sourceTypes = configurationService.getArrayProperty("aip.disseminate.sourceMD"); + if (ArrayUtils.isEmpty(sourceTypes)) { - String result[] = new String[1]; - result[0] = "AIP-TECHMD"; - return result; + return new String[] {"AIP-TECHMD"}; } else { - return sourceTypes.split("\\s*,\\s*"); + return sourceTypes; } } @@ -362,14 +361,14 @@ public class DSpaceAIPDisseminator extends AbstractMETSDisseminator public String[] getDigiprovMdTypes(Context context, DSpaceObject dso, PackageParameters params) throws SQLException, IOException, AuthorizeException { - String dpTypes = ConfigurationManager.getProperty("aip.disseminate.digiprovMD"); - if (dpTypes == null) + String[] dpTypes = configurationService.getArrayProperty("aip.disseminate.digiprovMD"); + if (ArrayUtils.isEmpty(dpTypes)) { return new String[0]; } else { - return dpTypes.split("\\s*,\\s*"); + return dpTypes; } } @@ -394,10 +393,10 @@ public class DSpaceAIPDisseminator extends AbstractMETSDisseminator { List result = new ArrayList(); - String rTypes = ConfigurationManager.getProperty("aip.disseminate.rightsMD"); + String[] rTypes = configurationService.getArrayProperty("aip.disseminate.rightsMD"); //If unspecified in configuration file, add default settings - if (rTypes == null) + if (ArrayUtils.isEmpty(rTypes)) { // Licenses only apply to an Item if (dso.getType() == Constants.ITEM) @@ -424,7 +423,7 @@ public class DSpaceAIPDisseminator extends AbstractMETSDisseminator } else { - return rTypes.split("\\s*,\\s*"); + return rTypes; } return result.toArray(new String[result.size()]); diff --git a/dspace-api/src/main/java/org/dspace/ctask/general/AbstractTranslator.java b/dspace-api/src/main/java/org/dspace/ctask/general/AbstractTranslator.java index f1cf61bcb1..c80f37ebd6 100644 --- a/dspace-api/src/main/java/org/dspace/ctask/general/AbstractTranslator.java +++ b/dspace-api/src/main/java/org/dspace/ctask/general/AbstractTranslator.java @@ -11,15 +11,17 @@ import org.apache.log4j.Logger; import org.dspace.content.MetadataValue; import org.dspace.content.DSpaceObject; import org.dspace.content.Item; -import org.dspace.core.ConfigurationManager; import org.dspace.curate.AbstractCurationTask; import org.dspace.curate.Curator; import org.dspace.curate.Distributive; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import java.io.IOException; import java.util.ArrayList; import java.util.List; + /** * MicrosoftTranslator translates stuff * @@ -42,6 +44,9 @@ public abstract class AbstractTranslator extends AbstractCurationTask private static Logger log = Logger.getLogger(AbstractTranslator.class); protected List results = new ArrayList(); + + private final transient ConfigurationService configurationService + = DSpaceServicesFactory.getInstance().getConfigurationService(); @Override @@ -50,12 +55,10 @@ public abstract class AbstractTranslator extends AbstractCurationTask super.init(curator, taskId); // Load configuration - authLang = ConfigurationManager.getProperty("default.locale"); - authLangField = ConfigurationManager.getProperty(PLUGIN_PREFIX, "field.language"); - String toTranslateStr = ConfigurationManager.getProperty(PLUGIN_PREFIX, "field.targets"); - String langsStr = ConfigurationManager.getProperty(PLUGIN_PREFIX, "language.targets"); - toTranslate = toTranslateStr.split(","); - langs = langsStr.split(","); + authLang = configurationService.getProperty("default.locale"); + authLangField = configurationService.getProperty(PLUGIN_PREFIX + ".field.language"); + String[] toTranslate = configurationService.getArrayProperty(PLUGIN_PREFIX + ".field.targets"); + String[] langs = configurationService.getArrayProperty(PLUGIN_PREFIX + ".language.targets"); if(!(toTranslate.length > 0 && langs.length > 0)) { diff --git a/dspace-api/src/main/java/org/dspace/ctask/general/ClamScan.java b/dspace-api/src/main/java/org/dspace/ctask/general/ClamScan.java index 87fdc4b438..c40459cc19 100644 --- a/dspace-api/src/main/java/org/dspace/ctask/general/ClamScan.java +++ b/dspace-api/src/main/java/org/dspace/ctask/general/ClamScan.java @@ -25,7 +25,6 @@ import org.dspace.authorize.AuthorizeException; import org.dspace.content.*; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.BitstreamService; -import org.dspace.core.ConfigurationManager; import org.dspace.curate.AbstractCurationTask; import org.dspace.curate.Curator; import org.dspace.curate.Suspendable; @@ -74,10 +73,10 @@ public class ClamScan extends AbstractCurationTask public void init(Curator curator, String taskId) throws IOException { super.init(curator, taskId); - host = ConfigurationManager.getProperty(PLUGIN_PREFIX, "service.host"); - port = ConfigurationManager.getIntProperty(PLUGIN_PREFIX, "service.port"); - timeout = ConfigurationManager.getIntProperty(PLUGIN_PREFIX, "socket.timeout"); - failfast = ConfigurationManager.getBooleanProperty(PLUGIN_PREFIX, "scan.failfast"); + host = configurationService.getProperty(PLUGIN_PREFIX + ".service.host"); + port = configurationService.getIntProperty(PLUGIN_PREFIX + ".service.port"); + timeout = configurationService.getIntProperty(PLUGIN_PREFIX + ".socket.timeout"); + failfast = configurationService.getBooleanProperty(PLUGIN_PREFIX + ".scan.failfast"); bitstreamService = ContentServiceFactory.getInstance().getBitstreamService(); } diff --git a/dspace-api/src/main/java/org/dspace/ctask/general/MetadataWebService.java b/dspace-api/src/main/java/org/dspace/ctask/general/MetadataWebService.java index 5e64e37f1b..bde7d88513 100644 --- a/dspace-api/src/main/java/org/dspace/ctask/general/MetadataWebService.java +++ b/dspace-api/src/main/java/org/dspace/ctask/general/MetadataWebService.java @@ -48,7 +48,6 @@ import org.xml.sax.SAXException; import org.dspace.authorize.AuthorizeException; import org.dspace.content.DSpaceObject; import org.dspace.content.Item; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Constants; import org.dspace.curate.AbstractCurationTask; import org.dspace.curate.Curator; @@ -167,7 +166,7 @@ public class MetadataWebService extends AbstractCurationTask implements Namespac @Override public void init(Curator curator, String taskId) throws IOException { super.init(curator, taskId); - lang = ConfigurationManager.getProperty("default.language"); + lang = configurationService.getProperty("default.language"); String fldSep = taskProperty("separator"); fieldSeparator = (fldSep != null) ? fldSep : " "; urlTemplate = taskProperty("template"); @@ -177,7 +176,7 @@ public class MetadataWebService extends AbstractCurationTask implements Namespac lookupField = parsed[0]; lookupTransform = parsed[1]; dataList = new ArrayList(); - for (String entry : taskProperty("datamap").split(",")) { + for (String entry : taskArrayProperty("datamap")) { entry = entry.trim(); String src = entry; String mapping = null; diff --git a/dspace-api/src/main/java/org/dspace/curate/AbstractCurationTask.java b/dspace-api/src/main/java/org/dspace/curate/AbstractCurationTask.java index b519e92e74..9529e6cc1c 100644 --- a/dspace-api/src/main/java/org/dspace/curate/AbstractCurationTask.java +++ b/dspace-api/src/main/java/org/dspace/curate/AbstractCurationTask.java @@ -11,8 +11,8 @@ import java.io.IOException; import java.sql.SQLException; import java.util.Iterator; import java.util.List; -import java.util.Properties; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.dspace.content.Collection; @@ -22,11 +22,12 @@ import org.dspace.content.Item; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.CommunityService; import org.dspace.content.service.ItemService; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.service.HandleService; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; /** * AbstractCurationTask encapsulates a few common patterns of task use, @@ -40,14 +41,12 @@ public abstract class AbstractCurationTask implements CurationTask protected Curator curator = null; // curator-assigned taskId protected String taskId = null; - // optional task configuration properties - private Properties taskProps = null; // logger private static Logger log = Logger.getLogger(AbstractCurationTask.class); protected CommunityService communityService; protected ItemService itemService; protected HandleService handleService; - + protected ConfigurationService configurationService; @Override public void init(Curator curator, String taskId) throws IOException @@ -57,6 +56,7 @@ public abstract class AbstractCurationTask implements CurationTask communityService = ContentServiceFactory.getInstance().getCommunityService(); itemService = ContentServiceFactory.getInstance().getItemService(); handleService = HandleServiceFactory.getInstance().getHandleService(); + configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); } @Override @@ -235,29 +235,15 @@ public abstract class AbstractCurationTask implements CurationTask */ protected String taskProperty(String name) { - if (taskProps == null) - { - // load properties - taskProps = new Properties(); - StringBuilder modName = new StringBuilder(); - for (String segment : taskId.split("\\.")) - { - // load property segments if present - modName.append(segment); - Properties modProps = ConfigurationManager.getProperties(modName.toString()); - if (modProps != null) - { - taskProps.putAll(modProps); - } - modName.append("."); - } - // warn if *no* properties found - if (taskProps.size() == 0) - { - log.warn("Warning: No configuration properties found for task: " + taskId); - } + // If a taskID/Name is specified, prepend it on the configuration name + if(StringUtils.isNotBlank(taskId)) + { + return configurationService.getProperty(taskId + "." + name); } - return taskProps.getProperty(name); + else + { + return configurationService.getProperty(name); + } } /** @@ -274,20 +260,15 @@ public abstract class AbstractCurationTask implements CurationTask */ protected int taskIntProperty(String name, int defaultValue) { - int intVal = defaultValue; - String strVal = taskProperty(name); - if (strVal != null) - { - try - { - intVal = Integer.parseInt(strVal.trim()); - } - catch(NumberFormatException nfE) - { - log.warn("Warning: Number format error in module: " + taskId + " property: " + name); - } + // If a taskID/Name is specified, prepend it on the configuration name + if(StringUtils.isNotBlank(taskId)) + { + return configurationService.getIntProperty(taskId + "." + name, defaultValue); } - return intVal; + else + { + return configurationService.getIntProperty(name, defaultValue); + } } /** @@ -304,20 +285,15 @@ public abstract class AbstractCurationTask implements CurationTask */ protected long taskLongProperty(String name, long defaultValue) { - long longVal = defaultValue; - String strVal = taskProperty(name); - if (strVal != null) - { - try - { - longVal = Long.parseLong(strVal.trim()); - } - catch(NumberFormatException nfE) - { - log.warn("Warning: Number format error in module: " + taskId + " property: " + name); - } + // If a taskID/Name is specified, prepend it on the configuration name + if(StringUtils.isNotBlank(taskId)) + { + return configurationService.getLongProperty(taskId + "." + name, defaultValue); } - return longVal; + else + { + return configurationService.getLongProperty(name, defaultValue); + } } /** @@ -334,13 +310,37 @@ public abstract class AbstractCurationTask implements CurationTask */ protected boolean taskBooleanProperty(String name, boolean defaultValue) { - String strVal = taskProperty(name); - if (strVal != null) - { - strVal = strVal.trim(); - return strVal.equalsIgnoreCase("true") || - strVal.equalsIgnoreCase("yes"); + // If a taskID/Name is specified, prepend it on the configuration name + if(StringUtils.isNotBlank(taskId)) + { + return configurationService.getBooleanProperty(taskId + "." + name, defaultValue); } - return defaultValue; - } + else + { + return configurationService.getBooleanProperty(name, defaultValue); + } + } + + /** + * Returns task configuration Array property value for passed name, else + * null if no properties defined or no value for passed key. + * + * @param name + * the property name + * @return value + * the property value, or null + * + */ + protected String[] taskArrayProperty(String name) + { + // If a taskID/Name is specified, prepend it on the configuration name + if(StringUtils.isNotBlank(taskId)) + { + return configurationService.getArrayProperty(taskId + "." + name); + } + else + { + return configurationService.getArrayProperty(name); + } + } } diff --git a/dspace-api/src/main/java/org/dspace/curate/FileTaskQueue.java b/dspace-api/src/main/java/org/dspace/curate/FileTaskQueue.java index 6b482f5c98..48831bd26e 100644 --- a/dspace-api/src/main/java/org/dspace/curate/FileTaskQueue.java +++ b/dspace-api/src/main/java/org/dspace/curate/FileTaskQueue.java @@ -20,8 +20,8 @@ import java.util.List; import java.util.Set; import org.apache.log4j.Logger; +import org.dspace.services.factory.DSpaceServicesFactory; -import org.dspace.core.ConfigurationManager; /** * FileTaskQueue provides a TaskQueue implementation based on flat files @@ -33,7 +33,7 @@ public class FileTaskQueue implements TaskQueue { private static Logger log = Logger.getLogger(TaskQueue.class); // base directory for curation task queues - protected String tqDir = ConfigurationManager.getProperty("curate", "taskqueue.dir"); + protected String tqDir; // ticket for queue readers protected long readTicket = -1L; @@ -42,6 +42,7 @@ public class FileTaskQueue implements TaskQueue public FileTaskQueue() { + tqDir = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("curate.taskqueue.dir"); } @Override diff --git a/dspace-api/src/main/java/org/dspace/curate/TaskResolver.java b/dspace-api/src/main/java/org/dspace/curate/TaskResolver.java index c4b3afca76..5c12e577e0 100644 --- a/dspace-api/src/main/java/org/dspace/curate/TaskResolver.java +++ b/dspace-api/src/main/java/org/dspace/curate/TaskResolver.java @@ -23,8 +23,8 @@ import javax.script.ScriptException; import org.apache.log4j.Logger; -import org.dspace.core.ConfigurationManager; import org.dspace.core.factory.CoreServiceFactory; +import org.dspace.services.factory.DSpaceServicesFactory; /** * TaskResolver takes a logical name of a curation task and attempts to deliver @@ -71,13 +71,14 @@ public class TaskResolver // base directory of task scripts & catalog name protected static final String CATALOG = "task.catalog"; - protected static final String scriptDir = ConfigurationManager.getProperty("curate", "script.dir"); + protected final String scriptDir; // catalog of script tasks protected Properties catalog; public TaskResolver() { + scriptDir = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("curate.script.dir"); } /** diff --git a/dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java b/dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java index 2f7fd0d249..02bd46d83f 100644 --- a/dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java @@ -968,14 +968,10 @@ public class SolrServiceImpl implements SearchService, IndexingService { List toProjectionFields = new ArrayList(); - String projectionFieldsString = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("discovery.index.projection"); - if(projectionFieldsString != null){ - if(projectionFieldsString.indexOf(",") != -1){ - for (int i = 0; i < projectionFieldsString.split(",").length; i++) { - toProjectionFields.add(projectionFieldsString.split(",")[i].trim()); - } - } else { - toProjectionFields.add(projectionFieldsString); + String[] projectionFields = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("discovery.index.projection"); + if(projectionFields != null){ + for (String field : projectionFields) { + toProjectionFields.add(field.trim()); } } diff --git a/dspace-api/src/main/java/org/dspace/event/EventServiceImpl.java b/dspace-api/src/main/java/org/dspace/event/EventServiceImpl.java index 95a54a6d3f..20e100cedf 100644 --- a/dspace-api/src/main/java/org/dspace/event/EventServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/event/EventServiceImpl.java @@ -9,10 +9,11 @@ package org.dspace.event; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; +import org.apache.commons.lang.ArrayUtils; import org.apache.commons.pool2.KeyedObjectPool; import org.apache.commons.pool2.KeyedPooledObjectFactory; @@ -22,9 +23,10 @@ import org.apache.commons.pool2.impl.DefaultPooledObject; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; import org.apache.log4j.Logger; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Context; import org.dspace.event.service.EventService; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; /** * Class for managing the content event environment. The EventManager mainly @@ -48,7 +50,10 @@ public class EventServiceImpl implements EventService protected Map consumerIndicies = null; - protected String CONSUMER_PFX = "event.consumer."; + protected String CONSUMER_PFX = "event.consumer"; + + private static final ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); + protected EventServiceImpl() { @@ -140,7 +145,8 @@ public class EventServiceImpl implements EventService protected void enumerateConsumers() { - Enumeration propertyNames = ConfigurationManager.propertyNames(); + // Get all configs starting with CONSUMER_PFX + List propertyNames = configurationService.getPropertyKeys(CONSUMER_PFX); int bitSetIndex = 0; if (consumerIndicies == null) @@ -148,13 +154,11 @@ public class EventServiceImpl implements EventService consumerIndicies = new HashMap(); } - while (propertyNames.hasMoreElements()) + for(String ckey : propertyNames) { - String ckey = ((String) propertyNames.nextElement()).trim(); - - if (ckey.startsWith(CONSUMER_PFX) && ckey.endsWith(".class")) + if (ckey.endsWith(".class")) { - String consumerName = ckey.substring(CONSUMER_PFX.length(), + String consumerName = ckey.substring(CONSUMER_PFX.length()+1, ckey.length() - 6); consumerIndicies.put(consumerName, (Integer) bitSetIndex); @@ -167,7 +171,7 @@ public class EventServiceImpl implements EventService { // Prefix of keys in DSpace Configuration - private static final String PROP_PFX = "event.dispatcher."; + private static final String PROP_PFX = "event.dispatcher"; // Cache of event dispatchers, keyed by name, for re-use. protected Map dispatchers = new HashMap(); @@ -201,37 +205,23 @@ public class EventServiceImpl implements EventService dispatcher = (Dispatcher) dc.newInstance(args); // OK, now get its list of consumers/filters - String consumerKey = PROP_PFX + dispatcherName + String consumerKey = PROP_PFX + "." + dispatcherName + ".consumers"; - String consumerList = ConfigurationManager - .getProperty(consumerKey); - if (consumerList == null) + String[] consumers = configurationService + .getArrayProperty(consumerKey); + if (ArrayUtils.isEmpty(consumers)) { throw new IllegalStateException( "No Configuration entry found for consumer list of event Dispatcher: \"" + consumerKey + "\""); } - // Consumer list format: - // :, ... - String[] consumerStanza = consumerList.trim().split( - "\\s*,\\s*"); - - // I think this should be a fatal error.. --lcs - if (consumerStanza.length < 1) - { - throw new IllegalStateException( - "Cannot initialize Dispatcher, malformed Configuration value for " - + consumerKey); - } - ConsumerProfile consumerProfile = null; - // parts: 0 is name, part 1 is mode. - for (int i = 0; i < consumerStanza.length; i++) + for (String consumer : consumers) { consumerProfile = ConsumerProfile - .makeConsumerProfile(consumerStanza[i]); + .makeConsumerProfile(consumer); consumerProfile.getConsumer().initialize(); dispatcher.addConsumerProfile(consumerProfile); @@ -346,16 +336,16 @@ public class EventServiceImpl implements EventService */ private void parseEventConfig() { - Enumeration propertyNames = ConfigurationManager.propertyNames(); - while (propertyNames.hasMoreElements()) + // Get all configs starting with PROP_PFX + List propertyNames = configurationService.getPropertyKeys(PROP_PFX); + + for(String ckey : propertyNames) { - String ckey = ((String) propertyNames.nextElement()).trim(); - - if (ckey.startsWith(PROP_PFX) && ckey.endsWith(".class")) + if (ckey.endsWith(".class")) { - String name = ckey.substring(PROP_PFX.length(), ckey + String name = ckey.substring(PROP_PFX.length()+1, ckey .length() - 6); - String dispatcherClass = ConfigurationManager + String dispatcherClass = configurationService .getProperty(ckey); // Can we grab all of the consumers configured for this diff --git a/dspace-api/src/main/java/org/dspace/harvest/OAIHarvester.java b/dspace-api/src/main/java/org/dspace/harvest/OAIHarvester.java index 78c53294ca..72398bff32 100644 --- a/dspace-api/src/main/java/org/dspace/harvest/OAIHarvester.java +++ b/dspace-api/src/main/java/org/dspace/harvest/OAIHarvester.java @@ -18,7 +18,6 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.Enumeration; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -37,7 +36,6 @@ import org.dspace.content.crosswalk.CrosswalkException; import org.dspace.content.crosswalk.IngestionCrosswalk; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.*; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.core.Email; @@ -50,6 +48,8 @@ import org.dspace.handle.service.HandleService; import org.dspace.harvest.factory.HarvestServiceFactory; import org.dspace.harvest.service.HarvestedCollectionService; import org.dspace.harvest.service.HarvestedItemService; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; @@ -90,6 +90,7 @@ public class OAIHarvester { protected HarvestedItemService harvestedItemService; protected WorkspaceItemService workspaceItemService; protected PluginService pluginService; + protected ConfigurationService configurationService; // The collection this harvester instance is dealing with Collection targetCollection; @@ -168,19 +169,16 @@ public class OAIHarvester { private static Namespace getORENamespace() { String ORESerializationString = null; String ORESeialKey = null; - String oreString = "oai.harvester.oreSerializationFormat."; + String oreString = "oai.harvester.oreSerializationFormat"; - Enumeration pe = ConfigurationManager.propertyNames("oai"); + List keys = DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyKeys(oreString); - while (pe.hasMoreElements()) + for(String key : keys) { - String key = (String)pe.nextElement(); - if (key.startsWith(oreString)) { - ORESeialKey = key.substring(oreString.length()); - ORESerializationString = ConfigurationManager.getProperty("oai", key); + ORESeialKey = key.substring(oreString.length()+1); + ORESerializationString = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty(key); - return Namespace.getNamespace(ORESeialKey, ORESerializationString); - } + return Namespace.getNamespace(ORESeialKey, ORESerializationString); } // Fallback if the configuration option is not present @@ -195,16 +193,14 @@ public class OAIHarvester { */ private static Namespace getDMDNamespace(String metadataKey) { String metadataString = null; - String metaString = "oai.harvester.metadataformats."; + String metaString = "oai.harvester.metadataformats"; - Enumeration pe = ConfigurationManager.propertyNames("oai"); + List keys = DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyKeys(metaString); - while (pe.hasMoreElements()) + for(String key : keys) { - String key = (String)pe.nextElement(); - - if (key.startsWith(metaString) && key.substring(metaString.length()).equals((metadataKey))) { - metadataString = ConfigurationManager.getProperty("oai", key); + if (key.substring(metaString.length()+1).equals((metadataKey))) { + metadataString = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty(key); String namespacePiece; if (metadataString.indexOf(',') != -1) { @@ -296,7 +292,7 @@ public class OAIHarvester { harvestedCollection.update(ourContext, harvestRow); // expiration timer starts - int expirationInterval = ConfigurationManager.getIntProperty("oai", "harvester.threadTimeout"); + int expirationInterval = configurationService.getIntProperty("oai.harvester.threadTimeout"); if (expirationInterval == 0) { expirationInterval = 24; @@ -613,25 +609,22 @@ public class OAIHarvester { */ protected String extractHandle(Item item) { - String acceptedHandleServersString = ConfigurationManager.getProperty("oai", "harvester.acceptedHandleServer"); - if (acceptedHandleServersString == null) + String[] acceptedHandleServers = configurationService.getArrayProperty("oai.harvester.acceptedHandleServer"); + if (acceptedHandleServers == null) { - acceptedHandleServersString = "hdl.handle.net"; + acceptedHandleServers = new String[]{"hdl.handle.net"}; } - String rejectedHandlePrefixString = ConfigurationManager.getProperty("oai", "harvester.rejectedHandlePrefix"); - if (rejectedHandlePrefixString == null) + String[] rejectedHandlePrefixes = configurationService.getArrayProperty("oai.harvester.rejectedHandlePrefix"); + if (rejectedHandlePrefixes == null) { - rejectedHandlePrefixString = "123456789"; + rejectedHandlePrefixes = new String[]{"123456789"}; } List values = itemService.getMetadata(item, "dc", "identifier", Item.ANY, Item.ANY); - if (values.size() > 0 && !acceptedHandleServersString.equals("")) + if (values.size() > 0 && acceptedHandleServers != null) { - String[] acceptedHandleServers = acceptedHandleServersString.split(","); - String[] rejectedHandlePrefixes = rejectedHandlePrefixString.split(","); - for (MetadataValue value : values) { // 0 1 2 3 4 @@ -667,7 +660,7 @@ public class OAIHarvester { * @return a string in the format 'yyyy-mm-ddThh:mm:ssZ' and converted to UTC timezone */ private String processDate(Date date) { - Integer timePad = ConfigurationManager.getIntProperty("oai", "harvester.timePadding"); + Integer timePad = configurationService.getIntProperty("oai.harvester.timePadding"); if (timePad == 0) { timePad = 120; @@ -748,7 +741,7 @@ public class OAIHarvester { protected void alertAdmin(int status, Exception ex) { try { - String recipient = ConfigurationManager.getProperty("alert.recipient"); + String recipient = configurationService.getProperty("alert.recipient"); if (StringUtils.isNotBlank(recipient)) { Email email = Email.getEmail(I18nUtil.getEmailFilename(Locale.getDefault(), "harvesting_error")); diff --git a/dspace-api/src/main/java/org/dspace/health/Report.java b/dspace-api/src/main/java/org/dspace/health/Report.java index 5c41ec1481..95ac3470a9 100644 --- a/dspace-api/src/main/java/org/dspace/health/Report.java +++ b/dspace-api/src/main/java/org/dspace/health/Report.java @@ -18,6 +18,7 @@ import java.util.*; import java.util.Map.Entry; import org.dspace.core.factory.CoreServiceFactory; import org.dspace.core.service.PluginService; +import org.dspace.services.factory.DSpaceServicesFactory; /** * @author LINDAT/CLARIN dev team @@ -70,7 +71,7 @@ public class Report { // create check list public static LinkedHashMap checks() { LinkedHashMap checks = new LinkedHashMap<>(); - String check_names[] = ConfigurationManager.getProperty("healthcheck", "checks").split(","); + String check_names[] = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("healthcheck.checks"); PluginService pluginService = CoreServiceFactory.getInstance().getPluginService(); for ( String check_name : check_names ) { Check check = (Check) pluginService.getNamedPlugin( diff --git a/dspace-api/src/main/java/org/dspace/license/CCLookup.java b/dspace-api/src/main/java/org/dspace/license/CCLookup.java index f0782f97c9..eb4ea641f9 100644 --- a/dspace-api/src/main/java/org/dspace/license/CCLookup.java +++ b/dspace-api/src/main/java/org/dspace/license/CCLookup.java @@ -32,7 +32,8 @@ import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; -import org.dspace.core.ConfigurationManager; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; /** @@ -45,9 +46,9 @@ public class CCLookup { /** log4j logger */ private static Logger log = Logger.getLogger(CCLookup.class); - private static String cc_root = ConfigurationManager.getProperty("cc.api.rooturl"); - private static String jurisdiction; - private static List lcFilter = new ArrayList(); + private String cc_root; + private String jurisdiction; + private List lcFilter = new ArrayList(); private Document license_doc = null; private String rdfString = null; @@ -57,18 +58,6 @@ public class CCLookup { private SAXBuilder parser = new SAXBuilder(); private List licenses = new ArrayList(); private List licenseFields = new ArrayList(); - - static { - String jurisProp = ConfigurationManager.getProperty("cc.license.jurisdiction"); - jurisdiction = (jurisProp != null) ? jurisProp : ""; - - String filterList = ConfigurationManager.getProperty("cc.license.classfilter"); - if (filterList != null) { - for (String name: filterList.split(",")) { - lcFilter.add(name.trim()); - } - } - } /** * Constructs a new instance with the default web services root. @@ -76,6 +65,20 @@ public class CCLookup { */ public CCLookup() { super(); + + ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); + + cc_root = configurationService.getProperty("cc.api.rooturl"); + + String jurisProp = configurationService.getProperty("cc.license.jurisdiction"); + jurisdiction = (jurisProp != null) ? jurisProp : ""; + + String[] filters = configurationService.getArrayProperty("cc.license.classfilter"); + if (filters != null) { + for (String name: filters) { + lcFilter.add(name.trim()); + } + } } /** diff --git a/dspace-api/src/main/java/org/dspace/rdf/conversion/MetadataConverterPlugin.java b/dspace-api/src/main/java/org/dspace/rdf/conversion/MetadataConverterPlugin.java index 338619f97b..bcba1b1162 100644 --- a/dspace-api/src/main/java/org/dspace/rdf/conversion/MetadataConverterPlugin.java +++ b/dspace-api/src/main/java/org/dspace/rdf/conversion/MetadataConverterPlugin.java @@ -203,29 +203,23 @@ public class MetadataConverterPlugin implements ConverterPlugin protected Model loadConfiguration() { - String mappingPathes = configurationService.getProperty(METADATA_MAPPING_PATH_KEY); - if (StringUtils.isEmpty(mappingPathes)) - { - return null; - } - String[] mappings = mappingPathes.split(",\\s*"); - if (mappings == null || mappings.length == 0) + InputStream is = null; + Model config = ModelFactory.createDefaultModel(); + String mapping = configurationService.getProperty(METADATA_MAPPING_PATH_KEY); + if (StringUtils.isEmpty(mapping)) { log.error("Cannot find metadata mappings (looking for " + "property " + METADATA_MAPPING_PATH_KEY + ")!"); return null; } - - InputStream is = null; - Model config = ModelFactory.createDefaultModel(); - for (String mappingPath : mappings) + else { - is = FileManager.get().open(mappingPath); + is = FileManager.get().open(mapping); if (is == null) { - log.warn("Cannot find file '" + mappingPath + "', ignoring..."); + log.warn("Cannot find file '" + mapping + "', ignoring..."); } - config.read(is, "file://" + mappingPath, FileUtils.guessLang(mappingPath)); + config.read(is, "file://" + mapping, FileUtils.guessLang(mapping)); try { // Make sure that we have an input stream to avoid NullPointer if(is != null) diff --git a/dspace-api/src/main/java/org/dspace/statistics/SolrLoggerServiceImpl.java b/dspace-api/src/main/java/org/dspace/statistics/SolrLoggerServiceImpl.java index 048805ea90..6c1db78ad3 100644 --- a/dspace-api/src/main/java/org/dspace/statistics/SolrLoggerServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/statistics/SolrLoggerServiceImpl.java @@ -11,7 +11,6 @@ import au.com.bytecode.opencsv.CSVReader; import au.com.bytecode.opencsv.CSVWriter; import com.maxmind.geoip.Location; import com.maxmind.geoip.LookupService; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; @@ -39,11 +38,11 @@ import org.dspace.content.Collection; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.BitstreamService; import org.dspace.content.service.DSpaceObjectLegacySupportService; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.eperson.EPerson; import org.dspace.eperson.Group; +import org.dspace.services.ConfigurationService; import org.dspace.statistics.service.SolrLoggerService; import org.dspace.statistics.util.DnsLookup; import org.dspace.statistics.util.LocationUtils; @@ -90,6 +89,8 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea protected BitstreamService bitstreamService; @Autowired(required = true) protected ContentServiceFactory contentServiceFactory; + @Autowired(required = true) + private ConfigurationService configurationService; public static enum StatisticsType { VIEW ("view"), @@ -114,20 +115,20 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea @Override public void afterPropertiesSet() throws Exception { - log.info("solr-statistics.spidersfile:" + ConfigurationManager.getProperty("solr-statistics", "spidersfile")); - log.info("solr-statistics.server:" + ConfigurationManager.getProperty("solr-statistics", "server")); - log.info("usage-statistics.dbfile:" + ConfigurationManager.getProperty("usage-statistics", "dbfile")); + log.info("solr-statistics.spidersfile:" + configurationService.getProperty("solr-statistics.spidersfile")); + log.info("solr-statistics.server:" + configurationService.getProperty("solr-statistics.server")); + log.info("usage-statistics.dbfile:" + configurationService.getProperty("usage-statistics.dbfile")); HttpSolrServer server = null; - if (ConfigurationManager.getProperty("solr-statistics", "server") != null) + if (configurationService.getProperty("solr-statistics.server") != null) { try { - server = new HttpSolrServer(ConfigurationManager.getProperty("solr-statistics", "server")); + server = new HttpSolrServer(configurationService.getProperty("solr-statistics.server")); //Attempt to retrieve all the statistic year cores - File solrDir = new File(ConfigurationManager.getProperty("dspace.dir") + "/solr/"); + File solrDir = new File(configurationService.getProperty("dspace.dir") + File.separator + "solr" + File.separator); File[] solrCoreFiles = solrDir.listFiles(new FileFilter() { @Override @@ -158,7 +159,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea LookupService service = null; // Get the db file for the location - String dbfile = ConfigurationManager.getProperty("usage-statistics", "dbfile"); + String dbfile = configurationService.getProperty("usage-statistics.dbfile"); if (dbfile != null) { try @@ -181,15 +182,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea } locationService = service; - if ("true".equals(ConfigurationManager.getProperty("useProxies"))) - { - useProxies = true; - } - else - { - useProxies = false; - } - + useProxies = configurationService.getBooleanProperty("useProxies"); log.info("useProxies=" + useProxies); } @@ -287,7 +280,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea protected SolrInputDocument getCommonSolrDoc(DSpaceObject dspaceObject, HttpServletRequest request, EPerson currentUser) throws SQLException { boolean isSpiderBot = request != null && SpiderDetector.isSpider(request); if(isSpiderBot && - !ConfigurationManager.getBooleanProperty("usage-statistics", "logBots", true)) + !configurationService.getBooleanProperty("usage-statistics.logBots", true)) { return null; } @@ -381,7 +374,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea protected SolrInputDocument getCommonSolrDoc(DSpaceObject dspaceObject, String ip, String userAgent, String xforwardedfor, EPerson currentUser) throws SQLException { boolean isSpiderBot = SpiderDetector.isSpider(ip); if(isSpiderBot && - !ConfigurationManager.getBooleanProperty("usage-statistics", "logBots", true)) + !configurationService.getBooleanProperty("usage-statistics.logBots", true)) { return null; } @@ -1088,14 +1081,14 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea // not be influenced // Choose to filter by the Legacy spider IP list (may get too long to properly filter all IP's - if(ConfigurationManager.getBooleanProperty("solr-statistics", "query.filter.spiderIp",false)) + if(configurationService.getBooleanProperty("solr-statistics.query.filter.spiderIp",false)) { solrQuery.addFilterQuery(getIgnoreSpiderIPs()); } // Choose to filter by isBot field, may be overriden in future // to allow views on stats based on bots. - if(ConfigurationManager.getBooleanProperty("solr-statistics", "query.filter.isBot",true)) + if(configurationService.getBooleanProperty("solr-statistics.query.filter.isBot",true)) { solrQuery.addFilterQuery("-isBot:true"); } @@ -1104,8 +1097,8 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea solrQuery.setSortField(sort, (ascending ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc)); } - String bundles; - if((bundles = ConfigurationManager.getProperty("solr-statistics", "query.filter.bundles")) != null && 0 < bundles.length()){ + String[] bundles = configurationService.getArrayProperty("solr-statistics.query.filter.bundles"); + if(bundles != null && bundles.length > 0){ /** * The code below creates a query that will allow only records which do not have a bundlename @@ -1114,11 +1107,10 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea StringBuffer bundleQuery = new StringBuffer(); //Also add the possibility that if no bundle name is there these results will also be returned ! bundleQuery.append("-(bundleName:[* TO *]"); - String[] split = bundles.split(","); - for (int i = 0; i < split.length; i++) { - String bundle = split[i].trim(); + for (int i = 0; i < bundles.length; i++) { + String bundle = bundles[i].trim(); bundleQuery.append("-bundleName:").append(bundle); - if(i != split.length - 1){ + if(i != bundles.length - 1){ bundleQuery.append(" AND "); } } @@ -1207,7 +1199,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea yearRangeQuery.add(FacetParams.FACET_MINCOUNT, String.valueOf(1)); //Create a temp directory to store our files in ! - File tempDirectory = new File(ConfigurationManager.getProperty("dspace.dir") + File.separator + "temp" + File.separator); + File tempDirectory = new File(configurationService.getProperty("dspace.dir") + File.separator + "temp" + File.separator); tempDirectory.mkdirs(); @@ -1292,7 +1284,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea } protected HttpSolrServer createCore(HttpSolrServer solr, String coreName) throws IOException, SolrServerException { - String solrDir = ConfigurationManager.getProperty("dspace.dir") + File.separator + "solr" +File.separator; + String solrDir = configurationService.getProperty("dspace.dir") + File.separator + "solr" +File.separator; String baseSolrUrl = solr.getBaseURL().replace("statistics", ""); CoreAdminRequest.Create create = new CoreAdminRequest.Create(); create.setCoreName(coreName); @@ -1320,7 +1312,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea addAdditionalSolrYearCores(query); long totalRecords = solr.query(query).getResults().getNumFound(); - File tempDirectory = new File(ConfigurationManager.getProperty("dspace.dir") + File.separator + "temp" + File.separator); + File tempDirectory = new File(configurationService.getProperty("dspace.dir") + File.separator + "temp" + File.separator); tempDirectory.mkdirs(); List tempCsvFiles = new ArrayList(); for(int i = 0; i < totalRecords; i+=10000){ @@ -1432,7 +1424,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea public void exportHits() throws Exception { Context context = new Context(); - File tempDirectory = new File(ConfigurationManager.getProperty("dspace.dir") + File.separator + "temp" + File.separator); + File tempDirectory = new File(configurationService.getProperty("dspace.dir") + File.separator + "temp" + File.separator); tempDirectory.mkdirs(); try { diff --git a/dspace-api/src/main/java/org/dspace/statistics/util/SpiderDetector.java b/dspace-api/src/main/java/org/dspace/statistics/util/SpiderDetector.java index 7398f3e9c0..df155c875d 100644 --- a/dspace-api/src/main/java/org/dspace/statistics/util/SpiderDetector.java +++ b/dspace-api/src/main/java/org/dspace/statistics/util/SpiderDetector.java @@ -18,7 +18,7 @@ import java.util.Set; import java.util.Collections; import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; -import org.dspace.core.ConfigurationManager; +import org.dspace.services.factory.DSpaceServicesFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -107,7 +107,7 @@ public class SpiderDetector { if (table == null) { table = new IPTable(); - String filePath = ConfigurationManager.getProperty("dspace.dir"); + String filePath = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.dir"); try { File spidersDir = new File(filePath, "config/spiders"); @@ -156,7 +156,7 @@ public class SpiderDetector { */ private static void loadPatterns(String directory, List patternList) { - String dspaceHome = ConfigurationManager.getProperty("dspace.dir"); + String dspaceHome = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.dir"); File spidersDir = new File(dspaceHome, "config/spiders"); File patternsDir = new File(spidersDir, directory); if (patternsDir.exists() && patternsDir.isDirectory()) @@ -296,7 +296,7 @@ public class SpiderDetector { private static boolean isUseProxies() { if(useProxies == null) { - useProxies = "true".equals(ConfigurationManager.getProperty("useProxies")); + useProxies = DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty("useProxies"); } return useProxies; diff --git a/dspace-api/src/main/java/org/dspace/statistics/util/StatisticsClient.java b/dspace-api/src/main/java/org/dspace/statistics/util/StatisticsClient.java index 6a9a48948c..1ada3bcf54 100644 --- a/dspace-api/src/main/java/org/dspace/statistics/util/StatisticsClient.java +++ b/dspace-api/src/main/java/org/dspace/statistics/util/StatisticsClient.java @@ -10,12 +10,12 @@ package org.dspace.statistics.util; import org.apache.commons.cli.*; import org.apache.log4j.Logger; import org.apache.tools.ant.taskdefs.Get; -import org.dspace.core.ConfigurationManager; import org.dspace.statistics.factory.StatisticsServiceFactory; import org.dspace.statistics.service.SolrLoggerService; import java.io.*; import java.net.URL; +import org.dspace.services.factory.DSpaceServicesFactory; /** * Class to load intermediate statistics files into solr @@ -54,7 +54,7 @@ public class StatisticsClient options.addOption("u", "update-spider-files", false, "Update Spider IP Files from internet into " + - ConfigurationManager.getProperty("dspace.dir") + "/config/spiders"); + DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.dir") + "/config/spiders"); options.addOption("m", "mark-spiders", false, "Update isBot Flag in Solr"); options.addOption("f", "delete-spiders-by-flag", false, "Delete Spiders in Solr By isBot Flag"); @@ -123,23 +123,22 @@ public class StatisticsClient System.out.println("Downloading latest spider IP addresses:"); // Get the list URLs to download from - String urls = ConfigurationManager.getProperty("solr-statistics", "spiderips.urls"); - if ((urls == null) || ("".equals(urls))) + String[] urls = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("solr-statistics.spiderips.urls"); + if((urls == null) || (urls.length==0)) { System.err.println(" - Missing setting from dspace.cfg: solr.spiderips.urls"); System.exit(0); } // Get the location of spiders directory - File spiders = new File(ConfigurationManager.getProperty("dspace.dir"),"config/spiders"); + File spiders = new File(DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.dir"),"config/spiders"); if (!spiders.exists() && !spiders.mkdirs()) { log.error("Unable to create spiders directory"); } - String[] values = urls.split(","); - for (String value : values) + for (String value : urls) { value = value.trim(); System.out.println(" Downloading: " + value); diff --git a/dspace-api/src/main/java/org/dspace/text/filter/MARC21InitialArticleWord.java b/dspace-api/src/main/java/org/dspace/text/filter/MARC21InitialArticleWord.java index c622a7e714..39362a3e74 100644 --- a/dspace-api/src/main/java/org/dspace/text/filter/MARC21InitialArticleWord.java +++ b/dspace-api/src/main/java/org/dspace/text/filter/MARC21InitialArticleWord.java @@ -12,7 +12,7 @@ import java.util.*; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; -import org.dspace.core.ConfigurationManager; +import org.dspace.services.factory.DSpaceServicesFactory; /** * Implements MARC 21 standards to disregard initial @@ -278,18 +278,15 @@ public class MARC21InitialArticleWord extends InitialArticleWord } // Setup default stop words for null languages - String defaultLangs = ConfigurationManager.getProperty("marc21wordfilter.defaultlang"); - if (!StringUtils.isEmpty(defaultLangs)) + String[] defaultLangs = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("marc21wordfilter.defaultlang"); + if (ArrayUtils.isNotEmpty(defaultLangs)) { - String[] langArr = defaultLangs.split("[, ]+"); - if (langArr != null && langArr.length > 0) - { int wordCount = 0; - ArticlesForLang[] afl = new ArticlesForLang[langArr.length]; + ArticlesForLang[] afl = new ArticlesForLang[defaultLangs.length]; for (int idx = 0; idx < afl.length; idx++) { - Language l = Language.getLanguage(langArr[idx]); + Language l = Language.getLanguage(defaultLangs[idx]); if (l != null && ianaArticleMap.containsKey(l.IANA)) { afl[idx] = ianaArticleMap.get(l.IANA); @@ -313,7 +310,6 @@ public class MARC21InitialArticleWord extends InitialArticleWord } } } - } } } diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/handle/HandleJSONResolver.java b/dspace-jspui/src/main/java/org/dspace/app/webui/handle/HandleJSONResolver.java index db6ba1dd14..1155be2a19 100644 --- a/dspace-jspui/src/main/java/org/dspace/app/webui/handle/HandleJSONResolver.java +++ b/dspace-jspui/src/main/java/org/dspace/app/webui/handle/HandleJSONResolver.java @@ -19,10 +19,11 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.dspace.app.webui.json.JSONRequest; import org.dspace.authorize.AuthorizeException; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Context; import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.service.HandleService; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import com.google.gson.Gson; @@ -32,9 +33,11 @@ public class HandleJSONResolver extends JSONRequest .getLogger(HandleJSONResolver.class); private HandleService handleService; + private ConfigurationService configurationService; public HandleJSONResolver() { handleService = HandleServiceFactory.getInstance().getHandleService(); + configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); } public void doJSONRequest(Context context, HttpServletRequest request, @@ -77,11 +80,11 @@ public class HandleJSONResolver extends JSONRequest { List prefixes = new ArrayList(); prefixes.add(handleService.getPrefix()); - String additionalPrefixes = ConfigurationManager - .getProperty("handle.additional.prefixes"); - if (StringUtils.isNotBlank(additionalPrefixes)) + String[] additionalPrefixes = configurationService + .getArrayProperty("handle.additional.prefixes"); + if (additionalPrefixes!=null) { - for (String apref : additionalPrefixes.split(",")) + for (String apref : additionalPrefixes) { prefixes.add(apref.trim()); } @@ -90,7 +93,7 @@ public class HandleJSONResolver extends JSONRequest } else if (reqPath.startsWith("listhandles/")) { - if (ConfigurationManager.getBooleanProperty( + if (configurationService.getBooleanProperty( "handle.hide.listhandles", true)) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/BrowseListTag.java b/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/BrowseListTag.java index 75ba0de535..9ec1565c5c 100644 --- a/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/BrowseListTag.java +++ b/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/BrowseListTag.java @@ -23,6 +23,7 @@ import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.jstl.fmt.LocaleSupport; import javax.servlet.jsp.tagext.TagSupport; +import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -42,10 +43,11 @@ import org.dspace.content.authority.service.MetadataAuthorityService; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.BitstreamService; import org.dspace.content.service.ItemService; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.core.Utils; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import org.dspace.sort.SortOption; /** @@ -86,10 +88,10 @@ public class BrowseListTag extends TagSupport private boolean disableCrossLinks = false; /** The default fields to be displayed when listing items */ - private static final String DEFAULT_LIST_FIELDS; + private static final String[] DEFAULT_LIST_FIELDS; /** The default widths for the columns */ - private static final String DEFAULT_LIST_WIDTHS; + private static final String[] DEFAULT_LIST_WIDTHS; /** The default field which is bound to the browse by date */ private static String dateField = "dc.date.issued"; @@ -113,6 +115,9 @@ public class BrowseListTag extends TagSupport transient private final BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService(); + + transient private final ConfigurationService configurationService + = DSpaceServicesFactory.getInstance().getConfigurationService(); static { @@ -120,30 +125,30 @@ public class BrowseListTag extends TagSupport if (showThumbs) { - DEFAULT_LIST_FIELDS = "thumbnail, dc.date.issued(date), dc.title, dc.contributor.*"; - DEFAULT_LIST_WIDTHS = "*, 130, 60%, 40%"; + DEFAULT_LIST_FIELDS = new String[]{"thumbnail", "dc.date.issued(date)", "dc.title", "dc.contributor.*"}; + DEFAULT_LIST_WIDTHS = new String[]{"*", "130", "60%", "40%"}; } else { - DEFAULT_LIST_FIELDS = "dc.date.issued(date), dc.title, dc.contributor.*"; - DEFAULT_LIST_WIDTHS = "130, 60%, 40%"; + DEFAULT_LIST_FIELDS = new String[]{"dc.date.issued(date)", "dc.title", "dc.contributor.*"}; + DEFAULT_LIST_WIDTHS = new String[]{"130", "60%", "40%"}; } // get the date and title fields - String dateLine = ConfigurationManager.getProperty("webui.browse.index.date"); + String dateLine = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("webui.browse.index.date"); if (dateLine != null) { dateField = dateLine; } - String titleLine = ConfigurationManager.getProperty("webui.browse.index.title"); + String titleLine = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("webui.browse.index.title"); if (titleLine != null) { titleField = titleLine; } // get the author truncation config - String authorLine = ConfigurationManager.getProperty("webui.browse.author-field"); + String authorLine = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("webui.browse.author-field"); if (authorLine != null) { authorField = authorLine; @@ -173,8 +178,8 @@ public class BrowseListTag extends TagSupport */ // get the elements to display - String browseListLine = null; - String browseWidthLine = null; + String[] browseFields = null; + String[] browseWidths = null; // As different indexes / sort options may require different columns to be displayed // try to obtain a custom configuration based for the browse that has been performed @@ -187,10 +192,10 @@ public class BrowseListTag extends TagSupport if (bix != null) { // First, try to get a configuration for this browse and sort option combined - if (so != null && browseListLine == null) + if (so != null && ArrayUtils.isEmpty(browseFields)) { - browseListLine = ConfigurationManager.getProperty("webui.itemlist.browse." + bix.getName() + ".sort." + so.getName() + ".columns"); - browseWidthLine = ConfigurationManager.getProperty("webui.itemlist.browse." + bix.getName() + ".sort." + so.getName() + ".widths"); + browseFields = configurationService.getArrayProperty("webui.itemlist.browse." + bix.getName() + ".sort." + so.getName() + ".columns"); + browseWidths = configurationService.getArrayProperty("webui.itemlist.browse." + bix.getName() + ".sort." + so.getName() + ".widths"); } // We haven't got a sort option defined, so get one for the index @@ -202,106 +207,72 @@ public class BrowseListTag extends TagSupport } // If no config found, attempt to get one for this sort option - if (so != null && browseListLine == null) + if (so != null && ArrayUtils.isEmpty(browseFields)) { - browseListLine = ConfigurationManager.getProperty("webui.itemlist.sort." + so.getName() + ".columns"); - browseWidthLine = ConfigurationManager.getProperty("webui.itemlist.sort." + so.getName() + ".widths"); + browseFields = configurationService.getArrayProperty("webui.itemlist.sort." + so.getName() + ".columns"); + browseWidths = configurationService.getArrayProperty("webui.itemlist.sort." + so.getName() + ".widths"); } // If no config found, attempt to get one for this browse index - if (bix != null && browseListLine == null) + if (bix != null && ArrayUtils.isEmpty(browseFields)) { - browseListLine = ConfigurationManager.getProperty("webui.itemlist.browse." + bix.getName() + ".columns"); - browseWidthLine = ConfigurationManager.getProperty("webui.itemlist.browse." + bix.getName() + ".widths"); + browseFields = configurationService.getArrayProperty("webui.itemlist.browse." + bix.getName() + ".columns"); + browseWidths = configurationService.getArrayProperty("webui.itemlist.browse." + bix.getName() + ".widths"); } // If no config found, attempt to get a general one, using the sort name - if (so != null && browseListLine == null) + if (so != null && ArrayUtils.isEmpty(browseFields)) { - browseListLine = ConfigurationManager.getProperty("webui.itemlist." + so.getName() + ".columns"); - browseWidthLine = ConfigurationManager.getProperty("webui.itemlist." + so.getName() + ".widths"); + browseFields = configurationService.getArrayProperty("webui.itemlist." + so.getName() + ".columns"); + browseWidths = configurationService.getArrayProperty("webui.itemlist." + so.getName() + ".widths"); } // If no config found, attempt to get a general one, using the index name - if (bix != null && browseListLine == null) + if (bix != null && ArrayUtils.isEmpty(browseFields)) { - browseListLine = ConfigurationManager.getProperty("webui.itemlist." + bix.getName() + ".columns"); - browseWidthLine = ConfigurationManager.getProperty("webui.itemlist." + bix.getName() + ".widths"); + browseFields = configurationService.getArrayProperty("webui.itemlist." + bix.getName() + ".columns"); + browseWidths = configurationService.getArrayProperty("webui.itemlist." + bix.getName() + ".widths"); } } - if (browseListLine == null) + if (ArrayUtils.isEmpty(browseFields)) { - browseListLine = ConfigurationManager.getProperty("webui.itemlist.columns"); - browseWidthLine = ConfigurationManager.getProperty("webui.itemlist.widths"); + browseFields = configurationService.getArrayProperty("webui.itemlist.columns"); + browseWidths = configurationService.getArrayProperty("webui.itemlist.widths"); } // Have we read a field configration from dspace.cfg? - if (browseListLine != null) + if (ArrayUtils.isNotEmpty(browseFields)) { // If thumbnails are disabled, strip out any thumbnail column from the configuration - if (!showThumbs && browseListLine.contains("thumbnail")) + if (!showThumbs) { - // Ensure we haven't got any nulls - browseListLine = browseListLine == null ? "" : browseListLine; - browseWidthLine = browseWidthLine == null ? "" : browseWidthLine; - - // Tokenize the field and width lines - StringTokenizer bllt = new StringTokenizer(browseListLine, ","); - StringTokenizer bwlt = new StringTokenizer(browseWidthLine, ","); - - StringBuilder newBLLine = new StringBuilder(); - StringBuilder newBWLine = new StringBuilder(); - while (bllt.hasMoreTokens() || bwlt.hasMoreTokens()) + // check if it contains a thumbnail entry + // If so, remove it, and the width associated with it + int thumbnailIndex = ArrayUtils.indexOf(browseFields, "thumbnail"); + if(thumbnailIndex>=0) { - String browseListTok = bllt.hasMoreTokens() ? bllt.nextToken() : null; - String browseWidthTok = bwlt.hasMoreTokens() ? bwlt.nextToken() : null; - - // Only use the Field and Width tokens, if the field isn't 'thumbnail' - if (browseListTok == null || !browseListTok.trim().equals("thumbnail")) + browseFields = (String[]) ArrayUtils.remove(browseFields, thumbnailIndex); + if(ArrayUtils.isNotEmpty(browseWidths)) { - if (browseListTok != null) - { - if (newBLLine.length() > 0) - { - newBLLine.append(","); - } - - newBLLine.append(browseListTok); - } - - if (browseWidthTok != null) - { - if (newBWLine.length() > 0) - { - newBWLine.append(","); - } - - newBWLine.append(browseWidthTok); - } + browseWidths = (String[]) ArrayUtils.remove(browseWidths, thumbnailIndex); } } - - // Use the newly built configuration file - browseListLine = newBLLine.toString(); - browseWidthLine = newBWLine.toString(); } } else { - browseListLine = DEFAULT_LIST_FIELDS; - browseWidthLine = DEFAULT_LIST_WIDTHS; + browseFields = DEFAULT_LIST_FIELDS; + browseWidths = DEFAULT_LIST_WIDTHS; } // Arrays used to hold the information we will require when outputting each row - String[] fieldArr = browseListLine == null ? new String[0] : browseListLine.split("\\s*,\\s*"); - String[] widthArr = browseWidthLine == null ? new String[0] : browseWidthLine.split("\\s*,\\s*"); - boolean isDate[] = new boolean[fieldArr.length]; - boolean emph[] = new boolean[fieldArr.length]; - boolean isAuthor[] = new boolean[fieldArr.length]; - boolean viewFull[] = new boolean[fieldArr.length]; - String[] browseType = new String[fieldArr.length]; - String[] cOddOrEven = new String[fieldArr.length]; + boolean isDate[] = new boolean[browseFields.length]; + boolean emph[] = new boolean[browseFields.length]; + boolean isAuthor[] = new boolean[browseFields.length]; + boolean viewFull[] = new boolean[browseFields.length]; + String[] browseType = new String[browseFields.length]; + String[] cOddOrEven = new String[browseFields.length]; try { @@ -309,11 +280,11 @@ public class BrowseListTag extends TagSupport CrossLinks cl = new CrossLinks(); // Get a width for the table - String tablewidth = ConfigurationManager.getProperty("webui.itemlist.tablewidth"); + String tablewidth = configurationService.getProperty("webui.itemlist.tablewidth"); // If we have column widths, try to use a fixed layout table - faster for browsers to render // but not if we have to add an 'edit item' button - we can't know how big it will be - if (widthArr.length > 0 && widthArr.length == fieldArr.length && !linkToEdit) + if (ArrayUtils.isNotEmpty(browseWidths) && browseWidths.length == browseFields.length && !linkToEdit) { // If the table width has been specified, we can make this a fixed layout if (!StringUtils.isEmpty(tablewidth)) @@ -329,18 +300,18 @@ public class BrowseListTag extends TagSupport // Output the known column widths out.print(""); - for (int w = 0; w < widthArr.length; w++) + for (int w = 0; w < browseWidths.length; w++) { out.print(""); @@ -360,9 +331,9 @@ public class BrowseListTag extends TagSupport // Output the table headers out.println(""); - for (int colIdx = 0; colIdx < fieldArr.length; colIdx++) + for (int colIdx = 0; colIdx < browseFields.length; colIdx++) { - String field = fieldArr[colIdx].toLowerCase().trim(); + String field = browseFields[colIdx].toLowerCase().trim(); cOddOrEven[colIdx] = (((colIdx + 1) % 2) == 0 ? "Odd" : "Even"); // find out if the field is a date @@ -373,7 +344,7 @@ public class BrowseListTag extends TagSupport } // Cache any modifications to field - fieldArr[colIdx] = field; + browseFields[colIdx] = field; // find out if this is the author column if (field.equals(authorField)) @@ -440,9 +411,9 @@ public class BrowseListTag extends TagSupport // now prepare the XHTML frag for this division String rOddOrEven; - for (int colIdx = 0; colIdx < fieldArr.length; colIdx++) + for (int colIdx = 0; colIdx < browseFields.length; colIdx++) { - String field = fieldArr[colIdx]; + String field = browseFields[colIdx]; // get the schema and the element qualifier pair // (Note, the schema is not used for anything yet) @@ -773,31 +744,34 @@ public class BrowseListTag extends TagSupport /* get the required thumbnail config items */ private static void getThumbSettings() { - showThumbs = ConfigurationManager + ConfigurationService configurationService = + DSpaceServicesFactory.getInstance().getConfigurationService(); + + showThumbs = configurationService .getBooleanProperty("webui.browse.thumbnail.show"); if (showThumbs) { - thumbItemListMaxHeight = ConfigurationManager + thumbItemListMaxHeight = configurationService .getIntProperty("webui.browse.thumbnail.maxheight"); if (thumbItemListMaxHeight == 0) { - thumbItemListMaxHeight = ConfigurationManager + thumbItemListMaxHeight = configurationService .getIntProperty("thumbnail.maxheight"); } - thumbItemListMaxWidth = ConfigurationManager + thumbItemListMaxWidth = configurationService .getIntProperty("webui.browse.thumbnail.maxwidth"); if (thumbItemListMaxWidth == 0) { - thumbItemListMaxWidth = ConfigurationManager + thumbItemListMaxWidth = configurationService .getIntProperty("thumbnail.maxwidth"); } } - String linkBehaviour = ConfigurationManager + String linkBehaviour = configurationService .getProperty("webui.browse.thumbnail.linkbehaviour"); if (linkBehaviour != null && linkBehaviour.equals("bitstream")) diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/ItemListTag.java b/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/ItemListTag.java index c4c54bc66e..4cdeb1e566 100644 --- a/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/ItemListTag.java +++ b/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/ItemListTag.java @@ -23,6 +23,7 @@ import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.jstl.fmt.LocaleSupport; import javax.servlet.jsp.tagext.TagSupport; +import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -41,10 +42,11 @@ import org.dspace.content.authority.service.MetadataAuthorityService; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.BitstreamService; import org.dspace.content.service.ItemService; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.core.Utils; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import org.dspace.sort.SortOption; /** @@ -84,10 +86,10 @@ public class ItemListTag extends TagSupport private boolean disableCrossLinks = false; /** The default fields to be displayed when listing items */ - private static final String DEFAULT_LIST_FIELDS; + private static final String[] DEFAULT_LIST_FIELDS; /** The default widths for the columns */ - private static final String DEFAULT_LIST_WIDTHS; + private static final String[] DEFAULT_LIST_WIDTHS; /** The default field which is bound to the browse by date */ private static String dateField = "dc.date.issued"; @@ -111,6 +113,9 @@ public class ItemListTag extends TagSupport private final transient BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService(); + + private final transient ConfigurationService configurationService + = DSpaceServicesFactory.getInstance().getConfigurationService(); static { @@ -118,29 +123,29 @@ public class ItemListTag extends TagSupport if (showThumbs) { - DEFAULT_LIST_FIELDS = "thumbnail, dc.date.issued(date), dc.title, dc.contributor.*"; - DEFAULT_LIST_WIDTHS = "*, 130, 60%, 40%"; + DEFAULT_LIST_FIELDS = new String[] {"thumbnail", "dc.date.issued(date)", "dc.title", "dc.contributor.*"}; + DEFAULT_LIST_WIDTHS = new String[] {"*", "130", "60%", "40%"}; } else { - DEFAULT_LIST_FIELDS = "dc.date.issued(date), dc.title, dc.contributor.*"; - DEFAULT_LIST_WIDTHS = "130, 60%, 40%"; + DEFAULT_LIST_FIELDS = new String[] {"dc.date.issued(date)", "dc.title", "dc.contributor.*"}; + DEFAULT_LIST_WIDTHS = new String[] {"130", "60%", "40%"}; } // get the date and title fields - String dateLine = ConfigurationManager.getProperty("webui.browse.index.date"); + String dateLine = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("webui.browse.index.date"); if (dateLine != null) { dateField = dateLine; } - String titleLine = ConfigurationManager.getProperty("webui.browse.index.title"); + String titleLine = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("webui.browse.index.title"); if (titleLine != null) { titleField = titleLine; } - String authorLine = ConfigurationManager.getProperty("webui.browse.author-field"); + String authorLine = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("webui.browse.author-field"); if (authorLine != null) { authorField = authorLine; @@ -168,96 +173,62 @@ public class ItemListTag extends TagSupport } // get the elements to display - String configLine = null; - String widthLine = null; + String[] browseFields = null; + String[] browseWidths = null; if (sortOption != null) { - if (configLine == null) + if (ArrayUtils.isEmpty(browseFields)) { - configLine = ConfigurationManager.getProperty("webui.itemlist.sort." + sortOption.getName() + ".columns"); - widthLine = ConfigurationManager.getProperty("webui.itemlist.sort." + sortOption.getName() + ".widths"); + browseFields = configurationService.getArrayProperty("webui.itemlist.sort." + sortOption.getName() + ".columns"); + browseWidths = configurationService.getArrayProperty("webui.itemlist.sort." + sortOption.getName() + ".widths"); } - if (configLine == null) + if (ArrayUtils.isEmpty(browseFields)) { - configLine = ConfigurationManager.getProperty("webui.itemlist." + sortOption.getName() + ".columns"); - widthLine = ConfigurationManager.getProperty("webui.itemlist." + sortOption.getName() + ".widths"); + browseFields = configurationService.getArrayProperty("webui.itemlist." + sortOption.getName() + ".columns"); + browseWidths = configurationService.getArrayProperty("webui.itemlist." + sortOption.getName() + ".widths"); } } - if (configLine == null) + if (ArrayUtils.isEmpty(browseFields)) { - configLine = ConfigurationManager.getProperty("webui.itemlist.columns"); - widthLine = ConfigurationManager.getProperty("webui.itemlist.widths"); + browseFields = configurationService.getArrayProperty("webui.itemlist.columns"); + browseWidths = configurationService.getArrayProperty("webui.itemlist.widths"); } // Have we read a field configration from dspace.cfg? - if (configLine != null) + if (ArrayUtils.isNotEmpty(browseFields)) { // If thumbnails are disabled, strip out any thumbnail column from the configuration - if (!showThumbs && configLine.contains("thumbnail")) + if (!showThumbs) { - // Ensure we haven't got any nulls - configLine = configLine == null ? "" : configLine; - widthLine = widthLine == null ? "" : widthLine; - - // Tokenize the field and width lines - StringTokenizer llt = new StringTokenizer(configLine, ","); - StringTokenizer wlt = new StringTokenizer(widthLine, ","); - - StringBuilder newLLine = new StringBuilder(); - StringBuilder newWLine = new StringBuilder(); - while (llt.hasMoreTokens() || wlt.hasMoreTokens()) + // check if it contains a thumbnail entry + // If so, remove it, and the width associated with it + int thumbnailIndex = ArrayUtils.indexOf(browseFields, "thumbnail"); + if(thumbnailIndex>=0) { - String listTok = llt.hasMoreTokens() ? llt.nextToken() : null; - String widthTok = wlt.hasMoreTokens() ? wlt.nextToken() : null; - - // Only use the Field and Width tokens, if the field isn't 'thumbnail' - if (listTok == null || !listTok.trim().equals("thumbnail")) + browseFields = (String[]) ArrayUtils.remove(browseFields, thumbnailIndex); + if(ArrayUtils.isNotEmpty(browseWidths)) { - if (listTok != null) - { - if (newLLine.length() > 0) - { - newLLine.append(","); - } - - newLLine.append(listTok); - } - - if (widthTok != null) - { - if (newWLine.length() > 0) - { - newWLine.append(","); - } - - newWLine.append(widthTok); - } + browseWidths = (String[]) ArrayUtils.remove(browseWidths, thumbnailIndex); } } - - // Use the newly built configuration file - configLine = newLLine.toString(); - widthLine = newWLine.toString(); } } else { - configLine = DEFAULT_LIST_FIELDS; - widthLine = DEFAULT_LIST_WIDTHS; + browseFields = DEFAULT_LIST_FIELDS; + browseWidths = DEFAULT_LIST_WIDTHS; } // Arrays used to hold the information we will require when outputting each row - String[] fieldArr = configLine == null ? new String[0] : configLine.split("\\s*,\\s*"); - String[] widthArr = widthLine == null ? new String[0] : widthLine.split("\\s*,\\s*"); - boolean isDate[] = new boolean[fieldArr.length]; - boolean emph[] = new boolean[fieldArr.length]; - boolean isAuthor[] = new boolean[fieldArr.length]; - boolean viewFull[] = new boolean[fieldArr.length]; - String[] browseType = new String[fieldArr.length]; - String[] cOddOrEven = new String[fieldArr.length]; + boolean isDate[] = new boolean[browseFields.length]; + boolean emph[] = new boolean[browseFields.length]; + boolean isAuthor[] = new boolean[browseFields.length]; + boolean viewFull[] = new boolean[browseFields.length]; + String[] browseType = new String[browseFields.length]; + String[] cOddOrEven = new String[browseFields.length]; try { @@ -265,11 +236,11 @@ public class ItemListTag extends TagSupport CrossLinks cl = new CrossLinks(); // Get a width for the table - String tablewidth = ConfigurationManager.getProperty("webui.itemlist.tablewidth"); + String tablewidth = configurationService.getProperty("webui.itemlist.tablewidth"); // If we have column widths, output a fixed layout table - faster for browsers to render // but not if we have to add an 'edit item' button - we can't know how big it will be - if (widthArr.length > 0 && widthArr.length == fieldArr.length && !linkToEdit) + if (ArrayUtils.isNotEmpty(browseWidths) && browseWidths.length == browseFields.length && !linkToEdit) { // If the table width has been specified, we can make this a fixed layout if (!StringUtils.isEmpty(tablewidth)) @@ -285,18 +256,18 @@ public class ItemListTag extends TagSupport // Output the known column widths out.print(""); - for (int w = 0; w < widthArr.length; w++) + for (int w = 0; w < browseWidths.length; w++) { out.print(""); @@ -316,9 +287,9 @@ public class ItemListTag extends TagSupport // Output the table headers out.println(""); - for (int colIdx = 0; colIdx < fieldArr.length; colIdx++) + for (int colIdx = 0; colIdx < browseFields.length; colIdx++) { - String field = fieldArr[colIdx].toLowerCase().trim(); + String field = browseFields[colIdx].toLowerCase().trim(); cOddOrEven[colIdx] = (((colIdx + 1) % 2) == 0 ? "Odd" : "Even"); // find out if the field is a date @@ -329,7 +300,7 @@ public class ItemListTag extends TagSupport } // Cache any modifications to field - fieldArr[colIdx] = field; + browseFields[colIdx] = field; // find out if this is the author column if (field.equals(authorField)) @@ -393,9 +364,9 @@ public class ItemListTag extends TagSupport // now prepare the XHTML frag for this division out.print(""); - for (int colIdx = 0; colIdx < fieldArr.length; colIdx++) + for (int colIdx = 0; colIdx < browseFields.length; colIdx++) { - String field = fieldArr[colIdx]; + String field = browseFields[colIdx]; // get the schema and the element qualifier pair // (Note, the schema is not used for anything yet) @@ -741,31 +712,34 @@ public class ItemListTag extends TagSupport /* get the required thumbnail config items */ private static void getThumbSettings() { - showThumbs = ConfigurationManager + ConfigurationService configurationService = + DSpaceServicesFactory.getInstance().getConfigurationService(); + + showThumbs = configurationService .getBooleanProperty("webui.browse.thumbnail.show"); if (showThumbs) { - thumbItemListMaxHeight = ConfigurationManager + thumbItemListMaxHeight = configurationService .getIntProperty("webui.browse.thumbnail.maxheight"); if (thumbItemListMaxHeight == 0) { - thumbItemListMaxHeight = ConfigurationManager + thumbItemListMaxHeight = configurationService .getIntProperty("thumbnail.maxheight"); } - thumbItemListMaxWidth = ConfigurationManager + thumbItemListMaxWidth = configurationService .getIntProperty("webui.browse.thumbnail.maxwidth"); if (thumbItemListMaxWidth == 0) { - thumbItemListMaxWidth = ConfigurationManager + thumbItemListMaxWidth = configurationService .getIntProperty("thumbnail.maxwidth"); } } - String linkBehaviour = ConfigurationManager + String linkBehaviour = configurationService .getProperty("webui.browse.thumbnail.linkbehaviour"); if ("bitstream".equals(linkBehaviour)) diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/FeedServlet.java b/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/FeedServlet.java index 1550cb383b..153871118c 100644 --- a/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/FeedServlet.java +++ b/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/FeedServlet.java @@ -41,7 +41,6 @@ import org.dspace.content.Item; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.CollectionService; import org.dspace.content.service.CommunityService; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.core.LogManager; @@ -49,6 +48,8 @@ import org.dspace.eperson.Group; import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.service.HandleService; import org.dspace.search.Harvest; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import org.dspace.sort.SortException; import org.dspace.sort.SortOption; @@ -74,21 +75,24 @@ public class FeedServlet extends DSpaceServlet private static final String clazz = "org.dspace.app.webui.servlet.FeedServlet"; // are syndication feeds enabled? - private static boolean enabled = false; + private boolean enabled = false; // number of DSpace items per feed - private static int itemCount = 0; + private int itemCount = 0; // optional cache of feeds private static Map feedCache = null; // maximum size of cache - 0 means caching disabled private static int cacheSize = 0; // how many days to keep a feed in cache before checking currency - private static int cacheAge = 0; + private int cacheAge = 0; // supported syndication formats - private static List formats = null; + private List formats = null; // Whether to include private items or not - private static boolean includeAll = true; + private boolean includeAll = true; // services API + private final transient ConfigurationService configurationService + = DSpaceServicesFactory.getInstance().getConfigurationService(); + private final transient HandleService handleService = HandleServiceFactory.getInstance().getHandleService(); @@ -98,30 +102,29 @@ public class FeedServlet extends DSpaceServlet private final transient CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService(); - static + public FeedServlet() { - enabled = ConfigurationManager.getBooleanProperty("webui.feed.enable"); + enabled = configurationService.getBooleanProperty("webui.feed.enable"); // read rest of config info if enabled if (enabled) { - String fmtsStr = ConfigurationManager.getProperty("webui.feed.formats"); - if ( fmtsStr != null ) + String[] fmts = configurationService.getArrayProperty("webui.feed.formats"); + if ( fmts != null ) { formats = new ArrayList<>(); - String[] fmts = fmtsStr.split(","); - for (int i = 0; i < fmts.length; i++) + for (String format : fmts) { - formats.add(fmts[i]); + formats.add(format); } } - itemCount = ConfigurationManager.getIntProperty("webui.feed.items"); - cacheSize = ConfigurationManager.getIntProperty("webui.feed.cache.size"); + itemCount = configurationService.getIntProperty("webui.feed.items"); + cacheSize = configurationService.getIntProperty("webui.feed.cache.size"); if (cacheSize > 0) { feedCache = new HashMap<>(); - cacheAge = ConfigurationManager.getIntProperty("webui.feed.cache.age"); + cacheAge = configurationService.getIntProperty("webui.feed.cache.age"); } } } @@ -131,7 +134,7 @@ public class FeedServlet extends DSpaceServlet HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { - includeAll = ConfigurationManager.getBooleanProperty("harvest.includerestricted.rss", true); + includeAll = configurationService.getBooleanProperty("harvest.includerestricted.rss", true); String path = request.getPathInfo(); String feedType = null; String handle = null; @@ -291,7 +294,7 @@ public class FeedServlet extends DSpaceServlet try { // new method of doing the browse: - String idx = ConfigurationManager.getProperty("recent.submissions.sort-option"); + String idx = configurationService.getProperty("recent.submissions.sort-option"); if (idx == null) { throw new IOException("There is no configuration supplied for: recent.submissions.sort-option"); diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/CurateServlet.java b/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/CurateServlet.java index 37e4e4d7fe..b2aaa718ba 100644 --- a/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/CurateServlet.java +++ b/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/CurateServlet.java @@ -34,13 +34,14 @@ import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.CollectionService; import org.dspace.content.service.CommunityService; import org.dspace.content.service.ItemService; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Context; import org.dspace.core.I18nUtil; import org.dspace.core.LogManager; import org.dspace.curate.Curator; import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.service.HandleService; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; /** * @@ -49,22 +50,23 @@ import org.dspace.handle.service.HandleService; public class CurateServlet extends DSpaceServlet { // Name of queue used when tasks queued in Admin UI - private static final String TASK_QUEUE_NAME = ConfigurationManager.getProperty("curate", "ui.queuename"); + private final String TASK_QUEUE_NAME; // curation status codes in Admin UI: key=status code, value=localized name - private static final Map statusMessages = new HashMap<>(); + private final Map statusMessages = new HashMap<>(); // curation tasks to appear in admin UI: key=taskID, value=friendly name - private static Map allTasks = new LinkedHashMap<>(); + private Map allTasks = new LinkedHashMap<>(); // named groups which display together in admin UI: key=groupID, value=friendly group name - private static Map taskGroups = new LinkedHashMap<>(); + private Map taskGroups = new LinkedHashMap<>(); // group membership: key=groupID, value=array of taskID - private static Map groupedTasks = new LinkedHashMap<>(); + private Map groupedTasks = new LinkedHashMap<>(); - static + public CurateServlet() { + TASK_QUEUE_NAME = configurationService.getProperty("curate.ui.queuename"); try { setStatusMessages(); @@ -93,6 +95,9 @@ public class CurateServlet extends DSpaceServlet private final transient HandleService handleService = HandleServiceFactory.getInstance().getHandleService(); + private final transient ConfigurationService configurationService + = DSpaceServicesFactory.getInstance().getConfigurationService(); + @Override protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, @@ -318,10 +323,10 @@ public class CurateServlet extends DSpaceServlet return curator; } - private static void setStatusMessages() throws UnsupportedEncodingException + private void setStatusMessages() throws UnsupportedEncodingException { - String statusCodes = ConfigurationManager.getProperty("curate", "ui.statusmessages"); - for (String property : statusCodes.split(",")) + String[] statusCodes = configurationService.getArrayProperty("curate.ui.statusmessages"); + for (String property : statusCodes) { String[] keyValuePair = property.split("="); statusMessages.put(URLDecoder.decode(keyValuePair[0].trim(), "UTF-8"), @@ -329,10 +334,10 @@ public class CurateServlet extends DSpaceServlet } } - private static void setAllTasks() throws UnsupportedEncodingException + private void setAllTasks() throws UnsupportedEncodingException { - String properties = ConfigurationManager.getProperty("curate", "ui.tasknames"); - for (String property : properties.split(",")) + String[] properties = configurationService.getArrayProperty("curate.ui.tasknames"); + for (String property : properties) { String[] keyValuePair = property.split("="); allTasks.put(URLDecoder.decode(keyValuePair[0].trim(), "UTF-8"), @@ -340,12 +345,12 @@ public class CurateServlet extends DSpaceServlet } } - private static void setTaskGroups() throws UnsupportedEncodingException + private void setTaskGroups() throws UnsupportedEncodingException { - String groups = ConfigurationManager.getProperty("curate", "ui.taskgroups"); + String[] groups = configurationService.getArrayProperty("curate.ui.taskgroups"); if (groups != null) { - for (String property : groups.split(",")) + for (String property : groups) { String[] keyValuePair = property.split("="); taskGroups.put(URLDecoder.decode(keyValuePair[0].trim(), "UTF-8"), @@ -354,7 +359,7 @@ public class CurateServlet extends DSpaceServlet } } - private static void setGroupedTasks() throws UnsupportedEncodingException + private void setGroupedTasks() throws UnsupportedEncodingException { if (!taskGroups.isEmpty()) { @@ -362,8 +367,7 @@ public class CurateServlet extends DSpaceServlet while (iterator.hasNext()) { String groupID = iterator.next(); - String memberList = ConfigurationManager.getProperty("curate", "ui.taskgroup" + "." + groupID); - String[] members = memberList.split(","); + String[] members = configurationService.getArrayProperty("curate.ui.taskgroup" + "." + groupID); groupedTasks.put(URLDecoder.decode(groupID, "UTF-8"), members); } } @@ -401,7 +405,7 @@ public class CurateServlet extends DSpaceServlet * @param group the short name / identifier for the group * @return the string of the html option elements */ - private static String getTaskSelectOptions(String group) + private String getTaskSelectOptions(String group) { StringBuilder sb = new StringBuilder(); if (groupedTasks.isEmpty()) diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/util/CollectionStyleSelection.java b/dspace-jspui/src/main/java/org/dspace/app/webui/util/CollectionStyleSelection.java index 1659a81d9a..be285e93dd 100644 --- a/dspace-jspui/src/main/java/org/dspace/app/webui/util/CollectionStyleSelection.java +++ b/dspace-jspui/src/main/java/org/dspace/app/webui/util/CollectionStyleSelection.java @@ -8,13 +8,14 @@ package org.dspace.app.webui.util; import java.sql.SQLException; -import java.util.Enumeration; import java.util.HashMap; +import java.util.List; import org.apache.log4j.Logger; import org.dspace.content.Collection; import org.dspace.content.Item; -import org.dspace.core.ConfigurationManager; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; /** * This is the standard (until 1.4.x) configuration mode based on owning collection handle @@ -27,14 +28,18 @@ import org.dspace.core.ConfigurationManager; public class CollectionStyleSelection extends AKeyBasedStyleSelection { /** Hashmap of collection Handles to styles to use, from dspace.cfg */ - private static java.util.Map styles; + private java.util.Map styles; /** log4j logger */ private static Logger log = Logger.getLogger(CollectionStyleSelection.class); + private final transient ConfigurationService configurationService + = DSpaceServicesFactory.getInstance().getConfigurationService(); + /** * Get the style using the owning collection handle */ + @Override public String getStyleForItem(Item item) throws SQLException { Collection c = item.getOwningCollection(); @@ -57,20 +62,17 @@ public class CollectionStyleSelection extends AKeyBasedStyleSelection { styles = new HashMap(); - Enumeration e = (Enumeration)ConfigurationManager.propertyNames(); - - while (e.hasMoreElements()) + // Get all properties starting with "webui.itemdisplay" + List keys = configurationService.getPropertyKeys("webui.itemdisplay"); + + for(String key: keys) { - String key = e.nextElement(); - - if (key.startsWith("webui.itemdisplay.") - && key.endsWith(".collections")) + if (key.endsWith(".collections")) { String styleName = key.substring("webui.itemdisplay.".length(), key.length() - ".collections".length()); - String[] collections = ConfigurationManager.getProperty(key) - .split(","); + String[] collections = configurationService.getArrayProperty(key); for (int i = 0; i < collections.length; i++) { diff --git a/dspace-jspui/src/main/webapp/collection-home.jsp b/dspace-jspui/src/main/webapp/collection-home.jsp index 0eb5940b04..b51ff31e28 100644 --- a/dspace-jspui/src/main/webapp/collection-home.jsp +++ b/dspace-jspui/src/main/webapp/collection-home.jsp @@ -28,6 +28,7 @@ <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %> +<%@ page import="org.apache.commons.lang.StringUtils" %> <%@ page import="org.dspace.app.webui.components.RecentSubmissions" %> <%@ page import="org.dspace.app.webui.servlet.admin.EditCommunitiesServlet" %> @@ -36,9 +37,10 @@ <%@ page import="org.dspace.browse.BrowseInfo" %> <%@ page import="org.dspace.browse.ItemCounter"%> <%@ page import="org.dspace.content.*"%> -<%@ page import="org.dspace.core.ConfigurationManager"%> <%@ page import="org.dspace.core.Utils" %> <%@ page import="org.dspace.eperson.Group" %> +<%@ page import="org.dspace.services.ConfigurationService" %> +<%@ page import="org.dspace.services.factory.DSpaceServicesFactory" %> <%@ page import="javax.servlet.jsp.jstl.fmt.LocaleSupport" %> <% @@ -89,11 +91,16 @@ Bitstream logo = collection.getLogo(); - boolean feedEnabled = ConfigurationManager.getBooleanProperty("webui.feed.enable"); + ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); + + boolean feedEnabled = configurationService.getBooleanProperty("webui.feed.enable"); String feedData = "NONE"; if (feedEnabled) { - feedData = "coll:" + ConfigurationManager.getProperty("webui.feed.formats"); + // FeedData is expected to be a comma separated list + String[] formats = configurationService.getArrayProperty("webui.feed.formats"); + String allFormats = StringUtils.join(formats, ","); + feedData = "coll:" + allFormats; } ItemCounter ic = new ItemCounter(UIUtil.obtainContext(request)); @@ -110,7 +117,7 @@

<%= name %> <% - if(ConfigurationManager.getBooleanProperty("webui.strengths.show")) + if(configurationService.getBooleanProperty("webui.strengths.show")) { %> : [<%= ic.getCount(collection) %>] diff --git a/dspace-jspui/src/main/webapp/community-home.jsp b/dspace-jspui/src/main/webapp/community-home.jsp index 11c717f93d..294508aca5 100644 --- a/dspace-jspui/src/main/webapp/community-home.jsp +++ b/dspace-jspui/src/main/webapp/community-home.jsp @@ -27,6 +27,7 @@ <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %> +<%@ page import="org.apache.commons.lang.StringUtils" %> <%@ page import="org.dspace.app.webui.components.RecentSubmissions" %> <%@ page import="org.dspace.app.webui.servlet.admin.EditCommunitiesServlet" %> @@ -34,8 +35,9 @@ <%@ page import="org.dspace.browse.BrowseIndex" %> <%@ page import="org.dspace.browse.ItemCounter" %> <%@ page import="org.dspace.content.*" %> -<%@ page import="org.dspace.core.ConfigurationManager" %> <%@ page import="org.dspace.core.Utils" %> +<%@ page import="org.dspace.services.ConfigurationService" %> +<%@ page import="org.dspace.services.factory.DSpaceServicesFactory" %> <%@ page import="javax.servlet.jsp.jstl.fmt.LocaleSupport" %> <% @@ -66,11 +68,16 @@ String sidebar = comServ.getMetadata(community, "side_bar_text"); Bitstream logo = community.getLogo(); - boolean feedEnabled = ConfigurationManager.getBooleanProperty("webui.feed.enable"); + ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); + + boolean feedEnabled = configurationService.getBooleanProperty("webui.feed.enable"); String feedData = "NONE"; if (feedEnabled) { - feedData = "comm:" + ConfigurationManager.getProperty("webui.feed.formats"); + // FeedData is expected to be a comma separated list + String[] formats = configurationService.getArrayProperty("webui.feed.formats"); + String allFormats = StringUtils.join(formats, ","); + feedData = "comm:" + allFormats; } ItemCounter ic = new ItemCounter(UIUtil.obtainContext(request)); @@ -83,7 +90,7 @@

<%= name %> <% - if(ConfigurationManager.getBooleanProperty("webui.strengths.show")) + if(configurationService.getBooleanProperty("webui.strengths.show")) { %> : [<%= ic.getCount(community) %>] @@ -239,7 +246,7 @@
<% - boolean showLogos = ConfigurationManager.getBooleanProperty("jspui.community-home.logos", true); + boolean showLogos = configurationService.getBooleanProperty("jspui.community-home.logos", true); if (subcommunities.size() != 0) { %> @@ -267,7 +274,7 @@

<%= subcommunities.get(j).getName() %> <% - if (ConfigurationManager.getBooleanProperty("webui.strengths.show")) + if (configurationService.getBooleanProperty("webui.strengths.show")) { %> [<%= ic.getCount(subcommunities.get(j)) %>] @@ -323,7 +330,7 @@

<%= collections.get(i).getName() %> <% - if(ConfigurationManager.getBooleanProperty("webui.strengths.show")) + if(configurationService.getBooleanProperty("webui.strengths.show")) { %> [<%= ic.getCount(collections.get(i)) %>] diff --git a/dspace-jspui/src/main/webapp/home.jsp b/dspace-jspui/src/main/webapp/home.jsp index 15e18e5bfd..61e238b997 100644 --- a/dspace-jspui/src/main/webapp/home.jsp +++ b/dspace-jspui/src/main/webapp/home.jsp @@ -32,13 +32,15 @@ <%@ page import="java.util.Locale"%> <%@ page import="javax.servlet.jsp.jstl.core.*" %> <%@ page import="javax.servlet.jsp.jstl.fmt.LocaleSupport" %> +<%@ page import="org.apache.commons.lang.StringUtils" %> <%@ page import="org.dspace.core.I18nUtil" %> <%@ page import="org.dspace.app.webui.util.UIUtil" %> <%@ page import="org.dspace.app.webui.components.RecentSubmissions" %> <%@ page import="org.dspace.content.Community" %> -<%@ page import="org.dspace.core.ConfigurationManager" %> <%@ page import="org.dspace.browse.ItemCounter" %> <%@ page import="org.dspace.content.Item" %> +<%@ page import="org.dspace.services.ConfigurationService" %> +<%@ page import="org.dspace.services.factory.DSpaceServicesFactory" %> <% List communities = (List) request.getAttribute("communities"); @@ -49,11 +51,16 @@ String topNews = newsService.readNewsFile(LocaleSupport.getLocalizedMessage(pageContext, "news-top.html")); String sideNews = newsService.readNewsFile(LocaleSupport.getLocalizedMessage(pageContext, "news-side.html")); - boolean feedEnabled = ConfigurationManager.getBooleanProperty("webui.feed.enable"); + ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); + + boolean feedEnabled = configurationService.getBooleanProperty("webui.feed.enable"); String feedData = "NONE"; if (feedEnabled) { - feedData = "ALL:" + ConfigurationManager.getProperty("webui.feed.formats"); + // FeedData is expected to be a comma separated list + String[] formats = configurationService.getArrayProperty("webui.feed.formats"); + String allFormats = StringUtils.join(formats, ","); + feedData = "ALL:" + allFormats; } ItemCounter ic = new ItemCounter(UIUtil.obtainContext(request)); @@ -170,7 +177,7 @@ if (communities != null && communities.size() != 0)

<% - boolean showLogos = ConfigurationManager.getBooleanProperty("jspui.home-page.logos", true); + boolean showLogos = configurationService.getBooleanProperty("jspui.home-page.logos", true); for (Community com : communities) { %>
@@ -186,7 +193,7 @@ if (communities != null && communities.size() != 0) <% } %>

<%= com.getName() %> <% - if (ConfigurationManager.getBooleanProperty("webui.strengths.show")) + if (configurationService.getBooleanProperty("webui.strengths.show")) { %> <%= ic.getCount(com) %> diff --git a/dspace-sword/src/main/java/org/dspace/sword/SWORDConfiguration.java b/dspace-sword/src/main/java/org/dspace/sword/SWORDConfiguration.java index 7461daed0a..3935a9115b 100644 --- a/dspace-sword/src/main/java/org/dspace/sword/SWORDConfiguration.java +++ b/dspace-sword/src/main/java/org/dspace/sword/SWORDConfiguration.java @@ -9,20 +9,19 @@ package org.dspace.sword; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.BitstreamFormatService; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Context; import org.dspace.content.Collection; import org.dspace.content.DSpaceObject; import org.dspace.content.Item; import org.dspace.content.BitstreamFormat; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import org.purl.sword.base.SWORDErrorException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; -import java.util.Set; import java.sql.SQLException; import org.apache.log4j.Logger; @@ -50,6 +49,9 @@ public class SWORDConfiguration protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory .getInstance().getBitstreamFormatService(); + + protected ConfigurationService configurationService = DSpaceServicesFactory + .getInstance().getConfigurationService(); /** whether we can support noOp */ private boolean noOp = true; @@ -85,47 +87,47 @@ public class SWORDConfiguration public SWORDConfiguration() { // set the max upload size - int mus = ConfigurationManager - .getIntProperty("sword-server", "max-upload-size"); + int mus = configurationService + .getIntProperty("sword-server.max-upload-size"); if (mus > 0) { this.maxUploadSize = mus; } // set the mediation value - this.mediated = ConfigurationManager - .getBooleanProperty("sword-server", "on-behalf-of.enable"); + this.mediated = configurationService + .getBooleanProperty("sword-server.on-behalf-of.enable"); // find out if we keep the original as bitstream - this.keepOriginal = ConfigurationManager - .getBooleanProperty("sword-server", "keep-original-package"); + this.keepOriginal = configurationService + .getBooleanProperty("sword-server.keep-original-package"); // get the sword bundle - String bundle = ConfigurationManager - .getProperty("sword-server", "bundle.name"); + String bundle = configurationService + .getProperty("sword-server.bundle.name"); if (bundle != null && "".equals(bundle)) { this.swordBundle = bundle; } // find out if we keep the package as a file in specified directory - this.keepPackageOnFailedIngest = ConfigurationManager - .getBooleanProperty("sword-server", "keep-package-on-fail", + this.keepPackageOnFailedIngest = configurationService + .getBooleanProperty("sword-server.keep-package-on-fail", false); // get directory path and name - this.failedPackageDir = ConfigurationManager - .getProperty("sword-server", "failed-package.dir"); + this.failedPackageDir = configurationService + .getProperty("sword-server.failed-package.dir"); // Get the accepted formats - String acceptsProperty = ConfigurationManager - .getProperty("sword-server", "accepts"); + String[] acceptsFormats = configurationService + .getArrayProperty("sword-server.accepts"); swordaccepts = new ArrayList(); - if (acceptsProperty == null) + if (acceptsFormats == null) { - acceptsProperty = "application/zip"; + acceptsFormats = new String[]{"application/zip"}; } - for (String element : acceptsProperty.split(",")) + for (String element : acceptsFormats) { swordaccepts.add(element.trim()); } @@ -349,31 +351,18 @@ public class SWORDConfiguration String handle = col.getHandle(); // build the holding maps of identifiers and q values - Properties props = ConfigurationManager.getProperties("sword-server"); - Set keyset = props.keySet(); - for (Object keyObj : keyset) + String acceptPackagingPrefix = "sword-server.accept-packaging"; + List keys = configurationService.getPropertyKeys(acceptPackagingPrefix); + for (String key : keys) { - String sw = "accept-packaging."; - - if (!(keyObj instanceof String)) - { - continue; - } - String key = (String) keyObj; - - if (!key.startsWith(sw)) - { - continue; - } - // extract the configuration into the holding Maps - String suffix = key.substring(sw.length()); + String suffix = key.substring(acceptPackagingPrefix.length()+1); String[] bits = suffix.split("\\."); if (bits.length == 2) { // global settings - String value = props.getProperty(key); + String value = configurationService.getProperty(key); if (bits[1].equals("identifier")) { identifiers.put(bits[0], value); @@ -388,7 +377,7 @@ public class SWORDConfiguration if (bits.length == 3 && bits[0].equals(handle)) { // this is configuration for our collection - String value = props.getProperty(key); + String value = configurationService.getProperty(key); if (bits[2].equals("identifier")) { identifiers.put(bits[1], value); @@ -473,9 +462,9 @@ public class SWORDConfiguration public String getTempDir() throws DSpaceSWORDException { - return (ConfigurationManager.getProperty("upload.temp.dir") != null) + return (configurationService.getProperty("upload.temp.dir") != null) ? - ConfigurationManager.getProperty("upload.temp.dir") : + configurationService.getProperty("upload.temp.dir") : System.getProperty("java.io.tmpdir"); } } diff --git a/dspace-swordv2/src/main/java/org/dspace/sword2/GenericStatementDisseminator.java b/dspace-swordv2/src/main/java/org/dspace/sword2/GenericStatementDisseminator.java index 71abca0cbb..6af37a8192 100644 --- a/dspace-swordv2/src/main/java/org/dspace/sword2/GenericStatementDisseminator.java +++ b/dspace-swordv2/src/main/java/org/dspace/sword2/GenericStatementDisseminator.java @@ -10,7 +10,6 @@ package org.dspace.sword2; import org.dspace.content.Bitstream; import org.dspace.content.Bundle; import org.dspace.content.Item; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Context; import org.swordapp.server.OriginalDeposit; import org.swordapp.server.ResourcePart; @@ -22,6 +21,8 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.commons.lang.ArrayUtils; +import org.dspace.services.factory.DSpaceServicesFactory; public abstract class GenericStatementDisseminator implements SwordStatementDisseminator @@ -177,15 +178,14 @@ public abstract class GenericStatementDisseminator private List getIncludeBundles() { - String cfg = ConfigurationManager - .getProperty("swordv2-server", "statement.bundles"); - if (cfg == null || "".equals(cfg)) + String[] bundles = DSpaceServicesFactory.getInstance().getConfigurationService() + .getArrayProperty("swordv2-server.statement.bundles"); + if (ArrayUtils.isEmpty(bundles)) { - cfg = "ORIGINAL, SWORD"; + bundles = new String[] {"ORIGINAL", "SWORD"}; } - String[] bits = cfg.split(","); List include = new ArrayList(); - for (String bit : bits) + for (String bit : bundles) { String bundleName = bit.trim().toUpperCase(); if (!include.contains(bundleName)) @@ -198,8 +198,8 @@ public abstract class GenericStatementDisseminator private String getOriginalDepositsBundle() { - String swordBundle = ConfigurationManager - .getProperty("swordv2-server", "bundle.name"); + String swordBundle = DSpaceServicesFactory.getInstance().getConfigurationService() + .getProperty("swordv2-server.bundle.name"); if (swordBundle == null) { swordBundle = "SWORD"; diff --git a/dspace-swordv2/src/main/java/org/dspace/sword2/SimpleDCEntryIngester.java b/dspace-swordv2/src/main/java/org/dspace/sword2/SimpleDCEntryIngester.java index 207ccc0984..9305673a85 100644 --- a/dspace-swordv2/src/main/java/org/dspace/sword2/SimpleDCEntryIngester.java +++ b/dspace-swordv2/src/main/java/org/dspace/sword2/SimpleDCEntryIngester.java @@ -12,15 +12,17 @@ import org.dspace.authorize.AuthorizeException; import org.dspace.content.*; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.WorkspaceItemService; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Context; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import org.swordapp.server.*; -import java.io.IOException; import java.sql.SQLException; import java.util.Date; import java.util.List; import java.util.Map; +import org.apache.commons.lang.StringUtils; + public class SimpleDCEntryIngester extends AbstractSimpleDC implements SwordEntryIngester @@ -30,6 +32,9 @@ public class SimpleDCEntryIngester extends AbstractSimpleDC protected WorkspaceItemService workspaceItemService = ContentServiceFactory .getInstance().getWorkspaceItemService(); + + protected ConfigurationService configurationService = DSpaceServicesFactory + .getInstance().getConfigurationService(); public SimpleDCEntryIngester() { @@ -115,10 +120,9 @@ public class SimpleDCEntryIngester extends AbstractSimpleDC private void removeMetadata(Context context, Item item) throws DSpaceSwordException { - String raw = ConfigurationManager - .getProperty("swordv2-server", "metadata.replaceable"); - String[] parts = raw.split(","); - for (String part : parts) + String[] replaceableMetadata = configurationService + .getArrayProperty("swordv2-server.metadata.replaceable"); + for (String part : replaceableMetadata) { MetadataValueInfo info = this .makeMetadataValueInfo(part.trim(), null); @@ -340,12 +344,12 @@ public class SimpleDCEntryIngester extends AbstractSimpleDC VerboseDescription verboseDescription) throws DSpaceSwordException { - String field = ConfigurationManager - .getProperty("swordv2-server", "updated.field"); - if (field == null || "".equals(field)) + String field = configurationService + .getProperty("swordv2-server.updated.field"); + if (StringUtils.isBlank(field)) { throw new DSpaceSwordException( - "No configuration, or configuration is invalid for: sword.updated.field"); + "No configuration, or configuration is invalid for: swordv2-server.updated.field"); } MetadataValueInfo info = this.makeMetadataValueInfo(field, null); @@ -389,12 +393,12 @@ public class SimpleDCEntryIngester extends AbstractSimpleDC return; } - String field = ConfigurationManager - .getProperty("swordv2-server", "slug.field"); - if (field == null || "".equals(field)) + String field = configurationService + .getProperty("swordv2-server.slug.field"); + if (StringUtils.isBlank(field)) { throw new DSpaceSwordException( - "No configuration, or configuration is invalid for: sword.slug.field"); + "No configuration, or configuration is invalid for: swordv2-server.slug.field"); } MetadataValueInfo info = this.makeMetadataValueInfo(field, null); diff --git a/dspace-swordv2/src/main/java/org/dspace/sword2/SwordAuthenticator.java b/dspace-swordv2/src/main/java/org/dspace/sword2/SwordAuthenticator.java index 02770731e4..72323dd9e6 100644 --- a/dspace-swordv2/src/main/java/org/dspace/sword2/SwordAuthenticator.java +++ b/dspace-swordv2/src/main/java/org/dspace/sword2/SwordAuthenticator.java @@ -7,10 +7,8 @@ */ package org.dspace.sword2; -import org.dspace.authenticate.AuthenticationServiceImpl; import org.dspace.authenticate.factory.AuthenticateServiceFactory; import org.dspace.authenticate.service.AuthenticationService; -import org.dspace.authorize.AuthorizeServiceImpl; import org.dspace.authorize.factory.AuthorizeServiceFactory; import org.dspace.authorize.service.AuthorizeService; import org.dspace.content.factory.ContentServiceFactory; @@ -18,17 +16,17 @@ import org.dspace.content.service.CollectionService; import org.dspace.content.service.CommunityService; import org.dspace.content.service.ItemService; import org.dspace.core.Context; -import org.dspace.core.ConfigurationManager; import org.dspace.core.LogManager; import org.dspace.core.Constants; import org.dspace.authenticate.AuthenticationMethod; import org.dspace.eperson.EPerson; import org.dspace.eperson.Group; -import org.dspace.authorize.AuthorizeException; import org.dspace.content.*; import org.apache.log4j.Logger; import org.dspace.eperson.factory.EPersonServiceFactory; import org.dspace.eperson.service.EPersonService; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import org.swordapp.server.AuthCredentials; import org.swordapp.server.SwordAuthException; import org.swordapp.server.SwordError; @@ -38,6 +36,7 @@ import java.sql.SQLException; import java.util.Iterator; import java.util.List; import java.util.ArrayList; +import org.apache.commons.lang.StringUtils; /** * This class offers a thin wrapper for the default DSpace @@ -68,6 +67,9 @@ public class SwordAuthenticator protected ItemService itemService = ContentServiceFactory.getInstance() .getItemService(); + + protected ConfigurationService configurationService = DSpaceServicesFactory + .getInstance().getConfigurationService(); /** * Does the given username and password authenticate for the @@ -155,14 +157,14 @@ public class SwordAuthenticator // smooth out the OnBehalfOf request, so that empty strings are // treated as null - if ("".equals(obo)) + if (StringUtils.isBlank(obo)) { obo = null; } // first find out if we support on-behalf-of deposit - boolean mediated = ConfigurationManager - .getBooleanProperty("swordv2-server", "on-behalf-of.enable"); + boolean mediated = configurationService + .getBooleanProperty("swordv2-server.on-behalf-of.enable", false); if (!mediated && obo != null) { // user is trying to do a mediated deposit on a repository which does not support it @@ -1002,9 +1004,9 @@ public class SwordAuthenticator private boolean allowedToMediate(Context context) { // get the configuration - String mediatorCfg = ConfigurationManager - .getProperty("swordv2-server", "on-behalf-of.update.mediators"); - if (mediatorCfg == null) + String[] mediators = configurationService + .getArrayProperty("swordv2-server.on-behalf-of.update.mediators"); + if (mediators == null || mediators.length==0) { // if there's no explicit list of mediators, then anyone can mediate return true; @@ -1019,7 +1021,6 @@ public class SwordAuthenticator String email = eperson.getEmail(); String netid = eperson.getNetid(); - String[] mediators = mediatorCfg.split(","); for (String mediator : mediators) { String m = mediator.trim(); diff --git a/dspace-swordv2/src/main/java/org/dspace/sword2/SwordConfigurationDSpace.java b/dspace-swordv2/src/main/java/org/dspace/sword2/SwordConfigurationDSpace.java index 9c56536c7f..ed278bbadc 100644 --- a/dspace-swordv2/src/main/java/org/dspace/sword2/SwordConfigurationDSpace.java +++ b/dspace-swordv2/src/main/java/org/dspace/sword2/SwordConfigurationDSpace.java @@ -14,18 +14,17 @@ import org.dspace.content.DSpaceObject; import org.dspace.content.Item; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.BitstreamFormatService; -import org.dspace.core.ConfigurationManager; import org.dspace.core.Context; -import org.dspace.core.LegacyPluginServiceImpl; -import org.jaxen.function.FalseFunction; import org.swordapp.server.SwordConfiguration; import org.swordapp.server.SwordError; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.Properties; -import java.util.Set; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.ArrayUtils; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; public class SwordConfigurationDSpace implements SwordConfiguration { @@ -35,6 +34,9 @@ public class SwordConfigurationDSpace implements SwordConfiguration protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory .getInstance().getBitstreamFormatService(); + + protected ConfigurationService configurationService = DSpaceServicesFactory + .getInstance().getConfigurationService(); /** whether we can be verbose */ private boolean verbose = true; @@ -71,59 +73,58 @@ public class SwordConfigurationDSpace implements SwordConfiguration public SwordConfigurationDSpace() { // set the max upload size - int mus = ConfigurationManager - .getIntProperty("swordv2-server", "max-upload-size"); + int mus = configurationService + .getIntProperty("swordv2-server.max-upload-size"); if (mus > 0) { this.maxUploadSize = mus; } // set the mediation value - this.mediated = ConfigurationManager - .getBooleanProperty("swordv2-server", "on-behalf-of.enable"); + this.mediated = configurationService + .getBooleanProperty("swordv2-server.on-behalf-of.enable", false); // find out if we keep the original as bitstream - this.keepOriginal = ConfigurationManager - .getBooleanProperty("swordv2-server", "keep-original-package"); + this.keepOriginal = configurationService + .getBooleanProperty("swordv2-server.keep-original-package"); // get the sword bundle - String bundle = ConfigurationManager - .getProperty("swordv2-server", "bundle.name"); - if (bundle != null && "".equals(bundle)) + String bundle = configurationService + .getProperty("swordv2-server.bundle.name"); + if (StringUtils.isBlank(bundle)) { this.swordBundle = bundle; } // find out if we keep the package as a file in specified directory - this.keepPackageOnFailedIngest = ConfigurationManager - .getBooleanProperty("swordv2-server", "keep-package-on-fail", + this.keepPackageOnFailedIngest = configurationService + .getBooleanProperty("swordv2-server.keep-package-on-fail", false); // get directory path and name - this.failedPackageDir = ConfigurationManager - .getProperty("swordv2-server", "failed-package.dir"); + this.failedPackageDir = configurationService + .getProperty("swordv2-server.failed-package.dir"); // Get the accepted formats - String acceptsProperty = ConfigurationManager - .getProperty("swordv2-server", "accepts"); + String[] acceptsFormats = configurationService + .getArrayProperty("swordv2-server.accepts"); swordaccepts = new ArrayList(); - if (acceptsProperty == null) + if (ArrayUtils.isEmpty(acceptsFormats)) { - acceptsProperty = "application/zip"; + acceptsFormats = new String[]{"application/zip"}; } - for (String element : acceptsProperty.split(",")) + for (String element : acceptsFormats) { swordaccepts.add(element.trim()); } // find out if community deposit is allowed - this.allowCommunityDeposit = ConfigurationManager - .getBooleanProperty("swordv2-server", - "allow-community-deposit"); + this.allowCommunityDeposit = configurationService + .getBooleanProperty("swordv2-server.allow-community-deposit"); // find out if we keep the package as a file in specified directory - this.entryFirst = ConfigurationManager - .getBooleanProperty("swordv2-server", "multipart.entry-first", + this.entryFirst = configurationService + .getBooleanProperty("swordv2-server.multipart.entry-first", false); } @@ -132,19 +133,11 @@ public class SwordConfigurationDSpace implements SwordConfiguration // Utilities /////////////////////////////////////////////////////////////////////////////////// - public String getStringProperty(String module, String propName, + public String getStringProperty(String propName, String defaultValue, String[] allowedValues) { - String cfg; - if (module == null) - { - cfg = ConfigurationManager.getProperty(propName); - } - else - { - cfg = ConfigurationManager.getProperty(module, propName); - } - if (cfg == null || "".equals(cfg)) + String cfg = configurationService.getProperty(propName); + if (StringUtils.isBlank(cfg)) { return defaultValue; } @@ -170,10 +163,10 @@ public class SwordConfigurationDSpace implements SwordConfiguration return defaultValue; } - public String getStringProperty(String module, String propName, + public String getStringProperty(String propName, String defaultValue) { - return this.getStringProperty(module, propName, defaultValue, null); + return this.getStringProperty(propName, defaultValue, null); } /////////////////////////////////////////////////////////////////////////////////// @@ -187,8 +180,7 @@ public class SwordConfigurationDSpace implements SwordConfiguration public boolean returnStackTraceInError() { - return ConfigurationManager.getBooleanProperty("swordv2-server", - "verbose-description.error.enable"); + return configurationService.getBooleanProperty("swordv2-server.verbose-description.error.enable"); } public boolean returnErrorBody() @@ -198,24 +190,24 @@ public class SwordConfigurationDSpace implements SwordConfiguration public String generator() { - return this.getStringProperty("swordv2-server", "generator.url", + return this.getStringProperty("swordv2-server.generator.url", DSpaceUriRegistry.DSPACE_SWORD_NS); } public String generatorVersion() { - return this.getStringProperty("swordv2-server", "generator.version", + return this.getStringProperty("swordv2-server.generator.version", "2.0"); } public String administratorEmail() { - return this.getStringProperty(null, "mail.admin", null); + return this.getStringProperty("mail.admin", null); } public String getAuthType() { - return this.getStringProperty("swordv2-server", "auth-type", "Basic", + return this.getStringProperty("swordv2-server.auth-type", "Basic", new String[] { "Basic", "None" }); } @@ -226,19 +218,19 @@ public class SwordConfigurationDSpace implements SwordConfiguration public String getTempDirectory() { - return this.getStringProperty("swordv2-server", "upload.tempdir", null); + return this.getStringProperty("swordv2-server.upload.tempdir", null); } public String getAlternateUrl() { - return ConfigurationManager - .getProperty("swordv2-server", "error.alternate.url"); + return configurationService + .getProperty("swordv2-server.error.alternate.url"); } public String getAlternateUrlContentType() { - return ConfigurationManager - .getProperty("swordv2-server", "error.alternate.content-type"); + return configurationService + .getProperty("swordv2-server.error.alternate.content-type"); } /////////////////////////////////////////////////////////////////////////////////// @@ -255,25 +247,10 @@ public class SwordConfigurationDSpace implements SwordConfiguration throws DSpaceSwordException, SwordError { List dps = new ArrayList(); - Properties props = ConfigurationManager.getProperties("swordv2-server"); - Set keyset = props.keySet(); - for (Object keyObj : keyset) + List packagingFormats = configurationService.getPropertyKeys("swordv2-server.disseminate-packaging"); + for (String key : packagingFormats) { - // start by getting anything that starts with sword.disseminate-packging. - String sw = "disseminate-packaging."; - - if (!(keyObj instanceof String)) - { - continue; - } - String key = (String) keyObj; - - if (!key.startsWith(sw)) - { - continue; - } - - String value = props.getProperty((key)); + String value = configurationService.getProperty(key); // now we want to ensure that the packaging format we offer has a disseminator // associated with it @@ -517,28 +494,14 @@ public class SwordConfigurationDSpace implements SwordConfiguration List aps = new ArrayList(); // build the holding maps of identifiers - Properties props = ConfigurationManager.getProperties("swordv2-server"); - Set keyset = props.keySet(); - for (Object keyObj : keyset) + String acceptPackagingPrefix = "swordv2-server.accept-packaging.collection"; + List acceptFormats = configurationService.getPropertyKeys(acceptPackagingPrefix); + for (String key : acceptFormats) { - // start by getting anything that starts with sword.accept-packaging.collection. - String sw = "accept-packaging.collection."; - - if (!(keyObj instanceof String)) - { - continue; - } - String key = (String) keyObj; - - if (!key.startsWith(sw)) - { - continue; - } - // extract the configuration into the holding Maps // the suffix will be [typeid] or [handle].[typeid] - String suffix = key.substring(sw.length()); + String suffix = key.substring(acceptPackagingPrefix.length()+1); // is there a handle which represents this collection? boolean withHandle = false; @@ -557,7 +520,7 @@ public class SwordConfigurationDSpace implements SwordConfiguration if (withHandle || general) { - String value = props.getProperty((key)); + String value = configurationService.getProperty(key); aps.add(value); } } @@ -570,26 +533,12 @@ public class SwordConfigurationDSpace implements SwordConfiguration List aps = new ArrayList(); // build the holding maps of identifiers - Properties props = ConfigurationManager.getProperties("swordv2-server"); - Set keyset = props.keySet(); - for (Object keyObj : keyset) + String acceptPackagingPrefix = "swordv2-server.accept-packaging.item"; + List acceptFormats = configurationService.getPropertyKeys(acceptPackagingPrefix); + for (String key : acceptFormats) { - // start by getting anything that starts with sword.accept-packging.collection. - String sw = "accept-packaging.item."; - - if (!(keyObj instanceof String)) - { - continue; - } - String key = (String) keyObj; - - if (!key.startsWith(sw)) - { - continue; - } - // extract the configuration into the holding Maps - String value = props.getProperty((key)); + String value = configurationService.getProperty(key); aps.add(value); } @@ -696,14 +645,14 @@ public class SwordConfigurationDSpace implements SwordConfiguration public String getStateUri(String state) { - return ConfigurationManager - .getProperty("swordv2-server", "state." + state + ".uri"); + return configurationService + .getProperty("swordv2-server.state." + state + ".uri"); } public String getStateDescription(String state) { - return ConfigurationManager.getProperty("swordv2-server", - "state." + state + ".description"); + return configurationService + .getProperty("swordv2-server.state." + state + ".description"); } public boolean allowUnauthenticatedMediaAccess() diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowCurationUtils.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowCurationUtils.java index 9fcc5263d0..400e796063 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowCurationUtils.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowCurationUtils.java @@ -68,8 +68,8 @@ public class FlowCurationUtils { if (map.isEmpty()) { - String statusCodes = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("curate.ui.statusmessages"); - for (String pair : statusCodes.split(",")) + String[] statusCodes = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("curate.ui.statusmessages"); + for (String pair : statusCodes) { String[] parts = pair.split("="); map.put(parts[0].trim(), parts[1].trim()); @@ -270,8 +270,7 @@ public class FlowCurationUtils public static void setAllTasks() throws WingException, UnsupportedEncodingException { - String csvList = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("curate." + CURATE_TASK_NAMES); - String[] properties = csvList.split(","); + String[] properties = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("curate." + CURATE_TASK_NAMES); for (String property : properties) { //System.out.println("set all tasks and property = " + property + "\n"); @@ -283,12 +282,11 @@ public class FlowCurationUtils public static void setGroups() throws WingException, UnsupportedEncodingException { - String csvList = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("curate." + CURATE_GROUP_NAMES); - if (csvList != null) + String[] properties = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("curate." + CURATE_GROUP_NAMES); + if (properties != null) { - String[] properties = csvList.split(","); for (String property : properties) - { + { String[] keyValuePair = property.split("="); groups.put(URLDecoder.decode(keyValuePair[0].trim(), "UTF-8"), URLDecoder.decode(keyValuePair[1].trim(), "UTF-8")); @@ -308,8 +306,7 @@ public class FlowCurationUtils while (iterator.hasNext()) { String key = iterator.next(); - String csvList = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("curate." + CURATE_GROUP_PREFIX + "." + key); - String[] properties = csvList.split(","); + String[] properties = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("curate." + CURATE_GROUP_PREFIX + "." + key); groupedTasks.put(URLDecoder.decode(key, "UTF-8"), properties); } } diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/item/AddBitstreamForm.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/item/AddBitstreamForm.java index ce28429578..1539777281 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/item/AddBitstreamForm.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/item/AddBitstreamForm.java @@ -10,6 +10,7 @@ package org.dspace.app.xmlui.aspect.administrative.item; import java.io.IOException; import java.sql.SQLException; import java.util.UUID; +import org.apache.commons.lang.ArrayUtils; import org.dspace.app.xmlui.aspect.submission.submit.AccessStepUtil; import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer; @@ -64,7 +65,7 @@ public class AddBitstreamForm extends AbstractDSpaceTransformer private static final Message T_no_bundles = message("xmlui.administrative.item.AddBitstreamForm.no_bundles"); - private static final String DEFAULT_BUNDLE_LIST = "ORIGINAL, METADATA, THUMBNAIL, LICENSE, CC-LICENSE"; + private static final String[] DEFAULT_BUNDLE_LIST = new String[]{"ORIGINAL", "METADATA", "THUMBNAIL", "LICENSE", "CC-LICENSE"}; private boolean isAdvancedFormEnabled=true; @@ -102,13 +103,12 @@ public class AddBitstreamForm extends AbstractDSpaceTransformer // Get the list of bundles to allow the user to upload too. Either use the default // or one supplied from the dspace.cfg. - String bundleString = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("xmlui.bundle.upload"); - if (bundleString == null || bundleString.length() == 0) + String[] bundles = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("xmlui.bundle.upload"); + if (ArrayUtils.isEmpty(bundles)) { - bundleString = DEFAULT_BUNDLE_LIST; + bundles = DEFAULT_BUNDLE_LIST; } - String[] parts = bundleString.split(","); - for (String part : parts) + for (String part : bundles) { if (addBundleOption(item, select, part.trim())) { diff --git a/dspace/config/modules/swordv2-server.cfg b/dspace/config/modules/swordv2-server.cfg index 0ea38c23ce..6e6cfd1c39 100644 --- a/dspace/config/modules/swordv2-server.cfg +++ b/dspace/config/modules/swordv2-server.cfg @@ -135,7 +135,7 @@ swordv2-server.keep-original-package = true # See the SWORD specification for a detailed explanation of deposit # On-Behalf-Of another user # -swordv2-server.on-behalf-of.enable = true +swordv2-server.on-behalf-of.enable = false # # Which user accounts are allowed to do updates on items which already # exist in DSpace, on-behalf-of other users? @@ -190,7 +190,8 @@ swordv2-server.error.alternate.content-type = text/html swordv2-server.generator.version = 2.0 # The form of authentication to use -# This is normally set to 'basic' for HTTP Basic +# This is normally set to 'Basic' for HTTP Basic +# Other valid values: 'None' swordv2-server.auth-type = Basic # The location where uploaded files and packages are