cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jonny Pony" <jonnypony...@hotmail.com>
Subject <xsp-session-fw:setxml> - Tried to write it myself, but failed
Date Wed, 10 Nov 2004 21:03:01 GMT
Hi there,

so I tried to write the <xsp-session-fw:setxml> - Method. I failed.
Here my code so far (the complete java and xsl-files are in the 
attachement).

XSPSessionFwHelper:
…
public static void setXML(ComponentManager cm, String context, String path,
			String xml) throws ProcessingException, Exception {

		SessionManager sessionManager = null;
		Document doc = null;
		try {
			// Start looking up the manager
			sessionManager = (SessionManager) cm.lookup(SessionManager.ROLE);

			//	Create a DOM builder and parse the string
			DocumentBuilderFactory factory = DocumentBuilderFactory
					.newInstance();
			Document d = factory.newDocumentBuilder().parse(
					new InputSource(new StringReader(xml)));

			// Import the nodes of the new document into doc so that they
			// will be compatible with doc
			Node node = doc.importNode(d.getDocumentElement(), true);

			// Create the document fragment node to hold the new nodes
			DocumentFragment docfrag = doc.createDocumentFragment();

			// Move the nodes into the fragment
			while (node.hasChildNodes()) {
				docfrag.appendChild(node.removeChild(node.getFirstChild()));
			}
			sessionManager.setContextFragment(context, path, docfrag);

		} catch (ComponentException ce) {
			throw new ProcessingException(
					"Error during lookup of SessionManager component.", ce);
		} catch (Exception e) {
		} finally {
			// End releasing the sessionmanager
			cm.release((Component) sessionManager);
		}
	}


Session-fw.xsl:
     <xsl:template match="xsp-session-fw:setxml">
		<xsl:variable name="context">
			<xsl:call-template name="value-for-context"/>
		</xsl:variable>
		<xsl:variable name="path">
			<xsl:call-template name="value-for-path"/>
		</xsl:variable>
		<xsl:variable name="df">
			<xsl:call-template name="value-for-DocumentFragment"/>
		</xsl:variable>
		<xsp:logic>XSPSessionFwHelper.setXML(this.manager,
                String.valueOf(<xsl:copy-of select="$context"/>),
                String.valueOf(<xsl:copy-of select="$path"/>), 
String.valueOf(<xsl:copy-of select="df"/>))</xsp:logic>
	</xsl:template>
     …
       <xsl:template name="value-for-DocumentFragment">
		<xsl:copy-of select="."/>
	</xsl:template>

I get the following error using the setxml in a xsp:
…
Original Exception: org.apache.cocoon.components.language.LanguageException: 
Error compiling session_xsp:
ERROR 1 (org\apache\cocoon\www\samples\blocks\portal_fw\session_xsp.java):
...
      "context",
      "context",
      "CDATA",
      "authentication"

// start error (lines 409-409) "Syntax error on token ";", ")" expected"
    );

// end error

    xspAttr.addAttribute(
      "",
      "path",

...
Line 409, column 0: Syntax error on token ";", ")" expected
	at 
org.apache.cocoon.components.language.programming.java.JavaLanguage.compile(JavaLanguage.java:204)
	at 
org.apache.cocoon.components.language.programming.CompiledProgrammingLanguage.load(CompiledProgrammingLanguage.java:173)
	at 
org.apache.cocoon.components.language.generator.ProgramGeneratorImpl.loadProgram(ProgramGeneratorImpl.java:399)
	at 
org.apache.cocoon.components.language.generator.ProgramGeneratorImpl.load(ProgramGeneratorImpl.java:311)
	at 
org.apache.cocoon.generation.ServerPagesGenerator.setup(ServerPagesGenerator.java:170)
	at 
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.setupPipeline(AbstractProcessingPipeline.java:362)
	at 
org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.setupPipeline(AbstractCachingProcessingPipeline.java:646)
…


Here the session_xsp.java; the error part:
…
XSPSessionFwHelper.setXML(this.manager,
          String.valueOf(""),
          String.valueOf(""), String.valueOf(

this.contentHandler.startElement(
"http://apache.org/xsp/session-fw/1.0",
"setxml",
"xsp-session-fw:setxml",
xspAttr
); // Syntax error, insert ")" to complete Expression
xspAttr.clear();
…


this.contentHandler.endElement(
"http://apache.org/xsp/session-fw/1.0",
"setxml",
"xsp-session-fw:setxml"
);

)) // Syntax error on tokens, delete these tokens


OK. This is my first attempt. If this is some kind of right approach, yeahh. 
If not, please don’t laugh.

Could someone give me a hint, if I’m “not so wrong”.

cheers
jonny

_________________________________________________________________
Tun Sie Ihrem Rechner ’was Gutes. MSN Hotmail mit McAfee® Anti-Virus. 
http://www.msn.de/email/antivirus/ Jetzt kostenlos anmelden!

Mime
View raw message