Skip to content

Commit

Permalink
Added suport for paths to allow ./
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosjepard committed Jul 25, 2024
1 parent 10360ec commit 04a841d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.roda_project.commons_ip2.validator.state.MetsValidatorState;
import org.roda_project.commons_ip2.validator.state.StructureValidatorState;
import org.roda_project.commons_ip2.validator.utils.CHECKSUMTYPE;
import org.roda_project.commons_ip2.validator.utils.DecoderUtils;
import org.roda_project.commons_ip2.validator.utils.Message;
import org.roda_project.commons_ip2.validator.utils.MetadataType;

Expand Down Expand Up @@ -88,7 +89,8 @@ protected ReporterDetails validateCSIP31(final StructureValidatorState structure
for (MdSecType md : allMdSecTypes) {
final MdSecType.MdRef mdRef = md.getMdRef();
if (mdRef != null && mdRef.getHref() != null) {
final String hrefDecoded = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()),
Constants.UTF_8);
if (metsValidatorState.isRootMets()) {
if (metadataFiles.containsKey(metsValidatorState.getMets().getOBJID() + "/" + hrefDecoded)) {
metadataFiles.replace(metsValidatorState.getMets().getOBJID() + "/" + hrefDecoded, true);
Expand All @@ -105,7 +107,8 @@ protected ReporterDetails validateCSIP31(final StructureValidatorState structure
for (MdSecType md : metsValidatorState.getMets().getDmdSec()) {
final MdSecType.MdRef mdRef = md.getMdRef();
if (mdRef != null && mdRef.getHref() != null) {
final String hrefDecoded = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()),
Constants.UTF_8);
if (metsValidatorState.isRootMets()) {
if (metadataFiles.containsKey(metsValidatorState.getMets().getOBJID() + "/" + hrefDecoded)) {
metadataFiles.replace(metsValidatorState.getMets().getOBJID() + "/" + hrefDecoded, true);
Expand Down Expand Up @@ -168,7 +171,8 @@ protected ReporterDetails validateCSIP31(final StructureValidatorState structure
for (MdSecType md : amd.getDigiprovMD()) {
final MdSecType.MdRef mdRef = md.getMdRef();
if (mdRef != null) {
final String hrefDecoded = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()),
Constants.UTF_8);
if (hrefDecoded != null) {
final String path = Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded).toString();
if (metadataFiles.containsKey(path)) {
Expand All @@ -182,7 +186,8 @@ protected ReporterDetails validateCSIP31(final StructureValidatorState structure
for (MdSecType md : metsValidatorState.getMets().getDmdSec()) {
final MdSecType.MdRef mdRef = md.getMdRef();
if (mdRef != null) {
final String hrefDecoded = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()),
Constants.UTF_8);
if (hrefDecoded != null) {
final String path = Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded).toString();
if (metadataFiles.containsKey(path)) {
Expand Down Expand Up @@ -416,7 +421,7 @@ protected ReporterDetails validateCSIP38(final StructureValidatorState structure
final MdSecType.MdRef mdRef = md.getMdRef();
final StringBuilder message = new StringBuilder();
if (mdRef != null && mdRef.getHref() != null) {
final String href = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String href = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()), Constants.UTF_8);
if (structureValidatorState.isZipFileFlag()) {
final StringBuilder path = new StringBuilder();
if (metsValidatorState.isRootMets()) {
Expand Down Expand Up @@ -527,7 +532,7 @@ protected ReporterDetails validateCSIP41(final StructureValidatorState structure
for (MdSecType md : digiprov) {
final MdSecType.MdRef mdRef = md.getMdRef();
if (mdRef != null && mdRef.getHref() != null) {
final String href = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String href = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()), Constants.UTF_8);
final Long size = mdRef.getSIZE();
if (size == null) {
return new ReporterDetails(Constants.VALIDATION_REPORT_HEADER_CSIP_VERSION,
Expand Down Expand Up @@ -641,7 +646,7 @@ protected ReporterDetails validateCSIP43(final StructureValidatorState structure
metsValidatorState.getMetsName(), metsValidatorState.isRootMets()),
false, false);
} else {
final String href = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String href = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()), Constants.UTF_8);
final StringBuilder message = new StringBuilder();
if (structureValidatorState.isZipFileFlag()) {
final StringBuilder file = new StringBuilder();
Expand Down Expand Up @@ -950,7 +955,7 @@ protected ReporterDetails validateCSIP51(final StructureValidatorState structure
for (MdSecType rmd : rigthsMD) {
final MdSecType.MdRef mdRef = rmd.getMdRef();
if (mdRef != null && mdRef.getHref() != null) {
final String href = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String href = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()), Constants.UTF_8);
final StringBuilder message = new StringBuilder();
if (structureValidatorState.isZipFileFlag()) {
final StringBuilder filePath = new StringBuilder();
Expand Down Expand Up @@ -1064,7 +1069,7 @@ protected ReporterDetails validateCSIP54(final StructureValidatorState structure
for (MdSecType rmd : rigthsMD) {
final MdSecType.MdRef mdRef = rmd.getMdRef();
if (mdRef != null && mdRef.getHref() != null) {
final String href = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String href = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()), Constants.UTF_8);
final Long size = mdRef.getSIZE();
if (size == null) {
return new ReporterDetails(Constants.VALIDATION_REPORT_HEADER_CSIP_VERSION,
Expand Down Expand Up @@ -1177,7 +1182,7 @@ protected ReporterDetails validateCSIP56(final StructureValidatorState structure
metsValidatorState.getMetsName(), metsValidatorState.isRootMets()),
false, false);
} else {
final String href = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String href = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()), Constants.UTF_8);
final StringBuilder message = new StringBuilder();
if (structureValidatorState.isZipFileFlag()) {
final StringBuilder filePath = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package org.roda_project.commons_ip2.validator.components.descriptiveMetadataComponent;

import java.io.IOException;
import java.io.InputStream;
import java.net.URLDecoder;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.roda_project.commons_ip2.mets_v1_12.beans.AmdSecType;
import org.roda_project.commons_ip2.mets_v1_12.beans.MdSecType;
Expand All @@ -14,20 +26,10 @@
import org.roda_project.commons_ip2.validator.state.MetsValidatorState;
import org.roda_project.commons_ip2.validator.state.StructureValidatorState;
import org.roda_project.commons_ip2.validator.utils.CHECKSUMTYPE;
import org.roda_project.commons_ip2.validator.utils.DecoderUtils;
import org.roda_project.commons_ip2.validator.utils.Message;
import org.roda_project.commons_ip2.validator.utils.MetadataType;

import java.io.IOException;
import java.io.InputStream;
import java.net.URLDecoder;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author Carlos Afonso <cafonso@keep.pt>
*/
Expand Down Expand Up @@ -88,7 +90,10 @@ protected ReporterDetails validateCSIP17(final StructureValidatorState structure
for (MdSecType md : dmdSec) {
final MdSecType.MdRef mdRef = md.getMdRef();
if (mdRef != null && mdRef.getHref() != null) {
final String hrefDecoded = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);

String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()), Constants.UTF_8);
Path path = Paths.get(hrefDecoded);
hrefDecoded = path.normalize().toString();
if (metsValidatorState.isRootMets()) {
if (metadataFiles.containsKey(mets.getOBJID() + Constants.SEPARATOR + hrefDecoded)) {
metadataFiles.replace(mets.getOBJID() + Constants.SEPARATOR + hrefDecoded, true);
Expand All @@ -112,7 +117,8 @@ protected ReporterDetails validateCSIP17(final StructureValidatorState structure
for (MdSecType md : allMdSecTypes) {
final MdSecType.MdRef mdRef = md.getMdRef();
if (mdRef != null && mdRef.getHref() != null) {
final String hrefDecoded = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()),
Constants.UTF_8);
if (metsValidatorState.isRootMets()) {
if (metadataFiles.containsKey(mets.getOBJID() + Constants.SEPARATOR + hrefDecoded)) {
metadataFiles.replace(mets.getOBJID() + Constants.SEPARATOR + hrefDecoded, true);
Expand Down Expand Up @@ -174,7 +180,8 @@ protected ReporterDetails validateCSIP17(final StructureValidatorState structure
for (MdSecType md : dmdSec) {
final MdSecType.MdRef mdRef = md.getMdRef();
if (mdRef != null) {
final String hrefDecoded = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()),
Constants.UTF_8);
if (hrefDecoded != null) {
final String path = Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded).toString();
if (metadataFiles.containsKey(path)) {
Expand All @@ -188,7 +195,8 @@ protected ReporterDetails validateCSIP17(final StructureValidatorState structure
for (MdSecType md : amd.getDigiprovMD()) {
final MdSecType.MdRef mdRef = md.getMdRef();
if (mdRef != null) {
final String hrefDecoded = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()),
Constants.UTF_8);
if (hrefDecoded != null) {
final String path = Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded).toString();
if (metadataFiles.containsKey(path)) {
Expand Down Expand Up @@ -414,7 +422,7 @@ protected ReporterDetails validateCSIP24(final StructureValidatorState structure
final MdSecType.MdRef mdRef = mdSec.getMdRef();
final String href = mdRef.getHref();
if (href != null) {
final String hrefDecoded = URLDecoder.decode(href, Constants.UTF_8);
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(href), Constants.UTF_8);
if (structureValidatorState.isZipFileFlag()) {
final StringBuilder path = new StringBuilder();
if (metsValidatorState.isRootMets()) {
Expand Down Expand Up @@ -531,7 +539,7 @@ protected ReporterDetails validateCSIP27(final StructureValidatorState structure
final MdSecType.MdRef mdRef = mdSec.getMdRef();
final String href = mdRef.getHref();
if (href != null) {
final String hrefDecoded = URLDecoder.decode(mdRef.getHref(), Constants.UTF_8);
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()), Constants.UTF_8);
final Long size = mdRef.getSIZE();
if (size != null) {
final StringBuilder message = new StringBuilder();
Expand Down Expand Up @@ -627,7 +635,7 @@ protected ReporterDetails validateCSIP29(final StructureValidatorState structure
if (checksum != null) {
final String href = mdRef.getHref();
if (href != null) {
final String file = URLDecoder.decode(href, Constants.UTF_8);
final String file = URLDecoder.decode(DecoderUtils.normalizePath(href), Constants.UTF_8);
final StringBuilder filePath = new StringBuilder();
final StringBuilder message = new StringBuilder();
if (structureValidatorState.isZipFileFlag()) {
Expand Down
Loading

0 comments on commit 04a841d

Please sign in to comment.