Package org.docx4j.openpackaging.parts.relationships

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


//        <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();
      //deprecatedSaveRawXmlPart(out, partName, rp.getDocument() );
      // 2008 06 12 - try this neater method
      saveRawXmlPart(out, rp, partName );
     
     
View Full Code Here


      saveRawXmlPart( out, 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(out, rrp, relPart );
View Full Code Here

    // Note 2: Really, you should clone - this is not a 'copy' as such:
    // the part will end up being referenced in both packages,
    // though part.getPackage() will only return the dest package.
    // So, be careful, you should throw away source package after doing this! 
    // TODO: This example probably should be re-worked.
    RelationshipsPart rp = wmlSourcePkg.getMainDocumentPart().getRelationshipsPart();
    Relationship rel = rp.getRelationshipByType(Namespaces.SPREADSHEETML_CHART);   
    Part p = rp.getPart(rel);
   
    System.out.println(p.getPartName().getName() );
   
    //p.setPartName( new PartName(p.getPartName().getName()) ); // same name
      // WARNING: that has the effect of removing the part of old name
View Full Code Here

//      <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
//    </Relationships>   
   
    String partName = "/_rels/.rels"; // note leading '/'
   
    RelationshipsPart rp = getRelationshipsPartFromXmlPackage(packageResult, partName);   
    packageResult.setRelationships(rp);
    //rp.setPackageRelationshipPart(true);   
   
   
    log.info( "Object created for: " + partName);
View Full Code Here

  }
 
  private RelationshipsPart getRelationshipsPartFromXmlPackage(Base p, String partName)
      throws Docx4JException {
   
    RelationshipsPart rp = null;
   
    try {
     
      org.docx4j.xmlPackage.Part part = parts.get(partName);
     
View Full Code Here

          + " to " + part.getPartName());
    }
   
//    log.info(".. added." );
   
    RelationshipsPart rrp = getRelationshipsPart( part);
    if (rrp!=null) {
      // recurse via this parts relationships, if it has any
      addPartsFromRelationships( part, rrp );
//      String relPart = PartName.getRelationshipsPartName(
//          part.getPartName().getName().substring(1) );
View Full Code Here

    // recurse via this parts relationships, if it has any
   
    String relPart = PartName.getRelationshipsPartName(
        part.getPartName().getName() );

    RelationshipsPart rrp = getRelationshipsPartFromXmlPackage(part,  relPart);
   
    if (rrp!=null) {
      part.setRelationships(rrp);
    } else {
      log.debug("No relationships " + relPart )
View Full Code Here

   * @throws InvalidFormatException
    
   */
  private static void handleRels(Differencer pd, MainDocumentPart newMDP) throws InvalidFormatException {
   
    RelationshipsPart rp = newMDP.getRelationshipsPart();
    //System.out.println("before: \n" + rp.getXML());   
   
    // Since we are going to add rels appropriate to the docs being
    // compared, for neatness and to avoid duplication
    // (duplication of internal part names is fatal in Word,
    //  and export xslt makes images internal, though it does avoid duplicating
    //  a part ),
    // remove any existing rels which point to images
    List<Relationship> relsToRemove = new ArrayList<Relationship>();
    for (Relationship r : rp.getRelationships().getRelationship() ) {
      //  Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
      if (r.getType().equals(Namespaces.IMAGE)) {
        relsToRemove.add(r);
      }
    }           
    for (Relationship r : relsToRemove) {       
      rp.removeRelationship(r);
    }
   
    // Now add the rels we composed
    Map<Relationship, Part> newRels = pd.getComposedRels();
    for (Relationship nr : newRels.keySet()) { 
View Full Code Here

    } finally {
      IOUtils.closeQuietly(is);
    }
   
    // .. now find the name of the main part
    RelationshipsPart rp = RelationshipsPart.createPackageRels();
    populatePackageRels(rp);
   
    String mainPartName = PackageRelsUtil.getNameOfMainPart(rp);
    PartName mainPartNameObj;
    if (mainPartName.startsWith("/")) {
      // OpenXML SDK 2.0 writes Target="/word/document.xml" (note leading "/")
      mainPartNameObj = new PartName(mainPartName);
    } else {
      // Microsoft Word, docx4j etc write Target="word/document.xml"
      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
//    (ii) add the new Part to the package
View Full Code Here

 
  private RelationshipsPart getRelationshipsPartFromZip(Base p, String partName)
      throws Docx4JException {
   
   
    RelationshipsPart rp = null;
   
    InputStream is = null;
    try {
      is =  partStore.loadPart( partName);
      if (is==null) {
        return null; // that's ok
      }
      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

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.