Skip to content
Permalink
Browse files

Using URLDecoder instead of String.replaceAll

  • Loading branch information...
escowles committed Jul 28, 2014
1 parent 494ab59 commit 5bc7a402a6a281d2b52cd29e4eef039564feea46
@@ -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;
@@ -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;
@@ -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);
}
}
@@ -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;
@@ -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.

0 comments on commit 5bc7a40

Please sign in to comment.
You can’t perform that action at this time.