JBoss.orgCommunity Documentation

Auxiliary attributes for documents

By default, your activities, such as writing a document, and uploading a file, are published on the activity stream. However, you can decide to publish these activities or not by creating a context named DocumentContext for a specific document. This context stores some auxiliary attributes of the document and helps document listeners make decision based on these attributes.

This context looks like:



public class DocumentContext {
private static ThreadLocal<DocumentContext> current = new ThreadLocal<DocumentContext>();
public static DocumentContext getCurrent() {
   if (current.get() == null) {
      setCurrent(new DocumentContext());
    }
   return current.get();
  }
....
//Each time, attributes are able to set and got via:
/**
  * @return the attributes
  */
  public HashMap<String, Object> getAttributes() {
   return attributes;
  }
 /**
  * @param attributes the attributes to set
  */
  public void setAttributes(HashMap<String, Object> attributes) {
    this.attributes = attributes;
  }
}

For example:

When you upload a document to a drive by using ManageDocumentService, but do not want to publish this activity on the activity stream, you can do as follows:

DocumentContext.getCurrent().getAttributes().put(DocumentContext.IS_SKIP_RAISE_ACT, true);

Then, this activity is skipped at:



 Object isSkipRaiseAct = DocumentContext.getCurrent().getAttributes().get(DocumentContext.IS_SKIP_RAISE_ACT);
if (isSkipRaiseAct != null && Boolean.valueOf(isSkipRaiseAct.toString())) {
  return;
 }

Note

The DocumentContext class is able to help developers manage various kinds of actions with a document based on its auxiliary attributes. You can be free to define new attributes for yourself.