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 2005/04/18 10:54:28 UTC
svn commit: r161744 - in lenya/trunk/src:
java/org/apache/lenya/cms/cocoon/source/
java/org/apache/lenya/cms/publication/ java/org/apache/lenya/cms/repository/
java/org/apache/lenya/cms/site/usecases/ webapp/lenya/usecases/tab/
Author: andreas
Date: Mon Apr 18 01:54:26 2005
New Revision: 161744
URL: http://svn.apache.org/viewcvs?view=rev&rev=161744
Log:
added mime-type, lastmodified, contentlength to repo sources and assets
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/RepositorySource.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java
lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java
lenya/trunk/src/java/org/apache/lenya/cms/repository/SourceNode.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java
lenya/trunk/src/webapp/lenya/usecases/tab/assets.jx
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/RepositorySource.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/RepositorySource.java?view=diff&r1=161743&r2=161744
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/RepositorySource.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/RepositorySource.java Mon Apr 18 01:54:26 2005
@@ -6,8 +6,6 @@
*/
package org.apache.lenya.cms.cocoon.source;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -31,7 +29,6 @@
import org.apache.lenya.cms.repository.SourceNodeFactory;
import org.apache.lenya.transaction.IdentityMap;
import org.apache.lenya.transaction.TransactionException;
-import org.w3c.dom.Document;
/**
* Repository source.
@@ -86,7 +83,7 @@
this.node = (Node) map.get(Node.IDENTIFIABLE_TYPE, uri);
}
-
+
/**
* @return The repository node which is accessed by this source.
*/
@@ -160,21 +157,8 @@
throw new SourceNotFoundException("The source [" + getURI() + "] does not exist!");
}
try {
- Document doc = this.node.getDocument();
- TransformerFactory tFactory = TransformerFactory.newInstance();
- Transformer transformer = tFactory.newTransformer();
-
- transformer.setOutputProperty("encoding", "UTF-8");
- transformer.setOutputProperty("indent", "yes");
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- transformer.transform(new DOMSource(doc), new StreamResult(bos));
- return new ByteArrayInputStream(bos.toByteArray());
-
- /*
- return convert(doc);
- */
- } catch (Exception e) {
+ return this.node.getInputStream();
+ } catch (TransactionException e) {
throw new RuntimeException(e);
}
}
@@ -269,21 +253,44 @@
return false;
}
- public Document getDocument() {
- return this.node.getDocument();
+ /**
+ * Registerns the source as dirty.
+ * @throws TransactionException if an error occurs.
+ */
+ public void registerDirty() throws TransactionException {
+ this.identityMap.getUnitOfWork().registerDirty(this.node);
}
- public void setDocument(Document document) {
- this.node.setDocument(document);
+ /**
+ * @see org.apache.excalibur.source.Source#getContentLength()
+ */
+ public long getContentLength() {
try {
- registerDirty();
+ return this.node.getContentLength();
} catch (TransactionException e) {
throw new RuntimeException(e);
}
}
- public void registerDirty() throws TransactionException {
- this.identityMap.getUnitOfWork().registerDirty(this.node);
+ /**
+ * @see org.apache.excalibur.source.Source#getLastModified()
+ */
+ public long getLastModified() {
+ try {
+ return this.node.getLastModified();
+ } catch (TransactionException e) {
+ throw new RuntimeException(e);
+ }
}
+ /**
+ * @see org.apache.excalibur.source.Source#getMimeType()
+ */
+ public String getMimeType() {
+ try {
+ return this.node.getMimeType();
+ } catch (TransactionException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java?view=diff&r1=161743&r2=161744
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java Mon Apr 18 01:54:26 2005
@@ -158,11 +158,7 @@
source = resolver.resolveURI(sourceUri);
if (source.exists()) {
- if (source instanceof RepositorySource) {
- document = ((RepositorySource) source).getDocument();
- } else {
- document = DocumentHelper.readDocument(source.getInputStream());
- }
+ document = DocumentHelper.readDocument(source.getInputStream());
}
} finally {
if (resolver != null) {
@@ -196,19 +192,15 @@
resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
source = (ModifiableSource) resolver.resolveURI(sourceUri);
- if (source instanceof RepositorySource) {
- ((RepositorySource) source).setDocument(document);
- } else {
- OutputStream oStream = source.getOutputStream();
- Writer writer = new OutputStreamWriter(oStream);
- DocumentHelper.writeDocument(document, writer);
- if (oStream != null) {
- oStream.flush();
- try {
- oStream.close();
- } catch (Throwable t) {
- throw new RuntimeException("Could not write document: ", t);
- }
+ OutputStream oStream = source.getOutputStream();
+ Writer writer = new OutputStreamWriter(oStream);
+ DocumentHelper.writeDocument(document, writer);
+ if (oStream != null) {
+ oStream.flush();
+ try {
+ oStream.close();
+ } catch (Throwable t) {
+ throw new RuntimeException("Could not write document: ", t);
}
}
} finally {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java?view=diff&r1=161743&r2=161744
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java Mon Apr 18 01:54:26 2005
@@ -17,6 +17,8 @@
package org.apache.lenya.cms.publication;
import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceNotFoundException;
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.cocoon.source.RepositorySource;
import org.apache.lenya.cms.metadata.MetaDataManager;
@@ -129,4 +131,88 @@
return nodes;
}
+ /**
+ * @return The content length of the source.
+ * @throws SourceNotFoundException if the source does not exist.
+ */
+ public long getContentLength() throws SourceNotFoundException {
+ SourceResolver resolver = null;
+ Source source = null;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = resolver.resolveURI(getSourceURI());
+ if (source.exists()) {
+ return source.getContentLength();
+ } else {
+ throw new SourceNotFoundException("The source [" + getSourceURI()
+ + "] does not exist!");
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ }
+
+ /**
+ * @return The last modification date of the source.
+ * @throws SourceNotFoundException if the source does not exist.
+ */
+ public long getLastModified() throws SourceNotFoundException {
+ SourceResolver resolver = null;
+ Source source = null;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = resolver.resolveURI(getSourceURI());
+ if (source.exists()) {
+ return source.getLastModified();
+ } else {
+ throw new SourceNotFoundException("The source [" + getSourceURI()
+ + "] does not exist!");
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ }
+
+ /**
+ * @return The mime type of the source.
+ * @throws SourceNotFoundException if the source does not exist.
+ */
+ public String getMimeType() throws SourceNotFoundException {
+ SourceResolver resolver = null;
+ Source source = null;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = resolver.resolveURI(getSourceURI());
+ if (source.exists()) {
+ return source.getMimeType();
+ } else {
+ throw new SourceNotFoundException("The source [" + getSourceURI()
+ + "] does not exist!");
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ }
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java?view=diff&r1=161743&r2=161744
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java Mon Apr 18 01:54:26 2005
@@ -21,7 +21,6 @@
import org.apache.lenya.transaction.TransactionException;
import org.apache.lenya.transaction.Transactionable;
-import org.w3c.dom.Document;
/**
* Repository node.
@@ -31,16 +30,6 @@
public interface Node extends Transactionable {
/**
- * @return The DOM that holds the information.
- */
- Document getDocument();
-
- /**
- * @param document The DOM that holds the information.
- */
- void setDocument(Document document);
-
- /**
* The identifiable type.
*/
String IDENTIFIABLE_TYPE = "node";
@@ -62,5 +51,23 @@
* @throws TransactionException if the node does not exist.
*/
OutputStream getOutputStream() throws TransactionException;
+
+ /**
+ * @return The last modification date.
+ * @throws TransactionException if the node does not exist.
+ */
+ long getLastModified() throws TransactionException;
+
+ /**
+ * @return The content length.
+ * @throws TransactionException if the node does not exist.
+ */
+ long getContentLength() throws TransactionException;
+
+ /**
+ * @return The MIME type.
+ * @throws TransactionException if the node does not exist.
+ */
+ String getMimeType() throws TransactionException;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repository/SourceNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repository/SourceNode.java?view=diff&r1=161743&r2=161744
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/SourceNode.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/SourceNode.java Mon Apr 18 01:54:26 2005
@@ -22,14 +22,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.excalibur.source.ModifiableSource;
import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceNotFoundException;
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.ac.Identity;
import org.apache.lenya.ac.User;
@@ -41,8 +40,6 @@
import org.apache.lenya.transaction.IdentityMap;
import org.apache.lenya.transaction.Lock;
import org.apache.lenya.transaction.TransactionException;
-import org.apache.lenya.xml.DocumentHelper;
-import org.w3c.dom.Document;
/**
* A repository node.
@@ -69,21 +66,6 @@
this.identityMap = map;
}
- /**
- * @see org.apache.lenya.cms.repository.Node#getDocument()
- */
- public Document getDocument() {
- Document document = null;
- try {
- if (exists()) {
- document = DocumentHelper.readDocument(getInputStream());
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return document;
- }
-
protected String getUserId() {
String userId = null;
Identity identity = this.identityMap.getUnitOfWork().getIdentity();
@@ -344,32 +326,6 @@
}
/**
- * @see org.apache.lenya.cms.repository.Node#setDocument(org.w3c.dom.Document)
- */
- public void setDocument(Document document) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Setting document [" + document.getDocumentElement().getNodeName()
- + "]");
- }
-
- Writer writer = null;
- try {
- writer = new OutputStreamWriter(getOutputStream());
- DocumentHelper.writeDocument(document, writer);
- } catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException e1) {
- throw new RuntimeException(e1);
- }
- }
- }
- }
-
- /**
* @see org.apache.lenya.cms.repository.Node#exists()
*/
public boolean exists() throws TransactionException {
@@ -465,6 +421,87 @@
public void close() throws IOException {
SourceNode.this.data = super.toByteArray();
super.close();
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.repository.Node#getContentLength()
+ */
+ public long getContentLength() throws TransactionException {
+ SourceResolver resolver = null;
+ Source source = null;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = resolver.resolveURI(getRealSourceURI());
+ if (source.exists()) {
+ return source.getContentLength();
+ } else {
+ throw new SourceNotFoundException("The source [" + getRealSourceURI()
+ + "] does not exist!");
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.repository.Node#getLastModified()
+ */
+ public long getLastModified() throws TransactionException {
+ SourceResolver resolver = null;
+ Source source = null;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = resolver.resolveURI(getRealSourceURI());
+ if (source.exists()) {
+ return source.getLastModified();
+ } else {
+ throw new TransactionException("The source [" + getRealSourceURI()
+ + "] does not exist!");
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.repository.Node#getMimeType()
+ */
+ public String getMimeType() throws TransactionException {
+ SourceResolver resolver = null;
+ Source source = null;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = resolver.resolveURI(getRealSourceURI());
+ if (source.exists()) {
+ return source.getMimeType();
+ } else {
+ throw new SourceNotFoundException("The source [" + getRealSourceURI()
+ + "] does not exist!");
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java?view=diff&r1=161743&r2=161744
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java Mon Apr 18 01:54:26 2005
@@ -16,21 +16,15 @@
*/
package org.apache.lenya.cms.site.usecases;
-import java.text.DateFormat;
import java.util.Arrays;
-import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.cocoon.servlet.multipart.Part;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceResolver;
-import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.Resource;
import org.apache.lenya.cms.publication.ResourcesManager;
import org.apache.lenya.cms.site.usecases.SiteUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
-import org.apache.lenya.xml.DocumentHelper;
/**
* Usecase to add Assets to a resource.
@@ -67,10 +61,8 @@
super.initParameters();
ResourcesManager resourcesManager = null;
- SourceResolver resolver = null;
try {
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
resourcesManager = (ResourcesManager) this.manager.lookup(ResourcesManager.ROLE);
Resource[] resources = resourcesManager.getResources(getSourceDocument());
Modified: lenya/trunk/src/webapp/lenya/usecases/tab/assets.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/tab/assets.jx?view=diff&r1=161743&r2=161744
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/tab/assets.jx (original)
+++ lenya/trunk/src/webapp/lenya/usecases/tab/assets.jx Mon Apr 18 01:54:26 2005
@@ -40,22 +40,23 @@
<tr>
<td><jx:out value="${asset.getName()}"/></td>
<td>
- <!--
- <jx:if test="${item.format.equals('image/jpeg') or item.format.equals('image/gif') or item.format.equals('image/png')}">
- <img src="../authoring/${usecase.getParameter('documentname')}/${item.source}" style="height: 32px; vertical-align: middle;"/> 
+ <jx:set var="mimeType" value="${asset.getMimeType()}"/>
+ <jx:if test="${mimeType.startsWith('image/')}">
+ <jx:set var="doc" value="${usecase.getParameter('document')}"/>
+ <img src="${request.getContextPath()}/${doc.getPublication().getId()}/authoring/${doc.getId()}/${asset.getName()}"
+ style="height: 32px; vertical-align: middle;"/> 
</jx:if>
- -->
</td>
<td><jx:out value="${asset.getMetaData().getFirstValue('title')}"/></td>
- <td align="right"><!--<jx:out value="${item.extent}"/> kB--></td>
- <td align="right"><!--<jx:out value="${item.date}"/>--></td>
+ <td align="right"><jx:out value="${asset.getContentLength() / 1000}"/> kB</td>
+ <td align="right"><jx:out value="${java.text.DateFormat.getDateInstance().format(asset.getLastModified())}"/></td>
<td>
<form method="POST">
- <input type="hidden" name="lenya.usecase" value="${request.getParameter('lenya.usecase')}"/>
+ <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
<input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
- <input type="hidden" name="delete" value="${item.source}"/>
+ <input type="hidden" name="delete" value="${asset.getName()}"/>
<jx:choose>
- <jx:when test="${usecase.getParameter('area').equals('authoring')}"><input i18n:attr="value" name="submit" type="submit" value="Delete"/></jx:when>
+ <jx:when test="${usecase.getParameter('document').getArea().equals('authoring')}"><input i18n:attr="value" name="submit" type="submit" value="Delete"/></jx:when>
<jx:otherwise><input i18n:attr="value" type="submit" disabled="disabled" value="Delete"/></jx:otherwise>
</jx:choose>
</form>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org