Package org.docx4j.openpackaging.io3.stores

Examples of org.docx4j.openpackaging.io3.stores.UnzippedPartStore


   
   
    // Load the docx
    File baseDir = new File(inputfilepath);
    UnzippedPartStore partLoader = new UnzippedPartStore(baseDir);
    final Load3 loader = new Load3(partLoader);
    OpcPackage opc = loader.get();
   
    // Save it zipped
    File docxFile = new File(System.getProperty("user.dir") + "/zip.docx");
   
    ZipPartStore zps = new ZipPartStore();
View Full Code Here


    startEvent.publish();     
   
    if (type.equals(Filetype.ZippedPackage)){
     
      final ZipPartStore partLoader = new ZipPartStore(is);
      final Load3 loader = new Load3(partLoader);
      OpcPackage opcPackage = loader.get();
     
      if (pkgIdentifier!=null) {
        opcPackage.setName(pkgIdentifier.name());
      }
     
      new EventFinished(startEvent).publish();           
      return opcPackage;
     
//      final LoadFromZipNG loader = new LoadFromZipNG();
//      return loader.get(is);     
     
    } else if (type.equals(Filetype.Compound)){
     
          try {
        POIFSFileSystem fs = new POIFSFileSystem(is);
        EncryptionInfo info = new EncryptionInfo(fs);
            Decryptor d = Decryptor.getInstance(info);
            d.verifyPassword(password);
           
        InputStream is2 = d.getDataStream(fs);
        final LoadFromZipNG loader = new LoadFromZipNG();
        return loader.get(is2);       
       
      } catch (java.security.InvalidKeyException e) {
            /* Wrong password results in:
             *
              Caused by: java.security.InvalidKeyException: No installed provider supports this key: (null)
View Full Code Here

    File docxFile = new File(System.getProperty("user.dir") + "/zip.docx");
   
    ZipPartStore zps = new ZipPartStore();
    zps.setSourcePartStore(opc.getSourcePartStore());
   
    Save saver = new Save(opc, zps);
    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(docxFile);
      saver.save(fos);
    } catch (FileNotFoundException e) {
      throw new Docx4JException("Couldn't save " + docxFile.getPath(), e);
    } finally {
      IOUtils.closeQuietly(fos);
    }     
View Full Code Here

        throw new Docx4JException("Exception marshalling document for output: " + e.getMessage(), e);
      }
    }
    else {
//      SaveToZipFile saver = new SaveToZipFile(wmlPackage);
      Save saver = new Save(this);
      saver.save(outStream);
    }
    new EventFinished(startEvent).publish();
 
View Full Code Here

    // We want to save images as they're created, so define our saver
    File baseDir = new File(System.getProperty("user.dir") + "/OUT_unzipped");
    baseDir.mkdir(); // TODO: directory should be empty, since old images won't get overwritten
   
    UnzippedPartStore ups = new UnzippedPartStore(baseDir);
    Save saver = new Save(wordMLPackage, ups);
   
   
    // Apply the bindings
   
//    if (hyperlinkStyle!=null) {
//      BindingHandler.getHyperlinkResolver().setHyperlinkStyle(hyperlinkStyle);
//    }
    BindingHandler bh = new BindingHandler(wordMLPackage);
    bh.applyBindings(wordMLPackage.getMainDocumentPart());
   
    // If you inspect the output, you should see your data in 2 places:
    // 1. the custom xml part
    // 2. (more importantly) the main document part
    System.out.println(
        XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)
        );
   
    // Strip content controls
    // RemovalHandler rh = new RemovalHandler(); // NB: this only removes if OpenDoPE tags are present (they aren't in binding-simple.docx)
   
    //wordMLPackage.save(new java.io.File(outputfilepath) );
   
    saver.save(null);
    // now zip up that dir, and rename to docx.
  }
View Full Code Here

    File baseDir = new File(System.getProperty("user.dir") + "/OUT");
    baseDir.mkdir();
   
    UnzippedPartStore ups = new UnzippedPartStore(baseDir);
    ups.setSourcePartStore(wordMLPackage.getSourcePartStore());
    Save saver = new Save(wordMLPackage, ups);
   
    saver.save(null);
  }
View Full Code Here

      log.warn("No package owns this part, and/or you didn't set its contents.");
      return null;       
    }
   
    // no cached buffer, try to load part data now     
    PartStore partStore = this.getPackage().getSourcePartStore();
    if (partStore==null) {
      log.warn("No PartStore configured for this package");
      return null;
    }
   
   
    InputStream is=null;
    try {
      String name = this.getPartName().getName();
     
      try {
        this.setContentLengthAsLoaded(
            partStore.getPartSize( name.substring(1)));
      } catch (UnsupportedOperationException uoe) {}
     
      is = partStore.loadPart( name.substring(1));
      if (is==null) {
        log.warn(name + " missing from part store");
      } else {
       
//        if (log.isDebugEnabled()) {
View Full Code Here

    if (jaxbElement==null) {
      if (this.getPackage()==null) {
        log.warn("This part not added to a package, so its contents can't be retrieved. " );
        return null;
      }
      PartStore partStore = this.getPackage().getSourcePartStore();
      if (partStore==null) {
        log.warn("No PartStore defined for this package (it was probably created, not loaded). " );
        log.warn(this.getPartName().getName() + ": did you initialise its contents to something?");
        return null;
        // or we could create it, with a bit of effort;
        // as to which see http://stackoverflow.com/questions/1090458/instantiating-a-generic-class-in-java
      }      
     
      try {
        String name = this.getPartName().getName();
       
        try {
          if (partStore!=null) {
            this.setContentLengthAsLoaded(
                partStore.getPartSize( name.substring(1)));
          }
        } catch (UnsupportedOperationException uoe) {}
         
        is = partStore.loadPart(
            name.substring(1));
        if (is==null) {
          log.warn(name + " missing from part store");
        } else {
          log.info("Lazily unmarshalling " + name);
View Full Code Here

   
    // Get the contents as a string
    String wmlTemplateString = null;
    if (jaxbElement==null) {

      PartStore partStore = this.getPackage().getSourcePartStore();
      String name = this.getPartName().getName();
      InputStream is = partStore.loadPart(
          name.substring(1));
      if (is==null) {
        log.warn(name + " missing from part store");
        throw new Docx4JException(name + " missing from part store");
      } else {
View Full Code Here

    if (jaxbElement == null) {
      // Test jaxbElement, since we don't want to do the
      // below if jaxbElement has already been set
      // using setJaxbElement (which doesn't create
      // binder)
      PartStore partStore = this.getPackage().getSourcePartStore();
     
      InputStream is = null;
      try {
        String name = this.getPartName().getName();
       
        try {
          this.setContentLengthAsLoaded(
              partStore.getPartSize( name.substring(1)));
        } catch (UnsupportedOperationException uoe) {}
       
        is = partStore.loadPart(
            name.substring(1));
        if (is==null) {
          log.warn(name + " missing from part store");
        } else {
          log.info("Lazily unmarshalling " + name);
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.io3.stores.UnzippedPartStore

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.