private Log log = LogFactory.getLog(AttachmentToPutAttachmentEncoder.class);
public Object encode(TracProperties tracProperties, Object parameter) {
if(parameter == null){
throw new TracException(MessageUtils.getMessage("core.parameter.not.found", "TicketAttachment", this.getClass().getName()));
}
WikiAttachment wikiAttachment = (WikiAttachment)parameter;
// check for mandatory fields
String pageName = wikiAttachment.getPageName();
if(pageName == null || pageName.trim().equals("")){
throw new TracException(MessageUtils.getMessage("core.parameter.not.found", "TicketAttachment.pageName", this.getClass().getName()));
}
String fileName = wikiAttachment.getFileName();
if(fileName == null || fileName.trim().equals("")){
throw new TracException(MessageUtils.getMessage("core.parameter.not.found", "TicketAttachment.fileName", this.getClass().getName()));
}
String description = wikiAttachment.getDescription();
if(description == null) description = "";
String fullFileName = wikiAttachment.getFullFileName();
if(fullFileName == null || fullFileName.trim().equals("")){
throw new TracException(MessageUtils.getMessage("core.parameter.not.found", "TicketAttachment.fullFileName", this.getClass().getName())); }
byte[] binaryData = Utils.getBinaryData(fullFileName, tracProperties);
String pathToAttachment = pageName + "/" + fileName;