List of usage examples for javax.activation DataSource getContentType
public String getContentType();
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"); }/*from ww w .ja v a 2 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()); }/*from w ww . ja v a 2s . co 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"); }// w w w.j a v a 2s. 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 ww w . ja va 2 s . 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:com.jaspersoft.jasperserver.ws.axis2.ManagementServiceImpl.java
private static String marshalResponse(OperationResult or, Map datasources, boolean isEncapsulationDime) { String result = ""; // First of all attach the attachments... if (datasources != null) { MessageContext msgContext = MessageContext.getCurrentContext(); Message responseMessage = msgContext.getResponseMessage(); log.debug("Encapsulation DIME? : " + isEncapsulationDime); if (isEncapsulationDime) { responseMessage.getAttachmentsImpl() .setSendType(org.apache.axis.attachments.Attachments.SEND_TYPE_DIME); }/*from w w w . j av a2 s .c o m*/ for (Iterator it = datasources.entrySet().iterator(); it.hasNext();) { try { Map.Entry entry = (Map.Entry) it.next(); String name = (String) entry.getKey(); DataSource datasource = (DataSource) entry.getValue(); log.debug("Adding attachment: " + name + ", type: " + datasource.getContentType()); DataHandler expectedDH = new DataHandler(datasource); javax.xml.soap.AttachmentPart attachPart = null; attachPart = responseMessage.createAttachmentPart(expectedDH); //javax.xml.soap.AttachmentPart ap2 = responseMessage.createAttachmentPart(); //ap2.setContent( datasource.getInputStream(), datasource.getContentType()); attachPart.setContentId(name); responseMessage.addAttachmentPart(attachPart); } catch (Exception ex) { log.error("caught exception marshalling an OperationResult: " + ex.getMessage(), ex); // What to do? or.setReturnCode(1); or.setMessage("Error attaching a resource to the SOAP message: " + ex.getMessage()); } } } try { StringWriter xmlStringWriter = new StringWriter(); Marshaller.marshal(or, xmlStringWriter); if (log.isDebugEnabled()) { log.debug("Has descriptors: " + ((or.getResourceDescriptors() == null || or.getResourceDescriptors().size() == 0) ? 0 : or.getResourceDescriptors().size())); log.debug("marshalled response"); log.debug(xmlStringWriter.toString()); } result = xmlStringWriter.toString(); } catch (Exception ex) { log.error("caught exception marshalling an OperationResult: " + ex.getMessage(), ex); // What to do? } return result; }
From source file:com.cubusmail.mail.MessageHandler.java
/** * @param msg/*from w w w . j a v a2s. co m*/ * @throws MessagingException * @throws IOException */ public void createForwardMessage(Message msg) throws MessagingException, IOException { init(); setSubject("Fwd: " + msg.getSubject()); setHtmlMessage(MessageUtils.isHtmlMessage(msg)); List<MimePart> attachments = MessageUtils.attachmentsFromPart(msg); if (attachments != null) { for (MimePart part : attachments) { DataSource source = part.getDataHandler().getDataSource(); ByteArrayDataSource newSource = new ByteArrayDataSource(source.getInputStream(), source.getContentType()); if (StringUtils.isEmpty(source.getName())) { newSource.setName(this.applicationContext.getMessage("message.unknown.attachment", null, SessionManager.get().getLocale())); } else { newSource.setName(source.getName()); } addComposeAttachment(newSource); } } Preferences prefs = SessionManager.get().getPreferences(); MessageTextUtil.messageTextFromPart(msg, this, true, MessageTextMode.REPLY, prefs, 0); }
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 ww w. j ava 2s . 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())); } } 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 {/*from w ww. ja va2 s . co 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 {/*from www . j av a 2 s. com*/ 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 ww w . j a v a 2 s . com*/ 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); } }