List of usage examples for javax.activation DataSource getName
public String getName();
From source file:com.jaspersoft.jasperserver.rest.utils.Utils.java
public void sendFile(DataSource ds, HttpServletResponse response) { response.setContentType(ds.getContentType()); if (ds.getName() != null && ds.getName().length() > 0) { response.addHeader("Content-Disposition", "attachment; filename=" + ds.getName()); }/*from www. jav a 2 s .c o m*/ OutputStream outputStream = null; BufferedInputStream bufferedInputStream = null; try { outputStream = response.getOutputStream(); bufferedInputStream = new BufferedInputStream(ds.getInputStream()); int readBytes = 0; while ((readBytes = bufferedInputStream.read()) != -1) { outputStream.write(readBytes); } if (log.isDebugEnabled()) { log.debug("finished sending bytes"); } } catch (IOException ex) { log.error("Error serving a file: " + ex.getMessage(), ex); } finally { if (outputStream != null) try { outputStream.close(); } catch (Exception ex) { } if (bufferedInputStream != null) try { bufferedInputStream.close(); } catch (Exception ex) { } } }
From source file:org.shredzone.cilla.service.impl.HeaderServiceImpl.java
@Override public void create(Header header, DataSource headerImg, DataSource fullImg) throws CillaServiceException { if (headerImg == null || fullImg == null) { throw new IllegalArgumentException("no header and/or full-view provided"); }/*w w w . j a v a2 s . c om*/ try { Date now = new Date(); Store headerStore = header.getHeaderImage(); headerStore.setContentType(headerImg.getContentType()); headerStore.setName(headerImg.getName()); headerStore.setLastModified(now); Store fullStore = header.getFullImage(); fullStore.setContentType(fullImg.getContentType()); fullStore.setName(fullImg.getName()); fullStore.setLastModified(now); Dimension dim = imageProcessor.analyzeDimension(headerImg); if (dim != null) { header.setWidth(dim.width); header.setHeight(dim.height); } ExifAnalyzer fullExif = imageProcessor.createExifAnalyzer(fullImg); header.setLocation(fullExif != null ? fullExif.getGeolocation() : null); headerDao.persist(header); ResourceDataSource headerDs = storeDao.access(header.getHeaderImage()); FileCopyUtils.copy(headerImg.getInputStream(), headerDs.getOutputStream()); ResourceDataSource fullDs = storeDao.access(header.getFullImage()); FileCopyUtils.copy(fullImg.getInputStream(), fullDs.getOutputStream()); } catch (IOException ex) { throw new CillaServiceException("Could not read medium", ex); } eventService.fireEvent(new Event<Header>(EventType.HEADER_NEW, header)); }
From source file:org.shredzone.cilla.service.impl.PageServiceImpl.java
@Override @CacheEvict(value = "processedImages", allEntries = true) public void updateMedium(Page page, Medium medium, DataSource source) throws CillaServiceException { if (!medium.getPage().equals(page)) { throw new IllegalArgumentException( "Medium id " + medium.getId() + " does not belong to Page id " + page.getId()); }// www. ja v a 2 s. c o m if (source != null) { try { Store store = medium.getImage(); store.setContentType(source.getContentType()); store.setName(source.getName()); store.setLastModified(new Date()); ResourceDataSource ds = storeDao.access(store); FileCopyUtils.copy(source.getInputStream(), ds.getOutputStream()); } catch (IOException ex) { throw new CillaServiceException("Could not set medium", ex); } } }
From source file:org.shredzone.cilla.service.impl.HeaderServiceImpl.java
@Override @CacheEvict(value = "processedImages", allEntries = true) public void updateImage(Header header, DataSource headerImg, DataSource fullImg) throws CillaServiceException { if (header.getId() == 0) { throw new IllegalArgumentException("header is not persisted"); }//from w w w. jav a 2 s . c o m try { Date now = new Date(); if (headerImg != null) { Store headerStore = header.getHeaderImage(); headerStore.setContentType(headerImg.getContentType()); headerStore.setName(headerImg.getName()); headerStore.setLastModified(now); Dimension dim = imageProcessor.analyzeDimension(headerImg); if (dim != null) { header.setWidth(dim.width); header.setHeight(dim.height); } else { header.setWidth(0); header.setHeight(0); } ResourceDataSource headerDs = storeDao.access(header.getHeaderImage()); FileCopyUtils.copy(headerImg.getInputStream(), headerDs.getOutputStream()); } if (fullImg != null) { Store fullStore = header.getFullImage(); fullStore.setContentType(fullImg.getContentType()); fullStore.setName(fullImg.getName()); fullStore.setLastModified(now); ExifAnalyzer fullExif = imageProcessor.createExifAnalyzer(fullImg); header.setLocation(fullExif != null ? fullExif.getGeolocation() : null); ResourceDataSource fullDs = storeDao.access(header.getFullImage()); FileCopyUtils.copy(fullImg.getInputStream(), fullDs.getOutputStream()); } eventService.fireEvent(new Event<Header>(EventType.HEADER_UPDATE, header)); } catch (IOException ex) { throw new CillaServiceException("Could not read medium", ex); } }
From source file:org.shredzone.cilla.service.impl.PictureServiceImpl.java
@Override public void addPicture(GallerySection section, Picture picture, DataSource source) throws CillaServiceException { if (picture.getId() != 0) { throw new IllegalArgumentException("picture is already persisted, id " + picture.getId()); }//from w ww. j ava2s . c om if (section.getId() == 0) { throw new IllegalArgumentException("section is not persisted"); } if (source == null) { throw new IllegalArgumentException("DataSource is not set"); } try { Store store = picture.getImage(); store.setContentType(source.getContentType()); store.setName(source.getName()); store.setLastModified(new Date()); Dimension dim = imageProcessor.analyzeDimension(source); if (dim != null) { picture.setWidth(dim.width); picture.setHeight(dim.height); } ExifAnalyzer exif = imageProcessor.createExifAnalyzer(source); if (exif != null) { TimeZone tz = picture.getCreateTimeZone(); if (tz == null) { tz = section.getDefaultTimeZone(); } picture.setCreateDate(exif.getDateTime(tz)); picture.setExifData(exif.getExifData()); picture.setLocation(exif.getGeolocation()); } else { picture.setCreateDate(null); picture.setExifData(null); picture.setLocation(null); } picture.setGallery(section); section.getPictures().add(picture); pictureDao.persist(picture); ResourceDataSource ds = storeDao.access(store); FileCopyUtils.copy(source.getInputStream(), ds.getOutputStream()); } catch (IOException ex) { throw new CillaServiceException("Could not read medium", ex); } eventService.fireEvent(new Event<Picture>(EventType.GALLERY_PICTURE_NEW, picture)); }
From source file:nl.clockwork.mule.ebms.dao.postgresql.EbMSDAOImpl.java
@Override public void insertMessage(final EbMSMessage message, final EbMSMessageStatus status) throws DAOException { try {//from w w w. j a v a2s.c o m transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); Long key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(timestamp, message.getMessageHeader().getCPAId(), message.getMessageHeader().getConversationId(), message.getMessageOrder() == null ? null : message.getMessageOrder().getSequenceNumber().getValue().longValue(), message.getMessageHeader().getMessageData().getMessageId(), message.getMessageHeader().getMessageData().getRefToMessageId(), message.getMessageHeader().getFrom().getRole(), message.getMessageHeader().getTo().getRole(), message.getMessageHeader().getService().getType(), message.getMessageHeader().getService().getValue(), message.getMessageHeader().getAction(), message.getOriginal(), XMLMessageBuilder.getInstance(SignatureType.class) .handle(new ObjectFactory().createSignature(message.getSignature())), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(message.getMessageHeader()), XMLMessageBuilder.getInstance(SyncReply.class).handle(message.getSyncReply()), XMLMessageBuilder.getInstance(MessageOrder.class).handle(message.getMessageOrder()), XMLMessageBuilder.getInstance(AckRequested.class).handle(message.getAckRequested()), XMLMessageBuilder.getInstance(Manifest.class).handle(message.getManifest()), status), new IdExtractor()); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update( "insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", key, attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(), attachment.getContentType().split(";")[0].trim(), IOUtils.toByteArray(attachment.getInputStream())); } } catch (Exception e) { throw new RuntimeException(e); } } }); } catch (Exception e) { throw new DAOException(e); } }
From source file:nl.clockwork.mule.ebms.dao.postgresql.EbMSDAOImpl.java
@Override public void insertMessage(final EbMSMessage message, final List<EbMSSendEvent> sendEvents) throws DAOException { try {//w ww .j a v a 2s .c o m transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); Long key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(timestamp, message.getMessageHeader().getCPAId(), message.getMessageHeader().getConversationId(), message.getMessageOrder() == null ? null : message.getMessageOrder().getSequenceNumber().getValue().longValue(), message.getMessageHeader().getMessageData().getMessageId(), message.getMessageHeader().getMessageData().getRefToMessageId(), message.getMessageHeader().getFrom().getRole(), message.getMessageHeader().getTo().getRole(), message.getMessageHeader().getService().getType(), message.getMessageHeader().getService().getValue(), message.getMessageHeader().getAction(), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(message.getMessageHeader()), XMLMessageBuilder.getInstance(SyncReply.class).handle(message.getSyncReply()), XMLMessageBuilder.getInstance(MessageOrder.class).handle(message.getMessageOrder()), XMLMessageBuilder.getInstance(AckRequested.class).handle(message.getAckRequested()), XMLMessageBuilder.getInstance(Manifest.class).handle(message.getManifest())), new IdExtractor()); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update( "insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", key, attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(), attachment.getContentType().split(";")[0].trim(), IOUtils.toByteArray(attachment.getInputStream())); } List<Object[]> events = new ArrayList<Object[]>(); for (EbMSSendEvent sendEvent : sendEvents) { //events.add(new Object[]{key,String.format(getDateFormat(),sendEvent.getTime())}); events.add(new Object[] { key, sendEvent.getTime() }); } simpleJdbcTemplate.batchUpdate( "insert into ebms_send_event (" + "ebms_message_id," + "time" + ") values (?,?)", events); } catch (Exception e) { throw new RuntimeException(e); } } }); } catch (Exception e) { throw new DAOException(e); } }
From source file:nl.clockwork.mule.ebms.dao.postgresql.EbMSDAOImpl.java
@Override public void insertMessage(final EbMSMessage message, final EbMSMessageStatus status, final EbMSMessageError messageError, final EbMSSendEvent sendEvent) throws DAOException { try {/* ww w . j a v a2s.c om*/ transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); Long key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(timestamp, message.getMessageHeader().getCPAId(), message.getMessageHeader().getConversationId(), message.getMessageOrder() == null ? null : message.getMessageOrder().getSequenceNumber().getValue().longValue(), message.getMessageHeader().getMessageData().getMessageId(), message.getMessageHeader().getMessageData().getRefToMessageId(), message.getMessageHeader().getFrom().getRole(), message.getMessageHeader().getTo().getRole(), message.getMessageHeader().getService().getType(), message.getMessageHeader().getService().getValue(), message.getMessageHeader().getAction(), message.getOriginal(), XMLMessageBuilder.getInstance(SignatureType.class) .handle(new ObjectFactory().createSignature(message.getSignature())), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(message.getMessageHeader()), XMLMessageBuilder.getInstance(SyncReply.class).handle(message.getSyncReply()), XMLMessageBuilder.getInstance(MessageOrder.class).handle(message.getMessageOrder()), XMLMessageBuilder.getInstance(AckRequested.class).handle(message.getAckRequested()), XMLMessageBuilder.getInstance(Manifest.class).handle(message.getManifest()), status), new IdExtractor()); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update( "insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", key, attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(), attachment.getContentType().split(";")[0].trim(), IOUtils.toByteArray(attachment.getInputStream())); } key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(timestamp, messageError.getMessageHeader().getCPAId(), messageError.getMessageHeader().getConversationId(), messageError.getMessageHeader().getMessageData().getMessageId(), messageError.getMessageHeader().getMessageData().getRefToMessageId(), messageError.getMessageHeader().getFrom().getRole(), messageError.getMessageHeader().getTo().getRole(), messageError.getMessageHeader().getService().getType(), messageError.getMessageHeader().getService().getValue(), messageError.getMessageHeader().getAction(), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(messageError.getMessageHeader()), XMLMessageBuilder.getInstance(ErrorList.class).handle(messageError.getErrorList())), new IdExtractor()); simpleJdbcTemplate.update( "insert into ebms_send_event (" + "ebms_message_id," + "time" + ") values (?,?)", key, //String.format(getDateFormat(),sendEvent.getTime()) sendEvent.getTime()); } catch (Exception e) { throw new RuntimeException(e); } } }); } catch (Exception e) { throw new DAOException(e); } }
From source file:nl.clockwork.mule.ebms.dao.postgresql.EbMSDAOImpl.java
@Override public void insertMessage(final EbMSMessage message, final EbMSMessageStatus status, final EbMSAcknowledgment acknowledgment, final EbMSSendEvent sendEvent) throws DAOException { try {//from w w w. j av a2 s. c om transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); Long key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(timestamp, message.getMessageHeader().getCPAId(), message.getMessageHeader().getConversationId(), message.getMessageOrder() == null ? null : message.getMessageOrder().getSequenceNumber().getValue().longValue(), message.getMessageHeader().getMessageData().getMessageId(), message.getMessageHeader().getMessageData().getRefToMessageId(), message.getMessageHeader().getFrom().getRole(), message.getMessageHeader().getTo().getRole(), message.getMessageHeader().getService().getType(), message.getMessageHeader().getService().getValue(), message.getMessageHeader().getAction(), message.getOriginal(), XMLMessageBuilder.getInstance(SignatureType.class) .handle(new ObjectFactory().createSignature(message.getSignature())), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(message.getMessageHeader()), XMLMessageBuilder.getInstance(SyncReply.class).handle(message.getSyncReply()), XMLMessageBuilder.getInstance(MessageOrder.class).handle(message.getMessageOrder()), XMLMessageBuilder.getInstance(AckRequested.class).handle(message.getAckRequested()), XMLMessageBuilder.getInstance(Manifest.class).handle(message.getManifest()), status), new IdExtractor()); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update( "insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", key, attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(), attachment.getContentType().split(";")[0].trim(), IOUtils.toByteArray(attachment.getInputStream())); } key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(timestamp, acknowledgment.getMessageHeader().getCPAId(), acknowledgment.getMessageHeader().getConversationId(), acknowledgment.getMessageHeader().getMessageData().getMessageId(), acknowledgment.getMessageHeader().getMessageData().getRefToMessageId(), acknowledgment.getMessageHeader().getFrom().getRole(), acknowledgment.getMessageHeader().getTo().getRole(), acknowledgment.getMessageHeader().getService().getType(), acknowledgment.getMessageHeader().getService().getValue(), acknowledgment.getMessageHeader().getAction(), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(acknowledgment.getMessageHeader()), XMLMessageBuilder.getInstance(Acknowledgment.class) .handle(acknowledgment.getAcknowledgment())), new IdExtractor()); simpleJdbcTemplate.update( "insert into ebms_send_event (" + "ebms_message_id," + "time" + ") values (?,?)", key, //String.format(getDateFormat(),sendEvent.getTime()) sendEvent.getTime()); } catch (Exception e) { throw new RuntimeException(e); } } }); } catch (Exception e) { throw new DAOException(e); } }
From source file:com.cubusmail.mail.MessageHandler.java
/** * @throws MessagingException/*from ww w. j ava 2s .c o m*/ * @throws IOException */ private void buildBodyContent() throws MessagingException, IOException { boolean hasAttachments = (this.composeAttachments != null && this.composeAttachments.size() > 0); boolean multipart = hasAttachments || isHtmlMessage(); MimeMessageHelper messageHelper = new MimeMessageHelper(this.message, multipart); if (isHtmlMessage()) { String plainText = MessageTextUtil.convertHtml2PlainText(this.messageTextHtml); messageHelper.setText(plainText, this.messageTextHtml); } else { messageHelper.setText(this.messageTextPlain, false); } if (hasAttachments) { for (DataSource attachment : this.composeAttachments) { messageHelper.addAttachment(attachment.getName(), attachment); } } if (!isRead()) { this.message.setFlag(Flags.Flag.SEEN, true); } }