Mitkees & Webcenter

Into the charm of Oracle Webcenter and ADF

Webcenter Imaging : Delete a tif page from a multi TIF page


One of the best use of Oracle IPM is to act as a front-end to your Webcenter content . but Unfortunately, it has limited capabilities on a content so  I will show you how to extend its capabilities  using IPM APIs.

We can edit the View ( and view only) of the IPM to add buttons that fire actions in different web applications you have created for the logic you need.

In this post will show you steps how to extend the IPM Viewer Features by adding a button to delete a page from the content of type multi TIF.

  1. create a web application
  2. Add imaging-client.jar to the project class path in order to be able to use IPM APIs
  3. create class that have the Delete tif page logic as follows
  4. 
    import com.sun.media.jai.codec.FileSeekableStream;
    import com.sun.media.jai.codec.ImageCodec;
    import com.sun.media.jai.codec.ImageDecoder;
    import com.sun.media.jai.codec.ImageEncoder;
    import com.sun.media.jai.codec.TIFFEncodeParam;
    
    import java.awt.image.BufferedImage;
    import java.awt.image.RenderedImage;
    
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.media.jai.NullOpImage;
    import javax.media.jai.OpImage;
    import javax.media.jai.PlanarImage;
    
    public class TiffDeleterClass {
    public TiffDeleterClass() {
    super();
    }
    
    public String countPages(String DocumentID) throws IOException{
    String tempDirectory="D:\\Oracle\\Middleware\\user_projects\\domains\\MGRP_domain\\ucm\\cs\\vault\\~temp\\";
    String pagesCount="0";
    List images = new ArrayList();
    FileSeekableStream ss = new FileSeekableStream(tempDirectory+DocumentID);
    ImageDecoder dec = ImageCodec.createImageDecoder("tiff", ss, null);
    int count = dec.getNumPages();
    return ""+count;
    }
    public void deleteTifPage(String DocumentID,int pageNumber) throws IOException {
    String tempDirectory="c:\\ipm\\";
    int pageToBeDeleted = 1;
    List images = new ArrayList();
    FileSeekableStream ss = new FileSeekableStream(tempDirectory+DocumentID+".tif");
    ImageDecoder dec = ImageCodec.createImageDecoder("tiff", ss, null);
    int count = dec.getNumPages();
    // System.out.println(count);
    for (int i = 1; i <= count; i++) {
    if(i== pageToBeDeleted) continue;
    PlanarImage op = new NullOpImage(dec.decodeAsRenderedImage(i-1), null, null, OpImage.OP_IO_BOUND);
    images.add(op.getAsBufferedImage());
    }
    
    TIFFEncodeParam params = new TIFFEncodeParam();
    OutputStream out = new FileOutputStream(tempDirectory +"deleted\\"+DocumentID +".tif");
    ImageEncoder encoder = ImageCodec.createImageEncoder("tiff", out, params);
    List imageList = new ArrayList();
    for (int i = 1; i < images.size(); i++)
    {
    imageList.add((BufferedImage)images.get(i));
    }
    params.setExtraImages(imageList.iterator());
    params.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);
    encoder.encode(images.get(0));
    out.close();
    }
    }
    
  5. create  a page or servlet that get the request with the page need to be deleted and the contentID and call the needed method in the previous class.
  6. deploy the application and test it using the browser
  7. customize the IPM and add a button and set the action to be the page/servlet and pass the required paramters
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: