Merge remote-tracking branch '4science-bitbucket/main' into CST-5306

This commit is contained in:
Luca Giamminonni
2022-04-04 11:28:48 +02:00
65 changed files with 832 additions and 479 deletions

View File

@@ -520,7 +520,7 @@
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<artifactId>jdom2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
@@ -581,9 +581,12 @@
</dependency>
<!-- Used for RSS / ATOM syndication feeds -->
<dependency>
<groupId>org.rometools</groupId>
<groupId>com.rometools</groupId>
<artifactId>rome</artifactId>
</dependency>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-modules</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.jbibtex</groupId>
@@ -815,44 +818,6 @@
<artifactId>jaxb-runtime</artifactId>
</dependency>
<!-- Apache Axiom -->
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>${axiom.version}</version>
<exclusions>
<!-- Exclude Geronimo as it is NOT necessary when using javax.activation (which we use)
See: https://ws.apache.org/axiom/userguide/ch04.html#d0e732 -->
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>*</artifactId>
</exclusion>
<!-- Exclude Woodstox, as later version provided by Solr dependencies -->
<exclusion>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>${axiom.version}</version>
<exclusions>
<!-- Exclude Geronimo as it is NOT necessary when using javax.activation (which we use)
See: https://ws.apache.org/axiom/userguide/ch04.html#d0e732 -->
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>*</artifactId>
</exclusion>
<!-- Exclude Woodstox, as later version provided by Solr dependencies -->
<exclusion>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Jersey / JAX-RS client (javax.ws.rs.*) dependencies needed to integrate with external sources/services -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
@@ -908,6 +873,14 @@
<version>20180130</version>
</dependency>
<!-- Useful for testing command-line tools -->
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.19.0</version>
<scope>test</scope>
</dependency>
<!-- Used for Solr core export/import -->
<dependency>
<groupId>com.opencsv</groupId>
@@ -919,7 +892,6 @@
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<type>jar</type>
</dependency>
<dependency>
@@ -994,7 +966,7 @@
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.2</version>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>

View File

