Skip to content

Commit

Permalink
[ignore] Java5-ified construction of (LOG) messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dizzzz committed Aug 4, 2013
1 parent c3a6502 commit 6d6ab1e
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 85 deletions.
30 changes: 15 additions & 15 deletions extensions/webdav/src/org/exist/webdav/ExistCollection.java
Expand Up @@ -66,7 +66,7 @@ public class ExistCollection extends ExistResource {
public ExistCollection(XmldbURI uri, BrokerPool pool) {

if(LOG.isTraceEnabled()) {
LOG.trace("New collection object for " + uri);
LOG.trace(String.format("New collection object for %s", uri));
}

brokerPool = pool;
Expand Down Expand Up @@ -98,7 +98,7 @@ public void initMetadata() {
collection = broker.openCollection(xmldbUri, Lock.READ_LOCK);

if (collection == null) {
LOG.error("Collection for " + xmldbUri + " cannot be opened for metadata");
LOG.error(String.format("Collection for %s cannot be opened for metadata", xmldbUri));
return;
}

Expand Down Expand Up @@ -224,7 +224,7 @@ public List<XmldbURI> getDocumentURIs() {
void delete() {

if(LOG.isDebugEnabled())
LOG.debug("Deleting '" + xmldbUri + "'");
LOG.debug(String.format("Deleting '%s'", xmldbUri));

DBBroker broker = null;
Collection collection = null;
Expand Down Expand Up @@ -287,7 +287,7 @@ void delete() {
public XmldbURI createCollection(String name) throws PermissionDeniedException, CollectionExistsException, EXistException {

if(LOG.isDebugEnabled())
LOG.debug("Create '" + name + "' in '" + xmldbUri + "'");
LOG.debug(String.format("Create '%s' in '%s'", name, xmldbUri));

XmldbURI newCollection = xmldbUri.append(name);

Expand All @@ -305,12 +305,13 @@ public XmldbURI createCollection(String name) throws PermissionDeniedException,
// checked by ResourceFactory
collection = broker.openCollection(newCollection, Lock.WRITE_LOCK);
if (collection != null) {
final String msg = "Collection already exists";

LOG.debug("Collection already exists");
LOG.debug(msg);

//XXX: double "abort" is bad thing!!!
txnManager.abort(txn);
throw new CollectionExistsException("Collection already exists");
throw new CollectionExistsException(msg);
}

// Create collection
Expand Down Expand Up @@ -365,7 +366,7 @@ public XmldbURI createFile(String newName, InputStream is, Long length, String c
throws IOException, PermissionDeniedException, CollectionDoesNotExistException {

if(LOG.isDebugEnabled())
LOG.debug("Create '" + newName + "' in '" + xmldbUri + "'");
LOG.debug(String.format("Create '%s' in '%s'", newName, xmldbUri));

XmldbURI newNameUri = XmldbURI.create(newName);

Expand Down Expand Up @@ -397,7 +398,7 @@ public XmldbURI createFile(String newName, InputStream is, Long length, String c
if (mime.isXMLType() && vtf.length() == 0L) {

if(LOG.isDebugEnabled())
LOG.debug("Creating dummy XML file for null resource lock '" + newNameUri + "'");
LOG.debug(String.format("Creating dummy XML file for null resource lock '%s'", newNameUri));

vtf = new VirtualTempFile();
IOUtils.write("<null_resource/>", vtf);
Expand All @@ -415,7 +416,7 @@ public XmldbURI createFile(String newName, InputStream is, Long length, String c
// by ResourceFactory
collection = broker.openCollection(xmldbUri, Lock.WRITE_LOCK);
if (collection == null) {
LOG.debug("Collection " + xmldbUri + " does not exist");
LOG.debug(String.format("Collection %s does not exist", xmldbUri));
txnManager.abort(txn);
throw new CollectionDoesNotExistException(xmldbUri + "");
}
Expand All @@ -424,7 +425,7 @@ public XmldbURI createFile(String newName, InputStream is, Long length, String c
if (mime.isXMLType()) {

if(LOG.isDebugEnabled())
LOG.debug("Inserting XML document '" + mime.getName() + "'");
LOG.debug(String.format("Inserting XML document '%s'", mime.getName()));

// Stream into database
VirtualTempFileInputSource vtfis = new VirtualTempFileInputSource(vtf);
Expand All @@ -436,7 +437,7 @@ public XmldbURI createFile(String newName, InputStream is, Long length, String c
} else {

if(LOG.isDebugEnabled())
LOG.debug("Inserting BINARY document '" + mime.getName() + "'");
LOG.debug(String.format("Inserting BINARY document '%s'", mime.getName()));

// Stream into database
InputStream fis = vtf.getByteStream();
Expand Down Expand Up @@ -508,8 +509,7 @@ public XmldbURI createFile(String newName, InputStream is, Long length, String c
void resourceCopyMove(XmldbURI destCollectionUri, String newName, Mode mode) throws EXistException {

if(LOG.isDebugEnabled())
LOG.debug(mode + " '" + xmldbUri + "' to '" +
destCollectionUri + "' named '" + newName + "'");
LOG.debug(String.format("%s '%s' to '%s' named '%s'", mode, xmldbUri, destCollectionUri, newName));

XmldbURI newNameUri = null;
try {
Expand Down Expand Up @@ -545,7 +545,7 @@ void resourceCopyMove(XmldbURI destCollectionUri, String newName, Mode mode) thr
// Open collection if possible, else abort
destCollection = broker.openCollection(destCollectionUri, Lock.WRITE_LOCK);
if (destCollection == null) {
LOG.debug("Destination collection " + xmldbUri + " does not exist.");
LOG.debug(String.format("Destination collection %s does not exist.", xmldbUri));
txnManager.abort(txn);
return; // TODO throw?
}
Expand All @@ -562,7 +562,7 @@ void resourceCopyMove(XmldbURI destCollectionUri, String newName, Mode mode) thr
txnManager.commit(txn);

if(LOG.isDebugEnabled())
LOG.debug("Collection " + mode + "d sucessfully");
LOG.debug(String.format("Collection %sd sucessfully", mode));

} catch (LockException e) {
LOG.error("Resource is locked.", e);
Expand Down
59 changes: 35 additions & 24 deletions extensions/webdav/src/org/exist/webdav/ExistDocument.java
Expand Up @@ -27,7 +27,9 @@
import java.io.Writer;
import java.net.URISyntaxException;
import java.util.Properties;

import javax.xml.transform.OutputKeys;

import org.exist.EXistException;
import org.exist.collections.Collection;
import org.exist.collections.triggers.TriggerException;
Expand All @@ -49,6 +51,7 @@
import org.exist.webdav.exceptions.DocumentAlreadyLockedException;
import org.exist.webdav.exceptions.DocumentNotLockedException;
import org.exist.xmldb.XmldbURI;

import org.xml.sax.SAXException;

/**
Expand All @@ -72,7 +75,7 @@ public class ExistDocument extends ExistResource {
public ExistDocument(XmldbURI uri, BrokerPool pool) {

if (LOG.isTraceEnabled()) {
LOG.trace("New document object for " + uri);
LOG.trace(String.format("New document object for %s", uri));
}

brokerPool = pool;
Expand Down Expand Up @@ -202,7 +205,7 @@ public void stream(OutputStream os) throws IOException, PermissionDeniedExceptio

} catch (SAXException e) {
LOG.error(e);
throw new IOException("Error while serializing XML document: " + e.getMessage(), e);
throw new IOException(String.format("Error while serializing XML document: %s", e.getMessage()), e);
}

} else {
Expand All @@ -228,7 +231,7 @@ public void stream(OutputStream os) throws IOException, PermissionDeniedExceptio
brokerPool.release(broker);

if (LOG.isDebugEnabled()) {
LOG.debug("Stream stopped, duration " + (System.currentTimeMillis() - startTime) + " msec.");
LOG.debug(String.format("Stream stopped, duration %s msec.", System.currentTimeMillis() - startTime));
}
}

Expand All @@ -240,7 +243,7 @@ public void stream(OutputStream os) throws IOException, PermissionDeniedExceptio
void delete() {

if (LOG.isDebugEnabled()) {
LOG.debug("Deleting " + xmldbUri);
LOG.debug(String.format("Deleting %s", xmldbUri));
}

DBBroker broker = null;
Expand Down Expand Up @@ -268,7 +271,7 @@ void delete() {
// Open document if possible, else abort
resource = collection.getDocument(broker, docName);
if (resource == null) {
LOG.debug("No resource found for path: " + xmldbUri);
LOG.debug(String.format("No resource found for path: %s", xmldbUri));
txnManager.abort(txn);
return;
}
Expand Down Expand Up @@ -415,7 +418,7 @@ public LockToken lock(LockToken inputToken) throws PermissionDeniedException,
if (document == null) {

if (LOG.isDebugEnabled()) {
LOG.debug("No resource found for path: " + xmldbUri);
LOG.debug(String.format("No resource found for path: %s", xmldbUri));
}
//return null; // throw exception?
throw new EXistException("No resource found.");
Expand All @@ -435,7 +438,7 @@ public LockToken lock(LockToken inputToken) throws PermissionDeniedException,
&& !userLock.getName().equals(subject.getName())
&& !subject.hasDbaRole() ) {
if (LOG.isDebugEnabled()) {
LOG.debug("Resource is locked by user " + userLock.getName() + ".");
LOG.debug(String.format("Resource is locked by user %s.", userLock.getName()));
}
throw new PermissionDeniedException(userLock.getName());
}
Expand Down Expand Up @@ -503,7 +506,10 @@ public LockToken lock(LockToken inputToken) throws PermissionDeniedException,
document.getUpdateLock().release(Lock.WRITE_LOCK);
}

txnManager.close(txn);
if (txnManager != null) {
txnManager.close(txn);
}

brokerPool.release(broker);

if (LOG.isDebugEnabled()) {
Expand Down Expand Up @@ -535,22 +541,23 @@ void unlock() throws PermissionDeniedException, DocumentNotLockedException, EXis
document = broker.getXMLResource(xmldbUri, Lock.WRITE_LOCK);

if (document == null) {
LOG.debug("No resource found for path: " + xmldbUri);
throw new EXistException("No resource found for path: " + xmldbUri);
final String msg = String.format("No resource found for path: %s", xmldbUri);
LOG.debug(msg);
throw new EXistException(msg);
}

// Get current userlock
Account lock = document.getUserLock();

// Check if Resource is already locked.
if (lock == null) {
LOG.debug("Resource " + xmldbUri + " is not locked.");
LOG.debug(String.format("Resource %s is not locked.", xmldbUri));
throw new DocumentNotLockedException("" + xmldbUri);
}

// Check if Resource is from subject
if (!lock.getName().equals(subject.getName()) && !subject.hasDbaRole() ) {
LOG.debug("Resource lock is from user " + lock.getName());
LOG.debug(String.format("Resource lock is from user %s", lock.getName()));
throw new PermissionDeniedException(lock.getName());
}

Expand Down Expand Up @@ -597,7 +604,7 @@ void unlock() throws PermissionDeniedException, DocumentNotLockedException, EXis
void resourceCopyMove(XmldbURI destCollectionUri, String newName, Mode mode) throws EXistException {

if (LOG.isDebugEnabled()) {
LOG.debug(mode + " " + xmldbUri + " to " + destCollectionUri + " named " + newName);
LOG.debug(String.format("%s %s to %s named %s", mode, xmldbUri, destCollectionUri, newName));
}

XmldbURI newNameUri = null;
Expand Down Expand Up @@ -635,15 +642,15 @@ void resourceCopyMove(XmldbURI destCollectionUri, String newName, Mode mode) thr
// Open document if possible, else abort
srcDocument = srcCollection.getDocument(broker, srdDocumentUri);
if (srcDocument == null) {
LOG.debug("No resource found for path: " + xmldbUri);
LOG.debug(String.format("No resource found for path: %s", xmldbUri));
txnManager.abort(txn);
return;
}

// Open collection if possible, else abort
destCollection = broker.openCollection(destCollectionUri, Lock.WRITE_LOCK);
if (destCollection == null) {
LOG.debug("Destination collection " + xmldbUri + " does not exist.");
LOG.debug(String.format("Destination collection %s does not exist.", xmldbUri));
txnManager.abort(txn);
return;
}
Expand All @@ -662,7 +669,7 @@ void resourceCopyMove(XmldbURI destCollectionUri, String newName, Mode mode) thr
txnManager.commit(txn);

if (LOG.isDebugEnabled()) {
LOG.debug("Document " + mode + "d sucessfully");
LOG.debug(String.format("Document %sd sucessfully", mode));
}

} catch (LockException e) {
Expand Down Expand Up @@ -713,9 +720,8 @@ void resourceCopyMove(XmldbURI destCollectionUri, String newName, Mode mode) thr
public LockToken refreshLock(String token) throws PermissionDeniedException,
DocumentAlreadyLockedException, EXistException, DocumentNotLockedException {


if (LOG.isDebugEnabled()) {
LOG.debug("refresh lock " + xmldbUri + " lock=" + token);
LOG.debug(String.format("refresh lock %s lock=%s", xmldbUri, token));
}

DBBroker broker = null;
Expand All @@ -740,7 +746,7 @@ public LockToken refreshLock(String token) throws PermissionDeniedException,

if (document == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No resource found for path: " + xmldbUri);
LOG.debug(String.format("No resource found for path: %s", xmldbUri));
}
//return null; // throw exception?
throw new EXistException("No resource found.");
Expand All @@ -751,16 +757,17 @@ public LockToken refreshLock(String token) throws PermissionDeniedException,

// Check if Resource is already locked.
if (userLock == null) {
final String msg = "Resource was not locked.";
if (LOG.isDebugEnabled()) {
LOG.debug("Resource was not locked.");
LOG.debug(msg);
}
throw new DocumentNotLockedException("Resource was not locked.");
throw new DocumentNotLockedException(msg);
}

if (userLock.getName() != null && !userLock.getName().equals(subject.getName())
&& !subject.hasDbaRole()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Resource is locked by " + userLock.getName());
LOG.debug(String.format("Resource is locked by %s", userLock.getName()));
}
throw new PermissionDeniedException(userLock.getName());
}
Expand All @@ -771,7 +778,7 @@ public LockToken refreshLock(String token) throws PermissionDeniedException,
if (LOG.isDebugEnabled()) {
LOG.debug("Token does not match");
}
throw new PermissionDeniedException("Token " + token + " does not match " + lockToken.getOpaqueLockToken());
throw new PermissionDeniedException(String.format("Token %s does not match %s", token, lockToken.getOpaqueLockToken()));
}

lockToken.setTimeOut(LockToken.LOCK_TIMEOUT_INFINITE);
Expand Down Expand Up @@ -810,7 +817,11 @@ public LockToken refreshLock(String token) throws PermissionDeniedException,
if (document != null) {
document.getUpdateLock().release(Lock.WRITE_LOCK);
}
txnManager.close(txn);

if (txnManager != null) {
txnManager.close(txn);
}

if(broker != null) {
brokerPool.release(broker);
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/webdav/src/org/exist/webdav/ExistResource.java
Expand Up @@ -114,7 +114,7 @@ protected Subject authenticate(String username, String password) {
subject = securityManager.authenticate(username, password);

} catch (AuthenticationException e) {
LOG.info("User " + username + " could not be authenticated. " + e.getMessage());
LOG.info(String.format("User %s could not be authenticated. %s", username, e.getMessage()));
}
return subject;
}
Expand Down

0 comments on commit 6d6ab1e

Please sign in to comment.