Package org.docx4j.openpackaging.exceptions

Examples of org.docx4j.openpackaging.exceptions.Docx4JException


   
    try {
      return OpcPackage.load(pkgIdentifier, new FileInputStream(docxFile), password );
    } catch (final FileNotFoundException e) {
      OpcPackage.log.error(e.getMessage(), e);
      throw new Docx4JException("Couldn't load file from " + docxFile.getAbsolutePath(), e);
    }
  }
View Full Code Here


    int read=0;
    try {
      read = bis.read(firstTwobytes);
      bis.reset();
    } catch (final IOException e) {
      throw new Docx4JException("Error reading from the stream", e);
    }
    if (read!=2){
      throw new Docx4JException("Error reading from the stream (no bytes available)");
    }
    if (firstTwobytes[0]=='P' && firstTwobytes[1]=='K') { // 50 4B
      return OpcPackage.load(pkgIdentifier, bis, Filetype.ZippedPackage, null);
    } else if  (firstTwobytes[0]==(byte)0xD0 && firstTwobytes[1]==(byte)0xCF) {
      // password protected docx is a compound file, with signature D0 CF 11 E0 A1 B1 1A E1
View Full Code Here

            at org.apache.poi.poifs.crypt.AgileDecryptor.access$200(AgileDecryptor.java:39)
            at org.apache.poi.poifs.crypt.AgileDecryptor$ChunkedCipherInputStream.<init>(AgileDecryptor.java:127)
            at org.apache.poi.poifs.crypt.AgileDecryptor.getDataStream(AgileDecryptor.java:103)
            at org.apache.poi.poifs.crypt.Decryptor.getDataStream(Decryptor.java:85)           
             */
        throw new Docx4JException("Problem reading compound file: wrong password?", e);
      } catch (Exception e) {
        throw new Docx4JException("Problem reading compound file", e);
      } finally {
        new EventFinished(startEvent).publish();       
      }
    }
   
    try {
      FlatOpcXmlImporter xmlPackage = new FlatOpcXmlImporter(is);
      return xmlPackage.get();
    } catch (final Exception e) {
      OpcPackage.log.error(e.getMessage(), e);
      throw new Docx4JException("Couldn't load xml from stream ",e);
    } finally {
      new EventFinished(startEvent).publish();                 
    }
  }
View Full Code Here

    OutputStream outStream = null;
    try {
      outStream = new FileOutputStream(outFile);
      save(outStream, flags);
    } catch (FileNotFoundException e) {
      throw new Docx4JException("Exception creating output stream: " + e.getMessage(), e);
    }
    finally {
      if (outStream != null) {
        try {
          outStream.close();
View Full Code Here

        marshaller = jc.createMarshaller();
        NamespacePrefixMapperUtils.setProperty(marshaller,
            NamespacePrefixMapperUtils.getPrefixMapper());     
        marshaller.marshal(pkg, outStream);       
      } catch (JAXBException e) {
        throw new Docx4JException("Exception marshalling document for output: " + e.getMessage(), e);
      }
    }
    else {
//      SaveToZipFile saver = new SaveToZipFile(wmlPackage);
      Save saver = new Save(this);
View Full Code Here

      FileOutputStream fos = new FileOutputStream(new File(filePath));
          ctm.marshal(fos);
          fos.close();

    } catch (Exception e) {
      throw new Docx4JException("Error marshalling Content_Types ", e);
    }

  }
View Full Code Here

          } else {

            if (!file.exists()
                && this.sourcePartStore==null) {
              throw new Docx4JException("part store has changed, and sourcePartStore not set");
            } else {
              InputStream is = sourcePartStore.loadPart(part.getPartName().getName().substring(1));
          FileOutputStream fos = new FileOutputStream(file);

              int read = 0;
              byte[] bytes = new byte[1024];

              while ((read = is.read(bytes)) != -1) {
                fos.write(bytes, 0, read);
              }

              is.close();
              fos.flush();
              fos.close();

            }

          }

    } catch (Exception e) {
      throw new Docx4JException("Error marshalling JaxbXmlPart " + part.getPartName(), e);
    }
  }
View Full Code Here

      FileOutputStream fos = new FileOutputStream(file);
          part.getData().writeDocument( fos );
          fos.close();

    } catch (Exception e) {
      throw new Docx4JException("Error marshalling CustomXmlDataStoragePart " + part.getPartName(), e);
    }

  }
View Full Code Here

           new StreamResult(fos) );

        fos.close();

    } catch (Exception e) {
      throw new Docx4JException("Error marshalling XmlPart " + part.getPartName(), e);
    }
  }
View Full Code Here

              // either source = target,
              // or incrementally saved to target already
           
            } else if (this.sourcePartStore==null) {

              throw new Docx4JException("part store has changed, and sourcePartStore not set");

            } else {

              InputStream is = sourcePartStore.loadPart(part.getPartName().getName().substring(1));
              int read = 0;
              byte[] bytes = new byte[1024];

              fos = new FileOutputStream(file);

              while ((read = is.read(bytes)) != -1) {
                fos.write(bytes, 0, read);
              }
              is.close();
            }
          }


    } catch (Exception e ) {
      throw new Docx4JException("Failed to put binary part", e);
    }

    log.info( "success writing part: " + resolvedPartUri);

  }
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.exceptions.Docx4JException

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.