Package es.ipsa.atril.doc.user

Examples of es.ipsa.atril.doc.user.Item


  }

  public void insertContentFromFile(AtrilSession oSes, File oFile)
    throws ElementNotFoundException, IOException {
    String sItemName = Gadgets.removeChars(oFile.getName(), "\"\\/?*:|<>;&");
    Item item = getDocument().item();
    item.setName(sItemName);
    item.insertContentFrom(oFile);
    Log.out.debug(getClass().getName()+".insertContentFromFile("+oFile.getName()+")");
    DAO.log(oSes, getDocument(), getClass(), "INSERT ITEM", AtrilEvent.Level.INFO, sItemName);
  }
View Full Code Here


    DAO.log(oSes, getDocument(), getClass(), "INSERT ITEM", AtrilEvent.Level.INFO, sItemName);
  }
   
  public void insertContentFromInputStream(AtrilSession oSes, InputStream instrm, String sItemName)
    throws ElementNotFoundException, IOException {
    Item item = getDocument().item();
    sItemName = Gadgets.removeChars(sItemName, "\"\\/?*:|<>;&");
    item.setName(sItemName);
    OutputStream outstrm = item.getOutputStream();
    StreamPipe pipe = new StreamPipe();
    pipe.between(instrm, outstrm);
    outstrm.close();
    Log.out.debug(getClass().getName()+".insertContentFromInputStream("+sItemName+")");
    DAO.log(oSes, getDocument(), getClass(), "INSERT ITEM", AtrilEvent.Level.INFO, sItemName);
View Full Code Here

      try {
        oSes = DAO.getAdminSession("ThumbnailCreator");
        oSes.autoCommit(true);
        Dms oDms = oSes.getDms();
        Document oDoc = oDms.getDocument(sParent);
        Item oItm = oDms.getDocument(sItem).item();
        String sFileName = oItm.name().toLowerCase();
        oPipe = new StreamPipe();
        ByteArrayOutputStream oByOut = new ByteArrayOutputStream();
        if (sFileName.endsWith(".pdf")) {
          Log.out.debug("Item.getInputStreamTranscodedToMime(image/jpeg)");
          oPipe.between(oItm.getInputStreamTranscodedToMime("image/jpeg"), oByOut);
        } else {
            Log.out.debug("Item.getInputStream()");
            oPipe.between(oItm.getInputStream(), oByOut);         
        }
        byte[] aBytes = oByOut.toByteArray();
        oByOut.close();
        oByOut = null;
        Log.out.debug("new Picture()");
        Picture oPic = new Picture();
        Log.out.debug("Before Picture.dimensions()");
        int[] aWidthHeight = oPic.dimensions(aBytes, "jpeg");
        Log.out.debug("After Picture.dimensions()");
        if (null==aWidthHeight)
          throw new NullPointerException("Unable to get dimensions for image "+oItm.name());
        Log.out.debug("Image width="+String.valueOf(aWidthHeight[0])+" height="+String.valueOf(aWidthHeight[1]));
        int iWidth, iHeight;
        if (aWidthHeight[0]<=MaxWidth && aWidthHeight[0]<=MaxHeight) {
          iWidth = aWidthHeight[0];
          iHeight = aWidthHeight[1];
        } else {
          float fWidthRatio = ((float) aWidthHeight[0]) / MaxWidth;
          float fHeightRatio = ((float) aWidthHeight[1]) / MaxHeight;
          if (fWidthRatio>fHeightRatio) {
            iWidth = (int) MaxWidth;
            iHeight = (int) (MaxWidth*aWidthHeight[1])/aWidthHeight[0];
          } else {
            iWidth = (int) (aWidthHeight[0]*MaxHeight)/aWidthHeight[1];
            iHeight = (int) MaxHeight;
          }
        }
        Log.out.debug("Resampled width="+String.valueOf(iWidth)+" height="+String.valueOf(iHeight));
        String sCodec = null;
        if (sFileName.endsWith(".jpg") || sFileName.endsWith(".jpeg") || sFileName.endsWith(".pdf"))
          sCodec = "jpeg";
        else if (sFileName.endsWith(".gif"))
          sCodec = "gif";
        else if (sFileName.endsWith(".tif") || sFileName.endsWith(".tiff"))
          sCodec = "tiff";
        else {
          Log.out.error("ThumbnailCreator.run()  Could not find suitable codec for file "+oItm.name());
          throw new InstantiationException("Could not find suitable codec for file "+oItm.name());
        }
        Log.out.debug("Picture.createThumbBitmap("+sCodec+","+String.valueOf(iWidth)+","+String.valueOf(iHeight)+",80)");
        byte[] byThumb = oPic.createThumbBitmap(aBytes, sCodec, iWidth, iHeight, 80);
       
        Document oThl = oDms.newDocument(oDms.getDocumentType(oDoc.type().name()+"Thumbnail"), oDoc);
        AttributeMultiValue oAtr = oThl.attribute("width");
      oAtr.set((long) iWidth);
      oAtr = oThl.attribute("height");
      oAtr.set((long) iHeight);
      oThl.save("");
        Item oThi = oThl.item();
        String sItemName = "th"+oDoc.id()+".jpg";
        oThi.setName(sItemName);
        oThi.mimeType("image/jpeg");
        OutputStream oOutStrm = oThi.getOutputStream();
        oPipe = new StreamPipe();
        oPipe.between(new ByteArrayInputStream(byThumb), oOutStrm);
        oThl.save("");
        oOutStrm.close();
        Log.out.debug("Thumbnail creation done");
View Full Code Here

TOP

Related Classes of es.ipsa.atril.doc.user.Item

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.