You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by st...@locus.apache.org on 2000/10/02 13:07:34 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon/util MIMEUtils.java NetUtils.java IOUtils.java
stefano 00/10/02 04:07:34
Modified: src/org/apache/cocoon Tag: xml-cocoon2 Constants.java
Main.java
src/org/apache/cocoon/components/language/markup Tag:
xml-cocoon2 AbstractMarkupLanguage.java
src/org/apache/cocoon/components/language/markup/sitemap/java
Tag: xml-cocoon2 sitemap.xsl
src/org/apache/cocoon/environment/commandline Tag:
xml-cocoon2 FileSavingEnvironment.java
LinkSamplingEnvironment.java
src/org/apache/cocoon/environment/http Tag: xml-cocoon2
HttpEnvironment.java
src/org/apache/cocoon/matching Tag: xml-cocoon2
RegexpURIMatcherFactory.java
WildcardURIMatcherFactory.java
src/org/apache/cocoon/util Tag: xml-cocoon2 IOUtils.java
Added: src/org/apache/cocoon/environment/commandline Tag:
xml-cocoon2 CommandLineRequest.java
CommandLineResponse.java
src/org/apache/cocoon/util Tag: xml-cocoon2 MIMEUtils.java
NetUtils.java
Log:
finally a fully working CLI :)
Revision Changes Path
No revision
No revision
1.1.2.7 +6 -5 xml-cocoon/src/org/apache/cocoon/Attic/Constants.java
Index: Constants.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Constants.java,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- Constants.java 2000/09/29 01:02:51 1.1.2.6
+++ Constants.java 2000/10/02 11:07:25 1.1.2.7
@@ -10,15 +10,16 @@
/**
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/09/29 01:02:51 $
+ * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/10/02 11:07:25 $
*/
public interface Constants {
- public static final String NAME = "@name@";
- public static final String VERSION = "@version@";
- public static final String CONF_VERSION = "2.0";
- public static final String YEAR = "@year@";
+ public static final String NAME = "@name@";
+ public static final String VERSION = "@version@";
+ public static final String COMPLETE_NAME = NAME + " " + VERSION;
+ public static final String CONF_VERSION = "2.0";
+ public static final String YEAR = "@year@";
public static final String RELOAD_PARAM = "cocoon-reload";
public static final String SHOWTIME_PARAM = "cocoon-showtime";
1.1.4.11 +44 -110 xml-cocoon/src/org/apache/cocoon/Attic/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Main.java,v
retrieving revision 1.1.4.10
retrieving revision 1.1.4.11
diff -u -r1.1.4.10 -r1.1.4.11
--- Main.java 2000/10/01 00:21:30 1.1.4.10
+++ Main.java 2000/10/02 11:07:26 1.1.4.11
@@ -23,6 +23,8 @@
import java.util.HashMap;
import org.apache.cocoon.util.IOUtils;
+import org.apache.cocoon.util.NetUtils;
+import org.apache.cocoon.util.MIMEUtils;
import org.apache.cocoon.util.JavaArchiveFilter;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.commandline.LinkSamplingEnvironment;
@@ -33,7 +35,7 @@
* Command line entry point.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.1.4.10 $ $Date: 2000/10/01 00:21:30 $
+ * @version CVS $Revision: 1.1.4.11 $ $Date: 2000/10/02 11:07:26 $
*/
public class Main {
@@ -200,6 +202,8 @@
private Cocoon cocoon;
private File destDir;
private File context;
+ private Map attributes;
+ private Map parameters;
/**
* Creates the Main class
@@ -208,13 +212,15 @@
this.cocoon = cocoon;
this.context = context;
this.destDir = destDir;
+ this.attributes = new HashMap();
+ this.parameters = new HashMap();
}
/**
* Warms up the engine by accessing the root.
*/
public void warmup() throws Exception {
- cocoon.process(new LinkSamplingEnvironment("/", context));
+ cocoon.process(new LinkSamplingEnvironment("/", context, attributes, parameters));
}
/**
@@ -249,52 +255,61 @@
public String processURI(String uri, String origUri, int level) throws Exception {
log(leaf(level) + uri);
- Collection links = getLinks(uri);
+ Collection links = this.getLinks(uri);
Map translatedLinks = new HashMap(links.size());
Iterator i = links.iterator();
while (i.hasNext()) {
log(tree(level));
String origLink = (String) i.next();
- String link = adjustContext(uri, origLink);
- translatedLinks.put(link, processURI(link, origLink, level + 1));
+ String link = NetUtils.normalizeURI(NetUtils.adjustContext(uri, origLink));
+ translatedLinks.put(link, this.processURI(link, origLink, level + 1));
}
- File outputFile = getFile(uri);
- String outputName = outputFile.getPath();
- FileOutputStream output = new FileOutputStream(outputFile);
+ String filename = mangle(uri);
+ File file = IOUtils.createFile(destDir, filename);
+ FileOutputStream output = new FileOutputStream(file);
String type = getPage(uri, translatedLinks, output);
output.close();
- String ext = getExtension(uri);
- String defaultExt = getDefaultExtension(type);
+ String ext = NetUtils.getExtension(uri);
+ String defaultExt = MIMEUtils.getDefaultExtension(type);
- if (!ext.equals(defaultExt)) {
- File newFile = getFile(uri + "." + defaultExt);
- outputFile.renameTo(newFile);
- outputName = outputFile.getPath();
- origUri += "." + defaultExt;
+ if ((ext == null) || (!ext.equals(defaultExt))) {
+ filename += defaultExt;
+ origUri += defaultExt;
+ File newFile = IOUtils.createFile(destDir, filename);
+ file.renameTo(newFile);
}
log(tree(level));
if (type == null) {
- log(leaf(level + 1) + "[broken link]--> " + outputName);
- PrintStream out = new PrintStream(new FileOutputStream(outputFile));
- out.println(
- "<html><head><title>Page Not Available</title></head>" +
- "<body><h1 align=\"center\">Page Not Available</h1>" +
- "<body><p align=\"center\">Generated by " +
- Cocoon.NAME + " " + Cocoon.VERSION +
- "</p></body></html>"
- );
- out.close();
+ log(leaf(level + 1) + "[broken link]--> " + filename);
+ resourceUnavailable(file);
} else {
- log(leaf(level + 1) + "[" + type + "]--> " + outputName);
+ log(leaf(level + 1) + "[" + type + "]--> " + filename);
}
- return origUri;
+ return mangle(origUri);
}
+ void resourceUnavailable(File file) throws IOException {
+ PrintStream out = new PrintStream(new FileOutputStream(file));
+ out.println(
+ "<html><head><title>Page Not Available</title></head>" +
+ "<body><h1 align=\"center\">Page Not Available</h1>" +
+ "<body><p align=\"center\">Generated by " +
+ Cocoon.COMPLETE_NAME +
+ "</p></body></html>"
+ );
+ out.close();
+ }
+
+ String mangle(String uri) {
+ uri = uri.replace('"', '\'');
+ return uri.replace('?','_');
+ }
+
String leaf(int level) {
if (level == 0) return "";
return tree(level - 2) + "+--";
@@ -309,96 +324,15 @@
}
Collection getLinks(String uri) throws Exception {
- LinkSamplingEnvironment env = new LinkSamplingEnvironment(uri, context);
+ LinkSamplingEnvironment env = new LinkSamplingEnvironment(uri, context, attributes, parameters);
cocoon.process(env);
return env.getLinks();
}
String getPage(String uri, Map links, OutputStream stream) throws Exception {
- FileSavingEnvironment env = new FileSavingEnvironment(uri, context, links, stream);
+ FileSavingEnvironment env = new FileSavingEnvironment(uri, context, attributes, parameters, links, stream);
cocoon.process(env);
return env.getContentType();
- }
-
- File getFile(String file) {
- File f = new File(destDir, file);
- File parent = f.getParentFile();
- if (parent != null) parent.mkdirs();
- return f;
- }
-
- String getExtension(String file) {
- int lastDot = file.lastIndexOf('.');
- if (lastDot > -1) file = file.substring(lastDot + 1);
- int lastSlash = file.lastIndexOf('/');
- if (lastSlash > -1) {
- return file.substring(lastSlash + 1);
- } else {
- return file;
- }
- }
-
- String adjustContext(String parent, String child) {
- if (child.charAt(0) != '/') {
- int lastSlash = parent.lastIndexOf('/');
- if (lastSlash > -1) {
- return parent.substring(0, lastSlash + 1) + child;
- } else {
- return child;
- }
- } else {
- return child;
- }
- }
-
- String getDefaultExtension(String type) {
- if (type == null) {
- return "html";
- } else if ("text/html".equals(type)) {
- return "html";
- } else if ("text/xml".equals(type)) {
- return "xml";
- } else if ("text/css".equals(type)) {
- return "css";
- } else if ("text/vnd.wap.wml".equals(type)) {
- return "wml";
- } else if ("image/jpg".equals(type)) {
- return "jpg";
- } else if ("image/jpeg".equals(type)) {
- return "jpg";
- } else if ("image/png".equals(type)) {
- return "png";
- } else if ("image/gif".equals(type)) {
- return "gif";
- } else if ("image/svg-xml".equals(type)) {
- return "svg";
- } else if ("application/pdf".equals(type)) {
- return "pdf";
- } else if ("model/vrml".equals(type)) {
- return "wrl";
- } else if ("text/plain".equals(type)) {
- return "txt";
- } else if ("application/rtf".equals(type)) {
- return "rtf";
- } else if ("text/rtf".equals(type)) {
- return "rtf";
- } else if ("application/smil".equals(type)) {
- return "smil";
- } else if ("application/x-javascript".equals(type)) {
- return "js";
- } else if ("application/zip".equals(type)) {
- return "zip";
- } else if ("video/mpeg".equals(type)) {
- return "mpg";
- } else if ("video/quicktime".equals(type)) {
- return "mov";
- } else if ("audio/midi".equals(type)) {
- return "mid";
- } else if ("audio/mpeg".equals(type)) {
- return "mp3";
- } else {
- return "";
- }
}
}
No revision
No revision
1.1.2.7 +9 -12 xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/AbstractMarkupLanguage.java
Index: AbstractMarkupLanguage.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/AbstractMarkupLanguage.java,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- AbstractMarkupLanguage.java 2000/08/21 17:38:56 1.1.2.6
+++ AbstractMarkupLanguage.java 2000/10/02 11:07:26 1.1.2.7
@@ -8,7 +8,9 @@
package org.apache.cocoon.components.language.markup;
import java.io.File;
+import java.io.IOException;
import java.net.URL;
+import java.net.MalformedURLException;
import java.util.Date;
import java.util.Vector;
import java.util.Hashtable;
@@ -22,26 +24,21 @@
import org.xml.sax.InputSource;
import org.xml.sax.EntityResolver;
+import org.xml.sax.SAXException;
import org.apache.avalon.Composer;
import org.apache.avalon.Component;
import org.apache.avalon.ComponentManager;
-
-import org.apache.avalon.utils.Parameters;
-import org.apache.avalon.AbstractNamedComponent;
-
import org.apache.avalon.Configuration;
import org.apache.avalon.ConfigurationException;
+import org.apache.avalon.AbstractNamedComponent;
+import org.apache.avalon.utils.Parameters;
import org.apache.cocoon.util.IOUtils;
+import org.apache.cocoon.util.NetUtils;
import org.apache.cocoon.components.store.MemoryStore;
-
import org.apache.cocoon.components.language.programming.ProgrammingLanguage;
-import java.io.IOException;
-import org.xml.sax.SAXException;
-import java.net.MalformedURLException;
-
/**
* Base implementation of <code>MarkupLanguage</code>. This class uses
* logicsheets as the only means of code generation. Code generation should
@@ -49,7 +46,7 @@
* (as opposed to Cocoon2's standard SAX events)
*
* @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
- * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/08/21 17:38:56 $
+ * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/10/02 11:07:26 $
*/
public abstract class AbstractMarkupLanguage
extends AbstractNamedComponent
@@ -132,7 +129,7 @@
String logicsheetLocation =
getRequiredParameter(lcp, "core-logicsheet");
- URL logicsheetURL = IOUtils.getURL(logicsheetLocation);
+ URL logicsheetURL = NetUtils.getURL(logicsheetLocation);
String logicsheetName = logicsheetURL.toExternalForm();
Logicsheet logicsheet = new Logicsheet();
logicsheet.setInputSource(new InputSource(logicsheetURL.openStream()));
@@ -150,7 +147,7 @@
String namedLogicsheetLocation = getRequiredParameter(ncp, "href");
// FIXME: This is repetitive; add method for both cases
- URL namedLogicsheetURL = IOUtils.getURL(namedLogicsheetLocation);
+ URL namedLogicsheetURL = NetUtils.getURL(namedLogicsheetLocation);
String namedLogicsheetName = namedLogicsheetURL.toExternalForm();
NamedLogicsheet namedLogicsheet = new NamedLogicsheet();
namedLogicsheet.setInputSource(
No revision
No revision
1.1.2.42 +3 -3 xml-cocoon/src/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl
Index: sitemap.xsl
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl,v
retrieving revision 1.1.2.41
retrieving revision 1.1.2.42
diff -u -r1.1.2.41 -r1.1.2.42
--- sitemap.xsl 2000/10/01 00:19:53 1.1.2.41
+++ sitemap.xsl 2000/10/02 11:07:27 1.1.2.42
@@ -11,7 +11,7 @@
<!--
* @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
- * @version CVS $Revision: 1.1.2.41 $ $Date: 2000/10/01 00:19:53 $
+ * @version CVS $Revision: 1.1.2.42 $ $Date: 2000/10/02 11:07:27 $
-->
<!-- Sitemap Core logicsheet for the Java language -->
@@ -135,7 +135,7 @@
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="java:getClassSource($factory-loader,string($factory),string($matcher-name),string(@pattern),$config)"/>
- private List <xsl:value-of select="$matcher-name"/> (String pattern, Environment environment) {
+ private List <xsl:value-of select="$matcher-name"/> (String pattern, Map objectModel) {
<xsl:value-of select="java:getMethodSource($factory-loader,string($factory),string($matcher-name),string(@pattern),$config)"/>
}
</xsl:for-each>
@@ -369,7 +369,7 @@
</xsl:choose>
</xsl:for-each>
</xsl:variable>
- if ((list = <xsl:value-of select="$matcher-name"/> ("<xsl:value-of select="$pattern-value"/>", environment)) != null) {
+ if ((list = <xsl:value-of select="$matcher-name"/> ("<xsl:value-of select="$pattern-value"/>", objectModel)) != null) {
listOfLists.add (list);
<xsl:apply-templates/>
listOfLists.remove (list);
No revision
No revision
1.1.2.6 +10 -1 xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/FileSavingEnvironment.java
Index: FileSavingEnvironment.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/FileSavingEnvironment.java,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- FileSavingEnvironment.java 2000/09/29 01:03:38 1.1.2.5
+++ FileSavingEnvironment.java 2000/10/02 11:07:29 1.1.2.6
@@ -20,16 +20,25 @@
import org.apache.cocoon.Cocoon;
import org.apache.cocoon.environment.AbstractEnvironment;
+/**
+ * This environment is used to save the requested file to disk.
+ *
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/10/02 11:07:29 $
+ */
+
public class FileSavingEnvironment extends AbstractEnvironment {
private String contentType;
private OutputStream stream;
- public FileSavingEnvironment(String uri, File context, Map links, OutputStream stream)
+ public FileSavingEnvironment(String uri, File context, Map attributes, Map parameters, Map links, OutputStream stream)
throws MalformedURLException {
super(uri, null, context);
this.stream = stream;
this.objectModel.put(Cocoon.LINK_OBJECT, links);
+ this.objectModel.put("request", new CommandLineRequest(null, uri, null, attributes, parameters));
+ this.objectModel.put("response", new CommandLineResponse());
}
/**
1.1.2.6 +12 -2 xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/LinkSamplingEnvironment.java
Index: LinkSamplingEnvironment.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/LinkSamplingEnvironment.java,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- LinkSamplingEnvironment.java 2000/09/29 01:03:38 1.1.2.5
+++ LinkSamplingEnvironment.java 2000/10/02 11:07:29 1.1.2.6
@@ -13,6 +13,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.ArrayList;
+import java.util.Map;
import java.io.File;
import java.io.IOException;
@@ -29,14 +30,23 @@
import org.apache.cocoon.Main;
import org.apache.cocoon.environment.AbstractEnvironment;
+/**
+ * This environment is sample the links of the resource.
+ *
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/10/02 11:07:29 $
+ */
+
public class LinkSamplingEnvironment extends AbstractEnvironment {
private boolean skip = false;
private ByteArrayOutputStream stream = new ByteArrayOutputStream();
- public LinkSamplingEnvironment(String uri, File context)
+ public LinkSamplingEnvironment(String uri, File contextFile, Map attributes, Map parameters)
throws MalformedURLException, IOException {
- super(uri, Cocoon.LINK_VIEW, context);
+ super(uri, Cocoon.LINK_VIEW, contextFile);
+ this.objectModel.put("request", new CommandLineRequest(null, uri, null, attributes, parameters));
+ this.objectModel.put("response", new CommandLineResponse());
}
/**
No revision
No revision
1.1.2.1 +165 -0 xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/CommandLineRequest.java
1.1.2.1 +68 -0 xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/CommandLineResponse.java
No revision
No revision
1.1.2.14 +0 -1 xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java
Index: HttpEnvironment.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java,v
retrieving revision 1.1.2.13
retrieving revision 1.1.2.14
diff -u -r1.1.2.13 -r1.1.2.14
--- HttpEnvironment.java 2000/09/02 19:42:10 1.1.2.13
+++ HttpEnvironment.java 2000/10/02 11:07:30 1.1.2.14
@@ -48,7 +48,6 @@
HttpServletResponse response,
ServletContext servletContext)
throws MalformedURLException, IOException {
-// super(uri, request.getHeader("cocoon-view"), servletContext.getRealPath("/"));
super(uri, request.getParameter("cocoon-view"), servletContext.getRealPath("/"));
this.request = new HttpRequest (request, this);
this.servletRequest = request;
No revision
No revision
1.1.2.8 +2 -2 xml-cocoon/src/org/apache/cocoon/matching/Attic/RegexpURIMatcherFactory.java
Index: RegexpURIMatcherFactory.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/RegexpURIMatcherFactory.java,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -r1.1.2.7 -r1.1.2.8
--- RegexpURIMatcherFactory.java 2000/09/27 16:07:26 1.1.2.7
+++ RegexpURIMatcherFactory.java 2000/10/02 11:07:31 1.1.2.8
@@ -20,7 +20,7 @@
* for request URIs
*
* @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
- * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/09/27 16:07:26 $
+ * @version CVS $Revision: 1.1.2.8 $ $Date: 2000/10/02 11:07:31 $
*/
public class RegexpURIMatcherFactory implements MatcherFactory {
@@ -70,7 +70,7 @@
String instructions = name + "PatternInstructions";
String pat = correctPattern (pattern);
sb.append("java.util.ArrayList list = new java.util.ArrayList ();")
- .append("if (").append(name).append("Pattern.match(environment.getURI()) {");
+ .append("if(").append(name).append("Pattern.match(((javax.servlet.http.HttpServletRequest)objectModel.get(\"request\")).getRequestURI())) {");
// Count number of parens
int i = 0;
int j = -1;
1.1.2.13 +2 -2 xml-cocoon/src/org/apache/cocoon/matching/Attic/WildcardURIMatcherFactory.java
Index: WildcardURIMatcherFactory.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/WildcardURIMatcherFactory.java,v
retrieving revision 1.1.2.12
retrieving revision 1.1.2.13
diff -u -r1.1.2.12 -r1.1.2.13
--- WildcardURIMatcherFactory.java 2000/09/27 16:07:29 1.1.2.12
+++ WildcardURIMatcherFactory.java 2000/10/02 11:07:31 1.1.2.13
@@ -18,7 +18,7 @@
*
* @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.1.2.12 $ $Date: 2000/09/27 16:07:29 $
+ * @version CVS $Revision: 1.1.2.13 $ $Date: 2000/10/02 11:07:31 $
*/
public class WildcardURIMatcherFactory implements MatcherFactory {
@@ -45,7 +45,7 @@
throws ConfigurationException {
StringBuffer result = new StringBuffer();
return result.append ("java.util.ArrayList list = new ArrayList();")
- .append ("if (org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (list, environment.getUri(), ")
+ .append ("if (org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (list,((javax.servlet.http.HttpServletRequest)objectModel.get(\"request\")).getRequestURI(), ")
.append(prefix).append("_expr))")
.append ("return list;")
.append ("else return null;").toString();
No revision
No revision
1.1.2.7 +24 -39 xml-cocoon/src/org/apache/cocoon/util/Attic/IOUtils.java
Index: IOUtils.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/util/Attic/IOUtils.java,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- IOUtils.java 2000/09/16 00:25:06 1.1.2.6
+++ IOUtils.java 2000/10/02 11:07:32 1.1.2.7
@@ -7,8 +7,6 @@
*****************************************************************************/
package org.apache.cocoon.util;
-import java.net.URL;
-
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
@@ -16,39 +14,21 @@
import java.io.ObjectOutputStream;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
-
import java.io.IOException;
-import java.net.MalformedURLException;
/**
* A collection of <code>File</code>, <code>URL</code> and filename
* utility methods
*
* @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
- * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/09/16 00:25:06 $
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/10/02 11:07:32 $
*/
public class IOUtils {
- /**
- * Create a URL from a location. This method supports the
- * <i>resource://</i> pseudo-protocol for loading resources
- * accessible to this same class' <code>ClassLoader</code>
- *
- * @param location The location
- * @return The URL pointed to by the location
- * @exception MalformedURLException If the location is malformed
- */
- public static URL getURL(String location) throws MalformedURLException {
- if (location.indexOf("://") < 0) {
- return (new File(location)).toURL();
- } else if (location.startsWith("resource://")) {
- URL u = ClassUtils.getClassLoader().getResource(location.substring("resource://".length()));
- if (u != null) return u;
- else throw new RuntimeException(location + " could not be found. (possible classloader problem)");
- } else {
- return new URL(location);
- }
- }
+ // **********************
+ // Serialize Methods
+ // **********************
/**
* Dump a <code>String</code> to a text file.
@@ -124,7 +104,7 @@
}
// **********************
- // Filename Methods
+ // File Methods
// **********************
/**
@@ -173,7 +153,7 @@
*/
public static String pathComponent(String filename) {
int i = filename.lastIndexOf(File.separator);
- return (i >= 0) ? filename.substring(0, i) : filename;
+ return (i > -1) ? filename.substring(0, i) : filename;
}
/**
@@ -185,7 +165,7 @@
*/
public static String fileComponent(String filename) {
int i = filename.lastIndexOf(File.separator);
- return (i >= 0) ? filename.substring(i + 1) : filename;
+ return (i > -1) ? filename.substring(i + 1) : filename;
}
/**
@@ -196,19 +176,10 @@
* @return The filename sans extension
*/
public static String baseName(String filename) {
- return baseName(filename, ".");
+ int i = filename.lastIndexOf('.');
+ return (i > -1) ? filename.substring(0, i) : filename;
}
- public static String baseName(String filename, String suffix) {
- int lastDot = filename.lastIndexOf(suffix);
-
- if (lastDot >= 0) {
- filename = filename.substring(0, lastDot);
- }
-
- return filename;
- }
-
/**
* Get the complete filename corresponding to a (typically relative)
* <code>File</code.
@@ -225,5 +196,19 @@
} catch (IOException e) {
return file.getAbsolutePath();
}
+ }
+
+ /**
+ * Return a file with the given filename creating the necessary
+ * directories if not present.
+ *
+ * @param filename The file
+ * @return The created File instance
+ */
+ public static File createFile(File destDir, String filename) {
+ File file = new File(destDir, filename);
+ File parent = file.getParentFile();
+ if (parent != null) parent.mkdirs();
+ return file;
}
}
No revision
No revision
1.1.2.1 +75 -0 xml-cocoon/src/org/apache/cocoon/util/Attic/MIMEUtils.java
1.1.2.1 +141 -0 xml-cocoon/src/org/apache/cocoon/util/Attic/NetUtils.java