Package com.volantis.mcs.utilities

Examples of com.volantis.mcs.utilities.MarinerURL


        RuntimeProject project =
            (RuntimeProject)asset.getIdentity().getProject();
        if (project == null) {
            project = (RuntimeProject)requestContext.getCurrentProject();
        }
        MarinerURL prefix = null;
        MarinerURL newURL = marinerURL;

        if (assetGroup != null) {
            prefix = new MarinerURL(assetGroup.getPrefixURL());
            if (logger.isDebugEnabled()) {
                logger.debug("Retrieved prefix from asset group as " + prefix);
            }
        } else {
            prefix = getPrefixURL(project, asset);
            if (logger.isDebugEnabled()) {
                logger.debug("Retrieved prefix from project " +
                    project + " as " + prefix);
            }
        }
        if (prefix != null) {
            newURL = new MarinerURL(prefix, marinerURL);
         }

        return newURL;
    }
View Full Code Here


        }
        if (project == null) {
            throw new IllegalStateException("Project not set");
        }

        MarinerURL assetsBaseURL = project.getAssetsBaseURL();
        if (isClientSideURL(asset, assetGroup)) {
            // Client side URLs are not affected by the project's base URL.
        } else if (project.getContainsOrphans() && project.isRemote()) {
            // Asset URLs from remote policies that are not in a remote project
            // should already be fully qualified.
            if (!marinerURL.isAbsolute()) {
                synchronized(DefaultAssetURLRewriter.class) {
                    if (!vikingCasualtyChipWOWFlag) {
                        vikingCasualtyChipWOWFlag = true;
                        logger.warn("url-not-absolute",
                                marinerURL.getExternalForm());
                    }
                }
            }
        } else if (marinerURL.containsDocumentRelativePath()) {

            // Document relative assets should only be resolved if the project
            // is portable, otherwise leave them as they are.
            // todo Always resolve these and then provide a way later to optimise URLs in the page to try and make them relative if possible.
            if (project.isPortable()) {

                // If the project is portable then get the project relative path to the
                // policy so that it can be used to resolve relative asset references
                // against.
                MarinerURL projectRelativePath;
                String name = asset.getName();
                if (name.startsWith("/")) {
                    projectRelativePath = new MarinerURL(name);
                } else {
                    projectRelativePath = new MarinerURL(
                            assetProject.makeProjectRelativePath(name, true));
                }

                // Resolve relative asset references against the project
                // relative path and then make sure that it can be resolved
                // against the assets base URL by removing leading /.
                marinerURL = new MarinerURL(projectRelativePath, marinerURL);
                marinerURL = new MarinerURL(
                        URLNormalizer.convertHostRelativeToDocumentRelative(
                                marinerURL.getExternalForm()));

                // Resolve the document relative asset URL against the assets
                // base URL.
                marinerURL = new MarinerURL(assetsBaseURL, marinerURL);

                // The result must be absolute, or host relative.
                if (marinerURL.isAbsolute()) {
                    // Nothing more to do.
                } else if (marinerURL.containsHostRelativePath()) {
                    // May need to make it relative to the context.
                    EnvironmentContext environmentContext =
                            ContextInternals.getEnvironmentContext(
                                    requestContext);
                    MarinerURL contextPath =
                            environmentContext.getContextPathURL();
                    marinerURL = new MarinerURL(contextPath,
                            URLNormalizer.convertHostRelativeToDocumentRelative(
                                    marinerURL.getExternalForm()));
                } else {
                    throw new IllegalStateException("The rewritten URL " +
                            marinerURL + " for remote asset " + asset + " " +
                            "must be absolute or host relative but is not");
                }
            }

        } else if (marinerURL.containsHostRelativePath()) {

            // Host relative paths are treated as being relative to the
            // project's asset base URL. This is because otherwise assets
            // and asset groups would need to know the host relative path to
            // the assets including the web application context (if any).

            // NOTE: I have the feeling this should be dealt with when the url
            // is computed but there is no description for the intermediate form
            // of the url so I am not prepared to change that. This class needs
            // rewriting/clarifying. Until then we are left with the following
            // bodge...
            // todo: later: deal with document relative urls which are from
            // asset groups which are host relative.
            //
            // If the url was computed from an asset group which was relative
            // to the host, then we should leave this as host relative.
            if (assetGroup != null && assetGroup.getLocationType() ==
                    AssetGroup.HOST) {
                // Leave the url as host relative. This will mean than when
                // resolved against the context the context is ignored.
                if (logger.isDebugEnabled()) {
                    logger.debug("leaving existing host relative url computed " +
                            "from host relative asset group url as host " +
                            "relative");
                }
            } else {
                // Either it was not from an asset group or the asset group was
                // context relative. In either case we should...

                // Strip the / off the front of the host relative URL to make it
                // a document relative URL so it will resolve against the base
                // URL properly.
                String url = URLNormalizer.convertHostRelativeToDocumentRelative(
                        marinerURL.getExternalForm());
                marinerURL = new MarinerURL(assetsBaseURL, url);
            }


            // The resulting URL must be either a host relative path or an
            // absolute URL. If it is not then it is a fatal error as it could
View Full Code Here

        String fragmentName = destination.getName();

        // Create an anchor tag for this fragment
        FraglinkAttributes a = new FraglinkAttributes();

        MarinerURL rootPageURL = pageContext.getRootPageURL(true);

        String inclusionPath =
                pageContext.getDeviceLayoutContext().getInclusionPath();

        // Get the key to the current fragmentation state.
        int currentKey = pageContext.getFragmentationIndex();

        if (toEnclosing) {
            if (logger.isDebugEnabled()) {
                logger.debug("Generating link to enclosing fragment");
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Generating link to enclosed fragment");
            }
        }

        String requestValue;
        PageGenerationCache pageGenerationCache
                = pageContext.getPageGenerationCache();

        RuntimeDeviceLayout deviceLayout =
                pageContext.getDeviceLayout();
        String defaultFragmentName = deviceLayout.getDefaultFragmentName();
        boolean isDefault = true;
        if (defaultFragmentName == null
                || !fragmentName.equals(defaultFragmentName)) {
            isDefault = false;
        }

        // If we are generating a link to the enclosing fragment and this is
        // the top inclusion then we do not need to add a vfrag value to the
        // URL.
        if (toEnclosing && inclusionPath == null && isDefault) {
            if (logger.isDebugEnabled()) {
                logger.debug("Returning to default top level fragment");
            }
            requestValue = null;
        } else {

            // The change to apply to the fragmentation state.
            FragmentationState.Change change;

            // If the enclosing fragment is the default fragment for the layout
            // then discard the information about it, this reduces the number
            // of possible fragmentation states for a particular layout which
            // reduces the memory usage.

            change = new FragmentationState.FragmentChange(inclusionPath,
                                                           fragmentName,
                                                           toEnclosing,
                                                           isDefault);

            if (logger.isDebugEnabled()) {
                logger.debug("Change to be applied is " + change);
            }

            int changeIndex = pageGenerationCache.
                    getFragmentationStateChangeIndex(change);

            requestValue = PageGenerationCache.
                    makeFragmentChangeSpecifier(currentKey, changeIndex);
        }

        if (logger.isDebugEnabled()) {
            logger.debug("URL before is "
                         + rootPageURL.getExternalForm());
        }

        if (requestValue == null) {
            rootPageURL.removeParameter(URLConstants.FRAGMENTATION_PARAMETER);
        } else {
            rootPageURL.setParameterValue(URLConstants.FRAGMENTATION_PARAMETER,
                                          requestValue);
        }

        // Get the URLRewriter to use to encode session information in the
        // URL and use it.
        MarinerRequestContext requestContext = pageContext.getRequestContext();
        URLRewriter sessionURLRewriter = pageContext.getSessionURLRewriter();
        MarinerURL sessionURL
                = sessionURLRewriter.mapToExternalURL(requestContext,
                                                      rootPageURL);

        // perform any URL rewriting that may be required by an external plugin
        PageURLRewriter urlRewriter = pageContext.getVolantisBean().
                getLayoutURLRewriter();
        MarinerURL externalURL =
                urlRewriter.rewriteURL(pageContext.getRequestContext(),
                        sessionURL,
                        PageURLDetailsFactory.createPageURLDetails(
                                PageURLType.FRAGMENT));

        String absoluteLink = externalURL.getExternalForm();
        if (logger.isDebugEnabled()) {
            logger.debug("URL after Rewriting is " + absoluteLink);
        }

        a.setInList(isInList);
View Full Code Here

    public void writeDefaultSegmentLink()
            throws RendererException, IOException {

        // Check whether this layout needs to provide a link back to the
        // default segment.
        MarinerURL url = pageContext.getRequestURL(false);
        String defaultSegmentURL
                = url.getParameterValue(URLConstants.SEGMENTATION_PARAMETER);
        if (defaultSegmentURL != null) {
            writeDefaultSegmentLink(pageContext, defaultSegmentURL);
        }
    }
View Full Code Here

            String generatedResourceBaseDir, CacheControlConstraintsMap cacheControlConstraintsMap) {

        this.policySource = policySource;
        String baseURLString = config.getBaseUrl();
        baseURL = (baseURLString != null ?
                new MarinerURL(baseURLString) : null);
        variantType2PrefixURL = new HashMap();
        addVariantPrefixURL(VariantType.AUDIO, config.getAudioAssets());
        addVariantPrefixURL(VariantType.VIDEO, config.getDynamicVisualAssets());
        addVariantPrefixURL(VariantType.IMAGE, config.getImageAssets());
        addVariantPrefixURL(VariantType.SCRIPT, config.getScriptAssets());
View Full Code Here

     * @param configuration The configuration from which the prefixURL should
     *                    be extracted.
     */
    private void addVariantPrefixURL(VariantType variantType,
                                     AssetConfiguration configuration) {
        MarinerURL prefixURL;
        if (configuration == null) {
            prefixURL = null;
        } else {
            prefixURL = new MarinerURL(configuration.getPrefixUrl());
            prefixURL.makeReadOnly();
        }

        variantType2PrefixURL.put(variantType, prefixURL);
    }
View Full Code Here

        builder.setAssetsBaseURL(baseURL);
        builder.setCacheControlDefaultsMap(cacheControlConstraintsMap);
        for (Iterator i = variantType2PrefixURL.entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();
            VariantType variantType = (VariantType) entry.getKey();
            MarinerURL prefixURL = (MarinerURL) entry.getValue();
            builder.addVariantPrefixURL(variantType, prefixURL);
        }
        return builder.getProject();
    }
