Package com.volantis.mcs.utilities

Examples of com.volantis.mcs.utilities.MarinerURL


            // 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!
View Full Code Here


        }

        AssetURLRewriter defaultAssetURLRewriter =
            getVolantisBean(requestContext).getAssetURLRewriter();
       
        MarinerURL rewrittenURL =
            defaultAssetURLRewriter.rewriteAssetURL(requestContext,
                                                    asset,
                                                    assetGroup,
                                                    marinerURL);
        // We do not want to mime encode links
        if (asset instanceof LinkAsset) {
            return rewrittenURL;
        } else {
            // To create a unique reference, generate a digest of the url and
            // convert it into a hex String.               
            //String newUrl = StringHash.getDigestAsHex(oldUrl);
            String oldUrl = rewrittenURL.getExternalForm();
            String newUrl;
           
            // Add the appropriate file extension for encoded images.
            if (imageEncodingString != null) {
                int imageEncoding=new Integer(imageEncodingString).intValue();
                newUrl = getFileName(oldUrl) + "." +
                    ImageAsset.fileExtension(imageEncoding);
            } else {
                newUrl = getFileName(oldUrl);
            }
       
            MPSApplicationContext applicationContext =
                (MPSApplicationContext)ContextInternals
                    .getApplicationContext(requestContext);

            HttpServletResponse response =
                (HttpServletResponse)((MarinerServletRequestContext)requestContext).getResponse();

            if (assetGroup != null) {
                response.setHeader("asset." +
                                   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
            // MPSApplicationContext#setDevice method
            Integer maxFileSize = applicationContext.getMaxFileSize();
            Integer maxMMSize = applicationContext.getMaxMMSize();
            if (maxFileSize != null) {
                response.setHeader("maxfilesize", maxFileSize.toString());
            }
            if (maxMMSize != null) {
                response.setHeader("maxmmsize", maxMMSize.toString());
            }

            // Cannot put cid: in the string passed to the MarinerURL constructor
            // because the constructor thinks that cid is the protocol, when in
            // actual fact we want to use cid: to refer to the Content-ID header.

            //return new MarinerURL(newUrl);
            MarinerURL urlToReturn = new MarinerURL();
            urlToReturn.setPath("cid:"+newUrl);
            return urlToReturn;
        }
    }
View Full Code Here

                    throw new IllegalStateException(
                            "No application registered");
                }
            }

            MarinerURL requestURL =
                    volantisBean.getClientAccessibleURL(
                            new MarinerURL("internalRequest"));

            ApplicationContext appContext;
            ApplicationContextFactory acf =
                    applicationRegistryContainer
                    .getInternalApplicationContextFactory();
View Full Code Here

                    throw new IllegalStateException(
                            "No application registered");
                }
            }

            MarinerURL requestURL = createRequestURL(request);
            requestURL = volantisBean.getClientAccessibleURL(requestURL);

            ApplicationContext appContext;
            ApplicationContextFactory acf =
                    applicationRegistryContainer.getServletApplicationContextFactory();
View Full Code Here

        }

        // Create a MarinerURL which contains the URL which could have been
        // used by the client to generate this request.

        return new MarinerURL(uri.toString(), getParameterMap(request));
    }
View Full Code Here

                        return baseURL;
                    }

                    // JavaDoc inherited
                    public MarinerURL getInternalURL() {
                        return new MarinerURL(internalURL);
                    }
                };
            }
        };
View Full Code Here

        }
       
        AssetURLRewriter defaultAssetURLRewriter =
            getVolantisBean(requestContext).getAssetURLRewriter();
       
        MarinerURL rewrittenURL =
            defaultAssetURLRewriter.rewriteAssetURL(requestContext,
                                                    asset,
                                                    assetGroup,
                                                    marinerURL);
       
        // We do not want to mime encode links
        if (asset instanceof LinkAsset) {
            return rewrittenURL;
        } else {       
            // To create a unique reference, generate a digest of the url and
            // convert it into a hex String.               
            //String newUrl = StringHash.getDigestAsHex(oldUrl);
            String oldUrl = rewrittenURL.getExternalForm();
            String newUrl;
           
            // Add the appropriate file extension for encoded images.
            if (imageEncodingString != null) {
                int imageEncoding=new Integer(imageEncodingString).intValue();
                newUrl = getFileName(oldUrl) + "." +
                    ImageAsset.fileExtension(imageEncoding);
            } else {
                newUrl = getFileName(oldUrl);
            }

            MPSApplicationContext applicationContext =
                (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

        PageURLRewriter layoutURLRewriter = new PageURLRewriter() {
            public MarinerURL rewriteURL(MarinerRequestContext context,
                                         MarinerURL url,
                                         PageURLDetails details) {
                return new MarinerURL(testURL);
            }
        };
        PrivateAccessor.setField(volantis, "layoutURLRewriter",
                layoutURLRewriter);

        TestMarinerPageContext context = new TestMarinerPageContext();
        context.setVolantis(volantis);
        context.setRequestURL(new MarinerURL("http://a.url"));

        FormDescriptor fd = new FormDescriptor();
        fd.setName(formName);
        final FormDataManager formDataManager = context.getFormDataManager();
        String formSpecifier = formDataManager.getFormSpecifier(fd);
View Full Code Here

                                               new TestEnvironmentContext());
        VolantisProtocol protocol = new VolantisProtocolStub();       
        pageContext.setProtocol(protocol);
        pageContext.setPageGenerationCache(new PageGenerationCache());
        pageContext.setRequestURL(
                new MarinerURL("http://server:8080/volantis/test.xdime"));
        ContextInternals.setMarinerPageContext(requestContext, pageContext);
        protocol.setMarinerPageContext(pageContext);

        // Create the xfform form element surrounding the xfimplicit. This is
        // required as XFImplicitElement.elementStart gets the current element
View Full Code Here

        Pane pane2 = new Pane(canvasLayout);
        pane2.setName("pane2");
        pane2.setParent(formFrag2);

        MarinerURL requestURL = context.getRequestURL(false);
        requestURL.setParameterValue("vfrag", "f1");

        try {
            // Set the children of the formats.
            outerFrag.setChildAt(innerFrag, 0);
            innerFrag.setChildAt(grid, 0);
View Full Code Here

TOP

Related Classes of com.volantis.mcs.utilities.MarinerURL

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.