balld 00/09/04 10:32:39
Modified: src/org/apache/cocoon/processor/xsp/library/sql esql.xsl
Added: src/org/apache/cocoon/processor/xsp/library/calendar
XSPCalendar.java calendar.xsl
src/org/apache/cocoon/processor/xsp/library/mail mail.xsl
Log:
added calendar and mail logicsheets to the library
don't know what i did to esql.xsl - i'll find out...
Revision Changes Path
1.1
xml-cocoon/src/org/apache/cocoon/processor/xsp/library/calendar/XSPCalendar.java
Index: XSPCalendar.java
===================================================================
/**
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Cocoon" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.processor.xsp.library.calendar;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.ParseException;
/*
* a class to generate xml calendar views
*
* @author Donald A. Ball Jr.
* @version 1.0
*/
public class XSPCalendar {
public static SimpleDateFormat month_number_format = new
SimpleDateFormat("M");
public static SimpleDateFormat month_name_format = new
SimpleDateFormat("MMMM");
public static SimpleDateFormat month_format = new
SimpleDateFormat("yyyy-MM");
/** Generates a calendar of the form:
<pre>
<month number="3" name="March">
<week number="1">
<day/>
<day/>
<day/>
<day/>
<day/>
<day number="1" string="01 March 2000"/>
<day number="2" string="02 March 2000"/>
</week>
<week number="2">
<day number="3"/>
<day number="4"/>
<day number="5"/>
<day number="6"/>
<day number="7"/>
<day number="8"/>
<day number="9"/>
</week>
...
</month>
</pre>
**/
public static Element generateMonth(Document document, String
date_format, Date date) {
SimpleDateFormat format = null;
if (date_format != null) {
format = new SimpleDateFormat(date_format);
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
Element month_element = document.createElement("month");
month_element.setAttribute("number",month_number_format.format(date));
month_element.setAttribute("name",month_name_format.format(date));
month_element.setAttribute("year",""+calendar.get(Calendar.YEAR));
Element week_element = document.createElement("week");
int week_number = 1;
week_element.setAttribute("number","1");
month_element.appendChild(week_element);
calendar.set(Calendar.DAY_OF_MONTH,1);
Calendar temp = (Calendar)calendar.clone();
while (temp.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
temp.add(Calendar.DATE,-1);
week_element.appendChild(document.createElement("day"));
}
temp.setTime(calendar.getTime());
while (temp.get(Calendar.MONTH) ==
calendar.get(Calendar.MONTH)) {
if (temp.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
week_number++;
week_element = document.createElement("week");
week_element.setAttribute("number",""+week_number);
month_element.appendChild(week_element);
}
Element day_element = document.createElement("day");
day_element.setAttribute("number",""+temp.get(Calendar.DAY_OF_MONTH));
day_element.setAttribute("string",""+format.format(temp.getTime()));
week_element.appendChild(day_element);
temp.add(Calendar.DATE,1);
}
while (temp.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
week_element.appendChild(document.createElement("day"));
temp.add(Calendar.DATE,1);
}
return month_element;
}
public static Element generateMonth(Document document, String
date_format, String date) throws ParseException {
return
generateMonth(document,date_format,month_format.parse(date));
}
public static Element generateMonth(Document document, String
date_format) {
return generateMonth(document,date_format,new Date());
}
}
1.1
xml-cocoon/src/org/apache/cocoon/processor/xsp/library/calendar/calendar.xsl
Index: calendar.xsl
===================================================================
<?xml version="1.0"?>
<!--
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Cocoon" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-->
<!--
<description>
This is the stylesheet to replace elements in the calendar namespace with
xml calendar views.
</description>
<author>Donald A. Ball Jr.</author>
<version>1.0</version>
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsp="http://www.apache.org/1999/XSP/Core"
xmlns:calendar="http://apache.org/cocoon/contrib/calendar/v1"
>
<xsl:template name="get-nested-content">
<xsl:param name="content"/>
<xsl:choose>
<xsl:when test="$content/*">
<xsl:apply-templates select="$content/*"/>
</xsl:when>
<xsl:otherwise>"<xsl:value-of
select="$content"/>"</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="get-nested-string">
<xsl:param name="content"/>
<xsl:choose>
<xsl:when test="$content/*">
""
<xsl:for-each select="$content/node()">
<xsl:choose>
<xsl:when test="name(.)">
+ <xsl:apply-templates
select="."/>
</xsl:when>
<xsl:otherwise>
+ "<xsl:value-of
select="translate(.,'	 ',' ')"/>"
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>"<xsl:value-of
select="$content"/>"</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="xsp:page">
<xsp:page>
<xsl:apply-templates select="@*"/>
<xsp:structure>
<xsp:include>org.apache.cocoon.contrib.calendar.XSPCalendar</xsp:include>
</xsp:structure>
<xsl:apply-templates/>
</xsp:page>
</xsl:template>
<xsl:template match="calendar:generate-month">
<xsl:variable name="date">
<xsl:call-template name="get-nested-string">
<xsl:with-param name="content" select="calendar:date"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="format">
<xsl:call-template name="get-nested-string">
<xsl:with-param name="content" select="calendar:format"/>
</xsl:call-template>
</xsl:variable>
<xsp:logic>
{
String format = String.valueOf(<xsl:copy-of select="$format"/>);
String date = String.valueOf(<xsl:copy-of select="$date"/>);
if (!"".equals(date)) {
<xsp:content>
<xsp:expr>XSPCalendar.generateMonth(document,format,date)</xsp:expr>
</xsp:content>
} else {
<xsp:content>
<xsp:expr>XSPCalendar.generateMonth(document,format)</xsp:expr>
</xsp:content>
}
}
</xsp:logic>
</xsl:template>
<xsl:template match="@*|node()" priority="-1">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
1.1
xml-cocoon/src/org/apache/cocoon/processor/xsp/library/mail/mail.xsl
Index: mail.xsl
===================================================================
<?xml version="1.0"?>
<!--
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Cocoon" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-->
<!--
<description>
This is the stylesheet to replace elements in the mail namespace with
calls to the java mail API to retrieve and display mail from a server.
</description>
<author>Donald A. Ball Jr.</author>
<version>1.0</version>
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsp="http://www.apache.org/1999/XSP/Core"
xmlns:mail="http://apache.org/cocoon/contrib/mail/v1"
version="1.0"
>
<xsl:template match="xsp:page">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsp:structure>
<xsp:include>javax.mail.Session</xsp:include>
<xsp:include>javax.mail.Store</xsp:include>
<xsp:include>javax.mail.Folder</xsp:include>
<xsp:include>javax.mail.Message</xsp:include>
<xsp:include>javax.mail.internet.MimeMessage</xsp:include>
<xsp:include>javax.mail.Address</xsp:include>
</xsp:structure>
<xsl:apply-templates/>
<xsp:logic>
void _mail_process_content(
HttpServletRequest request,
HttpServletResponse response,
Document document,
Node xspParentNode,
Node xspCurrentNode,
Stack xspNodeStack,
HttpSession session,
MimePart part) throws Exception {
if (part.isMimeType("text/plain")) {
<xsp:content><xsp:expr>(String)part.getContent()</xsp:expr></xsp:content>
} else if (part.isMimeType("message/rfc822")) {
<xsp:content><rfc822><xsp:logic>
_mail_process_content(request,response,document,xspParentNode,xspCurrentNode,xspNodeStack,session,(Part)part.getContent());
</xsp:logic></rfc822></xsp:content>
} else if (part.isMimeType("multipart/*")) {
Multipart multipart = (Multipart)part.getContent();
int count = multipart.getCount();
for (int i=0; i<count; i++) {
<xsp:content><part><xsp:logic>
_mail_process_content(request,response,document,xspParentNode,xspCurrentNode,xspNodeStack,session,multipart.getBodyPart(i));
</xsp:logic></part></xsp:content>
}
</xsp:logic>
</xsl:copy>
</xsl:template>
<xsl:template match="mail:execute-query">
<xsl:variable name="protocol">
<xsl:call-template name="get-nested-string">
<xsl:with-param name="content" select="mail:protocol"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="host">
<xsl:call-template name="get-nested-string">
<xsl:with-param name="content" select="mail:host"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="port">
<xsl:call-template name="get-nested-string">
<xsl:with-param name="content" select="mail:port"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="username">
<xsl:call-template name="get-nested-string">
<xsl:with-param name="content" select="mail:username"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="password">
<xsl:call-template name="get-nested-string">
<xsl:with-param name="content" select="mail:password"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="mbox">
<xsl:call-template name="get-nested-string">
<xsl:with-param name="content" select="mail:mbox"/>
</xsl:call-template>
</xsl:variable>
<xsp:logic>
{
Properties _mail_properties = new Properties();
Session _mail_session = Session.getDefaultInstance(_mail_properties,null);
<xsl:choose>
<xsl:when test="$protocol">
Store _mail_store = _mail_session.getStore(String.valueOf(<xsl:copy-of
select="$protocol"/>));
</xsl:when>
<xsl:otherwise>
Store _mail_store = _mail_session.getStore();
</xsl:otherwise>
</xsl:choose>
Integer _mail_port = null;
try {
_mail_port = new Integer(String.valueOf(<xsl:copy-of select="$port"/>));
} catch (Exception e) {}
_mail_store.connect(
String.valueOf(<xsl:copy-of select="$host"/>),
_mail_port == null ? -1 : _mail_port.intValue(),
String.valueOf(<xsl:copy-of select="$username"/>),
String.valueOf(<xsl:copy-of select="$password"/>));
Folder _mail_folder = _mail_store.getDefaultFolder();
_mail_folder = _mail_folder.getFolder(String.valueOf(<xsl:copy-of
select="$mbox"/>));
_mail_folder.open(Folder.READ_ONLY);
<xsl:apply-templates select="mail:results/*"/>
_mail_folder.close(false);
_mail_store.close();
}
</xsp:logic>
</xsl:template>
<xsl:template match="mail:results//mail:get-message-count">
<xsp:expr>_mail_folder.getMessageCount()</xsp:expr>
</xsl:template>
<xsl:template match="mail:results//mail:get-message">
<xsl:param name="number"><xsl:value-of select="@number"/></xsl:param>
{
MimeMessage _mail_message =
(MimeMessage)_mail_folder.getMessage(<xsl:value-of select="@number"/>);
<xsl:apply-templates/>
}
</xsl:template>
<xsl:template match="mail:results//mail:get-message//mail:get-subject">
<xsp:expr>_mail_message.getSubject()</xsp:expr>
</xsl:template>
<xsl:template match="mail:results//mail:get-message//mail:get-from">
<xsp:logic>
{
Address _mail_from[] = _mail_message.getFrom();
for (int _mail_i=0; _mail_i < _mail_from.length; _mail_i++) {
<address><xsp:expr>_mail_from[_mail_i].toString()</xsp:expr></address>
}
}
</xsp:logic>
</xsl:template>
<xsl:template match="mail:results//mail:get-message//mail:get-recipients">
<xsp:logic>
{
String _mail_type = "<xsl:value-of select="@type"/>";
RecipientType _mail_recipient_type = null;
if ("TO".equals(_mail_type)) {
_mail_recipient_Type = RecipientType.TO;
} else if ("CC".equals(_mail_type)) {
_mail_recipient_Type = RecipientType.CC;
} else if ("BCC".equals(_mail_type)) {
_mail_recipient_Type = RecipientType.BCC;
}
Address _mail_to[];
if (null == _mail_recipient_type) {
_mail_to = _mail_message.getAllRecipients();
} else {
_mail_to = _mail_message.getRecipients(_mail_recipient_type);
}
for (int _mail_i=0; _mail_i < _mail_to.length; _mail_i++) {
<address><xsp:expr>_mail_to[_mail_i].toString()</xsp:expr></address>
}
}
</xsp:logic>
</xsl:template>
<xsl:template match="mail:results//mail:get-message//get-all-headers">
<xsp:logic>
{
Enumeration _mail_enum = _mail_message.getAllHeaderLines();
while (_mail_enum.hasMoreElements()) {
<header><xsp:expr>(String)_mail_enum.nextElement()</xsp:expr></header>
}
}
</xsp:logic>
</xsl:template>
<xsl:template match="mail:results//mail:get-message//get-content">
<xsp:logic>
_mail_process_content(_mail_message);
</xsp:logic>
</xsl:template>
<!--
<xsl:template match="mail:results//mail:get-message//
<xsl:template match="mail:results//mail:get-message//
-->
<xsl:template match="@*|node()" priority="-1">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template name="get-nested-string">
<xsl:param name="content"/>
<xsl:choose>
<xsl:when test="$content/*">
""
<xsl:for-each select="$content/node()">
<xsl:choose>
<xsl:when test="name(.)">
+ <xsl:apply-templates
select="."/>
</xsl:when>
<xsl:otherwise>
+ "<xsl:value-of
select="translate(.,'	 ',' ')"/>"
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>"<xsl:value-of
select="normalize-space($content)"/>"</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
1.7 +1 -1
xml-cocoon/src/org/apache/cocoon/processor/xsp/library/sql/esql.xsl
Index: esql.xsl
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/library/sql/esql.xsl,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- esql.xsl 2000/09/01 17:39:34 1.6
+++ esql.xsl 2000/09/04 17:32:37 1.7
@@ -2,7 +2,7 @@
<!--
============================================================================
- The Apache Software License, Version 1.1
+ The Apache Software License, Version 1.2
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.