Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge 2024.06.x into main #2322

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mycore-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
* Use {@link MCRTransactionManager} instead.
*/
@Deprecated
public abstract class MCRTransactionHelper {
public final class MCRTransactionHelper {

private MCRTransactionHelper() {
}

/**
* commits the database transaction. Commit is only done if {@link #isTransactionActive()} returns true.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
* }
* </pre>
*/
public abstract class MCRTransactionManager {
public final class MCRTransactionManager {

private static TransactionLoader transactionLoader = new PooledSystemTransactionLoader();

Expand All @@ -92,6 +92,9 @@ public abstract class MCRTransactionManager {
private static final ThreadLocal<List<MCRPersistenceTransaction>> ROLLBACK_ONLY_TRANSACTIONS =
ThreadLocal.withInitial(ArrayList::new);

private MCRTransactionManager() {
}

/**
* Sets the {@link TransactionLoader} to be used by the {@link MCRTransactionManager}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ public static MCRConfigurationInputStream getMyCoRePropertiesInstance() throws I
LogManager.getLogger().info("Current configuration directory: {}",
configurationDirectory.getAbsolutePath());
// set MCR.basedir, is normally overwritten later
if (configurationDirectory.isDirectory()) {
initStream = getBaseDirInputStream(configurationDirectory);
if (!configurationDirectory.isDirectory()) {
LogManager.getLogger().warn("Current configuration directory does not exist: {}",
configurationDirectory.getAbsolutePath());
}
initStream = getBaseDirInputStream(configurationDirectory);
}
return new MCRConfigurationInputStream(MYCORE_PROPERTIES, initStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

/**
* Reads MCRContent from a byte[] array.
*
*
* @author Frank Lützenkichen
*/
public class MCRByteContent extends MCRContent {
Expand All @@ -53,6 +53,7 @@ public MCRByteContent(byte[] bytes, long lastModified) {
this(bytes, 0, bytes.length, lastModified);
}

@SuppressWarnings("PMD.ArrayIsStoredDirectly")
public MCRByteContent(byte[] bytes, int offset, int length, long lastModified) {
this.bytes = bytes;
this.offset = offset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@
/**
* @author Thomas Scheffler (yagee)
*/
public abstract class MCRRestContentHelper {
public final class MCRRestContentHelper {

public static final RuntimeDelegate.HeaderDelegate<Date> DATE_HEADER_DELEGATE = RuntimeDelegate.getInstance()
.createHeaderDelegate(Date.class);

private static Logger LOGGER = LogManager.getLogger();

private MCRRestContentHelper() {
}

public static Response serveContent(final MCRContent content, final UriInfo uriInfo,
final HttpHeaders requestHeader, List<Map.Entry<String, String>> responseHeader)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@
* @author Thomas Scheffler (yagee)
* @author Matthias Eichner
*/
public abstract class MCRServletContentHelper {
public final class MCRServletContentHelper {

public static final int DEFAULT_BUFFER_SIZE = ContentUtils.DEFAULT_BUFFER_SIZE;

public static final String ATT_SERVE_CONTENT = MCRServletContentHelper.class.getName() + ".serveContent";

private static Logger LOGGER = LogManager.getLogger(MCRServletContentHelper.class);

private MCRServletContentHelper() {
}

public static Config buildConfig(ServletConfig servletConfig) {
Config config = new Config();

Expand Down
43 changes: 30 additions & 13 deletions mycore-base/src/main/java/org/mycore/common/digest/MCRDigest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class MCRDigest {
* @param value The string representation of the digest.
* @throws MCRDigestValidationException If the digest value is invalid.
*/
public MCRDigest(String value) throws MCRDigestValidationException {
protected MCRDigest(String value) throws MCRDigestValidationException {
this.value = HexFormat.of().parseHex(value);
validate();
}
Expand All @@ -52,13 +52,23 @@ public MCRDigest(String value) throws MCRDigestValidationException {
* @param value The string representation of the digest.
* @throws MCRDigestValidationException If the digest value is invalid.
*/
public MCRDigest(byte[] value) throws MCRDigestValidationException {
this.value = value;
protected MCRDigest(byte[] value) throws MCRDigestValidationException {
this.value = Arrays.copyOf(value, value.length); //as we validate the value
validate();
}


/**
* Returns the value of the digest as a byte array.
*
* @return Digest value.
*/
public byte[] toBytes() {
return Arrays.copyOf(value, value.length);
}

/**
* Returns the value of the digest.
* Returns the value of the digest as a hex encoded string.
*
* @return Digest value.
*/
Expand All @@ -68,14 +78,10 @@ public String toHexString() {

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof MCRDigest mcrDigest)) {
return false;
}
MCRDigest mcrDigest = (MCRDigest) o;
return Arrays.equals(value, mcrDigest.value);
return Arrays.equals(value, mcrDigest.value) && getAlgorithm().equals(mcrDigest.getAlgorithm());
}

@Override
Expand All @@ -102,12 +108,12 @@ protected void validate() throws MCRDigestValidationException {
/**
* Digest Algorithm
*/
public static abstract class Algorithm {
public static class Algorithm {

final String name;

protected Algorithm(String name) {
this.name = name;
this.name = Objects.requireNonNull(name);
}

public String toLowerCase() {
Expand All @@ -118,6 +124,17 @@ public String toUpperCase() {
return name.toUpperCase(Locale.ROOT);
}

}
@Override
public final boolean equals(Object o) {
if (!(o instanceof Algorithm algorithm)) {
return false;
}
return name.equals(algorithm.name);
}

@Override
public int hashCode() {
return name.hashCode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ public List<String> treeLines() {

private void treeLines(List<Indent> prefix, List<String> lines) {
prefix.add(Indent.LEAD);
for (int i = 0, n = entries.size(); i < n; i++) {
int entriesCount = entries.size();
for (int i = 0; i < entriesCount; i++) {
Entry entry = entries.get(i);
if (i == n - 1) {
prefix.remove(prefix.size() - 1);
if (i == entriesCount - 1) {
prefix.removeLast();
prefix.add(Indent.LAST);
}
entry.treeLines(prefix, lines);
}
prefix.remove(prefix.size() - 1);
prefix.removeLast();
}

private enum Indent {
Expand All @@ -101,9 +102,10 @@ private static abstract class Entry {

protected String prefixString(List<Indent> prefix) {
StringBuilder builder = new StringBuilder();
for (int i = 0, n = prefix.size(); i < n; i++) {
int prefixCount = prefix.size();
for (int i = 0; i < prefixCount; i++) {
Indent indent = prefix.get(i);
String symbol = i == n - 1 ? indent.lastSymbol : indent.leadSymbol;
String symbol = i == prefixCount - 1 ? indent.lastSymbol : indent.leadSymbol;
builder.append(symbol);
}
return builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
/**
* MCREntityResolver uses {@link CatalogResolver} for resolving entities or - for compatibility reasons - looks in
* classpath to resolve XSD and DTD files.
*
*
* @author Thomas Scheffler (yagee)
* @since 2013.10
*/
Expand Down Expand Up @@ -264,6 +264,7 @@ private static class InputSourceProvider {

URL url;

@SuppressWarnings("PMD.ArrayIsStoredDirectly") //internal use only
InputSourceProvider(byte[] bytes, URL url) {
this.bytes = bytes;
this.url = url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@

/**
* Collects parameters used in XSL transformations, by copying them from
* MCRConfiguration, from the HTTP and MyCoRe session, from request attributes etc.
*
* MCRConfiguration, from the HTTP and MyCoRe session, from request attributes etc.
*
* @author Frank Lützenkirchen
*/
public class MCRParameterCollector {
Expand All @@ -63,14 +63,14 @@ public class MCRParameterCollector {
/**
* Collects parameters The collecting of parameters is done in steps,
* each step may overwrite parameters that already have been set.
*
*
* First, all configuration properties from MCRConfiguration are copied.
* Second, those variables stored in the HTTP session, that start with "XSL." are copied.
* Next, variables stored in the MCRSession are copied.
* Next, HTTP request parameters are copied.
*
*
* Only those parameters starting with "XSL." are copied from session and request,
*
*
* @param request the HttpRequest causing the XSL transformation, must NOT be null
*/
public MCRParameterCollector(HttpServletRequest request) {
Expand All @@ -80,13 +80,13 @@ public MCRParameterCollector(HttpServletRequest request) {
/**
* Collects parameters The collecting of parameters is done in steps,
* each step may overwrite parameters that already have been set.
*
*
* First, all configuration properties from MCRConfiguration are copied.
* Second, those variables stored in the HTTP session, that start with "XSL." are copied.
* Next, variables stored in the MCRSession are copied.
* Next, HTTP request parameters are copied.
* Next, HTTP request attributes are copied.
*
*
* @param request the HttpRequest causing the XSL transformation, must NOT be null
* @param onlySetXSLParameters if true, only those parameters starting with "XSL."
* are copied from session and request
Expand Down Expand Up @@ -116,7 +116,7 @@ public MCRParameterCollector(HttpServletRequest request, boolean onlySetXSLParam
/**
* Collects parameters The collecting of parameters is done in steps,
* each step may overwrite parameters that already have been set.
*
*
* First, all configuration properties from MCRConfiguration are copied.
* Next, those variables stored in the MCRSession that start with "XSL." are copied.
*/
Expand All @@ -127,10 +127,10 @@ public MCRParameterCollector() {
/**
* Collects parameters The collecting of parameters is done in steps,
* each step may overwrite parameters that already have been set.
*
*
* First, all configuration properties from MCRConfiguration are copied.
* Next, those variables stored in the MCRSession are copied.
*
*
* @param onlySetXSLParameters if true, only those parameters starting with "XSL." are copied from session
*/
public MCRParameterCollector(boolean onlySetXSLParameters) {
Expand Down Expand Up @@ -181,7 +181,7 @@ public String getParameter(String name, String defaultValue) {
}

/**
* Returns the parameter map.
* Returns the parameter map.
*/
public Map<String, Object> getParameterMap() {
return Collections.unmodifiableMap(parameters);
Expand All @@ -200,10 +200,10 @@ private void setFromConfiguration() {

private String xmlSafe(String key) {
StringBuilder builder = new StringBuilder();
if (key.length() != 0) {
if (!key.isEmpty()) {
char first = key.charAt(0);
builder.append(first == ':' || !Verifier.isXMLNameStartCharacter(first) ? "_" : first);
for (int i = 1, n = key.length(); i < n; i++) {
for (int i = 1; i < key.length(); i++) {
char following = key.charAt(i);
builder.append(following == ':' || !Verifier.isXMLNameCharacter(following) ? "_" : following);
}
Expand Down Expand Up @@ -297,8 +297,8 @@ private void setFromRequestHeader(HttpServletRequest request) {
parameters.put("UserAgent", request.getHeader("User-Agent") != null ? request.getHeader("User-Agent") : "");
}

/**
* Calculates the complete request URL, so that mod_proxy is supported
/**
* Calculates the complete request URL, so that mod_proxy is supported
*/
private String getCompleteURL(HttpServletRequest request) {
StringBuilder buffer = getBaseURLUpToHostName();
Expand Down Expand Up @@ -332,7 +332,7 @@ private StringBuilder getBaseURLUpToHostName() {
/**
* Sets XSL parameters for the given transformer by taking them from the
* properties object provided.
*
*
* @param transformer
* the Transformer object thats parameters should be set
*/
Expand Down
Loading
Loading