@Override public String getContent() { if(hasBeenCalledBefore ){ return txt.toString(); }else{ hasBeenCalledBefore = true; } txt.append(this.getUri()); txt.append(getDocumentHead()); txt.append(this.getBody().getContent()); txt.append("\n</w:wordDocument>"); String finalString = setUpPageOrientation(txt.toString()); return finalString; }
@Override public String toString() { return this.getContent(); }
@Test public void testDocHead() { IDocument myDoc = new Document2004(); myDoc.title("my title").subject("my subject").keywords("my keywords") .description("my description").category("my category") .author("the author").lastAuthor("the last author") .manager("the manager").company("my company");
@Override public IFooter getFooter() {//forward it to the body return this.getBody().getFooter(); } @Override
@Test public void testHead() { IDocument myDoc = new Document2004(); assertTrue(myDoc.getContent().contains("<w:docPr>")); assertTrue(myDoc.getContent() .contains("<w:view w:val=\"print\"/>")); assertTrue(myDoc.getContent() .contains("<w:zoom w:percent=\"100\"/>")); assertTrue(myDoc.getContent().contains("</w:docPr>")); }
@Override public IFooter getFooter() {//forward it to the body return this.getBody().getFooter(); } @Override
@Test public void testUri() { IDocument myDoc = new Document2004(); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> " + "<?mso-application progid=\"Word.Document\"?> " + "<w:wordDocument xmlns:aml=\"http://schemas.microsoft.com/aml/2001/core\" " + " xmlns:dt=\"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882\" xmlns:mo=\"http://schemas.microsoft.com/office/mac/office/2008/main\" " + " xmlns:ve=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" " + " xmlns:mv=\"urn:schemas-microsoft-com:mac:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" " + " xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" " + " xmlns:w=\"http://schemas.microsoft.com/office/word/2003/wordml\" " + " xmlns:wx=\"http://schemas.microsoft.com/office/word/2003/auxHint\" " + " xmlns:wsp=\"http://schemas.microsoft.com/office/word/2003/wordml/sp2\" " + " xmlns:sl=\"http://schemas.microsoft.com/schemaLibrary/2003/core\" " + " w:macrosPresent=\"no\" w:embeddedObjPresent=\"no\" w:ocxPresent=\"no\" " + " xml:space=\"preserve\"> " + " <w:ignoreSubtree w:val=\"http://schemas.microsoft.com/office/word/2003/wordml/sp2\" /> "; assertEquals("Uri is not as expected: ", expected, myDoc.getUri()); }
@Override public String getContent() { if(hasBeenCalledBefore ){ return txt.toString(); }else{ hasBeenCalledBefore = true; } txt.append(this.getUri()); txt.append(getDocumentHead()); txt.append(this.getBody().getContent()); txt.append("\n</w:wordDocument>"); String finalString = setUpPageOrientation(txt.toString()); return finalString; }
/** * This is an alias to 'getBody().addEle' */ @Override public void addEle(String str) { this.getBody().addEle(str); }
@Test public void testDefaultEncodingUTF() { IDocument myDoc = new Document2004(); assertEquals(1, TestUtils.regexCount(myDoc.getContent(), "encoding=\"UTF-8\"")); IDocument myDoc02 = new Document2004(); myDoc02.encoding(Encoding.UTF_8); assertEquals(1, TestUtils.regexCount(myDoc02.getContent(), "encoding=\"UTF-8\"")); }
@Override public String toString() { return this.getContent(); }
/** * This is an alias to 'getBody().addEle' */ @Override public void addEle(IElement e) { this.getBody().addEle(e); }
@Test public void testGetHeader() { IDocument myDoc = new Document2004(); assertTrue(myDoc.getBody().getContent().contains("<w:body>")); assertTrue(myDoc.getBody().getContent().contains("</w:body>")); }
/** * This is an alias to 'getBody().addEle' */ @Override public void addEle(String str) { this.getBody().addEle(str); }
@Test public void testPageOrientationDefault() { IDocument doc = new Document2004(); assertEquals(0, TestUtils.regexCount(doc.getContent(), "landscape")); }
/** * This is an alias to 'getBody().addEle' */ @Override public void addEle(IElement e) { this.getBody().addEle(e); }
@Ignore @Test public void test93() { IDocument myDoc = new Document2004(); // String xmlTemplate = Utils.readFile("/home/leonardo/Desktop/paulo_93.doc"); //String xmlTemplate = Utils.readFile("/home/leonardo/Desktop/template_branco.xml"); String xmlTemplate = Utils.readFile("/home/leonardo/Desktop/template.doc"); TableV2 tbl = new TableV2(); tbl.addRow(TableRow.with("Simple String cell", "Another String simple cell")); xmlTemplate = replacePh(xmlTemplate, "<w:t><phTabela></w:t>", tbl.getContent()); System.out.println(xmlTemplate.trim()); //System.out.println(tbl.getContent()); //TestUtils.createLocalDoc(xmlTemplate.replace("</w:body>", tbl.getContent() + "</w:body>")); TestUtils.createLocalDoc(xmlTemplate.trim()); }
@Override public IHeader getHeader() { return this.getBody().getHeader(); //forward it to the body }
@Test public void testPageOrientationLandscape() { IDocument doc = new Document2004(); doc.setPageOrientationLandscape(); assertEquals(1, TestUtils.regexCount(doc.getContent(), "landscape")); }
@Override public IHeader getHeader() { return this.getBody().getHeader(); //forward it to the body }