Package org.docx4j.openpackaging.parts

Examples of org.docx4j.openpackaging.parts.Part


   * @throws InvalidFormatException
   */
  public static Part getRawPart(InputStream is, ContentTypeManager ctm, String resolvedPartUri, Relationship rel)
      throws Docx4JException {
   
    Part part = null;

    try {
           
      try {
       
        part = ctm.getPart("/" + resolvedPartUri, rel);
               
       
        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 ) {
         
          // Is it a part we know?
          try {
            Unmarshaller u = Context.jc.createUnmarshaller();
            Object o = u.unmarshal( is );           
            log.info(o.getClass().getName());
           
            PartName name = part.getPartName();
           
            if (o instanceof CoverPageProperties) {
             
              part = new DocPropsCoverPagePart(name);             
              ((DocPropsCoverPagePart)part).setJaxbElement(
View Full Code Here


   
    //Iterator iterator = parts.entrySet().iterator();
    Collection col = parts.values();
    Iterator iterator = col.iterator();
    while( iterator.hasNext() ) {
      Part entry = (Part)iterator.next();
     
      if (entry instanceof CustomXmlPart) {
        log.info("Found a CustomXmlPart, named " + entry.getPartName().getName() );
        String itemId = null;
        if (entry.getRelationshipsPart()==null) {
          continue;
        } else {
          log.debug(".. it has a rels part");
          // Look in its rels for rel of @Type customXmlProps (eg @Target="itemProps1.xml")
          Relationship r = entry.getRelationshipsPart().getRelationshipByType(
              Namespaces.CUSTOM_XML_DATA_STORAGE_PROPERTIES);
          if (r==null) {
            log.debug(".. but that doesn't point to a  customXmlProps part");
            continue;
          }
          CustomXmlDataStoragePropertiesPart customXmlProps =
            (CustomXmlDataStoragePropertiesPart)entry.getRelationshipsPart().getPart(r);
          if (customXmlProps==null) {
            log.error(".. but the target seems to be missing?");
           
            if (entry instanceof CustomXmlDataStoragePart) {
              try {
View Full Code Here

   
    if (handled.get(resolvedPartUri)!=null) return;
   
    String relationshipType = r.getType();   
     
    Part part = getRawPart(ctm, resolvedPartUri,r);
    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.debug("Convenience method established from " + source.getPartName()
          + " to " + part.getPartName());
    }
   
//    log.info(".. added." );
   
    RelationshipsPart rrp = getRelationshipsPart( part);
View Full Code Here

   * @throws InvalidFormatException
   */
  public static Part getRawPart(ContentTypeManager ctm, org.docx4j.xmlPackage.Part pkgPart, Relationship rel)
      throws Docx4JException {
   
    Part part = null;
   
    try {
      org.w3c.dom.Element el = null;

      try {
       
        String contentType = pkgPart.getContentType();
        log.debug("contentType: " + contentType);
       
       
        if (pkgPart.getXmlData()!=null) {
          // if its not binary
          el = pkgPart.getXmlData().getAny();
        }
               
//         part = ctm.newPartForContentType(contentType, resolvedPartUri,rel);
         part = ctm.newPartForContentType(contentType, pkgPart.getName(), rel);
         part.setContentType( new ContentType(contentType) );
        
//         ctm.addOverrideContentType(new java.net.URI(resolvedPartUri),
         ctm.addOverrideContentType(new java.net.URI(pkgPart.getName()),
             contentType);
       
        if (part instanceof org.docx4j.openpackaging.parts.ThemePart) {

          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).setJAXBContext(Context.jcThemePart);
          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).unmarshal( el );
         
        } 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( el );
           
        } 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( el );
           
        } 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( el );

        } 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( el );         
         
        } else if (part instanceof org.docx4j.openpackaging.parts.digitalsignature.XmlSignaturePart ) {

          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).setJAXBContext(Context.jcXmlDSig);
          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).unmarshal( el );                   
         
        } else if (part instanceof JaxbPmlPart) {

          // Presentation type part
         
          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).setJAXBContext(org.pptx4j.jaxb.Context.jcPML);
          ((org.docx4j.openpackaging.parts.JaxbXmlPart)part).unmarshal( el );
         
        } 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( el );
         
//        } else if (part instanceof org.docx4j.openpackaging.parts.WordprocessingML.ObfuscatedFontPart) {
        } else if (part instanceof org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart) {
         
          log.debug("Detected BinaryPart " + part.getClass().getName() );
          ((BinaryPart)part).setBinaryData( pkgPart.getBinaryData() )
         
        } else if (part instanceof org.docx4j.openpackaging.parts.CustomXmlDataStoragePart) {
         
          // Is it a part we know?
          try {
            Unmarshaller u = Context.jc.createUnmarshaller();
            Object o = u.unmarshal( el );           
            log.debug(o.getClass().getName());
           
            PartName name = part.getPartName();
           
            if (o instanceof CoverPageProperties) {
             
              part = new DocPropsCoverPagePart(name);             
              ((DocPropsCoverPagePart)part).setJaxbElement(
View Full Code Here

    if (r==null) {
      log.error("Couldn't find rel " + relId);
      return;
    }
   
    Part p = docPartRels.getPart(r);
   
    Relationship r2 = (Relationship)XmlUtils.deepCopy(r, Context.jcRelationships);
   
    r2.setId(newRelId);
    log.debug(".. added rel " + newRelId + " -- " + r2.getTarget() );
View Full Code Here

   
    // Now add the rels we composed
    Map<Relationship, Part> newRels = pd.getComposedRels();
    for (Relationship nr : newRels.keySet()) { 
     
      Part part = newRels.get(nr);
      if (part instanceof BinaryPart) { // ensure contents are loaded, before moving to new pkg
        ((BinaryPart)part).getBuffer();
      }
     
      newMDP.addTargetPart(part, AddPartBehaviour.RENAME_IF_NAME_EXISTS, nr.getId());
View Full Code Here

 
  /* Return a part of the appropriate sub class */
  public  Part getPart(String partName, Relationship rel) throws URISyntaxException, PartUnrecognisedException,
   InvalidFormatException {
   
    Part p;

    // look for an override
    CTOverride overrideCT = (CTOverride) overrideContentType.get(new URI(partName));
    if (overrideCT!=null ) {
      String contentType = overrideCT.getContentType();
      log.debug("Found content type '" + contentType + "' for " + partName);
       p = newPartForContentType(contentType, partName, rel);
       p.setContentType( new ContentType(contentType) );
       return p;
    }   
   
    // if there is no override, get use the file extension
    String ext = partName.substring(partName.indexOf(".") + 1).toLowerCase();
    log.debug("Looking at extension '" + ext);
    CTDefault defaultCT = (CTDefault)defaultContentType.get(ext);
    if (defaultCT!=null ) {
      String contentType = defaultCT.getContentType();
      log.debug("Found content type '" + contentType + "' for "
              + partName);
      p = newPartForContentType(contentType, partName, rel);
      p.setContentType(new ContentType(contentType));
      return p;
    }
   
    // otherwise
    log.error("No content type found for " + partName);
View Full Code Here

  List<PartName> partsToRemove = new ArrayList<PartName>();
  RelationshipsPart relationshipsPart = wmlPackage.getMainDocumentPart().getRelationshipsPart();
  List<Relationship> relationshipsList = ((relationshipsPart != null) &&
                        (relationshipsPart.getRelationships() != null) ?
                        relationshipsPart.getRelationships().getRelationship() : null);
  Part part = null;
    if (relationshipsList != null) {
      for (Relationship relationship : relationshipsList) {
        if (Namespaces.CUSTOM_XML_DATA_STORAGE.equals(relationship.getType())) {
          part = relationshipsPart.getPart(relationship);
          if (part==customXmlDataStoragePart) {
            partsToRemove.add(part.getPartName());
          }
        }
      }
    }
    if (!partsToRemove.isEmpty()) {
View Full Code Here

    List<PartName> removedParts = new ArrayList<PartName>();
   
    if (partName == null)
      throw new IllegalArgumentException("partName was null");
   
    Part part = getPackage().getParts().get(partName);
   
    if (part!=null) {

      removeRelationship(partName);
     
      // Remove parts it references
      if (part.getRelationshipsPart()!=null) {
        removedParts.addAll(
            part.getRelationshipsPart().removeParts() ); // the recursive bit
       
        // part.setRelationships(null);  // Unnecessary
      }     

      // Remove from Content Type Manager
View Full Code Here

          }
          continue;
        }
       
        // Compare content
        Part thisPart = this.getPart(r);
        Part otherPart = otherRP.getPart(otherR)
        if (!thisPart.isContentEqual( otherPart)) {
          results.add(r);
          log.debug("Different: " + r.getTarget() )
        }
      }     
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.