mirror of
https://github.com/apache/poi.git
synced 2025-03-06 00:49:36 +00:00
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:
parent
abd6675bcf
commit
d246052993
@ -44,7 +44,7 @@ public interface IBody {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get the PartType of the body, for example
|
* get the PartType of the body, for example
|
||||||
* DOCUMENT, HEADER, FOOTER, FOOTNOTE,
|
* DOCUMENT, HEADER, FOOTER, FOOTNOTE,
|
||||||
* @return the PartType of the body
|
* @return the PartType of the body
|
||||||
*/
|
*/
|
||||||
public BodyType getPartType();
|
public BodyType getPartType();
|
||||||
|
@ -110,31 +110,31 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
private XWPFHeaderFooterPolicy headerFooterPolicy;
|
private XWPFHeaderFooterPolicy headerFooterPolicy;
|
||||||
|
|
||||||
public XWPFDocument(OPCPackage pkg) throws IOException {
|
public XWPFDocument(OPCPackage pkg) throws IOException {
|
||||||
super(pkg);
|
super(pkg);
|
||||||
|
|
||||||
//build a tree of POIXMLDocumentParts, this document being the root
|
//build a tree of POIXMLDocumentParts, this document being the root
|
||||||
load(XWPFFactory.getInstance());
|
load(XWPFFactory.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFDocument(InputStream is) throws IOException {
|
public XWPFDocument(InputStream is) throws IOException {
|
||||||
super(PackageHelper.open(is));
|
super(PackageHelper.open(is));
|
||||||
|
|
||||||
//build a tree of POIXMLDocumentParts, this workbook being the root
|
//build a tree of POIXMLDocumentParts, this workbook being the root
|
||||||
load(XWPFFactory.getInstance());
|
load(XWPFFactory.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFDocument(){
|
public XWPFDocument(){
|
||||||
super(newPackage());
|
super(newPackage());
|
||||||
onDocumentCreate();
|
onDocumentCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDocumentRead() throws IOException {
|
protected void onDocumentRead() throws IOException {
|
||||||
try {
|
try {
|
||||||
DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
|
DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
|
||||||
ctDocument = doc.getDocument();
|
ctDocument = doc.getDocument();
|
||||||
|
|
||||||
initFootnotes();
|
initFootnotes();
|
||||||
|
|
||||||
// parse the document with cursor and add
|
// parse the document with cursor and add
|
||||||
// the XmlObject to its lists
|
// 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
|
// We don't currently process the glossary itself
|
||||||
// Until we do, we do need to load the glossary child parts of it
|
// Until we do, we do need to load the glossary child parts of it
|
||||||
for (POIXMLDocumentPart gp : p.getRelations()) {
|
for (POIXMLDocumentPart gp : p.getRelations()) {
|
||||||
// Trigger the onDocumentRead for all the child parts
|
// Trigger the onDocumentRead for all the child parts
|
||||||
// Otherwise we'll hit issues on Styles, Settings etc on save
|
// Otherwise we'll hit issues on Styles, Settings etc on save
|
||||||
try {
|
try {
|
||||||
Method onDocumentRead = gp.getClass().getDeclaredMethod("onDocumentRead");
|
Method onDocumentRead = gp.getClass().getDeclaredMethod("onDocumentRead");
|
||||||
onDocumentRead.setAccessible(true);
|
onDocumentRead.setAccessible(true);
|
||||||
onDocumentRead.invoke(gp);
|
onDocumentRead.invoke(gp);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,39 +212,39 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initHyperlinks(){
|
private void initHyperlinks(){
|
||||||
// Get the hyperlinks
|
// Get the hyperlinks
|
||||||
// TODO: make me optional/separated in private function
|
// TODO: make me optional/separated in private function
|
||||||
try {
|
try {
|
||||||
Iterator<PackageRelationship> relIter =
|
Iterator<PackageRelationship> relIter =
|
||||||
getPackagePart().getRelationshipsByType(XWPFRelation.HYPERLINK.getRelation()).iterator();
|
getPackagePart().getRelationshipsByType(XWPFRelation.HYPERLINK.getRelation()).iterator();
|
||||||
while(relIter.hasNext()) {
|
while(relIter.hasNext()) {
|
||||||
PackageRelationship rel = relIter.next();
|
PackageRelationship rel = relIter.next();
|
||||||
hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString()));
|
hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString()));
|
||||||
}
|
}
|
||||||
} catch (InvalidFormatException e){
|
} catch (InvalidFormatException e){
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFootnotes() throws XmlException, IOException {
|
private void initFootnotes() throws XmlException, IOException {
|
||||||
for(POIXMLDocumentPart p : getRelations()){
|
for(POIXMLDocumentPart p : getRelations()){
|
||||||
String relation = p.getPackageRelationship().getRelationshipType();
|
String relation = p.getPackageRelationship().getRelationshipType();
|
||||||
if (relation.equals(XWPFRelation.FOOTNOTE.getRelation())) {
|
if (relation.equals(XWPFRelation.FOOTNOTE.getRelation())) {
|
||||||
FootnotesDocument footnotesDocument = FootnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
|
FootnotesDocument footnotesDocument = FootnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
|
||||||
this.footnotes = (XWPFFootnotes)p;
|
this.footnotes = (XWPFFootnotes)p;
|
||||||
this.footnotes.onDocumentRead();
|
this.footnotes.onDocumentRead();
|
||||||
|
|
||||||
for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteList()) {
|
for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteList()) {
|
||||||
footnotes.addFootnote(ctFtnEdn);
|
footnotes.addFootnote(ctFtnEdn);
|
||||||
}
|
}
|
||||||
} else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){
|
} else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){
|
||||||
EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
|
EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
|
||||||
|
|
||||||
for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteList()) {
|
for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteList()) {
|
||||||
endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
|
endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -287,11 +287,11 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
public CTDocument1 getDocument() {
|
public CTDocument1 getDocument() {
|
||||||
return ctDocument;
|
return ctDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentifierManager getDrawingIdManager() {
|
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()
|
* @see org.apache.poi.xwpf.usermodel.IBody#getBodyElements()
|
||||||
*/
|
*/
|
||||||
public List<IBodyElement> getBodyElements() {
|
public List<IBodyElement> getBodyElements() {
|
||||||
return Collections.unmodifiableList(bodyElements);
|
return Collections.unmodifiableList(bodyElements);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<IBodyElement> getBodyElementsIterator() {
|
public Iterator<IBodyElement> getBodyElementsIterator() {
|
||||||
return bodyElements.iterator();
|
return bodyElements.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.poi.xwpf.usermodel.IBody#getParagraphs()
|
* @see org.apache.poi.xwpf.usermodel.IBody#getParagraphs()
|
||||||
*/
|
*/
|
||||||
public List<XWPFParagraph> getParagraphs(){
|
public List<XWPFParagraph> getParagraphs(){
|
||||||
return Collections.unmodifiableList(paragraphs);
|
return Collections.unmodifiableList(paragraphs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.poi.xwpf.usermodel.IBody#getTables()
|
* @see org.apache.poi.xwpf.usermodel.IBody#getTables()
|
||||||
*/
|
*/
|
||||||
public List<XWPFTable> getTables(){
|
public List<XWPFTable> getTables(){
|
||||||
return Collections.unmodifiableList(tables);
|
return Collections.unmodifiableList(tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int)
|
* @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int)
|
||||||
*/
|
*/
|
||||||
public XWPFTable getTableArray(int pos) {
|
public XWPFTable getTableArray(int pos) {
|
||||||
if(pos > 0 && pos < tables.size()){
|
if (pos > 0 && pos < tables.size()){
|
||||||
return tables.get(pos);
|
return tables.get(pos);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -335,11 +335,11 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
* @return the list of footers
|
* @return the list of footers
|
||||||
*/
|
*/
|
||||||
public List<XWPFFooter> getFooterList(){
|
public List<XWPFFooter> getFooterList(){
|
||||||
return Collections.unmodifiableList(footers);
|
return Collections.unmodifiableList(footers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFFooter getFooterArray(int pos){
|
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
|
* @return the list of headers
|
||||||
*/
|
*/
|
||||||
public List<XWPFHeader> getHeaderList(){
|
public List<XWPFHeader> getHeaderList(){
|
||||||
return Collections.unmodifiableList(headers);
|
return Collections.unmodifiableList(headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFHeader getHeaderArray(int pos){
|
public XWPFHeader getHeaderArray(int pos){
|
||||||
return headers.get(pos);
|
return headers.get(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTblStyle(XWPFTable table){
|
public String getTblStyle(XWPFTable table){
|
||||||
return table.getStyleID();
|
return table.getStyleID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFHyperlink getHyperlinkByID(String id) {
|
public XWPFHyperlink getHyperlinkByID(String id) {
|
||||||
Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
|
Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
XWPFHyperlink link = iter.next();
|
XWPFHyperlink link = iter.next();
|
||||||
if(link.getId().equals(id))
|
if(link.getId().equals(id))
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFFootnote getFootnoteByID(int id) {
|
public XWPFFootnote getFootnoteByID(int id) {
|
||||||
if(footnotes == null) return null;
|
if(footnotes == null) return null;
|
||||||
return footnotes.getFootnoteById(id);
|
return footnotes.getFootnoteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFFootnote getEndnoteByID(int id) {
|
public XWPFFootnote getEndnoteByID(int id) {
|
||||||
if(endnotes == null) return null;
|
if(endnotes == null) return null;
|
||||||
return endnotes.get(id);
|
return endnotes.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<XWPFFootnote> getFootnotes() {
|
public List<XWPFFootnote> getFootnotes() {
|
||||||
if(footnotes == null) {
|
if(footnotes == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return footnotes.getFootnotesList();
|
return footnotes.getFootnotesList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFHyperlink[] getHyperlinks() {
|
public XWPFHyperlink[] getHyperlinks() {
|
||||||
return hyperlinks.toArray(new XWPFHyperlink[hyperlinks.size()]);
|
return hyperlinks.toArray(new XWPFHyperlink[hyperlinks.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFComment getCommentByID(String id) {
|
public XWPFComment getCommentByID(String id) {
|
||||||
Iterator<XWPFComment> iter = comments.iterator();
|
Iterator<XWPFComment> iter = comments.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
XWPFComment comment = iter.next();
|
XWPFComment comment = iter.next();
|
||||||
if(comment.getId().equals(id))
|
if(comment.getId().equals(id))
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFComment[] getComments() {
|
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();
|
XmlCursor tableCursor = t.newCursor();
|
||||||
try {
|
try {
|
||||||
cursor.toCursor(tableCursor);
|
cursor.toCursor(tableCursor);
|
||||||
while (cursor.toPrevSibling()) {
|
while (cursor.toPrevSibling()) {
|
||||||
o = cursor.getObject();
|
o = cursor.getObject();
|
||||||
if (o instanceof CTP || o instanceof CTTbl)
|
if (o instanceof CTP || o instanceof CTTbl)
|
||||||
i++;
|
i++;
|
||||||
|
}
|
||||||
|
bodyElements.add(i, newT);
|
||||||
|
cursor.toCursor(tableCursor);
|
||||||
|
cursor.toEndToken();
|
||||||
|
return newT;
|
||||||
}
|
}
|
||||||
bodyElements.add(i, newT);
|
|
||||||
cursor.toCursor(tableCursor);
|
|
||||||
cursor.toEndToken();
|
|
||||||
return newT;
|
|
||||||
}
|
|
||||||
finally {
|
finally {
|
||||||
tableCursor.dispose();
|
tableCursor.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -644,27 +644,27 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
* @param cursor
|
* @param cursor
|
||||||
*/
|
*/
|
||||||
private boolean isCursorInBody(XmlCursor cursor) {
|
private boolean isCursorInBody(XmlCursor cursor) {
|
||||||
XmlCursor verify = cursor.newCursor();
|
XmlCursor verify = cursor.newCursor();
|
||||||
verify.toParent();
|
verify.toParent();
|
||||||
try {
|
try {
|
||||||
return (verify.getObject() == this.ctDocument.getBody());
|
return (verify.getObject() == this.ctDocument.getBody());
|
||||||
} finally {
|
} finally {
|
||||||
verify.dispose();
|
verify.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPosOfBodyElement(IBodyElement needle) {
|
private int getPosOfBodyElement(IBodyElement needle) {
|
||||||
BodyElementType type = needle.getElementType();
|
BodyElementType type = needle.getElementType();
|
||||||
IBodyElement current;
|
IBodyElement current;
|
||||||
for(int i=0; i<bodyElements.size(); i++) {
|
for(int i=0; i<bodyElements.size(); i++) {
|
||||||
current = bodyElements.get(i);
|
current = bodyElements.get(i);
|
||||||
if(current.getElementType() == type) {
|
if(current.getElementType() == type) {
|
||||||
if(current.equals(needle)) {
|
if(current.equals(needle)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
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
|
* @return The location, or -1 if the paragraph couldn't be found
|
||||||
*/
|
*/
|
||||||
public int getPosOfParagraph(XWPFParagraph p){
|
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
|
* @return The location, or -1 if the table couldn't be found
|
||||||
*/
|
*/
|
||||||
public int getPosOfTable(XWPFTable t){
|
public int getPosOfTable(XWPFTable t){
|
||||||
return getPosOfBodyElement(t);
|
return getPosOfBodyElement(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -692,24 +692,24 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void commit() throws IOException {
|
protected void commit() throws IOException {
|
||||||
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
|
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
|
||||||
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document"));
|
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document"));
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
|
map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
|
||||||
map.put("urn:schemas-microsoft-com:office:office", "o");
|
map.put("urn:schemas-microsoft-com:office:office", "o");
|
||||||
map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
|
map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
|
||||||
map.put("urn:schemas-microsoft-com:vml", "v");
|
map.put("urn:schemas-microsoft-com:vml", "v");
|
||||||
map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
|
map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
|
||||||
map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
|
map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
|
||||||
map.put("urn:schemas-microsoft-com:office:word", "w10");
|
map.put("urn:schemas-microsoft-com:office:word", "w10");
|
||||||
map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne");
|
map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne");
|
||||||
map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
|
map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
|
||||||
xmlOptions.setSaveSuggestedPrefixes(map);
|
xmlOptions.setSaveSuggestedPrefixes(map);
|
||||||
|
|
||||||
PackagePart part = getPackagePart();
|
PackagePart part = getPackagePart();
|
||||||
OutputStream out = part.getOutputStream();
|
OutputStream out = part.getOutputStream();
|
||||||
ctDocument.save(out, xmlOptions);
|
ctDocument.save(out, xmlOptions);
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -813,22 +813,22 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
* @return true if removing was successfully, else return false
|
* @return true if removing was successfully, else return false
|
||||||
*/
|
*/
|
||||||
public boolean removeBodyElement(int pos) {
|
public boolean removeBodyElement(int pos) {
|
||||||
if(pos >= 0 && pos < bodyElements.size()) {
|
if (pos >= 0 && pos < bodyElements.size()) {
|
||||||
BodyElementType type = bodyElements.get(pos).getElementType();
|
BodyElementType type = bodyElements.get(pos).getElementType();
|
||||||
if(type == BodyElementType.TABLE){
|
if (type == BodyElementType.TABLE){
|
||||||
int tablePos = getTablePos(pos);
|
int tablePos = getTablePos(pos);
|
||||||
tables.remove(tablePos);
|
tables.remove(tablePos);
|
||||||
ctDocument.getBody().removeTbl(tablePos);
|
ctDocument.getBody().removeTbl(tablePos);
|
||||||
}
|
}
|
||||||
if(type == BodyElementType.PARAGRAPH) {
|
if (type == BodyElementType.PARAGRAPH) {
|
||||||
int paraPos = getParagraphPos(pos);
|
int paraPos = getParagraphPos(pos);
|
||||||
paragraphs.remove(paraPos);
|
paragraphs.remove(paraPos);
|
||||||
ctDocument.getBody().removeP(paraPos);
|
ctDocument.getBody().removeP(paraPos);
|
||||||
}
|
}
|
||||||
bodyElements.remove(pos);
|
bodyElements.remove(pos);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1063,7 +1063,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public void enforceUpdateFields() {
|
public void enforceUpdateFields() {
|
||||||
settings.setUpdateFields();
|
settings.setUpdateFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1280,13 +1280,12 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Iterator<XWPFTable> getTablesIterator() {
|
public Iterator<XWPFTable> getTablesIterator() {
|
||||||
return tables.iterator();
|
return tables.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<XWPFParagraph> getParagraphsIterator() {
|
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)
|
* @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int)
|
||||||
*/
|
*/
|
||||||
public XWPFParagraph getParagraphArray(int pos) {
|
public XWPFParagraph getParagraphArray(int pos) {
|
||||||
if(pos >= 0 && pos < paragraphs.size()){
|
if(pos >= 0 && pos < paragraphs.size()){
|
||||||
return paragraphs.get(pos);
|
return paragraphs.get(pos);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1307,7 +1306,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
|
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
|
||||||
*/
|
*/
|
||||||
public POIXMLDocumentPart 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()
|
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
|
||||||
*/
|
*/
|
||||||
public BodyType getPartType() {
|
public BodyType getPartType() {
|
||||||
return BodyType.DOCUMENT;
|
return BodyType.DOCUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1326,32 +1325,32 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
* @param cell
|
* @param cell
|
||||||
*/
|
*/
|
||||||
public XWPFTableCell getTableCell(CTTc cell) {
|
public XWPFTableCell getTableCell(CTTc cell) {
|
||||||
XmlCursor cursor = cell.newCursor();
|
XmlCursor cursor = cell.newCursor();
|
||||||
cursor.toParent();
|
cursor.toParent();
|
||||||
XmlObject o = cursor.getObject();
|
XmlObject o = cursor.getObject();
|
||||||
if(!(o instanceof CTRow)){
|
if(!(o instanceof CTRow)){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
CTRow row = (CTRow)o;
|
CTRow row = (CTRow)o;
|
||||||
cursor.toParent();
|
cursor.toParent();
|
||||||
o = cursor.getObject();
|
o = cursor.getObject();
|
||||||
cursor.dispose();
|
cursor.dispose();
|
||||||
if(! (o instanceof CTTbl)){
|
if(! (o instanceof CTTbl)){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
CTTbl tbl = (CTTbl) o;
|
CTTbl tbl = (CTTbl) o;
|
||||||
XWPFTable table = getTable(tbl);
|
XWPFTable table = getTable(tbl);
|
||||||
if(table == null){
|
if(table == null){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
XWPFTableRow tableRow = table.getRow(row);
|
XWPFTableRow tableRow = table.getRow(row);
|
||||||
if (tableRow == null) {
|
if (tableRow == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return tableRow.getTableCell(cell);
|
return tableRow.getTableCell(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFDocument getXWPFDocument() {
|
public XWPFDocument getXWPFDocument() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,13 +41,13 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
|
|||||||
public XWPFFootnote(CTFtnEdn note, XWPFFootnotes xFootnotes) {
|
public XWPFFootnote(CTFtnEdn note, XWPFFootnotes xFootnotes) {
|
||||||
footnotes = xFootnotes;
|
footnotes = xFootnotes;
|
||||||
ctFtnEdn = note;
|
ctFtnEdn = note;
|
||||||
for (CTP p : ctFtnEdn.getPList()) {
|
for (CTP p : ctFtnEdn.getPList()) {
|
||||||
paragraphs.add(new XWPFParagraph(p, this));
|
paragraphs.add(new XWPFParagraph(p, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFFootnote(XWPFDocument document, CTFtnEdn body) {
|
public XWPFFootnote(XWPFDocument document, CTFtnEdn body) {
|
||||||
for (CTP p : body.getPList()) {
|
for (CTP p : body.getPList()) {
|
||||||
paragraphs.add(new XWPFParagraph(p, document));
|
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
|
* inserts an existing XWPFTable to the arrays bodyElements and tables
|
||||||
* @param pos
|
* @param pos
|
||||||
* @param table
|
* @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) {
|
public void insertTable(int pos, XWPFTable table) {
|
||||||
bodyElements.add(pos, table);
|
bodyElements.add(pos, table);
|
||||||
@ -116,7 +116,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
|
|||||||
* the method will return this table
|
* the method will return this table
|
||||||
* if there is no corresponding {@link XWPFTable} the method will return null
|
* if there is no corresponding {@link XWPFTable} the method will return null
|
||||||
* @param ctTable
|
* @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){
|
public XWPFTable getTable(CTTbl ctTable){
|
||||||
for (XWPFTable table : tables) {
|
for (XWPFTable table : tables) {
|
||||||
@ -135,7 +135,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
|
|||||||
* @param p is instance of CTP and is searching for an XWPFParagraph
|
* @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
|
* @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
|
* 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){
|
public XWPFParagraph getParagraph(CTP p){
|
||||||
for (XWPFParagraph paragraph : paragraphs) {
|
for (XWPFParagraph paragraph : paragraphs) {
|
||||||
@ -148,7 +148,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
|
|||||||
/**
|
/**
|
||||||
* Returns the paragraph that holds
|
* Returns the paragraph that holds
|
||||||
* the text of the header or footer.
|
* 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) {
|
public XWPFParagraph getParagraphArray(int pos) {
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
|
|||||||
/**
|
/**
|
||||||
* get the TableCell which belongs to the TableCell
|
* get the TableCell which belongs to the TableCell
|
||||||
* @param cell
|
* @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) {
|
public XWPFTableCell getTableCell(CTTc cell) {
|
||||||
XmlCursor cursor = cell.newCursor();
|
XmlCursor cursor = cell.newCursor();
|
||||||
@ -207,7 +207,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
|
|||||||
*
|
*
|
||||||
* @param cursor
|
* @param cursor
|
||||||
* @return the inserted table
|
* @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) {
|
public XWPFTable insertNewTbl(XmlCursor cursor) {
|
||||||
if(isCursorInFtn(cursor)){
|
if(isCursorInFtn(cursor)){
|
||||||
@ -248,7 +248,7 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
|
|||||||
* add a new paragraph at position of the cursor
|
* add a new paragraph at position of the cursor
|
||||||
* @param cursor
|
* @param cursor
|
||||||
* @return the inserted paragraph
|
* @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){
|
public XWPFParagraph insertNewParagraph(XmlCursor cursor){
|
||||||
if(isCursorInFtn(cursor)){
|
if(isCursorInFtn(cursor)){
|
||||||
@ -284,37 +284,37 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a new table to the end of the footnote
|
* add a new table to the end of the footnote
|
||||||
* @param table
|
* @param table
|
||||||
* @return the added XWPFTable
|
* @return the added XWPFTable
|
||||||
*/
|
*/
|
||||||
public XWPFTable addNewTbl(CTTbl table) {
|
public XWPFTable addNewTbl(CTTbl table) {
|
||||||
CTTbl newTable = ctFtnEdn.addNewTbl();
|
CTTbl newTable = ctFtnEdn.addNewTbl();
|
||||||
newTable.set(table);
|
newTable.set(table);
|
||||||
XWPFTable xTable = new XWPFTable(newTable, this);
|
XWPFTable xTable = new XWPFTable(newTable, this);
|
||||||
tables.add(xTable);
|
tables.add(xTable);
|
||||||
return xTable;
|
return xTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a new paragraph to the end of the footnote
|
* add a new paragraph to the end of the footnote
|
||||||
* @param paragraph
|
* @param paragraph
|
||||||
* @return the added XWPFParagraph
|
* @return the added XWPFParagraph
|
||||||
*/
|
*/
|
||||||
public XWPFParagraph addNewParagraph(CTP paragraph) {
|
public XWPFParagraph addNewParagraph(CTP paragraph) {
|
||||||
CTP newPara = ctFtnEdn.addNewP();
|
CTP newPara = ctFtnEdn.addNewP();
|
||||||
newPara.set(paragraph);
|
newPara.set(paragraph);
|
||||||
XWPFParagraph xPara = new XWPFParagraph(newPara, this);
|
XWPFParagraph xPara = new XWPFParagraph(newPara, this);
|
||||||
paragraphs.add(xPara);
|
paragraphs.add(xPara);
|
||||||
return xPara;
|
return xPara;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.poi.xwpf.usermodel.IBody#getXWPFDocument()
|
* @see org.apache.poi.xwpf.usermodel.IBody#getXWPFDocument()
|
||||||
*/
|
*/
|
||||||
public XWPFDocument getXWPFDocument() {
|
public XWPFDocument getXWPFDocument() {
|
||||||
return footnotes.getXWPFDocument();
|
return footnotes.getXWPFDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +55,7 @@ public class XWPFFootnotes extends POIXMLDocumentPart {
|
|||||||
* @param rel the package relationship of type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"
|
* @param rel the package relationship of type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"
|
||||||
*/
|
*/
|
||||||
public XWPFFootnotes(PackagePart part, PackageRelationship rel) throws IOException, OpenXML4JException{
|
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
|
@Override
|
||||||
protected void onDocumentRead () throws IOException {
|
protected void onDocumentRead () throws IOException {
|
||||||
FootnotesDocument notesDoc;
|
FootnotesDocument notesDoc;
|
||||||
try {
|
try {
|
||||||
InputStream is = getPackagePart().getInputStream();
|
InputStream is = getPackagePart().getInputStream();
|
||||||
notesDoc = FootnotesDocument.Factory.parse(is);
|
notesDoc = FootnotesDocument.Factory.parse(is);
|
||||||
ctFootnotes = notesDoc.getFootnotes();
|
ctFootnotes = notesDoc.getFootnotes();
|
||||||
} catch (XmlException e) {
|
} catch (XmlException e) {
|
||||||
throw new POIXMLException();
|
throw new POIXMLException();
|
||||||
}
|
}
|
||||||
|
|
||||||
//get any Footnote
|
// Find our footnotes
|
||||||
for(CTFtnEdn note : ctFootnotes.getFootnoteList()) {
|
for(CTFtnEdn note : ctFootnotes.getFootnoteList()) {
|
||||||
listFootnote.add(new XWPFFootnote(note, this));
|
listFootnote.add(new XWPFFootnote(note, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void commit() throws IOException {
|
protected void commit() throws IOException {
|
||||||
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
|
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
|
||||||
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes"));
|
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes"));
|
||||||
Map<String,String> map = new HashMap<String,String>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
|
map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
|
||||||
map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
|
map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
|
||||||
xmlOptions.setSaveSuggestedPrefixes(map);
|
xmlOptions.setSaveSuggestedPrefixes(map);
|
||||||
PackagePart part = getPackagePart();
|
PackagePart part = getPackagePart();
|
||||||
OutputStream out = part.getOutputStream();
|
OutputStream out = part.getOutputStream();
|
||||||
ctFootnotes.save(out, xmlOptions);
|
ctFootnotes.save(out, xmlOptions);
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<XWPFFootnote> getFootnotesList() {
|
public List<XWPFFootnote> getFootnotesList() {
|
||||||
return listFootnote;
|
return listFootnote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFFootnote getFootnoteById(int id) {
|
public XWPFFootnote getFootnoteById(int id) {
|
||||||
for(XWPFFootnote note : listFootnote) {
|
for(XWPFFootnote note : listFootnote) {
|
||||||
if(note.getCTFtnEdn().getId().intValue() == id)
|
if(note.getCTFtnEdn().getId().intValue() == id)
|
||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,7 +115,7 @@ public class XWPFFootnotes extends POIXMLDocumentPart {
|
|||||||
* @param footnotes
|
* @param footnotes
|
||||||
*/
|
*/
|
||||||
public void setFootnotes(CTFootnotes footnotes) {
|
public void setFootnotes(CTFootnotes footnotes) {
|
||||||
ctFootnotes = footnotes;
|
ctFootnotes = footnotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -124,8 +124,8 @@ public class XWPFFootnotes extends POIXMLDocumentPart {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void addFootnote(XWPFFootnote footnote){
|
public void addFootnote(XWPFFootnote footnote){
|
||||||
listFootnote.add(footnote);
|
listFootnote.add(footnote);
|
||||||
ctFootnotes.addNewFootnote().set(footnote.getCTFtnEdn());
|
ctFootnotes.addNewFootnote().set(footnote.getCTFtnEdn());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,25 +134,25 @@ public class XWPFFootnotes extends POIXMLDocumentPart {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public XWPFFootnote addFootnote(CTFtnEdn note){
|
public XWPFFootnote addFootnote(CTFtnEdn note){
|
||||||
CTFtnEdn newNote = ctFootnotes.addNewFootnote();
|
CTFtnEdn newNote = ctFootnotes.addNewFootnote();
|
||||||
newNote.set(note);
|
newNote.set(note);
|
||||||
XWPFFootnote xNote = new XWPFFootnote(newNote, this);
|
XWPFFootnote xNote = new XWPFFootnote(newNote, this);
|
||||||
listFootnote.add(xNote);
|
listFootnote.add(xNote);
|
||||||
return xNote;
|
return xNote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setXWPFDocument(XWPFDocument doc) {
|
public void setXWPFDocument(XWPFDocument doc) {
|
||||||
document = doc;
|
document = doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
|
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
|
||||||
*/
|
*/
|
||||||
public XWPFDocument getXWPFDocument() {
|
public XWPFDocument getXWPFDocument() {
|
||||||
if ( document != null) {
|
if ( document != null) {
|
||||||
return document;
|
return document;
|
||||||
} else {
|
} else {
|
||||||
return (XWPFDocument)getParent();
|
return (XWPFDocument)getParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
|
|||||||
CTHdrFtr headerFooter;
|
CTHdrFtr headerFooter;
|
||||||
XWPFDocument document;
|
XWPFDocument document;
|
||||||
|
|
||||||
XWPFHeaderFooter(XWPFDocument doc, CTHdrFtr hdrFtr){
|
XWPFHeaderFooter(XWPFDocument doc, CTHdrFtr hdrFtr) {
|
||||||
if (doc==null) {
|
if (doc==null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
@ -499,15 +499,15 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setXWPFDocument(XWPFDocument doc) {
|
public void setXWPFDocument(XWPFDocument doc) {
|
||||||
document = doc;
|
document = doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFDocument getXWPFDocument() {
|
public XWPFDocument getXWPFDocument() {
|
||||||
if (document!=null) {
|
if (document!=null) {
|
||||||
return document;
|
return document;
|
||||||
} else {
|
} else {
|
||||||
return (XWPFDocument)getParent();
|
return (XWPFDocument)getParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -517,4 +517,4 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
|
|||||||
public POIXMLDocumentPart getPart() {
|
public POIXMLDocumentPart getPart() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}//end class
|
}
|
||||||
|
@ -55,7 +55,11 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
|
|||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
|
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 {
|
public class XWPFParagraph implements IBodyElement {
|
||||||
private final CTP paragraph;
|
private final CTP paragraph;
|
||||||
@ -182,7 +186,7 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
public String getText() {
|
public String getText() {
|
||||||
StringBuffer out = new StringBuffer();
|
StringBuffer out = new StringBuffer();
|
||||||
for(XWPFRun run : runs) {
|
for(XWPFRun run : runs) {
|
||||||
out.append(run.toString());
|
out.append(run.toString());
|
||||||
}
|
}
|
||||||
out.append(footnoteText);
|
out.append(footnoteText);
|
||||||
return out.toString();
|
return out.toString();
|
||||||
@ -193,14 +197,14 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
* if not, null will be returned
|
* if not, null will be returned
|
||||||
* @return styleID as String
|
* @return styleID as String
|
||||||
*/
|
*/
|
||||||
public String getStyleID(){
|
public String getStyleID() {
|
||||||
if (paragraph.getPPr() != null){
|
if (paragraph.getPPr() != null) {
|
||||||
if(paragraph.getPPr().getPStyle()!= null){
|
if(paragraph.getPPr().getPStyle()!= null) {
|
||||||
if (paragraph.getPPr().getPStyle().getVal()!= null)
|
if (paragraph.getPPr().getPStyle().getVal()!= null)
|
||||||
return paragraph.getPPr().getPStyle().getVal();
|
return paragraph.getPPr().getPStyle().getVal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* If style exist for this paragraph
|
* If style exist for this paragraph
|
||||||
@ -282,22 +286,22 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
* paragraph
|
* paragraph
|
||||||
*/
|
*/
|
||||||
public String getParagraphText() {
|
public String getParagraphText() {
|
||||||
StringBuffer out = new StringBuffer();
|
StringBuffer out = new StringBuffer();
|
||||||
for(XWPFRun run : runs) {
|
for(XWPFRun run : runs) {
|
||||||
out.append(run.toString());
|
out.append(run.toString());
|
||||||
}
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns any text from any suitable pictures in the paragraph
|
* Returns any text from any suitable pictures in the paragraph
|
||||||
*/
|
*/
|
||||||
public String getPictureText() {
|
public String getPictureText() {
|
||||||
StringBuffer out = new StringBuffer();
|
StringBuffer out = new StringBuffer();
|
||||||
for(XWPFRun run : runs) {
|
for(XWPFRun run : runs) {
|
||||||
out.append(run.getPictureText());
|
out.append(run.getPictureText());
|
||||||
}
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -383,7 +387,7 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
CTPPr pr = getCTPPr();
|
CTPPr pr = getCTPPr();
|
||||||
return (pr == null || !pr.isSetTextAlignment()) ? TextAlignment.AUTO
|
return (pr == null || !pr.isSetTextAlignment()) ? TextAlignment.AUTO
|
||||||
: TextAlignment.valueOf(pr.getTextAlignment().getVal()
|
: TextAlignment.valueOf(pr.getTextAlignment().getVal()
|
||||||
.intValue());
|
.intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -409,9 +413,9 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
CTPPr pr = getCTPPr();
|
CTPPr pr = getCTPPr();
|
||||||
CTTextAlignment textAlignment = pr.isSetTextAlignment() ? pr
|
CTTextAlignment textAlignment = pr.isSetTextAlignment() ? pr
|
||||||
.getTextAlignment() : pr.addNewTextAlignment();
|
.getTextAlignment() : pr.addNewTextAlignment();
|
||||||
STTextAlignment.Enum en = STTextAlignment.Enum
|
STTextAlignment.Enum en = STTextAlignment.Enum
|
||||||
.forInt(valign.getValue());
|
.forInt(valign.getValue());
|
||||||
textAlignment.setVal(en);
|
textAlignment.setVal(en);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1162,8 +1166,7 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
* @param searched
|
* @param searched
|
||||||
* @param startPos
|
* @param startPos
|
||||||
*/
|
*/
|
||||||
public TextSegement searchText(String searched,PositionInParagraph startPos){
|
public TextSegement searchText(String searched,PositionInParagraph startPos) {
|
||||||
|
|
||||||
int startRun = startPos.getRun(),
|
int startRun = startPos.getRun(),
|
||||||
startText = startPos.getText(),
|
startText = startPos.getText(),
|
||||||
startChar = startPos.getChar();
|
startChar = startPos.getChar();
|
||||||
@ -1183,6 +1186,7 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
charPos= startChar;
|
charPos= startChar;
|
||||||
else
|
else
|
||||||
charPos = 0;
|
charPos = 0;
|
||||||
|
|
||||||
for(; charPos<candidate.length(); charPos++){
|
for(; charPos<candidate.length(); charPos++){
|
||||||
if((candidate.charAt(charPos)==searched.charAt(0))&&(candCharPos==0)){
|
if((candidate.charAt(charPos)==searched.charAt(0))&&(candCharPos==0)){
|
||||||
beginTextPos = textPos;
|
beginTextPos = textPos;
|
||||||
@ -1204,8 +1208,9 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
return segement;
|
return segement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
candCharPos=0;
|
candCharPos=0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
textPos++;
|
textPos++;
|
||||||
@ -1230,29 +1235,27 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
* @return the inserted run
|
* @return the inserted run
|
||||||
*/
|
*/
|
||||||
public XWPFRun insertNewRun(int pos){
|
public XWPFRun insertNewRun(int pos){
|
||||||
if (pos >= 0 && pos <= paragraph.sizeOfRArray()) {
|
if (pos >= 0 && pos <= paragraph.sizeOfRArray()) {
|
||||||
CTR ctRun = paragraph.insertNewR(pos);
|
CTR ctRun = paragraph.insertNewR(pos);
|
||||||
XWPFRun newRun = new XWPFRun(ctRun, this);
|
XWPFRun newRun = new XWPFRun(ctRun, this);
|
||||||
runs.add(pos, newRun);
|
runs.add(pos, newRun);
|
||||||
return newRun;
|
return newRun;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a Text
|
* get a Text
|
||||||
* @param segment
|
* @param segment
|
||||||
*/
|
*/
|
||||||
public String getText(TextSegement segment){
|
public String getText(TextSegement segment){
|
||||||
int runBegin = segment.getBeginRun();
|
int runBegin = segment.getBeginRun();
|
||||||
int textBegin = segment.getBeginText();
|
int textBegin = segment.getBeginText();
|
||||||
int charBegin = segment.getBeginChar();
|
int charBegin = segment.getBeginChar();
|
||||||
int runEnd = segment.getEndRun();
|
int runEnd = segment.getEndRun();
|
||||||
int textEnd = segment.getEndText();
|
int textEnd = segment.getEndText();
|
||||||
int charEnd = segment.getEndChar();
|
int charEnd = segment.getEndChar();
|
||||||
StringBuffer out = new StringBuffer();
|
StringBuffer out = new StringBuffer();
|
||||||
for(int i=runBegin; i<=runEnd;i++){
|
for(int i=runBegin; i<=runEnd;i++){
|
||||||
int startText=0, endText = paragraph.getRArray(i).getTList().size()-1;
|
int startText=0, endText = paragraph.getRArray(i).getTList().size()-1;
|
||||||
if(i==runBegin)
|
if(i==runBegin)
|
||||||
@ -1267,7 +1270,7 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
if((j==textEnd)&&(i==runEnd)){
|
if((j==textEnd)&&(i==runEnd)){
|
||||||
endChar = charEnd;
|
endChar = charEnd;
|
||||||
}
|
}
|
||||||
out.append(tmpText.substring(startChar, endChar+1));
|
out.append(tmpText.substring(startChar, endChar+1));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1280,12 +1283,12 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
* @return true if the run was removed
|
* @return true if the run was removed
|
||||||
*/
|
*/
|
||||||
public boolean removeRun(int pos){
|
public boolean removeRun(int pos){
|
||||||
if (pos >= 0 && pos < paragraph.sizeOfRArray()){
|
if (pos >= 0 && pos < paragraph.sizeOfRArray()) {
|
||||||
getCTP().removeR(pos);
|
getCTP().removeR(pos);
|
||||||
runs.remove(pos);
|
runs.remove(pos);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1345,5 +1348,4 @@ public class XWPFParagraph implements IBodyElement {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ public class XWPFTable implements IBodyElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public XWPFTable(CTTbl table, IBody part){
|
public XWPFTable(CTTbl table, IBody part){
|
||||||
this.part = part;
|
this.part = part;
|
||||||
this.ctTbl = table;
|
this.ctTbl = table;
|
||||||
|
|
||||||
tableRows = new ArrayList<XWPFTableRow>();
|
tableRows = new ArrayList<XWPFTableRow>();
|
||||||
@ -203,7 +203,7 @@ public class XWPFTable implements IBodyElement {
|
|||||||
public XWPFTableRow getRow(int pos) {
|
public XWPFTableRow getRow(int pos) {
|
||||||
if (pos >= 0 && pos < ctTbl.sizeOfTrArray()) {
|
if (pos >= 0 && pos < ctTbl.sizeOfTrArray()) {
|
||||||
//return new XWPFTableRow(ctTbl.getTrArray(pos));
|
//return new XWPFTableRow(ctTbl.getTrArray(pos));
|
||||||
return getRows().get(pos);
|
return getRows().get(pos);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -277,167 +277,167 @@ public class XWPFTable implements IBodyElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public XWPFBorderType getInsideHBorderType() {
|
public XWPFBorderType getInsideHBorderType() {
|
||||||
XWPFBorderType bt = null;
|
XWPFBorderType bt = null;
|
||||||
|
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
if (tblPr.isSetTblBorders()) {
|
if (tblPr.isSetTblBorders()) {
|
||||||
CTTblBorders ctb = tblPr.getTblBorders();
|
CTTblBorders ctb = tblPr.getTblBorders();
|
||||||
if (ctb.isSetInsideH()) {
|
if (ctb.isSetInsideH()) {
|
||||||
CTBorder border = ctb.getInsideH();
|
CTBorder border = ctb.getInsideH();
|
||||||
bt = stBorderTypeMap.get(border.getVal().intValue());
|
bt = stBorderTypeMap.get(border.getVal().intValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bt;
|
return bt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInsideHBorderSize() {
|
public int getInsideHBorderSize() {
|
||||||
int size = -1;
|
int size = -1;
|
||||||
|
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
if (tblPr.isSetTblBorders()) {
|
if (tblPr.isSetTblBorders()) {
|
||||||
CTTblBorders ctb = tblPr.getTblBorders();
|
CTTblBorders ctb = tblPr.getTblBorders();
|
||||||
if (ctb.isSetInsideH()) {
|
if (ctb.isSetInsideH()) {
|
||||||
CTBorder border = ctb.getInsideH();
|
CTBorder border = ctb.getInsideH();
|
||||||
size = border.getSz().intValue();
|
size = border.getSz().intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInsideHBorderSpace() {
|
public int getInsideHBorderSpace() {
|
||||||
int space = -1;
|
int space = -1;
|
||||||
|
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
if (tblPr.isSetTblBorders()) {
|
if (tblPr.isSetTblBorders()) {
|
||||||
CTTblBorders ctb = tblPr.getTblBorders();
|
CTTblBorders ctb = tblPr.getTblBorders();
|
||||||
if (ctb.isSetInsideH()) {
|
if (ctb.isSetInsideH()) {
|
||||||
CTBorder border = ctb.getInsideH();
|
CTBorder border = ctb.getInsideH();
|
||||||
space = border.getSpace().intValue();
|
space = border.getSpace().intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return space;
|
return space;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInsideHBorderColor() {
|
public String getInsideHBorderColor() {
|
||||||
String color = null;
|
String color = null;
|
||||||
|
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
if (tblPr.isSetTblBorders()) {
|
if (tblPr.isSetTblBorders()) {
|
||||||
CTTblBorders ctb = tblPr.getTblBorders();
|
CTTblBorders ctb = tblPr.getTblBorders();
|
||||||
if (ctb.isSetInsideH()) {
|
if (ctb.isSetInsideH()) {
|
||||||
CTBorder border = ctb.getInsideH();
|
CTBorder border = ctb.getInsideH();
|
||||||
color = border.xgetColor().getStringValue();
|
color = border.xgetColor().getStringValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFBorderType getInsideVBorderType() {
|
public XWPFBorderType getInsideVBorderType() {
|
||||||
XWPFBorderType bt = null;
|
XWPFBorderType bt = null;
|
||||||
|
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
if (tblPr.isSetTblBorders()) {
|
if (tblPr.isSetTblBorders()) {
|
||||||
CTTblBorders ctb = tblPr.getTblBorders();
|
CTTblBorders ctb = tblPr.getTblBorders();
|
||||||
if (ctb.isSetInsideV()) {
|
if (ctb.isSetInsideV()) {
|
||||||
CTBorder border = ctb.getInsideV();
|
CTBorder border = ctb.getInsideV();
|
||||||
bt = stBorderTypeMap.get(border.getVal().intValue());
|
bt = stBorderTypeMap.get(border.getVal().intValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bt;
|
return bt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInsideVBorderSize() {
|
public int getInsideVBorderSize() {
|
||||||
int size = -1;
|
int size = -1;
|
||||||
|
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
if (tblPr.isSetTblBorders()) {
|
if (tblPr.isSetTblBorders()) {
|
||||||
CTTblBorders ctb = tblPr.getTblBorders();
|
CTTblBorders ctb = tblPr.getTblBorders();
|
||||||
if (ctb.isSetInsideV()) {
|
if (ctb.isSetInsideV()) {
|
||||||
CTBorder border = ctb.getInsideV();
|
CTBorder border = ctb.getInsideV();
|
||||||
size = border.getSz().intValue();
|
size = border.getSz().intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInsideVBorderSpace() {
|
public int getInsideVBorderSpace() {
|
||||||
int space = -1;
|
int space = -1;
|
||||||
|
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
if (tblPr.isSetTblBorders()) {
|
if (tblPr.isSetTblBorders()) {
|
||||||
CTTblBorders ctb = tblPr.getTblBorders();
|
CTTblBorders ctb = tblPr.getTblBorders();
|
||||||
if (ctb.isSetInsideV()) {
|
if (ctb.isSetInsideV()) {
|
||||||
CTBorder border = ctb.getInsideV();
|
CTBorder border = ctb.getInsideV();
|
||||||
space = border.getSpace().intValue();
|
space = border.getSpace().intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return space;
|
return space;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInsideVBorderColor() {
|
public String getInsideVBorderColor() {
|
||||||
String color = null;
|
String color = null;
|
||||||
|
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
if (tblPr.isSetTblBorders()) {
|
if (tblPr.isSetTblBorders()) {
|
||||||
CTTblBorders ctb = tblPr.getTblBorders();
|
CTTblBorders ctb = tblPr.getTblBorders();
|
||||||
if (ctb.isSetInsideV()) {
|
if (ctb.isSetInsideV()) {
|
||||||
CTBorder border = ctb.getInsideV();
|
CTBorder border = ctb.getInsideV();
|
||||||
color = border.xgetColor().getStringValue();
|
color = border.xgetColor().getStringValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRowBandSize() {
|
public int getRowBandSize() {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
if (tblPr.isSetTblStyleRowBandSize()) {
|
if (tblPr.isSetTblStyleRowBandSize()) {
|
||||||
CTDecimalNumber rowSize = tblPr.getTblStyleRowBandSize();
|
CTDecimalNumber rowSize = tblPr.getTblStyleRowBandSize();
|
||||||
size = rowSize.getVal().intValue();
|
size = rowSize.getVal().intValue();
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRowBandSize(int size) {
|
public void setRowBandSize(int size) {
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
CTDecimalNumber rowSize = tblPr.isSetTblStyleRowBandSize() ? tblPr.getTblStyleRowBandSize() : tblPr.addNewTblStyleRowBandSize();
|
CTDecimalNumber rowSize = tblPr.isSetTblStyleRowBandSize() ? tblPr.getTblStyleRowBandSize() : tblPr.addNewTblStyleRowBandSize();
|
||||||
rowSize.setVal(BigInteger.valueOf(size));
|
rowSize.setVal(BigInteger.valueOf(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColBandSize() {
|
public int getColBandSize() {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
if (tblPr.isSetTblStyleColBandSize()) {
|
if (tblPr.isSetTblStyleColBandSize()) {
|
||||||
CTDecimalNumber colSize = tblPr.getTblStyleColBandSize();
|
CTDecimalNumber colSize = tblPr.getTblStyleColBandSize();
|
||||||
size = colSize.getVal().intValue();
|
size = colSize.getVal().intValue();
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColBandSize(int size) {
|
public void setColBandSize(int size) {
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
CTDecimalNumber colSize = tblPr.isSetTblStyleColBandSize() ? tblPr.getTblStyleColBandSize() : tblPr.addNewTblStyleColBandSize();
|
CTDecimalNumber colSize = tblPr.isSetTblStyleColBandSize() ? tblPr.getTblStyleColBandSize() : tblPr.addNewTblStyleColBandSize();
|
||||||
colSize.setVal(BigInteger.valueOf(size));
|
colSize.setVal(BigInteger.valueOf(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInsideHBorder(XWPFBorderType type, int size, int space, String rgbColor) {
|
public void setInsideHBorder(XWPFBorderType type, int size, int space, String rgbColor) {
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
|
CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
|
||||||
CTBorder b = ctb.isSetInsideH() ? ctb.getInsideH() : ctb.addNewInsideH();
|
CTBorder b = ctb.isSetInsideH() ? ctb.getInsideH() : ctb.addNewInsideH();
|
||||||
b.setVal(xwpfBorderTypeMap.get(type));
|
b.setVal(xwpfBorderTypeMap.get(type));
|
||||||
b.setSz(BigInteger.valueOf(size));
|
b.setSz(BigInteger.valueOf(size));
|
||||||
b.setSpace(BigInteger.valueOf(space));
|
b.setSpace(BigInteger.valueOf(space));
|
||||||
b.setColor(rgbColor);
|
b.setColor(rgbColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInsideVBorder(XWPFBorderType type, int size, int space, String rgbColor) {
|
public void setInsideVBorder(XWPFBorderType type, int size, int space, String rgbColor) {
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
|
CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
|
||||||
CTBorder b = ctb.isSetInsideV() ? ctb.getInsideV() : ctb.addNewInsideV();
|
CTBorder b = ctb.isSetInsideV() ? ctb.getInsideV() : ctb.addNewInsideV();
|
||||||
b.setVal(xwpfBorderTypeMap.get(type));
|
b.setVal(xwpfBorderTypeMap.get(type));
|
||||||
b.setSz(BigInteger.valueOf(size));
|
b.setSz(BigInteger.valueOf(size));
|
||||||
b.setSpace(BigInteger.valueOf(space));
|
b.setSpace(BigInteger.valueOf(space));
|
||||||
b.setColor(rgbColor);
|
b.setColor(rgbColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCellMarginTop() {
|
public int getCellMarginTop() {
|
||||||
@ -445,10 +445,10 @@ public class XWPFTable implements IBodyElement {
|
|||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
CTTblCellMar tcm = tblPr.getTblCellMar();
|
CTTblCellMar tcm = tblPr.getTblCellMar();
|
||||||
if (tcm != null) {
|
if (tcm != null) {
|
||||||
CTTblWidth tw = tcm.getTop();
|
CTTblWidth tw = tcm.getTop();
|
||||||
if (tw != null) {
|
if (tw != null) {
|
||||||
margin = tw.getW().intValue();
|
margin = tw.getW().intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return margin;
|
return margin;
|
||||||
}
|
}
|
||||||
@ -458,10 +458,10 @@ public class XWPFTable implements IBodyElement {
|
|||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
CTTblCellMar tcm = tblPr.getTblCellMar();
|
CTTblCellMar tcm = tblPr.getTblCellMar();
|
||||||
if (tcm != null) {
|
if (tcm != null) {
|
||||||
CTTblWidth tw = tcm.getLeft();
|
CTTblWidth tw = tcm.getLeft();
|
||||||
if (tw != null) {
|
if (tw != null) {
|
||||||
margin = tw.getW().intValue();
|
margin = tw.getW().intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return margin;
|
return margin;
|
||||||
}
|
}
|
||||||
@ -471,46 +471,46 @@ public class XWPFTable implements IBodyElement {
|
|||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
CTTblCellMar tcm = tblPr.getTblCellMar();
|
CTTblCellMar tcm = tblPr.getTblCellMar();
|
||||||
if (tcm != null) {
|
if (tcm != null) {
|
||||||
CTTblWidth tw = tcm.getBottom();
|
CTTblWidth tw = tcm.getBottom();
|
||||||
if (tw != null) {
|
if (tw != null) {
|
||||||
margin = tw.getW().intValue();
|
margin = tw.getW().intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return margin;
|
return margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCellMarginRight() {
|
public int getCellMarginRight() {
|
||||||
int margin = 0;
|
int margin = 0;
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
CTTblCellMar tcm = tblPr.getTblCellMar();
|
CTTblCellMar tcm = tblPr.getTblCellMar();
|
||||||
if (tcm != null) {
|
if (tcm != null) {
|
||||||
CTTblWidth tw = tcm.getRight();
|
CTTblWidth tw = tcm.getRight();
|
||||||
if (tw != null) {
|
if (tw != null) {
|
||||||
margin = tw.getW().intValue();
|
margin = tw.getW().intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return margin;
|
return margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCellMargins(int top, int left, int bottom, int right) {
|
public void setCellMargins(int top, int left, int bottom, int right) {
|
||||||
CTTblPr tblPr = getTrPr();
|
CTTblPr tblPr = getTrPr();
|
||||||
CTTblCellMar tcm = tblPr.isSetTblCellMar() ? tblPr.getTblCellMar() : tblPr.addNewTblCellMar();
|
CTTblCellMar tcm = tblPr.isSetTblCellMar() ? tblPr.getTblCellMar() : tblPr.addNewTblCellMar();
|
||||||
|
|
||||||
CTTblWidth tw = tcm.isSetLeft() ? tcm.getLeft() : tcm.addNewLeft();
|
CTTblWidth tw = tcm.isSetLeft() ? tcm.getLeft() : tcm.addNewLeft();
|
||||||
tw.setType(STTblWidth.DXA);
|
tw.setType(STTblWidth.DXA);
|
||||||
tw.setW(BigInteger.valueOf(left));
|
tw.setW(BigInteger.valueOf(left));
|
||||||
|
|
||||||
tw = tcm.isSetTop() ? tcm.getTop() : tcm.addNewTop();
|
tw = tcm.isSetTop() ? tcm.getTop() : tcm.addNewTop();
|
||||||
tw.setType(STTblWidth.DXA);
|
tw.setType(STTblWidth.DXA);
|
||||||
tw.setW(BigInteger.valueOf(top));
|
tw.setW(BigInteger.valueOf(top));
|
||||||
|
|
||||||
tw = tcm.isSetBottom() ? tcm.getBottom() : tcm.addNewBottom();
|
tw = tcm.isSetBottom() ? tcm.getBottom() : tcm.addNewBottom();
|
||||||
tw.setType(STTblWidth.DXA);
|
tw.setType(STTblWidth.DXA);
|
||||||
tw.setW(BigInteger.valueOf(bottom));
|
tw.setW(BigInteger.valueOf(bottom));
|
||||||
|
|
||||||
tw = tcm.isSetRight() ? tcm.getRight() : tcm.addNewRight();
|
tw = tcm.isSetRight() ? tcm.getRight() : tcm.addNewRight();
|
||||||
tw.setType(STTblWidth.DXA);
|
tw.setType(STTblWidth.DXA);
|
||||||
tw.setW(BigInteger.valueOf(right));
|
tw.setW(BigInteger.valueOf(right));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -518,103 +518,102 @@ public class XWPFTable implements IBodyElement {
|
|||||||
*
|
*
|
||||||
* @param row the row which should be added
|
* @param row the row which should be added
|
||||||
*/
|
*/
|
||||||
public void addRow(XWPFTableRow row){
|
public void addRow(XWPFTableRow row){
|
||||||
ctTbl.addNewTr();
|
ctTbl.addNewTr();
|
||||||
ctTbl.setTrArray(getNumberOfRows()-1, row.getCtRow());
|
ctTbl.setTrArray(getNumberOfRows()-1, row.getCtRow());
|
||||||
tableRows.add(row);
|
tableRows.add(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a new Row to the table
|
* add a new Row to the table
|
||||||
* at position pos
|
* at position pos
|
||||||
* @param row the row which should be added
|
* @param row the row which should be added
|
||||||
*/
|
*/
|
||||||
public boolean addRow(XWPFTableRow row, int pos){
|
public boolean addRow(XWPFTableRow row, int pos){
|
||||||
if(pos >= 0 && pos <= tableRows.size()){
|
if(pos >= 0 && pos <= tableRows.size()){
|
||||||
ctTbl.insertNewTr(pos);
|
ctTbl.insertNewTr(pos);
|
||||||
ctTbl.setTrArray(pos,row.getCtRow());
|
ctTbl.setTrArray(pos,row.getCtRow());
|
||||||
tableRows.add(pos, row);
|
tableRows.add(pos, row);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inserts a new tablerow
|
* inserts a new tablerow
|
||||||
* @param pos
|
* @param pos
|
||||||
* @return the inserted row
|
* @return the inserted row
|
||||||
*/
|
*/
|
||||||
public XWPFTableRow insertNewTableRow(int pos){
|
public XWPFTableRow insertNewTableRow(int pos){
|
||||||
if(pos >= 0 && pos <= tableRows.size()){
|
if(pos >= 0 && pos <= tableRows.size()){
|
||||||
CTRow row = ctTbl.insertNewTr(pos);
|
CTRow row = ctTbl.insertNewTr(pos);
|
||||||
XWPFTableRow tableRow = new XWPFTableRow(row, this);
|
XWPFTableRow tableRow = new XWPFTableRow(row, this);
|
||||||
tableRows.add(pos, tableRow);
|
tableRows.add(pos, tableRow);
|
||||||
return tableRow;
|
return tableRow;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a row at position pos from the table
|
* Remove a row at position pos from the table
|
||||||
* @param pos position the Row in the Table
|
* @param pos position the Row in the Table
|
||||||
*/
|
*/
|
||||||
public boolean removeRow(int pos) throws IndexOutOfBoundsException {
|
public boolean removeRow(int pos) throws IndexOutOfBoundsException {
|
||||||
if (pos >= 0 && pos < tableRows.size()) {
|
if (pos >= 0 && pos < tableRows.size()) {
|
||||||
if (ctTbl.sizeOfTrArray() > 0) {
|
if (ctTbl.sizeOfTrArray() > 0) {
|
||||||
ctTbl.removeTr(pos);
|
ctTbl.removeTr(pos);
|
||||||
}
|
}
|
||||||
tableRows.remove(pos);
|
tableRows.remove(pos);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<XWPFTableRow> getRows() {
|
public List<XWPFTableRow> getRows() {
|
||||||
return tableRows;
|
return tableRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the type of the BodyElement Table
|
* returns the type of the BodyElement Table
|
||||||
* @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType()
|
* @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType()
|
||||||
*/
|
*/
|
||||||
public BodyElementType getElementType() {
|
public BodyElementType getElementType() {
|
||||||
return BodyElementType.TABLE;
|
return BodyElementType.TABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBody getBody()
|
public IBody getBody() {
|
||||||
{
|
return part;
|
||||||
return part;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the part of the bodyElement
|
* returns the part of the bodyElement
|
||||||
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
|
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
|
||||||
*/
|
*/
|
||||||
public POIXMLDocumentPart getPart() {
|
public POIXMLDocumentPart getPart() {
|
||||||
if(part != null){
|
if(part != null){
|
||||||
return part.getPart();
|
return part.getPart();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the partType of the bodyPart which owns the bodyElement
|
* returns the partType of the bodyPart which owns the bodyElement
|
||||||
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
|
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
|
||||||
*/
|
*/
|
||||||
public BodyType getPartType() {
|
public BodyType getPartType() {
|
||||||
return part.getPartType();
|
return part.getPartType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the XWPFRow which belongs to the CTRow row
|
* returns the XWPFRow which belongs to the CTRow row
|
||||||
* if this row is not existing in the table null will be returned
|
* if this row is not existing in the table null will be returned
|
||||||
*/
|
*/
|
||||||
public XWPFTableRow getRow(CTRow row) {
|
public XWPFTableRow getRow(CTRow row) {
|
||||||
for(int i=0; i<getRows().size(); i++){
|
for(int i=0; i<getRows().size(); i++){
|
||||||
if(getRows().get(i).getCtRow()== row) return getRow(i);
|
if(getRows().get(i).getCtRow()== row) return getRow(i);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
* 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) {
|
public XWPFTableCell(CTTc cell, XWPFTableRow tableRow, IBody part) {
|
||||||
this.ctTc = cell;
|
this.ctTc = cell;
|
||||||
this.part = part;
|
this.part = part;
|
||||||
this.tableRow = tableRow;
|
this.tableRow = tableRow;
|
||||||
// NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
|
// 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)
|
if(cell.getPList().size()<1)
|
||||||
cell.addNewP();
|
cell.addNewP();
|
||||||
bodyElements = new ArrayList<IBodyElement>();
|
bodyElements = new ArrayList<IBodyElement>();
|
||||||
paragraphs = new ArrayList<XWPFParagraph>();
|
paragraphs = new ArrayList<XWPFParagraph>();
|
||||||
tables = new ArrayList<XWPFTable>();
|
tables = new ArrayList<XWPFTable>();
|
||||||
|
|
||||||
XmlCursor cursor = ctTc.newCursor();
|
XmlCursor cursor = ctTc.newCursor();
|
||||||
cursor.selectPath("./*");
|
cursor.selectPath("./*");
|
||||||
while (cursor.toNextSelection()) {
|
while (cursor.toNextSelection()) {
|
||||||
XmlObject o = cursor.getObject();
|
XmlObject o = cursor.getObject();
|
||||||
if (o instanceof CTP) {
|
if (o instanceof CTP) {
|
||||||
XWPFParagraph p = new XWPFParagraph((CTP)o, this);
|
XWPFParagraph p = new XWPFParagraph((CTP)o, this);
|
||||||
paragraphs.add(p);
|
paragraphs.add(p);
|
||||||
bodyElements.add(p);
|
bodyElements.add(p);
|
||||||
}
|
}
|
||||||
if (o instanceof CTTbl) {
|
if (o instanceof CTTbl) {
|
||||||
XWPFTable t = new XWPFTable((CTTbl)o, this);
|
XWPFTable t = new XWPFTable((CTTbl)o, this);
|
||||||
tables.add(t);
|
tables.add(t);
|
||||||
bodyElements.add(t);
|
bodyElements.add(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor.dispose();
|
cursor.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
public CTTc getCTTc() {
|
public CTTc getCTTc() {
|
||||||
return ctTc;
|
return ctTc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,14 +40,14 @@ public class XWPFTableRow {
|
|||||||
private List<XWPFTableCell> tableCells;
|
private List<XWPFTableCell> tableCells;
|
||||||
|
|
||||||
public XWPFTableRow(CTRow row, XWPFTable table) {
|
public XWPFTableRow(CTRow row, XWPFTable table) {
|
||||||
this.table = table;
|
this.table = table;
|
||||||
this.ctRow = row;
|
this.ctRow = row;
|
||||||
getTableCells();
|
getTableCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
public CTRow getCtRow() {
|
public CTRow getCtRow() {
|
||||||
return ctRow;
|
return ctRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user