Package org.docx4j.relationships

Examples of org.docx4j.relationships.Relationship


    // 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
View Full Code Here


        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;
          }
View Full Code Here

    if ( this instanceof RelationshipsPart ) {     
      throw new InvalidFormatException("You should add your part to the target part, not the target part's relationships part.");
    }
   
    // Now add the targetpart to the relationships
    Relationship rel = this.getRelationshipsPart().addPart(targetpart, mode,
        getPackage().getContentTypeManager(), proposedRelId);
   
    // Finally, set part shortcut if there is one to set
    boolean shortcutSet = setPartShortcut(targetpart, targetpart.getRelationshipType());
    if (shortcutSet) {
View Full Code Here

      return;
    }
   
   
    log.debug("Looking for rel " + relId);
    Relationship r = docPartRels.getRelationshipByID(relId);
    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() );
   
   
   
   
    pd.composedRels.put(r2, p);
View Full Code Here

  @Override
  public AlternativeFormatInputPart addAltChunk(AltChunkType type, byte[] bytes,
      ContentAccessor attachmentPoint)   throws Docx4JException {
   
    AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(type);
    Relationship altChunkRel = this.addTargetPart(afiPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
    // now that its attached to the package ..
    afiPart.registerInContentTypeManager();
   
    afiPart.setBinaryData(bytes);    
   
    // .. the bit in document body
    CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
    ac.setId(altChunkRel.getId() );
    attachmentPoint.getContent().add(ac);
         
    return afiPart;
  }
View Full Code Here

  @Override
  public AlternativeFormatInputPart addAltChunk(AltChunkType type, InputStream is,
      ContentAccessor attachmentPoint) throws Docx4JException {
   
    AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(type);
    Relationship altChunkRel = this.addTargetPart(afiPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
    // now that its attached to the package ..
    afiPart.registerInContentTypeManager();   
   
    afiPart.setBinaryData(is);
   
    // .. the bit in document body
    CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
    ac.setId(altChunkRel.getId() );
    attachmentPoint.getContent().add(ac);
         
    return afiPart;
  }
View Full Code Here

    {

        WordprocessingMLPackage wmlPackage = WordprocessingMLPackage
                .createPackage();

    Relationship relationship = createHeaderPart(wmlPackage);
    createHeaderReference(wmlPackage, relationship);
        File f = new File(System.getProperty("user.dir") + "/waterMarksample.docx");
        wmlPackage.save(f);

    }
View Full Code Here

  public static Relationship createHeaderPart(
      WordprocessingMLPackage wordprocessingMLPackage)
      throws Exception {
   
    HeaderPart headerPart = new HeaderPart();
    Relationship rel =  wordprocessingMLPackage.getMainDocumentPart()
        .addTargetPart(headerPart);
   
    headerPart.setJaxbElement(getHdr(wordprocessingMLPackage, headerPart));

    return rel;
View Full Code Here

   
    if (master!=null) {
      return master;
    }
   
    Relationship masterRel = getRelationshipsPart().getRelationshipByType(
        Namespaces.PRESENTATIONML_SLIDE_MASTER);
    if (masterRel==null) {
      log.warn(this.getPartName().getName() + " has no master!");
    } else {
      master = (SlideMasterPart)getRelationshipsPart().getPart(masterRel);
View Full Code Here

    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
        .load(new java.io.File(
            System.getProperty("user.dir")
            + "/SmartArt/OUT-xx.docx"));
   
    Relationship r = wordMLPackage.getMainDocumentPart().getRelationshipsPart().getRelationshipByType(Namespaces.DRAWINGML_DIAGRAM_DATA);
   
    if (r==null) {
      System.out.println("No DDP!");
      return;
    }

    DiagramDataPart thisPart = (DiagramDataPart)wordMLPackage.getMainDocumentPart().getRelationshipsPart().getPart(r);     
   
    thisPart.setFriendlyIds(thisPart.getJaxbElement());
   
    System.out.println( XmlUtils.marshaltoString(thisPart.getJaxbElement(), true, true));

    // What does it look like in our format?
    DiagramDataUnflatten diagramDataUnflatten = new DiagramDataUnflatten(thisPart);
    String exchange= XmlUtils.marshaltoString(diagramDataUnflatten.convert(), true, true);
    System.out.println( exchange );   
    PrintWriter out = new PrintWriter(System.getProperty("user.dir")
        + "/SmartArt/12hi.xml");
    out.println(exchange);
    out.flush();
    out.close();

    // Check our format templates
    List<JAXBElement<CTTextBody>> textFormats = diagramDataUnflatten.getTextFormats();
    System.out.println("Template list =============== ");
    for (JAXBElement<CTTextBody> tb : textFormats) {
      System.out.println( XmlUtils.marshaltoString(tb, true, true));       
    }
    System.out.println("============================= ");
   
    // Now fix the IDs in the drawing part to match
    // TODO: just drop this part altogether; we don't need it
    Relationship r2 = wordMLPackage.getMainDocumentPart().getRelationshipsPart().getRelationshipByType(Namespaces.DRAWINGML_DIAGRAM_DRAWING);   
    if (r2==null) {
      System.out.println("No DDrawingP!");
    } else {
      DiagramDrawingPart drawingPart = (DiagramDrawingPart)wordMLPackage.getMainDocumentPart().getRelationshipsPart().getPart(r2);
      drawingPart.setFriendlyIds(thisPart.map);     
View Full Code Here

TOP

Related Classes of org.docx4j.relationships.Relationship

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.