Package com.volantis.mps.message

Examples of com.volantis.mps.message.MessageAsset


                                   assetGroup.getLocationType() +
                                   "." +
                                   Base64.encodeString(newUrl),
                                   Base64.encodeString(oldUrl));
                applicationContext.mapAsset(newUrl,
                        new MessageAsset(assetGroup.getLocationType(), oldUrl));
            } else {
                response.setHeader("asset." +
                                   AssetGroup.ON_SERVER +
                                   "." +
                                   Base64.encodeString(newUrl),
                                   Base64.encodeString(oldUrl));
                applicationContext.mapAsset(newUrl,
                        new MessageAsset(AssetGroup.ON_SERVER, oldUrl));
            }

            // Add headers for maximum file and MM (message) sizes.
            // This reuses the names found in the
            // MarinerPageContext#constructURL method and also used in the
View Full Code Here


            // Assemble Assets
            Map assetMap = message.getAssetMap();
            Iterator i = assetMap.keySet().iterator();
            String mimeReference;
            MarinerURL url;
            MessageAsset messageAsset;

            // Sizes are in bytes
            Integer maxImageSize = message.getMaxFileSize();
            Integer maxMessageSize = message.getMaxMMSize();
            int actualMessageSize = 0;

            ArrayList imageAssets = new ArrayList();

            // Process each of the assets
            while( i.hasNext() ) {

                mimeReference = ( String ) i.next();
                // We can only retrieve assets that reside on the
                // server.
                messageAsset = ( MessageAsset ) assetMap.get( mimeReference );

                // Set appropriate headers
                asset = new MimeBodyPart();
                asset.setHeader( "Content-Disposition",
                        "inline; filename=\"" + mimeReference + "\"" );
                asset.setHeader( "Content-ID", "<" + mimeReference + ">" );

                if (messageAsset.isTextMessage()) {
                    // Handle simple textual content
                    String contentType = "text/plain";
                    if (message.getCharacterEncoding() != null) {
                            contentType += "; charset=" +
                                            message.getCharacterEncoding();
                    }
                    asset.setContent( messageAsset.getText(), contentType);
                    mimeMultipart.addBodyPart( asset );
                    actualMessageSize += determineAssetSize( asset );
                } else {
                    // Handle other content, but only if they reside on the
                    // server
                    if( messageAsset.getLocationType() ==
                            MessageAsset.ON_SERVER ) {
                        url = fixupURL( message.getBaseURL(),
                                new MarinerURL( messageAsset.getUrl() ) );
                        URL assetURL = new URL( url.getExternalForm() );

                        // Now sort out the content type and whether the asset
                        // exists or not...
                        try {
                            URLConnection connection =
                                    assetURL.openConnection();

                            // Check to see if a connection object has been
                            // successfully obtained
                            if( connection != null ) {
                                // Set the connection up
                                connection.setDoInput( true );
                                connection.setDoOutput( false );
                                connection.setAllowUserInteraction( false );

                                // Actually connect
                                connection.connect();

                                // Force the connection to be used
                                connection.getInputStream();

                                // Grab the content type from the stream to
                                // use in the mime body part of the asset
                                String contentType =
                                        connection.getContentType();
                                // By getting here, the asset exists and the
                                // connection succesfully opened so add the
                                // asset
                                asset.setDataHandler( new DataHandler( assetURL ) );
                                asset.setHeader( "Content-location",
                                        url.getExternalForm() );
                                asset.setHeader( "Content-Type", contentType );
                                mimeMultipart.addBodyPart( asset );

                                // Store the images for later size processing
                                imageAssets.add( asset );
                            }
                        } catch( MalformedURLException mue ) {
                            // Quietly ignore this asset
                            if( logger.isDebugEnabled() ) {
                                logger.debug( "Ignoring asset with malformed URL: " +
                                        url.toString() );
                            }
                        } catch( IOException ioe ) {
                            // Quietly ignore this asset
                            if( logger.isDebugEnabled() ) {
                                logger.debug( "Ignoring asset with URL that " +
                                        "doesn't exist: " + assetURL +
                                        " (" + url.toString() + ")" );
                            }
                        }
                    } else {
                        // For device based assets there's not much that can
                        // be set apart from where it is!
                        asset.setHeader( "Content-Location",
                                "file://" + messageAsset.getUrl() );
                    }
                }
            }

            // Add on any attachments
View Full Code Here

                                    key.substring( ASSET_SERVER.length() ) );
                url = Base64.decodeToString(
                        ( (NameValuePair)headerMap.get( key ) ).getValue() );
                locationType = MessageAsset.ON_SERVER;

                assetMap.put( mimeReference, new MessageAsset( locationType, url ) );
            } else if( key.startsWith( ASSET_DEVICE ) ) {
                mimeReference = Base64.decodeToString(
                                    key.substring( ASSET_DEVICE.length() ) );
                url = Base64.decodeToString(
                        ( (NameValuePair)headerMap.get( key ) ).getValue() );
                locationType = MessageAsset.ON_DEVICE;

                assetMap.put( mimeReference, new MessageAsset( locationType, url ) );
            } else if( key.startsWith( TEXT_ASSET_SERVER ) ) {
                mimeReference = key.substring( TEXT_ASSET_SERVER.length() );
                text = Base64.decodeToString(
                        ( (com.volantis.synergetics.NameValuePair)headerMap.get( key ) ).getValue() );
                assetMap.put( mimeReference, new MessageAsset( text ) );
            }
        }
        return assetMap;
    }
View Full Code Here

     * map to allow the MessageRequestor to build a messgae with assets
     */
   
    public String  mapSMILAsset(String value) {
        String mimeReference = super.mapSMILAsset(value);
        mapAsset(mimeReference, new MessageAsset(value));
        return mimeReference;
    }
View Full Code Here

                (MPSApplicationContext)ContextInternals
                    .getApplicationContext(requestContext);

            if (assetGroup != null) {
                applicationContext.mapAsset(newUrl,
                        new MessageAsset(assetGroup.getLocationType(), oldUrl));
            } else {
                applicationContext.mapAsset(newUrl,
                        new MessageAsset(AssetGroup.ON_SERVER, oldUrl));
            }   
            MarinerURL urlToReturn = new MarinerURL();
            urlToReturn.setPath("cid:"+newUrl);
            return urlToReturn;
        }
View Full Code Here

                // or asset size or ...
            }
        };

        HashMap assetMap = new HashMap();
        assetMap.put("mimeref", new MessageAsset("Test Message"));

        MessageAsset asset1 = new MessageAsset(MessageAsset.ON_SERVER,
                "http://127.0.0.1:9999/test.gif");
        MessageAsset asset2 = new MessageAsset(MessageAsset.ON_DEVICE,
                "http://127.0.0.1:9999/test.gif");
        assetMap.put("asset1", asset1);
        assetMap.put("asset2", asset2);

        ProtocolIndependentMessage mesg = new ProtocolIndependentMessage(
View Full Code Here

TOP

Related Classes of com.volantis.mps.message.MessageAsset

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.