View Full Code Here

        }

        // Resolve the asset's base URL against the external location of the
        // project file.
        String assetsBase = assets.getBaseUrl();
        MarinerURL assetsBaseURL = new MarinerURL(externalLocation, assetsBase);
        assetsBase = assetsBaseURL.getExternalForm();

        // This method is only used for portable projects.
        builder.setPortable(true);

        assets.setBaseUrl(assetsBase);
View Full Code Here

     * @return A fully qualified Asset Base URL.
     */
    protected String resolveAbsoluteURL(String projectBaseURL, String url) {
        // Lets start off by assuming that they have specified a fully
        // qualified URL.
        MarinerURL result = new MarinerURL(url);
        //Then again they may not have
        if (!result.isAbsolute()) {
            // So lets resolve it properly if we have a base URL;
            if (projectBaseURL != null) {
                result = new MarinerURL(projectBaseURL, url);
            }
        }
        return result.getExternalForm();
    }
View Full Code Here

    private RuntimePolicyReference evaluateRuntimePolicyExpression(
            RuntimePolicyReferenceExpression policyExpression) {
        Expression expression = policyExpression.getExpression();
        RuntimeProject project = (RuntimeProject) policyExpression.getProject();
        MarinerURL baseURL = policyExpression.getBaseURL();
        String brandName = policyExpression.getBrandName();

        RuntimePolicyReference reference = null;
        try {
            Value value = expression.evaluate(expressionContext);
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.