Skip to content

Commit

Permalink
Merge pull request #470 from syjer/469-accept-generic-uri
Browse files Browse the repository at this point in the history
Fixes #469 - better handling of href uri
  • Loading branch information
danfickle authored Apr 30, 2020
2 parents c5d5452 + 4eab947 commit 705cfd2
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.awt.*;
import java.awt.geom.*;
import java.io.IOException;
import java.net.URI;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;
Expand Down Expand Up @@ -232,7 +233,7 @@ private void addUriAsLink(RenderingContext c, Box box, PDPage page, float pageHe
} else {
XRLog.general(Level.WARNING, "Could not find valid target for link. Link href = " + uri);
}
} else if (uri.contains("://")) {
} else if (isURI(uri)) {
PDActionURI uriAct = new PDActionURI();
uriAct.setURI(uri);

Expand All @@ -249,6 +250,15 @@ private void addUriAsLink(RenderingContext c, Box box, PDPage page, float pageHe
}
}

private static boolean isURI(String uri) {
try {
return URI.create(uri) != null;
} catch (IllegalArgumentException e) {
XRLog.general(Level.INFO, "'"+uri+"' in href is not a valid URI, will be skipped");
return false;
}
}

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean placeAnnotation(AffineTransform transform, Shape linkShape, Rectangle2D targetArea,
PDAnnotationLink annot) {
Expand Down

0 comments on commit 705cfd2

Please sign in to comment.