You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2007/02/15 18:41:54 UTC
svn commit: r508032 - in /lenya/trunk/src:
modules-core/linking/java/src/org/apache/lenya/cms/linking/
modules/bxe/usecases/ modules/editors/java/src/org/apache/lenya/cms/editors/
modules/export/java/src/org/apache/lenya/cms/export/ modules/webdav/java...
Author: andreas
Date: Thu Feb 15 09:41:53 2007
New Revision: 508032
URL: http://svn.apache.org/viewvc?view=rev&rev=508032
Log:
Considering context path when rewriting links
Modified:
lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java
lenya/trunk/src/modules/bxe/usecases/insertAsset.jx
lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java
lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java
lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.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?view=diff&rev=508032&r1=508031&r2=508032
==============================================================================
--- 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 Thu Feb 15 09:41:53 2007
@@ -20,7 +20,9 @@
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
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;
@@ -32,10 +34,11 @@
import org.w3c.dom.NodeList;
/**
- * Utility class to convert <code>lenya-document:</code> links from and to URL links.
+ * Utility class to convert <code>lenya-document:</code> links from and to URL
+ * links.
*/
public class LinkConverter extends AbstractLogEnabled {
-
+
private ServiceManager manager;
/**
@@ -47,13 +50,14 @@
ContainerUtil.enableLogging(this, logger);
this.manager = manager;
}
-
+
/**
* Converts all URL-based links to UUID-based links.
* @param doc The document to convert.
+ * @param useContextPath If the request's context path should be considered.
*/
- public void convertUrlsToUuids(Document doc) {
- convertUrlsToUuids(doc.getPublication(), doc);
+ public void convertUrlsToUuids(Document doc, boolean useContextPath) {
+ convertUrlsToUuids(doc.getPublication(), doc, useContextPath);
}
/**
@@ -61,11 +65,19 @@
* originate from a different publication.
* @param srcPub The publication where the content comes from.
* @param examinedDocument The document in the target publication.
+ * @param useContextPath If the request's context path should be considered.
*/
- public void convertUrlsToUuids(Publication srcPub, Document examinedDocument) {
+ public void convertUrlsToUuids(Publication srcPub, Document examinedDocument,
+ boolean useContextPath) {
boolean linksRewritten = false;
LinkResolver linkResolver = null;
try {
+
+ String prefix = "";
+ if (useContextPath) {
+ prefix = getContextPath();
+ }
+
ResourceType type = examinedDocument.getResourceType();
String[] xPaths = type.getLinkAttributeXPaths();
@@ -78,7 +90,8 @@
linkResolver = (LinkResolver) this.manager.lookup(LinkResolver.ROLE);
DocumentFactory factory = examinedDocument.getFactory();
- org.w3c.dom.Document xmlDocument = DocumentHelper.readDocument(examinedDocument.getInputStream());
+ org.w3c.dom.Document xmlDocument = DocumentHelper.readDocument(examinedDocument
+ .getInputStream());
for (int xPathIndex = 0; xPathIndex < xPaths.length; xPathIndex++) {
if (getLogger().isDebugEnabled()) {
@@ -98,11 +111,11 @@
getLogger().debug("Convert links: Check URL [" + url + "]");
}
- if (url.startsWith("/" + srcPub.getId() + "/" + examinedDocument.getArea()
- + "/")) {
+ if (url.startsWith(prefix + "/" + srcPub.getId() + "/"
+ + examinedDocument.getArea() + "/")) {
String targetPubId = examinedDocument.getPublication().getId();
final String webappUrl = "/" + targetPubId
- + url.substring(("/" + srcPub.getId()).length());
+ + url.substring((prefix + "/" + srcPub.getId()).length());
if (factory.isDocument(webappUrl)) {
Document targetDocument = factory.getFromURL(webappUrl);
@@ -131,6 +144,20 @@
this.manager.release(linkResolver);
}
}
+ }
+
+ protected String getContextPath() throws ServiceException {
+ String prefix;
+ ContextUtility ctxUtil = null;
+ try {
+ ctxUtil = (ContextUtility) this.manager.lookup(ContextUtility.ROLE);
+ prefix = ctxUtil.getRequest().getContextPath();
+ } finally {
+ if (ctxUtil != null) {
+ this.manager.release(ctxUtil);
+ }
+ }
+ return prefix;
}
}
Modified: lenya/trunk/src/modules/bxe/usecases/insertAsset.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/bxe/usecases/insertAsset.jx?view=diff&rev=508032&r1=508031&r2=508032
==============================================================================
--- lenya/trunk/src/modules/bxe/usecases/insertAsset.jx (original)
+++ lenya/trunk/src/modules/bxe/usecases/insertAsset.jx Thu Feb 15 09:41:53 2007
@@ -49,7 +49,7 @@
<th style="background: none;"><i18n:text>Creation Date</i18n:text></th>
</tr>
<jx:forEach var="asset" items="${usecase.getParameter('assets')}">
- <jx:set var="originalUrl" value="${asset.getCanonicalWebappURL()}"/>
+ <jx:set var="originalUrl" value="${cocoon.request.getContextPath() + asset.getCanonicalWebappURL()}"/>
<jx:set var="lastDotIndex" value="${originalUrl.lastIndexOf('.')}"/>
<jx:set var="extension" value="${asset.getMetaData('http://apache.org/lenya/metadata/document/1.0').getFirstValue('extension')}"/>
<jx:set var="url" value="${originalUrl.substring(0, lastDotIndex).concat('.').concat(extension)}"/>
@@ -63,8 +63,7 @@
<jx:set var="mimeType" value="${asset.getMimeType()}"/>
<jx:if test="${mimeType.startsWith('image/')}">
<jx:set var="doc" value="${usecase.getParameter('document')}"/>
- <img src="${cocoon.request.getContextPath()}${url}"
- style="height: 32px; vertical-align: middle; margin: 3px 0px;"/> 
+ <img src="${url}" style="height: 32px; vertical-align: middle; margin: 3px 0px;"/> 
</jx:if>
</td>
<td><jx:out value="${asset.getMetaData('http://purl.org/dc/elements/1.1/').getFirstValue('title')}"/></td>
Modified: lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java?view=diff&rev=508032&r1=508031&r2=508032
==============================================================================
--- lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java (original)
+++ lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java Thu Feb 15 09:41:53 2007
@@ -86,7 +86,7 @@
SourceUtil.writeDOM(xmlDoc, sourceDoc.getOutputStream());
LinkConverter converter = new LinkConverter(this.manager, getLogger());
- converter.convertUrlsToUuids(getSourceDocument());
+ converter.convertUrlsToUuids(getSourceDocument(), true);
String event = getParameterAsString(EVENT, DEFAULT_EVENT);
WorkflowUtil
Modified: lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java?view=diff&rev=508032&r1=508031&r2=508032
==============================================================================
--- lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java (original)
+++ lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java Thu Feb 15 09:41:53 2007
@@ -183,7 +183,7 @@
Document[] docs = area.getDocuments();
for (int i = 0; i < docs.length; i++) {
LinkConverter converter = new LinkConverter(this.manager, getLogger());
- converter.convertUrlsToUuids(srcPub, docs[i]);
+ converter.convertUrlsToUuids(srcPub, docs[i], false);
}
}
Modified: lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java?view=diff&rev=508032&r1=508031&r2=508032
==============================================================================
--- lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java (original)
+++ lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java Thu Feb 15 09:41:53 2007
@@ -159,7 +159,7 @@
}
LinkConverter converter = new LinkConverter(this.manager, getLogger());
- converter.convertUrlsToUuids(doc);
+ converter.convertUrlsToUuids(doc, true);
String event = getParameterAsString(EVENT);
if (event != null) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org