Fix and update JavaDoc entries, and correct areas with wildy inconsistent whitespace / style to the surrounding code

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1492818 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2013-06-13 18:52:03 +00:00
parent abd6675bcf
commit d246052993
9 changed files with 598 additions and 598 deletions

View File

@ -44,7 +44,7 @@ public interface IBody {
/**
* 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();

View File

@ -110,31 +110,31 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
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
@ -193,15 +193,15 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
// 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);
}
}
}
}
@ -212,39 +212,39 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
}
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(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 : 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(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteList()) {
endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
}
}
}
}
/**
@ -287,11 +287,11 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
*/
@Internal
public CTDocument1 getDocument() {
return ctDocument;
return ctDocument;
}
IdentifierManager getDrawingIdManager() {
return drawingIdManager;
return drawingIdManager;
}
/**
@ -299,35 +299,35 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @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;
}
/**
@ -335,11 +335,11 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @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);
}
/**
@ -347,62 +347,62 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @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()]);
}
/**
@ -622,18 +622,18 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
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;
@ -644,27 +644,27 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @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;
}
/**
@ -674,7 +674,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @return The location, or -1 if the paragraph couldn't be found
*/
public int getPosOfParagraph(XWPFParagraph p){
return getPosOfBodyElement(p);
return getPosOfBodyElement(p);
}
/**
@ -684,7 +684,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @return The location, or -1 if the table couldn't be found
*/
public int getPosOfTable(XWPFTable t){
return getPosOfBodyElement(t);
return getPosOfBodyElement(t);
}
/**
@ -692,24 +692,24 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
*/
@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);
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();
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
ctDocument.save(out, xmlOptions);
out.close();
}
/**
@ -813,22 +813,22 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @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;
}
/**
@ -1063,7 +1063,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* </ul>
*/
public void enforceUpdateFields() {
settings.setUpdateFields();
settings.setUpdateFields();
}
/**
@ -1280,13 +1280,12 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
return null;
}
public Iterator<XWPFTable> getTablesIterator() {
return tables.iterator();
return tables.iterator();
}
public Iterator<XWPFParagraph> getParagraphsIterator() {
return paragraphs.iterator();
return paragraphs.iterator();
}
/**
@ -1294,10 +1293,10 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @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;
}
/**
@ -1307,7 +1306,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
*/
public POIXMLDocumentPart getPart() {
return this;
return this;
}
@ -1318,7 +1317,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
*/
public BodyType getPartType() {
return BodyType.DOCUMENT;
return BodyType.DOCUMENT;
}
/**
@ -1326,32 +1325,32 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @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;
}
}

View File

@ -41,13 +41,13 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
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));
}
}
@ -96,7 +96,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
* 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);
@ -116,14 +116,14 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
* 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;
}
@ -135,7 +135,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
* @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) {
@ -148,7 +148,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
/**
* 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) {
@ -158,7 +158,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
/**
* 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();
@ -207,7 +207,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
*
* @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)){
@ -248,7 +248,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
* 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)){
@ -284,37 +284,37 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
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();
}
/**

View File

@ -55,7 +55,7 @@ public class XWPFFootnotes extends POIXMLDocumentPart {
* @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);
}
/**
@ -69,45 +69,45 @@ public class XWPFFootnotes extends POIXMLDocumentPart {
*/
@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();
}
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));
}
// 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;
}
/**
@ -115,7 +115,7 @@ public class XWPFFootnotes extends POIXMLDocumentPart {
* @param footnotes
*/
public void setFootnotes(CTFootnotes footnotes) {
ctFootnotes = footnotes;
ctFootnotes = footnotes;
}
/**
@ -124,8 +124,8 @@ public class XWPFFootnotes extends POIXMLDocumentPart {
* @throws IOException
*/
public void addFootnote(XWPFFootnote footnote){
listFootnote.add(footnote);
ctFootnotes.addNewFootnote().set(footnote.getCTFtnEdn());
listFootnote.add(footnote);
ctFootnotes.addNewFootnote().set(footnote.getCTFtnEdn());
}
/**
@ -134,25 +134,25 @@ public class XWPFFootnotes extends POIXMLDocumentPart {
* @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();
}
}
}

View File

@ -53,7 +53,7 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
CTHdrFtr headerFooter;
XWPFDocument document;
XWPFHeaderFooter(XWPFDocument doc, CTHdrFtr hdrFtr){
XWPFHeaderFooter(XWPFDocument doc, CTHdrFtr hdrFtr) {
if (doc==null) {
throw new NullPointerException();
}
@ -171,7 +171,7 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
if(table==null)
return null;
if(table.getCTTbl().equals(ctTable))
return table;
return table;
}
return null;
}
@ -257,7 +257,7 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
// ignore
}
}
document.registerPackagePictureData(xwpfPicData);
pictures.add(xwpfPicData);
return getRelationId(xwpfPicData);
@ -313,7 +313,7 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
if (relatedPart != null && relatedPart instanceof XWPFPictureData) {
return (XWPFPictureData) relatedPart;
}
return null;
return null;
}
/**
@ -499,15 +499,15 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
}
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();
}
}
/**
@ -517,4 +517,4 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
public POIXMLDocumentPart getPart() {
return this;
}
}//end class
}

View File

@ -55,7 +55,11 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
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;
@ -182,25 +186,25 @@ public class XWPFParagraph implements IBodyElement {
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
@ -217,7 +221,7 @@ public class XWPFParagraph implements IBodyElement {
}
return null;
}
/**
* Returns Ilvl of the numeric style for this paragraph.
* Returns null if this paragraph does not have numeric style.
@ -261,7 +265,7 @@ public class XWPFParagraph implements IBodyElement {
}
return null;
}
/**
* setNumID of Paragraph
* @param numPos
@ -282,22 +286,22 @@ public class XWPFParagraph implements IBodyElement {
* 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();
}
/**
@ -383,7 +387,7 @@ public class XWPFParagraph implements IBodyElement {
CTPPr pr = getCTPPr();
return (pr == null || !pr.isSetTextAlignment()) ? TextAlignment.AUTO
: TextAlignment.valueOf(pr.getTextAlignment().getVal()
.intValue());
.intValue());
}
/**
@ -409,9 +413,9 @@ public class XWPFParagraph implements IBodyElement {
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);
}
/**
@ -1162,8 +1166,7 @@ public class XWPFParagraph implements IBodyElement {
* @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();
@ -1182,7 +1185,8 @@ public class XWPFParagraph implements IBodyElement {
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;
@ -1204,8 +1208,9 @@ public class XWPFParagraph implements IBodyElement {
return segement;
}
}
else
else {
candCharPos=0;
}
}
}
textPos++;
@ -1230,29 +1235,27 @@ public class XWPFParagraph implements IBodyElement {
* @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)
@ -1267,8 +1270,8 @@ public class XWPFParagraph implements IBodyElement {
if((j==textEnd)&&(i==runEnd)){
endChar = charEnd;
}
out.append(tmpText.substring(startChar, endChar+1));
out.append(tmpText.substring(startChar, endChar+1));
}
}
return out.toString();
@ -1280,12 +1283,12 @@ public class XWPFParagraph implements IBodyElement {
* @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;
}
/**
@ -1345,5 +1348,4 @@ public class XWPFParagraph implements IBodyElement {
}
return null;
}
}

View File

@ -77,7 +77,7 @@ public class XWPFTable implements IBodyElement {
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) {
@ -94,9 +94,9 @@ public class XWPFTable implements IBodyElement {
}
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
@ -203,7 +203,7 @@ public class XWPFTable implements IBodyElement {
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;
}
@ -277,167 +277,167 @@ public class XWPFTable implements IBodyElement {
}
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() {
@ -445,10 +445,10 @@ public class XWPFTable implements IBodyElement {
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;
}
@ -458,10 +458,10 @@ public class XWPFTable implements IBodyElement {
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;
}
@ -471,46 +471,46 @@ public class XWPFTable implements IBodyElement {
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));
}
/**
@ -518,103 +518,102 @@ public class XWPFTable implements IBodyElement {
*
* @param row the row which should be added
*/
public void addRow(XWPFTableRow row){
ctTbl.addNewTr();
ctTbl.setTrArray(getNumberOfRows()-1, row.getCtRow());
tableRows.add(row);
}
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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
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;
}
/**
* 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;
}
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 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 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;
}
/**
* 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;
}
}

View File

@ -73,38 +73,38 @@ public class XWPFTableCell implements IBody {
* 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>();
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();
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;
}
/**

View File

@ -40,14 +40,14 @@ public class XWPFTableRow {
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;
}
/**