svn commit: r603379 - /lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java
[email protected] Tue, 11 Dec 2007 22:08:19 -0000
Newsgroups
gmane.comp.cms.lenya.cvs
Message-ID
<[email protected] >
Author: andreas
Date: Tue Dec 11 14:08:18 2007
New Revision: 603379
URL: http://svn.apache.org/viewvc?rev=603379&view=rev
Log:
Use UrlToUuidRewriter in LinkConverter to avoid code duplication. No semantic or API changes.
Modified:
lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java
Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java?rev=603379&r1=603378&r2=603379&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java Tue Dec 11 14:08:18 2007
@@ -24,7 +24,6 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.lenya.cms.cocoon.components.context.ContextUtility;
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.ResourceType;
import org.apache.lenya.xml.DocumentHelper;
@@ -70,7 +69,6 @@
public void convertUrlsToUuids(Publication srcPub, Document examinedDocument,
boolean useContextPath) {
boolean linksRewritten = false;
- LinkResolver linkResolver = null;
try {
String prefix = "";
@@ -87,10 +85,9 @@
"Convert links: No XPaths for resource type [" + type.getName() + "]");
}
} else {
- linkResolver = (LinkResolver) this.manager.lookup(LinkResolver.ROLE);
- DocumentFactory factory = examinedDocument.getFactory();
+ LinkRewriter rewriter = new UrlToUuidRewriter(examinedDocument.area());
- org.w3c.dom.Document xmlDocument = DocumentHelper.readDocument(examinedDocument
+ org.w3c.dom.Document xml = DocumentHelper.readDocument(examinedDocument
.getInputStream());
for (int xPathIndex = 0; xPathIndex < xPaths.length; xPathIndex++) {
@@ -98,7 +95,7 @@
getLogger()
.debug("Convert links: Check XPath [" + xPaths[xPathIndex] + "]");
}
- NodeList nodes = XPathAPI.selectNodeList(xmlDocument, xPaths[xPathIndex]);
+ NodeList nodes = XPathAPI.selectNodeList(xml, xPaths[xPathIndex]);
for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
Node node = nodes.item(nodeIndex);
if (node.getNodeType() != Node.ATTRIBUTE_NODE) {
@@ -110,39 +107,21 @@
if (getLogger().isDebugEnabled()) {
getLogger().debug("Convert links: Check URL [" + url + "]");
}
-
- if (url.startsWith(prefix + "/" + srcPub.getId() + "/"
- + examinedDocument.getArea() + "/")) {
- String targetPubId = examinedDocument.getPublication().getId();
- final String webappUrl = "/" + targetPubId
- + url.substring((prefix + "/" + srcPub.getId()).length());
- if (factory.isDocument(webappUrl)) {
- Document targetDocument = factory.getFromURL(webappUrl);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(
- "Convert links: Check webapp URL [" + webappUrl + "]");
- }
-
- Link link = new Link();
- link.setUuid(targetDocument.getUUID());
- attribute.setValue(link.getUri());
- linksRewritten = true;
- }
+ final String originalUrl = url.startsWith(prefix) ? url.substring(prefix.length()) : url;
+ if (rewriter.matches(originalUrl)) {
+ String rewrittenUrl = rewriter.rewrite(originalUrl);
+ attribute.setValue(rewrittenUrl);
+ linksRewritten = true;
}
}
}
if (linksRewritten) {
- DocumentHelper.writeDocument(xmlDocument, examinedDocument.getOutputStream());
+ DocumentHelper.writeDocument(xml, examinedDocument.getOutputStream());
}
}
} catch (Exception e) {
throw new RuntimeException("Error rewriting document: [" + examinedDocument + "]", e);
- } finally {
- if (linkResolver != null) {
- this.manager.release(linkResolver);
- }
}
}