Author: andreas
Date: Sun Apr 13 02:13:27 2008
New Revision: 647545
URL: http://svn.apache.org/viewvc?rev=647545&view=rev
Log:
Adding method to update the size meta data of images.
Modified:
lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java
Modified: lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java?rev=647545&r1=647544&r2=647545&view=diff
==============================================================================
--- lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java (original)
+++ lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java Sun Apr 13 02:13:27 2008
@@ -45,6 +45,7 @@
*/
public class ResourceWrapper extends AbstractLogEnabled {
+ protected static final String MEDIA_METADATA_NAMESPACE = "http://apache.org/lenya/metadata/media/1.0";
private ServiceManager manager;
private Document document;
@@ -141,7 +142,7 @@
OutputStream destOutputStream = null;
try {
- mediaMeta = document.getMetaData("http://apache.org/lenya/metadata/media/1.0");
+ mediaMeta = document.getMetaData(MEDIA_METADATA_NAMESPACE);
addResourceMeta(fileName, mimeType, input, mediaMeta);
destOutputStream = document.getOutputStream();
@@ -159,12 +160,30 @@
if (getLogger().isDebugEnabled())
getLogger().debug("Resource::addResource() done.");
}
+
+ /**
+ * Updates the image width and height depending on the content, if possible.
+ */
+ public void updateImageDimensions() {
+ Document doc = getDocument();
+ try {
+ updateImageDimensions(doc.getMimeType(), doc.getInputStream(), doc.getMetaData(MEDIA_METADATA_NAMESPACE));
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
protected void addResourceMeta(String fileName, String mimeType, InputStream stream,
MetaData customMeta) throws MetaDataException, IOException {
if (customMeta != null) {
customMeta.setValue("filename", fileName);
}
+ updateImageDimensions(mimeType, stream, customMeta);
+ }
+
+ protected void updateImageDimensions(String mimeType, InputStream stream, MetaData customMeta)
+ throws IOException, MetaDataException {
if (canReadMimeType(mimeType)) {
BufferedImage input = ImageIO.read(stream);
String width = Integer.toString(input.getWidth());
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.