com.hfg.xml.msofficexml.docx.wordprocessingml.WmlHyperlink Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
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);
}
}
}