Package org.docx4j.openpackaging.parts

Examples of org.docx4j.openpackaging.parts.Part


   
    Presentation.SldIdLst.SldId entry = this.getJaxbElement().getSldIdLst().getSldId().remove(index);
   
    Relationship rel = this.getRelationshipsPart().getRelationshipByID(entry.getRid());
   
    Part part = this.getRelationshipsPart().getPart(rel);
   
    this.getPackage().getParts().remove(part.getPartName());
    this.getRelationshipsPart().removeRelationship(rel);
  }
View Full Code Here


   
    org.docx4j.convert.in.FlatOpcXmlImporter xmlPackage = new org.docx4j.convert.in.FlatOpcXmlImporter( wmlPackageEl);
   
    ContentTypeManager ctm = new ContentTypeManager();
   
    Part tmpDocPart = xmlPackage.getRawPart(ctm,  "/word/document.xml", null);
    Part tmpStylesPart = xmlPackage.getRawPart(ctm,  "/word/styles.xml", null);
   
    // This code assumes all the existing rels etc of
    // the existing main document part are still relevant.
//    if (wmlDocument==null) {
//      log.warn("Couldn't get main document part from package transform result!");     
View Full Code Here

    // Add the main document part to the package relationships
    // (creating it if necessary)
    wmlPack.addTargetPart(wordDocumentPart);
       
    // Create a styles part
    Part stylesPart = new org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart();
    try {
      ((org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart) stylesPart)
          .unmarshalDefaultStyles();
     
      // Add the styles part to the main document part relationships
View Full Code Here

        } else if (missings.contains(r)) {
          addTree(alterations.getPartsDeleted(), thisRP.getPart(r).getRelationshipsPart() );
        } else {
          // its present in both trees.
          // irrespective of whether content of part is the same, content of a rel could still have changed
          Part thisPart = thisRP.getPart(r);
          Part otherPart = otherRP.getPart(
              RelationshipsPart.getRelationshipByTarget(otherRP, r.getTarget()) );
         
          if (thisPart.getRelationshipsPart()==null) {
           
            if (otherPart.getRelationshipsPart()!=null) {
              // add tree, including any external parts 
              alterations.getPartsDeleted().add(
                  new Alteration( thisPart.getPartName(), toStorageFormat(thisPart.getRelationshipsPart())));                       
              addTree(alterations.getPartsDeleted(), thisPart.getRelationshipsPart() );
            }
           
          } else {
           
            if (otherPart.getRelationshipsPart()==null) {
              // add tree, including any external parts 
              alterations.getPartsAdded().add(
                  new Alteration( thisPart.getPartName(), toStorageFormat(thisPart.getRelationshipsPart())));                       
              addTree(alterations.getPartsAdded(), thisPart.getRelationshipsPart() );
             
            } else {
              recurse(alterations, thisPart.getRelationshipsPart(), otherPart.getRelationshipsPart());
            }
           
          }
         
        }
View Full Code Here

        list.add(
            new Alteration( rp, toStorageFormat(rp.getPart(r)) ));
        log.debug("add tree: " + r.getTarget() );       
       
        // recurse
        Part nextSourcePart = rp.getPart(r);
        RelationshipsPart nextRP = nextSourcePart.getRelationshipsPart();
        if (nextRP!=null) {
          list.add(
              new Alteration( nextSourcePart.getPartName(), toStorageFormat(nextRP)));                       
          addTree(list, nextRP );
        }
      }
    }   
   
