Package org.docx4j.openpackaging.parts.relationships

Examples of org.docx4j.openpackaging.parts.relationships.RelationshipsPart


      saveRawXmlPart( part );
    }
    handled.put(resolvedPartUri, resolvedPartUri);
   
    // recurse via this parts relationships, if it has any
    RelationshipsPart rrp = part.getRelationshipsPart(false); //don't create
    if (rrp!= null ) {
     
      //log.debug("Found relationships " + rrp.getPartName() );
     
      // Only save it if it actually has rels in it
      if (rrp.getRelationships().getRelationship().size()>0) {
       
//        String relPart = PartName.getRelationshipsPartName(resolvedPartUri);
//        //log.debug("Cf constructed name " + relPart );
//       
//        saveRawXmlPart(rrp, relPart );
View Full Code Here


    // Open a document from the file system
    // 1. Load the Package - .docx or Flat OPC .xml
    org.docx4j.openpackaging.packages.OpcPackage opcPackage = org.docx4j.openpackaging.packages.OpcPackage.load(new java.io.File(inputfilepath));   
   
    // List the parts by walking the rels tree
    RelationshipsPart rp = opcPackage.getRelationshipsPart();
    StringBuilder sb = new StringBuilder();
    traverseRelationships(opcPackage, rp, sb, "    ");
   
    approach2(opcPackage, sb);
   
View Full Code Here

    // Open a document from the file system
    // 1. Load the Package - .docx or Flat OPC .xml
    org.docx4j.openpackaging.packages.OpcPackage xlsxPkg = org.docx4j.openpackaging.packages.OpcPackage.load(new java.io.File(inputfilepath));   
   
    // List the parts by walking the rels tree
    RelationshipsPart rp = xlsxPkg.getRelationshipsPart();
    StringBuilder sb = new StringBuilder();
    printInfo(rp, sb, "");
    traverseRelationships(xlsxPkg, rp, sb, "    ");
   
    System.out.println(sb.toString());
View Full Code Here

//        <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 = p.getRelationshipsPart();
      // TODO - replace with saveRawXmlPart(baseNode, rp)
      // once we know that partName resolves correctly
//      saveRawXmlPart(baseNode, partName, rp.getW3cDocument() );
      saveRawXmlPart(baseNode, rp );
     
View Full Code Here

    }
    handled.put(resolvedPartUri, resolvedPartUri);
   
    // recurse via this parts relationships, if it has any
    if (part.getRelationshipsPart()!= null ) {
      RelationshipsPart rrp = part.getRelationshipsPart(); // **
      String relPart = PartName.getRelationshipsPartName(resolvedPartUri);
      log.info("Found relationships " + relPart );
     
      //saveRawXmlPart(baseNode,  relPart, rrp.getW3cDocument() );
      saveRawXmlPart(baseNode,  rrp );
View Full Code Here

    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
   
    // Change the rels to TargetMode="External"
    // Fetch rels part
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
    RelationshipsPart relsPart = documentPart.getRelationshipsPart();
    Relationships rels = relsPart.getRelationships();
    List<Relationship> relsList = rels.getRelationship();
   
    // For each image rel
    for (Relationship r : relsList) {

      System.out.println(r.getTargetMode());
      if ( r.getType().equals( Namespaces.IMAGE )
          && (r.getTargetMode()==null
              || r.getTargetMode().equalsIgnoreCase("internal"))) {
       
        String target = r.getTarget();
        System.out.println("target: " + target);
       
        if (saveImages) {
          // Save the image as a file in the specified location
         
          File f = new File(BASE_DIR + "/" + target);
          if (f.exists()) {
            System.out.println("Overwriting existing object: " + f.getPath() );
          } else if ( !f.getParentFile().exists() ) {
            System.out.println("creating " + f.getParentFile().getAbsolutePath() );
            f.getParentFile().mkdirs();
            //f = new File(BASE_DIR + "/" + target);
          }         
         
          Part p = relsPart.getPart(r);
          FileOutputStream fos = new FileOutputStream( f );
          ((BinaryPart)p).writeDataToOutputStream(fos);
          fos.close();
         
        }
View Full Code Here

    } catch (NullPointerException e) {
      throw new Docx4JException("Couldn't get [Content_Types].xml from ZipFile", e);
    }
   
    // .. now find the name of the main part
    RelationshipsPart rp = RelationshipsPart.createPackageRels();
    populatePackageRels(partByteArrays, rp);
   
    String mainPartName = PackageRelsUtil.getNameOfMainPart(rp);
    String pkgContentType = ctm.getContentType(new PartName("/" + mainPartName));

    // 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.setRelationships(rp);
    rp.setSourceP(p); //
   
    // 5. Now recursively
//    (i) create new Parts for each thing listed
//    in the relationships
//    (ii) add the new Part to the package
View Full Code Here

 
  //private RelationshipsPart getRelationshipsPartFromZip(Base p, ZipFile zf, String partName)
  private RelationshipsPart getRelationshipsPartFromZip(Base p, HashMap<String, ByteArray> partByteArrays, String partName)
      throws Docx4JException {
   
    RelationshipsPart rp = null;
   
    InputStream is = null;
    try {
      is =  getInputStreamFromZippedPart( partByteArrays,  partName);
      //thePart = new RelationshipsPart( p, new PartName("/" + partName), is );
//      rp = new RelationshipsPart(new PartName("/" + partName) );
//      rp.setSourceP(p);
      rp = p.getRelationshipsPart(true);
      rp.unmarshal(is);
     
    } catch (Exception e) {
      e.printStackTrace();
      throw new Docx4JException("Error getting document from Zipped Part:" + partName, e);
     
View Full Code Here

    pkg.handled.put(resolvedPartUri, resolvedPartUri);

   
//    unusedZipEntries.put(resolvedPartUri, new Boolean(false));
   
    RelationshipsPart rrp = getRelationshipsPart(partByteArrays, part);
    if (rrp!=null) {
      // recurse via this parts relationships, if it has any
      addPartsFromRelationships(partByteArrays, part, rrp, ctm );
//      String relPart = PartName.getRelationshipsPartName(
//          part.getPartName().getName().substring(1) );
View Full Code Here

  //public RelationshipsPart getRelationshipsPart(ZipFile zf, Part part)
  public RelationshipsPart getRelationshipsPart(HashMap<String, ByteArray> partByteArrays,
      Part part)
  throws Docx4JException, InvalidFormatException {
   
    RelationshipsPart rrp = null;
    // recurse via this parts relationships, if it has any
    //String relPart = PartName.getRelationshipsPartName(target);
    String relPart = PartName.getRelationshipsPartName(
        part.getPartName().getName().substring(1) );
   
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.parts.relationships.RelationshipsPart

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.