Skip to content

Commit

Permalink
Using URLDecoder instead of String.replaceAll
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Jul 28, 2014
1 parent 494ab59 commit 5bc7a40
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Expand Up @@ -26,6 +26,7 @@

import static com.google.common.base.Throwables.propagate;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static java.net.URLDecoder.decode;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static javax.jcr.PropertyType.PATH;
Expand All @@ -36,6 +37,7 @@
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -152,11 +154,11 @@ public boolean isCanonical() {
@Override
public Resource getSubject(final String absPath) throws RepositoryException {
resetTranslationChain();
if ( absPath != null && absPath.indexOf("%20") != -1 ) {
LOGGER.debug("Creating RDF subject from identifier with spaces: {}", absPath);
return doForward(absPath.replaceAll("%20"," "));
} else {
LOGGER.debug("Creating RDF subject from identifier: {}", absPath);
try {
LOGGER.debug("Creating RDF subject from identifier: {}", decode(absPath, "UTF-8"));
return doForward(decode(absPath, "UTF-8"));
} catch ( UnsupportedEncodingException ex ) {
LOGGER.warn("Required encoding (UTF-8) not supported, trying undecoded path",ex);
return doForward(absPath);
}
}
Expand Down
Expand Up @@ -16,11 +16,13 @@
package org.fcrepo.kernel.impl.utils;

import static com.google.common.base.Throwables.propagate;
import static java.net.URLDecoder.decode;
import static java.util.UUID.randomUUID;
import static org.fcrepo.kernel.RdfLexicon.COULD_NOT_STORE_PROPERTY;
import static org.fcrepo.kernel.RdfLexicon.LDP_NAMESPACE;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.UnsupportedEncodingException;
import javax.jcr.NamespaceException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
Expand Down Expand Up @@ -123,12 +125,17 @@ public void addedStatement(final Statement s) {
skolemizedBnodeMap.put(subject.getId(), subjectNode);
}
} else {
final String path = subjects.getPathFromSubject(subject);
if ( path != null && path.indexOf("%20") != -1 ) {
subjectNode = session.getNode(path.replaceAll("%20"," "));
} else {
subjectNode = session.getNode(path);
String path = null;
try {
path = decode(subjects.getPathFromSubject(subject), "UTF-8");
} catch ( UnsupportedEncodingException ex ) {
LOGGER.warn("Required encoding (UTF-8) not supported, trying undecoded path",ex);
path = subjects.getPathFromSubject(subject);
} catch ( NullPointerException ex ) {
LOGGER.debug("Looking up null path",ex);
path = null;
}
subjectNode = session.getNode(path);
}

// special logic for handling rdf:type updates.
Expand Down

0 comments on commit 5bc7a40

Please sign in to comment.