@@ -52,9 +52,9 @@ import org.dspace.content.service.CommunityService;
import org.dspace.core.Context;
import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.eperson.service.EPersonService;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -307,7 +307,7 @@ public class StructBuilder {
}
// finally write the string into the output file.
final org.jdom.Document xmlOutput = new org.jdom.Document(root);
final org.jdom2.Document xmlOutput = new org.jdom2.Document(root);
try {
new XMLOutputter().output(xmlOutput, output);
} catch (IOException e) {
@@ -411,7 +411,7 @@ public class StructBuilder {
}
// Now write the structure out.
org.jdom.Document xmlOutput = new org.jdom.Document(rootElement);
org.jdom2.Document xmlOutput = new org.jdom2.Document(rootElement);
try {
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
outputter.output(xmlOutput, output);

View File

@@ -16,7 +16,7 @@ import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.List;
import org.jdom.Document;
import org.jdom2.Document;
/**
* @author mwood

View File

@@ -29,9 +29,9 @@ import org.dspace.scripts.service.ScriptService;
import org.dspace.servicemanager.DSpaceKernelImpl;
import org.dspace.servicemanager.DSpaceKernelInit;
import org.dspace.services.RequestService;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;
/**
* A DSpace script launcher.

View File

@@ -37,6 +37,7 @@ public class Configuration {
* <li>{@code --property name} prints the value of the DSpace configuration
* property {@code name} to the standard output.</li>
* <li>{@code --raw} suppresses parameter substitution in the output.</li>
* <li>{@code --first} print only the first of multiple values.</li>
* <li>{@code --help} describes these options.</li>
* </ul>
* If the property does not exist, nothing is written.
@@ -51,6 +52,8 @@ public class Configuration {
"optional name of the module in which 'property' exists");
options.addOption("r", "raw", false,
"do not do property substitution on the value");
options.addOption("f", "first", false,
"display only the first value of an array property");
options.addOption("?", "Get help");
options.addOption("h", "help", false, "Get help");
@@ -90,19 +93,36 @@ public class Configuration {
propNameBuilder.append(cmd.getOptionValue('p'));
String propName = propNameBuilder.toString();
// Print the property's value, if it exists
// Print the property's value(s), if it exists
ConfigurationService cfg = DSpaceServicesFactory.getInstance().getConfigurationService();
if (!cfg.hasProperty(propName)) {
System.out.println();
} else {
String val;
if (cmd.hasOption('r')) {
val = cfg.getPropertyValue(propName).toString();
// Print "raw" values (without property substitutions)
Object rawValue = cfg.getPropertyValue(propName);
if (rawValue.getClass().isArray()) {
for (Object value : (Object[]) rawValue) {
System.out.println(value.toString());
if (cmd.hasOption('f')) {
break; // If --first print only one value
}
}
} else { // Not an array
System.out.println(rawValue.toString());
}
} else {
val = cfg.getProperty(propName);
// Print values with property substitutions
String[] values = cfg.getArrayProperty(propName);
for (String value : values) {
System.out.println(value);
if (cmd.hasOption('f')) {
break; // If --first print only one value
}
}
}
System.out.println(val);
}
System.exit(0);
}
}

View File

@@ -42,7 +42,7 @@ import org.dspace.core.Context;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Element;
import org.jdom2.Element;
/**
* Configuration and mapping for Google Scholar output metadata

View File

@@ -16,10 +16,10 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.sun.syndication.feed.module.opensearch.OpenSearchModule;
import com.sun.syndication.feed.module.opensearch.entity.OSQuery;
import com.sun.syndication.feed.module.opensearch.impl.OpenSearchModuleImpl;
import com.sun.syndication.io.FeedException;
import com.rometools.modules.opensearch.OpenSearchModule;
import com.rometools.modules.opensearch.entity.OSQuery;
import com.rometools.modules.opensearch.impl.OpenSearchModuleImpl;
import com.rometools.rome.io.FeedException;
import org.apache.logging.log4j.Logger;
import org.dspace.app.util.service.OpenSearchService;
import org.dspace.content.DSpaceObject;
@@ -29,11 +29,11 @@ import org.dspace.discovery.IndexableObject;
import org.dspace.handle.service.HandleService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.output.DOMOutputter;
import org.jdom.output.XMLOutputter;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.Namespace;
import org.jdom2.output.DOMOutputter;
import org.jdom2.output.XMLOutputter;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.Document;
@@ -192,7 +192,7 @@ public class OpenSearchServiceImpl implements OpenSearchService {
* @param scope - null for the entire repository, or a collection/community handle
* @return Service Document
*/
protected org.jdom.Document getServiceDocument(String scope) {
protected org.jdom2.Document getServiceDocument(String scope) {
ConfigurationService config = DSpaceServicesFactory.getInstance().getConfigurationService();
Namespace ns = Namespace.getNamespace(osNs);
@@ -245,7 +245,7 @@ public class OpenSearchServiceImpl implements OpenSearchService {
url.setAttribute("template", template.toString());
root.addContent(url);
}
return new org.jdom.Document(root);
return new org.jdom2.Document(root);
}
/**
@@ -255,7 +255,7 @@ public class OpenSearchServiceImpl implements OpenSearchService {
* @return W3C Document object
* @throws IOException if IO error
*/
protected Document jDomToW3(org.jdom.Document jdomDoc) throws IOException {
protected Document jDomToW3(org.jdom2.Document jdomDoc) throws IOException {
DOMOutputter domOut = new DOMOutputter();
try {
return domOut.output(jdomDoc);

View File

@@ -15,26 +15,26 @@ import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.sun.syndication.feed.module.DCModule;
import com.sun.syndication.feed.module.DCModuleImpl;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.feed.module.itunes.EntryInformation;
import com.sun.syndication.feed.module.itunes.EntryInformationImpl;
import com.sun.syndication.feed.module.itunes.types.Duration;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndContentImpl;
import com.sun.syndication.feed.synd.SyndEnclosure;
import com.sun.syndication.feed.synd.SyndEnclosureImpl;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndEntryImpl;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl;
import com.sun.syndication.feed.synd.SyndImage;
import com.sun.syndication.feed.synd.SyndImageImpl;
import com.sun.syndication.feed.synd.SyndPerson;
import com.sun.syndication.feed.synd.SyndPersonImpl;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedOutput;
import com.rometools.modules.itunes.EntryInformation;
import com.rometools.modules.itunes.EntryInformationImpl;
import com.rometools.modules.itunes.types.Duration;
import com.rometools.rome.feed.module.DCModule;
import com.rometools.rome.feed.module.DCModuleImpl;
import com.rometools.rome.feed.module.Module;
import com.rometools.rome.feed.synd.SyndContent;
import com.rometools.rome.feed.synd.SyndContentImpl;
import com.rometools.rome.feed.synd.SyndEnclosure;
import com.rometools.rome.feed.synd.SyndEnclosureImpl;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndEntryImpl;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.feed.synd.SyndFeedImpl;
import com.rometools.rome.feed.synd.SyndImage;
import com.rometools.rome.feed.synd.SyndImageImpl;
import com.rometools.rome.feed.synd.SyndPerson;
import com.rometools.rome.feed.synd.SyndPersonImpl;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedOutput;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;

View File

@@ -14,8 +14,8 @@ import java.util.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Context;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom2.Element;
import org.jdom2.Namespace;
/**
* Crosswalk descriptive metadata to and from DIM (DSpace Intermediate

View File

@@ -40,8 +40,8 @@ import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom2.Element;
import org.jdom2.Namespace;
/**
* Crosswalk of technical metadata for DSpace AIP. This is

View File

@@ -23,8 +23,8 @@ import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom2.Element;
import org.jdom2.Namespace;
/**
* DIM dissemination crosswalk

View File

@@ -19,8 +19,8 @@ import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom2.Element;
import org.jdom2.Namespace;
/**
* DIM ingestion crosswalk

View File

@@ -14,8 +14,8 @@ import java.util.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Context;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom2.Element;
import org.jdom2.Namespace;
/**
* Dissemination Crosswalk plugin -- translate DSpace native

View File

@@ -14,7 +14,7 @@ import java.util.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Context;
import org.jdom.Element;
import org.jdom2.Element;
/**
* Ingestion Crosswalk plugin -- translate an external metadata format

View File

@@ -24,11 +24,11 @@ import org.dspace.core.Context;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.Namespace;
import org.jdom2.input.SAXBuilder;
/**
* METS dissemination crosswalk

View File

@@ -35,8 +35,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.jdom.Element;
import org.jdom.Namespace;
import org.jdom2.Element;
import org.jdom2.Namespace;
/**
* METSRights Ingestion and Dissemination Crosswalk

View File

@@ -15,7 +15,6 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -42,16 +41,18 @@ import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.Text;
import org.jdom.Verifier;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom.xpath.XPath;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.Namespace;
import org.jdom2.Text;
import org.jdom2.Verifier;
import org.jdom2.filter.Filters;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.XMLOutputter;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
/**
* Configurable MODS Crosswalk
@@ -156,7 +157,7 @@ public class MODSDisseminationCrosswalk extends SelfNamedPlugin
static class modsTriple {
public String qdc = null;
public Element xml = null;
public XPath xpath = null;
public XPathExpression xpath = null;
/**
* Initialize from text versions of QDC, XML and XPath.
@@ -171,9 +172,9 @@ public class MODSDisseminationCrosswalk extends SelfNamedPlugin
final String postlog = "</mods>";
try {
result.qdc = qdc;
result.xpath = XPath.newInstance(xpath);
result.xpath.addNamespace(MODS_NS.getPrefix(), MODS_NS.getURI());
result.xpath.addNamespace(XLINK_NS);
result.xpath =
XPathFactory.instance()
.compile(xpath, Filters.fpassthrough(), null, MODS_NS, XLINK_NS);
Document d = builder.build(new StringReader(prolog + xml + postlog));
result.xml = (Element) d.getRootElement().getContent(0);
} catch (JDOMException | IOException je) {
@@ -295,6 +296,7 @@ public class MODSDisseminationCrosswalk extends SelfNamedPlugin
* @throws IOException if IO error
* @throws SQLException if database error
* @throws AuthorizeException if authorization error
* @return List of Elements
*/
@Override
public List<Element> disseminateList(Context context, DSpaceObject dso)
@@ -352,37 +354,29 @@ public class MODSDisseminationCrosswalk extends SelfNamedPlugin
if (trip == null) {
log.warn("WARNING: " + getPluginInstanceName() + ": No MODS mapping for \"" + qdc + "\"");
} else {
try {
Element me = (Element) trip.xml.clone();
if (addSchema) {
me.setAttribute("schemaLocation", schemaLocation, XSI_NS);
}
Iterator ni = trip.xpath.selectNodes(me).iterator();
if (!ni.hasNext()) {
log.warn("XPath \"" + trip.xpath.getXPath() +
"\" found no elements in \"" +
outputUgly.outputString(me) +
"\", qdc=" + qdc);
}
while (ni.hasNext()) {
Object what = ni.next();
if (what instanceof Element) {
((Element) what).setText(checkedString(value));
} else if (what instanceof Attribute) {
((Attribute) what).setValue(checkedString(value));
} else if (what instanceof Text) {
((Text) what).setText(checkedString(value));
} else {
log.warn("Got unknown object from XPath, class=" + what.getClass().getName());
}
}
result.add(me);
} catch (JDOMException je) {
log.error("Error following XPath in modsTriple: context=" +
outputUgly.outputString(trip.xml) +
", xpath=" + trip.xpath.getXPath() + ", exception=" +
je.toString());
Element me = (Element) trip.xml.clone();
if (addSchema) {
me.setAttribute("schemaLocation", schemaLocation, XSI_NS);
}
List<Object> matches = trip.xpath.evaluate(me);
if (matches.isEmpty()) {
log.warn("XPath \"" + trip.xpath.getExpression() +
"\" found no elements in \"" +
outputUgly.outputString(me) +
"\", qdc=" + qdc);
}
for (Object match: matches) {
if (match instanceof Element) {
((Element) match).setText(checkedString(value));
} else if (match instanceof Attribute) {
((Attribute) match).setValue(checkedString(value));
} else if (match instanceof Text) {
((Text) match).setText(checkedString(value));
} else {
log.warn("Got unknown object from XPath, class=" + match.getClass().getName());
}
}
result.add(me);
}
}
return result;

View File

@@ -15,9 +15,9 @@ import org.apache.logging.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Context;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
/**
* "Null" ingestion crosswalk

View File

@@ -20,8 +20,8 @@ import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom2.Element;
import org.jdom2.Namespace;
/**
* DIM ingestion crosswalk

View File

@@ -31,8 +31,8 @@ import org.dspace.core.Context;
import org.dspace.core.Utils;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom2.Element;
import org.jdom2.Namespace;
/**
* ORE dissemination crosswalk

View File

@@ -34,12 +34,13 @@ import org.dspace.content.service.BundleService;
import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.xpath.XPath;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.filter.Filters;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
/**
* ORE ingestion crosswalk
@@ -113,23 +114,21 @@ public class OREIngestionCrosswalk
Document doc = new Document();
doc.addContent(root.detach());
XPath xpathLinks;
List<Element> aggregatedResources;
String entryId;
try {
xpathLinks = XPath.newInstance("/atom:entry/atom:link[@rel=\"" + ORE_NS.getURI() + "aggregates" + "\"]");
xpathLinks.addNamespace(ATOM_NS);
aggregatedResources = xpathLinks.selectNodes(doc);
XPathExpression<Element> xpathLinks =
XPathFactory.instance()
.compile("/atom:entry/atom:link[@rel=\"" + ORE_NS.getURI() + "aggregates" + "\"]",
Filters.element(), null, ATOM_NS);
aggregatedResources = xpathLinks.evaluate(doc);
xpathLinks = XPath.newInstance("/atom:entry/atom:link[@rel='alternate']/@href");
xpathLinks.addNamespace(ATOM_NS);
entryId = ((Attribute) xpathLinks.selectSingleNode(doc)).getValue();
} catch (JDOMException e) {
throw new CrosswalkException("JDOM exception occurred while ingesting the ORE", e);
}
XPathExpression<Attribute> xpathAltHref =
XPathFactory.instance()
.compile("/atom:entry/atom:link[@rel='alternate']/@href",
Filters.attribute(), null, ATOM_NS);
entryId = xpathAltHref.evaluateFirst(doc).getValue();
// Next for each resource, create a bitstream
XPath xpathDesc;
NumberFormat nf = NumberFormat.getInstance();
nf.setGroupingUsed(false);
nf.setMinimumIntegerDigits(4);
@@ -140,16 +139,12 @@ public class OREIngestionCrosswalk
String bundleName;
Element desc = null;
try {
xpathDesc = XPath.newInstance(
"/atom:entry/oreatom:triples/rdf:Description[@rdf:about=\"" + this.encodeForURL(href) + "\"][1]");
xpathDesc.addNamespace(ATOM_NS);
xpathDesc.addNamespace(ORE_ATOM);
xpathDesc.addNamespace(RDF_NS);
desc = (Element) xpathDesc.selectSingleNode(doc);
} catch (JDOMException e) {
log.warn("Could not find description for {}", href, e);
}
XPathExpression<Element> xpathDesc =
XPathFactory.instance()
.compile("/atom:entry/oreatom:triples/rdf:Description[@rdf:about=\"" +
this.encodeForURL(href) + "\"][1]",
Filters.element(), null, ATOM_NS, ORE_ATOM, RDF_NS);
desc = xpathDesc.evaluateFirst(doc);
if (desc != null && desc.getChild("type", RDF_NS).getAttributeValue("resource", RDF_NS)
.equals(DS_NS.getURI() + "DSpaceBitstream")) {

View File

@@ -30,8 +30,8 @@ import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom2.Element;
import org.jdom2.Namespace;
/**
* PREMIS Crosswalk

View File

@@ -14,7 +14,7 @@ import java.util.Map;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Context;
import org.jdom.Element;
import org.jdom2.Element;
/**
* Translate DSpace native metadata into an external XML format, with parameters.

View File

@@ -36,10 +36,10 @@ import org.dspace.core.Context;
import org.dspace.core.SelfNamedPlugin;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.input.SAXBuilder;
/**
* Configurable QDC Crosswalk
@@ -290,7 +290,7 @@ public class QDCCrosswalk extends SelfNamedPlugin
qdc2element.put(qdc, element);
element2qdc.put(makeQualifiedTagName(element), qdc);
log.debug("Building Maps: qdc=\"" + qdc + "\", element=\"" + element.toString() + "\"");
} catch (org.jdom.JDOMException je) {
} catch (org.jdom2.JDOMException je) {
throw new CrosswalkInternalException(
"Failed parsing XML fragment in properties file: \"" + prolog + val + postlog + "\": " + je
.toString(), je);
@@ -326,6 +326,7 @@ public class QDCCrosswalk extends SelfNamedPlugin
* @throws IOException if IO error
* @throws SQLException if database error
* @throws AuthorizeException if authorization error
* @return List of Elements
*/
@Override
public List<Element> disseminateList(Context context, DSpaceObject dso)

View File

@@ -26,12 +26,12 @@ import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.workflow.WorkflowException;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.Namespace;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.XMLOutputter;
/**
* Role Crosswalk

View File

@@ -24,8 +24,8 @@ import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.SelfNamedPlugin;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom2.Element;
import org.jdom2.Namespace;
/**
* Disseminator for Simple Dublin Core metadata in XML format.
@@ -84,6 +84,7 @@ public class SimpleDCDisseminationCrosswalk extends SelfNamedPlugin
* @throws IOException if IO error
* @throws SQLException if database error
* @throws AuthorizeException if authorization error
* @return List of Elements
*/
@Override
public List<Element> disseminateList(Context context, DSpaceObject dso)

View File

@@ -34,9 +34,9 @@ import org.dspace.core.Context;
import org.dspace.core.SelfNamedPlugin;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.Verifier;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.Verifier;
/**
* Crosswalk for creating appropriate &lt;meta&gt; elements to appear in the
@@ -178,6 +178,7 @@ public class XHTMLHeadDisseminationCrosswalk
* @throws IOException if IO error
* @throws SQLException if database error
* @throws AuthorizeException if authorization error
* @return List of Elements
*/
@Override
public List<Element> disseminateList(Context context, DSpaceObject dso) throws CrosswalkException,

View File

@@ -21,7 +21,7 @@ import javax.xml.transform.stream.StreamSource;
import org.dspace.core.SelfNamedPlugin;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Namespace;
import org.jdom2.Namespace;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -18,6 +18,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
@@ -41,14 +42,15 @@ import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.Verifier;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.jdom.transform.JDOMResult;
import org.jdom.transform.JDOMSource;
import org.jdom2.Content;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.Verifier;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.jdom2.transform.JDOMResult;
import org.jdom2.transform.JDOMSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -244,6 +246,7 @@ public class XSLTDisseminationCrosswalk
* @throws SQLException if database error
* @throws AuthorizeException if authorization error
* @see DisseminationCrosswalk
* @return List of Elements
*/
@Override
public List<Element> disseminateList(Context context, DSpaceObject dso)
@@ -268,7 +271,12 @@ public class XSLTDisseminationCrosswalk
try {
JDOMResult result = new JDOMResult();
xform.transform(new JDOMSource(createDIM(dso).getChildren()), result);
return result.getResult();
List<Content> contentList = result.getResult();
// Transform List<Content> into List<Element>
List<Element> elementList = contentList.stream()
.filter(obj -> obj instanceof Element)
.map(Element.class::cast).collect(Collectors.toList());
return elementList;
} catch (TransformerException e) {
LOG.error("Got error: " + e.toString());
throw new CrosswalkInternalException("XSL translation failed: " + e.toString(), e);

View File

@@ -12,6 +12,7 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
@@ -34,13 +35,14 @@ import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.factory.CoreServiceFactory;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.jdom.transform.JDOMResult;
import org.jdom.transform.JDOMSource;
import org.jdom2.Content;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.jdom2.transform.JDOMResult;
import org.jdom2.transform.JDOMSource;
/**
* Configurable XSLT-driven ingestion Crosswalk
@@ -141,7 +143,12 @@ public class XSLTIngestionCrosswalk
try {
JDOMResult result = new JDOMResult();
xform.transform(new JDOMSource(metadata), result);
ingestDIM(context, dso, result.getResult(), createMissingMetadataFields);
List<Content> contentList = result.getResult();
// Transform List<Content> into List<Element>
List<Element> elementList = contentList.stream()
.filter(obj -> obj instanceof Element)
.map(Element.class::cast).collect(Collectors.toList());
ingestDIM(context, dso, elementList, createMissingMetadataFields);
} catch (TransformerException e) {
log.error("Got error: " + e.toString());
throw new CrosswalkInternalException("XSL Transformation failed: " + e.toString(), e);

View File

@@ -83,10 +83,10 @@ 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;
import org.jdom.output.XMLOutputter;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
/**
* Base class for disseminator of

View File

@@ -51,7 +51,7 @@ import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.workflow.WorkflowException;
import org.dspace.workflow.factory.WorkflowServiceFactory;
import org.jdom.Element;
import org.jdom2.Element;
/**
* Base class for package ingester of METS (Metadata Encoding and Transmission

View File

@@ -20,7 +20,7 @@ import org.dspace.content.crosswalk.CrosswalkException;
import org.dspace.content.crosswalk.MetadataValidationException;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.jdom.Element;
import org.jdom2.Element;
/**
* Subclass of the METS packager framework to ingest a DSpace

View File

@@ -23,7 +23,7 @@ import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.PluginService;
import org.jdom.Element;
import org.jdom2.Element;
/**
* Packager plugin to ingest a

View File

@@ -35,15 +35,17 @@ import org.dspace.core.Context;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Content;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.jdom.xpath.XPath;
import org.jdom2.Content;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.Namespace;
import org.jdom2.filter.Filters;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
/**
* <P>
@@ -382,15 +384,12 @@ public class METSManifest {
public List getMdFiles()
throws MetadataValidationException {
if (mdFiles == null) {
try {
// Use a special namespace with known prefix
// so we get the right prefix.
XPath xpath = XPath.newInstance("descendant::mets:mdRef");
xpath.addNamespace(metsNS);
mdFiles = xpath.selectNodes(mets);
} catch (JDOMException je) {
throw new MetadataValidationException("Failed while searching for mdRef elements in manifest: ", je);
}
// Use a special namespace with known prefix
// so we get the right prefix.
XPathExpression<Element> xpath =
XPathFactory.instance()
.compile("descendant::mets:mdRef", Filters.element(), null, metsNS);
mdFiles = xpath.evaluate(mets);
}
return mdFiles;
}
@@ -414,25 +413,22 @@ public class METSManifest {
return null;
}
try {
XPath xpath = XPath.newInstance(
"mets:fileSec/mets:fileGrp[@USE=\"CONTENT\"]/mets:file[@GROUPID=\"" + groupID + "\"]");
xpath.addNamespace(metsNS);
List oFiles = xpath.selectNodes(mets);
if (oFiles.size() > 0) {
if (log.isDebugEnabled()) {
log.debug("Got ORIGINAL file for derived=" + file.toString());
}
Element flocat = ((Element) oFiles.get(0)).getChild("FLocat", metsNS);
if (flocat != null) {
return flocat.getAttributeValue("href", xlinkNS);
}
XPathExpression<Element> xpath =
XPathFactory.instance()
.compile(
"mets:fileSec/mets:fileGrp[@USE=\"CONTENT\"]/mets:file[@GROUPID=\"" + groupID + "\"]",
Filters.element(), null, metsNS);
List<Element> oFiles = xpath.evaluate(mets);
if (oFiles.size() > 0) {
if (log.isDebugEnabled()) {
log.debug("Got ORIGINAL file for derived=" + file.toString());
}
Element flocat = oFiles.get(0).getChild("FLocat", metsNS);
if (flocat != null) {
return flocat.getAttributeValue("href", xlinkNS);
}
return null;
} catch (JDOMException je) {
log.warn("Got exception on XPATH looking for Original file, " + je.toString());
return null;
}
return null;
}
// translate bundle name from METS to DSpace; METS may be "CONTENT"
@@ -888,20 +884,16 @@ public class METSManifest {
// use only when path varies each time you call it.
protected Element getElementByXPath(String path, boolean nullOk)
throws MetadataValidationException {
try {
XPath xpath = XPath.newInstance(path);
xpath.addNamespace(metsNS);
xpath.addNamespace(xlinkNS);
Object result = xpath.selectSingleNode(mets);
if (result == null && nullOk) {
return null;
} else if (result instanceof Element) {
return (Element) result;
} else {
throw new MetadataValidationException("METSManifest: Failed to resolve XPath, path=\"" + path + "\"");
}
} catch (JDOMException je) {
throw new MetadataValidationException("METSManifest: Failed to resolve XPath, path=\"" + path + "\"", je);
XPathExpression<Element> xpath =
XPathFactory.instance()
.compile(path, Filters.element(), null, metsNS, xlinkNS);
Element result = xpath.evaluateFirst(mets);
if (result == null && nullOk) {
return null;
} else if (result == null && !nullOk) {
throw new MetadataValidationException("METSManifest: Failed to resolve XPath, path=\"" + path + "\"");
} else {
return result;
}
}

View File

@@ -35,7 +35,7 @@ import org.dspace.eperson.PasswordHash;
import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.eperson.service.EPersonService;
import org.dspace.eperson.service.GroupService;
import org.jdom.Namespace;
import org.jdom2.Namespace;
/**
* Plugin to export all Group and EPerson objects in XML, perhaps for reloading.

View File

@@ -152,14 +152,14 @@ public class Email {
private static final String RESOURCE_REPOSITORY_NAME = "Email";
private static final Properties VELOCITY_PROPERTIES = new Properties();
static {
VELOCITY_PROPERTIES.put(Velocity.RESOURCE_LOADER, "string");
VELOCITY_PROPERTIES.put("string.resource.loader.description",
VELOCITY_PROPERTIES.put(Velocity.RESOURCE_LOADERS, "string");
VELOCITY_PROPERTIES.put("resource.loader.string.description",
"Velocity StringResource loader");
VELOCITY_PROPERTIES.put("string.resource.loader.class",
VELOCITY_PROPERTIES.put("resource.loader.string.class",
StringResourceLoader.class.getName());
VELOCITY_PROPERTIES.put("string.resource.loader.repository.name",
VELOCITY_PROPERTIES.put("resource.loader.string.repository.name",
RESOURCE_REPOSITORY_NAME);
VELOCITY_PROPERTIES.put("string.resource.loader.repository.static",
VELOCITY_PROPERTIES.put("resource.loader.string.repository.static",
"false");
}

View File

@@ -29,10 +29,10 @@ import org.dspace.harvest.dao.HarvestedCollectionDAO;
import org.dspace.harvest.service.HarvestedCollectionService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.input.DOMBuilder;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.input.DOMBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.DOMException;
import org.xml.sax.SAXException;

View File

@@ -70,11 +70,11 @@ 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;
import org.jdom.input.DOMBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.input.DOMBuilder;
import org.jdom2.output.XMLOutputter;
import org.xml.sax.SAXException;

View File

@@ -23,8 +23,8 @@ import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.services.ConfigurationService;
import org.dspace.utils.DSpace;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import org.jdom2.Element;
import org.jdom2.output.XMLOutputter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -45,13 +45,13 @@ import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.handle.service.HandleService;
import org.dspace.identifier.DOI;
import org.dspace.services.ConfigurationService;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.filter.ElementFilter;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.filter.ElementFilter;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -9,10 +9,10 @@ package org.dspace.importer.external.arxiv.metadatamapping.contributor;
import java.util.Collection;
import org.apache.axiom.om.OMElement;
import org.dspace.importer.external.metadatamapping.MetadatumDTO;
import org.dspace.importer.external.metadatamapping.contributor.MetadataContributor;
import org.dspace.importer.external.metadatamapping.contributor.SimpleXpathMetadatumContributor;
import org.jdom2.Element;
/**
* Arxiv specific implementation of {@link MetadataContributor}
@@ -32,7 +32,7 @@ public class ArXivIdMetadataContributor extends SimpleXpathMetadatumContributor
* @return a collection of import records. Only the identifier of the found records may be put in the record.
*/
@Override
public Collection<MetadatumDTO> contributeMetadata(OMElement t) {
public Collection<MetadatumDTO> contributeMetadata(Element t) {
Collection<MetadatumDTO> values = super.contributeMetadata(t);
parseValue(values);
return values;

View File

@@ -7,8 +7,10 @@
*/
package org.dspace.importer.external.arxiv.service;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
@@ -20,10 +22,6 @@ import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.apache.commons.lang3.StringUtils;
import org.dspace.content.Item;
import org.dspace.importer.external.datamodel.ImportRecord;
@@ -31,7 +29,14 @@ import org.dspace.importer.external.datamodel.Query;
import org.dspace.importer.external.exception.MetadataSourceException;
import org.dspace.importer.external.service.AbstractImportMetadataSourceService;
import org.dspace.importer.external.service.components.QuerySource;
import org.jaxen.JaxenException;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.Namespace;
import org.jdom2.filter.Filters;
import org.jdom2.input.SAXBuilder;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
/**
* Implements a data source for querying ArXiv
@@ -39,7 +44,7 @@ import org.jaxen.JaxenException;
* @author Pasquale Cavallo (pasquale.cavallo at 4Science dot it)
*
*/
public class ArXivImportMetadataSourceServiceImpl extends AbstractImportMetadataSourceService<OMElement>
public class ArXivImportMetadataSourceServiceImpl extends AbstractImportMetadataSourceService<Element>
implements QuerySource {
private WebTarget webTarget;
@@ -213,15 +218,20 @@ public class ArXivImportMetadataSourceServiceImpl extends AbstractImportMetadata
Response response = invocationBuilder.get();
if (response.getStatus() == 200) {
String responseString = response.readEntity(String.class);
OMXMLParserWrapper records = OMXMLBuilderFactory.createOMBuilder(new StringReader(responseString));
OMElement element = records.getDocumentElement();
AXIOMXPath xpath = null;
SAXBuilder saxBuilder = new SAXBuilder();
Document document = saxBuilder.build(new StringReader(responseString));
Element root = document.getRootElement();
List namespaces = Arrays.asList(Namespace.getNamespace("opensearch",
"http://a9.com/-/spec/opensearch/1.1/"));
XPathExpression<Element> xpath =
XPathFactory.instance().compile("opensearch:totalResults", Filters.element(), null, namespaces);
Element count = xpath.evaluateFirst(root);
try {
xpath = new AXIOMXPath("opensearch:totalResults");
xpath.addNamespace("opensearch", "http://a9.com/-/spec/opensearch/1.1/");
OMElement count = (OMElement) xpath.selectSingleNode(element);
return Integer.parseInt(count.getText());
} catch (JaxenException e) {
} catch (NumberFormatException e) {
return null;
}
} else {
@@ -274,8 +284,8 @@ public class ArXivImportMetadataSourceServiceImpl extends AbstractImportMetadata
Response response = invocationBuilder.get();
if (response.getStatus() == 200) {
String responseString = response.readEntity(String.class);
List<OMElement> omElements = splitToRecords(responseString);
for (OMElement record : omElements) {
List<Element> elements = splitToRecords(responseString);
for (Element record : elements) {
results.add(transformSourceRecords(record));
}
return results;
@@ -321,8 +331,8 @@ public class ArXivImportMetadataSourceServiceImpl extends AbstractImportMetadata
Response response = invocationBuilder.get();
if (response.getStatus() == 200) {
String responseString = response.readEntity(String.class);
List<OMElement> omElements = splitToRecords(responseString);
for (OMElement record : omElements) {
List<Element> elements = splitToRecords(responseString);
for (Element record : elements) {
results.add(transformSourceRecords(record));
}
return results;
@@ -359,8 +369,8 @@ public class ArXivImportMetadataSourceServiceImpl extends AbstractImportMetadata
Response response = invocationBuilder.get();
if (response.getStatus() == 200) {
String responseString = response.readEntity(String.class);
List<OMElement> omElements = splitToRecords(responseString);
for (OMElement record : omElements) {
List<Element> elements = splitToRecords(responseString);
for (Element record : elements) {
results.add(transformSourceRecords(record));
}
return results;
@@ -387,16 +397,21 @@ public class ArXivImportMetadataSourceServiceImpl extends AbstractImportMetadata
}
}
private List<OMElement> splitToRecords(String recordsSrc) {
OMXMLParserWrapper records = OMXMLBuilderFactory.createOMBuilder(new StringReader(recordsSrc));
OMElement element = records.getDocumentElement();
AXIOMXPath xpath = null;
private List<Element> splitToRecords(String recordsSrc) {
try {
xpath = new AXIOMXPath("ns:entry");
xpath.addNamespace("ns", "http://www.w3.org/2005/Atom");
List<OMElement> recordsList = xpath.selectNodes(element);
SAXBuilder saxBuilder = new SAXBuilder();
Document document = saxBuilder.build(new StringReader(recordsSrc));
Element root = document.getRootElement();
List namespaces = Arrays.asList(Namespace.getNamespace("ns",
"http://www.w3.org/2005/Atom"));
XPathExpression<Element> xpath =
XPathFactory.instance().compile("ns:entry", Filters.element(), null, namespaces);
List<Element> recordsList = xpath.evaluate(root);
return recordsList;
} catch (JaxenException e) {
} catch (JDOMException | IOException e) {
return null;
}
}

View File

@@ -7,33 +7,36 @@
*/
package org.dspace.importer.external.metadatamapping.contributor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.apache.logging.log4j.Logger;
import org.dspace.importer.external.metadatamapping.MetadataFieldConfig;
import org.dspace.importer.external.metadatamapping.MetadataFieldMapping;
import org.dspace.importer.external.metadatamapping.MetadatumDTO;
import org.jaxen.JaxenException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jdom2.Attribute;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.Text;
import org.jdom2.filter.Filters;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Metadata contributor that takes an axiom OMElement and turns it into a metadatum
* Metadata contributor that takes a JDOM Element and turns it into a metadatum
*
* @author Roeland Dillen (roeland at atmire dot com)
*/
public class SimpleXpathMetadatumContributor implements MetadataContributor<OMElement> {
public class SimpleXpathMetadatumContributor implements MetadataContributor<Element> {
private MetadataFieldConfig field;
private static final Logger log = LoggerFactory.getLogger(SimpleXpathMetadatumContributor.class);
private static final Logger log
= org.apache.logging.log4j.LogManager.getLogger();
/**
* Return prefixToNamespaceMapping
@@ -44,14 +47,14 @@ public class SimpleXpathMetadatumContributor implements MetadataContributor<OMEl
return prefixToNamespaceMapping;
}
private MetadataFieldMapping<OMElement, MetadataContributor<OMElement>> metadataFieldMapping;
private MetadataFieldMapping<Element, MetadataContributor<Element>> metadataFieldMapping;
/**
* Return metadataFieldMapping
*
* @return MetadataFieldMapping
*/
public MetadataFieldMapping<OMElement, MetadataContributor<OMElement>> getMetadataFieldMapping() {
public MetadataFieldMapping<Element, MetadataContributor<Element>> getMetadataFieldMapping() {
return metadataFieldMapping;
}
@@ -62,7 +65,7 @@ public class SimpleXpathMetadatumContributor implements MetadataContributor<OMEl
*/
@Override
public void setMetadataFieldMapping(
MetadataFieldMapping<OMElement, MetadataContributor<OMElement>> metadataFieldMapping) {
MetadataFieldMapping<Element, MetadataContributor<Element>> metadataFieldMapping) {
this.metadataFieldMapping = metadataFieldMapping;
}
@@ -140,36 +143,35 @@ public class SimpleXpathMetadatumContributor implements MetadataContributor<OMEl
* Depending on the retrieved node (using the query), different types of values will be added to the MetadatumDTO
* list
*
* @param t A class to retrieve metadata from.
* @param t An element to retrieve metadata from.
* @return a collection of import records. Only the identifier of the found records may be put in the record.
*/
@Override
public Collection<MetadatumDTO> contributeMetadata(OMElement t) {
public Collection<MetadatumDTO> contributeMetadata(Element t) {
List<MetadatumDTO> values = new LinkedList<>();
try {
AXIOMXPath xpath = new AXIOMXPath(query);
for (String ns : prefixToNamespaceMapping.keySet()) {
xpath.addNamespace(prefixToNamespaceMapping.get(ns), ns);
}
List<Object> nodes = xpath.selectNodes(t);
for (Object el : nodes) {
if (el instanceof OMElement) {
values.add(metadataFieldMapping.toDCValue(field, ((OMElement) el).getText()));
} else if (el instanceof OMAttribute) {
values.add(metadataFieldMapping.toDCValue(field, ((OMAttribute) el).getAttributeValue()));
} else if (el instanceof String) {
values.add(metadataFieldMapping.toDCValue(field, (String) el));
} else if (el instanceof OMText) {
values.add(metadataFieldMapping.toDCValue(field, ((OMText) el).getText()));
} else {
log.error("node of type: " + el.getClass());
}
}
return values;
} catch (JaxenException e) {
log.error(query, e);
throw new RuntimeException(e);
List<Namespace> namespaces = new ArrayList<>();
for (String ns : prefixToNamespaceMapping.keySet()) {
namespaces.add(Namespace.getNamespace(prefixToNamespaceMapping.get(ns), ns));
}
XPathExpression<Object> xpath =
XPathFactory.instance().compile(query, Filters.fpassthrough(), null, namespaces);
List<Object> nodes = xpath.evaluate(t);
for (Object el : nodes) {
if (el instanceof Element) {
values.add(metadataFieldMapping.toDCValue(field, ((Element) el).getText()));
} else if (el instanceof Attribute) {
values.add(metadataFieldMapping.toDCValue(field, ((Attribute) el).getValue()));
} else if (el instanceof String) {
values.add(metadataFieldMapping.toDCValue(field, (String) el));
} else if (el instanceof Text) {
values.add(metadataFieldMapping.toDCValue(field, ((Text) el).getText()));
} else {
log.error("Encountered unsupported XML node of type: {}. Skipped that node.", el.getClass());
}
}
return values;
}
}

View File

@@ -25,10 +25,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.google.common.io.CharStreams;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.dspace.content.Item;
import org.dspace.importer.external.datamodel.ImportRecord;
import org.dspace.importer.external.datamodel.Query;
@@ -38,7 +34,13 @@ import org.dspace.importer.external.exception.MetadataSourceException;
import org.dspace.importer.external.service.AbstractImportMetadataSourceService;
import org.dspace.importer.external.service.components.FileSource;
import org.dspace.importer.external.service.components.QuerySource;
import org.jaxen.JaxenException;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.filter.Filters;
import org.jdom2.input.SAXBuilder;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
/**
* Implements a data source for querying PubMed Central
@@ -46,7 +48,7 @@ import org.jaxen.JaxenException;
* @author Roeland Dillen (roeland at atmire dot com)
* @author Pasquale Cavallo (pasquale.cavallo at 4science dot it)
*/
public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadataSourceService<OMElement>
public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadataSourceService<Element>
implements QuerySource, FileSource {
private String baseAddress;
@@ -59,7 +61,7 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
/**
* Set the file extensions supported by this metadata service
*
* @param supportedExtensionsthe file extensions (xml,txt,...) supported by this service
* @param supportedExtensions the file extensions (xml,txt,...) supported by this service
*/
public void setSupportedExtensions(List<String> supportedExtensions) {
this.supportedExtensions = supportedExtensions;
@@ -243,17 +245,21 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
private String getSingleElementValue(String src, String elementName) {
OMXMLParserWrapper records = OMXMLBuilderFactory.createOMBuilder(new StringReader(src));
OMElement element = records.getDocumentElement();
AXIOMXPath xpath = null;
String value = null;
try {
xpath = new AXIOMXPath("//" + elementName);
List<OMElement> recordsList = xpath.selectNodes(element);
if (!recordsList.isEmpty()) {
value = recordsList.get(0).getText();
SAXBuilder saxBuilder = new SAXBuilder();
Document document = saxBuilder.build(new StringReader(src));
Element root = document.getRootElement();
XPathExpression<Element> xpath =
XPathFactory.instance().compile("//" + elementName, Filters.element());
Element record = xpath.evaluateFirst(root);
if (record != null) {
value = record.getText();
}
} catch (JaxenException e) {
} catch (JDOMException | IOException e) {
value = null;
}
return value;
@@ -314,9 +320,9 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
invocationBuilder = getRecordsTarget.request(MediaType.TEXT_PLAIN_TYPE);
response = invocationBuilder.get();
List<OMElement> omElements = splitToRecords(response.readEntity(String.class));
List<Element> elements = splitToRecords(response.readEntity(String.class));
for (OMElement record : omElements) {
for (Element record : elements) {
records.add(transformSourceRecords(record));
}
@@ -324,15 +330,18 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
}
}
private List<OMElement> splitToRecords(String recordsSrc) {
OMXMLParserWrapper records = OMXMLBuilderFactory.createOMBuilder(new StringReader(recordsSrc));
OMElement element = records.getDocumentElement();
AXIOMXPath xpath = null;
private List<Element> splitToRecords(String recordsSrc) {
try {
xpath = new AXIOMXPath("//PubmedArticle");
List<OMElement> recordsList = xpath.selectNodes(element);
SAXBuilder saxBuilder = new SAXBuilder();
Document document = saxBuilder.build(new StringReader(recordsSrc));
Element root = document.getRootElement();
XPathExpression<Element> xpath =
XPathFactory.instance().compile("//PubmedArticle", Filters.element());
List<Element> recordsList = xpath.evaluate(root);
return recordsList;
} catch (JaxenException e) {
} catch (JDOMException | IOException e) {
return null;
}
}
@@ -362,13 +371,13 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
Response response = invocationBuilder.get();
List<OMElement> omElements = splitToRecords(response.readEntity(String.class));
List<Element> elements = splitToRecords(response.readEntity(String.class));
if (omElements.size() == 0) {
if (elements.isEmpty()) {
return null;
}
return transformSourceRecords(omElements.get(0));
return transformSourceRecords(elements.get(0));
}
}
@@ -441,8 +450,8 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
private List<ImportRecord> parseXMLString(String xml) {
List<ImportRecord> records = new LinkedList<ImportRecord>();
List<OMElement> omElements = splitToRecords(xml);
for (OMElement record : omElements) {
List<Element> elements = splitToRecords(xml);
for (Element record : elements) {
records.add(transformSourceRecords(record));
}
return records;

View File

@@ -10,7 +10,7 @@ package org.dspace.license;
import java.io.IOException;
import java.util.Map;
import org.jdom.Document;
import org.jdom2.Document;
/**
* Service interface class for the Creative commons license connector service.

View File

@@ -32,13 +32,14 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.Logger;
import org.dspace.services.ConfigurationService;
import org.jaxen.JaxenException;
import org.jaxen.jdom.JDOMXPath;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.filter.Filters;
import org.jdom2.input.SAXBuilder;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.xml.sax.InputSource;
@@ -96,7 +97,7 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService,
List<String> licenses;
try (CloseableHttpResponse response = client.execute(httpGet)) {
licenses = retrieveLicenses(response);
} catch (JDOMException | JaxenException | IOException e) {
} catch (JDOMException | IOException e) {
log.error("Error while retrieving the license details using url: " + uri, e);
licenses = Collections.emptyList();
}
@@ -110,7 +111,7 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService,
try (CloseableHttpResponse response = client.execute(licenseHttpGet)) {
CCLicense ccLicense = retrieveLicenseObject(license, response);
ccLicenses.put(ccLicense.getLicenseId(), ccLicense);
} catch (JaxenException | JDOMException | IOException e) {
} catch (JDOMException | IOException e) {
log.error("Error while retrieving the license details using url: " + licenseUri, e);
}
}
@@ -125,25 +126,23 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService,
* @param response The response from the API
* @return a list of license identifiers for which details need to be retrieved
* @throws IOException
* @throws JaxenException
* @throws JDOMException
*/
private List<String> retrieveLicenses(CloseableHttpResponse response)
throws IOException, JaxenException, JDOMException {
throws IOException, JDOMException {
List<String> domains = new LinkedList<>();
String[] excludedLicenses = configurationService.getArrayProperty("cc.license.classfilter");
String responseString = EntityUtils.toString(response.getEntity());
JDOMXPath licenseClassXpath = new JDOMXPath("//licenses/license");
XPathExpression<Element> licenseClassXpath =
XPathFactory.instance().compile("//licenses/license", Filters.element());
try (StringReader stringReader = new StringReader(responseString)) {
InputSource is = new InputSource(stringReader);
org.jdom.Document classDoc = this.parser.build(is);
org.jdom2.Document classDoc = this.parser.build(is);
List<Element> elements = licenseClassXpath.selectNodes(classDoc);
List<Element> elements = licenseClassXpath.evaluate(classDoc);
for (Element element : elements) {
String licenseId = getSingleNodeValue(element, "@id");
if (StringUtils.isNotBlank(licenseId) && !ArrayUtils.contains(excludedLicenses, licenseId)) {
@@ -163,30 +162,29 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService,
* @param response for a specific CC License response
* @return the corresponding CC License Object
* @throws IOException
* @throws JaxenException
* @throws JDOMException
*/
private CCLicense retrieveLicenseObject(final String licenseId, CloseableHttpResponse response)
throws IOException, JaxenException, JDOMException {
throws IOException, JDOMException {
String responseString = EntityUtils.toString(response.getEntity());
JDOMXPath licenseClassXpath = new JDOMXPath("//licenseclass");
JDOMXPath licenseFieldXpath = new JDOMXPath("field");
XPathExpression<Object> licenseClassXpath =
XPathFactory.instance().compile("//licenseclass", Filters.fpassthrough());
XPathExpression<Element> licenseFieldXpath =
XPathFactory.instance().compile("field", Filters.element());
try (StringReader stringReader = new StringReader(responseString)) {
InputSource is = new InputSource(stringReader);
org.jdom.Document classDoc = this.parser.build(is);
org.jdom2.Document classDoc = this.parser.build(is);
Object element = licenseClassXpath.selectSingleNode(classDoc);
Object element = licenseClassXpath.evaluateFirst(classDoc);
String licenseLabel = getSingleNodeValue(element, "label");
List<CCLicenseField> ccLicenseFields = new LinkedList<>();
List<Element> licenseFields = licenseFieldXpath.selectNodes(element);
List<Element> licenseFields = licenseFieldXpath.evaluate(element);
for (Element licenseField : licenseFields) {
CCLicenseField ccLicenseField = parseLicenseField(licenseField);
ccLicenseFields.add(ccLicenseField);
@@ -196,13 +194,14 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService,
}
}
private CCLicenseField parseLicenseField(final Element licenseField) throws JaxenException {
private CCLicenseField parseLicenseField(final Element licenseField) {
String id = getSingleNodeValue(licenseField, "@id");
String label = getSingleNodeValue(licenseField, "label");
String description = getSingleNodeValue(licenseField, "description");
JDOMXPath enumXpath = new JDOMXPath("enum");
List<Element> enums = enumXpath.selectNodes(licenseField);
XPathExpression<Element> enumXpath =
XPathFactory.instance().compile("enum", Filters.element());
List<Element> enums = enumXpath.evaluate(licenseField);
List<CCLicenseFieldEnum> ccLicenseFieldEnumList = new LinkedList<>();
@@ -215,7 +214,7 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService,
}
private CCLicenseFieldEnum parseEnum(final Element enumElement) throws JaxenException {
private CCLicenseFieldEnum parseEnum(final Element enumElement) {
String id = getSingleNodeValue(enumElement, "@id");
String label = getSingleNodeValue(enumElement, "label");
String description = getSingleNodeValue(enumElement, "description");
@@ -236,9 +235,10 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService,
}
}
private String getSingleNodeValue(final Object t, String query) throws JaxenException {
JDOMXPath xpath = new JDOMXPath(query);
Object singleNode = xpath.selectSingleNode(t);
private String getSingleNodeValue(final Object t, String query) {
XPathExpression xpath =
XPathFactory.instance().compile(query, Filters.fpassthrough());
Object singleNode = xpath.evaluateFirst(t);
return getNodeValue(singleNode);
}
@@ -273,7 +273,7 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService,
try (CloseableHttpResponse response = client.execute(httpPost)) {
return retrieveLicenseUri(response);
} catch (JDOMException | JaxenException | IOException e) {
} catch (JDOMException | IOException e) {
log.error("Error while retrieving the license uri for license : " + licenseId + " with answers "
+ answerMap.toString(), e);
}
@@ -286,21 +286,20 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService,
* @param response for a specific CC License URI response
* @return the corresponding CC License URI as a string
* @throws IOException
* @throws JaxenException
* @throws JDOMException
*/
private String retrieveLicenseUri(final CloseableHttpResponse response)
throws IOException, JaxenException, JDOMException {
throws IOException, JDOMException {
String responseString = EntityUtils.toString(response.getEntity());
JDOMXPath licenseClassXpath = new JDOMXPath("//result/license-uri");
XPathExpression<Object> licenseClassXpath =
XPathFactory.instance().compile("//result/license-uri", Filters.fpassthrough());
try (StringReader stringReader = new StringReader(responseString)) {
InputSource is = new InputSource(stringReader);
org.jdom.Document classDoc = this.parser.build(is);
org.jdom2.Document classDoc = this.parser.build(is);
Object node = licenseClassXpath.selectSingleNode(classDoc);
Object node = licenseClassXpath.evaluateFirst(classDoc);
String nodeValue = getNodeValue(node);
if (StringUtils.isNotBlank(nodeValue)) {
@@ -364,12 +363,7 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService,
* @return the license name
*/
public String retrieveLicenseName(final Document doc) {
try {
return getSingleNodeValue(doc, "//result/license-name");
} catch (JaxenException e) {
log.error("Error while retrieving the license name from the license document", e);
}
return null;
return getSingleNodeValue(doc, "//result/license-name");
}
}

View File

@@ -40,8 +40,8 @@ import org.dspace.core.Utils;
import org.dspace.license.service.CreativeCommonsService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Document;
import org.jdom.transform.JDOMSource;
import org.jdom2.Document;
import org.jdom2.transform.JDOMSource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -18,7 +18,7 @@ import org.dspace.content.Bitstream;
import org.dspace.content.Item;
import org.dspace.core.Context;
import org.dspace.license.CCLicense;
import org.jdom.Document;
import org.jdom2.Document;
/**
* Service interface class for the Creative commons licensing.

View File

@@ -24,10 +24,10 @@ import org.apache.commons.cli.Options;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

View File

@@ -32,7 +32,7 @@ import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.statistics.MockSolrLoggerServiceImpl;
import org.dspace.statistics.MockSolrStatisticsCore;
import org.dspace.storage.rdbms.DatabaseUtils;
import org.jdom.Document;
import org.jdom2.Document;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;

View File

@@ -38,7 +38,7 @@ import org.dspace.content.service.ItemService;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Element;
import org.jdom2.Element;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

View File

@@ -0,0 +1,268 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.util;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder;
import static org.junit.Assert.assertEquals;
import org.dspace.AbstractDSpaceTest;
import org.dspace.services.ConfigurationService;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.Assertion;
import org.junit.contrib.java.lang.system.ExpectedSystemExit;
import org.junit.contrib.java.lang.system.SystemErrRule;
import org.junit.contrib.java.lang.system.SystemOutRule;
/**
* Tests for configuration utilities.
*
* Because our command-line tools call System.exit(), we can't expect any code
* (such as assertions) following the call to main() to be executed. Instead we
* set up expectations in advance and attach them to an exit() trapper.
*
* @author mhwood
*/
public class ConfigurationIT
extends AbstractDSpaceTest {
private static ConfigurationService cfg;
private static final String SINGLE_PROPERTY = "test.single";
private static final String SINGLE_VALUE = "value";
private static final String ARRAY_PROPERTY = "test.array";
private static final String[] ARRAY_VALUE = { "one", "two" };
private static final String PLACEHOLDER_PROPERTY = "test.substituted";
private static final String PLACEHOLDER_VALUE = "insert ${test.single} here"; // Keep aligned with SINGLE_NAME
private static final String SUBSTITUTED_VALUE = "insert value here"; // Keep aligned with SINGLE_VALUE
private static final String MISSING_PROPERTY = "test.missing";
/** Capture standard output. */
@Rule
public final SystemOutRule systemOutRule = new SystemOutRule();
/** Capture standard error. */
@Rule
public final SystemErrRule systemErrRule = new SystemErrRule();
/** Capture System.exit() value. */
@Rule
public final ExpectedSystemExit expectedSystemExit = ExpectedSystemExit.none();
/**
* Create some expected properties before all tests.
*/
@BeforeClass
public static void setupSuite() {
cfg = kernelImpl.getConfigurationService();
cfg.setProperty(SINGLE_PROPERTY, SINGLE_VALUE);
cfg.setProperty(ARRAY_PROPERTY, ARRAY_VALUE);
cfg.setProperty(PLACEHOLDER_PROPERTY, PLACEHOLDER_VALUE);
cfg.setProperty(MISSING_PROPERTY, null); // Ensure that this one is undefined
}
/**
* After all tests, remove the properties that were created at entry.
*/
@AfterClass
public static void teardownSuite() {
if (null != cfg) {
cfg.setProperty(SINGLE_PROPERTY, null);
cfg.setProperty(ARRAY_PROPERTY, null);
cfg.setProperty(PLACEHOLDER_PROPERTY, null);
}
}
/**
* Test fetching all values of a single-valued property.
*/
@Test
public void testMainAllSingle() {
String[] argv;
argv = new String[] {
"--property", SINGLE_PROPERTY
};
expectedSystemExit.expectSystemExitWithStatus(0);
expectedSystemExit.checkAssertionAfterwards(new Assertion() {
@Override public void checkAssertion() {
String[] output = systemOutRule.getLogWithNormalizedLineSeparator()
.split("\n");
assertThat(output, arrayWithSize(1));
}
});
expectedSystemExit.checkAssertionAfterwards(new Assertion() {
@Override public void checkAssertion() {
String[] output = systemOutRule.getLogWithNormalizedLineSeparator()
.split("\n");
assertThat(output[0], equalTo(SINGLE_VALUE));
}
});
systemOutRule.enableLog();
Configuration.main(argv);
}
/**
* Test fetching all values of an array property.
*/
@Test
public void testMainAllArray() {
String[] argv;
argv = new String[] {
"--property", ARRAY_PROPERTY
};
expectedSystemExit.expectSystemExitWithStatus(0);
expectedSystemExit.checkAssertionAfterwards(new Assertion() {
@Override public void checkAssertion() {
String[] output = systemOutRule.getLogWithNormalizedLineSeparator()
.split("\n");
assertThat(output, arrayWithSize(ARRAY_VALUE.length));
}
});
expectedSystemExit.checkAssertionAfterwards(new Assertion() {
@Override public void checkAssertion() {
String[] output = systemOutRule.getLogWithNormalizedLineSeparator()
.split("\n");
assertThat(output, arrayContainingInAnyOrder(ARRAY_VALUE));
}
});
systemOutRule.enableLog();
Configuration.main(argv);
}
/**
* Test fetching all values of a single-valued property containing property
* placeholders.
*/
@Test
public void testMainAllSubstitution() {
String[] argv;
argv = new String[] {
"--property", PLACEHOLDER_PROPERTY
};
expectedSystemExit.expectSystemExitWithStatus(0);
expectedSystemExit.checkAssertionAfterwards(new Assertion() {
@Override public void checkAssertion() {
String[] output = systemOutRule.getLogWithNormalizedLineSeparator()
.split("\n");
assertThat(output, arrayWithSize(1));
}
});
expectedSystemExit.checkAssertionAfterwards(new Assertion() {
@Override public void checkAssertion() {
String[] output = systemOutRule.getLogWithNormalizedLineSeparator()
.split("\n");
assertThat(output[0], equalTo(SUBSTITUTED_VALUE));
}
});
systemOutRule.enableLog();
Configuration.main(argv);
}
/**
* Test fetching all values of a single-valued property containing property
* placeholders, suppressing property substitution.
*/
@Test
public void testMainAllRaw() {
// Can it handle a raw property (with substitution placeholders)?
String[] argv;
argv = new String[] {
"--property", PLACEHOLDER_PROPERTY,
"--raw"
};
expectedSystemExit.expectSystemExitWithStatus(0);
expectedSystemExit.checkAssertionAfterwards(new Assertion() {
@Override public void checkAssertion() {
String[] output = systemOutRule.getLogWithNormalizedLineSeparator()
.split("\n");
assertThat(output, arrayWithSize(1));
}
});
expectedSystemExit.checkAssertionAfterwards(new Assertion() {
@Override public void checkAssertion() {
String[] output = systemOutRule.getLogWithNormalizedLineSeparator()
.split("\n");
assertThat(output[0], equalTo(PLACEHOLDER_VALUE));
}
});
systemOutRule.enableLog();
Configuration.main(argv);
}
/**
* Test fetching all values of an undefined property.
*/
@Test
public void testMainAllUndefined() {
// Can it handle an undefined property?
String[] argv;
argv = new String[] {
"--property", MISSING_PROPERTY
};
expectedSystemExit.expectSystemExitWithStatus(0);
expectedSystemExit.checkAssertionAfterwards(new Assertion() {
@Override public void checkAssertion() {
String outputs = systemOutRule.getLogWithNormalizedLineSeparator();
String[] output = outputs.split("\n");
assertThat(output, arrayWithSize(0)); // Huh? Shouldn't split() return { "" } ?
}
});
systemOutRule.enableLog();
Configuration.main(argv);
}
/**
* Test fetching only the first value of an array property.
*/
@Test
public void testMainFirstArray() {
String[] argv = new String[] {
"--property", ARRAY_PROPERTY,
"--first"
};
expectedSystemExit.expectSystemExitWithStatus(0);
expectedSystemExit.checkAssertionAfterwards(() -> {
String outputs = systemOutRule.getLogWithNormalizedLineSeparator();
String[] output = outputs.split("\n");
assertThat(output, arrayWithSize(1));
assertEquals("--first should return first value", output[0], ARRAY_VALUE[0]);
});
systemOutRule.enableLog();
Configuration.main(argv);
}
/**
* Test fetching a single-valued property using {@code --first}
*/
@Test
public void testMainFirstSingle() {
String[] argv = new String[] {
"--property", SINGLE_PROPERTY,
"--first"
};
expectedSystemExit.expectSystemExitWithStatus(0);
expectedSystemExit.checkAssertionAfterwards(() -> {
String outputs = systemOutRule.getLogWithNormalizedLineSeparator();
String[] output = outputs.split("\n");
assertThat(output, arrayWithSize(1));
assertEquals("--first should return only value", output[0], SINGLE_VALUE);
});
systemOutRule.enableLog();
Configuration.main(argv);
}
}

View File

@@ -14,7 +14,7 @@ import org.dspace.AbstractDSpaceTest;
import org.dspace.core.service.PluginService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Namespace;
import org.jdom2.Namespace;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;

View File

@@ -15,8 +15,8 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom2.Document;
import org.jdom2.JDOMException;
/**
* Mock implementation for the Creative commons license connector service.

View File

@@ -9,6 +9,7 @@ package org.dspace.app.rest.utils;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static javax.mail.internet.MimeUtility.encodeText;
import java.io.IOException;
import java.util.Arrays;
@@ -163,7 +164,8 @@ public class HttpHeadersInitializer {
}
httpHeaders.put(CONTENT_DISPOSITION, Collections.singletonList(String.format(CONTENT_DISPOSITION_FORMAT,
disposition, fileName)));
disposition,
encodeText(fileName))));
log.debug("Content-Disposition : {}", disposition);
// Content phase

View File

@@ -8,6 +8,7 @@
package org.dspace.app.rest;
import static java.util.UUID.randomUUID;
import static javax.mail.internet.MimeUtility.encodeText;
import static org.apache.commons.codec.CharEncoding.UTF_8;
import static org.apache.commons.collections.CollectionUtils.isEmpty;
import static org.apache.commons.io.IOUtils.toInputStream;
@@ -293,6 +294,53 @@ public class BitstreamRestControllerIT extends AbstractControllerIntegrationTest
checkNumberOfStatsRecords(bitstream, 0);
}
@Test
public void testBitstreamName() throws Exception {
context.turnOffAuthorisationSystem();
//** GIVEN **
//1. A community-collection structure with one parent community and one collection
parentCommunity = CommunityBuilder
.createCommunity(context)
.build();
Collection collection = CollectionBuilder
.createCollection(context, parentCommunity)
.build();
//2. A public item with a bitstream
String bitstreamContent = "0123456789";
String bitstreamName = "ภาษาไทย";
try (InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
Item item = ItemBuilder
.createItem(context, collection)
.build();
bitstream = BitstreamBuilder
.createBitstream(context, item, is)
.withName(bitstreamName)
.build();
}
context.restoreAuthSystemState();
//** WHEN **
//We download the bitstream
getClient().perform(get("/api/core/bitstreams/" + bitstream.getID() + "/content"))
//** THEN **
.andExpect(status().isOk())
//We expect the content disposition to have the encoded bitstream name
.andExpect(header().string(
"Content-Disposition",
"attachment;filename=\"" + encodeText(bitstreamName) + "\""
));
}
@Test
public void testBitstreamNotFound() throws Exception {
getClient().perform(get("/api/core/bitstreams/" + UUID.randomUUID() + "/content"))

View File

@@ -15,8 +15,8 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom2.Document;
import org.jdom2.JDOMException;
/**
* Mock implementation for the Creative commons license connector service.

View File

@@ -135,7 +135,8 @@
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>fom-impl</artifactId>
<version>${axiom.version}</version>
<!-- CANNOT UPGRADE WITHOUT BREAKING sword2-server (see above) -->
<version>1.2.22</version>
<exclusions>
<!-- Exclude Geronimo as it is NOT necessary when using javax.activation (which we use)
See: https://ws.apache.org/axiom/userguide/ch04.html#d0e732 -->

View File

@@ -1425,8 +1425,7 @@ plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \
authority.minconfidence = ambiguous
# Configuration settings for ORCID based authority control.
# Uncomment the lines below to enable configuration.
#solr.authority.server=${solr.server}/${solr.multicorePrefix}authority
# Uncomment the lines below to enable configuration
#choices.plugin.dc.contributor.author = SolrAuthorAuthority
#choices.presentation.dc.contributor.author = authorLookup
#authority.controlled.dc.contributor.author = true

View File

@@ -31,20 +31,22 @@
</resources>
</cache-template>
<!-- this cache tracks the timestamps of the most recent updates to particular
tables. It is important that the cache timeout of the underlying cache
implementation be set to a higher value than the timeouts of any of the
query caches. In fact, it is recommended that the the underlying cache
not be configured for expiry at all. -->
<cache alias="org.hibernate.cache.spi.UpdateTimestampsCache">
<!-- This cache tracks the timestamps of the most recent updates to
particular tables. It is important that the cache timeout of
the underlying cache implementation be set to a higher value
than the timeouts of any of the query caches. In fact, it is
recommended that the the underlying cache not be configured
for expiry at all. -->
<cache alias='default-update-timestamps-region'>
<expiry>
<none/>
</expiry>
<heap unit='entries'>6000</heap>
</cache>
<!-- this cache stores the actual objects pulled out of the DB by hibernate -->
<cache alias="org.hibernate.cache.internal.StandardQueryCache">
<!-- This cache stores the actual objects pulled out of the DB by
Hibernate. -->
<cache alias='default-query-results-region'>
<expiry>
<ttl>600</ttl>
</expiry>

View File

@@ -4,6 +4,10 @@
# These configs are only used by the SOLR authority index #
#---------------------------------------------------------------#
# Solr Authority index location
# Default is ${solr.server}/authority, unless solr.multicorePrefix is specified
solr.authority.server=${solr.server}/${solr.multicorePrefix}authority
# Update item metadata displayed values (not the authority keys)
# with the lasted cached versions when running the UpdateAuthorities index script
#solrauthority.auto-update-items=false

View File

@@ -24,6 +24,6 @@ services:
tar xvfz /tmp/assetstore.tar.gz
fi
/dspace/bin/dspace index-discovery
/dspace/bin/dspace index-discovery -b
/dspace/bin/dspace oai import
/dspace/bin/dspace oai clean-cache

View File

@@ -13,7 +13,7 @@ services:
image: dspace/dspace-postgres-pgcrypto:loadsql
environment:
# This SQL is available from https://github.com/DSpace-Labs/AIP-Files/releases/tag/demo-entities-data
- LOADSQL=https://github.com/DSpace-Labs/AIP-Files/releases/download/demo-entities-data/dspace7-entities-2021-04-14.sql
- LOADSQL=https://github.com/DSpace-Labs/AIP-Files/releases/download/demo-entities-data/dspace7-entities-data.sql
dspace:
### OVERRIDE default 'entrypoint' in 'docker-compose.yml ####
# Ensure that the database is ready BEFORE starting tomcat

26
pom.xml
View File

@@ -27,7 +27,6 @@
<postgresql.driver.version>42.3.3</postgresql.driver.version>
<solr.client.version>8.8.1</solr.client.version>
<axiom.version>1.2.22</axiom.version>
<ehcache.version>3.4.0</ehcache.version>
<errorprone.version>2.10.0</errorprone.version>
<!-- NOTE: when updating jackson.version, also sync jackson-databind dependency below -->
@@ -41,6 +40,7 @@
<log4j.version>2.17.1</log4j.version>
<pdfbox-version>2.0.24</pdfbox-version>
<poi-version>3.17</poi-version>
<rome.version>1.18.0</rome.version>
<slf4j.version>1.7.25</slf4j.version>
<!--=== SERVER WEBAPP DEPENDENCIES ===-->
@@ -1116,7 +1116,7 @@
<version>3.4.14</version>
</dependency>
<!-- solr-cell and axiom-api disagree on versions -->
<!-- solr-cell and axiom-api (in dspace-swordv2) disagree on versions -->
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>apache-mime4j-core</artifactId>
@@ -1161,6 +1161,23 @@
<version>${hibernate-validator.version}</version>
</dependency>
<!-- Rome is used for RSS / ATOM syndication feeds -->
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome</artifactId>
<version>${rome.version}</version>
</dependency>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-modules</artifactId>
<version>${rome.version}</version>
</dependency>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-utils</artifactId>
<version>${rome.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
@@ -1468,6 +1485,7 @@
<version>3.1.0</version>
</dependency>
<!-- Jaxen is needed by xoai and sword2-server, but they disagree on the versions -->
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
@@ -1481,8 +1499,8 @@
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1.3</version>
<artifactId>jdom2</artifactId>
<version>2.0.6.1</version>
</dependency>
<dependency>