throws ContentRepositoryException, JAXBException
{
ServerSessionManager ssm = LoginManager.getPrimary();
ContentCollection dir = getContentDir();
ContentResource file;
if (report.getId() == null) {
// create a new file
String fileName;
int index = 0;
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
do {
fileName = ssm.getUsername() + "-" + df.format(new Date());
fileName += (index == 0)?"":index;
index++;
} while (dir.getChild(fileName) != null);
file = (ContentResource)
dir.createChild(fileName, ContentNode.Type.RESOURCE);
} else {
// update an existing file
file = (ContentResource) dir.getChild(report.getId());
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Marshaller m = getContext().createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
m.marshal(report, baos);
file.put(baos.toByteArray());
}