Search in sources :

Example 1 with P

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);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

Example 2 with P

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);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) Test(org.junit.Test)

Example 3 with P

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);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

Example 4 with P

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] &lt; &apos; Requirement 3 &lt; 2 &quot; 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"));
}
Also used : P(org.docx4j.wml.P) StringWriter(java.io.StringWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 5 with P

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"));
}
Also used : P(org.docx4j.wml.P) StringWriter(java.io.StringWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Aggregations

P (org.docx4j.wml.P)101 R (org.docx4j.wml.R)58 Text (org.docx4j.wml.Text)32 Test (org.junit.Test)23 PPr (org.docx4j.wml.PPr)22 RPr (org.docx4j.wml.RPr)21 ObjectFactory (org.docx4j.wml.ObjectFactory)18 Jc (org.docx4j.wml.Jc)16 BigInteger (java.math.BigInteger)14 CTVerticalJc (org.docx4j.wml.CTVerticalJc)14 Drawing (org.docx4j.wml.Drawing)14 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)13 STVerticalJc (org.docx4j.wml.STVerticalJc)11 Tc (org.docx4j.wml.Tc)11 File (java.io.File)10 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)10 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)10 Tbl (org.docx4j.wml.Tbl)10 Tr (org.docx4j.wml.Tr)10 Br (org.docx4j.wml.Br)9