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 2008/03/04 01:27:32 UTC
svn commit: r633331 - in /lenya/sandbox/modules/sitemeta:
config/cocoon-xconf/metadata-store.xconf
java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java
Author: andreas
Date: Mon Mar 3 16:27:29 2008
New Revision: 633331
URL: http://svn.apache.org/viewvc?rev=633331&view=rev
Log:
Adding meta data store for SiteMetaDataTransformer.
Added:
lenya/sandbox/modules/sitemeta/config/cocoon-xconf/metadata-store.xconf
Modified:
lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java
Added: lenya/sandbox/modules/sitemeta/config/cocoon-xconf/metadata-store.xconf
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/sitemeta/config/cocoon-xconf/metadata-store.xconf?rev=633331&view=auto
==============================================================================
--- lenya/sandbox/modules/sitemeta/config/cocoon-xconf/metadata-store.xconf (added)
+++ lenya/sandbox/modules/sitemeta/config/cocoon-xconf/metadata-store.xconf Mon Mar 3 16:27:29 2008
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.modules.sitemeta.SiteMetaDataTransformerStore']">
+ <component role="org.apache.lenya.modules.sitemeta.SiteMetaDataTransformerStore"
+ class="org.apache.excalibur.store.impl.MRUMemoryStore" logger="lenya.source.sitemeta.store">
+ <parameter name="maxobjects" value="10000"/>
+ </component>
+</xconf>
Modified: lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java?rev=633331&r1=633330&r2=633331&view=diff
==============================================================================
--- lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java (original)
+++ lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java Mon Mar 3 16:27:29 2008
@@ -19,15 +19,18 @@
import java.io.IOException;
import java.net.MalformedURLException;
+import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.transformation.AbstractSAXTransformer;
+import org.apache.excalibur.store.impl.MRUMemoryStore;
import org.apache.lenya.cms.linking.Link;
import org.apache.lenya.cms.linking.LinkResolver;
import org.apache.lenya.cms.linking.LinkTarget;
@@ -53,6 +56,19 @@
private Area area;
private LinkResolver linkResolver;
+ protected static MRUMemoryStore cache;
+
+ protected synchronized MRUMemoryStore getCache() {
+ if (cache == null) {
+ try {
+ cache = (MRUMemoryStore) this.manager.lookup(getClass().getName() + "Store");
+ } catch (ServiceException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return cache;
+ }
+
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params)
throws ProcessingException, SAXException, IOException {
super.setup(resolver, objectModel, src, params);
@@ -80,8 +96,8 @@
}
}
- protected static final String NAV_NAMESPACE = "http://apache.org/cocoon/lenya/navigation/1.0";
- protected static final String ELEM_NODE = "node";
+ protected static final String NAV_NAMESPACE = "http://apache.org/lenya/site/1.0";
+ protected static final String ELEM_LINK = "link";
protected static final String ATTR_HREF = "href";
/**
@@ -101,7 +117,7 @@
public void startElement(String uri, String localName, String qName, Attributes attr)
throws SAXException {
- if (uri != null && uri.equals(NAV_NAMESPACE) && localName.equals(ELEM_NODE)) {
+ if (uri != null && uri.equals(NAV_NAMESPACE) && localName.equals(ELEM_LINK)) {
AttributesImpl attrs = new AttributesImpl(attr);
String href = attrs.getValue(ATTR_HREF);
try {
@@ -133,14 +149,14 @@
}
protected boolean isFolderNode(Document doc) throws MetaDataException {
- MetaData meta = doc.getMetaData(NAMESPACE);
+ CacheableMetaData meta = getMetaData(doc);
String value = meta.getFirstValue(ELEM_FOLDER_NODE);
boolean isFolderNode = value != null && Boolean.valueOf(value).booleanValue();
return isFolderNode;
}
protected String getExternalLink(Document doc) throws MetaDataException {
- MetaData meta = doc.getMetaData(NAMESPACE);
+ CacheableMetaData meta = getMetaData(doc);
return meta.getFirstValue(ELEM_EXTERNAL_LINK);
}
@@ -155,6 +171,52 @@
link.setPubId(this.area.getPublication().getId());
}
return link.getUri();
+ }
+
+ protected CacheableMetaData getMetaData(Document doc) throws MetaDataException {
+ CacheableMetaData cacheableMeta = null;
+ String key = doc.getRepositoryNode().getSourceURI();
+ MRUMemoryStore cache = getCache();
+ MetaData meta = doc.getMetaData(NAMESPACE);
+ if (cache.containsKey(key)) {
+ cacheableMeta = (CacheableMetaData) cache.get(key);
+ if (meta.getLastModified() > cacheableMeta.getLastModified()) {
+ cacheableMeta = null;
+ }
+ }
+ if (cacheableMeta == null) {
+ cacheableMeta = new CacheableMetaData(meta);
+ cache.hold(key, cacheableMeta);
+ }
+ return cacheableMeta;
+ }
+
+ protected static class CacheableMetaData {
+
+ private Map map = new HashMap();
+ private long lastModified;
+
+ public CacheableMetaData(MetaData meta) throws MetaDataException {
+ this.lastModified = meta.getLastModified();
+ String[] keys = meta.getAvailableKeys();
+ for (int i = 0; i < keys.length; i++) {
+ this.map.put(keys[i], meta.getValues(keys[i]));
+ }
+ }
+
+ public String getFirstValue(String key) {
+ String[] values = (String[]) this.map.get(key);
+ if (values != null && values.length > 0) {
+ return values[0];
+ } else {
+ return null;
+ }
+ }
+
+ public long getLastModified() {
+ return this.lastModified;
+ }
+
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org