cancel
Showing results for 
Search instead for 
Did you mean: 

Display asset content without <@streamasset

morphinof
Champ in-the-making
Champ in-the-making
Hi !

In a web script ftl file, i list html files collection from a section and i would like to get the html content of these files.
When i list asset properties i have following ones :

cm:content = org.alfresco.wcm.client.impl.ContentInfo@822086
cm:created = 21 avr. 2011
cm:creator = admin
cm:description = 48.86094,2.422041
cm:modified = 21 avr. 2011
cm:modifier = admin
cm:name = location1.html
cm:title = Someflu Paris
cmis:contentStreamLength = 73
cmis:contentStreamMimeType = text/html
cmis:lastModificationDate = 21 avr. 2011
cmis:name = location1.html
cmisSmiley SurprisedbjectId = workspace://SpacesStore/4a132890-73c8-48e1-83da-45a8b06e481f
cmisSmiley SurprisedbjectTypeId = ws:article
id = workspace://SpacesStore/4a132890-73c8-48e1-83da-45a8b06e481f
type = ws:article
ws:available = yes
wsSmiley TongueublishedTime = 21 avr. 2011

I assume that html content is in cm:content but i dont know how to access to ContentInfo properties.
6 REPLIES 6

bremmington
Champ on-the-rise
Champ on-the-rise
Why do you not want to use "streamasset"?

morphinof
Champ in-the-making
Champ in-the-making
Because i need to store this content into a js var that i want to give to a jQuery plugin.

bremmington
Champ on-the-rise
Champ on-the-rise
If I understand you correctly you have a Freemarker template rendering property names and values directly into JavaScript which is being sent back to the browser for execution. Presumably you need to escape each property name and value to ensure it's valid JavaScript which is why streamasset isn't appropriate.

I suggest that you write a Freemarker directive similar to AssetDirective (which is the one that is exposed with the name "streamasset") that escapes the content stream on the fly. I don't recommend that you read the content in as a String and then process it, since that will adversely affect the scalability of your webapp.

morphinof
Champ in-the-making
Champ in-the-making
Not exactly, maybe the post title is not really appropriate, in fact i was wondering how to access to html content of an html asset in a collection, and give it to js with ${}.

So far i found this in java <@streamasset implementation :

// Get the assets content stream
InputStream stream = asset.getContentAsInputStream().getStream();

I would like to access it directly (such as any asset propertie in my template ie : <#assign coords = location.properties["cm:description"]?split(",")>) and not through a directive, that's why i tried to found the right way to access it by displaying properties of an asset, is it possible ?

Here is my template :

<#if locations?? && locations.assets?size != 0>
    <script type="text/javascript">
    $("#gmap").gMap
    (
        {
            markers:
            [
                <#list locations.assets as location>
                    <#assign coords = location.properties["cm:description"]?split(",")>
                    {
                        latitude: ${coords[0]},
                        longitude: ${coords[1]},
                        html: "here i would like to put the html content of my asset"
                    },
                </#list>
            ],
            zoom: 10
        }
    );
    </script>
<#else>
    No locations !
</#if>

bremmington
Champ on-the-rise
Champ on-the-rise
There isn't any support in the WebQS API to read the content as a String. You would have to write that yourself by wrapping Asset.getContentAsInputStream with code that reads the stream into a String. I don't recommend that you do that unless you absolutely know that the content is small (and text-based).

For your specific example I would tend to do something like this:

<#if locations?? && locations.assets?size != 0>
    <script type="text/javascript">
    $("#gmap").gMap
    (
        {
            markers:
            [
                <#list locations.assets as location>
                    <#assign coords = location.properties["cm:description"]?split(",")>
                    {
                        latitude: ${coords[0]},
                        longitude: ${coords[1]},
                        html: <@streamasset asset=location />
                    },
                </#list>
            ],
            zoom: 10
        }
    );
    </script>
<#else>
    No locations !
</#if>

If you have to escape the content of the location asset then I suggest that you write a variant of the streamasset directive that escapes the content stream directly.

morphinof
Champ in-the-making
Champ in-the-making
Sounds good Smiley Happy

Is there any tutorial to create customs user-directives ?

Thanks a lot for your help !