Author: mir
Date: Wed Dec 16 13:02:30 2009
New Revision: 891226
URL: http://svn.apache.org/viewvc?rev=891226&view=rev
Log:
CLEREZZA-25: changed exception handling. improved thumbnail uri creation. fixed
bug where thumbnails of thumbnails were created
Modified:
incubator/clerezza/issues/CLEREZZA-25/org.apache.clerezza.platform.content.thumbnails/src/main/java/org/apache/clerezza/platform/content/thumbnails/ThumbnailGenerator.java
incubator/clerezza/issues/CLEREZZA-25/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/AbstractDiscobitsHandler.java
Modified:
incubator/clerezza/issues/CLEREZZA-25/org.apache.clerezza.platform.content.thumbnails/src/main/java/org/apache/clerezza/platform/content/thumbnails/ThumbnailGenerator.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-25/org.apache.clerezza.platform.content.thumbnails/src/main/java/org/apache/clerezza/platform/content/thumbnails/ThumbnailGenerator.java?rev=891226&r1=891225&r2=891226&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-25/org.apache.clerezza.platform.content.thumbnails/src/main/java/org/apache/clerezza/platform/content/thumbnails/ThumbnailGenerator.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-25/org.apache.clerezza.platform.content.thumbnails/src/main/java/org/apache/clerezza/platform/content/thumbnails/ThumbnailGenerator.java
Wed Dec 16 13:02:30 2009
@@ -50,21 +50,29 @@
@Service(MetaDataGenerator.class)
public class ThumbnailGenerator implements MetaDataGenerator {
- @Property(intValue = 50, description = "Specifies the width of the
thumbnail.")
+ @Property(intValue = 90, description = "Specifies the width in pixel of
the thumbnail.")
private static final String THUMBNAIL_WIDTH = "thumbnailWidth";
- @Property(intValue = 50, description = "Specifies the height of the
thumbnail.")
+ @Property(intValue = 90, description = "Specifies the height in pixel
of the thumbnail.")
private static final String THUMBNAIL_HEIGHT = "thumbnailHeight";
@Reference
private ImageProcessor imageProcessor;
- private int widthThumbnail;
- private int heightThumbnail;
+ private int thumbnailWidth;
+ private int thumbnailHeight;
+
+ private ThreadLocal<Boolean> isThumbnail = new ThreadLocal<Boolean>() {
+
+ @Override
+ protected Boolean initialValue() {
+ return false;
+ }
+ };
private ServiceTracker discobitTracker;
protected void activate(ComponentContext context) {
- widthThumbnail = (Integer)
context.getProperties().get(THUMBNAIL_WIDTH);
- heightThumbnail = (Integer)
context.getProperties().get(THUMBNAIL_HEIGHT);
+ thumbnailWidth = (Integer)
context.getProperties().get(THUMBNAIL_WIDTH);
+ thumbnailHeight = (Integer)
context.getProperties().get(THUMBNAIL_HEIGHT);
discobitTracker = new ServiceTracker(context.getBundleContext(),
DiscobitsHandler.class.getName(), null);
@@ -83,20 +91,23 @@
@Override
public void generate(GraphNode node, byte[] data, MediaType mediaType) {
- if (node.getSubjects(DISCOBITS.thumbnail).hasNext()) {
+ if (isThumbnail.get()) {
return;
}
if (mediaType.getType().startsWith("image")) {
try {
BufferedImage buffImage = ImageIO.read(new
ByteArrayInputStream(data));
- BufferedImage thumbnail =
imageProcessor.makeAThumbnail(buffImage, widthThumbnail, heightThumbnail);
+ BufferedImage thumbnail =
imageProcessor.makeAThumbnail(buffImage, thumbnailWidth, thumbnailHeight);
byte[] thumbnailBytes =
bufferedImage2ByteArray(thumbnail, mediaType);
DiscobitsHandler contentHandler =
(DiscobitsHandler)discobitTracker.getService();
UriRef thumbnailUri =
createThumbnailUri((UriRef) node.getNode());
- node.addProperty(DISCOBITS.thumbnail,
thumbnailUri);
+ isThumbnail.set(Boolean.TRUE);
contentHandler.put(thumbnailUri, mediaType,
thumbnailBytes);
+ node.addProperty(DISCOBITS.thumbnail,
thumbnailUri);
} catch (IOException ex) {
- return;
+ throw new RuntimeException(ex);
+ } finally {
+ isThumbnail.set(Boolean.FALSE);
}
}
}
@@ -115,7 +126,9 @@
String oldUri = uriRef.getUnicodeString();
String newUri;
int lastIndexOfDot = oldUri.lastIndexOf(".");
- if (lastIndexOfDot >= (oldUri.length() - 4)) {
+ int lastIndexOfSlash = oldUri.lastIndexOf("/");
+ if (lastIndexOfSlash < lastIndexOfDot &&
+ lastIndexOfDot >= (oldUri.length() - 6)) {
String firstPart = oldUri.substring(0, lastIndexOfDot);
String lastPart = oldUri.substring(lastIndexOfDot,
oldUri.length());
newUri = firstPart + thumbnail + lastPart;
Modified:
incubator/clerezza/issues/CLEREZZA-25/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/AbstractDiscobitsHandler.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-25/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/AbstractDiscobitsHandler.java?rev=891226&r1=891225&r2=891226&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-25/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/AbstractDiscobitsHandler.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-25/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/AbstractDiscobitsHandler.java
Wed Dec 16 13:02:30 2009
@@ -33,6 +33,8 @@
import org.apache.clerezza.rdf.ontologies.DISCOBITS;
import org.apache.clerezza.rdf.ontologies.RDF;
import org.apache.clerezza.rdf.utils.GraphNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
@@ -40,6 +42,8 @@
*/
public abstract class AbstractDiscobitsHandler implements DiscobitsHandler {
+ private static final Logger logger =
LoggerFactory.getLogger(Editor.class);
+
/**
*
* @return the MGraph to be used to retrieve and create discobits
@@ -66,7 +70,11 @@
TypedLiteral mediaTypeLiteral =
LiteralFactory.getInstance().createTypedLiteral(mediaType.toString());
infoDiscoBitNode.addProperty(DISCOBITS.mediaType,mediaTypeLiteral);
for(MetaDataGenerator generator : getMetaDataGenerators()) {
- generator.generate(infoDiscoBitNode, data, mediaType);
+ try {
+ generator.generate(infoDiscoBitNode, data,
mediaType);
+ } catch (RuntimeException ex) {
+ logger.error("Exception in MetaDataGenerator ",
ex);
+ }
}
}