cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Neeme Praks" <ne...@one.lv>
Subject RE: XMLResourceBundle
Date Mon, 26 Jun 2000 16:41:24 GMT

> -----Original Message-----
> From: Niclas Hedhman [mailto:niclas@localbar.com]
> Sent: Monday, June 26, 2000 6:46 AM
> 
> Neeme Praks wrote:
> 
> > A disadvantage: no easy way to enforce that the translated 
> file contains
> > the same information as the original file. In the previous case you
> > could simply generate a DTD or XSchema from the original and check
> > against that. Then you can at least be sure that the 
> structure is the
> > same...
> 
> But you can also not add a resource without becoming 
> incompatible with an
> existing DTD version. I definite minus, IMHO.

depends on application, yep... I can have a separate DTD for each
"version" of the resource file... But this is manageable only when you
have tight control over the the things that go into the resource file...
You could, of course, write a custom application that would check the
files (with attributes as in your approach) against some definition.

> The fact is, Mike and I have privately been discussing all 
> kinds of ways
> how to handle XMLResourceBundle for better performance et cetera.
> Look out for a 'interesting' new version shortly.

looking forward to it...

meanwhile I put together a basic taglib for resource handling for my own
application. As this is one of the first taglibs that I'm writing, feel
free to make some corrections and generalize it more.

The basic idea is to have two elements: <group> and <resource>. Right
now I have the functionality that you can have structures like:

	<res:group ref="/resources/forms/contacts-search/desc">
		<res:resource ref="searchfor"/>
	</res:group>
	<res:group ref="/resources/forms/contacts-search/input">
		<res:resource ref="submit"/>
	</res:group>
	<res:group
ref="/resources/forms/contacts-search/input/field-to-search">
		<res:resource ref="email"/>
		<res:resource
ref="/resources/forms/contacts-search/desc/from"/>
	</res:group>

Note that <resource> can reference the resource relative to the root or
relative to the containing group.

I would also like to add the ability to have nested groups, but the
implementation of this was a little bit too much for me right now.
The idea is to allow this kind of contructs:

	<res:group ref="/resources/forms/contacts-search/input">
		<res:group ref="field-to-search">
			<res:resource ref="email"/><!-- XPath:
/resources/forms/contacts-search/input/field-to-search/email -->
			<res:group
ref="/resources/forms/contacts-search/desc">
				<res:resource ref="searchfor"/><!--
XPath: /resources/forms/contacts-search/desc/searchfor -->
			</res:group>
		</res:group>
		<res:resource ref="submit"/><!-- XPath:
/resources/forms/contacts-search/input/submit -->
		<res:resource
ref="/resources/forms/contacts-search/desc/from"/>
	</res:group>

And maybe also using ".." for going up one level? Something like this:

	<res:group ref="/resources/forms/contacts-search/input">
		<res:group ref="field-to-search">
			<res:group ref="../desc">
				<res:resource ref="searchfor"/><!--
XPath: /resources/forms/contacts-search/desc/searchfor -->
			</res:group>
		</res:group>
	</res:group>

If someone would like to take a challenge and implement all these
features then go ahead... I don't need it right now, so I don't want to
get a headache from this...




Here is the logicsheet:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xsp="http://www.apache.org/1999/XSP/Core"
	xmlns:res="urn:resources"
>

<xsl:template match="root">
<xsl:processing-instruction
name="cocoon-process">type="xsp"</xsl:processing-instruction>
<!--
    <xsl:processing-instruction
name="cocoon-process">type="xslt"</xsl:processing-instruction>
    <xsl:processing-instruction
name="xml-stylesheet">href="one-html-list.xsl"
type="text/xsl"</xsl:processing-instruction>
-->
<xsp:page language="java"
xmlns:xsp="http://www.apache.org/1999/XSP/Core">
	<xsp:structure>
		<xsp:include>XMLResourceBundleFactory</xsp:include>
		<xsp:include>XMLResourceBundle</xsp:include>
	</xsp:structure>
	<xsp:logic><![CDATA[
			XMLResourceBundle bundle =
XMLResourceBundleFactory.getBundle("/d:/turbine/webapps/cocoon/resource"
);
			String roleStr;
			String bundleStr;
			Node role = null;
	]]></xsp:logic>

	<xsl:copy>
		<xsl:apply-templates/>
	</xsl:copy>

</xsp:page>

</xsl:template>

  <xsl:template match="res:group">
   <xsp:logic>
			<xsl:if test="not(starts-with(@ref,'/'))">
				roleStr = "<xsl:for-each
select="ancestor-or-self::res:group">/<xsl:value-of
select="@ref"/></xsl:for-each>";
			</xsl:if>
			<xsl:if test="starts-with(@ref,'/')">
				roleStr = "<xsl:value-of
select="@ref"/>";
			</xsl:if>
			role = bundle.getRole(roleStr);
   </xsp:logic>
	<xsl:apply-templates/>
   <xsp:logic>
			roleStr = "<xsl:for-each
select="ancestor::res:group"><xsl:value-of
select="@ref"/></xsl:for-each>";
   </xsp:logic>
  </xsl:template>

  <xsl:template match="res:resource">
			<xsl:if test="starts-with(@ref,'/')">
			   <xsp:logic>
					bundleStr = "<xsl:value-of
select="@ref"/>";
				</xsp:logic>
	
<xsp:expr>bundle.getString(bundleStr)</xsp:expr>
			</xsl:if>

			<xsl:if test="not(starts-with(@ref,'/'))">
			   <xsp:logic>
					bundleStr = "<xsl:value-of
select="@ref"/>";
				</xsp:logic>
				<xsp:expr>bundle.getString(role,
bundleStr)</xsp:expr>
			</xsl:if>
  </xsl:template>

</xsl:stylesheet>


Neeme

Mime
View raw message