View Full Code Here

      // have been modified or deleted.  So look for that.
      // BUT IT WON'T BE THERE IF ITS BEEN DELETED! DOH!
      // So we have to store the info when AlteredParts is run
      // after all.

      Part parentPart = otherPackage.getParts().get(a.getSourcePartName());
      if (a.getPart().getContentType().equals(ContentTypes.RELATIONSHIPS_PART)) {
        parentPart.setRelationships(null);
      } else {
        removedParts.addAll(
            parentPart.getRelationshipsPart().removePart(
                new PartName(xmlpart.getName())) );
      }
     
    }
   
   
    // -- Modifications
    for (Alteration a : alterations.getPartsModified() ) {
     
      log.info("Applying modifications to part: " + a.getPart().getName() );
     
      if (a.getPart().getContentType().equals(ContentTypes.RELATIONSHIPS_PART)) {
       
       
        RelationshipsPart newRP = null; //FlatOpcXmlImporter.createRelationshipsPart(a.getPart());
       
        if (a.getSourcePartName().equals("/")) {
          newRP = otherPackage.getRelationshipsPart(true);
//          otherPackage.setRelationships(newRP);
//          newRP.setSourceP(otherPackage);         
        } else {
          Part parentPart = otherPackage.getParts().get(a.getSourcePartName());
          newRP = parentPart.getRelationshipsPart(true);
//          parentPart.setRelationships(newRP);
//          newRP.setSourceP(parentPart);         
        }
        FlatOpcXmlImporter.populateRelationshipsPart(newRP,  a.getPart().getXmlData().getAny());
       
      } else {

        Part targetPart = otherPackage.getParts().get(
            new PartName(a.getPart().getName()));
       
        if (targetPart==null) {
          log.error("Couldn't find " +  a.getPart().getName() + " @ " + a.getSourcePartName().getName() );
          continue;
        }
       
        Part tmpPart = FlatOpcXmlImporter.getRawPart(otherPackage.getContentTypeManager(),
            a.getPart(), null);
       
        if (targetPart instanceof JaxbXmlPart) {
          ((JaxbXmlPart)targetPart).setJaxbElement(
              ((JaxbXmlPart)tmpPart).getJaxbElement() );
         
        } else if (targetPart instanceof XmlPart) {
         
          ((XmlPart)targetPart).setDocument(
              ((XmlPart)tmpPart).getDocument() );
       
        } else if (targetPart instanceof CustomXmlDataStoragePart) {
         
          ((CustomXmlDataStoragePart)targetPart).setData(
              ((CustomXmlDataStoragePart)tmpPart).getData() );
            // TODO: check that
         
        } else if (targetPart instanceof BinaryPart) {

          ((BinaryPart)targetPart).setBinaryData(
              ((BinaryPart)tmpPart).getBuffer() );
         
        } else {
          log.error("TODO: handle " + targetPart.getClass().getName() );
        }
      }
    }
   
    // -- Additions
    for (Alteration a : alterations.getPartsAdded() ) {
     
      log.info("Adding part: " + a.getPart().getName() );
     
      if (a.getPart().getContentType().equals(ContentTypes.RELATIONSHIPS_PART)) {
       
        RelationshipsPart newRP = null; //FlatOpcXmlImporter.createRelationshipsPart(a.getPart());
       
        if (a.getSourcePartName().equals("/")) {
          newRP = otherPackage.getRelationshipsPart(true);
//          otherPackage.setRelationships(newRP);
//          newRP.setSourceP(otherPackage);
        } else {
          Part parentPart = otherPackage.getParts().get(a.getSourcePartName());
          newRP = parentPart.getRelationshipsPart(true);
//          parentPart.setRelationships(newRP);
//          newRP.setSourceP(parentPart);
        }
        FlatOpcXmlImporter.populateRelationshipsPart(newRP,  a.getPart().getXmlData().getAny());
       
       
      } else {

        Part parentPart = otherPackage.getParts().get(a.getSourcePartName());
        Part newPart = FlatOpcXmlImporter.getRawPart(otherPackage.getContentTypeManager(),
            a.getPart(), null);
       
        // There will already be a rel for the new part,
        // since we will already have modified or added the rels part
        // so don't do AddTargetPart (which will probably create a new rel id,
        // which will cause problems)
       
        newPart.setOwningRelationshipPart(parentPart.getRelationshipsPart());
        newPart.getSourceRelationships().add(
            parentPart.getRelationshipsPart().getRel(new PartName(a.getPart().getName())));
        otherPackage.getParts().put(newPart);
        newPart.setPackage( otherPackage );

        // TODO: add content type if necessary
      }     
     
    } 
