Author: andreas
Date: Sun Feb 10 15:19:41 2008
New Revision: 620356
URL: http://svn.apache.org/viewvc?rev=620356&view=rev
Log:
Made url2uuid rewriting independent from the current publication+area. This means it can't be cached anymore, but in the usual scenario (saving in editors) this doesn't matter.
Modified:
lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/transformation/UrlToUuidTransformer.java
lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/UrlToUuidRewriter.java
Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/transformation/UrlToUuidTransformer.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/transformation/UrlToUuidTransformer.java?rev=620356&r1=620355&r2=620356&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/transformation/UrlToUuidTransformer.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/transformation/UrlToUuidTransformer.java Sun Feb 10 15:19:41 2008
@@ -18,28 +18,20 @@
package org.apache.lenya.cms.cocoon.transformation;
import java.io.IOException;
-import java.io.Serializable;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceValidity;
import org.apache.lenya.cms.linking.LinkResolver;
import org.apache.lenya.cms.linking.LinkRewriter;
import org.apache.lenya.cms.linking.UrlToUuidRewriter;
-import org.apache.lenya.cms.publication.Area;
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.DocumentUtil;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.URLInformation;
import org.apache.lenya.cms.repository.RepositoryUtil;
import org.apache.lenya.cms.repository.Session;
-import org.apache.lenya.util.ServletHelper;
import org.xml.sax.SAXException;
/**
@@ -53,11 +45,9 @@
* </p>
* @see UrlToUuidRewriter
*/
-public class UrlToUuidTransformer extends AbstractLinkTransformer implements CacheableProcessingComponent {
+public class UrlToUuidTransformer extends AbstractLinkTransformer {
private LinkRewriter rewriter;
- private String cacheKey;
- private SourceValidity validity;
/**
* @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
@@ -68,44 +58,18 @@
Parameters _parameters) throws ProcessingException, SAXException, IOException {
super.setup(_resolver, _objectModel, _source, _parameters);
- Source source = null;
- Request _request = ObjectModelHelper.getRequest(_objectModel);
+ Request request = ObjectModelHelper.getRequest(_objectModel);
try {
- Session session = RepositoryUtil.getSession(this.manager, _request);
+ Session session = RepositoryUtil.getSession(this.manager, request);
DocumentFactory factory = DocumentUtil.createDocumentFactory(this.manager, session);
- String url = ServletHelper.getWebappURI(_request);
- URLInformation info = new URLInformation(url);
- Publication pub = factory.getPublication(info.getPublicationId());
- Area area = pub.getArea(info.getArea());
- this.rewriter = new UrlToUuidRewriter(area);
- this.cacheKey = pub.getId() + ":" + area.getName();
- source = resolver.resolveURI(area.getSite().getRepositoryNode().getSourceURI());
- this.validity = source.getValidity();
+ this.rewriter = new UrlToUuidRewriter(factory);
} catch (final Exception e1) {
throw new ProcessingException(e1);
- } finally {
- if (source != null) {
- resolver.release(source);
- }
}
}
protected LinkRewriter getLinkRewriter() {
return this.rewriter;
- }
-
- public Serializable getKey() {
- if (this.cacheKey == null) {
- throw new IllegalStateException("setup() was not called.");
- }
- return this.cacheKey;
- }
-
- public SourceValidity getValidity() {
- if (this.validity == null) {
- throw new IllegalStateException("setup() was not called.");
- }
- return this.validity;
}
}
Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/UrlToUuidRewriter.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/UrlToUuidRewriter.java?rev=620356&r1=620355&r2=620356&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/UrlToUuidRewriter.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/UrlToUuidRewriter.java Sun Feb 10 15:19:41 2008
@@ -17,14 +17,18 @@
*/
package org.apache.lenya.cms.linking;
+import java.util.Arrays;
+
import org.apache.lenya.cms.publication.Area;
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.URLInformation;
/**
* <p>
- * Converts webapp URLs to UUID-based internal links. If the URL
- * doesn't refer to a document, the original URL is returned.
+ * Converts webapp URLs to UUID-based internal links. If the URL doesn't refer to a document, the
+ * original URL is returned.
* </p>
* <p>
* Objects of this class are not thread-safe.
@@ -32,17 +36,32 @@
*/
public class UrlToUuidRewriter implements LinkRewriter {
- private Area area;
+ private DocumentFactory factory;
/**
- * @param area The area to operate in.
+ * @param factory The document factory to use.
*/
- public UrlToUuidRewriter(Area area) {
- this.area = area;
+ public UrlToUuidRewriter(DocumentFactory factory) {
+ this.factory = factory;
}
public boolean matches(String url) {
- return url.startsWith("/" + this.area.getPublication().getId() + "/" + this.area.getName());
+ URLInformation info = new URLInformation(url);
+ String pubId = info.getPublicationId();
+ String area = info.getArea();
+ if (pubId != null && area != null) {
+ if (this.factory.existsPublication(pubId)) {
+ try {
+ Publication pub = this.factory.getPublication(pubId);
+ if (Arrays.asList(pub.getAreaNames()).contains(area)) {
+ return true;
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ return false;
}
public String rewrite(String webappUrl) {
@@ -64,8 +83,6 @@
if (linkUrlAndQuery.length > 1) {
queryString = linkUrlAndQuery[1];
}
-
- DocumentFactory factory = this.area.getPublication().getFactory();
String rewrittenUrl;
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.