def add_document(self, item_uri, name, metadata,
                     content=None, docurl=None, file=None,
                     displaydoc=False, preferName=False,
                     contrib_id=None):
        if not preferName and file is not None:
            docid = os.path.basename(file)
        else:
            docid = name
        docmeta = {"metadata": {"@context": self.context,
                                "@type": "foaf:Document",
                                "dcterms:identifier": docid,
                                }
                  }
        docmeta["metadata"].update(metadata)
        if contrib_id:
            docmeta['contribution_id'] = contrib_id
        if content is not None:
            docmeta['document_content'] = content
        elif docurl is not None:
            docmeta["metadata"]["dcterms:source"] = { "@id": docurl }
        elif file is not None:
            docmeta = docmeta['metadata']
        else:
            raise Exception("One of content, docurl or file must be specified in add_document")
        if file is not None:
            result = self.api_request(item_uri, method='POST', data={'metadata': json.dumps(docmeta)}, file=file)
        else:
            result = self.api_request(item_uri, method='POST', data=json.dumps(docmeta))
        self.__check_success(result)
        if displaydoc:
            itemmeta = {"http://alveo.edu.org/vocabulary/display_document": docid}
            self.modify_item(item_uri, itemmeta)
        doc_uri = item_uri + "/document/" + name
        return doc_uri