From 6d6ab1ec8cb4b676cab1a6214325a2af2ccfe845 Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sun, 4 Aug 2013 12:07:06 +0200 Subject: [PATCH] [ignore] Java5-ified construction of (LOG) messages --- .../src/org/exist/webdav/ExistCollection.java | 30 +++++----- .../src/org/exist/webdav/ExistDocument.java | 59 +++++++++++-------- .../src/org/exist/webdav/ExistResource.java | 2 +- .../exist/webdav/ExistResourceFactory.java | 16 ++--- .../org/exist/webdav/MiltonCollection.java | 28 ++++----- .../src/org/exist/webdav/MiltonDocument.java | 22 +++---- .../src/org/exist/webdav/MiltonResource.java | 20 +++---- .../org/exist/webdav/MiltonWebDAVServlet.java | 5 +- 8 files changed, 97 insertions(+), 85 deletions(-) diff --git a/extensions/webdav/src/org/exist/webdav/ExistCollection.java b/extensions/webdav/src/org/exist/webdav/ExistCollection.java index 39f4f23f99d..5d8af60eeeb 100644 --- a/extensions/webdav/src/org/exist/webdav/ExistCollection.java +++ b/extensions/webdav/src/org/exist/webdav/ExistCollection.java @@ -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; @@ -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; } @@ -224,7 +224,7 @@ public List getDocumentURIs() { void delete() { if(LOG.isDebugEnabled()) - LOG.debug("Deleting '" + xmldbUri + "'"); + LOG.debug(String.format("Deleting '%s'", xmldbUri)); DBBroker broker = null; Collection collection = null; @@ -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); @@ -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 @@ -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); @@ -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("", vtf); @@ -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 + ""); } @@ -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); @@ -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(); @@ -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 { @@ -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? } @@ -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); diff --git a/extensions/webdav/src/org/exist/webdav/ExistDocument.java b/extensions/webdav/src/org/exist/webdav/ExistDocument.java index 669c12b2441..0074c9bd314 100644 --- a/extensions/webdav/src/org/exist/webdav/ExistDocument.java +++ b/extensions/webdav/src/org/exist/webdav/ExistDocument.java @@ -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; @@ -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; /** @@ -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; @@ -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 { @@ -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)); } } @@ -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; @@ -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; } @@ -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."); @@ -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()); } @@ -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()) { @@ -535,8 +541,9 @@ 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 @@ -544,13 +551,13 @@ void unlock() throws PermissionDeniedException, DocumentNotLockedException, EXis // 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()); } @@ -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; @@ -635,7 +642,7 @@ 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; } @@ -643,7 +650,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; } @@ -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) { @@ -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; @@ -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."); @@ -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()); } @@ -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); @@ -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); } diff --git a/extensions/webdav/src/org/exist/webdav/ExistResource.java b/extensions/webdav/src/org/exist/webdav/ExistResource.java index 1454386ecd2..e89beedfd18 100644 --- a/extensions/webdav/src/org/exist/webdav/ExistResource.java +++ b/extensions/webdav/src/org/exist/webdav/ExistResource.java @@ -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; } diff --git a/extensions/webdav/src/org/exist/webdav/ExistResourceFactory.java b/extensions/webdav/src/org/exist/webdav/ExistResourceFactory.java index fc7bc36ba7b..ab8434f53e7 100644 --- a/extensions/webdav/src/org/exist/webdav/ExistResourceFactory.java +++ b/extensions/webdav/src/org/exist/webdav/ExistResourceFactory.java @@ -90,7 +90,7 @@ public Resource getResource(String host, String path) { } if(LOG.isDebugEnabled()) { - LOG.debug("host='" + host + "' path='" + path + "'"); + LOG.debug(String.format("host='%s' path='%s'", host, path)); } // Create uri inside database @@ -99,11 +99,11 @@ public Resource getResource(String host, String path) { // MacOsX finder specific files String documentSeqment = xmldbUri.lastSegment().toString(); if(documentSeqment.startsWith("._") || documentSeqment.equals(".DS_Store")){ - LOG.debug("skipping MacOsX file '"+xmldbUri.lastSegment().toString()+"'"); + LOG.debug(String.format("skipping MacOsX file '%s'", xmldbUri.lastSegment().toString())); } } catch (URISyntaxException e) { - LOG.error("Unable to convert path '" + path + "'into a XmldbURI representation."); + LOG.error(String.format("Unable to convert path '%s'into a XmldbURI representation.", path)); return null; } @@ -123,12 +123,12 @@ public Resource getResource(String host, String path) { case NOT_EXISTING: if (LOG.isDebugEnabled()) { - LOG.debug("Resource does not exist: '" + xmldbUri + "'"); + LOG.debug(String.format("Resource does not exist: '%s'", xmldbUri)); } return null; default: - LOG.error("Unkown resource type for " + xmldbUri); + LOG.error(String.format("Unkown resource type for %s", xmldbUri)); return null; } } @@ -145,7 +145,7 @@ private ResourceType getResourceType(BrokerPool brokerPool, XmldbURI xmldbUri) { try { if(LOG.isDebugEnabled()) { - LOG.debug("Path: " + xmldbUri.toString()); + LOG.debug(String.format("Path: %s", xmldbUri.toString())); } // Try to read as system user. Note that the actual user is not know @@ -179,7 +179,7 @@ private ResourceType getResourceType(BrokerPool brokerPool, XmldbURI xmldbUri) { } catch (Exception ex) { - LOG.error("Error determining nature of resource " + xmldbUri.toString(), ex); + LOG.error(String.format("Error determining nature of resource %s", xmldbUri.toString()), ex); type = ResourceType.NOT_EXISTING; } finally { @@ -201,7 +201,7 @@ private ResourceType getResourceType(BrokerPool brokerPool, XmldbURI xmldbUri) { } if(LOG.isDebugEnabled()) { - LOG.debug("Resource type=" + type.toString()); + LOG.debug(String.format("Resource type=%s", type.toString())); } return type; diff --git a/extensions/webdav/src/org/exist/webdav/MiltonCollection.java b/extensions/webdav/src/org/exist/webdav/MiltonCollection.java index 3ae7d997167..33a74089cf3 100644 --- a/extensions/webdav/src/org/exist/webdav/MiltonCollection.java +++ b/extensions/webdav/src/org/exist/webdav/MiltonCollection.java @@ -105,7 +105,7 @@ public MiltonCollection(String host, XmldbURI uri, BrokerPool pool, Subject subj super(); if(LOG.isDebugEnabled()) { - LOG.debug("COLLECTION:" + uri.toString()); + LOG.debug(String.format("COLLECTION=%s", uri.toString())); } resourceXmldbUri = uri; @@ -131,7 +131,7 @@ public MiltonCollection(String host, XmldbURI uri, BrokerPool pool, Subject subj public Resource child(String childName) { if(LOG.isDebugEnabled()) { - LOG.debug("get child=" + childName); + LOG.debug(String.format("get child=%s", childName)); } // Safe guard value @@ -178,7 +178,7 @@ public List getChildren() { allResources.addAll(getDocumentResources()); if(LOG.isDebugEnabled()) { - LOG.debug("Nr of children=" + allResources.size()); + LOG.debug(String.format("Nr of children=%s", allResources.size())); } return allResources; @@ -199,7 +199,7 @@ public Date getCreateDate() { } if(LOG.isTraceEnabled()) { - LOG.trace("Create date=" + createDate); + LOG.trace(String.format("Create date=%s", createDate)); } return createDate; @@ -212,7 +212,7 @@ public Date getCreateDate() { public void delete() throws NotAuthorizedException, ConflictException, BadRequestException { if(LOG.isDebugEnabled()) { - LOG.debug("Delete collection '" + resourceXmldbUri + "'."); + LOG.debug(String.format("Delete collection '%s'.", resourceXmldbUri)); } existCollection.delete(); @@ -226,7 +226,7 @@ public CollectionResource createCollection(String name) throws NotAuthorizedException, ConflictException { if (LOG.isTraceEnabled()) { - LOG.trace("Create collection '" + name + "' in '" + resourceXmldbUri + "'."); + LOG.trace(String.format("Create collection '%s' in '%s'.", name, resourceXmldbUri)); } CollectionResource collection = null; @@ -259,7 +259,7 @@ public Resource createNew(String newName, InputStream is, Long length, String co throws IOException, ConflictException { if (LOG.isTraceEnabled()) { - LOG.trace("Create '" + newName + "' in '" + resourceXmldbUri + "'"); + LOG.trace(String.format("Create '%s' in '%s'", newName, resourceXmldbUri)); } Resource resource = null; @@ -291,7 +291,7 @@ public Resource createNew(String newName, InputStream is, Long length, String co public LockToken createAndLock(String name, LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException { if(LOG.isDebugEnabled()) { - LOG.debug("'" + resourceXmldbUri + "' name='" + name + "'"); + LOG.debug(String.format("'%s' name='%s'", resourceXmldbUri, name)); } String token = UUID.randomUUID().toString(); @@ -308,7 +308,7 @@ public LockResult lock(LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException, PreConditionFailedException, LockedException { if (LOG.isDebugEnabled()) { - LOG.debug("'" + resourceXmldbUri + "' -- " + lockInfo.toString()); + LOG.debug(String.format("'%s' -- %s", resourceXmldbUri, lockInfo.toString())); } return refreshLock(UUID.randomUUID().toString()); @@ -318,7 +318,7 @@ public LockResult lock(LockTimeout timeout, LockInfo lockInfo) public LockResult refreshLock(String token) throws NotAuthorizedException, PreConditionFailedException { if(LOG.isDebugEnabled()) { - LOG.debug("'" + resourceXmldbUri + "' token='" + token + "'"); + LOG.debug(String.format("'%s' token='%s'", resourceXmldbUri, token)); } LockInfo lockInfo = new LockInfo(LockInfo.LockScope.NONE, LockInfo.LockType.READ, token, LockInfo.LockDepth.ZERO); @@ -333,14 +333,14 @@ public LockResult refreshLock(String token) throws NotAuthorizedException, PreCo public void unlock(String tokenId) throws NotAuthorizedException, PreConditionFailedException { // Just do nothing if(LOG.isDebugEnabled()) { - LOG.debug("'" + resourceXmldbUri + "' token='" + tokenId + "'"); + LOG.debug(String.format("'%s' token='%s'", resourceXmldbUri, tokenId)); } } @Override public LockToken getCurrentLock() { if(LOG.isDebugEnabled()) { - LOG.debug("'" + resourceXmldbUri + "'"); + LOG.debug(String.format("'%s'", resourceXmldbUri)); } return null; // null is allowed } @@ -353,7 +353,7 @@ public LockToken getCurrentLock() { public void moveTo(CollectionResource rDest, String newName) throws ConflictException { if(LOG.isDebugEnabled()) { - LOG.debug("Move '"+ resourceXmldbUri + "' to '" + newName + "' in '" + rDest.getName() + "'"); + LOG.debug(String.format("Move '%s' to '%s' in '%s'", resourceXmldbUri, newName, rDest.getName())); } XmldbURI destCollection = ((MiltonCollection) rDest).getXmldbUri(); @@ -373,7 +373,7 @@ public void moveTo(CollectionResource rDest, String newName) throws ConflictExce public void copyTo(CollectionResource toCollection, String newName) { if(LOG.isDebugEnabled()) { - LOG.debug("Move '"+ resourceXmldbUri + "' to '" + newName + "' in '" + toCollection.getName() + "'"); + LOG.debug(String.format("Move '%s' to '%s' in '%s'", resourceXmldbUri, newName, toCollection.getName())); } XmldbURI destCollection = ((MiltonCollection) toCollection).getXmldbUri(); diff --git a/extensions/webdav/src/org/exist/webdav/MiltonDocument.java b/extensions/webdav/src/org/exist/webdav/MiltonDocument.java index c47926a4b97..de318cfdd5c 100644 --- a/extensions/webdav/src/org/exist/webdav/MiltonDocument.java +++ b/extensions/webdav/src/org/exist/webdav/MiltonDocument.java @@ -128,7 +128,7 @@ public MiltonDocument(String host, XmldbURI uri, BrokerPool pool, Subject subjec } if(LOG.isTraceEnabled()) { - LOG.trace("DOCUMENT:" + uri.toString()); + LOG.trace(String.format("DOCUMENT:%s", uri.toString())); } resourceXmldbUri = uri; @@ -287,8 +287,8 @@ public Long getContentLength() { // or when set by a system property if(LOG.isDebugEnabled()){ - LOG.debug("Serializing XML to /dev/null to determine size" - + " (" + resourceXmldbUri + ") MacFinder="+isMacFinder ); + LOG.debug(String.format("Serializing XML to /dev/null to determine size (%s) MacFinder=%s", + resourceXmldbUri, isMacFinder)); } // Stream document to '/dev/null' and count bytes @@ -331,7 +331,7 @@ public Long getContentLength() { try { if(LOG.isDebugEnabled()) { - LOG.debug("Serializing XML to virtual file" + " (" + resourceXmldbUri + ")"); + LOG.debug(String.format("Serializing XML to virtual file (%s)", resourceXmldbUri)); } vtf = new VirtualTempFile(); @@ -369,7 +369,7 @@ public Long getContentLength() { } if(LOG.isDebugEnabled()) { - LOG.debug("Size=" + size + " (" + resourceXmldbUri + ")"); + LOG.debug(String.format("Size=%s (%s)", size, resourceXmldbUri)); } return size; @@ -412,7 +412,7 @@ public LockResult lock(LockTimeout timeout, LockInfo lockInfo) org.exist.dom.LockToken inputToken = convertToken(timeout, lockInfo); if (LOG.isDebugEnabled()) { - LOG.debug("Lock: " + resourceXmldbUri); + LOG.debug(String.format("Lock: %s", resourceXmldbUri)); } LockResult lr = null; @@ -444,7 +444,7 @@ public LockResult lock(LockTimeout timeout, LockInfo lockInfo) public LockResult refreshLock(String token) throws NotAuthorizedException, PreConditionFailedException { if(LOG.isDebugEnabled()) { - LOG.debug("Refresh: " + resourceXmldbUri + " token=" + token); + LOG.debug(String.format("Refresh: %s token=%s", resourceXmldbUri, token)); } LockResult lr = null; @@ -480,7 +480,7 @@ public LockResult refreshLock(String token) throws NotAuthorizedException, PreCo public void unlock(String tokenId) throws NotAuthorizedException, PreConditionFailedException { if(LOG.isDebugEnabled()) { - LOG.debug("Unlock: " + resourceXmldbUri); + LOG.debug(String.format("Unlock: %s", resourceXmldbUri)); } try { @@ -503,7 +503,7 @@ public void unlock(String tokenId) throws NotAuthorizedException, PreConditionFa public LockToken getCurrentLock() { if(LOG.isDebugEnabled()) { - LOG.debug("getLock: " + resourceXmldbUri); + LOG.debug(String.format("getCurrentLock: %s", resourceXmldbUri)); } org.exist.dom.LockToken existLT = existDocument.getCurrentLock(); @@ -529,7 +529,7 @@ public LockToken getCurrentLock() { public void moveTo(CollectionResource rDest, String newName) throws ConflictException { if(LOG.isDebugEnabled()) { - LOG.debug("moveTo: " + resourceXmldbUri + " newName=" + newName); + LOG.debug(String.format("moveTo: %s newName=%s", resourceXmldbUri, newName)); } XmldbURI destCollection = ((MiltonCollection) rDest).getXmldbUri(); @@ -550,7 +550,7 @@ public void moveTo(CollectionResource rDest, String newName) throws ConflictExce public void copyTo(CollectionResource rDest, String newName) { if(LOG.isDebugEnabled()) { - LOG.debug("copyTo: " + resourceXmldbUri + " newName=" + newName); + LOG.debug(String.format("copyTo: %s newName=%s", resourceXmldbUri, newName)); } XmldbURI destCollection = ((MiltonCollection) rDest).getXmldbUri(); diff --git a/extensions/webdav/src/org/exist/webdav/MiltonResource.java b/extensions/webdav/src/org/exist/webdav/MiltonResource.java index d8f34eb960f..a1a8d5997b5 100644 --- a/extensions/webdav/src/org/exist/webdav/MiltonResource.java +++ b/extensions/webdav/src/org/exist/webdav/MiltonResource.java @@ -303,7 +303,7 @@ public String getName() { public Object authenticate(String username, String password) { if(LOG.isDebugEnabled()) - LOG.debug("Authenticating user " + username + " for " + resourceXmldbUri); + LOG.debug(String.format("Authenticating user %s for %s", username, resourceXmldbUri)); // Check if username is provided. if (username == null) { @@ -330,7 +330,7 @@ public Object authenticate(String username, String password) { // Guest is not allowed to access. Subject guest = brokerPool.getSecurityManager().getGuestSubject(); if (guest.equals(subject)) { - LOG.error("The user " + guest.getName() + " is prohibited from logging in through WebDAV."); + LOG.error(String.format("The user %s is prohibited from logging in through WebDAV.", guest.getName())); return null; } @@ -340,14 +340,14 @@ public Object authenticate(String username, String password) { existResource.initMetadata(); if(LOG.isDebugEnabled()) - LOG.debug("User '" + subject.getName() + "' has been authenticated."); + LOG.debug(String.format("User '%s' has been authenticated.", subject.getName())); return AUTHENTICATED; } @Override public boolean authorise(Request request, Method method, Auth auth) { - LOG.info(method.toString() + " " + resourceXmldbUri + " (write="+ method.isWrite+")"); + LOG.info(String.format("%s %s (write=%s)", method.toString(), resourceXmldbUri, method.isWrite)); /* * First perform checks on Milton authentication @@ -370,7 +370,7 @@ public boolean authorise(Request request, Method method, Auth auth) { // If object does not exist, there was no successfull authentication if (tag == null) { if(LOG.isDebugEnabled()) - LOG.debug("No tag, user " + userName + " not authenticated"); + LOG.debug(String.format("No tag, user %s not authenticated", userName)); return false; } else if (tag instanceof String) { @@ -380,8 +380,7 @@ public boolean authorise(Request request, Method method, Auth auth) { } else { if(LOG.isDebugEnabled()) - LOG.debug("Authentication tag contains wrong value, user " - + userName + " is not authenticated"); + LOG.debug(String.format("Authentication tag contains wrong value, user %s is not authenticated", userName)); return false; } } @@ -392,14 +391,14 @@ public boolean authorise(Request request, Method method, Auth auth) { if (method.isWrite) { if (!existResource.writeAllowed) { if(LOG.isDebugEnabled()) - LOG.debug("User " + userName + " is NOT authorized to write resource, abort."); + LOG.debug(String.format("User %s is NOT authorized to write resource, abort.", userName)); return false; } } else { if (!existResource.readAllowed) { if(LOG.isDebugEnabled()) - LOG.debug("User " + userName + " is NOT authorized to read resource, abort."); + LOG.debug(String.format("User %s is NOT authorized to read resource, abort.", userName)); return false; } } @@ -412,8 +411,7 @@ public boolean authorise(Request request, Method method, Auth auth) { String action = method.isWrite ? "write" : "read"; if(LOG.isDebugEnabled()) - LOG.debug("User " + userName + " is authorized to " + action - + " resource " + resourceXmldbUri.toString()); + LOG.debug(String.format("User %s is authorized to %s resource %s", userName, action, resourceXmldbUri.toString())); return true; } diff --git a/extensions/webdav/src/org/exist/webdav/MiltonWebDAVServlet.java b/extensions/webdav/src/org/exist/webdav/MiltonWebDAVServlet.java index 2fa77c8e0f9..f0e5bb7c91a 100644 --- a/extensions/webdav/src/org/exist/webdav/MiltonWebDAVServlet.java +++ b/extensions/webdav/src/org/exist/webdav/MiltonWebDAVServlet.java @@ -24,11 +24,14 @@ import com.bradmcevoy.http.MiltonServlet; import com.bradmcevoy.http.http11.DefaultHttp11ResponseHandler; + import java.io.IOException; import java.io.InputStream; import java.util.Properties; + import javax.servlet.ServletConfig; import javax.servlet.ServletException; + import org.apache.log4j.Logger; /** @@ -83,6 +86,6 @@ public void init(ServletConfig config) throws ServletException { // Pass value to Milton httpManager.setEnableExpectContinue(enableExpectContinue); - LOG.debug("Set 'Enable Expect Continue' to " + enableExpectContinue); + LOG.debug(String.format("Set 'Enable Expect Continue' to %s", enableExpectContinue)); } }