}
public String getCacheKey(Object... objects) {
WikiDocument currentDocument = (WikiDocument)Component.getInstance("currentDocument");
Integer accessLevel = (Integer) Component.getInstance("currentAccessLevel");
Hash hash = (Hash)Component.getInstance(Hash.class);
log.debug("generating cache key for document: " + currentDocument + " and macro: " + this + " and access level: " + accessLevel);
StringBuilder builder = new StringBuilder();
if (log.isDebugEnabled()) log.debug("including id of document: " + currentDocument.getId());
builder.append( currentDocument.getId() );
int namePositionHash = (getName() + "_" + getPosition()).hashCode();
if (log.isDebugEnabled()) log.debug("including name/position of this macro: " + Math.abs(namePositionHash));
builder.append( Math.abs(namePositionHash) );
if (log.isDebugEnabled()) log.debug("including hashCode of macro params: " + Math.abs(getParams().hashCode()));
builder.append( Math.abs(getParams().hashCode()) );
if (log.isDebugEnabled()) log.debug("including accessLevel: " + accessLevel);
builder.append( accessLevel );
// This needs to be empty-String safe (the additional objects might be some of the
// JSF "oh let's map a non-existant request parameter to an empty string" genius behavior...
if (objects != null && objects.length > 0) {
for (Object o : objects) {
if (o != null && Math.abs(o.hashCode()) != 0) {
log.debug("including hashCode of object: " + Math.abs(o.hashCode()));
builder.append( Math.abs(o.hashCode()) );
}
}
}
return hash.hash(builder.toString());
}