Package javax.activation

Examples of javax.activation.DataSource


            // add output attachments
            map = CastUtils.cast((Map<?, ?>)ctx.getMessageContext().get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS));

            try {
                DataSource ds = new AttachmentDataSource("image/jpeg", getClass().getResourceAsStream("/Splash.jpg"));
                map.put(MtomTestHelper.RESP_IMAGE_CID, new DataHandler(ds));
               
            } catch (IOException e) {
                e.printStackTrace();
            }
           
            try {
                DataSource ds = new AttachmentDataSource("application/octet-stream",
                                                         new ByteArrayInputStream(MtomTestHelper.RESP_PHOTO_DATA));
                map.put(MtomTestHelper.RESP_PHOTO_CID, new DataHandler(ds));
               
            } catch (IOException e) {
                e.printStackTrace();
View Full Code Here


    File file = new File(SOURCE_IMAGE_FILE);
    assertTrue(file.exists());

    sourceLength = file.length();

    DataSource dataSource = new FileDataSource(file);
    assertNotNull(dataSource);
    DataHandler dataHandler = new DataHandler(dataSource);

    OMText textData = fac.createOMText(dataHandler, true);
    attachElem.addChild(textData);
View Full Code Here

     * @throws IOException resolving the resources failed
     */
    private String replacePattern(final String htmlMessage, final Pattern pattern)
            throws EmailException, IOException
    {
        DataSource dataSource;
        final StringBuffer stringBuffer = new StringBuffer();

        // maps "cid" --> name
        final Map<String, String> cidCache = new HashMap<String, String>();

        // maps "name" --> dataSource
        final Map<String, DataSource> dataSourceCache = new HashMap<String, DataSource>();

        // in the String, replace all "img src" with a CID and embed the related
        // image file if we find it.
        final Matcher matcher = pattern.matcher(htmlMessage);

        // the matcher returns all instances one by one
        while (matcher.find())
        {
            // in the RegEx we have the <src> element as second "group"
            final String resourceLocation = matcher.group(2);

            // avoid loading the same data source more than once
            if (dataSourceCache.get(resourceLocation) == null)
            {
                // in lenient mode we might get a 'null' data source if the resource was not found
                dataSource = getDataSourceResolver().resolve(resourceLocation);

                if (dataSource != null)
                {
                    dataSourceCache.put(resourceLocation, dataSource);
                }
            }
            else
            {
                dataSource = dataSourceCache.get(resourceLocation);
            }

            if (dataSource != null)
            {
                String name = dataSource.getName();
                if (EmailUtils.isEmpty(name))
                {
                    name = resourceLocation;
                }

                String cid = cidCache.get(name);

                if (cid == null)
                {
                    cid = embed(dataSource, dataSource.getName());
                    cidCache.put(name, cid);
                }

                // if we embedded something, then we need to replace the URL with
                // the CID, otherwise the Matcher takes care of adding the
View Full Code Here

    }

    /** {@inheritDoc} */
    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
    {
        DataSource result = null;

        try
        {
            if (!isCid(resourceLocation) && !isHttpUrl(resourceLocation))
            {
View Full Code Here

    }

    /** {@inheritDoc} */
    public DataSource resolve(final String resourceLocation) throws IOException
    {
        final DataSource result = resolve(resourceLocation, true);

        if (isLenient() || result != null)
        {
            return result;
        }
View Full Code Here

    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
    {
        for (int i = 0; i < getDataSourceResolvers().length; i++)
        {
            final DataSourceResolver dataSourceResolver = getDataSourceResolvers()[i];
            final DataSource dataSource = dataSourceResolver.resolve(resourceLocation, isLenient);

            if (dataSource != null)
            {
                return dataSource;
            }
View Full Code Here

    }

    /** {@inheritDoc} */
    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
    {
        DataSource result = null;

        try
        {
            if (!isCid(resourceLocation))
            {
                final URL url = createUrl(resourceLocation);
                result = new URLDataSource(url);
                result.getInputStream();
            }

            return result;
        }
        catch (final IOException e)
View Full Code Here

     */
    protected DataSource createDataSource(final Multipart parent, final MimePart part)
        throws MessagingException, IOException
    {
        final DataHandler dataHandler = part.getDataHandler();
        final DataSource dataSource = dataHandler.getDataSource();
        final String contentType = getBaseMimeType(dataSource.getContentType());
        final byte[] content = this.getContent(dataSource.getInputStream());
        final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType);
        final String dataSourceName = getDataSourceName(part, dataSource);

        result.setName(dataSourceName);
        return result;
View Full Code Here

     * @param name the name of the attachment
     * @return the corresponding datasource or null if nothing was found
     */
    public DataSource findAttachmentByName(final String name)
    {
        DataSource dataSource;

        for (int i = 0; i < getAttachmentList().size(); i++)
        {
            dataSource = getAttachmentList().get(i);
            if (name.equalsIgnoreCase(dataSource.getName()))
            {
                return dataSource;
            }
        }

View Full Code Here

        final MultiPartEmail email = (MultiPartEmail) create(MultiPartEmail.class);
        email.setSubject(subject);
        email.setMsg(textMsg);

        // create a proper UTF-8 sequence for the text attachment (matching our default charset)
        final DataSource attachment = new javax.mail.util.ByteArrayDataSource(textMsg.getBytes("utf-8"), "text/plain");
        email.attach(attachment, attachmentName, "Attachment in Greek");

        EmailUtils.writeMimeMessage( new File("./target/test-emails/correct-encoding.eml"), send(email).getMimeMessage());
    }
View Full Code Here

TOP

Related Classes of javax.activation.DataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.