Package com.volantis.mcs.assets

Examples of com.volantis.mcs.assets.ScriptAsset


        pattributes.setDefer(attributes.getDefer());

        // @todo this code duplicates the functionality of the protocols Script
        // object. we should refactor it away...
        if (src != null && src.isPolicyReference()) {
            ScriptAsset asset = src.getScriptAsset();
            // If no asset was found then there is nothing more to do.
            if (asset == null) {
                return SKIP_ELEMENT_BODY;
            }

            // If an id was specified then we need to remember whether we found a
            // suitable ScriptAsset, or not.
            if (id != null) {
                pageContext.putIdValue(id, asset);
            }

            pattributes.setScriptReference(src);
            pattributes.setCharSet(asset.getCharacterSet());
            pattributes.setType(asset.getMimeType());
            pattributes.setLanguage(asset.getProgrammingLanguage());

            // Write the open script.
            protocol.writeOpenScript(pattributes);
            opened = true;
            return SKIP_ELEMENT_BODY;
View Full Code Here


        assetResolverMock.expects.selectBestVariant(
            runtimePolicyReferenceMock1, null).returns(selectedVariantMock1).any();
        selectedVariantMock1.expects.getVariant().returns(variantMock).any();
        selectedVariantMock1.expects.getPolicy().returns(policyMock1).any();
        selectedVariantMock1.expects.getOldObject().returns(
            new ScriptAsset("name1", "deviceName1", "javascript1", "mimeType1",
                "charSet1", ScriptAsset.URL, "assetGroupName1", "value1")).any();
        final DefaultComponentScriptAssetReference scriptAssetReference1 =
            new DefaultComponentScriptAssetReference(
                runtimePolicyReferenceMock1, assetResolverMock);
        assertTrue(slm.addScript(scriptAssetReference1));

        final ActivatedVariablePolicyMock policyMock2 =
            new ActivatedVariablePolicyMock("ActivatedVariablePolicyMock2",
                expectations);
        policyMock2.expects.getName().returns("name2").any();
        final SelectedVariantMock selectedVariantMock2 =
            new SelectedVariantMock("SelectedVariantMock2", expectations);
        selectedVariantMock2.expects.getVariant().returns(variantMock).any();
        selectedVariantMock2.expects.getPolicy().returns(policyMock2).any();
        selectedVariantMock2.expects.getOldObject().returns(
            new ScriptAsset("name2", "deviceName2", "javascript2", "mimeType2",
                "charSet2", ScriptAsset.URL, "assetGroupName2", "value2")).any();
        assetResolverMock.expects.selectBestVariant(
            runtimePolicyReferenceMock2, null).returns(selectedVariantMock2).any();
        final DefaultComponentScriptAssetReference scriptAssetReference2 =
            new DefaultComponentScriptAssetReference(
                runtimePolicyReferenceMock2, assetResolverMock);
        assertTrue(slm.addScript(scriptAssetReference2));

        final SelectedVariantMock selectedVariantMock1b =
            new SelectedVariantMock("SelectedVariantMock1b", expectations);
        selectedVariantMock1b.expects.getVariant().returns(variantMock).any();
        selectedVariantMock1b.expects.getPolicy().returns(policyMock1).any();
        selectedVariantMock1b.expects.getOldObject().returns(new ScriptAsset(
            "name1b", "deviceName1b", "javascript1b", "mimeType1b", "charSet1b",
            ScriptAsset.URL, "assetGroupName1b", "value1b")).any();
        final DefaultComponentScriptAssetReference scriptAssetReference1b =
            new DefaultComponentScriptAssetReference(
                runtimePolicyReferenceMock1, assetResolverMock);
        assertFalse(slm.addScript(scriptAssetReference1b));

        final ActivatedVariablePolicyMock policyMock3 =
            new ActivatedVariablePolicyMock("ActivatedVariablePolicyMock3",
                expectations);
        policyMock3.expects.getName().returns("name3").any();
        final SelectedVariantMock selectedVariantMock3 =
            new SelectedVariantMock("SelectedVariantMock3", expectations);
        selectedVariantMock3.expects.getVariant().returns(variantMock).any();
        selectedVariantMock3.expects.getPolicy().returns(policyMock3).any();
        selectedVariantMock3.expects.getOldObject().returns(
            new ScriptAsset("name3", "deviceName3", "javascript3", "mimeType3",
                "charSet3", ScriptAsset.URL, "assetGroupName3", "value3")).any();
        assetResolverMock.expects.selectBestVariant(
            runtimePolicyReferenceMock3, null).returns(selectedVariantMock3).any();
        final DefaultComponentScriptAssetReference scriptAssetReference3 =
            new DefaultComponentScriptAssetReference(
                runtimePolicyReferenceMock3, assetResolverMock);
        assertTrue(slm.addScript(scriptAssetReference3));

        assetResolverMock.expects.computeURLAsString(selectedVariantMock1).
            returns("source1").any();
        assetResolverMock.expects.computeURLAsString(selectedVariantMock2).
            returns("source2").any();
        assetResolverMock.expects.computeURLAsString(selectedVariantMock3).
            returns("source3").any();

        assetResolverMock.expects.rewriteURLWithPageURLRewriter("source1", PageURLType.SCRIPT)
            .returns("source1").any();
        assetResolverMock.expects.rewriteURLWithPageURLRewriter("source2", PageURLType.SCRIPT)
            .returns("source2").any();
        assetResolverMock.expects.rewriteURLWithPageURLRewriter("source3", PageURLType.SCRIPT)
            .returns("source3").any();
       
        slm.writeScriptElements();

        assertEquals(3, scriptAttributesList.size());
        final ScriptAttributes scriptAttributes1 =
            (ScriptAttributes) scriptAttributesList.get(0);
        assertEquals("charSet1", scriptAttributes1.getCharSet());
        assertEquals("javascript1", scriptAttributes1.getLanguage());
        assertEquals("source1", scriptAttributes1.getScriptReference().getURL());
        final ScriptAttributes scriptAttributes2 =
            (ScriptAttributes) scriptAttributesList.get(1);
        assertEquals("charSet2", scriptAttributes2.getCharSet());
        assertEquals("javascript2", scriptAttributes2.getLanguage());
        assertEquals("source2", scriptAttributes2.getScriptReference().getURL());
        final ScriptAttributes scriptAttributes3 =
            (ScriptAttributes) scriptAttributesList.get(2);
        assertEquals("charSet3", scriptAttributes3.getCharSet());
        assertEquals("javascript3", scriptAttributes3.getLanguage());
        assertEquals("source3", scriptAttributes3.getScriptReference().getURL());

        final Element headRoot =
            ((DOMOutputBuffer) pageHead.getHead()).getRoot();
        assertEquals("DELETE_ME", ((Element) headRoot.getHead()).getName());

        final ActivatedVariablePolicyMock policyMock4 =
            new ActivatedVariablePolicyMock("ActivatedVariablePolicyMock4",
                expectations);
        policyMock4.expects.getName().returns("name4").any();
        final SelectedVariantMock selectedVariantMock4 =
            new SelectedVariantMock("SelectedVariantMock4", expectations);
        selectedVariantMock4.expects.getVariant().returns(variantMock).any();
        selectedVariantMock4.expects.getPolicy().returns(policyMock4).any();
        selectedVariantMock4.expects.getOldObject().returns(
            new ScriptAsset("name4", "deviceName4", "javascript4", "mimeType4",
                "charSet4", ScriptAsset.URL, "assetGroupName4", "value4")).any();
        assetResolverMock.expects.selectBestVariant(
            runtimePolicyReferenceMock4, null).returns(selectedVariantMock4).any();
        assetResolverMock.expects.computeURLAsString(selectedVariantMock4).
            returns("source4").any();
View Full Code Here

     */
    public boolean addScript(final ScriptAssetReference scriptReference) {
        checkClosed();
        final String name = ((DefaultComponentScriptAssetReference) scriptReference).
            getPolicyReference().getName();
        final ScriptAsset scriptAsset = scriptReference.getScriptAsset();
        final Project project = scriptAsset.getProject();
        final boolean isNew = policyKeys.add(new PolicyKey(project, name));
        if (isNew) {
            if (markerElement == null) {
                scriptReferences.add(scriptReference);
            } else {
View Full Code Here

     * @param scriptReference
     * @return the created ScriptAttributes object
     */
    private ScriptAttributes assetToAttributes(
            final ScriptAssetReference scriptReference) {
        final ScriptAsset scriptAsset = scriptReference.getScriptAsset();
        final ScriptAttributes attributes = new ScriptAttributes();
        attributes.setCharSet(scriptAsset.getCharacterSet());
        attributes.setLanguage(scriptAsset.getProgrammingLanguage());
        attributes.setType(scriptAsset.getMimeType());
        attributes.setScriptReference(scriptReference);
        return attributes;
    }
View Full Code Here

     * @param scriptReference
     * @return the created ScriptAttributes object
     */
    private static ScriptAttributes assetToAttributes(
            final ScriptAssetReference scriptReference) throws ProtocolException {
        final ScriptAsset scriptAsset = scriptReference.getScriptAsset();
        if (scriptAsset == null) {
           throw new ProtocolException(exceptionLocalizer.format(
                    "widget-missing-script-policy-variant"));
       
        final ScriptAttributes attributes = new ScriptAttributes();
        attributes.setCharSet(scriptAsset.getCharacterSet());
        attributes.setLanguage(scriptAsset.getProgrammingLanguage());
        attributes.setType(scriptAsset.getMimeType());
        attributes.setScriptReference(scriptReference);
        return attributes;
    }
View Full Code Here

        final SelectedVariantMock selectedVariantMock =
            new SelectedVariantMock("selectedVariantMock", expectations);
        selectedVariantMock.expects.getOldObject().does(new MethodAction(){
            public Object perform(MethodActionEvent event) throws Throwable {
                return new ScriptAsset("name", "deviceName",
                    "programmingLanguage", "mimeType", "characterSet",
                    ScriptAsset.URL, "assetGroupName", "value");
            }}).any();

        assetResolverMock.expects.selectBestVariant(
View Full Code Here

            }

            scriptAttributes.setType("text/javascript");
        } else {
            scriptAttributes.setScriptReference(scriptReference);
            final ScriptAsset scriptAsset = scriptReference.getScriptAsset();
            scriptAttributes.setCharSet(scriptAsset.getCharacterSet());
            scriptAttributes.setLanguage(scriptAsset.getProgrammingLanguage());
            scriptAttributes.setType(scriptAsset.getMimeType());
        }

        // Create an output buffer for the content of the script element.
        // This will enable us to grab it easily when the element ends and
        // either throw it away if the src attribute can be used or use it
View Full Code Here

            InternalDevice device) {

        // Convert the variant into an asset.
        ScriptMetaData metaData = (ScriptMetaData) variant.getMetaData();

        ScriptAsset asset = new ScriptAsset();

        setAssetIdentity(policy, asset);

        final ScriptEncoding scriptEncoding = metaData.getScriptEncoding();
        if (scriptEncoding != null) {
            asset.setProgrammingLanguage((String) ENCODING.get(scriptEncoding));
            // use the first mime type if there is any
            final Iterator iter = scriptEncoding.mimeTypes();
            if (iter.hasNext()) {
                asset.setMimeType((String) iter.next());
            }
        }
        asset.setCharacterSet(metaData.getCharacterSet());

        setValue(asset, variant);

        return asset;
    }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.assets.ScriptAsset

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.