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 2004/07/30 11:46:01 UTC
svn commit: rev 30981 - in cocoon/branches/BRANCH_2_1_X: lib src/blocks/mail/java/org/apache/cocoon/mail src/blocks/mail/java/org/apache/cocoon/mail/transformation src/blocks/portal/conf src/blocks/portal/java/org/apache/cocoon/portal src/blocks/portal/java/org/apache/cocoon/portal/acting src/blocks/portal/java/org/apache/cocoon/portal/event/aspect/impl src/blocks/portal/java/org/apache/cocoon/portal/impl src/blocks/portal/java/org/apache/cocoon/portal/pluto src/blocks/portal/java/org/apache/cocoon/portal/pluto/om src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet src/blocks/portal/java/org/apache/cocoon/portal/profile/impl src/blocks/portal/java/org/apache/cocoon/portal/reading src/blocks/portal/java/org/apache/cocoon/portal/transformation src/blocks/portal/lib src/java/org/apache/cocoon/util
Author: cziegeler
Date: Fri Jul 30 02:46:00 2004
New Revision: 30981
Added:
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/Deploy.java (contents, props changed)
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/MimeType.java (contents, props changed)
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/TagDefinition.java (contents, props changed)
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/lib/pluto-20040607.jar (contents, props changed)
Removed:
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/lib/pluto-20040310.jar
Modified:
cocoon/branches/BRANCH_2_1_X/lib/jars.xml
cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailCommandBuilder.java
cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.samplesxconf
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/LinkService.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/PortalComponentManager.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/acting/CopletSetDataAction.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/event/aspect/impl/ActionCounterEventAspect.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultLinkService.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultPortalComponentManager.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/PortletApplicationDefinitionImpl.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/WebApplicationDefinitionImpl.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/LanguageSetImpl.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/PreferenceImpl.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/PreferenceSetImpl.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/portletdefinitionmapping.xml
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/servletdefinitionmapping.xml
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationProfileManager.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/reading/ProxyReader.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/ProxyTransformer.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/NetUtils.java
Log:
Merge source code from mail and portal block
Modified: cocoon/branches/BRANCH_2_1_X/lib/jars.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/lib/jars.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/lib/jars.xml Fri Jul 30 02:46:00 2004
@@ -16,7 +16,7 @@
-->
<!--+
- | CVS $Id: jars.xml,v 1.217 2004/05/18 09:23:32 unico Exp $
+ | CVS $Id$
|
| Add an entry for each jar file used by Cocoon, following the other entries.
| Please ensure that you use a version number or datestamp in the jar filename.
@@ -1106,7 +1106,7 @@
original spec.
</description>
<used-by>Portal</used-by>
- <lib>portal/lib/pluto-20040310.jar</lib>
+ <lib>portal/lib/pluto-20040607.jar</lib>
<homepage>http://jakarta.apache.org/pluto/</homepage>
</file>
<file>
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailCommandBuilder.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailCommandBuilder.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailCommandBuilder.java Fri Jul 30 02:46:00 2004
@@ -17,9 +17,9 @@
import java.util.HashMap;
import java.util.Map;
+
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.cocoon.mail.command.AbstractMailCommand;
/**
@@ -32,7 +32,7 @@
*
* @author Bernhard Huber
* @since 28. Dezember 2002
- * @version CVS $Id: MailCommandBuilder.java,v 1.4 2004/03/05 13:02:00 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class MailCommandBuilder extends AbstractLogEnabled {
@@ -66,9 +66,7 @@
if (clazz != null) {
ama = (AbstractMailCommand) clazz.newInstance();
// enable logging of the mail command
- if (ama instanceof LogEnabled) {
- ((LogEnabled) ama).enableLogging(getLogger());
- }
+ ama.enableLogging(getLogger());
// contextualize the mail command
if (ama instanceof Contextualizable) {
((Contextualizable) ama).contextualize(mailContext);
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java Fri Jul 30 02:46:00 2004
@@ -18,11 +18,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.Enumeration;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
-import java.util.Vector;
import javax.activation.DataHandler;
import javax.activation.DataSource;
@@ -39,9 +40,8 @@
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
-import org.apache.avalon.excalibur.pool.Recyclable;
-import org.apache.avalon.framework.parameters.ParameterException;
-import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
@@ -170,11 +170,11 @@
* </p>
*
* @author <a href="mailto:pklassen@s-und-n.de">Peter Klassen</a>
- * @version CVS $Id: SendMailTransformer.java,v 1.10 2004/03/06 05:09:57 joerg Exp $
+ * @version CVS $Id$
*
*/
-public class SendMailTransformer extends AbstractSAXTransformer
- implements Parameterizable, Recyclable {
+public class SendMailTransformer extends AbstractSAXTransformer {
+
/*
* constants, related to elements in configuration-file
*/
@@ -219,10 +219,11 @@
/*
* communication parameters, which will be used to send mails
*/
- protected Vector toAddresses;
- protected Vector attachments;
- protected StringBuffer subject;
- protected StringBuffer body;
+ protected List toAddresses;
+ protected List defaultToAddresses;
+ protected List attachments;
+ protected String subject;
+ protected String body;
protected String bodyURI;
protected String mailHost;
protected String fromAddress;
@@ -230,8 +231,11 @@
protected int port;
protected String contextPath;
protected boolean sendPartial;
- protected Message smtpMessage = null;
+ protected Message smtpMessage;
+ protected String defaultSmtpHost;
+ protected String defaultFromAddress;
+
/**
* create a new Transformer
*/
@@ -239,6 +243,16 @@
this.defaultNamespaceURI = NAMESPACE;
}
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void configure(Configuration configuration)
+ throws ConfigurationException {
+ super.configure(configuration);
+ this.defaultSmtpHost = configuration.getChild("smtphost").getValue("");
+ this.defaultFromAddress = configuration.getChild("from").getValue("");
+ }
+
/**
* invoked every time when the transformer is triggered by the pipeline
*/
@@ -246,147 +260,118 @@
Parameters par)
throws ProcessingException, SAXException, IOException {
super.setup(resolver, objectModel, src, par);
- this.mailHost = par.getParameter(PARAM_SMTPHOST, "");
- this.fromAddress = par.getParameter(PARAM_FROM, "");
+
+ this.mailHost = par.getParameter(PARAM_SMTPHOST, this.defaultSmtpHost);
+ this.fromAddress = par.getParameter(PARAM_FROM, this.defaultFromAddress);
this.port = this.request.getServerPort();
this.contextPath = this.request.getContextPath();
this.sendPartial = par.getParameterAsBoolean(PARAM_SENDPARTIAL, true);
- if (this.getLogger().isDebugEnabled() == true) {
+ if ( this.getLogger().isDebugEnabled() ) {
this.getLogger().debug("overwritten by Transformer-Parameters in Pipeline");
this.getLogger().debug("overwritten Parameters=" + mailHost + ":" +
fromAddress);
}
- String s = par.getParameter(PARAM_TO, "");
- this.toAddresses = new Vector();
- this.attachments = new Vector();
- this.appendToAddress(s, ";");
-
- try {
- this.subject = new StringBuffer(par.getParameter(PARAM_SUBJECT));
- } catch (ParameterException pe) {
- this.getLogger().debug("Parameter <subject> not set.");
- } try {
- this.body = new StringBuffer(par.getParameter(PARAM_BODY));
- } catch (ParameterException pe) {
- this.getLogger().debug("Parameter <body> not set.");
- }
-
- this.defaultNamespaceURI = NAMESPACE;
- }
+ this.attachments = new ArrayList();
+ this.defaultToAddresses = new ArrayList();
+ appendToAddress(this.defaultToAddresses, par.getParameter(PARAM_TO, ""));
- /**
- * invoked initially
- */
- public void parameterize(Parameters parameters) throws ParameterException {
- // nothing to do by now
- }
+ this.subject = par.getParameter(PARAM_SUBJECT, null);
+ this.body = par.getParameter(PARAM_BODY, null);
+ }
- /**
- * overwritten method of AbstractSAXTransformer
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.transformation.AbstractSAXTransformer#startTransformingElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
*/
public void startTransformingElement(String uri, String name, String raw,
Attributes attr)
throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN startElement uri=" + uri + ", name=" +
- name + ", raw=" + raw + ", attr=" + attr);
- }
-
- if (name.equals(ELEMENT_SENDMAIL) == true) {
+ if (name.equals(ELEMENT_SENDMAIL)) {
// Clean from possible previous usage
- this.toAddresses.clear();
+ this.toAddresses = new ArrayList(this.defaultToAddresses);
this.attachments.clear();
- } else if (name.equals(ELEMENT_SMTPHOST) == true) {
+ } else if (name.equals(ELEMENT_SMTPHOST)) {
this.startTextRecording();
this.mode = MODE_SMTPHOST;
- } else if (name.equals(ELEMENT_MAILFROM) == true) {
+ } else if (name.equals(ELEMENT_MAILFROM)) {
//this.fromAddress = attr.getValue(ELEMENT_MAILFROM);
this.startTextRecording();
this.mode = MODE_FROM;
- } else if (name.equals(ELEMENT_MAILTO) == true) {
+ } else if (name.equals(ELEMENT_MAILTO)) {
this.startTextRecording();
this.mode = MODE_TO;
- } else if (name.equals(ELEMENT_MAILSUBJECT) == true) {
+ } else if (name.equals(ELEMENT_MAILSUBJECT)) {
this.startTextRecording();
this.mode = MODE_SUBJECT;
- } else if (name.equals(ELEMENT_MAILBODY) == true) {
+ } else if (name.equals(ELEMENT_MAILBODY)) {
String strBody = attr.getValue("src");
if (strBody != null) {
- this.bodyURI = new String(strBody);
+ this.bodyURI = strBody;
}
this.startTextRecording();
this.mode = MODE_BODY;
- } else if (name.equals(ELEMENT_ATTACHMENT) == true) {
+ } else if (name.equals(ELEMENT_ATTACHMENT)) {
this.attachmentDescriptor = new AttachmentDescriptor(attr.getValue("name"),
attr.getValue("mime-type"),
attr.getValue("src"),
attr.getValue("url"));
this.mode = MODE_ATTACHMENT;
- } else if (name.equals(ELEMENT_ATTACHMENT_CONTENT) == true) {
+ } else if (name.equals(ELEMENT_ATTACHMENT_CONTENT)) {
this.startSerializedXMLRecording(new Properties());
this.mode = MODE_ATTACHMENT_CONTENT;
} else {
throw new SAXException("Unknown element " + name);
}
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END startElement");
- }
}
- /**
- * overwritten method of AbstractSAXTransformer
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.transformation.AbstractSAXTransformer#endTransformingElement(java.lang.String, java.lang.String, java.lang.String)
*/
public void endTransformingElement(String uri, String name, String raw)
throws SAXException, ProcessingException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN endTransformingElement uri=" + uri +
- ", name=" + name + ", raw=" + raw);
- }
-
- if (name.equals(ELEMENT_SENDMAIL) == true) {
- if (this.getLogger().isInfoEnabled() == true) {
+ if (name.equals(ELEMENT_SENDMAIL)) {
+ if (this.getLogger().isInfoEnabled()) {
this.getLogger().info("Mail contents- Subject: " +
this.subject + "\n" + "Body: " +
this.body);
}
- sendMail();
- } else if (name.equals(ELEMENT_SMTPHOST) == true) {
+ this.sendMail();
+ } else if (name.equals(ELEMENT_SMTPHOST) ) {
this.mailHost = this.endTextRecording();
this.mode = MODE_NONE;
- } else if (name.equals(ELEMENT_MAILFROM) == true) {
+ } else if (name.equals(ELEMENT_MAILFROM)) {
this.fromAddress = this.endTextRecording();
this.mode = MODE_NONE;
- } else if (name.equals(ELEMENT_MAILTO) == true) {
+ } else if (name.equals(ELEMENT_MAILTO)) {
this.toAddresses.add(this.endTextRecording());
this.mode = MODE_NONE;
- } else if (name.equals(ELEMENT_MAILSUBJECT) == true) {
+ } else if (name.equals(ELEMENT_MAILSUBJECT)) {
String strSubject = this.endTextRecording();
if (strSubject != null) {
- this.subject = new StringBuffer(strSubject);
+ this.subject = strSubject;
} else {
this.getLogger().debug("Mail-Subject not available");
}
this.mode = MODE_NONE;
- } else if (name.equals(ELEMENT_ATTACHMENT) == true) {
+ } else if (name.equals(ELEMENT_ATTACHMENT)) {
this.attachments.add(this.attachmentDescriptor.copy());
this.attachmentDescriptor = null;
this.mode = MODE_NONE;
- } else if (name.equals(ELEMENT_ATTACHMENT_CONTENT) == true) {
- this.attachmentDescriptor.setContent(new StringBuffer(this.endSerializedXMLRecording()));
+ } else if (name.equals(ELEMENT_ATTACHMENT_CONTENT)) {
+ this.attachmentDescriptor.setContent(this.endSerializedXMLRecording());
this.mode = MODE_NONE;
- } else if (name.equals(ELEMENT_MAILBODY) == true) {
+ } else if (name.equals(ELEMENT_MAILBODY)) {
String strB = null;
try {
- strB = new String(this.endTextRecording());
+ strB = this.endTextRecording();
} catch (Exception e) {
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("No Body as String in config-file available");
@@ -394,25 +379,20 @@
}
if (strB != null) {
- this.body = new StringBuffer(strB);
+ this.body = strB;
}
this.mode = MODE_NONE;
} else {
throw new SAXException("Unknown element " + name);
}
-
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END endElement");
- }
}
- private void appendToAddress(String s, String delim) {
- StringTokenizer t = null;
- t = new StringTokenizer(s.trim(), delim);
+ private static void appendToAddress(List addresses, String s) {
+ StringTokenizer t = new StringTokenizer(s.trim(), ";");
while (t.hasMoreElements()) {
- this.toAddresses.add(t.nextToken());
+ addresses.add(t.nextToken());
}
}
@@ -434,7 +414,7 @@
return;
}
- if ((this.body == null) && (this.bodyURI == null)) {
+ if (this.body == null && this.bodyURI == null) {
this.ignoreHooksCount++;
super.sendStartElementEventNS(ELEMENT_ERROR);
super.sendTextEvent("Mailbody not available - sending mail aborted");
@@ -454,14 +434,14 @@
this.ignoreHooksCount++;
super.sendStartElementEventNS(ELEMENT_RESULT);
- if (this.sendPartial == true) {
+ if (this.sendPartial) {
for (int i = 0; i < this.toAddresses.size(); i++) {
- Vector v = new Vector(1);
- v.add(this.toAddresses.elementAt(i));
- sendMail(v, trans);
+ List v = new ArrayList(1);
+ v.add(this.toAddresses.get(i));
+ this.sendMail(v, trans);
}
} else {
- sendMail(this.toAddresses, trans);
+ this.sendMail(this.toAddresses, trans);
}
trans.close();
@@ -474,15 +454,15 @@
}
/**
- * @link http://java.sun.com/products/javamail/1.3/docs/javadocs/com/sun/mail/smtp/package-summary.html
+ * @see <a href="http://java.sun.com/products/javamail/1.3/docs/javadocs/com/sun/mail/smtp/package-summary.html">Sun Javamail Javadoc</a>
* @throws Exception
*/
- private void sendMail(Vector newAddresses, Transport trans)
+ private void sendMail(List newAddresses, Transport trans)
throws Exception {
AddressHandler[] iA = new AddressHandler[newAddresses.size()];
for (int i = 0; i < newAddresses.size(); i++) {
- InternetAddress inA = new InternetAddress((String) newAddresses.elementAt(i));
+ InternetAddress inA = new InternetAddress((String) newAddresses.get(i));
iA[i] = new AddressHandler(inA);
}
@@ -533,7 +513,7 @@
//sm.setAllow8bitMIME(true);
sm.setFrom(new InternetAddress(this.fromAddress));
- sm.setSubject(this.subject.toString());
+ sm.setSubject(this.subject);
// process mail-body
BodyPart messageBodyPart = new MimeBodyPart();
@@ -549,17 +529,17 @@
String mailBody = new String(byteArr);
messageBodyPart.setContent(mailBody, "text/html");
} else {
- messageBodyPart.setContent(this.body.toString(), "text/html");
+ messageBodyPart.setContent(this.body, "text/html");
}
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// process attachments
- Enumeration enumAtt = this.attachments.elements();
+ Iterator iterAtt = this.attachments.iterator();
- while (enumAtt.hasMoreElements()) {
- AttachmentDescriptor aD = (AttachmentDescriptor) enumAtt.nextElement();
+ while (iterAtt.hasNext()) {
+ AttachmentDescriptor aD = (AttachmentDescriptor) iterAtt.next();
messageBodyPart = new MimeBodyPart();
if (!aD.isTextContent()) {
@@ -569,7 +549,7 @@
if (aD.isURLSource()) {
inputSource = resolver.resolveURI(aD.strAttrSrc);
- String iSS = new String(inputSource.getURI());
+ String iSS = inputSource.getURI();
if (iSS.startsWith("cocoon:")) {
iSS = iSS.substring(7, iSS.length());
@@ -581,7 +561,7 @@
iSS = "http://localhost:" + this.port + iSS;
}
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("cocoon-URI changed to " +
iSS);
}
@@ -598,7 +578,7 @@
messageBodyPart.setDataHandler(new DataHandler(dataSource));
}
} else {
- messageBodyPart.setContent(aD.strBufContent.toString(),
+ messageBodyPart.setContent(aD.strContent,
aD.strAttrMimeType);
}
@@ -674,6 +654,7 @@
public void recycle() {
this.toAddresses = null;
+ this.defaultToAddresses = null;
this.attachments = null;
this.subject = null;
this.body = null;
@@ -688,12 +669,12 @@
super.recycle();
}
- class AttachmentDescriptor {
- String strAttrName = null;
- String strAttrMimeType = null;
- String strAttrSrc = null;
- String strAttrFile = null;
- StringBuffer strBufContent = null;
+ static class AttachmentDescriptor {
+ String strAttrName;
+ String strAttrMimeType;
+ String strAttrSrc;
+ String strAttrFile;
+ String strContent;
protected AttachmentDescriptor(String newAttrName,
String newAttrMimeType,
@@ -704,8 +685,8 @@
this.strAttrFile = newAttrFile;
}
- protected void setContent(StringBuffer newContent) {
- strBufContent = newContent;
+ protected void setContent(String newContent) {
+ this.strContent = newContent;
}
protected AttachmentDescriptor copy() {
@@ -713,27 +694,27 @@
this.strAttrMimeType,
this.strAttrSrc,
this.strAttrFile);
- aD.setContent(this.strBufContent);
+ aD.setContent(this.strContent);
return aD;
}
protected boolean isURLSource() {
- return (this.strAttrSrc != null) ? true : false;
+ return (this.strAttrSrc != null);
}
protected boolean isFileSource() {
- return (this.strAttrFile != null) ? true : false;
+ return (this.strAttrFile != null);
}
protected boolean isTextContent() {
- return (this.strBufContent != null) ? true : false;
+ return (this.strContent != null);
}
}
- class AddressHandler {
- private InternetAddress address = null;
- private String sendMailResult = null;
+ static class AddressHandler {
+ private InternetAddress address;
+ private String sendMailResult;
protected AddressHandler(InternetAddress newAddress) {
this.address = newAddress;
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.samplesxconf
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.samplesxconf (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.samplesxconf Fri Jul 30 02:46:00 2004
@@ -170,31 +170,31 @@
role="org.apache.cocoon.portal.layout.LayoutFactory">
<layouts>
<layout name="column"
- class="org.apache.cocoon.portal.layout.impl.CompositeLayout">
+ class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl">
<renderers default="column">
<renderer name="column"/>
</renderers>
</layout>
<layout name="row"
- class="org.apache.cocoon.portal.layout.impl.CompositeLayout">
+ class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl">
<renderers default="row">
<renderer name="row"/>
</renderers>
</layout>
<layout name="tab"
- class="org.apache.cocoon.portal.layout.impl.CompositeLayout">
+ class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl">
<renderers default="tab">
<renderer name="tab"/>
</renderers>
</layout>
<layout name="rawtab"
- class="org.apache.cocoon.portal.layout.impl.CompositeLayout">
+ class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl">
<renderers default="rawtab">
<renderer name="rawtab"/>
</renderers>
</layout>
<layout name="linktab"
- class="org.apache.cocoon.portal.layout.impl.CompositeLayout" >
+ class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl" >
<renderers default="linktab">
<renderer name="linktab"/>
</renderers>
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/LinkService.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/LinkService.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/LinkService.java Fri Jul 30 02:46:00 2004
@@ -25,7 +25,7 @@
* @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
* @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
*
- * @version CVS $Id: LinkService.java,v 1.5 2004/03/05 13:02:08 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public interface LinkService extends Component {
@@ -54,12 +54,27 @@
void addEventToLink(Event event);
/**
- * Add this parameter to every link
+ * Add this parameter to every link.
+ * If the link already contains a parameter with this name,
+ * then the link will have both parameters with the same
+ * name, but different values.
* @param name The request parameter name
* @param value The value for the parameter
+ * @see #addUniqueParameterToLink(String, String)
*/
void addParameterToLink(String name, String value);
+ /**
+ * Add this parameter to every link.
+ * If the link already contains a parameter with this name,
+ * then this old parameter will be removed and replaced by
+ * the new one.
+ * @param name The request parameter name
+ * @param value The value for the parameter
+ * @see #addUniqueParameterToLink(String, String)
+ */
+ void addUniqueParameterToLink(String name, String value);
+
/**
* Get a link that simply refreshs the portal
* @return A URI
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/PortalComponentManager.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/PortalComponentManager.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/PortalComponentManager.java Fri Jul 30 02:46:00 2004
@@ -16,6 +16,7 @@
package org.apache.cocoon.portal;
import org.apache.cocoon.portal.coplet.CopletFactory;
+import org.apache.cocoon.portal.event.EventManager;
import org.apache.cocoon.portal.layout.LayoutFactory;
import org.apache.cocoon.portal.layout.renderer.Renderer;
import org.apache.cocoon.portal.profile.ProfileManager;
@@ -32,7 +33,7 @@
*
* @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
*
- * @version CVS $Id: PortalComponentManager.java,v 1.2 2004/03/05 13:02:08 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public interface PortalComponentManager {
@@ -60,4 +61,9 @@
* Get the layout factory
*/
LayoutFactory getLayoutFactory();
+
+ /**
+ * Get the event manager
+ */
+ EventManager getEventManager();
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/acting/CopletSetDataAction.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/acting/CopletSetDataAction.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/acting/CopletSetDataAction.java Fri Jul 30 02:46:00 2004
@@ -20,19 +20,22 @@
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceException;
+import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.acting.ServiceableAction;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.portal.Constants;
import org.apache.cocoon.portal.PortalService;
-import org.apache.commons.jxpath.JXPathContext;
+import org.apache.cocoon.portal.event.Event;
+import org.apache.cocoon.portal.event.Publisher;
+import org.apache.cocoon.portal.event.impl.CopletJXPathEvent;
/**
* Using this action, you can set values in a coplet
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Id: CopletSetDataAction.java,v 1.3 2004/03/15 18:18:19 cziegeler Exp $
+ * @version CVS $Id$
*/
public class CopletSetDataAction
extends ServiceableAction {
@@ -63,18 +66,21 @@
throw new ConfigurationException("copletId must be passed in the object model either directly (e.g. by using ObjectModelAction) or within the parent context.");
}
- JXPathContext jxpathContext = JXPathContext.newContext(portalService.getComponentManager().getProfileManager().getCopletInstanceData(copletId));
// now traverse parameters:
// parameter name is path
// parameter value is value
// if the value is null or empty, the value is not set!
final String[] names = parameters.getNames();
if ( names != null ) {
+ final Publisher publisher = portalService.getComponentManager().getEventManager().getPublisher();
for(int i=0; i<names.length; i++) {
final String path = names[i];
final String value = parameters.getParameter(path, null );
if ( value != null && value.trim().length() > 0 ) {
- jxpathContext.setValue(path, value);
+ final Event event = new CopletJXPathEvent(portalService.getComponentManager().getProfileManager().getCopletInstanceData(copletId),
+ path,
+ value);
+ publisher.publish(event);
}
}
}
@@ -82,7 +88,7 @@
return EMPTY_MAP;
} catch (ServiceException e) {
- throw new ConfigurationException("ComponentException ", e);
+ throw new ProcessingException("Unable to lookup component.", e);
} finally {
this.manager.release(portalService);
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/event/aspect/impl/ActionCounterEventAspect.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/event/aspect/impl/ActionCounterEventAspect.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/event/aspect/impl/ActionCounterEventAspect.java Fri Jul 30 02:46:00 2004
@@ -32,7 +32,7 @@
* @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
* @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
*
- * @version CVS $Id: ActionCounterEventAspect.java,v 1.5 2004/04/07 12:03:46 cziegeler Exp $
+ * @version CVS $Id$
*/
public class ActionCounterEventAspect
extends AbstractLogEnabled
@@ -79,7 +79,7 @@
context.invokeNext( service );
}
}
- service.getComponentManager().getLinkService().addParameterToLink( requestParameterName, String.valueOf(actionCount));
+ service.getComponentManager().getLinkService().addUniqueParameterToLink( requestParameterName, String.valueOf(actionCount));
final Response response = ObjectModelHelper.getResponse( context.getObjectModel() );
response.setHeader("Cache-Control", "no-cache");
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultLinkService.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultLinkService.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultLinkService.java Fri Jul 30 02:46:00 2004
@@ -16,6 +16,7 @@
package org.apache.cocoon.portal.impl;
import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
@@ -30,6 +31,7 @@
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.wrapper.RequestParameters;
import org.apache.cocoon.portal.LinkService;
import org.apache.cocoon.portal.event.ComparableEvent;
import org.apache.cocoon.portal.event.Event;
@@ -42,7 +44,7 @@
* @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
* @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
*
- * @version CVS $Id: DefaultLinkService.java,v 1.13 2004/04/28 13:58:16 cziegeler Exp $
+ * @version CVS $Id$
*/
public class DefaultLinkService
extends AbstractLogEnabled
@@ -247,6 +249,36 @@
info.hasParameters = true;
}
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.portal.LinkService#addUniqueParameterToLink(java.lang.String, java.lang.String)
+ */
+ public void addUniqueParameterToLink(String name, String value) {
+ final Info info = this.getInfo();
+ if ( info.hasParameters ) {
+ final int pos = info.linkBase.toString().indexOf("?");
+ final String queryString = info.linkBase.substring(pos + 1);
+ final RequestParameters params = new RequestParameters(queryString);
+ if ( params.getParameter(name) != null ) {
+ // the parameter is available, so remove it
+ info.linkBase.delete(pos, info.linkBase.length() + 1);
+ info.hasParameters = false;
+
+ Enumeration enum = params.getParameterNames();
+ while ( enum.hasMoreElements() ) {
+ final String paramName = (String)enum.nextElement();
+ if ( !paramName.equals(name) ) {
+ String[] values = params.getParameterValues(paramName);
+ for( int i = 0; i < values.length; i++ ) {
+ this.addParameterToLink(paramName, values[i]);
+ }
+ }
+ }
+ }
+ }
+ // the parameter is not available, so just add it
+ this.addParameterToLink(name, value);
+ }
+
/* (non-Javadoc)
* @see org.apache.cocoon.portal.LinkService#getRefreshLinkURI()
*/
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultPortalComponentManager.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultPortalComponentManager.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultPortalComponentManager.java Fri Jul 30 02:46:00 2004
@@ -33,6 +33,7 @@
import org.apache.cocoon.portal.LinkService;
import org.apache.cocoon.portal.PortalComponentManager;
import org.apache.cocoon.portal.coplet.CopletFactory;
+import org.apache.cocoon.portal.event.EventManager;
import org.apache.cocoon.portal.layout.LayoutFactory;
import org.apache.cocoon.portal.layout.renderer.Renderer;
import org.apache.cocoon.portal.profile.ProfileManager;
@@ -46,7 +47,7 @@
*
* @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
*
- * @version CVS $Id: DefaultPortalComponentManager.java,v 1.4 2004/03/05 13:02:13 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class DefaultPortalComponentManager
extends AbstractLogEnabled
@@ -76,6 +77,8 @@
protected LayoutFactory layoutFactory;
+ protected EventManager eventManager;
+
/* (non-Javadoc)
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
@@ -112,6 +115,20 @@
}
/* (non-Javadoc)
+ * @see org.apache.cocoon.portal.PortalComponentManager#getEventManager()
+ */
+ public EventManager getEventManager() {
+ if ( null == this.eventManager ) {
+ try {
+ this.eventManager = (EventManager)this.manager.lookup( EventManager.ROLE );
+ } catch (ServiceException e) {
+ throw new CascadingRuntimeException("Unable to lookup event manager with role " + EventManager.ROLE, e);
+ }
+ }
+ return this.eventManager;
+ }
+
+ /* (non-Javadoc)
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
@@ -134,6 +151,8 @@
this.copletFactory = null;
this.layoutFactory = null;
this.manager = null;
+ this.manager.release(this.eventManager);
+ this.eventManager = null;
}
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java Fri Jul 30 02:46:00 2004
@@ -33,7 +33,7 @@
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.components.ContextHelper;
-import org.apache.cocoon.components.persistence.RequestDataStore;
+import org.apache.cocoon.environment.Request;
import org.apache.cocoon.portal.PortalComponentManager;
import org.apache.cocoon.portal.PortalService;
@@ -44,7 +44,7 @@
* @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
* @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
*
- * @version CVS $Id: PortalServiceImpl.java,v 1.10 2004/03/05 13:02:13 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class PortalServiceImpl
extends AbstractLogEnabled
@@ -61,8 +61,6 @@
protected Map portalComponentManagers = new HashMap();
- protected RequestDataStore dataStore;
-
final protected String key = this.getClass().getName();
/* (non-Javadoc)
@@ -70,15 +68,15 @@
*/
public void service(ServiceManager serviceManager) throws ServiceException {
this.manager = serviceManager;
- this.dataStore = (RequestDataStore) this.manager.lookup(RequestDataStore.ROLE);
}
protected PortalServiceInfo getInfo() {
- PortalServiceInfo info = (PortalServiceInfo) this.dataStore.getRequestData(this.key);
+ final Request request = ContextHelper.getRequest( this.context );
+ PortalServiceInfo info = (PortalServiceInfo) request.getAttribute(this.key);
if ( info == null ) {
info = new PortalServiceInfo();
info.setup(ContextHelper.getObjectModel(this.context), this.portalComponentManagers);
- this.dataStore.setRequestData(this.key, info);
+ request.setAttribute(this.key, info);
}
return info;
}
@@ -141,11 +139,6 @@
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
- if ( this.manager != null ) {
- this.manager.release( this.dataStore );
- this.manager = null;
- this.dataStore = null;
- }
final Iterator i = this.portalComponentManagers.values().iterator();
while ( i.hasNext() ) {
ContainerUtil.dispose( i.next() );
Added: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/Deploy.java
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/Deploy.java Fri Jul 30 02:46:00 2004
@@ -0,0 +1,464 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.pluto;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Vector;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.cocoon.portal.pluto.factory.ControllerFactoryImpl;
+import org.apache.cocoon.portal.pluto.om.PortletApplicationDefinitionImpl;
+import org.apache.cocoon.portal.pluto.om.PortletDefinitionRegistryImpl;
+import org.apache.cocoon.portal.pluto.om.ServletDefinitionImpl;
+import org.apache.cocoon.portal.pluto.om.ServletMapping;
+import org.apache.cocoon.portal.pluto.om.WebApplicationDefinitionImpl;
+import org.apache.cocoon.portal.pluto.om.common.DescriptionImpl;
+import org.apache.cocoon.portal.pluto.om.common.DescriptionSetImpl;
+import org.apache.cocoon.portal.pluto.om.common.DisplayNameImpl;
+import org.apache.cocoon.portal.pluto.om.common.DisplayNameSetImpl;
+import org.apache.cocoon.portal.pluto.om.common.TagDefinition;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.apache.commons.lang.SystemUtils;
+import org.apache.pluto.om.ControllerFactory;
+import org.apache.pluto.om.common.Parameter;
+import org.apache.pluto.om.common.ParameterCtrl;
+import org.apache.pluto.om.common.ParameterSet;
+import org.apache.pluto.om.common.ParameterSetCtrl;
+import org.apache.pluto.om.common.SecurityRoleRef;
+import org.apache.pluto.om.common.SecurityRoleRefSet;
+import org.apache.pluto.om.common.SecurityRoleRefSetCtrl;
+import org.apache.pluto.om.common.SecurityRoleSet;
+import org.apache.pluto.om.portlet.PortletDefinition;
+import org.apache.pluto.om.servlet.ServletDefinition;
+import org.apache.pluto.om.servlet.ServletDefinitionCtrl;
+import org.apache.pluto.om.servlet.ServletDefinitionListCtrl;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.exolab.castor.mapping.Mapping;
+import org.exolab.castor.xml.Marshaller;
+import org.exolab.castor.xml.Unmarshaller;
+import org.xml.sax.InputSource;
+
+/**
+ * First version of a simple portlet deploy tool for the Cocoon Portal.
+ * It works very similar to the deploy tool of the Pluto project (most
+ * code is taken and improved from the Pluto tool!).
+ * The only difference is that this deploy tool does not copy the taglib
+ * definition for the portlet tags, so you have to have these in your
+ * portlet war already!
+ *
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ *
+ * @version CVS $Id: Deploy.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class Deploy {
+
+ //attributes for the web.xml creation for portlets
+ public final static String WEB_PORTLET_PUBLIC_ID = "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN";
+ public final static String WEB_PORTLET_DTD = "http://java.sun.com/dtd/web-app_2_3.dtd";
+
+ private static boolean debug = false;
+ private static final String webInfDir = File.separatorChar + "WEB-INF" + File.separatorChar;
+
+ /**
+ * Deploy the archive
+ * Unpack the archive in the servlet engine context directory
+ */
+ public static void deployArchive(final String webAppsDir,
+ final String warFile,
+ final String warFileName)
+ throws IOException {
+ System.out.println("Deploying '" + warFileName + "' ...");
+
+ final String destination = webAppsDir + warFileName;
+
+ if ( debug) {
+ System.out.println(" unpacking '" + warFile + "' ...");
+ }
+ final JarFile jarFile = new JarFile(warFile);
+ final Enumeration files = jarFile.entries();
+ while (files.hasMoreElements()) {
+ JarEntry entry = (JarEntry) files.nextElement();
+
+ File file = new File(destination, entry.getName());
+ File dirF = new File(file.getParent());
+ dirF.mkdirs();
+ if (entry.isDirectory()) {
+ file.mkdirs();
+ } else {
+ byte[] buffer = new byte[1024];
+ int length = 0;
+ InputStream fis = jarFile.getInputStream(entry);
+ FileOutputStream fos = new FileOutputStream(file);
+ while ((length = fis.read(buffer)) >= 0) {
+ fos.write(buffer, 0, length);
+ }
+ fos.close();
+ }
+
+ }
+
+ if ( debug ) {
+ System.out.println("Finished!");
+ }
+ }
+
+ /**
+ * Helper method to setup the mapping
+ */
+ private static Mapping getMapping(final String uri)
+ throws IOException {
+ final String mappingResource = uri.substring(uri.indexOf("://")+2);
+ final Mapping mapping = new Mapping();
+
+ final InputSource is = new InputSource(Deploy.class.getResourceAsStream(mappingResource));
+ try {
+ mapping.loadMapping( is );
+ } catch (Exception e) {
+ throw new IOException("Failed to load mapping file " + mappingResource);
+ }
+ return mapping;
+ }
+
+ /**
+ * Prepare the web archive of the portlet web app
+ */
+ public static void prepareWebArchive(String webAppsDir, String webModule)
+ throws Exception {
+ System.out.println("Preparing web archive '" + webModule + "' ...");
+
+ // get portlet xml mapping file
+ Mapping mappingPortletXml = getMapping(PortletDefinitionRegistryImpl.PORTLET_MAPPING);
+ // get web xml mapping file
+ Mapping mappingWebXml = getMapping(PortletDefinitionRegistryImpl.WEBXML_MAPPING);
+
+ File portletXml = new File(webAppsDir + webModule + webInfDir + "portlet.xml");
+ File webXml = new File(webAppsDir + webModule + webInfDir + "web.xml");
+
+ Unmarshaller unmarshaller = new Unmarshaller(mappingPortletXml);
+ PortletApplicationDefinitionImpl portletApp =
+ (PortletApplicationDefinitionImpl)unmarshaller.unmarshal(new FileReader(portletXml));
+
+ // refill structure with necessary information
+ Vector structure = new Vector();
+ structure.add(webModule);
+ structure.add(null);
+ structure.add(null);
+ portletApp.preBuild(structure);
+
+ if (debug) {
+ System.out.println(portletApp);
+ }
+
+ // now generate web part
+
+ WebApplicationDefinitionImpl webApp = null;
+
+ if (webXml.exists()) {
+ Unmarshaller unmarshallerWeb = new Unmarshaller(mappingWebXml);
+ unmarshallerWeb.setIgnoreExtraElements(true);
+ webApp =
+ (WebApplicationDefinitionImpl) unmarshallerWeb.unmarshal(
+ new FileReader(webXml));
+ } else {
+ webApp = new WebApplicationDefinitionImpl();
+ DisplayNameImpl dispName = new DisplayNameImpl();
+ dispName.setDisplayName(webModule);
+ dispName.setLocale(Locale.ENGLISH);
+ DisplayNameSetImpl dispSet = new DisplayNameSetImpl();
+ dispSet.add(dispName);
+ webApp.setDisplayNames(dispSet);
+ DescriptionImpl desc = new DescriptionImpl();
+ desc.setDescription("Automated generated Application Wrapper");
+ desc.setLocale(Locale.ENGLISH);
+ DescriptionSetImpl descSet = new DescriptionSetImpl();
+ descSet.add(desc);
+ webApp.setDescriptions(descSet);
+ }
+
+ ControllerFactory controllerFactory = new ControllerFactoryImpl();
+
+ ServletDefinitionListCtrl servletDefinitionSetCtrl =
+ (ServletDefinitionListCtrl) controllerFactory.get(
+ webApp.getServletDefinitionList());
+ Collection servletMappings = webApp.getServletMappings();
+
+ Iterator portlets = portletApp.getPortletDefinitionList().iterator();
+ while (portlets.hasNext()) {
+
+ PortletDefinition portlet = (PortletDefinition) portlets.next();
+
+ if ( debug ) {
+ System.out.println(" Portlet: " + portlet.getId());
+ }
+ // check if already exists
+ ServletDefinition servlet =
+ webApp.getServletDefinitionList().get(portlet.getName());
+ if (servlet != null) {
+ if (!servlet
+ .getServletClass()
+ .equals("org.apache.pluto.core.PortletServlet")) {
+ System.out.println(
+ "Note: Replaced already existing the servlet with the name '"
+ + portlet.getName()
+ + "' with the wrapper servlet.");
+ }
+ ServletDefinitionCtrl _servletCtrl =
+ (ServletDefinitionCtrl) controllerFactory.get(servlet);
+ _servletCtrl.setServletClass(
+ "org.apache.pluto.core.PortletServlet");
+ } else {
+ servlet =
+ servletDefinitionSetCtrl.add(
+ portlet.getName(),
+ "org.apache.pluto.core.PortletServlet");
+ }
+
+ ServletDefinitionCtrl servletCtrl =
+ (ServletDefinitionCtrl) controllerFactory.get(servlet);
+
+ DisplayNameImpl dispName = new DisplayNameImpl();
+ dispName.setDisplayName(portlet.getName() + " Wrapper");
+ dispName.setLocale(Locale.ENGLISH);
+ DisplayNameSetImpl dispSet = new DisplayNameSetImpl();
+ dispSet.add(dispName);
+ servletCtrl.setDisplayNames(dispSet);
+ DescriptionImpl desc = new DescriptionImpl();
+ desc.setDescription("Automated generated Portlet Wrapper");
+ desc.setLocale(Locale.ENGLISH);
+ DescriptionSetImpl descSet = new DescriptionSetImpl();
+ descSet.add(desc);
+ servletCtrl.setDescriptions(descSet);
+ ParameterSet parameters = servlet.getInitParameterSet();
+
+ ParameterSetCtrl parameterSetCtrl =
+ (ParameterSetCtrl) controllerFactory.get(parameters);
+
+ Parameter parameter1 = parameters.get("portlet-class");
+ if (parameter1 == null) {
+ parameterSetCtrl.add(
+ "portlet-class",
+ portlet.getClassName());
+ } else {
+ ParameterCtrl parameterCtrl =
+ (ParameterCtrl) controllerFactory.get(parameter1);
+ parameterCtrl.setValue(portlet.getClassName());
+
+ }
+ Parameter parameter2 = parameters.get("portlet-guid");
+ if (parameter2 == null) {
+ parameterSetCtrl.add(
+ "portlet-guid",
+ portlet.getId().toString());
+ } else {
+ ParameterCtrl parameterCtrl =
+ (ParameterCtrl) controllerFactory.get(parameter2);
+ parameterCtrl.setValue(portlet.getId().toString());
+
+ }
+
+ boolean found = false;
+ Iterator mappings = servletMappings.iterator();
+ while (mappings.hasNext()) {
+ ServletMapping servletMapping =
+ (ServletMapping) mappings.next();
+ if (servletMapping
+ .getServletName()
+ .equals(portlet.getName())) {
+ found = true;
+ servletMapping.setUrlPattern(
+ "/" + portlet.getName().replace(' ', '_') + "/*");
+ }
+ }
+ if (!found) {
+ ServletMapping servletMapping =
+ new ServletMapping();
+ servletMapping.setServletName(portlet.getName());
+ servletMapping.setUrlPattern(
+ "/" + portlet.getName().replace(' ', '_') + "/*");
+ servletMappings.add(servletMapping);
+ }
+
+ SecurityRoleRefSet servletSecurityRoleRefs =
+ ((ServletDefinitionImpl)servlet).getInitSecurityRoleRefSet();
+
+ SecurityRoleRefSetCtrl servletSecurityRoleRefSetCtrl =
+ (SecurityRoleRefSetCtrl) controllerFactory.get(
+ servletSecurityRoleRefs);
+
+ SecurityRoleSet webAppSecurityRoles = webApp.getSecurityRoles();
+
+ SecurityRoleRefSet portletSecurityRoleRefs =
+ portlet.getInitSecurityRoleRefSet();
+
+ Iterator p = portletSecurityRoleRefs.iterator();
+
+ while (p.hasNext()) {
+ SecurityRoleRef portletSecurityRoleRef =
+ (SecurityRoleRef) p.next();
+
+ if ( portletSecurityRoleRef.getRoleLink()== null
+ &&
+ webAppSecurityRoles.get(portletSecurityRoleRef.getRoleName())==null
+ ){
+ System.out.println(
+ "Note: The web application has no security role defined which matches the role name \""
+ + portletSecurityRoleRef.getRoleName()
+ + "\" of the security-role-ref element defined for the wrapper-servlet with the name '"
+ + portlet.getName()
+ + "'.");
+ break;
+ }
+ SecurityRoleRef servletSecurityRoleRef =
+ servletSecurityRoleRefs.get(
+ portletSecurityRoleRef.getRoleName());
+ if (null != servletSecurityRoleRef) {
+ System.out.println(
+ "Note: Replaced already existing element of type <security-role-ref> with value \""
+ + portletSecurityRoleRef.getRoleName()
+ + "\" for subelement of type <role-name> for the wrapper-servlet with the name '"
+ + portlet.getName()
+ + "'.");
+ servletSecurityRoleRefSetCtrl.remove(
+ servletSecurityRoleRef);
+ }
+ servletSecurityRoleRefSetCtrl.add(portletSecurityRoleRef);
+ }
+
+ }
+
+ TagDefinition portletTagLib = new TagDefinition();
+ Collection taglibs = webApp.getCastorTagDefinitions();
+ taglibs.add(portletTagLib);
+
+ if (debug) {
+ System.out.println(webApp);
+ }
+
+ OutputFormat of = new OutputFormat();
+ of.setIndenting(true);
+ of.setIndent(4); // 2-space indention
+ of.setLineWidth(16384);
+ // As large as needed to prevent linebreaks in text nodes
+ of.setDoctype(WEB_PORTLET_PUBLIC_ID, WEB_PORTLET_DTD);
+
+ FileWriter writer =
+ new FileWriter(webAppsDir + webModule +
+ SystemUtils.FILE_SEPARATOR + "WEB-INF"+
+ SystemUtils.FILE_SEPARATOR + "web.xml");
+ XMLSerializer serializer = new XMLSerializer(writer, of);
+ try {
+ Marshaller marshaller = new Marshaller(serializer.asDocumentHandler());
+ marshaller.setMapping(mappingWebXml);
+ marshaller.marshal(webApp);
+ } finally {
+ writer.close();
+ }
+
+ if ( debug ) {
+ System.out.println("Finished!");
+ }
+ }
+
+ public static void main(String args[]) {
+ String warFile;
+ String webAppsDir;
+
+ final Options options = new Options();
+
+ Option o;
+ o = new Option("w", true, "webapps directory");
+ o.setRequired(true);
+ o.setArgName("WEBAPPS_DIR");
+ options.addOption(o);
+
+ o = new Option("p", true, "web archive containing the portlet(s)");
+ o.setRequired(true);
+ o.setArgName("PORTLET_WAR");
+ options.addOption(o);
+
+ options.addOption("d", "debug", false, "Show debug messages.");
+
+ try {
+ final CommandLineParser parser = new PosixParser();
+ final CommandLine cmd = parser.parse( options, args);
+
+ // first test/turn on debug
+ debug = cmd.hasOption("d");
+ if (debug) {
+ for(int i=0; i<args.length;i++) {
+ System.out.println( "args["+ i +"]:" + args[i]);
+ }
+ }
+
+
+ webAppsDir = cmd.getOptionValue("w");
+ if (!webAppsDir.endsWith(File.separator))
+ webAppsDir += File.separatorChar;
+
+ //portalImplWebDir = cmd.getOptionValue("X");
+ //if (!portalImplWebDir.endsWith(File.separator))
+ // portalImplWebDir += File.separatorChar;
+
+ warFile = cmd.getOptionValue("p");
+ } catch( ParseException exp ) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp( "deploy", options, true );
+ System.exit(1);
+ return;
+ }
+
+ // let's do some tests on the war file name
+ String warFileName = warFile;
+ if (warFileName.indexOf("/") != -1) {
+ warFileName = warFileName.substring(warFileName.lastIndexOf("/") + 1);
+ }
+ if (warFileName.indexOf(File.separatorChar) != -1) {
+ warFileName = warFileName.substring(warFileName.lastIndexOf(File.separatorChar) + 1);
+ }
+ if (warFileName.endsWith(".war")) {
+ warFileName = warFileName.substring(0, warFileName.lastIndexOf("."));
+ }
+
+ try {
+ deployArchive(webAppsDir, warFile, warFileName);
+
+ prepareWebArchive(webAppsDir, warFileName);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ return;
+ }
+ System.exit(0);
+ }
+
+}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/PortletApplicationDefinitionImpl.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/PortletApplicationDefinitionImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/PortletApplicationDefinitionImpl.java Fri Jul 30 02:46:00 2004
@@ -32,7 +32,7 @@
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
*
- * @version CVS $Id: PortletApplicationDefinitionImpl.java,v 1.2 2004/03/05 13:02:14 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class PortletApplicationDefinitionImpl
extends AbstractSupportSet
@@ -40,8 +40,8 @@
protected String GUID;
- protected String appId = null;
- protected String version = null;
+ protected String appId;
+ protected String version;
private ArrayList customPortletMode = new ArrayList();
@@ -51,15 +51,15 @@
private PortletDefinitionListImpl portlets = new PortletDefinitionListImpl();
- private WebApplicationDefinition webApplication = null;
+ private WebApplicationDefinition webApplication;
- private ObjectID objectId = null;
+ private ObjectID objectId;
- private String contextPath = null;
+ private String contextPath;
- // PortletApplicationDefinition implementation.
-
- /** PUBLIC*/
+ /* (non-Javadoc)
+ * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getId()
+ */
public ObjectID getId() {
if ( this.objectId == null ) {
this.objectId = org.apache.cocoon.portal.pluto.om.common.ObjectIDImpl.createFromString(getGUID());
@@ -67,36 +67,45 @@
return this.objectId;
}
- /** PUBLIC*/
+ /* (non-Javadoc)
+ * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getVersion()
+ */
public String getVersion() {
return this.version;
}
- /** TODO PUBLIC*/
+ /* (non-Javadoc)
+ * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getPortletDefinitionList()
+ */
public PortletDefinitionList getPortletDefinitionList() {
return this.portlets;
}
- /** PUBLIC*/
+ /* (non-Javadoc)
+ * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getWebApplicationDefinition()
+ */
public WebApplicationDefinition getWebApplicationDefinition() {
return this.webApplication;
}
- // Support implementation.
-
- public void postLoad(Object parameter) throws Exception
- {
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.portal.pluto.om.common.Support#postLoad(java.lang.Object)
+ */
+ public void postLoad(Object parameter) throws Exception {
((Support)portlets).postLoad(parameter);
}
- public void preBuild(Object parameter) throws Exception
- {
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.portal.pluto.om.common.Support#preBuild(java.lang.Object)
+ */
+ public void preBuild(Object parameter)
+ throws Exception {
Vector structure = (Vector)parameter;
String contextRoot = (String)structure.get(0);
WebApplicationDefinition webApplication = (WebApplicationDefinition)structure.get(1);
Map servletMap = (Map)structure.get(2);
- setContextRoot(contextRoot);
+ this.setContextRoot(contextRoot);
setWebApplicationDefinition(webApplication);
@@ -108,17 +117,23 @@
}
- public void postBuild(Object parameter) throws Exception
- {
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.portal.pluto.om.common.Support#postBuild(java.lang.Object)
+ */
+ public void postBuild(Object parameter) throws Exception {
}
- public void preStore(Object parameter) throws Exception
- {
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.portal.pluto.om.common.Support#preStore(java.lang.Object)
+ */
+ public void preStore(Object parameter) throws Exception {
((Support)portlets).preStore(parameter);
}
- public void postStore(Object parameter) throws Exception
- {
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.portal.pluto.om.common.Support#postStore(java.lang.Object)
+ */
+ public void postStore(Object parameter) throws Exception {
((Support)portlets).postStore(parameter);
}
@@ -147,79 +162,70 @@
return GUID;
}
- private void setContextRoot(String contextRoot)
- {
+ private void setContextRoot(String contextRoot) {
+ // PATCH for IBM WebSphere
+ if (contextRoot != null && contextRoot.endsWith(".war") ) {
+ this.contextPath = contextRoot.substring(0, contextRoot.length()-4);
+ } else {
this.contextPath = contextRoot;
}
+ }
// additional methods.
- public String getAppId()
- {
+ public String getAppId() {
return appId;
}
- public void setAppId(String appId)
- {
+ public void setAppId(String appId) {
this.appId = appId;
}
- public void setVersion(String version)
- {
+ public void setVersion(String version) {
this.version = version;
}
// not yet fully supported:
- public Collection getCustomPortletMode()
- {
+ public Collection getCustomPortletMode() {
return customPortletMode;
}
- public void setCustomPortletMode(Collection customPortletMode)
- {
+ public void setCustomPortletMode(Collection customPortletMode) {
this.customPortletMode = (ArrayList)customPortletMode;
}
- public Collection getCustomPortletState()
- {
+ public Collection getCustomPortletState() {
return customPortletState;
}
- public void setCustomPortletState(Collection customPortletState)
- {
+ public void setCustomPortletState(Collection customPortletState) {
this.customPortletState = (ArrayList)customPortletState;
}
- public Collection getUserAttribute()
- {
+ public Collection getUserAttribute() {
return userAttribute;
}
- public void setUserAttribute(Collection userAttribute)
- {
+ public void setUserAttribute(Collection userAttribute) {
this.userAttribute = (ArrayList)userAttribute;
}
- public Collection getSecurityConstraint()
- {
+ public Collection getSecurityConstraint() {
return securityConstraint;
}
- public void setSecurityConstraint(Collection securityConstraint)
- {
+ public void setSecurityConstraint(Collection securityConstraint) {
this.securityConstraint = (ArrayList)securityConstraint;
}
// additional internal methods
- public Collection getCastorPortlets()
- {
+ public Collection getCastorPortlets() {
return portlets;
}
- protected void setWebApplicationDefinition(WebApplicationDefinition webApplication)
- {
+ protected void setWebApplicationDefinition(WebApplicationDefinition webApplication) {
this.webApplication = webApplication;
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java Fri Jul 30 02:46:00 2004
@@ -53,7 +53,7 @@
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
*
- * @version CVS $Id: PortletDefinitionRegistryImpl.java,v 1.4 2004/03/05 13:02:15 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class PortletDefinitionRegistryImpl
extends AbstractLogEnabled
@@ -145,9 +145,18 @@
}
String baseWMDir = servletContext.getRealPath("");
+ // BEGIN PATCH for IBM WebSphere
+ if (baseWMDir.endsWith(File.separator)) {
+ baseWMDir = baseWMDir.substring(0, baseWMDir.length()-1);
+ }
+ // END PATCH for IBM WebSphere
int lastIndex = baseWMDir.lastIndexOf(File.separatorChar);
this.contextName = baseWMDir.substring(lastIndex+1);
baseWMDir = baseWMDir.substring(0, lastIndex+1);
+ if ( this.getLogger().isDebugEnabled() ) {
+ this.getLogger().debug("servletContext.getRealPath('') ="+ servletContext.getRealPath(""));
+ this.getLogger().debug("baseWMDir = " + baseWMDir);
+ }
this.load(baseWMDir,mappingPortletXml, mappingWebXml);
} catch (Exception e) {
e.printStackTrace();
@@ -170,9 +179,11 @@
throws Exception {
File f = new File(baseWMDir);
String[] entries = f.list();
- for (int i=0; i<entries.length; i++)
- {
+ for (int i=0; i<entries.length; i++) {
File entry = new File(baseWMDir+entries[i]);
+ if ( this.getLogger().isDebugEnabled() ) {
+ this.getLogger().debug("Searching file: " + entry);
+ }
if (entry.isDirectory()) {
load(baseWMDir, entries[i], portletXMLMapping, webXMLMapping);
}
@@ -185,6 +196,9 @@
Mapping webXMLMapping)
throws Exception {
String directory = baseDir+webModule+File.separatorChar+"WEB-INF"+File.separatorChar;
+ if ( this.getLogger().isDebugEnabled() ) {
+ this.getLogger().debug("Searching in directory: " + directory);
+ }
File portletXml = new File(directory+"portlet.xml");
File webXml = new File(directory+"web.xml");
@@ -243,9 +257,13 @@
portletApp.preBuild(structure);
portletApp.postBuild(structure);
+
+ this.getLogger().debug("portlet.xml loaded");
}
this.registry.add( portletApp );
+
+ this.getLogger().debug("Portlet added to registry");
// fill portletsKeyObjectId
final Iterator portlets = portletApp.getPortletDefinitionList().iterator();
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/WebApplicationDefinitionImpl.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/WebApplicationDefinitionImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/WebApplicationDefinitionImpl.java Fri Jul 30 02:46:00 2004
@@ -45,12 +45,27 @@
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
*
- * @version CVS $Id: WebApplicationDefinitionImpl.java,v 1.5 2004/03/05 13:02:15 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class WebApplicationDefinitionImpl
implements WebApplicationDefinition, Support {
+ // <not used variables - only for castor>
+ public String icon;
+ public String distributable;
+ public String sessionConfig;
+ private Collection mimeMappings = new ArrayList();
+ public String welcomeFileList;
+ public String errorPage;
+ public String resourceRef;
+ public String securityConstraint;
+ public String loginConfig;
+ public String securityRole;
+ public String envEntry;
+ public String ejbRef;
+ // </not used variables - only for castor>
+
private String contextPath;
private DescriptionSet descriptions = new DescriptionSetImpl();
private DisplayNameSet displayNames = new DisplayNameSetImpl();
@@ -61,6 +76,7 @@
private Collection servletMappings = new ArrayList();
private ServletDefinitionList servlets = new ServletDefinitionListImpl();
private SecurityRoleSet securityRoles = new SecurityRoleSetImpl();
+ private Collection castorTagDefinitions = new ArrayList();
/* (non-Javadoc)
* @see org.apache.pluto.om.servlet.WebApplicationDefinition#getId()
@@ -220,8 +236,13 @@
return servletMappings;
}
- protected void setContextRoot(String contextPath) {
- this.contextPath = contextPath;
+ protected void setContextRoot(String contextRoot) {
+ // PATCH for IBM WebSphere
+ if (contextRoot != null && contextRoot.endsWith(".war") ) {
+ this.contextPath = contextRoot.substring(0, contextRoot.length()-4);
+ } else {
+ this.contextPath = contextRoot;
+ }
}
public void setDescriptions(DescriptionSet descriptions) {
@@ -240,4 +261,29 @@
this.displayNames = castorDisplayNames;
}
+ /**
+ * @return
+ */
+ public Collection getCastorTagDefinitions() {
+ return castorTagDefinitions;
+ }
+
+ /**
+ * @param definition
+ */
+ public void setCastorTagDefinitions(Collection definition) {
+ castorTagDefinitions = definition;
+ }
+ /**
+ * @return Returns the mimeMappings.
+ */
+ public Collection getMimeMappings() {
+ return mimeMappings;
+ }
+ /**
+ * @param mimeMappings The mimeMappings to set.
+ */
+ public void setMimeMappings(Collection mimeMappings) {
+ this.mimeMappings = mimeMappings;
+ }
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/LanguageSetImpl.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/LanguageSetImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/LanguageSetImpl.java Fri Jul 30 02:46:00 2004
@@ -31,7 +31,7 @@
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
*
- * @version CVS $Id: LanguageSetImpl.java,v 1.3 2004/03/05 13:02:15 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class LanguageSetImpl extends AbstractSupportSet implements LanguageSet, java.io.Serializable, Support
{
@@ -61,7 +61,7 @@
{
LanguageImpl lang = new LanguageImpl(locale, bundle, title, shortTitle, castorKeywords);
- return(Language)lang;
+ return lang;
}
/* never used
Added: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/MimeType.java
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/MimeType.java Fri Jul 30 02:46:00 2004
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.pluto.om.common;
+
+/**
+ *
+ *
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ *
+ * @version CVS $Id: MimeType.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class MimeType {
+
+ private String extension;
+ private String mimeType;
+
+ /**
+ * @return Returns the extension.
+ */
+ public String getExtension() {
+ return extension;
+ }
+ /**
+ * @param extension The extension to set.
+ */
+ public void setExtension(String extension) {
+ this.extension = extension;
+ }
+ /**
+ * @return Returns the mimeType.
+ */
+ public String getMimeType() {
+ return mimeType;
+ }
+ /**
+ * @param mimeType The mimeType to set.
+ */
+ public void setMimeType(String mimeType) {
+ this.mimeType = mimeType;
+ }
+}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/PreferenceImpl.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/PreferenceImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/PreferenceImpl.java Fri Jul 30 02:46:00 2004
@@ -29,7 +29,7 @@
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
*
- * @version CVS $Id: PreferenceImpl.java,v 1.3 2004/03/05 13:02:15 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class PreferenceImpl implements Preference, PreferenceCtrl, java.io.Serializable {
private final static String NULL_VALUE = "#*!0_NULL_0!*#";
@@ -89,7 +89,7 @@
this.name = name;
}
- public void setValues(Collection _value)
+ public void setValues(java.util.List _value)
{
if (this.value == null) {
this.value = new ArrayList();
@@ -149,7 +149,7 @@
value.addAll(_value);
}
- protected Collection getClonedCastorValuesAsCollection()
+ protected List getClonedCastorValuesAsList()
{
List returnValue = new ArrayList(value.size());
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/PreferenceSetImpl.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/PreferenceSetImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/PreferenceSetImpl.java Fri Jul 30 02:46:00 2004
@@ -18,6 +18,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import javax.portlet.PreferencesValidator;
@@ -31,7 +32,7 @@
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
*
- * @version CVS $Id: PreferenceSetImpl.java,v 1.2 2004/03/05 13:02:15 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class PreferenceSetImpl extends HashSet
implements PreferenceSet, PreferenceSetCtrl, java.io.Serializable {
@@ -73,7 +74,7 @@
// PreferenceSetCtrl implementation.
- public Preference add(String name, Collection values)
+ public Preference add(String name, List values)
{
PreferenceImpl preference = new PreferenceImpl();
preference.setName(name);
@@ -153,7 +154,7 @@
Iterator it = c.iterator();
while (it.hasNext()) {
PreferenceImpl pref = (PreferenceImpl) it.next();
- this.add(pref.getName(), pref.getClonedCastorValuesAsCollection());
+ this.add(pref.getName(), pref.getClonedCastorValuesAsList());
}
return true; //always assume something changed
Added: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/TagDefinition.java
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/TagDefinition.java Fri Jul 30 02:46:00 2004
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2004,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.pluto.om.common;
+
+/**
+ *
+ *
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ *
+ * @version CVS $Id: TagDefinition.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class TagDefinition {
+
+ private String uri ="http://java.sun.com/portlet";
+ private String location = "/WEB-INF/tld/portlet.tld";
+
+ /**
+ * @return
+ */
+ public String getLocation() {
+ return this.location;
+ }
+
+ /**
+ * @return
+ */
+ public String getUri() {
+ return this.uri;
+ }
+
+ /**
+ * @param string
+ */
+ public void setLocation(String string) {
+ this.location = string;
+ }
+
+ /**
+ * @param string
+ */
+ public void setUri(String string) {
+ this.uri = string;
+ }
+
+}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/portletdefinitionmapping.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/portletdefinitionmapping.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/portletdefinitionmapping.xml Fri Jul 30 02:46:00 2004
@@ -1,4 +1,6 @@
<?xml version="1.0"?>
+<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
+ "http://castor.exolab.org/mapping.dtd">
<!--
Copyright 1999-2004 The Apache Software Foundation
@@ -14,8 +16,6 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
- "http://castor.exolab.org/mapping.dtd">
<mapping xmlns:portlet="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<class name="org.apache.cocoon.portal.pluto.om.common.DisplayNameImpl">
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/servletdefinitionmapping.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/servletdefinitionmapping.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/servletdefinitionmapping.xml Fri Jul 30 02:46:00 2004
@@ -1,4 +1,6 @@
<?xml version="1.0"?>
+<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
+ "http://castor.exolab.org/mapping.dtd">
<!--
Copyright 1999-2004 The Apache Software Foundation
@@ -14,8 +16,6 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
- "http://castor.exolab.org/mapping.dtd">
<mapping>
<class name="org.apache.cocoon.portal.pluto.om.common.DisplayNameImpl">
@@ -28,6 +28,30 @@
</field>
</class>
+ <class name="org.apache.cocoon.portal.pluto.om.common.TagDefinition">
+
+ <field name="uri" type="java.lang.String" required="true">
+ <bind-xml name="taglib-uri" node="element"/>
+ </field>
+
+ <field name="location" type="java.lang.String" required="true">
+ <bind-xml name="taglib-location" node="element"/>
+ </field>
+
+ </class>
+
+ <class name="org.apache.cocoon.portal.pluto.om.common.MimeType">
+
+ <field name="extension" type="java.lang.String" required="true">
+ <bind-xml name="extension" node="element"/>
+ </field>
+
+ <field name="mimeType" type="java.lang.String" required="true">
+ <bind-xml name="mime-type" node="element"/>
+ </field>
+
+ </class>
+
<class name="org.apache.cocoon.portal.pluto.om.common.DescriptionImpl">
<field name="description" type="java.lang.String">
@@ -176,6 +200,49 @@
required="true">
<bind-xml name="servlet-mapping" node="element"/>
</field>
+
+ <field name="castorTagDefinitions"
+ type="org.apache.cocoon.portal.pluto.om.common.TagDefinition"
+ collection="collection">
+ <bind-xml name="taglib" node="element" />
+ </field>
+
+ <!-- only for completion, not used in class file -->
+ <field name="icon" transient="true" direct="true">
+ <bind-xml name="icon" node="element"/>
+ </field>
+ <field name="distributable" transient="true" direct="true">
+ <bind-xml name="distributable" node="element"/>
+ </field>
+ <field name="sessionConfig" transient="true" direct="true">
+ <bind-xml name="session-config" node="element"/>
+ </field>
+ <field name="mimeMappings"
+ transient="true"
+ required="false"
+ type="org.apache.cocoon.portal.pluto.om.common.MimeType"
+ collection="collection">
+ <bind-xml name="mime-mapping" node="element"/>
+ </field>
+ <field name="welcomeFileList" transient="true" direct="true">
+ <bind-xml name="welcome-file-list" node="element"/>
+ </field>
+ <field name="errorPage" transient="true" direct="true">
+ <bind-xml name="error-page" node="element"/>
+ </field>
+
+ <field name="resourceRef" transient="true" direct="true">
+ <bind-xml name="resource-ref" node="element"/>
+ </field>
+ <field name="securityConstraint" transient="true" direct="true">
+ <bind-xml name="security-constraint" node="element"/>
+ </field>
+ <field name="loginConfig" transient="true" direct="true">
+ <bind-xml name="login-config" node="element"/>
+ </field>
+ <!--field name="securityRole" transient="false" direct="true">
+ <bind-xml name="security-role" node="element"/>
+ </field-->
<field name="securityRoles"
transient="false"
type="org.apache.cocoon.portal.pluto.om.common.SecurityRoleImpl"
@@ -183,6 +250,12 @@
collection="collection">
<bind-xml name="security-role" node="element"/>
</field>
+ <field name="envEntry" transient="true" direct="true">
+ <bind-xml name="env-entry" node="element"/>
+ </field>
+ <field name="ejbRef" transient="true" direct="true">
+ <bind-xml name="ejb-ref" node="element"/>
+ </field>
</class>
-</mapping>
\ No newline at end of file
+</mapping>
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java Fri Jul 30 02:46:00 2004
@@ -483,7 +483,7 @@
*
* @see javax.servlet.ServletRequest#getContentType()
*/
- public java.lang.String getContentType() {
+ public String getContentType() {
String contentType = "text/html";
if (getCharacterEncoding() != null) {
contentType += ";" + getCharacterEncoding();
@@ -580,4 +580,4 @@
public String[] getParameterValues(String name) {
return (String[]) this.getParameterMap().get(name);
}
-}
\ No newline at end of file
+}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationProfileManager.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationProfileManager.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationProfileManager.java Fri Jul 30 02:46:00 2004
@@ -50,7 +50,7 @@
* @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
* @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
*
- * @version CVS $Id: AuthenticationProfileManager.java,v 1.19 2004/03/19 14:21:06 cziegeler Exp $
+ * @version CVS $Id$
*/
public class AuthenticationProfileManager
extends AbstractUserProfileManager {
@@ -306,8 +306,9 @@
Object result = this.checkValidity(key, parameters, forcedLoad, adapter);
- if (!(result instanceof SourceValidity))
+ if ( result != null && !(result instanceof SourceValidity)) {
return new Object[]{result, Boolean.FALSE};
+ }
SourceValidity newValidity = (SourceValidity)result;
this.lock.releaseReadLock();
@@ -316,8 +317,9 @@
// check validity again in case of another thread has already loaded
result = this.checkValidity(key, parameters, forcedLoad, adapter);
- if (!(result instanceof SourceValidity))
+ if ( result != null && !(result instanceof SourceValidity) ) {
return new Object[]{result, Boolean.FALSE};
+ }
newValidity = (SourceValidity)result;
Object object = adapter.loadProfile(key, parameters);
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/reading/ProxyReader.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/reading/ProxyReader.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/reading/ProxyReader.java Fri Jul 30 02:46:00 2004
@@ -19,7 +19,6 @@
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
-import java.net.URLEncoder;
import java.util.Enumeration;
import java.util.Map;
@@ -32,6 +31,7 @@
import org.apache.cocoon.portal.coplet.CopletInstanceData;
import org.apache.cocoon.portal.transformation.ProxyTransformer;
import org.apache.cocoon.reading.ServiceableReader;
+import org.apache.cocoon.util.NetUtils;
import org.xml.sax.SAXException;
/**
@@ -45,7 +45,7 @@
* @author <a href="mailto:gernot.koller@rizit.at">Gernot Koller</a>
* @author <a href="mailto:friedrich.klenner@rzb.at">Friedrich Klenner</a>
*
- * @version CVS $Id: ProxyReader.java,v 1.6 2004/03/19 14:21:06 cziegeler Exp $
+ * @version CVS $Id$
*/
public class ProxyReader extends ServiceableReader {
@@ -177,9 +177,9 @@
query.append('&');
}
- query.append(URLEncoder.encode(paramName));
+ query.append(NetUtils.encode(paramName, "utf-8"));
query.append('=');
- query.append(URLEncoder.encode(paramValues[i]));
+ query.append(NetUtils.encode(paramValues[i], "utf-8"));
}
}
@@ -228,4 +228,4 @@
}
}
-}
\ No newline at end of file
+}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java Fri Jul 30 02:46:00 2004
@@ -38,7 +38,7 @@
* TODO: Support target attribute
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Id: HTMLEventLinkTransformer.java,v 1.12 2004/05/06 11:03:44 cziegeler Exp $
+ * @version CVS $Id$
*/
public class HTMLEventLinkTransformer
extends AbstractCopletTransformer {
@@ -72,7 +72,7 @@
boolean convert = false;
final boolean isRemoteAnchor = this.isRemoteAnchor(attr);
if ( isRemoteAnchor ) {
- convert = this.isExternalLink(attr);
+ convert = !this.isExternalLink(attr);
}
this.stack.push(convert ? Boolean.TRUE: Boolean.FALSE);
if ( convert ) {
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/ProxyTransformer.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/ProxyTransformer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/ProxyTransformer.java Fri Jul 30 02:46:00 2004
@@ -23,7 +23,6 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
-import java.net.URLEncoder;
import java.util.Enumeration;
import java.util.Map;
@@ -43,6 +42,7 @@
import org.apache.cocoon.portal.coplet.CopletInstanceData;
import org.apache.cocoon.portal.profile.ProfileManager;
import org.apache.cocoon.transformation.AbstractTransformer;
+import org.apache.cocoon.util.NetUtils;
import org.apache.cocoon.xml.XMLUtils;
import org.apache.cocoon.xml.dom.DOMStreamer;
import org.w3c.dom.Document;
@@ -62,7 +62,7 @@
* @author <a href="mailto:friedrich.klenner@rzb.at">Friedrich Klenner</a>
* @author <a href="mailto:gernot.koller@rizit.at">Gernot Koller</a>
*
- * @version CVS $Id: ProxyTransformer.java,v 1.10 2004/03/20 17:02:46 cziegeler Exp $
+ * @version CVS $Id$
*/
public class ProxyTransformer
extends AbstractTransformer
@@ -263,9 +263,9 @@
query.append('&');
}
- query.append(URLEncoder.encode(paramName));
+ query.append(NetUtils.encode(paramName, "utf-8"));
query.append('=');
- query.append(URLEncoder.encode(paramValues[i]));
+ query.append(NetUtils.encode(paramValues[i], "utf-8"));
}
}
}
@@ -651,4 +651,4 @@
}
}
-}
\ No newline at end of file
+}
Added: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/lib/pluto-20040607.jar
==============================================================================
Binary file. No diff available.
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/NetUtils.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/NetUtils.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/NetUtils.java Fri Jul 30 02:46:00 2004
@@ -19,6 +19,10 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
import java.util.BitSet;
import java.util.Enumeration;
import java.util.Iterator;
@@ -28,6 +32,7 @@
import org.apache.cocoon.environment.Request;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.SystemUtils;
import org.apache.excalibur.source.SourceParameters;
/**
@@ -35,9 +40,8 @@
* utility methods
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version CVS $Id: NetUtils.java,v 1.15 2004/05/01 17:04:10 ugo Exp $
+ * @version CVS $Id$
*/
-
public class NetUtils {
/**
@@ -45,7 +49,6 @@
*/
private static BitSet safeCharacters;
-
private static final char[] hexadecimal =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
@@ -117,12 +120,14 @@
byte x = (byte)Integer.parseInt(path.substring(i + 1, i + 3), 16);
encodedchars[encodedcharsLength] = x;
} catch (NumberFormatException e) {
- throw new IllegalArgumentException("NetUtils.decodePath: illegal hex characters in pattern %" + path.substring(i + 1, i + 3));
+ throw new IllegalArgumentException("NetUtils.decodePath: " +
+ "Illegal hex characters in pattern %" + path.substring(i + 1, i + 3));
}
encodedcharsLength++;
i += 3;
} else {
- throw new IllegalArgumentException("NetUtils.decodePath: % character should be followed by 2 hexadecimal characters.");
+ throw new IllegalArgumentException("NetUtils.decodePath: " +
+ "% character should be followed by 2 hexadecimal characters.");
}
}
try {
@@ -476,8 +481,67 @@
public static String removeAuthorisation(String uri) {
if (uri.indexOf("@")!=-1 && (uri.startsWith("ftp://") || uri.startsWith("http://"))) {
return uri.substring(0, uri.indexOf(":")+2)+uri.substring(uri.indexOf("@")+1);
+ }
+ return uri;
+ }
+
+ // FIXME Remove when JDK1.3 support is removed.
+ private static Method urlEncode;
+ private static Method urlDecode;
+
+ static {
+ if (SystemUtils.isJavaVersionAtLeast(140)) {
+ try {
+ urlEncode = URLEncoder.class.getMethod("encode", new Class[]{String.class, String.class});
+ urlDecode = URLDecoder.class.getMethod("decode", new Class[]{String.class, String.class});
+ } catch (NoSuchMethodException e) {
+ // EMPTY
+ }
+ } else {
+ urlEncode = null;
+ urlDecode = null;
+ }
}
- return uri;
+ /**
+ * Pass through to the {@link java.net.URLEncoder}. If running under JDK < 1.4,
+ * default encoding will always be used.
+ */
+ public static String encode(String s, String enc) throws UnsupportedEncodingException {
+ if (urlEncode != null) {
+ try {
+ return (String)urlEncode.invoke(s, new Object[]{ s, enc } );
+ } catch (IllegalAccessException e) {
+ // EMPTY
+ } catch (InvocationTargetException e) {
+ if (e.getTargetException() instanceof UnsupportedEncodingException) {
+ throw (UnsupportedEncodingException)e.getTargetException();
+ } else if (e.getTargetException() instanceof RuntimeException) {
+ throw (RuntimeException)e.getTargetException();
+ }
+ }
+ }
+ return URLEncoder.encode(s);
+ }
+
+ /**
+ * Pass through to the {@link java.net.URLDecoder}. If running under JDK < 1.4,
+ * default encoding will always be used.
+ */
+ public static String decode(String s, String enc) throws UnsupportedEncodingException {
+ if (urlDecode != null) {
+ try {
+ return (String)urlDecode.invoke(s, new Object[]{ s, enc } );
+ } catch (IllegalAccessException e) {
+ // EMPTY
+ } catch (InvocationTargetException e) {
+ if (e.getTargetException() instanceof UnsupportedEncodingException) {
+ throw (UnsupportedEncodingException)e.getTargetException();
+ } else if (e.getTargetException() instanceof RuntimeException) {
+ throw (RuntimeException)e.getTargetException();
+ }
+ }
+ }
+ return URLDecoder.decode(s);
}
}