cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh2007 <josh070...@gmail.com>
Subject Re: How to access cocoon object from javascript scriptAction?
Date Wed, 10 Oct 2007 14:48:59 GMT

Thanks Joerg, I'm almost done.

Not familiar with Java, I still need to get access to the session to store
my xml.
Using session =
manager.lookup(Packages.org.apache.cocoon.environmentSession.ROLE); I get an
error "no public instance called "ROLE".
Furthermore I use objectModel to get sitemap instance and do
objectModel.session.setAttribute(...) but I'm not sure about it's the good
way.

Here's my scriptAction, if you have time to take a look.
Thanks,

Josh


// streamToSession
/*
get xforms post from stream and store the result 
in session attribute "stream".
*/

// Step 1 — Retrieve helper "beans" from the BSF framework
request = bsf.lookupBean( "request" )
logger = bsf.lookupBean( "logger" )
actionMap = bsf.lookupBean( "actionMap" )

objectModel = bsf.lookupBean( "objectModel" )
manager = bsf.lookupBean( "manager" )

// Step 2 — Perform the action
logger.debug( "START streamToSession.js" )

// loadDocument() reads in an XML file and returns a DOM Document. 
function loadDocument(uri) {
var parser = null;
var source = null;
var resolver = null;
try {
parser =
manager.lookup(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
resolver =
manager.lookup(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
source = resolver.resolveURI(uri);
var is = new Packages.org.xml.sax.InputSource(source.getInputStream());
is.setSystemId(source.getURI());
return parser.parseDocument(is);
} finally {
if (source != null) resolver.release(source);
}
}

// ------------------------- getStreamToSession
-----------------------------------------------------------------------------------------------------------------------------

// retrieve the XML
var stream = loadDocument("cocoon:/stream");

// save stream in session
var session = objectModel.session;
objectModel.session.setAttribute("stream", stream);

//
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// Hello action always succeeds, and returns message
actionMap.put( "scriptaction-continue", "" )
actionMap.put( "message", "success!" )
logger.debug( "END streamToSession.js" )

-- 
View this message in context: http://www.nabble.com/How-to-access-cocoon-object-from-javascript-scriptAction--tf4596915.html#a13137398
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message