Skip to content

Commit

Permalink
ClasspathResourceResolver now returns null when resource is not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
essiembre committed Aug 19, 2023
1 parent 018e601 commit e3296c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public String getEncoding() {
public String getStringData() {
synchronized (inputStream) {
try {
byte[] input = new byte[inputStream.available()];
var input = new byte[inputStream.available()];
inputStream.read(input); //NOSONAR
return new String(input);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
package com.norconex.commons.lang.xml;

import java.io.InputStream;

import javax.xml.validation.SchemaFactory;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -68,15 +66,16 @@ public ClasspathResourceResolver(String relativeTo) {
@Override
public LSInput resolveResource(String type, String namespaceURI,
String publicId, String systemId, String baseURI) {
String path = rootPath;
var path = rootPath;
if (baseURI != null) {
path = getPackageResourcePathFromBaseURI(baseURI);
}
String r = getResourcePath(path, systemId);
InputStream resourceAsStream = getClass().getResourceAsStream(r);
var r = getResourcePath(path, systemId);
var resourceAsStream = getClass().getResourceAsStream(r);
if (resourceAsStream == null) {
LOG.error("Resource not found: {} (baseURI: {}; systemId: {})",
r, baseURI, systemId);
return null;
}
return new ClasspathInput(publicId, r, resourceAsStream);
}
Expand All @@ -86,9 +85,9 @@ private String getResourcePath(String path, String systemId) {
// Absolute path, no need to resolve
return systemId;
}
int upCount = StringUtils.countMatches(systemId, "../");
String newPath = path;
for (int i = 0; i < upCount; i++) {
var upCount = StringUtils.countMatches(systemId, "../");
var newPath = path;
for (var i = 0; i < upCount; i++) {
newPath = newPath.replaceFirst("(.*/)(.*/)$", "$1");
}
return newPath + systemId.replaceFirst("^(../)+", "");
Expand Down

0 comments on commit e3296c9

Please sign in to comment.