You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by mi...@apache.org on 2010/06/29 18:32:40 UTC
svn commit: r959022 -
/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations...
Author: mir
Date: Tue Jun 29 16:32:40 2010
New Revision: 959022
URL: http://svn.apache.org/viewvc?rev=959022&view=rev
Log:
CLEREZZA-248: reverted back
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/AlternativeRepresentationGenerator.java
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/ThumbnailService.java
Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/AlternativeRepresentationGenerator.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/AlternativeRepresentationGenerator.java?rev=959022&r1=959021&r2=959022&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/AlternativeRepresentationGenerator.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/AlternativeRepresentationGenerator.java Tue Jun 29 16:32:40 2010
@@ -25,7 +25,6 @@ import java.io.IOException;
import javax.imageio.ImageIO;
import javax.ws.rs.core.MediaType;
import org.apache.clerezza.platform.content.DiscobitsHandler;
-import org.apache.clerezza.platform.content.InfoDiscobit;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
@@ -35,7 +34,6 @@ import org.apache.clerezza.utils.imagepr
import org.apache.clerezza.rdf.ontologies.DISCOBITS;
import org.apache.clerezza.rdf.utils.GraphNode;
import org.apache.clerezza.rdf.metadata.MetaDataGenerator;
-import org.apache.felix.scr.annotations.Services;
import org.osgi.service.component.ComponentContext;
import org.osgi.util.tracker.ServiceTracker;
@@ -49,11 +47,7 @@ import org.osgi.util.tracker.ServiceTrac
* @author mir
*/
@Component(metatype=true)
-@Services({
- @Service(MetaDataGenerator.class),
- @Service(AlternativeRepresentationGenerator.class)
-})
-
+@Service(MetaDataGenerator.class)
public class AlternativeRepresentationGenerator implements MetaDataGenerator {
private static class Resolution {
@@ -73,17 +67,6 @@ public class AlternativeRepresentationGe
height = new Integer(widthAndHeight[1]);
}
- /**
- * A Resolution with the specified width and height.
- *
- * @param width
- * @param height
- */
- public Resolution(int width, int height) {
- this.width = width;
- this.height = height;
- }
-
public int getHeight() {
return height;
}
@@ -147,52 +130,31 @@ public class AlternativeRepresentationGe
return;
}
if (mediaType.getType().startsWith("image")) {
- generateAlternativeImages(data, mediaType, node);
- }
- }
-
- public UriRef generateAlternativeImage(GraphNode infoBitNode, int width, int height) {
- try {
- isAltRepresentation.set(Boolean.TRUE);
- InfoDiscobit infoBit = new InfoDiscobit(infoBitNode);
- BufferedImage buffImage = ImageIO.read(new ByteArrayInputStream(infoBit.getData()));
- return generateAlternativeImage(buffImage, new Resolution(width, height),
- MediaType.valueOf(infoBit.getContentType()), infoBitNode);
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- } finally {
- isAltRepresentation.set(Boolean.FALSE);
- }
- }
-
- private void generateAlternativeImages(byte[] data, MediaType mediaType, GraphNode node) throws RuntimeException {
- try {
- isAltRepresentation.set(Boolean.TRUE);
- BufferedImage buffImage = ImageIO.read(new ByteArrayInputStream(data));
- int imgWidth = buffImage.getWidth();
- int imgHeigth = buffImage.getHeight();
- for (Resolution resolution : resolutions) {
- if (imgWidth > resolution.getWidth() || imgHeigth > resolution.getHeight()) {
- generateAlternativeImage( buffImage, resolution, mediaType, node);
+ try {
+ isAltRepresentation.set(Boolean.TRUE);
+ BufferedImage buffImage = ImageIO.read(new ByteArrayInputStream(data));
+ int imgWidth = buffImage.getWidth();
+ int imgHeigth = buffImage.getHeight();
+ for (Resolution resolution : resolutions) {
+ if (imgWidth > resolution.getWidth() ||
+ imgHeigth > resolution.getHeight()){
+ BufferedImage alternativeImage = imageProcessor.makeAThumbnail(
+ buffImage, resolution.getWidth(), resolution.getHeight());
+ byte[] alternativeImageBytes = bufferedImage2ByteArray(alternativeImage, mediaType);
+ DiscobitsHandler contentHandler = (DiscobitsHandler)discobitTracker.getService();
+ UriRef thumbnailUri = createThumbnailUri((UriRef) node.getNode(), alternativeImage);
+ contentHandler.put(thumbnailUri, mediaType, alternativeImageBytes);
+ node.addProperty(DISCOBITS.thumbnail, thumbnailUri);
+ }
}
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ } finally {
+ isAltRepresentation.set(Boolean.FALSE);
}
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- } finally {
- isAltRepresentation.set(Boolean.FALSE);
}
}
- private UriRef generateAlternativeImage(BufferedImage buffImage, Resolution resolution, MediaType mediaType, GraphNode node) throws IOException {
- BufferedImage alternativeImage = imageProcessor.makeAThumbnail(buffImage, resolution.getWidth(), resolution.getHeight());
- byte[] alternativeImageBytes = bufferedImage2ByteArray(alternativeImage, mediaType);
- DiscobitsHandler contentHandler = (DiscobitsHandler) discobitTracker.getService();
- UriRef thumbnailUri = createThumbnailUri((UriRef) node.getNode(), alternativeImage);
- contentHandler.put(thumbnailUri, mediaType, alternativeImageBytes);
- node.addProperty(DISCOBITS.thumbnail, thumbnailUri);
- return thumbnailUri;
- }
-
private byte[] bufferedImage2ByteArray(BufferedImage image,
MediaType mediaType) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/ThumbnailService.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/ThumbnailService.java?rev=959022&r1=959021&r2=959022&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/ThumbnailService.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/ThumbnailService.java Tue Jun 29 16:32:40 2010
@@ -72,13 +72,10 @@ public class ThumbnailService implements
ContentGraphProvider cgProvider;
@Reference
PlatformConfig config;
- @Reference
- AlternativeRepresentationGenerator altRepGen;
-
private static final Logger log = LoggerFactory.getLogger(ThumbnailService.class);
private BundleContext bundleContext;
private String STATICWEB_PATH = "/org/apache/clerezza/web/resources/style/staticweb/";
- private String MEDIA_TYPE_BASE_PATH = STATICWEB_PATH + "images/icons/mediatype/";
+ private String BASE_PATH = STATICWEB_PATH + "images/icons/mediatype/";
private Bundle cachedStyleBundle = null;
private Map<MediaType, String> mediaTypeIconUriCache =
Collections.synchronizedMap(new HashMap<MediaType, String>());
@@ -100,11 +97,9 @@ public class ThumbnailService implements
* maximum width and height can optionally be specified over the query parameters
* "width" and "height". If more than one acceptable thumbnail is available
* then the thumbnail uri of the thumbnail with the highest resolution
- * (width * height) is returned. If no thumbnail is available and the logged
- * in user has the write permission for the content graph, then an attempt is
- * made to create the thumbnail on the fly. If this fails or the write permission
- * is missing, then the uri of the icon representing the media type is returned.
- * If also no media type icon is available the uri to default icon is returned.
+ * (width * height) is returned. If no thumbnail is available then the uri of
+ * the icon representing the media type is returned. If also no media type
+ * icon is available the uri to default icon is returned.
* @param infoBitUri the uri of the infoDiscoBit of which the thumbnail uri should be returned
* @param height the maximum height that the thumbnail has
* @param width the maximum width that the thumbnail has
@@ -112,8 +107,9 @@ public class ThumbnailService implements
*/
@GET
public Response getThumbnailUri(@QueryParam("uri") UriRef infoBitUri,
- @QueryParam("width") Integer width, @QueryParam("height") Integer height,
- @Context UriInfo uriInfo) {
+ @QueryParam("width") Integer width,
+ @QueryParam("height") Integer height,
+ @Context UriInfo uriInfo) {
if ((width == null) && (height == null)) {
throw new WebApplicationException(new IllegalArgumentException("height and/or width must be specified"),
Response.Status.BAD_REQUEST);
@@ -130,23 +126,10 @@ public class ThumbnailService implements
return Response.seeOther(
URI.create((thumbnailUri).getUnicodeString())).build();
}
-
-
Iterator<Resource> mediaTypes = infoBitNode.getObjects(DISCOBITS.mediaType);
if (mediaTypes.hasNext()) {
MediaType mediaType = MediaType.valueOf(LiteralFactory.getInstance().createObject(
String.class, (TypedLiteral) mediaTypes.next()));
- // if the infoBit is an image, create a thumbnail on the fly.
- if (mediaType.getType().startsWith("image")) {
- try {
- thumbnailUri = altRepGen.generateAlternativeImage(infoBitNode, width,
- height);
- return RedirectUtil.createSeeOtherResponse(thumbnailUri.getUnicodeString(), uriInfo);
- } catch (Exception ex) {
- // Was worth a try. eLets go on
- }
- }
-
String iconUri = mediaTypeIconUriCache.get(mediaType);
if (iconUri == null) {
iconUri = getMediaTypeIconUri(mediaType);
@@ -163,7 +146,7 @@ public class ThumbnailService implements
if (styleBundle == null) {
throw new RuntimeException("no style bundle found");
}
- String path = MEDIA_TYPE_BASE_PATH + mediaType.getType() + "/";
+ String path = BASE_PATH + mediaType.getType() + "/";
Enumeration entries = styleBundle.findEntries(path,
mediaType.getSubtype() + ".*", false);
String iconUri = createIconUri(entries);
@@ -179,7 +162,7 @@ public class ThumbnailService implements
}
private String getDefaultIconUrl(Bundle bundle) {
- Enumeration entries = bundle.findEntries(MEDIA_TYPE_BASE_PATH, "any.*", false);
+ Enumeration entries = bundle.findEntries(BASE_PATH, "any.*", false);
String iconUri = createIconUri(entries);
if (iconUri != null) {
return iconUri;