/**
* get the PartType of the body, for example
- * DOCUMENT, HEADER, FOOTER, FOOTNOTE,
+ * DOCUMENT, HEADER, FOOTER, FOOTNOTE,
* @return the PartType of the body
*/
public BodyType getPartType();
private XWPFHeaderFooterPolicy headerFooterPolicy;
public XWPFDocument(OPCPackage pkg) throws IOException {
- super(pkg);
+ super(pkg);
- //build a tree of POIXMLDocumentParts, this document being the root
- load(XWPFFactory.getInstance());
+ //build a tree of POIXMLDocumentParts, this document being the root
+ load(XWPFFactory.getInstance());
}
public XWPFDocument(InputStream is) throws IOException {
- super(PackageHelper.open(is));
+ super(PackageHelper.open(is));
- //build a tree of POIXMLDocumentParts, this workbook being the root
- load(XWPFFactory.getInstance());
+ //build a tree of POIXMLDocumentParts, this workbook being the root
+ load(XWPFFactory.getInstance());
}
public XWPFDocument(){
- super(newPackage());
- onDocumentCreate();
+ super(newPackage());
+ onDocumentCreate();
}
@Override
protected void onDocumentRead() throws IOException {
- try {
- DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
- ctDocument = doc.getDocument();
+ try {
+ DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
+ ctDocument = doc.getDocument();
- initFootnotes();
+ initFootnotes();
// parse the document with cursor and add
// the XmlObject to its lists
// We don't currently process the glossary itself
// Until we do, we do need to load the glossary child parts of it
for (POIXMLDocumentPart gp : p.getRelations()) {
- // Trigger the onDocumentRead for all the child parts
- // Otherwise we'll hit issues on Styles, Settings etc on save
- try {
- Method onDocumentRead = gp.getClass().getDeclaredMethod("onDocumentRead");
- onDocumentRead.setAccessible(true);
- onDocumentRead.invoke(gp);
- } catch(Exception e) {
- throw new POIXMLException(e);
- }
+ // Trigger the onDocumentRead for all the child parts
+ // Otherwise we'll hit issues on Styles, Settings etc on save
+ try {
+ Method onDocumentRead = gp.getClass().getDeclaredMethod("onDocumentRead");
+ onDocumentRead.setAccessible(true);
+ onDocumentRead.invoke(gp);
+ } catch(Exception e) {
+ throw new POIXMLException(e);
+ }
}
}
}
}
private void initHyperlinks(){
- // Get the hyperlinks
- // TODO: make me optional/separated in private function
- try {
- Iterator<PackageRelationship> relIter =
- getPackagePart().getRelationshipsByType(XWPFRelation.HYPERLINK.getRelation()).iterator();
- while(relIter.hasNext()) {
- PackageRelationship rel = relIter.next();
- hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString()));
- }
- } catch (InvalidFormatException e){
- throw new POIXMLException(e);
- }
+ // Get the hyperlinks
+ // TODO: make me optional/separated in private function
+ try {
+ Iterator<PackageRelationship> relIter =
+ getPackagePart().getRelationshipsByType(XWPFRelation.HYPERLINK.getRelation()).iterator();
+ while(relIter.hasNext()) {
+ PackageRelationship rel = relIter.next();
+ hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString()));
+ }
+ } catch (InvalidFormatException e){
+ throw new POIXMLException(e);
+ }
}
private void initFootnotes() throws XmlException, IOException {
- for(POIXMLDocumentPart p : getRelations()){
- String relation = p.getPackageRelationship().getRelationshipType();
- if (relation.equals(XWPFRelation.FOOTNOTE.getRelation())) {
- FootnotesDocument footnotesDocument = FootnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
- this.footnotes = (XWPFFootnotes)p;
- this.footnotes.onDocumentRead();
-
- for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteList()) {
- footnotes.addFootnote(ctFtnEdn);
- }
- } else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){
- EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
-
- for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteList()) {
- endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
- }
- }
- }
+ for(POIXMLDocumentPart p : getRelations()){
+ String relation = p.getPackageRelationship().getRelationshipType();
+ if (relation.equals(XWPFRelation.FOOTNOTE.getRelation())) {
+ FootnotesDocument footnotesDocument = FootnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
+ this.footnotes = (XWPFFootnotes)p;
+ this.footnotes.onDocumentRead();
+
+ for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteList()) {
+ footnotes.addFootnote(ctFtnEdn);
+ }
+ } else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){
+ EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
+
+ for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteList()) {
+ endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
+ }
+ }
+ }
}
/**
*/
@Internal
public CTDocument1 getDocument() {
- return ctDocument;
+ return ctDocument;
}
IdentifierManager getDrawingIdManager() {
- return drawingIdManager;
+ return drawingIdManager;
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getBodyElements()
*/
public List<IBodyElement> getBodyElements() {
- return Collections.unmodifiableList(bodyElements);
+ return Collections.unmodifiableList(bodyElements);
}
public Iterator<IBodyElement> getBodyElementsIterator() {
- return bodyElements.iterator();
+ return bodyElements.iterator();
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getParagraphs()
*/
public List<XWPFParagraph> getParagraphs(){
- return Collections.unmodifiableList(paragraphs);
+ return Collections.unmodifiableList(paragraphs);
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getTables()
*/
public List<XWPFTable> getTables(){
- return Collections.unmodifiableList(tables);
+ return Collections.unmodifiableList(tables);
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int)
*/
public XWPFTable getTableArray(int pos) {
- if(pos > 0 && pos < tables.size()){
- return tables.get(pos);
- }
- return null;
+ if (pos > 0 && pos < tables.size()){
+ return tables.get(pos);
+ }
+ return null;
}
/**
* @return the list of footers
*/
public List<XWPFFooter> getFooterList(){
- return Collections.unmodifiableList(footers);
+ return Collections.unmodifiableList(footers);
}
public XWPFFooter getFooterArray(int pos){
- return footers.get(pos);
+ return footers.get(pos);
}
/**
* @return the list of headers
*/
public List<XWPFHeader> getHeaderList(){
- return Collections.unmodifiableList(headers);
+ return Collections.unmodifiableList(headers);
}
public XWPFHeader getHeaderArray(int pos){
- return headers.get(pos);
+ return headers.get(pos);
}
public String getTblStyle(XWPFTable table){
- return table.getStyleID();
+ return table.getStyleID();
}
public XWPFHyperlink getHyperlinkByID(String id) {
- Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
- while (iter.hasNext()) {
- XWPFHyperlink link = iter.next();
- if(link.getId().equals(id))
- return link;
- }
+ Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
+ while (iter.hasNext()) {
+ XWPFHyperlink link = iter.next();
+ if(link.getId().equals(id))
+ return link;
+ }
- return null;
+ return null;
}
public XWPFFootnote getFootnoteByID(int id) {
- if(footnotes == null) return null;
- return footnotes.getFootnoteById(id);
+ if(footnotes == null) return null;
+ return footnotes.getFootnoteById(id);
}
public XWPFFootnote getEndnoteByID(int id) {
- if(endnotes == null) return null;
- return endnotes.get(id);
+ if(endnotes == null) return null;
+ return endnotes.get(id);
}
public List<XWPFFootnote> getFootnotes() {
- if(footnotes == null) {
- return Collections.emptyList();
- }
- return footnotes.getFootnotesList();
+ if(footnotes == null) {
+ return Collections.emptyList();
+ }
+ return footnotes.getFootnotesList();
}
public XWPFHyperlink[] getHyperlinks() {
- return hyperlinks.toArray(new XWPFHyperlink[hyperlinks.size()]);
+ return hyperlinks.toArray(new XWPFHyperlink[hyperlinks.size()]);
}
public XWPFComment getCommentByID(String id) {
- Iterator<XWPFComment> iter = comments.iterator();
- while (iter.hasNext()) {
- XWPFComment comment = iter.next();
- if(comment.getId().equals(id))
- return comment;
- }
+ Iterator<XWPFComment> iter = comments.iterator();
+ while (iter.hasNext()) {
+ XWPFComment comment = iter.next();
+ if(comment.getId().equals(id))
+ return comment;
+ }
- return null;
+ return null;
}
public XWPFComment[] getComments() {
- return comments.toArray(new XWPFComment[comments.size()]);
+ return comments.toArray(new XWPFComment[comments.size()]);
}
/**
XmlCursor tableCursor = t.newCursor();
try {
cursor.toCursor(tableCursor);
- while (cursor.toPrevSibling()) {
- o = cursor.getObject();
- if (o instanceof CTP || o instanceof CTTbl)
- i++;
+ while (cursor.toPrevSibling()) {
+ o = cursor.getObject();
+ if (o instanceof CTP || o instanceof CTTbl)
+ i++;
+ }
+ bodyElements.add(i, newT);
+ cursor.toCursor(tableCursor);
+ cursor.toEndToken();
+ return newT;
}
- bodyElements.add(i, newT);
- cursor.toCursor(tableCursor);
- cursor.toEndToken();
- return newT;
- }
finally {
- tableCursor.dispose();
+ tableCursor.dispose();
}
}
return null;
* @param cursor
*/
private boolean isCursorInBody(XmlCursor cursor) {
- XmlCursor verify = cursor.newCursor();
- verify.toParent();
- try {
- return (verify.getObject() == this.ctDocument.getBody());
- } finally {
- verify.dispose();
- }
+ XmlCursor verify = cursor.newCursor();
+ verify.toParent();
+ try {
+ return (verify.getObject() == this.ctDocument.getBody());
+ } finally {
+ verify.dispose();
+ }
}
private int getPosOfBodyElement(IBodyElement needle) {
- BodyElementType type = needle.getElementType();
- IBodyElement current;
- for(int i=0; i<bodyElements.size(); i++) {
- current = bodyElements.get(i);
- if(current.getElementType() == type) {
- if(current.equals(needle)) {
- return i;
- }
- }
- }
- return -1;
+ BodyElementType type = needle.getElementType();
+ IBodyElement current;
+ for(int i=0; i<bodyElements.size(); i++) {
+ current = bodyElements.get(i);
+ if(current.getElementType() == type) {
+ if(current.equals(needle)) {
+ return i;
+ }
+ }
+ }
+ return -1;
}
/**
* @return The location, or -1 if the paragraph couldn't be found
*/
public int getPosOfParagraph(XWPFParagraph p){
- return getPosOfBodyElement(p);
+ return getPosOfBodyElement(p);
}
/**
* @return The location, or -1 if the table couldn't be found
*/
public int getPosOfTable(XWPFTable t){
- return getPosOfBodyElement(t);
+ return getPosOfBodyElement(t);
}
/**
*/
@Override
protected void commit() throws IOException {
- XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
- xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document"));
- Map<String, String> map = new HashMap<String, String>();
- map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
- map.put("urn:schemas-microsoft-com:office:office", "o");
- map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
- map.put("urn:schemas-microsoft-com:vml", "v");
- map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
- map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
- map.put("urn:schemas-microsoft-com:office:word", "w10");
- map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne");
- map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
- xmlOptions.setSaveSuggestedPrefixes(map);
-
- PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- ctDocument.save(out, xmlOptions);
- out.close();
+ XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
+ xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document"));
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
+ map.put("urn:schemas-microsoft-com:office:office", "o");
+ map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
+ map.put("urn:schemas-microsoft-com:vml", "v");
+ map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
+ map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
+ map.put("urn:schemas-microsoft-com:office:word", "w10");
+ map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne");
+ map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
+ xmlOptions.setSaveSuggestedPrefixes(map);
+
+ PackagePart part = getPackagePart();
+ OutputStream out = part.getOutputStream();
+ ctDocument.save(out, xmlOptions);
+ out.close();
}
/**
* @return true if removing was successfully, else return false
*/
public boolean removeBodyElement(int pos) {
- if(pos >= 0 && pos < bodyElements.size()) {
- BodyElementType type = bodyElements.get(pos).getElementType();
- if(type == BodyElementType.TABLE){
- int tablePos = getTablePos(pos);
- tables.remove(tablePos);
- ctDocument.getBody().removeTbl(tablePos);
- }
- if(type == BodyElementType.PARAGRAPH) {
- int paraPos = getParagraphPos(pos);
- paragraphs.remove(paraPos);
- ctDocument.getBody().removeP(paraPos);
- }
- bodyElements.remove(pos);
- return true;
- }
- return false;
+ if (pos >= 0 && pos < bodyElements.size()) {
+ BodyElementType type = bodyElements.get(pos).getElementType();
+ if (type == BodyElementType.TABLE){
+ int tablePos = getTablePos(pos);
+ tables.remove(tablePos);
+ ctDocument.getBody().removeTbl(tablePos);
+ }
+ if (type == BodyElementType.PARAGRAPH) {
+ int paraPos = getParagraphPos(pos);
+ paragraphs.remove(paraPos);
+ ctDocument.getBody().removeP(paraPos);
+ }
+ bodyElements.remove(pos);
+ return true;
+ }
+ return false;
}
/**
* </ul>
*/
public void enforceUpdateFields() {
- settings.setUpdateFields();
+ settings.setUpdateFields();
}
/**
return null;
}
-
public Iterator<XWPFTable> getTablesIterator() {
- return tables.iterator();
+ return tables.iterator();
}
public Iterator<XWPFParagraph> getParagraphsIterator() {
- return paragraphs.iterator();
+ return paragraphs.iterator();
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int)
*/
public XWPFParagraph getParagraphArray(int pos) {
- if(pos >= 0 && pos < paragraphs.size()){
- return paragraphs.get(pos);
- }
- return null;
+ if(pos >= 0 && pos < paragraphs.size()){
+ return paragraphs.get(pos);
+ }
+ return null;
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
*/
public POIXMLDocumentPart getPart() {
- return this;
+ return this;
}
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
*/
public BodyType getPartType() {
- return BodyType.DOCUMENT;
+ return BodyType.DOCUMENT;
}
/**
* @param cell
*/
public XWPFTableCell getTableCell(CTTc cell) {
- XmlCursor cursor = cell.newCursor();
- cursor.toParent();
- XmlObject o = cursor.getObject();
- if(!(o instanceof CTRow)){
- return null;
- }
- CTRow row = (CTRow)o;
- cursor.toParent();
- o = cursor.getObject();
- cursor.dispose();
- if(! (o instanceof CTTbl)){
- return null;
- }
- CTTbl tbl = (CTTbl) o;
- XWPFTable table = getTable(tbl);
- if(table == null){
- return null;
- }
- XWPFTableRow tableRow = table.getRow(row);
- if (tableRow == null) {
- return null;
- }
- return tableRow.getTableCell(cell);
+ XmlCursor cursor = cell.newCursor();
+ cursor.toParent();
+ XmlObject o = cursor.getObject();
+ if(!(o instanceof CTRow)){
+ return null;
+ }
+ CTRow row = (CTRow)o;
+ cursor.toParent();
+ o = cursor.getObject();
+ cursor.dispose();
+ if(! (o instanceof CTTbl)){
+ return null;
+ }
+ CTTbl tbl = (CTTbl) o;
+ XWPFTable table = getTable(tbl);
+ if(table == null){
+ return null;
+ }
+ XWPFTableRow tableRow = table.getRow(row);
+ if (tableRow == null) {
+ return null;
+ }
+ return tableRow.getTableCell(cell);
}
public XWPFDocument getXWPFDocument() {
- return this;
+ return this;
}
}
public XWPFFootnote(CTFtnEdn note, XWPFFootnotes xFootnotes) {
footnotes = xFootnotes;
ctFtnEdn = note;
- for (CTP p : ctFtnEdn.getPList()) {
+ for (CTP p : ctFtnEdn.getPList()) {
paragraphs.add(new XWPFParagraph(p, this));
}
}
public XWPFFootnote(XWPFDocument document, CTFtnEdn body) {
- for (CTP p : body.getPList()) {
+ for (CTP p : body.getPList()) {
paragraphs.add(new XWPFParagraph(p, document));
}
}
* inserts an existing XWPFTable to the arrays bodyElements and tables
* @param pos
* @param table
- * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int pos, XWPFTable table)
+ * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int pos, XWPFTable table)
*/
public void insertTable(int pos, XWPFTable table) {
bodyElements.add(pos, table);
* the method will return this table
* if there is no corresponding {@link XWPFTable} the method will return null
* @param ctTable
- * @see org.apache.poi.xwpf.usermodel.IBody#getTable(CTTbl ctTable)
+ * @see org.apache.poi.xwpf.usermodel.IBody#getTable(CTTbl ctTable)
*/
public XWPFTable getTable(CTTbl ctTable){
for (XWPFTable table : tables) {
if(table==null)
return null;
if(table.getCTTbl().equals(ctTable))
- return table;
+ return table;
}
return null;
}
* @param p is instance of CTP and is searching for an XWPFParagraph
* @return null if there is no XWPFParagraph with an corresponding CTPparagraph in the paragraphList of this header or footer
* XWPFParagraph with the correspondig CTP p
- * @see org.apache.poi.xwpf.usermodel.IBody#getParagraph(CTP p)
+ * @see org.apache.poi.xwpf.usermodel.IBody#getParagraph(CTP p)
*/
public XWPFParagraph getParagraph(CTP p){
for (XWPFParagraph paragraph : paragraphs) {
/**
* Returns the paragraph that holds
* the text of the header or footer.
- * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int pos)
+ * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int pos)
*/
public XWPFParagraph getParagraphArray(int pos) {
/**
* get the TableCell which belongs to the TableCell
* @param cell
- * @see org.apache.poi.xwpf.usermodel.IBody#getTableCell(CTTc cell)
+ * @see org.apache.poi.xwpf.usermodel.IBody#getTableCell(CTTc cell)
*/
public XWPFTableCell getTableCell(CTTc cell) {
XmlCursor cursor = cell.newCursor();
*
* @param cursor
* @return the inserted table
- * @see org.apache.poi.xwpf.usermodel.IBody#insertNewTbl(XmlCursor cursor)
+ * @see org.apache.poi.xwpf.usermodel.IBody#insertNewTbl(XmlCursor cursor)
*/
public XWPFTable insertNewTbl(XmlCursor cursor) {
if(isCursorInFtn(cursor)){
* add a new paragraph at position of the cursor
* @param cursor
* @return the inserted paragraph
- * @see org.apache.poi.xwpf.usermodel.IBody#insertNewParagraph(XmlCursor cursor)
+ * @see org.apache.poi.xwpf.usermodel.IBody#insertNewParagraph(XmlCursor cursor)
*/
public XWPFParagraph insertNewParagraph(XmlCursor cursor){
if(isCursorInFtn(cursor)){
return null;
}
- /**
- * add a new table to the end of the footnote
- * @param table
- * @return the added XWPFTable
- */
+ /**
+ * add a new table to the end of the footnote
+ * @param table
+ * @return the added XWPFTable
+ */
public XWPFTable addNewTbl(CTTbl table) {
- CTTbl newTable = ctFtnEdn.addNewTbl();
- newTable.set(table);
- XWPFTable xTable = new XWPFTable(newTable, this);
- tables.add(xTable);
- return xTable;
+ CTTbl newTable = ctFtnEdn.addNewTbl();
+ newTable.set(table);
+ XWPFTable xTable = new XWPFTable(newTable, this);
+ tables.add(xTable);
+ return xTable;
}
-
- /**
- * add a new paragraph to the end of the footnote
- * @param paragraph
- * @return the added XWPFParagraph
- */
+
+ /**
+ * add a new paragraph to the end of the footnote
+ * @param paragraph
+ * @return the added XWPFParagraph
+ */
public XWPFParagraph addNewParagraph(CTP paragraph) {
- CTP newPara = ctFtnEdn.addNewP();
- newPara.set(paragraph);
- XWPFParagraph xPara = new XWPFParagraph(newPara, this);
- paragraphs.add(xPara);
- return xPara;
+ CTP newPara = ctFtnEdn.addNewP();
+ newPara.set(paragraph);
+ XWPFParagraph xPara = new XWPFParagraph(newPara, this);
+ paragraphs.add(xPara);
+ return xPara;
}
-
+
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getXWPFDocument()
*/
public XWPFDocument getXWPFDocument() {
- return footnotes.getXWPFDocument();
+ return footnotes.getXWPFDocument();
}
/**
* @param rel the package relationship of type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"
*/
public XWPFFootnotes(PackagePart part, PackageRelationship rel) throws IOException, OpenXML4JException{
- super(part, rel);
+ super(part, rel);
}
/**
*/
@Override
protected void onDocumentRead () throws IOException {
- FootnotesDocument notesDoc;
- try {
- InputStream is = getPackagePart().getInputStream();
- notesDoc = FootnotesDocument.Factory.parse(is);
- ctFootnotes = notesDoc.getFootnotes();
- } catch (XmlException e) {
- throw new POIXMLException();
- }
-
- //get any Footnote
- for(CTFtnEdn note : ctFootnotes.getFootnoteList()) {
- listFootnote.add(new XWPFFootnote(note, this));
- }
+ FootnotesDocument notesDoc;
+ try {
+ InputStream is = getPackagePart().getInputStream();
+ notesDoc = FootnotesDocument.Factory.parse(is);
+ ctFootnotes = notesDoc.getFootnotes();
+ } catch (XmlException e) {
+ throw new POIXMLException();
+ }
+
+ // Find our footnotes
+ for(CTFtnEdn note : ctFootnotes.getFootnoteList()) {
+ listFootnote.add(new XWPFFootnote(note, this));
+ }
}
@Override
protected void commit() throws IOException {
- XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
- xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes"));
- Map<String,String> map = new HashMap<String,String>();
- map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
- map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
- xmlOptions.setSaveSuggestedPrefixes(map);
- PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- ctFootnotes.save(out, xmlOptions);
- out.close();
+ XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
+ xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes"));
+ Map<String,String> map = new HashMap<String,String>();
+ map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
+ map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
+ xmlOptions.setSaveSuggestedPrefixes(map);
+ PackagePart part = getPackagePart();
+ OutputStream out = part.getOutputStream();
+ ctFootnotes.save(out, xmlOptions);
+ out.close();
}
public List<XWPFFootnote> getFootnotesList() {
- return listFootnote;
+ return listFootnote;
}
public XWPFFootnote getFootnoteById(int id) {
- for(XWPFFootnote note : listFootnote) {
- if(note.getCTFtnEdn().getId().intValue() == id)
- return note;
- }
- return null;
+ for(XWPFFootnote note : listFootnote) {
+ if(note.getCTFtnEdn().getId().intValue() == id)
+ return note;
+ }
+ return null;
}
/**
* @param footnotes
*/
public void setFootnotes(CTFootnotes footnotes) {
- ctFootnotes = footnotes;
+ ctFootnotes = footnotes;
}
/**
* @throws IOException
*/
public void addFootnote(XWPFFootnote footnote){
- listFootnote.add(footnote);
- ctFootnotes.addNewFootnote().set(footnote.getCTFtnEdn());
+ listFootnote.add(footnote);
+ ctFootnotes.addNewFootnote().set(footnote.getCTFtnEdn());
}
/**
* @throws IOException
*/
public XWPFFootnote addFootnote(CTFtnEdn note){
- CTFtnEdn newNote = ctFootnotes.addNewFootnote();
- newNote.set(note);
- XWPFFootnote xNote = new XWPFFootnote(newNote, this);
- listFootnote.add(xNote);
- return xNote;
+ CTFtnEdn newNote = ctFootnotes.addNewFootnote();
+ newNote.set(note);
+ XWPFFootnote xNote = new XWPFFootnote(newNote, this);
+ listFootnote.add(xNote);
+ return xNote;
}
public void setXWPFDocument(XWPFDocument doc) {
- document = doc;
+ document = doc;
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
*/
public XWPFDocument getXWPFDocument() {
- if ( document != null) {
- return document;
- } else {
- return (XWPFDocument)getParent();
- }
+ if ( document != null) {
+ return document;
+ } else {
+ return (XWPFDocument)getParent();
+ }
}
}
CTHdrFtr headerFooter;
XWPFDocument document;
- XWPFHeaderFooter(XWPFDocument doc, CTHdrFtr hdrFtr){
+ XWPFHeaderFooter(XWPFDocument doc, CTHdrFtr hdrFtr) {
if (doc==null) {
throw new NullPointerException();
}
if(table==null)
return null;
if(table.getCTTbl().equals(ctTable))
- return table;
+ return table;
}
return null;
}
// ignore
}
}
-
+
document.registerPackagePictureData(xwpfPicData);
pictures.add(xwpfPicData);
return getRelationId(xwpfPicData);
if (relatedPart != null && relatedPart instanceof XWPFPictureData) {
return (XWPFPictureData) relatedPart;
}
- return null;
+ return null;
}
/**
}
public void setXWPFDocument(XWPFDocument doc) {
- document = doc;
+ document = doc;
}
public XWPFDocument getXWPFDocument() {
- if (document!=null) {
- return document;
- } else {
- return (XWPFDocument)getParent();
- }
+ if (document!=null) {
+ return document;
+ } else {
+ return (XWPFDocument)getParent();
+ }
}
/**
public POIXMLDocumentPart getPart() {
return this;
}
-}//end class
+}
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
/**
- * Sketch of XWPF paragraph class
+ * <p>A Paragraph within a Document, Table, Header etc.</p>
+ *
+ * <p>A paragraph has a lot of styling information, but the
+ * actual text (possibly along with more styling) is held on
+ * the child {@link XWPFRun}s.</p>
*/
public class XWPFParagraph implements IBodyElement {
private final CTP paragraph;
public String getText() {
StringBuffer out = new StringBuffer();
for(XWPFRun run : runs) {
- out.append(run.toString());
+ out.append(run.toString());
}
out.append(footnoteText);
return out.toString();
}
-
+
/**
* Return styleID of the paragraph if style exist for this paragraph
* if not, null will be returned
* @return styleID as String
*/
- public String getStyleID(){
- if (paragraph.getPPr() != null){
- if(paragraph.getPPr().getPStyle()!= null){
- if (paragraph.getPPr().getPStyle().getVal()!= null)
- return paragraph.getPPr().getPStyle().getVal();
- }
- }
- return null;
+ public String getStyleID() {
+ if (paragraph.getPPr() != null) {
+ if(paragraph.getPPr().getPStyle()!= null) {
+ if (paragraph.getPPr().getPStyle().getVal()!= null)
+ return paragraph.getPPr().getPStyle().getVal();
+ }
+ }
+ return null;
}
/**
* If style exist for this paragraph
}
return null;
}
-
+
/**
* Returns Ilvl of the numeric style for this paragraph.
* Returns null if this paragraph does not have numeric style.
}
return null;
}
-
+
/**
* setNumID of Paragraph
* @param numPos
* paragraph
*/
public String getParagraphText() {
- StringBuffer out = new StringBuffer();
- for(XWPFRun run : runs) {
- out.append(run.toString());
- }
- return out.toString();
+ StringBuffer out = new StringBuffer();
+ for(XWPFRun run : runs) {
+ out.append(run.toString());
+ }
+ return out.toString();
}
/**
* Returns any text from any suitable pictures in the paragraph
*/
public String getPictureText() {
- StringBuffer out = new StringBuffer();
- for(XWPFRun run : runs) {
- out.append(run.getPictureText());
- }
- return out.toString();
+ StringBuffer out = new StringBuffer();
+ for(XWPFRun run : runs) {
+ out.append(run.getPictureText());
+ }
+ return out.toString();
}
/**
CTPPr pr = getCTPPr();
return (pr == null || !pr.isSetTextAlignment()) ? TextAlignment.AUTO
: TextAlignment.valueOf(pr.getTextAlignment().getVal()
- .intValue());
+ .intValue());
}
/**
CTPPr pr = getCTPPr();
CTTextAlignment textAlignment = pr.isSetTextAlignment() ? pr
.getTextAlignment() : pr.addNewTextAlignment();
- STTextAlignment.Enum en = STTextAlignment.Enum
- .forInt(valign.getValue());
- textAlignment.setVal(en);
+ STTextAlignment.Enum en = STTextAlignment.Enum
+ .forInt(valign.getValue());
+ textAlignment.setVal(en);
}
/**
* @param searched
* @param startPos
*/
- public TextSegement searchText(String searched,PositionInParagraph startPos){
-
+ public TextSegement searchText(String searched,PositionInParagraph startPos) {
int startRun = startPos.getRun(),
startText = startPos.getText(),
startChar = startPos.getChar();
if(runPos==startRun)
charPos= startChar;
else
- charPos = 0;
+ charPos = 0;
+
for(; charPos<candidate.length(); charPos++){
if((candidate.charAt(charPos)==searched.charAt(0))&&(candCharPos==0)){
beginTextPos = textPos;
return segement;
}
}
- else
+ else {
candCharPos=0;
+ }
}
}
textPos++;
* @return the inserted run
*/
public XWPFRun insertNewRun(int pos){
- if (pos >= 0 && pos <= paragraph.sizeOfRArray()) {
+ if (pos >= 0 && pos <= paragraph.sizeOfRArray()) {
CTR ctRun = paragraph.insertNewR(pos);
XWPFRun newRun = new XWPFRun(ctRun, this);
runs.add(pos, newRun);
return newRun;
- }
- return null;
+ }
+ return null;
}
-
-
-
+
/**
* get a Text
* @param segment
*/
public String getText(TextSegement segment){
- int runBegin = segment.getBeginRun();
- int textBegin = segment.getBeginText();
- int charBegin = segment.getBeginChar();
- int runEnd = segment.getEndRun();
- int textEnd = segment.getEndText();
- int charEnd = segment.getEndChar();
- StringBuffer out = new StringBuffer();
+ int runBegin = segment.getBeginRun();
+ int textBegin = segment.getBeginText();
+ int charBegin = segment.getBeginChar();
+ int runEnd = segment.getEndRun();
+ int textEnd = segment.getEndText();
+ int charEnd = segment.getEndChar();
+ StringBuffer out = new StringBuffer();
for(int i=runBegin; i<=runEnd;i++){
int startText=0, endText = paragraph.getRArray(i).getTList().size()-1;
if(i==runBegin)
if((j==textEnd)&&(i==runEnd)){
endChar = charEnd;
}
- out.append(tmpText.substring(startChar, endChar+1));
-
+ out.append(tmpText.substring(startChar, endChar+1));
+
}
}
return out.toString();
* @return true if the run was removed
*/
public boolean removeRun(int pos){
- if (pos >= 0 && pos < paragraph.sizeOfRArray()){
- getCTP().removeR(pos);
- runs.remove(pos);
- return true;
- }
- return false;
+ if (pos >= 0 && pos < paragraph.sizeOfRArray()) {
+ getCTP().removeR(pos);
+ runs.remove(pos);
+ return true;
+ }
+ return false;
}
/**
}
return null;
}
-
}
stBorderTypeMap.put(STBorder.INT_DOUBLE, XWPFBorderType.DOUBLE);
stBorderTypeMap.put(STBorder.INT_DOTTED, XWPFBorderType.DOTTED);
stBorderTypeMap.put(STBorder.INT_DASHED, XWPFBorderType.DASHED);
- stBorderTypeMap.put(STBorder.INT_DOT_DASH, XWPFBorderType.DOT_DASH);
+ stBorderTypeMap.put(STBorder.INT_DOT_DASH, XWPFBorderType.DOT_DASH);
}
public XWPFTable(CTTbl table, IBody part, int row, int col) {
}
public XWPFTable(CTTbl table, IBody part){
- this.part = part;
+ this.part = part;
this.ctTbl = table;
-
+
tableRows = new ArrayList<XWPFTableRow>();
// is an empty table: I add one row and one column as default
public XWPFTableRow getRow(int pos) {
if (pos >= 0 && pos < ctTbl.sizeOfTrArray()) {
//return new XWPFTableRow(ctTbl.getTrArray(pos));
- return getRows().get(pos);
+ return getRows().get(pos);
}
return null;
}
}
public XWPFBorderType getInsideHBorderType() {
- XWPFBorderType bt = null;
+ XWPFBorderType bt = null;
- CTTblPr tblPr = getTrPr();
- if (tblPr.isSetTblBorders()) {
- CTTblBorders ctb = tblPr.getTblBorders();
- if (ctb.isSetInsideH()) {
- CTBorder border = ctb.getInsideH();
- bt = stBorderTypeMap.get(border.getVal().intValue());
- }
- }
- return bt;
+ CTTblPr tblPr = getTrPr();
+ if (tblPr.isSetTblBorders()) {
+ CTTblBorders ctb = tblPr.getTblBorders();
+ if (ctb.isSetInsideH()) {
+ CTBorder border = ctb.getInsideH();
+ bt = stBorderTypeMap.get(border.getVal().intValue());
+ }
+ }
+ return bt;
}
public int getInsideHBorderSize() {
- int size = -1;
+ int size = -1;
- CTTblPr tblPr = getTrPr();
- if (tblPr.isSetTblBorders()) {
- CTTblBorders ctb = tblPr.getTblBorders();
- if (ctb.isSetInsideH()) {
- CTBorder border = ctb.getInsideH();
- size = border.getSz().intValue();
- }
- }
- return size;
+ CTTblPr tblPr = getTrPr();
+ if (tblPr.isSetTblBorders()) {
+ CTTblBorders ctb = tblPr.getTblBorders();
+ if (ctb.isSetInsideH()) {
+ CTBorder border = ctb.getInsideH();
+ size = border.getSz().intValue();
+ }
+ }
+ return size;
}
public int getInsideHBorderSpace() {
- int space = -1;
+ int space = -1;
- CTTblPr tblPr = getTrPr();
- if (tblPr.isSetTblBorders()) {
- CTTblBorders ctb = tblPr.getTblBorders();
- if (ctb.isSetInsideH()) {
- CTBorder border = ctb.getInsideH();
- space = border.getSpace().intValue();
- }
- }
- return space;
+ CTTblPr tblPr = getTrPr();
+ if (tblPr.isSetTblBorders()) {
+ CTTblBorders ctb = tblPr.getTblBorders();
+ if (ctb.isSetInsideH()) {
+ CTBorder border = ctb.getInsideH();
+ space = border.getSpace().intValue();
+ }
+ }
+ return space;
}
public String getInsideHBorderColor() {
- String color = null;
+ String color = null;
- CTTblPr tblPr = getTrPr();
- if (tblPr.isSetTblBorders()) {
- CTTblBorders ctb = tblPr.getTblBorders();
- if (ctb.isSetInsideH()) {
- CTBorder border = ctb.getInsideH();
- color = border.xgetColor().getStringValue();
- }
- }
- return color;
+ CTTblPr tblPr = getTrPr();
+ if (tblPr.isSetTblBorders()) {
+ CTTblBorders ctb = tblPr.getTblBorders();
+ if (ctb.isSetInsideH()) {
+ CTBorder border = ctb.getInsideH();
+ color = border.xgetColor().getStringValue();
+ }
+ }
+ return color;
}
public XWPFBorderType getInsideVBorderType() {
- XWPFBorderType bt = null;
+ XWPFBorderType bt = null;
- CTTblPr tblPr = getTrPr();
- if (tblPr.isSetTblBorders()) {
- CTTblBorders ctb = tblPr.getTblBorders();
- if (ctb.isSetInsideV()) {
- CTBorder border = ctb.getInsideV();
- bt = stBorderTypeMap.get(border.getVal().intValue());
- }
- }
- return bt;
+ CTTblPr tblPr = getTrPr();
+ if (tblPr.isSetTblBorders()) {
+ CTTblBorders ctb = tblPr.getTblBorders();
+ if (ctb.isSetInsideV()) {
+ CTBorder border = ctb.getInsideV();
+ bt = stBorderTypeMap.get(border.getVal().intValue());
+ }
+ }
+ return bt;
}
public int getInsideVBorderSize() {
- int size = -1;
+ int size = -1;
- CTTblPr tblPr = getTrPr();
- if (tblPr.isSetTblBorders()) {
- CTTblBorders ctb = tblPr.getTblBorders();
- if (ctb.isSetInsideV()) {
- CTBorder border = ctb.getInsideV();
- size = border.getSz().intValue();
- }
- }
- return size;
+ CTTblPr tblPr = getTrPr();
+ if (tblPr.isSetTblBorders()) {
+ CTTblBorders ctb = tblPr.getTblBorders();
+ if (ctb.isSetInsideV()) {
+ CTBorder border = ctb.getInsideV();
+ size = border.getSz().intValue();
+ }
+ }
+ return size;
}
public int getInsideVBorderSpace() {
- int space = -1;
+ int space = -1;
- CTTblPr tblPr = getTrPr();
- if (tblPr.isSetTblBorders()) {
- CTTblBorders ctb = tblPr.getTblBorders();
- if (ctb.isSetInsideV()) {
- CTBorder border = ctb.getInsideV();
- space = border.getSpace().intValue();
- }
- }
- return space;
+ CTTblPr tblPr = getTrPr();
+ if (tblPr.isSetTblBorders()) {
+ CTTblBorders ctb = tblPr.getTblBorders();
+ if (ctb.isSetInsideV()) {
+ CTBorder border = ctb.getInsideV();
+ space = border.getSpace().intValue();
+ }
+ }
+ return space;
}
public String getInsideVBorderColor() {
- String color = null;
+ String color = null;
- CTTblPr tblPr = getTrPr();
- if (tblPr.isSetTblBorders()) {
- CTTblBorders ctb = tblPr.getTblBorders();
- if (ctb.isSetInsideV()) {
- CTBorder border = ctb.getInsideV();
- color = border.xgetColor().getStringValue();
- }
- }
- return color;
+ CTTblPr tblPr = getTrPr();
+ if (tblPr.isSetTblBorders()) {
+ CTTblBorders ctb = tblPr.getTblBorders();
+ if (ctb.isSetInsideV()) {
+ CTBorder border = ctb.getInsideV();
+ color = border.xgetColor().getStringValue();
+ }
+ }
+ return color;
}
public int getRowBandSize() {
- int size = 0;
- CTTblPr tblPr = getTrPr();
- if (tblPr.isSetTblStyleRowBandSize()) {
- CTDecimalNumber rowSize = tblPr.getTblStyleRowBandSize();
- size = rowSize.getVal().intValue();
- }
- return size;
+ int size = 0;
+ CTTblPr tblPr = getTrPr();
+ if (tblPr.isSetTblStyleRowBandSize()) {
+ CTDecimalNumber rowSize = tblPr.getTblStyleRowBandSize();
+ size = rowSize.getVal().intValue();
+ }
+ return size;
}
public void setRowBandSize(int size) {
- CTTblPr tblPr = getTrPr();
- CTDecimalNumber rowSize = tblPr.isSetTblStyleRowBandSize() ? tblPr.getTblStyleRowBandSize() : tblPr.addNewTblStyleRowBandSize();
- rowSize.setVal(BigInteger.valueOf(size));
+ CTTblPr tblPr = getTrPr();
+ CTDecimalNumber rowSize = tblPr.isSetTblStyleRowBandSize() ? tblPr.getTblStyleRowBandSize() : tblPr.addNewTblStyleRowBandSize();
+ rowSize.setVal(BigInteger.valueOf(size));
}
public int getColBandSize() {
- int size = 0;
- CTTblPr tblPr = getTrPr();
- if (tblPr.isSetTblStyleColBandSize()) {
- CTDecimalNumber colSize = tblPr.getTblStyleColBandSize();
- size = colSize.getVal().intValue();
- }
- return size;
+ int size = 0;
+ CTTblPr tblPr = getTrPr();
+ if (tblPr.isSetTblStyleColBandSize()) {
+ CTDecimalNumber colSize = tblPr.getTblStyleColBandSize();
+ size = colSize.getVal().intValue();
+ }
+ return size;
}
public void setColBandSize(int size) {
- CTTblPr tblPr = getTrPr();
- CTDecimalNumber colSize = tblPr.isSetTblStyleColBandSize() ? tblPr.getTblStyleColBandSize() : tblPr.addNewTblStyleColBandSize();
- colSize.setVal(BigInteger.valueOf(size));
+ CTTblPr tblPr = getTrPr();
+ CTDecimalNumber colSize = tblPr.isSetTblStyleColBandSize() ? tblPr.getTblStyleColBandSize() : tblPr.addNewTblStyleColBandSize();
+ colSize.setVal(BigInteger.valueOf(size));
}
public void setInsideHBorder(XWPFBorderType type, int size, int space, String rgbColor) {
- CTTblPr tblPr = getTrPr();
- CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
- CTBorder b = ctb.isSetInsideH() ? ctb.getInsideH() : ctb.addNewInsideH();
- b.setVal(xwpfBorderTypeMap.get(type));
- b.setSz(BigInteger.valueOf(size));
- b.setSpace(BigInteger.valueOf(space));
- b.setColor(rgbColor);
+ CTTblPr tblPr = getTrPr();
+ CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
+ CTBorder b = ctb.isSetInsideH() ? ctb.getInsideH() : ctb.addNewInsideH();
+ b.setVal(xwpfBorderTypeMap.get(type));
+ b.setSz(BigInteger.valueOf(size));
+ b.setSpace(BigInteger.valueOf(space));
+ b.setColor(rgbColor);
}
public void setInsideVBorder(XWPFBorderType type, int size, int space, String rgbColor) {
- CTTblPr tblPr = getTrPr();
- CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
- CTBorder b = ctb.isSetInsideV() ? ctb.getInsideV() : ctb.addNewInsideV();
- b.setVal(xwpfBorderTypeMap.get(type));
- b.setSz(BigInteger.valueOf(size));
- b.setSpace(BigInteger.valueOf(space));
- b.setColor(rgbColor);
+ CTTblPr tblPr = getTrPr();
+ CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
+ CTBorder b = ctb.isSetInsideV() ? ctb.getInsideV() : ctb.addNewInsideV();
+ b.setVal(xwpfBorderTypeMap.get(type));
+ b.setSz(BigInteger.valueOf(size));
+ b.setSpace(BigInteger.valueOf(space));
+ b.setColor(rgbColor);
}
public int getCellMarginTop() {
CTTblPr tblPr = getTrPr();
CTTblCellMar tcm = tblPr.getTblCellMar();
if (tcm != null) {
- CTTblWidth tw = tcm.getTop();
- if (tw != null) {
- margin = tw.getW().intValue();
- }
+ CTTblWidth tw = tcm.getTop();
+ if (tw != null) {
+ margin = tw.getW().intValue();
+ }
}
return margin;
}
CTTblPr tblPr = getTrPr();
CTTblCellMar tcm = tblPr.getTblCellMar();
if (tcm != null) {
- CTTblWidth tw = tcm.getLeft();
- if (tw != null) {
- margin = tw.getW().intValue();
- }
+ CTTblWidth tw = tcm.getLeft();
+ if (tw != null) {
+ margin = tw.getW().intValue();
+ }
}
return margin;
}
CTTblPr tblPr = getTrPr();
CTTblCellMar tcm = tblPr.getTblCellMar();
if (tcm != null) {
- CTTblWidth tw = tcm.getBottom();
- if (tw != null) {
- margin = tw.getW().intValue();
- }
+ CTTblWidth tw = tcm.getBottom();
+ if (tw != null) {
+ margin = tw.getW().intValue();
+ }
}
return margin;
}
public int getCellMarginRight() {
- int margin = 0;
- CTTblPr tblPr = getTrPr();
- CTTblCellMar tcm = tblPr.getTblCellMar();
- if (tcm != null) {
- CTTblWidth tw = tcm.getRight();
- if (tw != null) {
- margin = tw.getW().intValue();
- }
- }
- return margin;
+ int margin = 0;
+ CTTblPr tblPr = getTrPr();
+ CTTblCellMar tcm = tblPr.getTblCellMar();
+ if (tcm != null) {
+ CTTblWidth tw = tcm.getRight();
+ if (tw != null) {
+ margin = tw.getW().intValue();
+ }
+ }
+ return margin;
}
public void setCellMargins(int top, int left, int bottom, int right) {
- CTTblPr tblPr = getTrPr();
- CTTblCellMar tcm = tblPr.isSetTblCellMar() ? tblPr.getTblCellMar() : tblPr.addNewTblCellMar();
+ CTTblPr tblPr = getTrPr();
+ CTTblCellMar tcm = tblPr.isSetTblCellMar() ? tblPr.getTblCellMar() : tblPr.addNewTblCellMar();
- CTTblWidth tw = tcm.isSetLeft() ? tcm.getLeft() : tcm.addNewLeft();
- tw.setType(STTblWidth.DXA);
- tw.setW(BigInteger.valueOf(left));
+ CTTblWidth tw = tcm.isSetLeft() ? tcm.getLeft() : tcm.addNewLeft();
+ tw.setType(STTblWidth.DXA);
+ tw.setW(BigInteger.valueOf(left));
- tw = tcm.isSetTop() ? tcm.getTop() : tcm.addNewTop();
- tw.setType(STTblWidth.DXA);
- tw.setW(BigInteger.valueOf(top));
+ tw = tcm.isSetTop() ? tcm.getTop() : tcm.addNewTop();
+ tw.setType(STTblWidth.DXA);
+ tw.setW(BigInteger.valueOf(top));
- tw = tcm.isSetBottom() ? tcm.getBottom() : tcm.addNewBottom();
- tw.setType(STTblWidth.DXA);
- tw.setW(BigInteger.valueOf(bottom));
+ tw = tcm.isSetBottom() ? tcm.getBottom() : tcm.addNewBottom();
+ tw.setType(STTblWidth.DXA);
+ tw.setW(BigInteger.valueOf(bottom));
- tw = tcm.isSetRight() ? tcm.getRight() : tcm.addNewRight();
- tw.setType(STTblWidth.DXA);
- tw.setW(BigInteger.valueOf(right));
+ tw = tcm.isSetRight() ? tcm.getRight() : tcm.addNewRight();
+ tw.setType(STTblWidth.DXA);
+ tw.setW(BigInteger.valueOf(right));
}
/**
*
* @param row the row which should be added
*/
- public void addRow(XWPFTableRow row){
- ctTbl.addNewTr();
- ctTbl.setTrArray(getNumberOfRows()-1, row.getCtRow());
- tableRows.add(row);
- }
-
- /**
- * add a new Row to the table
- * at position pos
- * @param row the row which should be added
- */
- public boolean addRow(XWPFTableRow row, int pos){
- if(pos >= 0 && pos <= tableRows.size()){
- ctTbl.insertNewTr(pos);
- ctTbl.setTrArray(pos,row.getCtRow());
- tableRows.add(pos, row);
- return true;
- }
- return false;
- }
-
- /**
- * inserts a new tablerow
- * @param pos
- * @return the inserted row
- */
- public XWPFTableRow insertNewTableRow(int pos){
- if(pos >= 0 && pos <= tableRows.size()){
- CTRow row = ctTbl.insertNewTr(pos);
- XWPFTableRow tableRow = new XWPFTableRow(row, this);
- tableRows.add(pos, tableRow);
- return tableRow;
- }
- return null;
- }
-
-
- /**
- * Remove a row at position pos from the table
- * @param pos position the Row in the Table
- */
- public boolean removeRow(int pos) throws IndexOutOfBoundsException {
- if (pos >= 0 && pos < tableRows.size()) {
- if (ctTbl.sizeOfTrArray() > 0) {
- ctTbl.removeTr(pos);
- }
- tableRows.remove(pos);
- return true;
- }
- return false;
- }
-
- public List<XWPFTableRow> getRows() {
- return tableRows;
- }
-
-
- /**
- * returns the type of the BodyElement Table
- * @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType()
- */
- public BodyElementType getElementType() {
- return BodyElementType.TABLE;
- }
-
- public IBody getBody()
- {
- return part;
- }
-
- /**
- * returns the part of the bodyElement
- * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
- */
- public POIXMLDocumentPart getPart() {
- if(part != null){
- return part.getPart();
- }
- return null;
- }
-
- /**
- * returns the partType of the bodyPart which owns the bodyElement
- * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
- */
- public BodyType getPartType() {
- return part.getPartType();
- }
-
- /**
- * returns the XWPFRow which belongs to the CTRow row
- * if this row is not existing in the table null will be returned
- */
- public XWPFTableRow getRow(CTRow row) {
- for(int i=0; i<getRows().size(); i++){
- if(getRows().get(i).getCtRow()== row) return getRow(i);
- }
- return null;
- }
+ public void addRow(XWPFTableRow row){
+ ctTbl.addNewTr();
+ ctTbl.setTrArray(getNumberOfRows()-1, row.getCtRow());
+ tableRows.add(row);
+ }
+
+ /**
+ * add a new Row to the table
+ * at position pos
+ * @param row the row which should be added
+ */
+ public boolean addRow(XWPFTableRow row, int pos){
+ if(pos >= 0 && pos <= tableRows.size()){
+ ctTbl.insertNewTr(pos);
+ ctTbl.setTrArray(pos,row.getCtRow());
+ tableRows.add(pos, row);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * inserts a new tablerow
+ * @param pos
+ * @return the inserted row
+ */
+ public XWPFTableRow insertNewTableRow(int pos){
+ if(pos >= 0 && pos <= tableRows.size()){
+ CTRow row = ctTbl.insertNewTr(pos);
+ XWPFTableRow tableRow = new XWPFTableRow(row, this);
+ tableRows.add(pos, tableRow);
+ return tableRow;
+ }
+ return null;
+ }
+
+
+ /**
+ * Remove a row at position pos from the table
+ * @param pos position the Row in the Table
+ */
+ public boolean removeRow(int pos) throws IndexOutOfBoundsException {
+ if (pos >= 0 && pos < tableRows.size()) {
+ if (ctTbl.sizeOfTrArray() > 0) {
+ ctTbl.removeTr(pos);
+ }
+ tableRows.remove(pos);
+ return true;
+ }
+ return false;
+ }
+
+ public List<XWPFTableRow> getRows() {
+ return tableRows;
+ }
+
+
+ /**
+ * returns the type of the BodyElement Table
+ * @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType()
+ */
+ public BodyElementType getElementType() {
+ return BodyElementType.TABLE;
+ }
+
+ public IBody getBody() {
+ return part;
+ }
+
+ /**
+ * returns the part of the bodyElement
+ * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
+ */
+ public POIXMLDocumentPart getPart() {
+ if(part != null){
+ return part.getPart();
+ }
+ return null;
+ }
+
+ /**
+ * returns the partType of the bodyPart which owns the bodyElement
+ * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
+ */
+ public BodyType getPartType() {
+ return part.getPartType();
+ }
+
+ /**
+ * returns the XWPFRow which belongs to the CTRow row
+ * if this row is not existing in the table null will be returned
+ */
+ public XWPFTableRow getRow(CTRow row) {
+ for(int i=0; i<getRows().size(); i++){
+ if(getRows().get(i).getCtRow()== row) return getRow(i);
+ }
+ return null;
+ }
}
* If a table cell does not include at least one block-level element, then this document shall be considered corrupt
*/
public XWPFTableCell(CTTc cell, XWPFTableRow tableRow, IBody part) {
- this.ctTc = cell;
- this.part = part;
- this.tableRow = tableRow;
- // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
- if(cell.getPList().size()<1)
- cell.addNewP();
- bodyElements = new ArrayList<IBodyElement>();
- paragraphs = new ArrayList<XWPFParagraph>();
- tables = new ArrayList<XWPFTable>();
-
- XmlCursor cursor = ctTc.newCursor();
- cursor.selectPath("./*");
- while (cursor.toNextSelection()) {
- XmlObject o = cursor.getObject();
- if (o instanceof CTP) {
- XWPFParagraph p = new XWPFParagraph((CTP)o, this);
- paragraphs.add(p);
- bodyElements.add(p);
- }
- if (o instanceof CTTbl) {
- XWPFTable t = new XWPFTable((CTTbl)o, this);
- tables.add(t);
- bodyElements.add(t);
- }
- }
- cursor.dispose();
+ this.ctTc = cell;
+ this.part = part;
+ this.tableRow = tableRow;
+ // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
+ if(cell.getPList().size()<1)
+ cell.addNewP();
+ bodyElements = new ArrayList<IBodyElement>();
+ paragraphs = new ArrayList<XWPFParagraph>();
+ tables = new ArrayList<XWPFTable>();
+
+ XmlCursor cursor = ctTc.newCursor();
+ cursor.selectPath("./*");
+ while (cursor.toNextSelection()) {
+ XmlObject o = cursor.getObject();
+ if (o instanceof CTP) {
+ XWPFParagraph p = new XWPFParagraph((CTP)o, this);
+ paragraphs.add(p);
+ bodyElements.add(p);
+ }
+ if (o instanceof CTTbl) {
+ XWPFTable t = new XWPFTable((CTTbl)o, this);
+ tables.add(t);
+ bodyElements.add(t);
+ }
+ }
+ cursor.dispose();
}
@Internal
public CTTc getCTTc() {
- return ctTc;
+ return ctTc;
}
/**
private List<XWPFTableCell> tableCells;
public XWPFTableRow(CTRow row, XWPFTable table) {
- this.table = table;
- this.ctRow = row;
- getTableCells();
+ this.table = table;
+ this.ctRow = row;
+ getTableCells();
}
@Internal
public CTRow getCtRow() {
- return ctRow;
+ return ctRow;
}
/**