Package nz.govt.natlib.fx

Examples of nz.govt.natlib.fx.DataSource


    return "2.0";
  }

  public void adapt(File file, ParserContext ctx) throws IOException {
    // add the MetaData to the tree!
    DataSource ftk = null;
   
    try {
      ftk = new FileDataSource(file);
     
      ctx.fireStartParseEvent("WAV");
      writeFileInfo(file, ctx);
 
      ctx.fireStartParseEvent("RIFF");
 
      // move 4 bytes in (for the RIFF tag)
      ftk.setPosition(4);
      riffElement.read(ftk, ctx);
 
      ctx.fireEndParseEvent("RIFF");
 
      // 1. is there a chunk to be read...
      long chunkSize = 12;
      long riffHeaderLength = ctx.getIntAttribute("WAV.RIFF.length");
      while (chunkSize < riffHeaderLength) {
        // 2. read the chunk...
        // get the file position...
        long startPos = ftk.getPosition();
        long reportedLength = 0;
        // read the type;
        String st = FXUtil.getFixedStringValue(ftk, 4);
 
        // 3. process the chunk...
        Element parser = null;
        // get data for the type of block it is...
        if ("fmt ".equals(st)) {
          ctx.fireStartParseEvent("Wave");
          ctx.fireParseEvent("type", st);
          wavElement.read(ftk, ctx);
          ctx.fireEndParseEvent("Wave");
          reportedLength = ctx.getIntAttribute("WAV.Wave.length");
          // break; // only want the first format tag...
        } else if ("data".equals(st)) {
          ctx.fireStartParseEvent("data");
          ctx.fireParseEvent("type", st);
          genericElement.read(ftk, ctx);
          ctx.fireEndParseEvent("data");
          reportedLength = ctx.getIntAttribute("WAV.data.length");
        } else if ("bext".equals(st)) {
          // System.out.println("Broadcast Wave Format extension chunk
          // found");
          ctx.fireStartParseEvent("bext");
          ctx.fireParseEvent("type", st);
          bextElement.read(ftk, ctx);
          ctx.fireEndParseEvent("bext");
          reportedLength = ctx.getIntAttribute("WAV.bext.length");
 
          // debug the bext
          // System.out.println("BEXT ->");
          // for (int i=0;i<bextNames.length;i++) {
          // System.out.println(bextNames[i]+"="+ctx.getAttribute("WAV.bext."+bextNames[i]));
          // }
        } else {
          // System.out.println("Unknown RIFF chunk :"+st);
          ctx.fireStartParseEvent("unknown");
          ctx.fireParseEvent("type", st);
          genericElement.read(ftk, ctx);
          ctx.fireEndParseEvent("unknown");
          reportedLength = ctx.getIntAttribute("WAV.unknown.length");
        }
 
        // work out if there is any padding at the end of the chunk
        long endPos = ftk.getPosition();
        long moveTo = startPos + reportedLength + 8; // the 8's 'cause
        // there's a 2 word
        // format/length
        // added to the
        // chunk at the
        // start
 
        // repositioning
        // System.out.println("Repo :");
        // System.out.println(" Reported Length :"+reportedLength);
        // System.out.println(" End :"+endPos);
        // System.out.println(" Start :"+startPos);
        // System.out.println(" Move Formula :"+moveTo);
 
        // 4. move the file pointer to the next chunk...
        ftk.setPosition(moveTo);
        // 5. loop...
        chunkSize += (reportedLength + 8);
      }
      ctx.fireEndParseEvent("WAV");
    }
View Full Code Here


   */
  public boolean acceptsFile(File file) {

    // Start by assuming that this is not a bitmap.   
    boolean bmp = false;
    DataSource ftk = null;
   
    try {
      // Start to read the bitmap, and make sure that the first
      // two bytes are "BM", which is the standard "magic bytes" for
      // a bitmap file.
View Full Code Here

  public String getVersion() {
    return "1.0";
  }

  public void adapt(File file, ParserContext ctx) throws IOException {
    DataSource ftk = new FileDataSource(file);

    // Open the BMP section of the metadata file. Part of the
    // bmp.dtd defintion is that the native format starts with an
    // opening <BMP> tag.
    ctx.fireStartParseEvent("BMP");

    // Extract the basic file metadata. This includes things like
    // last modified date and so forth.
    writeFileInfo(file, ctx);

    // Extract information from the header element.
    ctx.fireStartParseEvent("header");
    headerElement.read(ftk, ctx);
    ctx.fireEndParseEvent("header");

    // Extract information from the "information" element.
    ctx.fireStartParseEvent("information");
    infoHeaderElement.read(ftk, ctx);
    ctx.fireEndParseEvent("information");

    // is there a color map? We can check from the "bitcount" attribute
    // found in the "information" element.
    if (ctx.getIntAttribute("BMP.information.bitcount") <= 8) {

      // Using metadata already extracted, we can move to the right place
      // in the file...
      long length = ctx.getIntAttribute("BMP.information.length");
      long colors = ctx.getIntAttribute("BMP.information.colors");
      ftk.setPosition(ftk.getPosition() + (40 - length));

      // Now iterate through each color and write out a color index
      // metadata section.
      for (int i = 0; i < colors; i++) {
        ctx.fireStartParseEvent("color");
        ctx.fireParseEvent("index", i);
        colorTableElement.read(ftk, ctx);
        ctx.fireEndParseEvent("color");
      }
    }

    // We must now close the root <BMP> tag.
    ctx.fireEndParseEvent("BMP");

    // Close the datasource.
    ftk.close();
  }
View Full Code Here

    }
    return false;
  }

  public void process(File file, ParserContext ctx) throws IOException {
    DataSource ftk = new FileDataSource(file);
    FIB pFib = new FIB(Word2LanguageMap.getLanguageMap(),
        Word2Adapter.Offset_To_DOP);

    ctx.fireStartParseEvent("header");
    WordUtils.getHeader(ftk, ctx);
    ctx.fireEndParseEvent("header");

    ctx.fireStartParseEvent("FIB");
    pFib.read(ftk, ctx);
    ctx.fireEndParseEvent("FIB");

    // Check fib is good
    ftk.setPosition(Offset_To_sttbfAssoc);
    int iSttbAssocFP = (int) FXUtil.getNumericalValue(ftk,
        IntegerElement.INT_SIZE, false);

    // Set position in file to the summary strings start
    // Skip first bytes
    ftk.setPosition(iSttbAssocFP + 2);

    String assocFileNext = FXUtil.getPascalStringValue(ftk);
    String assocDot = FXUtil.getPascalStringValue(ftk);
    String assocTitle = FXUtil.getPascalStringValue(ftk);
    String subject = FXUtil.getPascalStringValue(ftk);
    String AssocKeysWords = FXUtil.getPascalStringValue(ftk);
    String Comments = FXUtil.getPascalStringValue(ftk);
    String Author = FXUtil.getPascalStringValue(ftk);
    String LastRevBy = FXUtil.getPascalStringValue(ftk);

    ctx.fireStartParseEvent("summary");
    ctx.fireParseEvent("template", assocDot);
    ctx.fireParseEvent("title", assocTitle);
    ctx.fireParseEvent("subject", subject);
    ctx.fireParseEvent("keywords", AssocKeysWords);
    ctx.fireParseEvent("comments", Comments);
    ctx.fireParseEvent("lastReviewedBy", LastRevBy);
    ctx.fireParseEvent("author", Author);
    ctx.fireEndParseEvent("summary");

    ctx.fireStartParseEvent("Properties");
    long dopPos = ctx.getIntAttribute("Word.FIB.dopOffset");
    WordUtils.getDOPProperties(ftk, (int) dopPos, ctx);
    ctx.fireParseEvent("Application", "Word 2.0");
    ctx.fireEndParseEvent("Properties");
    ftk.close();
  }
View Full Code Here

      this.into = into;
    }

    public void processPOIFSReaderEvent(POIFSReaderEvent event) {

      DataSource ftk = null;
      try {
        long dopPos = into.getIntAttribute("MSExcel.FIB.dopOffset");
        ftk = new DocumentDataSource(event.getStream());
        into.fireStartParseEvent("Properties");
        OLEUtils.getDOPProperties(ftk, (int) dopPos, into);
        into.fireEndParseEvent("Properties");
      } catch (Exception ex) {
        ex.printStackTrace();
      } finally {
        if (ftk != null) {
          try {
            ftk.close();
          } catch (Exception ex) {
            ;
          }
        }
      }
View Full Code Here

    public MainStreamReader(ParserContext into) {
      this.into = into;
    }

    public void processPOIFSReaderEvent(POIFSReaderEvent event) {
      DataSource ftk = null;
      try {
        ftk = new DocumentDataSource(event.getStream());

        into.fireStartParseEvent("header");
        OLEUtils.getHeader(ftk, into);
        into.fireEndParseEvent("header");

        // FIB oFib = new FIB(langMap,Offset_To_DOP);
        // into.fireStartParseEvent("FIB");
        // oFib.read(ftk,into);
        // into.fireEndParseEvent("FIB");

        // processText(oFib,ftk, into);
      } catch (Exception ex) {
        ex.printStackTrace();
      } finally {
        if (ftk != null) {
          try {
            ftk.close();
          } catch (Exception ex) {
            ;
          }
        }
      }
View Full Code Here

public class PDFAdapter extends DataAdapter {

  public boolean acceptsFile(File file) {
    boolean pdf = false;
    try {
      DataSource ftk = new FileDataSource(file);
      // Header and default information
      String head = FXUtil.getFixedStringValue(ftk, 4);
      if ((head.toLowerCase().equals("%pdf"))) {
        // version follows - but this adpater will do all!
        pdf = true;
      }
      ftk.close();
    } catch (IOException ex) {
      LogManager.getInstance().logMessage(LogMessage.WORTHLESS_CHATTER,
          "IO Exception determining PDF file type");
    }
    return pdf;
View Full Code Here

  public boolean acceptsFile(File file) {
    boolean gif = false;
   
    try {
      // Read the header bytes to check if this really is a GIF.
      DataSource ftk = new FileDataSource(file);
      // Header and default information
      String head = FXUtil.getFixedStringValue(ftk, 6);
      if ((head.toLowerCase().equals("gif87a"))
          || (head.toLowerCase().equals("gif89a"))) {
        gif = true;
      }
      ftk.close();
    } catch (IOException ex) {
      LogManager.getInstance().logMessage(LogMessage.WORTHLESS_CHATTER,
          "IO Exception determining GIF file type");
    }
    return gif;
View Full Code Here

    return "image/gif";
  }

  public void adapt(File oFile, ParserContext ctx) throws IOException {
    // Add the MetaData to the tree!
    DataSource ftk = new FileDataSource(oFile);
    // Header and default information
    ctx.fireStartParseEvent("GIF");
    writeFileInfo(oFile, ctx);
    try {
      gifHeaderElement.read(ftk, ctx);

      String version = ((String) ctx.getAttribute("GIF.version"))
          .toLowerCase();
      // this is where the standards file formats diverge
      if (version.equals("87a")) {
        gifScreenElement87a.read(ftk, ctx);
      } else if (version.equals("89a")) {
        gifScreenElement89a.read(ftk, ctx);
      } else {
        throw new RuntimeException("Unknown GIF Version :" + version);
      }

      // now jump over the global colour map.
      boolean hasGlobalMap = ctx
          .getBooleanAttribute("GIF.PACKED.global-map");
      // System.out.println(hasGlobalMap);
      if (hasGlobalMap) {
        int bitsPerPixel = (int) ctx
            .getIntAttribute("GIF.PACKED.bits-per-pixel");
        readColorTable(ftk, ctx, bitsPerPixel);
      }

      // start reading all the blocks...
      int imgC = 1;
      boolean clean = false;
      while (true) {
        long b = FXUtil.getNumericalValue(ftk.getData(1), false);

        // System.out.println("Block head "+b+"
        // ("+Integer.toHexString((int)b)+")");
        if (b == 0x21) {
          /* Control Block */
          // there are different kinds of control block...
          long sb = FXUtil.getNumericalValue(ftk.getData(1), false);
          if (sb == 0xf9) {
            ctx.fireStartParseEvent("control-block");
            ctx.fireParseEvent("sequence", imgC);
            gifControlElement89a.read(ftk, ctx);
            ctx.fireEndParseEvent("control-block");
          } else if (sb == 0x01) {
            // plain text
            ctx.fireStartParseEvent("text");
            gifPlainTextElement89a.read(ftk, ctx);
            int blocks = readSubBlocks(ftk, ctx, false);
            ctx.fireEndParseEvent("text");

          } else if (sb == 0xfe) {
            // plain text
            ctx.fireStartParseEvent("comment");
            int blocks = readSubBlocks(ftk, ctx, false);
            ctx.fireEndParseEvent("comment");
          } else if (sb == 0xff) {
            ctx.fireStartParseEvent("application");
            gifApplicationElement.read(ftk, ctx);
            int blocks = readSubBlocks(ftk, ctx, true);
            ctx.fireParseEvent("data-blocks", blocks);
            ctx.fireEndParseEvent("application");
          } else {
            // System.out.println("unknown extension block "+sb+" at
            // "+(ftk.getPosition()-1));
            // can we recover and move on... No!
            throw new RuntimeException("unknown extension block "
                + sb + " at " + (ftk.getPosition()));
          }
        } else if (b == 0x3b) {
          /* Terminator */
          clean = true;
          break;
        } else if (b == 0x2c) {
          /* The Image... */
          ctx.fireStartParseEvent("image-info");
          ctx.fireParseEvent("sequence", imgC);
          gifImageElement.read(ftk, ctx);

          // move the pointer along to the next block (skip local
          // color table and image data)
          boolean hasLocalMap = ctx
              .getBooleanAttribute("GIF.image-info.PACKED.has-local-map");
          if (hasLocalMap) {
            int bitsPerPixel = (int) ctx
                .getIntAttribute("GIF.PACKED.image-bits-per-pixel");
            readColorTable(ftk, ctx, bitsPerPixel);
          }

          // ...and the image data itself...
          byte lzwMinCodeSize = ftk.getData(1)[0];
          int blocks = readSubBlocks(ftk, ctx, true);
          ctx.fireParseEvent("data-blocks", blocks);

          // done!
          ctx.fireEndParseEvent("image-info");
          imgC++;
        } else {
          /* Unknown */
          clean = false;
          break;
        }
      }

      ctx.fireParseEvent("frames", imgC - 1);
      ctx.fireParseEvent("clean-termination", clean);
      ctx.fireParseEvent("animated", imgC > 2 ? "true" : "false");

    } catch (Exception ex) {
      ex.printStackTrace();
      ex.fillInStackTrace();
      throw new RuntimeException(ex);
    } finally {
      ctx.fireEndParseEvent("GIF");
      ftk.close();
    }
  }
View Full Code Here

    return "1.1";
  }

  public boolean acceptsFile(File file) {
    boolean jpg = false;
    DataSource ftk = null;
    try {
      // Read the header and see if this appears to be a JPG.
      ftk = new FileDataSource(file);
      // Header and default information
      JpgMarker marker = null;
View Full Code Here

TOP

Related Classes of nz.govt.natlib.fx.DataSource

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.