Package org.docx4j.openpackaging.parts

Examples of org.docx4j.openpackaging.parts.Part


       
        if (!false) {
          log.debug("Getting part /" + resolvedPartUri );
         
          //Part part = p.getParts().get(new PartName("/" + resolvedPartUri));
          Part part = rp.getPart(r);
            // 2012 09 26: If the part is actually attached to
            // a different package, using this you can still get it.
            // Use this 'feature' at your own risk!
         
          if (part==null) {
            log.error("Part " + resolvedPartUri + " not found!");
          } else {
            log.debug(part.getClass().getName() );
          }

          if (part.getPackage()==null) {
            log.warn("Part " + resolvedPartUri + " is not attached to any package");           
          } else if (!part.getPackage().equals(p)) {
            log.warn("Part " + resolvedPartUri + " is attached to some other package");
          }
         
          savePart(part);
         
View Full Code Here


      return;
    }
   
   
    String relationshipType = r.getType();   
    Part part;
   
    if (pkg.handled.get(resolvedPartUri)!=null) {
     
      // The source Part (or Package) might have a convenience
      // method for this
      part = pkg.getParts().getParts().get(new PartName("/" + resolvedPartUri));
      if (source.setPartShortcut(part, relationshipType ) ) {
        log.debug("Convenience method established from " + source.getPartName()
            + " to " + part.getPartName());
      }
     
      // v3.2.1: also note this additional source rel
      part.getSourceRelationships().add(r)
     
      return;
    }
   
    part = getRawPart(ctm, resolvedPartUri, r); // will throw exception if null

    // 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());
    }

   
    if (part instanceof BinaryPart
        || part instanceof DefaultXmlPart) {
      // The constructors of other parts should take care of this...
      part.setRelationshipType(relationshipType);
    }
    rp.loadPart(part, r);
     // That loads a pre-existing target part into the package
     // (but does not load its contents as such; that is
     //  done elsewhere).
