/**
   * Create a linked image part, and attach it as a rel of the specified source part (eg a header
   * part).
   *
   * <p>The current behaviour is that the part is added to the package, but since the target mode of
   * the rel is external, the part is redundant.
   *
   * @param wordMLPackage
   * @param sourcePart
   * @param url
   * @return
   * @throws Exception
   */
  public static BinaryPartAbstractImage createLinkedImagePart(
      OpcPackage opcPackage, Part sourcePart, URL url) throws Exception {

    log.debug("Incoming url for linked image: " + url.toString());

    ImageInfo info =
        ensureFormatIsSupported(url, null, null, false); // final param doesn't matter in this case

    ContentTypeManager ctm = opcPackage.getContentTypeManager();
    String proposedRelId = sourcePart.getRelationshipsPart().getNextId();
    // In order to ensure unique part name,
    // idea is to use the relId, which ought to be unique
    String ext = info.getMimeType().substring(info.getMimeType().indexOf("/") + 1);

    BinaryPartAbstractImage imagePart =
        (BinaryPartAbstractImage)
            ctm.newPartForContentType(
                info.getMimeType(),
                createImageName(opcPackage, sourcePart, proposedRelId, ext),
                null);

    // NB: contents never populated

    log.debug(
        "created part "
            + imagePart.getClass().getName()
            + " with name "
            + imagePart.getPartName().toString());

    imagePart.rels.add(
        sourcePart.addTargetPart(
            imagePart)); // want to create rel with suitable name; side effect is to add part
    imagePart.getRelLast().setTargetMode("External");

    opcPackage.getExternalResources().put(imagePart.getExternalTarget(), imagePart);

    //		if (!url.getProtocol().equals("file") && new File(url.toString() ).isFile()) {
    //			imagePart.rel.setTarget("file:///" + url);
    //		} else {
    //			imagePart.rel.setTarget(url.toString());
    //		}
    imagePart.getRelLast().setTarget(url.toString());

    imagePart.setImageInfo(info);

    return imagePart;
  }