Java Code Examples for org.docx4j.wml.P#Hyperlink

The following examples show how to use org.docx4j.wml.P#Hyperlink . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UrlVisitor.java    From yarg with Apache License 2.0 6 votes vote down vote up
@Override
public List<Object> apply(Object o) {
    if (o instanceof P.Hyperlink) {
        P.Hyperlink hyperlink = (P.Hyperlink) o;
        try {
            Relationships contents = mainDocumentPart.getRelationshipsPart().getContents();
            List<Relationship> relationships = contents.getRelationship();
            for (Relationship relationship : relationships) {
                if (relationship.getId().equals(hyperlink.getId())) {
                    relationship.setTarget(docxFormatter.handleStringWithAliases(URLDecoder.decode(relationship.getTarget(), "UTF-8")));
                }
            }
        } catch (Exception e) {
            throw new RuntimeException("An error occurred while processing URL with aliases",e);
        }
    }
    return null;
}
 
Example 2
Source File: AliasVisitor.java    From yarg with Apache License 2.0 5 votes vote down vote up
@Override
public List<Object> apply(Object o) {
    if (o instanceof P || o instanceof P.Hyperlink) {
        String paragraphText = docxFormatter.getElementText(o);

        if (AbstractFormatter.UNIVERSAL_ALIAS_PATTERN.matcher(paragraphText).find()) {
            Set<Text> mergedTexts = new TextMerger((ContentAccessor) o, AbstractFormatter.UNIVERSAL_ALIAS_REGEXP).mergeMatchedTexts();
            for (Text text : mergedTexts) {
                handle(text);
            }
        }
    }

    return null;
}