|
11 | 11 | import java.text.DecimalFormat; |
12 | 12 | import java.time.LocalDateTime; |
13 | 13 | import java.time.format.DateTimeFormatter; |
14 | | -import java.util.Iterator; |
15 | 14 | import java.util.List; |
16 | 15 | import java.util.stream.IntStream; |
17 | 16 |
|
@@ -45,45 +44,53 @@ private static double round(double value, int precision) { |
45 | 44 | return (double) Math.round(value * scale) / scale; |
46 | 45 | } |
47 | 46 |
|
48 | | - public Document convertMessageToAdl(String message, String address, Font f, CardType ct) throws Exception { |
49 | | - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
50 | | - Document d = db.newDocument(); |
51 | | - Element diagram = d.createElementNS(ADL_NAMESPACE, "diagram"); |
52 | | - diagram.setAttributeNS(XSL_TEMPLATE_NAMESPACE, "xslt:template", "/public/templates/tweet/tweet-template.xsl"); |
53 | | - |
54 | | - Element frame = d.createElementNS(ADL_NAMESPACE, ct.name().toLowerCase()); |
55 | | - diagram.appendChild(frame); |
| 47 | + public Document convertMessageToAdl(String message, String address, Font f, CardType ct) throws RuntimeException { |
| 48 | + try { |
| 49 | + DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
| 50 | + Document d = db.newDocument(); |
| 51 | + Element diagram = d.createElementNS(ADL_NAMESPACE, "diagram"); |
| 52 | + diagram.setAttributeNS(XSL_TEMPLATE_NAMESPACE, "xslt:template", "/public/templates/tweet/tweet-template.xsl"); |
| 53 | + |
| 54 | + Element frame = d.createElementNS(ADL_NAMESPACE, ct.name().toLowerCase()); |
| 55 | + diagram.appendChild(frame); |
56 | 56 |
|
57 | | - Element messageElement = convertEmojis(frame, "message", message); |
58 | | - messageElement.setAttribute("style","font-family: "+f.text); |
59 | | - |
60 | | - if (ct == CardType.POSTCARD) { |
61 | | - convertEmojis(frame, "address", address); |
62 | | - } |
63 | | - |
64 | | - d.appendChild(diagram); |
| 57 | + Element messageElement = convertEmojis(frame, "message", message); |
| 58 | + messageElement.setAttribute("style","font-family: "+f.text); |
| 59 | + |
| 60 | + if (ct == CardType.POSTCARD) { |
| 61 | + convertEmojis(frame, "address", address); |
| 62 | + } |
| 63 | + |
| 64 | + d.appendChild(diagram); |
65 | 65 |
|
66 | | - |
67 | | - return d; |
| 66 | + |
| 67 | + return d; |
| 68 | + } catch (Exception e) { |
| 69 | + throw new RuntimeException("Couldn't create XML Representation of Message", e); |
| 70 | + } |
68 | 71 | } |
69 | 72 |
|
70 | | - public Document convertTweetsToAdl(List<Tweet> tweets) throws Exception { |
71 | | - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
72 | | - Document d = db.newDocument(); |
73 | | - Element diagram = d.createElementNS(ADL_NAMESPACE, "diagram"); |
74 | | - diagram.setAttributeNS(XSL_TEMPLATE_NAMESPACE, "xslt:template", "/public/templates/tweet/tweet-template.xsl"); |
75 | | - diagram.setAttributeNS(Kite9Namespaces.SVG_NAMESPACE, "svg:version", "1.0"); |
76 | | - |
77 | | - Element frame = d.createElementNS(ADL_NAMESPACE, "frame"); |
78 | | - diagram.appendChild(frame); |
79 | | - |
80 | | - IntStream.range(0, tweets.size()) |
81 | | - .mapToObj(i -> convertTweet(tweets.get(i), i == tweets.size() - 1, d)) |
82 | | - .forEach(t -> frame.appendChild(t)); |
83 | | - |
84 | | - d.appendChild(diagram); |
85 | | - |
86 | | - return d; |
| 73 | + public Document convertTweetsToAdl(List<Tweet> tweets) throws RuntimeException { |
| 74 | + try { |
| 75 | + DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
| 76 | + Document d = db.newDocument(); |
| 77 | + Element diagram = d.createElementNS(ADL_NAMESPACE, "diagram"); |
| 78 | + diagram.setAttributeNS(XSL_TEMPLATE_NAMESPACE, "xslt:template", "/public/templates/tweet/tweet-template.xsl"); |
| 79 | + diagram.setAttributeNS(Kite9Namespaces.SVG_NAMESPACE, "svg:version", "1.0"); |
| 80 | + |
| 81 | + Element frame = d.createElementNS(ADL_NAMESPACE, "frame"); |
| 82 | + diagram.appendChild(frame); |
| 83 | + |
| 84 | + IntStream.range(0, tweets.size()) |
| 85 | + .mapToObj(i -> convertTweet(tweets.get(i), i == tweets.size() - 1, d)) |
| 86 | + .forEach(t -> frame.appendChild(t)); |
| 87 | + |
| 88 | + d.appendChild(diagram); |
| 89 | + |
| 90 | + return d; |
| 91 | + } catch (Exception e) { |
| 92 | + throw new RuntimeException("Couldn't create XML Representation of Tweet", e); |
| 93 | + } |
87 | 94 | } |
88 | 95 |
|
89 | 96 | private Element convertTweet(Tweet status, boolean isLast, Document d) { |
@@ -144,7 +151,7 @@ private void removeText(Node n, String key) { |
144 | 151 | } |
145 | 152 |
|
146 | 153 | private void addEntities(Tweet status, Document d, Element tweet, Element textarea) { |
147 | | - if (status.getEntities() != null) { |
| 154 | + if ((status.getEntities() != null) && (status.getEntities().getUrls() != null)) { |
148 | 155 | for (UrlEntity me : status.getEntities().getUrls()) { |
149 | 156 | UrlEntityV2 mev2 = (UrlEntityV2) me; |
150 | 157 |
|
|
0 commit comments