Using Java 11 with Intellj
I have been going over, the use of a declared List<Object> NodePath = "//w:p", and working through the idea of targeting only paragraphs, not bullet points, independent variables. I just want paragraphs, I have used the Object with P, and not sure, if I have to insinuate the paragraph with a text generation, and then giving that text a value. I am unsure from the documentation, even with Utils given, which haven't been able to get only a paragraph. I want to target the xml directly, but the documentation is not working in that manner. Supplied below is some of the code I have been using, it feeds into a javascript ui, with a springboot backend for the mapping portion, which shouldn't be a problem, but the java program, I want to only get text, so if a table is given, I want it to ignore, baased on the XML, for bullet points, I want the same, If I have to filter by t he JAXBElement, how would I do that, would it just be going after that directly, is there a Data Relation of some sort if so, any links would be helpful, videos or anything. When I do the for(Object paragraph:
List<Object> SeriesNodes = DocumentFull.getJAXBNodesViaXPath(NodePath, true);
List<Object> paragraphs = getAllElementFromObject(DocumentFull.getContent(), P.class);
One of which grabs the full, document the same one which uses a different node path does the same, I am unsure, why there is no filter at all. Do I have to apply styling settings, create a new document, with the given XML.
Using java Syntax Highlighting
public String uploadNewFile(@NotNull @RequestParam("file") MultipartFile ProposalGenerate) throws IOException, Docx4JException, JAXBException, XMLStreamException {
//Can do it one function, need to finish input stream reading portion of DOcx4j
System.out.println("File Uploaded");
WordprocessingMLPackage dataUpload = WordprocessingMLPackage.load(ProposalGenerate.getInputStream());
System.out.println("Lazy 1:" + dataUpload);
WordprocessingMLPackage.load(ProposalGenerate.getInputStream());
System.out.println("Lazy 2:" + dataUpload);
MainDocumentPart DocumentFull = dataUpload.getMainDocumentPart();
System.out.println("Document Full" + DocumentFull);
System.out.println("Lazy" + dataUpload);
ProposalGenerate.getOriginalFilename();
System.out.println("Number 1" + ProposalGenerate.getOriginalFilename());
ProposalGenerate.getInputStream();
System.out.println("Number 2" + ProposalGenerate.getInputStream());
//Get the file contents and save it to the console
byte[] bytes = ProposalGenerate.getBytes();
System.out.println("Number 3" + Arrays.toString(bytes));
//Create a new file
File file = new File("C:\\Users\\" + ProposalGenerate.getOriginalFilename());
System.out.println("Number 4" + file);
//Write the file to the file system
// file.createNewFile();
// System.out.println("Number 5" + file);
FileEntity fileEntity = new FileEntity(file);
System.out.println("Number 6" + fileEntity);
ProposalGenerate.getContentType();
ProposalGenerate.getBytes();
System.out.println("Number 7" + Arrays.toString(ProposalGenerate.getBytes()));
//Give What type of Content you want to grab from the docuemtn
String NodePath = "//w:t";
// String NodePath = "//w:p[1]/w:r[1]/w:t[1]";
// Making Tmp Variable for NodePath Routing to Taking Place Upon the Document
// resfresXMLfirst (Does Maybe refesh the XML)
List<Object> SeriesNodes = DocumentFull.getJAXBNodesViaXPath(NodePath, true);
System.out.println("Number 8" + SeriesNodes);
//P.content.get(SeriesNodes);
// Just a Object Declaration, with the Series of Nodes going to be used, with the document given.
for (Object ignored : SeriesNodes) {
// Piece of Garbage Code
Text place = (Text) ((JAXBElement<?>) ignored).getValue();
// Get Value of String (Get Value may be Wrong for getting ParagraphH)
//QUestioning place.getValue(); .getValue();
String placeValue = place.getValue();
// Just a way to show the data can return the object
System.out.println("Index 1:" + placeValue);
}//placevalue
System.out.println("Number 8" + SeriesNodes);
System.out.println("Number 9" + DocumentFull);
System.out.println("Plake Number 10.5" + DocumentFull.getContent());
// System.out.println("Plake Number 10.6" + DocumentFull.getContent().contains(this.getAllElementFromObject(1, P.class)));
// System.out.println("Plake Number 10.6" + DocumentFull.getContent().contains(this.getAllElementFromObject(1, P.class)));
// Really Important: "//w:p";
String NodePathing = "//w:p";
//System.out.println("NEW Runnner Scene: Before Bed Number 22" + DocumentFull.getJAXBNodesViaXPath(NodePathing, P.class, true));
// Pass NodePathing to Object Xpath
// List<Object> SeriesPara = DocumentFull.getJAXBNodesViaXPath(NodePathing, true);
// List<Object> SeriesPara = DocumentFull.getJAXBNodesViaXPath(NodePathing, true);
// List <Object> SerialNodes = Collections.singletonList(DocumentFull.getContent().contains(this.getAllElementFromObject(NodePathing, P.class)));
//Only Reads Text(Paragraph reads only Text, while Text Reads everything)
List<Object> paragraphs = getAllElementFromObject(DocumentFull.getContent(), P.class);
System.out.println("Number 11" + paragraphs);
//Worst Thing: ", ," for new line andd startIndex and endIndex
List <Object> SerialNodes = DocumentFull.getJAXBNodesViaXPath(NodePathing, false);
System.out.println("Number 11" + SerialNodes);
//System.out.println("NEW Runnner Scene: Before Bed Number 22" + DocumentFull.getJAXBNodesViaXPath(NodePathing, P.class, true));
// System.out.println("NEW Runnner Scene: Before Bed Number 22" + DocumentFull.getJAXBNodesViaXPath(1, String.valueOf(P.class), true));
// System.out.println("NEW Runnner Scene: Before Bed Number 22" + DocumentFull.getJAXBNodesViaXPath(String.valueOf(P.class), true));
//System.out.println("NEW Runnner Scene: Before Bed Number 22" + DocumentFull.getJAXBNodesViaXPath(String.valueOf(P.class), false));
// IF statement
System.out.println("Plake Number 11.65" + SerialNodes);
for (Object drake : SerialNodes) {
//if(drake instanceof P) {
// P drakeP = (P) drake;
// System.out.println("Plake Number 11.66" + drakeP);
// }
System.out.println("Plake Number 10.7" + drake);
//P place = P.class.cast(drake);
//Get Paragraph from the Document
P ParaI = (P) drake;
System.out.println("Plake Number 10.8" + ParaI);
System.out.println("Plake Number 10.85" + ParaI.getParaId());
System.out.println("Plake Number 10.9" + ParaI.getTextId());
System.out.println("Plake Number 10.10" + ((P) drake).getContent());
// System.out.println(place);
System.out.println("Plake Number 10.9" + ParaI.getContent());
// System.out.println("Plake Number 10.10" + ParaI.getContent().get(0));
// System.out.println("Plake Number 10.11" + ParaI.getContent().get(0).getClass());
// System.out.println("Plake Number 10.12" + ParaI.getContent().get(0).getClass().getName());
// System.out.println("Plake Number 10.13" + ParaI.getContent().get(0).getClass().getName().equals("org.docx4j.wml.Text"));
String Placer = String.valueOf(ParaI.getPPr().getPStyle().getVal());
System.out.println("Plake Number 10.14" + Placer);
System.out.println("Plake Number 10.15" + Placer.contains("\n"));
String ParaText = Placer.replace("\n", " ");
System.out.println("Plake Number 10.16" + ParaText);
//String testingP = ParaI.getContent().get(0).toString();
// String placeValue = place.getPPr().getPStyle().getVal();
//String placeValue = place.getValue();
String placeValue = ParaI.getParaId();
// String placeValue2 = ParaI.getValue();
System.out.println("ERROR SEEN" + placeValue);
System.out.println("Number 13" + drake);
System.out.println("Number 14" + ParaI);
}//placevalue
System.out.println("Number 12" + SerialNodes);
// System.out.println("Number 8" + SeriesPara);
//DocumentFull.getContent(); //This is the content of the document in the form of a string can pass to the front end
System.out.println("Number 10" + DocumentFull.getContent());
System.out.println("Number 11" + dataUpload);
// PPr pPr = ((P) XmlUtils.unwrap(DocumentFull)).getPPr();
// if (pPr != null) {
// PPrBase.PStyle pStyle = pPr.getPStyle();
// if (pStyle != null) {
// // String style = pStyle.getVal();
// System.out.println("Style: " + style);
// }
// }
// System.out.println("Number 12" + DocumentFull);
// System.out.println("Number 13" + pPr);
// return DocumentFull.getContent() + "Hi There";
return DocumentFull.getContent() + "Hi There";
}
//Can do it one function, need to finish input stream reading portion of DOcx4j
System.out.println("File Uploaded");
WordprocessingMLPackage dataUpload = WordprocessingMLPackage.load(ProposalGenerate.getInputStream());
System.out.println("Lazy 1:" + dataUpload);
WordprocessingMLPackage.load(ProposalGenerate.getInputStream());
System.out.println("Lazy 2:" + dataUpload);
MainDocumentPart DocumentFull = dataUpload.getMainDocumentPart();
System.out.println("Document Full" + DocumentFull);
System.out.println("Lazy" + dataUpload);
ProposalGenerate.getOriginalFilename();
System.out.println("Number 1" + ProposalGenerate.getOriginalFilename());
ProposalGenerate.getInputStream();
System.out.println("Number 2" + ProposalGenerate.getInputStream());
//Get the file contents and save it to the console
byte[] bytes = ProposalGenerate.getBytes();
System.out.println("Number 3" + Arrays.toString(bytes));
//Create a new file
File file = new File("C:\\Users\\" + ProposalGenerate.getOriginalFilename());
System.out.println("Number 4" + file);
//Write the file to the file system
// file.createNewFile();
// System.out.println("Number 5" + file);
FileEntity fileEntity = new FileEntity(file);
System.out.println("Number 6" + fileEntity);
ProposalGenerate.getContentType();
ProposalGenerate.getBytes();
System.out.println("Number 7" + Arrays.toString(ProposalGenerate.getBytes()));
//Give What type of Content you want to grab from the docuemtn
String NodePath = "//w:t";
// String NodePath = "//w:p[1]/w:r[1]/w:t[1]";
// Making Tmp Variable for NodePath Routing to Taking Place Upon the Document
// resfresXMLfirst (Does Maybe refesh the XML)
List<Object> SeriesNodes = DocumentFull.getJAXBNodesViaXPath(NodePath, true);
System.out.println("Number 8" + SeriesNodes);
//P.content.get(SeriesNodes);
// Just a Object Declaration, with the Series of Nodes going to be used, with the document given.
for (Object ignored : SeriesNodes) {
// Piece of Garbage Code
Text place = (Text) ((JAXBElement<?>) ignored).getValue();
// Get Value of String (Get Value may be Wrong for getting ParagraphH)
//QUestioning place.getValue(); .getValue();
String placeValue = place.getValue();
// Just a way to show the data can return the object
System.out.println("Index 1:" + placeValue);
}//placevalue
System.out.println("Number 8" + SeriesNodes);
System.out.println("Number 9" + DocumentFull);
System.out.println("Plake Number 10.5" + DocumentFull.getContent());
// System.out.println("Plake Number 10.6" + DocumentFull.getContent().contains(this.getAllElementFromObject(1, P.class)));
// System.out.println("Plake Number 10.6" + DocumentFull.getContent().contains(this.getAllElementFromObject(1, P.class)));
// Really Important: "//w:p";
String NodePathing = "//w:p";
//System.out.println("NEW Runnner Scene: Before Bed Number 22" + DocumentFull.getJAXBNodesViaXPath(NodePathing, P.class, true));
// Pass NodePathing to Object Xpath
// List<Object> SeriesPara = DocumentFull.getJAXBNodesViaXPath(NodePathing, true);
// List<Object> SeriesPara = DocumentFull.getJAXBNodesViaXPath(NodePathing, true);
// List <Object> SerialNodes = Collections.singletonList(DocumentFull.getContent().contains(this.getAllElementFromObject(NodePathing, P.class)));
//Only Reads Text(Paragraph reads only Text, while Text Reads everything)
List<Object> paragraphs = getAllElementFromObject(DocumentFull.getContent(), P.class);
System.out.println("Number 11" + paragraphs);
//Worst Thing: ", ," for new line andd startIndex and endIndex
List <Object> SerialNodes = DocumentFull.getJAXBNodesViaXPath(NodePathing, false);
System.out.println("Number 11" + SerialNodes);
//System.out.println("NEW Runnner Scene: Before Bed Number 22" + DocumentFull.getJAXBNodesViaXPath(NodePathing, P.class, true));
// System.out.println("NEW Runnner Scene: Before Bed Number 22" + DocumentFull.getJAXBNodesViaXPath(1, String.valueOf(P.class), true));
// System.out.println("NEW Runnner Scene: Before Bed Number 22" + DocumentFull.getJAXBNodesViaXPath(String.valueOf(P.class), true));
//System.out.println("NEW Runnner Scene: Before Bed Number 22" + DocumentFull.getJAXBNodesViaXPath(String.valueOf(P.class), false));
// IF statement
System.out.println("Plake Number 11.65" + SerialNodes);
for (Object drake : SerialNodes) {
//if(drake instanceof P) {
// P drakeP = (P) drake;
// System.out.println("Plake Number 11.66" + drakeP);
// }
System.out.println("Plake Number 10.7" + drake);
//P place = P.class.cast(drake);
//Get Paragraph from the Document
P ParaI = (P) drake;
System.out.println("Plake Number 10.8" + ParaI);
System.out.println("Plake Number 10.85" + ParaI.getParaId());
System.out.println("Plake Number 10.9" + ParaI.getTextId());
System.out.println("Plake Number 10.10" + ((P) drake).getContent());
// System.out.println(place);
System.out.println("Plake Number 10.9" + ParaI.getContent());
// System.out.println("Plake Number 10.10" + ParaI.getContent().get(0));
// System.out.println("Plake Number 10.11" + ParaI.getContent().get(0).getClass());
// System.out.println("Plake Number 10.12" + ParaI.getContent().get(0).getClass().getName());
// System.out.println("Plake Number 10.13" + ParaI.getContent().get(0).getClass().getName().equals("org.docx4j.wml.Text"));
String Placer = String.valueOf(ParaI.getPPr().getPStyle().getVal());
System.out.println("Plake Number 10.14" + Placer);
System.out.println("Plake Number 10.15" + Placer.contains("\n"));
String ParaText = Placer.replace("\n", " ");
System.out.println("Plake Number 10.16" + ParaText);
//String testingP = ParaI.getContent().get(0).toString();
// String placeValue = place.getPPr().getPStyle().getVal();
//String placeValue = place.getValue();
String placeValue = ParaI.getParaId();
// String placeValue2 = ParaI.getValue();
System.out.println("ERROR SEEN" + placeValue);
System.out.println("Number 13" + drake);
System.out.println("Number 14" + ParaI);
}//placevalue
System.out.println("Number 12" + SerialNodes);
// System.out.println("Number 8" + SeriesPara);
//DocumentFull.getContent(); //This is the content of the document in the form of a string can pass to the front end
System.out.println("Number 10" + DocumentFull.getContent());
System.out.println("Number 11" + dataUpload);
// PPr pPr = ((P) XmlUtils.unwrap(DocumentFull)).getPPr();
// if (pPr != null) {
// PPrBase.PStyle pStyle = pPr.getPStyle();
// if (pStyle != null) {
// // String style = pStyle.getVal();
// System.out.println("Style: " + style);
// }
// }
// System.out.println("Number 12" + DocumentFull);
// System.out.println("Number 13" + pPr);
// return DocumentFull.getContent() + "Hi There";
return DocumentFull.getContent() + "Hi There";
}
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
LINKS or Any Help would be Appreciated.
If I grab the document, do I need to use the Factory in some manner, is my loading incorrect. I tried using paragraph is org.docx4j.wml.P; a paragraph is basically made up of runs of text.
@XmlRootElement(name = "p")
public class P implements Child, ContentAccessor
But got problems the with xml root, and unsure, how to access the different portions, I tried using the webapp for more data info, but I only know about the three different portions, core, extended and custom.
Listed Below is the Two Document I have been testing with. The Current UI is able to send over any document chosen.