Package org.docx4j.openpackaging.packages

Examples of org.docx4j.openpackaging.packages.OpcPackage


  (iii) cross the PartName off unusedZipEntries
  */
  private void addPartsFromRelationships( Base source, RelationshipsPart rp)
    throws Docx4JException {
   
    OpcPackage pkg = source.getPackage();       
   
//    for (Iterator it = rp.iterator(); it.hasNext(); ) {
//      Relationship r = (Relationship)it.next();
//      log.info("For Relationship Id=" + r.getId() + " Source is "
//          + r.getSource().getPartName()
View Full Code Here


    super.initializeSettings(svgSettings, opcPackage);
  }

  @Override
  protected OpcPackage initializeOpcPackage(AbstractConversionSettings settings, OpcPackage opcPackage) {
  OpcPackage ret = super.initializeOpcPackage(settings, opcPackage);
    if (!(ret instanceof PresentationMLPackage)) {
      throw new IllegalArgumentException("The opcPackage isn't a PresentationMLPackage, it is a " + ret.getClass().getName());
    }
    return ret;
  }
View Full Code Here

   
    // 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();
    zps.setSourcePartStore(opc.getSourcePartStore());
   
    Save saver = new Save(opc, zps);
    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(docxFile);
View Full Code Here

  /** Return a package of the appropriate type.  Used when loading an existing
   *  Package, with an already populated [Content_Types].xml.  When
   *  creating a new Package, start with the new WordprocessingMLPackage constructor. */
  public OpcPackage createPackage(String pkgContentType) throws InvalidFormatException {
   
    OpcPackage p;
   
     
    // Check overrides first
    if (pkgContentType.equals(ContentTypes.WORDPROCESSINGML_DOCUMENT)
        || pkgContentType.equals(ContentTypes.WORDPROCESSINGML_DOCUMENT_MACROENABLED)
View Full Code Here

    // We need a source layout part
    // Could get it from a docx, or a glox
    String layoutSrcFilePath = System.getProperty("user.dir")
    + "/sample-docs/glox/extracted/chevron1.glox";
   
    OpcPackage opcPackage = OpcPackage.load(new java.io.File(layoutSrcFilePath));
    DiagramLayoutPart thisPart = null;
    for (Entry<PartName,Part> entry : opcPackage.getParts().getParts().entrySet() ) {
     
      if (entry.getValue().getContentType().equals(
          ContentTypes.DRAWINGML_DIAGRAM_LAYOUT )) {
        thisPart = (DiagramLayoutPart)entry.getValue();
        break;
View Full Code Here

      }
  }
 
  public OpcPackage get(Session jcrSession, Node docxNode ) throws Docx4JException  {
   
    OpcPackage p = null;
   
    // 1. The idea is to walk the tree of relationships, getting
//    everything we need from JCR.
   
//    unusedJCRNodes = new HashMap();
        try {
//          Node docxContentNode = docxNode.getNode("jcr:content");
      Node docxContentNode = nodeMapper.getContentNode(docxNode);

            // Its a flat structure since we've URL Encoded '/'
//            NodeIterator nodeIterator = docxContentNode.getNodes();
//          while(nodeIterator.hasNext()) {
//              Node n=nodeIterator.nextNode();
//              log.info(n.getName());
//        unusedJCRNodes.put(decodeSlashes(nodeMapper, n.getName()), new Boolean(true) );       
//          }   
   
      // 2. Create a new Package
  //    Eventually, you'll only be able to create an Excel package etc
  //    but only the WordML package exists at present
//          Document ctmDocument = null;
//          ctmDocument = deprecatedGetDocumentFromJCRPart(jcrSession, nodeMapper, docxContentNode, "[Content_Types].xml");           
//      debugPrint(ctmDocument);
         
          initialiseContentTypeManager(ctm,
             jcrSession,
             docxContentNode , nodeMapper );
         
      p = ctm.createPackage();
           
     
      // 3. Get [Content_Types].xml
  //    Once we've got this, then we can look up the content type for
  //    each PartName, and use it in the Part constructor.

//      p.setContentTypeManager(ctm); - 20080111 - done by ctm.createPackage();
     
//      unusedJCRNodes.put("[Content_Types].xml", new Boolean(false));
     
      // 4. Start with _rels/.rels
 
  //    <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  //      <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
  //      <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
  //      <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
  //    </Relationships>   
     
      String partName = "_rels/.rels";
      RelationshipsPart rp = getRelationshipsPartFromJCR(p, jcrSession, docxContentNode,  partName);
      p.setRelationships(rp);
      //rp.setPackageRelationshipPart(true);
//      unusedJCRNodes.put(partName, new Boolean(false));
     
     
      log.info( "Object created for: " + partName);
View Full Code Here

  (iii) cross the PartName off unusedJCRNodes
  */
  public void addPartsFromRelationships(Session jcrSession,
      Node docxNode, Base source, RelationshipsPart rp) throws Docx4JException {
   
    OpcPackage pkg = source.getPackage();   
       
    for ( Relationship r : rp.getRelationships().getRelationship() ) {
     
      log.info("For Relationship Id=" + r.getId()
          + " Source is " + rp.getSourceP().getPartName()
View Full Code Here

      inputfilepath = System.getProperty("user.dir") + "/sample-docs/glox/extracted/CirclePictureHierarchy.docx";
    }
    String outputdir = inputfilepath.substring(0, inputfilepath.lastIndexOf("/")+1);
    String outputfilename = inputfilepath.substring(inputfilepath.lastIndexOf("/"))+ ".glox";
   
    OpcPackage opcPackage = OpcPackage.load(new java.io.File(inputfilepath));   
   
    GloxPackage gloxPackage = new GloxPackage();   
   
    // DiagramLayoutPart - from the exemplar docx or pptx 
    // .. just the first one we encounter
    DiagramLayoutPart source = null;
    for (Entry<PartName,Part> entry : opcPackage.getParts().getParts().entrySet() ) {
     
      if (entry.getValue().getContentType().equals(
          ContentTypes.DRAWINGML_DIAGRAM_LAYOUT )) {
        source = (DiagramLayoutPart)entry.getValue();
        break;
View Full Code Here

      mainPartNameObj = new PartName("/" + mainPartName);
    }
    String pkgContentType = ctm.getContentType(mainPartNameObj);

    // 2. Create a new Package; this'll return the appropriate subclass
    OpcPackage p = ctm.createPackage(pkgContentType);
    log.info("Instantiated package of type " + p.getClass().getName() );
    p.setSourcePartStore(partStore);

    p.setRelationships(rp);
    rp.setSourceP(p); //
   
    // 5. Now recursively
//    (i) create new Parts for each thing listed
//    in the relationships
View Full Code Here

  */
  private void addPartsFromRelationships(
      Base source, RelationshipsPart rp, ContentTypeManager ctm)
    throws Docx4JException {
   
    OpcPackage pkg = source.getPackage();       
   
    for ( Relationship r : rp.getRelationships().getRelationship() ) {
     
      log.debug("\n For Relationship Id=" + r.getId()
          + " Source is " + rp.getSourceP().getPartName()
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.packages.OpcPackage

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.