Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.docx4j.convert.out.common.writer;
  
  import java.util.List;
  
  
Model for the hyperlink tag.
 
 	
 	private static Logger log = LoggerFactory.getLogger(AbstractHyperlinkWriterModel.class);
 	
 	protected Node content = null;

field-argument of the Hyperlink field or the targetUri of the relationship. corresponds to switch \l field-argument, the \l switch might be omitted.
 
 	protected String target = null;

Only avaiable if the information is read from a relationship. Otherwise always false.
 
 	protected boolean external = false;

Specifies the name of a bookmark in the current document which shall be the target of this hyperlink.
If this attribute is omitted, then the default behavior shall be to navigate to the start of the document. If a hyperlink target is also specified using the r:id attribute, then this attribute shall be ignored.
 
 	protected String anchor = null;

Specifies a location in the target of the hyperlink that has no bookmarks. The method by which the contents of this attribute are linked to document text is outside the scope of ECMA-376.
 
 	protected String docLocation = null;
 	
 	//history - ignored
 	
Specifies the ID of the relationship whose target shall be used as the target for this hyperlink.
 
 	protected String rId = null;

Specifies a frame within the parent HTML frameset for the target of the parent hyperlink when one exists. corresponds to switch \t field-argument corresponds to switch \n with tgtFrame = "_blank"
 
 	protected String tgtFrame = null;

Specifies a string which can be surfaced in a user interface as associated with the parent hyperlink. corresponds to switch \o field-argument
 
 	protected String tooltip = null;
 
 	// imageMapCoordinates switch \m ignored - requires a ismap attribute in an embedded img
 	
 //	P.Hyperlink pHyperlink;
 //	/**
 //	 * Where this model was built with a P.Hyperlink,
 //	 * here it is.  Useful for debugging.
 //	 * @return
 //	 */
 //	public P.Hyperlink getPHyperlink() {
 //		return pHyperlink;
 //	}
 	
Default build method, get's called with a P.Hyperlink.
 
 	public void build(AbstractWmlConversionContext conversionContextObject nodeNode contentthrows TransformerException {
 		
 		Relationship relationship = null;
 		RelationshipsPart rPart = null;
 		P.Hyperlink pHyperlink = (P.Hyperlink)node;
 		
 //		log.debug(XmlUtils.marshaltoString(hyperlink, true, true));
 		
 		this. = content;
 		setAnchor(pHyperlink.getAnchor());
		setRId(pHyperlink.getId());
		setTgtFrame(pHyperlink.getTgtFrame());
		setTooltip(pHyperlink.getTooltip());
		if (conversionContext.getCurrentPart() == null) {
			.warn("set currentPart (via conversionContext)");
else if ((getRId() != null) && 
			(getRId().length() > 0) ) {
			rPart = conversionContext.getCurrentPart().getRelationshipsPart();
			if (rPart == null) {
				.error("RelationshipsPart is missing!");				
else {
				.debug("looking for rel" + getRId());
				relationship = rPart.getRelationshipByID(getRId());
				if ((relationship != null) &&
					(..equals(relationship.getType()))) {
					setTarget(relationship.getTarget());
					setExternal("External".equals(relationship.getTargetMode()));
				}
			}
		}
	}

Custom build method, get's used with a FldSimpleModel in those cases where the hyperlink is defined within a Field
	public void build(AbstractWmlConversionContext conversionContextFldSimpleModel fldSimpleModelNode contentthrows TransformerException {
		int idx = 0;
		List<Stringparameters = fldSimpleModel.getFldParameters();
		String parameter = null;
		boolean isSwitch = false;
		char switchChar = '\0';
		String switchParameter = null;
		this. = content;
		while (idx < parameters.size()) {
			parameter = parameters.get(idx);
			if ((parameter != null) && (parameter.length() > 0)) {//should allways be true
				isSwitch = ((parameter.charAt(0) == '\\') && (parameter.length() == 2));
				if (isSwitch) {
					switchChar = Character.toLowerCase(parameter.charAt(1));
					switch (switchChar) {
						case 'l'//target
							switchParameter = FormattingSwitchHelper.getSwitchValue(idx + 1, parameters);
							if (switchParameter != null) {
								setTarget(switchParameter);
								idx++;
							}
							break;
						case 't'//target frame name
							switchParameter = FormattingSwitchHelper.getSwitchValue(idx + 1, parameters);
							if (switchParameter != null) {
								setTgtFrame(switchParameter);
								idx++;
							}
							break;
						case 'n'//target frame = "_blank"
							setTgtFrame("_blank");
							break;
						case 'o'//tooltip
							switchParameter = FormattingSwitchHelper.getSwitchValue(idx + 1, parameters);
							if (switchParameter != null) {
								setTooltip(switchParameter);
								idx++;
							}
							break;
						case 'm'//image map coordinates
							break;
					}
				}
				else { 
					//should only happen once with the first value, all others should be preceeded by a switch
					if (idx == 0) {
						setTarget(FormattingSwitchHelper.getSwitchValue(idxparameters));
					}
				}
			}
			idx++;
		}
		if ((getTarget() != null) && 
			(getTarget().length() > 0) &&
			((getTarget().indexOf('/') > -1) ||
			 (getTarget().indexOf('\\') > -1) ||
			 (getTarget().indexOf('.') > -1) ||
			 (getTarget().indexOf(':') > -1))) {
			/* Don't know if this is correct: assume an external target if it contains
			 * one of the following characters: \/:.
			 */
		}
	}
		return (isExternal() ? getTarget() : null);
	}
		String ret = (isExternal() ? null : getTarget());
		if (ret == null) {
			ret = getAnchor(); // this is a target, see http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/hyperlink_2.html
		}
		if (ret == null) {
			ret = getDocLocation();
		}
		return ret;
	}
	public String getTarget() {
		return ;
	}
	public void setTarget(String target) {
		this. = target;
	}
	public boolean isExternal() {
		return ;
	}
	public void setExternal(boolean external) {
		this. = external;
	}
	public String getAnchor() {
		return ;
	}
	public void setAnchor(String anchor) {
		this. = anchor;
	}
	public String getDocLocation() {
		return ;
	}
	public void setDocLocation(String docLocation) {
		this. = docLocation;
	}
	public String getRId() {
		return ;
	}
	public void setRId(String rId) {
		this. = rId;
	}
	public String getTgtFrame() {
		return ;
	}
	public void setTgtFrame(String tgtFrame) {
		this. = tgtFrame;
	}
	public String getTooltip() {
		return ;
	}
	public void setTooltip(String tooltip) {
		this. = tooltip;
	}
	public Node getContent() {
		return ;
	}
	public String toString() {
		return "HyperlinkModel [target=" +  + ", external=" + 
", anchor=" +  + ", docLocation=" + 
", rId=" +  + ", tgtFrame=" +  + "]";
	}
New to GrepCode? Check out our FAQ X