upayavira 2003/09/10 02:12:21
Modified: src/java/org/apache/cocoon/bean CocoonBean.java Target.java
Log:
Moving derivedTarget creation earlier
Starting renaming variables before move of URI arithmetic into Target class
Revision Changes Path
1.21 +40 -43
cocoon-2.1/src/java/org/apache/cocoon/bean/CocoonBean.java
Index: CocoonBean.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/bean/CocoonBean.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- CocoonBean.java 9 Sep 2003 17:32:36 -0000 1.20
+++ CocoonBean.java 10 Sep 2003 09:12:20 -0000 1.21
@@ -385,42 +385,42 @@
}
}
- String filename;
+ String destinationURI;
if (confirmExtension) {
- filename = (String) allTranslatedLinks.get(suri);
- if (filename == null) {
- filename = mangle(suri);
+ destinationURI = (String) allTranslatedLinks.get(suri);
+ if (destinationURI == null) {
+ destinationURI = mangle(suri);
final String type = getType(deparameterizedURI, parameters);
- final String ext = NetUtils.getExtension(filename);
+ final String ext = NetUtils.getExtension(destinationURI);
final String defaultExt =
MIMEUtils.getDefaultExtension(type);
if (defaultExt != null) {
if ((ext == null) || (!ext.equals(defaultExt))) {
- filename += defaultExt;
+ destinationURI += defaultExt;
}
}
- allTranslatedLinks.put(suri, filename);
+ allTranslatedLinks.put(suri, destinationURI);
}
} else {
- filename = suri;
+ destinationURI = suri;
}
// Store processed URI list to avoid eternal loop
allProcessedLinks.put(target, target);
- if ("".equals(filename)) {
+ if ("".equals(destinationURI)) {
return new ArrayList();
}
// Process links
- final List absoluteLinks = new ArrayList();
final HashMap translatedLinks = new HashMap();
List gatheredLinks = new ArrayList();
-
+ final List targets = new ArrayList();
if (followLinks && confirmExtension) {
final Iterator i =
this.getLinks(deparameterizedURI, parameters).iterator();
while (i.hasNext()) {
String link = (String) i.next();
+
// Fix relative links starting with "?"
String relativeLink = link;
if (relativeLink.startsWith("?")) {
@@ -452,7 +452,6 @@
allTranslatedLinks.put(
absoluteLink,
translatedAbsoluteLink);
- absoluteLinks.add(absoluteLink);
} catch (ProcessingException pe) {
this.sendBrokenLinkWarning(absoluteLink,
pe.getMessage());
}
@@ -460,7 +459,12 @@
// I have to add also broken links to the absolute links
// to be able to generate the "broken link" page
- absoluteLinks.add(absoluteLink);
+
+ Target derivedTarget =
target.getDerivedTarget(absoluteLink);
+ if (derivedTarget != null) {
+ targets.add(derivedTarget);
+ }
+
final String translatedRelativeLink =
NetUtils.relativize(path, translatedAbsoluteLink);
translatedLinks.put(link, translatedRelativeLink);
@@ -476,7 +480,7 @@
status =
getPage(
deparameterizedURI,
- getLastModified(target, filename),
+ getLastModified(target, destinationURI),
parameters,
confirmExtension ? translatedLinks : null,
gatheredLinks,
@@ -488,10 +492,8 @@
}
if (followLinks && !confirmExtension) {
- for (Iterator it = gatheredLinks.iterator();
- it.hasNext();
- ) {
- String link = (String) it.next();
+ for (Iterator it =
gatheredLinks.iterator();it.hasNext();) {
+ String link = (String) it.next();
if (link.startsWith("?")) {
link = pageURI + link;
}
@@ -504,8 +506,11 @@
NetUtils.deparameterize(absoluteLink, p),
p);
}
- if (isIncluded(absoluteLink)) {
- absoluteLinks.add(absoluteLink);
+ Target derivedTarget =
target.getDerivedTarget(absoluteLink);
+ if (isIncluded(absoluteLink)) {
+ if (derivedTarget !=
null) {
+
targets.add(derivedTarget);
+ }
} else {
// @TODO@ Log/report skipped link
}
@@ -517,14 +522,14 @@
} catch (ProcessingException pe) {
output.close();
output = null;
- this.resourceUnavailable(target, uri, filename);
+ this.resourceUnavailable(target, uri, destinationURI);
this.sendBrokenLinkWarning(
- filename,
+ destinationURI,
DefaultNotifyingBuilder.getRootCause(pe).getMessage());
} finally {
if (output != null && status != -1) {
- ModifiableSource source = getSource(target, filename);
+ ModifiableSource source = getSource(target,
destinationURI);
try {
OutputStream stream = source.getOutputStream();
@@ -544,14 +549,6 @@
this.sendBrokenLinkWarning(deparameterizedURI, "URI not found");
}
- List targets = new ArrayList();
- for (Iterator i = absoluteLinks.iterator(); i.hasNext();) {
- String link = (String) i.next();
- Target derivedTarget = target.getDerivedTarget(link);
- if (derivedTarget != null) {
- targets.add(target.getDerivedTarget(link));
- }
- }
/* Commenting out timestamp - will reimplement properly using the
BeanListener interface
double d = (System.currentTimeMillis()- startTimeMillis);
String time = " [" + (d/1000) + " seconds]";
@@ -576,19 +573,19 @@
HashMap parameters = new HashMap();
String deparameterizedURI = NetUtils.deparameterize(uri, parameters);
- String filename = mangle(uri);
+ String destinationURI = mangle(uri);
if (confirmExtension) {
String type = getType(deparameterizedURI, parameters);
- String ext = NetUtils.getExtension(filename);
+ String ext = NetUtils.getExtension(destinationURI);
String defaultExt = MIMEUtils.getDefaultExtension(type);
if (defaultExt != null) {
if ((ext == null) || (!ext.equals(defaultExt))) {
- filename += defaultExt;
+ destinationURI += defaultExt;
}
}
}
- return filename;
+ return destinationURI;
}
/**
@@ -597,10 +594,10 @@
* @param target being unavailable
* @exception IOException if an error occurs
*/
- private void resourceUnavailable(Target target, String uri, String
filename)
+ private void resourceUnavailable(Target target, String uri, String
destinationURI)
throws IOException, ProcessingException {
if (brokenLinkGenerate) {
- String brokenFile = NetUtils.decodePath(filename);
+ String brokenFile = NetUtils.decodePath(destinationURI);
if (brokenLinkExtension != null) {
brokenFile = brokenFile + brokenLinkExtension;
}
@@ -613,7 +610,7 @@
n.addExtraDescription(Notifying.EXTRA_REQUESTURI, uri);
n.addExtraDescription("missing-file", uri);
- ModifiableSource source = getSource(target, filename);
+ ModifiableSource source = getSource(target, destinationURI);
try {
OutputStream stream = source.getOutputStream();
@@ -649,9 +646,9 @@
return uri;
}
- public ModifiableSource getSource(Target target, String filename)
+ public ModifiableSource getSource(Target target, String destinationURI)
throws IOException, ProcessingException {
- final String finalDestinationURI = target.getFinalURI(filename);
+ final String finalDestinationURI =
target.getDestinationURI(destinationURI);
Source src = sourceResolver.resolveURI(finalDestinationURI);
if (!(src instanceof ModifiableSource)) {
sourceResolver.release(src);
@@ -661,8 +658,8 @@
return (ModifiableSource) src;
}
- public long getLastModified(Target target, String filename) throws
IOException, ProcessingException {
- return getSource(target, filename).getLastModified();
+ public long getLastModified(Target target, String destinationURI) throws
IOException, ProcessingException {
+ return getSource(target, destinationURI).getLastModified();
}
public void releaseSource(ModifiableSource source) {
1.2 +2 -2 cocoon-2.1/src/java/org/apache/cocoon/bean/Target.java
Index: Target.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/bean/Target.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Target.java 27 Aug 2003 19:18:18 -0000 1.1
+++ Target.java 10 Sep 2003 09:12:21 -0000 1.2
@@ -113,7 +113,7 @@
return new Target(this.type, this.root, newURI, this.destURI);
}
- public String getFinalURI(String actualSourceURI)
+ public String getDestinationURI(String actualSourceURI)
throws ProcessingException {
if (!actualSourceURI.startsWith(root)) {
throw new ProcessingException(