View Full Code Here

   
    if (handled.get(resolvedPartUri)!=null) return;
   
    String relationshipType = r.getType();   
   
    Part part = getRawPart(jcrSession, nodeMapper, docxNode, ctm, resolvedPartUri);
    if (part instanceof BinaryPart
        || part instanceof DefaultXmlPart) {
      // The constructors of other parts should take care of this...
      part.setRelationshipType(relationshipType);
    }   
    rp.loadPart(part, r);
    handled.put(resolvedPartUri, resolvedPartUri);   
   
    // The source Part (or Package) might have a convenience
    // method for this
    if (source.setPartShortcut(part, relationshipType ) ) {
      log.info("Convenience method established from " + source.getPartName()
          + " to " + part.getPartName());
    }       
   
//    unusedJCRNodes.put(resolvedPartUri, new Boolean(false));
    log.info(".. added part '" + part.getPartName() + "'" );
   
    RelationshipsPart rrp = getRelationshipsPart(jcrSession, docxNode, part);
    if (rrp!=null) {
      // recurse via this parts relationships, if it has any
      addPartsFromRelationships(jcrSession, docxNode, part, rrp );         
      String relPart = PartName.getRelationshipsPartName(
          part.getPartName().getName().substring(1) );
//      unusedJCRNodes.put(relPart, new Boolean(false));
    }
  }
View Full Code Here

   * @throws InvalidFormatException
   */
  public static Part getRawPart(Session jcrSession, NodeMapper nodeMapper, Node docxNode, ContentTypeManager ctm, String resolvedPartUri)
      throws Docx4JException {
   
    Part part = null;

    InputStream is = null;   
    try {
           
      try {
       
        // Get the input stream first, so it is available
        // even if getPart throws PartUnrecognisedException.
        Node contentNode = getPartNode(jcrSession,nodeMapper, 
            docxNode,  resolvedPartUri);
        is = getInputStreamFromJCRPart( nodeMapper, contentNode);

        part = ctm.getPart("/" + resolvedPartUri);
               
       
        if (part instanceof org.docx4j.openpackaging.parts.ThemePart) {

          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).setJAXBContext(Context.jcThemePart);
          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).unmarshal( is );
         
        } else if (part instanceof org.docx4j.openpackaging.parts.DocPropsCorePart ) {

          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).setJAXBContext(Context.jcDocPropsCore);
          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).unmarshal( is );
         
        } else if (part instanceof org.docx4j.openpackaging.parts.DocPropsCustomPart ) {

          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).setJAXBContext(Context.jcDocPropsCustom);
          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).unmarshal( is );
         
        } else if (part instanceof org.docx4j.openpackaging.parts.DocPropsExtendedPart ) {

          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).setJAXBContext(Context.jcDocPropsExtended);
          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).unmarshal( is );
       
        } else if (part instanceof org.docx4j.openpackaging.parts.CustomXmlDataStoragePropertiesPart ) {

          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).setJAXBContext(Context.jcCustomXmlProperties);
          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).unmarshal( is );
         
        } else if (part instanceof org.docx4j.openpackaging.parts.JaxbXmlPart) {
         
          // MainDocument part, Styles part, Font part etc

          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).setJAXBContext(Context.jc);
          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).unmarshal( is );
         
        } else if (part instanceof org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart) {
         
          log.debug("Detected BinaryPart " + part.getClass().getName() );
          ((BinaryPart)part).setBinaryData(is);
         
        } else if (part instanceof org.docx4j.openpackaging.parts.CustomXmlDataStoragePart ) {
         
          CustomXmlDataStorage data = getCustomXmlDataStorageClass().factory();         
View Full Code Here

   
  public static Part getBinaryPart(Session jcrSession, NodeMapper nodeMapper, Node docxNode,
      ContentTypeManager ctm, String resolvedPartUri)
      throws Docx4JException {

    Part part = null;
    InputStream in = null;

    try {

      log.info("Fetching " + encodeSlashes(nodeMapper, resolvedPartUri));
View Full Code Here

    Iterator partIterator = presentationMLPackage.getParts().getParts().entrySet().iterator();
      while (partIterator.hasNext()) {
       
          Map.Entry pairs = (Map.Entry)partIterator.next();
         
          Part p = (Part)pairs.getValue();
          if (p instanceof SlidePart) {
           
            System.out.println(
                SvgExporter.svg(presentationMLPackage, (SlidePart)p)
                );
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.parts.Part

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.