View Full Code Here

   */
  public Part getRawPart(
      ContentTypeManager ctm, String resolvedPartUri, Relationship rel
      throws Docx4JException {
   
    Part part = null;
   
    InputStream is = null;
    try {
      try {
        log.debug("resolved uri: " + resolvedPartUri);
       
        // Get a subclass of Part appropriate for this content type 
        // This will throw UnrecognisedPartException in the absence of
        // specific knowledge. Hence it is important to get the is
        // first, as we do above.
        part = ctm.getPart("/" + resolvedPartUri, rel);       

        log.debug("ctm returned " + part.getClass().getName() );
       
        if (part instanceof org.docx4j.openpackaging.parts.ThemePart
            || part instanceof org.docx4j.openpackaging.parts.DocPropsCorePart
            || part instanceof org.docx4j.openpackaging.parts.DocPropsCustomPart
            || part instanceof org.docx4j.openpackaging.parts.DocPropsExtendedPart
            || part instanceof org.docx4j.openpackaging.parts.CustomXmlDataStoragePropertiesPart
            || part instanceof org.docx4j.openpackaging.parts.digitalsignature.XmlSignaturePart
            || part instanceof org.docx4j.openpackaging.parts.JaxbXmlPart) {
         
          // Nothing to do here
         
        } else if (part instanceof org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart) {
         
          log.debug("Detected BinaryPart " + part.getClass().getName() );
         
          // Note that this is done lazily, since the below lines are commented out
         
//          is = partStore.loadPart( resolvedPartUri);
//          ((BinaryPart)part).setBinaryData(is);

        } else if (part instanceof org.docx4j.openpackaging.parts.CustomXmlDataStoragePart ) {
          // ContentTypeManager initially detects them as CustomXmlDataStoragePart;
          // the below changes as necessary
         
          // Is it a part we know?
          is = partStore.loadPart( resolvedPartUri);
          try {
            Unmarshaller u = Context.jc.createUnmarshaller();
            Object o = u.unmarshal( is );           
            log.debug(o.getClass().getName());
           
            PartName name = part.getPartName();
            if (o instanceof CoverPageProperties) {
             
              part = new DocPropsCoverPagePart(name)
              ((DocPropsCoverPagePart)part).setJaxbElement(
                  (CoverPageProperties)o);
View Full Code Here

 
  public Part getBinaryPart(
      ContentTypeManager ctm, String resolvedPartUri
      throws Docx4JException {

    Part part = null;
    InputStream is = null;         
    try {
      is = partStore.loadPart(resolvedPartUri);
      //in = partByteArrays.get(resolvedPartUri).getInputStream();
      part = new BinaryPart( new PartName("/" + resolvedPartUri));
     
      // Set content type
      part.setContentType(
          new ContentType(
              ctm.getContentType(new PartName("/" + resolvedPartUri)) ) );
     
      ((BinaryPart)part).setBinaryData(is);
      log.info("Stored as BinaryData" );
View Full Code Here

      if (r.getTargetMode() != null
          && r.getTargetMode().equals("External") ) {       
        continue;       
      }
     
      Part part = rp.getPart(r);
                 
      printInfo(part, sb, indent);
      if (handled.get(part)!=null) {
        sb.append(" [additional reference] ");
        continue;
      }
      handled.put(part, part);
      if (part.getRelationshipsPart()==null) {
        // sb.append(".. no rels" );           
      } else {
        traverseRelationships(wordMLPackage, part.getRelationshipsPart(), sb, indent + "    ");
      }
         
    }
   
   
View Full Code Here

    HashMap<String, Object> tmp = new HashMap<String, Object> ();
   
    Collection col = parts.values();
    Iterator iterator = col.iterator();
    while( iterator.hasNext() ) {
      Part entry = (Part)iterator.next();
     
      if (entry instanceof org.docx4j.openpackaging.parts.CustomXmlDataStoragePart
          || entry instanceof JaxbCustomXmlDataStoragePart) {
        sb.append("\nFound a CustomXmlDataStoragePart, named " + entry.getPartName().getName() );
        if (entry.getRelationshipsPart()==null) { continue; }
        sb.append("\n.. 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) {
          sb.append("\n.. but that doesn't point to a  customXmlProps part");
          continue;
        }
        CustomXmlDataStoragePropertiesPart customXmlProps =
          (CustomXmlDataStoragePropertiesPart)entry.getRelationshipsPart().getPart(r);
        if (customXmlProps==null) {
          sb.append("\n.. but the target seems to be missing?");
          continue;
        }
        String itemId = customXmlProps.getItemId().toLowerCase();
View Full Code Here

    Iterator partIterator = this.getParts().getParts().entrySet().iterator();
      while (partIterator.hasNext()) {
       
          Map.Entry pairs = (Map.Entry)partIterator.next();
         
          Part p = (Part)pairs.getValue();
          if (p instanceof SlideLayoutPart) {
            SldLayout sldLayout = ((SlideLayoutPart)p).getJaxbElement();           
            globalPlaceHolders.putAll( ((SlideLayoutPart)p).getIndexedPlaceHolders()  );
          }
      }
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) {

//            ResolvedLayout rl = ((SlidePart)p).getResolvedLayout();             
//            System.out.println( XmlUtils.marshaltoString(rl.getShapeTree(), false, true, Context.jcPML,
//                "http://schemas.openxmlformats.org/presentationml/2006/main", "spTree", GroupShape.class) );
View Full Code Here

        sb.append("\n" + indent + "external resource " + r.getTarget()
               + " of type " + r.getType() );
        continue;       
      }
     
      Part part = rp.getPart(r);
     
     
      printInfo(part, sb, indent);
      if (handled.get(part)!=null) {
        sb.append(" [additional reference] ");
        continue;
      }
      handled.put(part, part);
      if (part.getRelationshipsPart()==null) {
        // sb.append(".. no rels" );           
      } else {
        traverseRelationships(wordMLPackage, part.getRelationshipsPart(), sb, indent + "    ");
      }
         
    }
   
   
View Full Code Here

//        target = (new java.net.URI(target)).normalize().toString();
//        log.info("Normalised, it is " + target );
       
        if (!false) {
          log.info("Getting part /" + resolvedPartUri );
          Part part = p.getParts().get(new PartName("/" + resolvedPartUri));
          log.info( part.getClass());
         
          savePart(baseNode, part);
         
        }
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.