All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.xml.msofficexml.docx.wordprocessingml.WmlHyperlink Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.xml.msofficexml.docx.wordprocessingml;

import java.net.URL;

import com.hfg.xml.XMLizable;
import com.hfg.xml.msofficexml.docx.Docx;
import com.hfg.xml.msofficexml.docx.DocxException;
import com.hfg.xml.msofficexml.docx.RelationshipXML;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlCharacterStyle;


public class WmlHyperlink extends WmlXMLTag
{

   //---------------------------------------------------------------------------
   public WmlHyperlink(URL inURL, Docx inDocx)
   {
      super(WmlXML.HYPERLINK, inDocx);

      if (null == inDocx)
      {
         throw new DocxException("No reference to the parent doc available!?");
      }

      String id = inDocx.getMainDocPartRelationshipPart().addHyperlink(inURL);
      setAttribute(RelationshipXML.ID_ATT, id);

      // Ensure that the styles part has been initialized
      inDocx.getStylesPart();
   }

   //---------------------------------------------------------------------------
   public WmlHyperlink setId(String inValue)
   {
      setAttribute(RelationshipXML.ID_ATT, inValue);
      return this;
   }

   //---------------------------------------------------------------------------
   public String getId()
   {
      return getAttributeValue(RelationshipXML.ID_ATT.getLocalName());
   }

   //---------------------------------------------------------------------------
   public WmlTextRun addTextRun()
   {
      WmlTextRun run = new WmlTextRun(getParentDoc());
      run.getProperties().setStyle(WmlCharacterStyle.HYPERLINK_STYLE_NAME);
      addSubtag(run);

      return run;
   }

   //---------------------------------------------------------------------------
   public WmlTextRun addTextRun(String inContent)
   {
      WmlTextRun run = addTextRun();
      run.addText(inContent);

      return run;
   }

   //---------------------------------------------------------------------------
   @Override
   public void addSubtag(XMLizable inSubtag)
   {
      super.addSubtag(inSubtag);
      // If it's a textRun, make sure that it has the hyperlink style
      if (inSubtag instanceof WmlTextRun)
      {
         ((WmlTextRun)inSubtag).getProperties().setStyle(WmlCharacterStyle.HYPERLINK_STYLE_NAME);
      }
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy