use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testFull.
@Test
public void testFull() throws Docx4JException {
String name = "anchor4";
String href = "http://www.google.com";
String content = "Google";
List<Object> objects = fromXHTML(a(href, name, content));
P p = (P) objects.get(0);
// Test bookmark
testBookmarkName(XmlUtils.unwrap(p.getContent().get(0)), name);
P.Hyperlink h = (P.Hyperlink) p.getContent().get(1);
testLink(h.getId(), href);
// Test content
testContent(h, P.Hyperlink.class, content);
}
use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testNamedAnchorInSpan.
@Test
public void testNamedAnchorInSpan() throws Docx4JException {
String name = "anchor3";
String href = null;
String content = "Google";
List<Object> objects = fromXHTML("<span>" + a(href, name, content) + "</span>");
P p = (P) objects.get(0);
// Test bookmark
testBookmarkName(XmlUtils.unwrap(p.getContent().get(0)), name);
// Test content - not hyperlinked
R r = (R) p.getContent().get(1);
testContent(r, R.class, content);
}
use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testRichContent.
/**
* This test illustrates how Flying Saucer handles rich hyperlink content.
*/
@Test
public void testRichContent() throws Docx4JException {
String name = "anchor5";
String href = "http://www.google.com";
String followingSpanContent = "SPAN";
String followingPContent = "NEXTP";
List<Object> converted = convert("<div><p>" + "<a name='" + name + "' href='" + href + "' >Some <span>rich</span> <b>content</b></a>" + "<span>" + followingSpanContent + "</span></p>" + "<p>" + followingPContent + "</p></div>");
System.out.println(XmlUtils.marshaltoString(converted.get(0), true, true));
// Address risk that hyperlink processing destroys following content
testFollowingSpan(((P) converted.get(0)).getContent(), followingSpanContent);
testFollowingP((P) converted.get(1), followingPContent);
List<Object> objects = converted;
P p = (P) objects.get(0);
// Test bookmark
testBookmarkName(XmlUtils.unwrap(p.getContent().get(0)), name);
P.Hyperlink h = (P.Hyperlink) p.getContent().get(1);
testLink(h.getId(), href);
// Test content
assertTrue(h.getContent().size() == 4);
}
use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testXmlPredefinedEntities.
@Test
public void testXmlPredefinedEntities() throws Exception {
List<Object> converted = convert("<div><p><a href=\"#requirement897\">[R_897] < ' Requirement 3 < 2 " done</a></p></div>");
System.out.println(XmlUtils.marshaltoString(converted.get(0), true, true));
List<Object> objects = converted;
P p = (P) objects.get(0);
P.Hyperlink h = (P.Hyperlink) p.getContent().get(0);
// Test content
Writer out = new StringWriter();
TextUtils.extractText(h, out);
out.close();
assertTrue(out.toString().equals("[R_897] < ' Requirement 3 < 2 \" done"));
}
use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testRichContentTail.
@Test
public void testRichContentTail() throws Exception {
List<Object> converted = convert("<div><p><a href=\"#requirement897\">[R_897] <b>Requirement</b> 12</a></p></div>");
System.out.println(XmlUtils.marshaltoString(converted.get(0), true, true));
List<Object> objects = converted;
P p = (P) objects.get(0);
P.Hyperlink h = (P.Hyperlink) p.getContent().get(0);
// Test content
assertTrue(h.getContent().size() == 3);
Writer out = new StringWriter();
TextUtils.extractText(h, out);
out.close();
assertTrue(out.toString().equals("[R_897] Requirement 12"));
}
Aggregations