Package org.docx4j.relationships

Examples of org.docx4j.relationships.Relationship


  /** Gets a loaded Part by its id */
  public Part getPart(String id) {

    log.debug("looking for: " + id);
   
    Relationship r = getRelationshipByID(id);
      log.info(id + " points to " + r.getTarget());
   
    return getPart(r);   
  }
View Full Code Here


    log.debug("Result " + target);
   
    // Check whether we already have a rel with this target
    // This code is a bit more efficient than getRel, since it
    // doesn't unrelativise each existing rel!
    Relationship existsAlready = null;
    for (Relationship rel : jaxbElement.getRelationship() ) {
      if (rel.getTarget().equals(target)) {
        existsAlready = rel;
        break// Assumes at most 1 existing rel with this target
      }
    }

    if (log.isDebugEnabled()) {
      boolean exists = (existsAlready!=null);
      log.debug("rel exists: " + exists);
    }
   
    if (existsAlready!=null
        && mode.equals(AddPartBehaviour.REUSE_EXISTING)) {
      log.debug("Returning preexisting rel");
      return existsAlready;
    }
   
    // sanity check
    if (existsAlready!=null && mode.equals(AddPartBehaviour.RENAME_IF_NAME_EXISTS)) {
      // Shouldn't happen
      throw new InvalidFormatException("Found existing rel, and yet constructed part name should be globally unique!");
    }
   
    if (this.getPackage().getParts().get( newPartName )!=null
        && mode.equals(AddPartBehaviour.OVERWRITE_IF_NAME_EXISTS)) {
     
      // ie we have the same part in the package already, not
      // necessarily referenced by a rel in this rp.
     
      // overwrite the part
      if (existsAlready!=null) {
       
        // we reuse it. can't assume its the same type, though, so
        existsAlready.setType( part.getRelationshipType() );       
       
        loadPart(part, existsAlready);
        return existsAlready;
      }
           
      // case where rel doesn't exist (it might not in this rp), create a rel to it
      // is handled below
    }   
   
    // OK, create the new rel
   
    org.docx4j.relationships.ObjectFactory factory =
      new org.docx4j.relationships.ObjectFactory();
   
    Relationship rel = factory.createRelationship();
   
    rel.setTarget(target );
    //rel.setTargetMode( TargetMode.INTERNAL );
    rel.setType( part.getRelationshipType() );
   
    if (relId!=null) {
      rel.setId( relId );     
    }
   
    addRelationship(rel );
   
      String ext = part.getPartName().getExtension();
View Full Code Here

 
  public void removeRelationship(PartName partName) {
   
    // Remove the relationship for which it is a target from here
    // Throw an error if this can't be found!
    Relationship relToBeRemoved = null;
    for (Relationship rel : jaxbElement.getRelationship() ) {
     
      if (rel.getTargetMode() !=null
          && rel.getTargetMode().equals("External") ) {
        // This method can't be used to remove external resources
View Full Code Here

    public List<Relationship> differingContent(RelationshipsPart otherRP) throws Docx4JException {
     
      List<Relationship> results = new ArrayList<Relationship>();
           
    for ( Relationship r : jaxbElement.getRelationship()  ) {
      Relationship otherR = getRelationshipByTarget(otherRP, r.getTarget());
      if (otherR!=null ) {
       
        if (r.getTargetMode() !=null && r.getTargetMode().equals("External") ) {
          if (otherR.getTargetMode() !=null && otherR.getTargetMode().equals("External")) {
            // Usual case
            if (!r.getTarget().equals(otherR.getTarget()) ) {
              // Should never happen, since we matched on target
              throw new Docx4JException("broken logic!");
              //results.add(r);
              //log.debug("External: " + r.getTarget() );             
            }
View Full Code Here

   */ 
  @Deprecated
  public Presentation.SldIdLst.SldId addSlideIdListEntry(SlidePart slidePart, AddPartBehaviour mode)
    throws InvalidFormatException

    Relationship rel = this.addTargetPart(slidePart, mode);
   
    Presentation.SldIdLst.SldId entry = Context.getpmlObjectFactory().createPresentationSldIdLstSldId();
   
    entry.setId( this.getSlideId() );
    entry.setRid(rel.getId());
   
    this.getJaxbElement().getSldIdLst().getSldId().add(entry);
   
    return entry;
   
View Full Code Here

  }
 
  public Presentation.SldMasterIdLst.SldMasterId addSlideMasterIdListEntry(SlideMasterPart slideMasterPart)
    throws InvalidFormatException

    Relationship rel = this.addTargetPart(slideMasterPart);
   
    Presentation.SldMasterIdLst.SldMasterId entry = Context.getpmlObjectFactory().createPresentationSldMasterIdLstSldMasterId();
   
    entry.setId( new Long(this.getSlideLayoutOrMasterId()) );
    entry.setRid(rel.getId());

    this.getJaxbElement().getSldMasterIdLst().getSldMasterId().add(entry);
   
    return entry;
     
View Full Code Here

     *
     * Nor can 2 distinct relIds target the same part.
     */
   
    try {
      Relationship rel = this.addTargetPart(slidePart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
      return this.getJaxbElement().getSldIdLst().getSldId().add(createSlideIdListEntry(rel));
    } catch (InvalidFormatException e) {
      throw new Pptx4jException(e.getMessage(), e);
    }
  }
View Full Code Here

    if (index< 0 || index>zeroBasedCount) {
      throw new Pptx4jException("Can't add slide at index " + index + ".  (There are " + sldIds.size() + " slides) ");     
    }
   
    try {
      Relationship rel = this.addTargetPart(slidePart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
      sldIds.add(index, createSlideIdListEntry(rel));
    } catch (InvalidFormatException e) {
      throw new Pptx4jException(e.getMessage(), e);
    }
  }
View Full Code Here

      throw new Pptx4jException("No slide at index " + index + ".  (There are " + sldIds.size() + " slides) ");     
    }
   
    Presentation.SldIdLst.SldId entry = this.getJaxbElement().getSldIdLst().getSldId().remove(index);
   
    Relationship rel = this.getRelationshipsPart().getRelationshipByID(entry.getRid());
   
    Part part = this.getRelationshipsPart().getPart(rel);
   
    this.getPackage().getParts().remove(part.getPartName());
    this.getRelationshipsPart().removeRelationship(rel);
View Full Code Here

    SlideLayoutPart layoutPart = null;
   
    // Need these for images etc
    resolvedLayout.relationships = slidePart.getRelationshipsPart();   
   
    Relationship rel = slidePart.getRelationshipsPart().getRelationshipByType(
        Namespaces.PRESENTATIONML_SLIDE_LAYOUT);
    if (rel==null) {
      log.warn(slidePart.getPartName().getName() + " has no explicit layout!");
      // This happens at least some of the time.
      // eg for title slide
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.