You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2001/11/15 12:20:42 UTC
cvs commit: xml-cocoon2/src/org/apache/cocoon/transformation SQLTransformer.java TraxTransformer.java
cziegeler 01/11/15 03:20:41
Modified: . Tag: cocoon_20_branch changes.xml
src/org/apache/cocoon/transformation Tag: cocoon_20_branch
SQLTransformer.java TraxTransformer.java
Log:
Small sync with 2.1 - and changed use of deprecated method
Revision Changes Path
No revision
No revision
1.2.2.46 +9 -1 xml-cocoon2/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/changes.xml,v
retrieving revision 1.2.2.45
retrieving revision 1.2.2.46
diff -u -r1.2.2.45 -r1.2.2.46
--- changes.xml 2001/11/09 07:19:09 1.2.2.45
+++ changes.xml 2001/11/15 11:20:40 1.2.2.46
@@ -4,7 +4,7 @@
<!--
History of Cocoon changes
- $Id: changes.xml,v 1.2.2.45 2001/11/09 07:19:09 cziegeler Exp $
+ $Id: changes.xml,v 1.2.2.46 2001/11/15 11:20:40 cziegeler Exp $
-->
<changes title="History of Changes">
@@ -27,6 +27,14 @@
</devs>
<release version="@version@" date="@date@">
+ <action dev="CZ" type="update">
+ Applied patch for session-info for TraxTransformer from Jörn Heid
+ [heid@fh-heilbronn.de].
+ </action>
+ <action dev="CZ" type="update">
+ Applied patch for the SQLTransformer to output namespaces for the
+ generated elements. Patch submitted by Per-Olof Norč¬ [pelle@alma.nu].
+ </action>
<action dev="OP" type="update">
Applied patch for incremental XSLT processing from Jörn Heid
[heid@fh-heilbronn.de].
No revision
No revision
1.5.2.15 +89 -16 xml-cocoon2/src/org/apache/cocoon/transformation/SQLTransformer.java
Index: SQLTransformer.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/SQLTransformer.java,v
retrieving revision 1.5.2.14
retrieving revision 1.5.2.15
diff -u -r1.5.2.14 -r1.5.2.15
--- SQLTransformer.java 2001/10/25 20:25:11 1.5.2.14
+++ SQLTransformer.java 2001/11/15 11:20:40 1.5.2.15
@@ -35,7 +35,7 @@
* @author <a href="mailto:giacomo.pati@pwr.ch">Giacomo Pati</a>
* (PWR Organisation & Entwicklung)
* @author <a href="mailto:sven.beauprez@the-ecorp.com">Sven Beauprez</a>
- * @version CVS $Revision: 1.5.2.14 $ $Date: 2001/10/25 20:25:11 $ $Author: bloritsch $
+ * @version CVS $Revision: 1.5.2.15 $ $Date: 2001/11/15 11:20:40 $ $Author: cziegeler $
*/
public class SQLTransformer extends AbstractTransformer implements Composable, Recyclable, Disposable, Configurable {
@@ -63,6 +63,9 @@
public static final String MAGIC_OUT_PARAMETER_NR_ATTRIBUTE = "nr";
public static final String MAGIC_OUT_PARAMETER_TYPE_ATTRIBUTE = "type";
+ public static final String MAGIC_NS_URI_ELEMENT = "namespace-uri";
+ public static final String MAGIC_NS_PREFIX_ELEMENT = "namespace-prefix";
+
public static final String MAGIC_ANCESTOR_VALUE = "ancestor-value";
public static final String MAGIC_ANCESTOR_VALUE_LEVEL_ATTRIBUTE = "level";
public static final String MAGIC_ANCESTOR_VALUE_NAME_ATTRIBUTE = "name";
@@ -106,6 +109,15 @@
/** Is the old-driver turned on? (default is off) */
private boolean oldDriver = false;
+ /** Namespace prefix to output */
+ protected String outPrefix;
+
+ /** Namespace uri to output */
+ protected String outUri;
+
+ /** The prefix of our namespace to listen to */
+ protected String inPrefix;
+
protected ComponentSelector dbSelector = null;
protected ComponentManager manager;
@@ -206,6 +218,19 @@
getLogger().debug( "ROW-ELEMENT: " + parameter );
default_properties.setProperty( SQLTransformer.MAGIC_ROW_ELEMENT, parameter );
}
+
+ // Check namespace-prefix and namespace-uri
+ parameter = parameters.getParameter( SQLTransformer.MAGIC_NS_URI_ELEMENT, null );
+ if ( parameter != null ) {
+ getLogger().debug( "NS-URI: " + parameter );
+ default_properties.setProperty( SQLTransformer.MAGIC_NS_URI_ELEMENT, parameter );
+ }
+
+ parameter = parameters.getParameter( SQLTransformer.MAGIC_NS_PREFIX_ELEMENT, null );
+ if ( parameter != null ) {
+ getLogger().debug( "NS-PREFIX: " + parameter );
+ default_properties.setProperty( SQLTransformer.MAGIC_NS_PREFIX_ELEMENT, parameter );
+ }
}
/** END SitemapComponent methods **/
@@ -216,7 +241,24 @@
* This will be the meat of SQLTransformer, where the query is run.
*/
protected void executeQuery( int index ) throws SAXException {
-// this.contentHandler.startPrefixMapping("",my_uri);
+
+
+ // First set up the namespace handling
+ if ( getCurrentQuery().properties.getProperty( SQLTransformer.MAGIC_NS_URI_ELEMENT ) != null ) {
+ outUri = getCurrentQuery().properties.getProperty( SQLTransformer.MAGIC_NS_URI_ELEMENT );
+ } else {
+ outUri = my_uri;
+ }
+
+ if ( getCurrentQuery().properties.getProperty( SQLTransformer.MAGIC_NS_PREFIX_ELEMENT ) != null ) {
+ outPrefix = getCurrentQuery().properties.getProperty( SQLTransformer.MAGIC_NS_PREFIX_ELEMENT );
+ } else {
+ outPrefix = "";
+ }
+ if ( !"".equals( outPrefix ) && !"".equals( outUri ) ) {
+ this.contentHandler.startPrefixMapping( outPrefix, outUri );
+ }
+
getLogger().debug( "SQLTransformer executing query nr " + index );
AttributesImpl attr = new AttributesImpl();
Query query = (Query) queries.elementAt( index );
@@ -224,13 +266,11 @@
query.execute();
if ( showNrOfRows != null && showNrOfRows.equalsIgnoreCase( "true" ) ) {
- attr.addAttribute( my_uri, query.nr_of_rows, query.nr_of_rows, "CDATA",
- String.valueOf( query.getNrOfRows() ) );
+ this.attribute( attr, query.nr_of_rows, String.valueOf( query.getNrOfRows() ) );
}
String name = query.getName();
if ( name != null ) {
- attr.addAttribute( my_uri, query.name_attribute, query.name_attribute, "CDATA",
- name );
+ this.attribute( attr, query.name_attribute, name );
}
this.start( query.rowset_name, attr );
attr = new AttributesImpl();
@@ -257,7 +297,9 @@
}
}
this.end( query.rowset_name );
-// this.contentHandler.endPrefixMapping("");
+ if ( !"".equals( outPrefix ) && !"".equals( outUri ) ) {
+ this.contentHandler.endPrefixMapping( outPrefix );
+ }
}
protected static void throwIllegalStateException( String message ) {
@@ -510,13 +552,45 @@
}
}
+ /**
+ Qualifies an element name by giving it a prefix.
+ @param name the element name
+ @param prefix the prefix to qualify with
+ @return a namespace qualified name that is correct
+ */
+ protected String nsQualify( String name, String prefix ) {
+ if ( name == null || "".equals( name ) ) {
+ return name;
+ }
+ if ( prefix != null && !"".equals( prefix ) ) {
+ return new StringBuffer( prefix ).append( ":" ).append( name ).toString();
+ } else {
+ return name;
+ }
+ }
+
/** END my very own methods **/
/** BEGIN SAX ContentHandler handlers **/
+ public void startPrefixMapping( String prefix, String uri ) throws SAXException {
+ if ( uri.equals( my_uri ) ) {
+ inPrefix = prefix;
+ } else {
+ super.contentHandler.startPrefixMapping( prefix, uri );
+ }
+ }
+
+ public void endPrefixMapping( String prefix ) throws SAXException {
+ if ( !prefix.equals( inPrefix ) ) {
+ super.contentHandler.endPrefixMapping( prefix );
+ }
+ }
+
+
public void setDocumentLocator( Locator locator ) {
- getLogger().info( "PUBLIC ID" + locator.getPublicId() );
- getLogger().info( "SYSTEM ID" + locator.getSystemId() );
+ getLogger().info( "PUBLIC ID: " + locator.getPublicId() );
+ getLogger().info( "SYSTEM ID: " + locator.getSystemId() );
if ( super.contentHandler != null )
super.contentHandler.setDocumentLocator( locator );
}
@@ -585,23 +659,21 @@
}
private void attribute( AttributesImpl attr, String name, String value ) {
- attr.addAttribute( "", name, name, "CDATA", value );
+ attr.addAttribute( outUri, name, nsQualify( name, outPrefix ), "CDATA", value );
}
- private void start( String name,
- AttributesImpl attr ) throws SAXException {
- super.contentHandler.startElement( my_uri, name, name, attr );
+ private void start( String name, AttributesImpl attr ) throws SAXException {
+ super.contentHandler.startElement( outUri, name, nsQualify( name, outPrefix ), attr );
attr.clear();
}
private void end( String name ) throws SAXException {
- super.contentHandler.endElement( my_uri, name, name );
+ super.contentHandler.endElement( outUri, name, nsQualify( name, outPrefix ) );
}
private void data( String data ) throws SAXException {
if ( data != null ) {
- super.contentHandler.characters( data.toCharArray(), 0,
- data.length() );
+ super.contentHandler.characters( data.toCharArray(), 0, data.length() );
}
}
@@ -823,6 +895,7 @@
if ( null != properties.getProperty( SQLTransformer.MAGIC_ROW_ELEMENT ) ) {
this.row_name = properties.getProperty( SQLTransformer.MAGIC_ROW_ELEMENT );
}
+
Enumeration enum = query_parts.elements();
StringBuffer sb = new StringBuffer();
1.15.2.20 +62 -21 xml-cocoon2/src/org/apache/cocoon/transformation/TraxTransformer.java
Index: TraxTransformer.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/TraxTransformer.java,v
retrieving revision 1.15.2.19
retrieving revision 1.15.2.20
diff -u -r1.15.2.19 -r1.15.2.20
--- TraxTransformer.java 2001/11/06 10:47:44 1.15.2.19
+++ TraxTransformer.java 2001/11/15 11:20:40 1.15.2.20
@@ -25,6 +25,7 @@
import org.apache.cocoon.caching.TimeStampCacheValidity;
import org.apache.cocoon.components.browser.Browser;
import org.apache.cocoon.components.xslt.XSLTProcessor;
+import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.Cookie;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Source;
@@ -49,6 +50,7 @@
* <map:transformer name="xslt" src="org.apache.cocoon.transformation.TraxTransformer"><br>
* <use-request-parameters>false</use-request-parameters>
* <use-browser-capabilities-db>false</use-browser-capabilities-db>
+ * <use-session-info>false</use-session-info>
* <xslt-processor-role>org.apache.cocoon.components.xslt.XSLTProcessor</xslt-processor-role>
* </map:transformer>
* </pre>
@@ -69,7 +71,16 @@
* Note that this might have issues concerning cachability of the generated output of this
* transformer.<br>
* This property is false by default.
+ * <p>
+ * The <use-session-info> configuration forces the transformer to make all
+ * of the session information available in the XSLT stylesheetas.<br>
+ * These infos are (boolean values are "true" or "false" strings: session-is-new,
+ * session-id-from-cookie, session-id-from-url, session-valid, session-id.<br>
+ * Note that this might have issues concerning cachability of the generated output of this
+ * transformer.<br>
+ * This property is false by default.
*
+ *
* The <xslt-processor> configuration allows to specify the XSLT processor that will be
* used by its role name. This allows to have several XSLT processors in the configuration
* (e.g. Xalan and Saxon) and choose one or the other depending on the needs of stylesheet
@@ -92,7 +103,7 @@
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
* @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
- * @version CVS $Id: TraxTransformer.java,v 1.15.2.19 2001/11/06 10:47:44 sylvain Exp $
+ * @version CVS $Id: TraxTransformer.java,v 1.15.2.20 2001/11/15 11:20:40 cziegeler Exp $
*/
public class TraxTransformer extends AbstractTransformer
implements Transformer, Composable, Recyclable, Configurable, Cacheable, Disposable {
@@ -114,6 +125,10 @@
private boolean useCookies = false;
private boolean _useCookies = false;
+ /** Should we info about the session availalbe in the stylesheet? (default is off) */
+ private boolean useSessionInfo = false;
+ private boolean _useSessionInfo = false;
+
private ComponentManager manager;
/** The trax TransformerHandler */
@@ -151,6 +166,12 @@
this._useBrowserCap = this.useBrowserCap;
getLogger().debug("Use browser capabilities is " + this.useBrowserCap + " for " + this);
+ child = conf.getChild("use-session-info");
+ this.useSessionInfo = child.getValueAsBoolean(false);
+ this._useSessionInfo = this.useSessionInfo;
+ getLogger().debug("Use session info is " + this.useSessionInfo + " for " + this);
+
+
child = conf.getChild("xslt-processor-role");
String xsltRole = child.getValue(XSLTProcessor.ROLE);
getLogger().debug("Use XSLTProcessor of role " + xsltRole);
@@ -194,6 +215,7 @@
_useParameters = par.getParameterAsBoolean("use-request-parameters", this.useParameters);
_useBrowserCap = par.getParameterAsBoolean("use-browser-capabilities-db", this.useBrowserCap);
_useCookies = par.getParameterAsBoolean("use-cookies", this.useCookies);
+ _useSessionInfo = par.getParameterAsBoolean("use-session-info", this.useSessionInfo);
}
/**
@@ -281,16 +303,18 @@
private HashMap getLogicSheetParameters() {
HashMap map = null;
if (par != null) {
- Iterator params = par.getParameterNames();
- while (params.hasNext()) {
- String name = (String) params.next();
- if (isValidXSLTParameterName(name)) {
- String value = par.getParameter(name,null);
- if (value != null) {
- if (map == null) {
- map = new HashMap();
+ String[] params = par.getNames();
+ if (params != null) {
+ for(int i = 0; i < params.length; i++) {
+ String name = (String) params[i];
+ if (isValidXSLTParameterName(name)) {
+ String value = par.getParameter(name,null);
+ if (value != null) {
+ if (map == null) {
+ map = new HashMap();
+ }
+ map.put(name,value);
}
- map.put(name,value);
}
}
}
@@ -300,23 +324,39 @@
/** The Request object */
Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
- if (request != null) {
- Enumeration parameters = request.getParameterNames();
- if ( parameters != null ) {
- while (parameters.hasMoreElements()) {
- String name = (String) parameters.nextElement();
- if (isValidXSLTParameterName(name)) {
- String value = request.getParameter(name);
- if (map == null) {
- map = new HashMap();
- }
- map.put(name,value);
+ Enumeration parameters = request.getParameterNames();
+ if ( parameters != null ) {
+ while (parameters.hasMoreElements()) {
+ String name = (String) parameters.nextElement();
+ if (isValidXSLTParameterName(name)) {
+ String value = request.getParameter(name);
+ if (map == null) {
+ map = new HashMap();
}
+ map.put(name,value);
}
}
}
}
+ if (this._useSessionInfo) {
+ /** The Request object */
+ Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
+ if (map == null) map = new HashMap(5);
+
+ Session session = request.getSession(false);
+ if (session != null) {
+ map.put("session-available","true");
+ map.put("session-is-new",session.isNew()?"true":"false");
+ map.put("session-id-from-cookie",request.isRequestedSessionIdFromCookie()?"true":"false");
+ map.put("session-id-from-url",request.isRequestedSessionIdFromURL()?"true":"false");
+ map.put("session-valid",request.isRequestedSessionIdValid()?"true":"false");
+ map.put("session-id",session.getId());
+ } else {
+ map.put("session-available","false");
+ }
+ }
+
if (this._useCookies) {
Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
Cookie cookies[] = request.getCookies();
@@ -436,6 +476,7 @@
this._useParameters = this.useParameters;
this._useCookies = this.useCookies;
this._useBrowserCap = this.useBrowserCap;
+ this._useSessionInfo = this.useSessionInfo;
super.recycle();
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org