Click here to Skip to main content
15,917,176 members
Home / Discussions / Java
   

Java

 
QuestionHow to mark the user inputted value by some shapes in Java? Pin
Member 1343755829-Sep-17 9:05
Member 1343755829-Sep-17 9:05 
AnswerRe: How to mark the user inputted value by some shapes in Java? Pin
jschell2-Oct-17 11:40
jschell2-Oct-17 11:40 
Questionjava Pin
Member 1343015225-Sep-17 22:16
Member 1343015225-Sep-17 22:16 
AnswerRe: java Pin
jschell27-Sep-17 9:26
jschell27-Sep-17 9:26 
QuestionWav file problems Pin
Member 1340872613-Sep-17 14:21
Member 1340872613-Sep-17 14:21 
AnswerRe: Wav file problems Pin
Richard MacCutchan13-Sep-17 19:11
mveRichard MacCutchan13-Sep-17 19:11 
AnswerRe: Wav file problems Pin
jschell26-Sep-17 8:18
jschell26-Sep-17 8:18 
QuestionHello India 123 Pin
daves312-Sep-17 4:55
daves312-Sep-17 4:55 
AnswerRe: Hello India 123 Pin
jschell12-Sep-17 6:09
jschell12-Sep-17 6:09 
QuestionSingly Linked List Pin
kinderu12-Sep-17 2:58
kinderu12-Sep-17 2:58 
AnswerRe: Singly Linked List Pin
Richard MacCutchan12-Sep-17 5:07
mveRichard MacCutchan12-Sep-17 5:07 
GeneralRe: Singly Linked List Pin
kinderu12-Sep-17 5:13
kinderu12-Sep-17 5:13 
GeneralRe: Singly Linked List Pin
Richard MacCutchan12-Sep-17 5:37
mveRichard MacCutchan12-Sep-17 5:37 
GeneralRe: Singly Linked List Pin
Richard Deeming12-Sep-17 6:12
mveRichard Deeming12-Sep-17 6:12 
Questionfinger print Pin
Member 1314044319-Aug-17 1:45
Member 1314044319-Aug-17 1:45 
AnswerRe: finger print Pin
jschell21-Aug-17 5:43
jschell21-Aug-17 5:43 
AnswerRe: finger print Pin
Patrice T25-Aug-17 19:26
mvePatrice T25-Aug-17 19:26 
Generaljava Pin
Member 1336471716-Aug-17 19:34
Member 1336471716-Aug-17 19:34 
GeneralRe: java Pin
Richard MacCutchan16-Aug-17 21:17
mveRichard MacCutchan16-Aug-17 21:17 
GeneralRe: java Pin
Patrice T23-Aug-17 16:19
mvePatrice T23-Aug-17 16:19 
QuestionHow to Connect Fingerprint Reader To Java Program Pin
Kistlak12-Aug-17 10:34
Kistlak12-Aug-17 10:34 
AnswerRe: How to Connect Fingerprint Reader To Java Program Pin
Richard MacCutchan12-Aug-17 20:50
mveRichard MacCutchan12-Aug-17 20:50 
SuggestionRe: How to Connect Fingerprint Reader To Java Program Pin
Richard Deeming13-Aug-17 23:42
mveRichard Deeming13-Aug-17 23:42 
GeneralRe: How to Connect Fingerprint Reader To Java Program Pin
Kistlak14-Aug-17 21:28
Kistlak14-Aug-17 21:28 
QuestionReplace placeholders with HTML text in dotx file using docx4 Pin
Sandeep Reddy9-Aug-17 0:08
Sandeep Reddy9-Aug-17 0:08 
I am working on dotx file template to generate word documents using docx4j in java. I will be replacing some placeholders in dotx file with text which comes from database columns. But problem is one of my database field contains HTML code(rich text editor value), when I place this text in placeholder in template, generated document display as-is content of html. I want that HTML code to be rendered to be proper text with styles.
Cold you please let me know how can I achieve this?

Sample Code which I have written to replace placeholders:

ByteArrayOutputStream baos = null;
      DataRequestVO dataRequest = null;
      WordprocessingMLPackage wordMLPackageMain = null;
      try {
         dataRequest = reportDAO.fetchDocketData(dataRequestNO);

         String templateFile = dataRequest.getReportType().getTemplatePath();
         String fileName = dataRequest.getDocketNo() + " - " + dataRequest.getDataRequestNo() + "-" + dataRequest.getReportType().getReportName();

         URL url = this.getClass().getClassLoader().getResource(templateFile);

         String templateFilePath = url.toURI().getPath();
         WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(url.toURI().getPath()));

         ContentTypeManager ctm = wordMLPackage.getContentTypeManager();

         CTOverride override = ctm.getOverrideContentType().get(new URI("/word/document.xml"));
         if (templateFilePath.endsWith("dotm")) {
            override.setContentType(
                  org.docx4j.openpackaging.contenttype.ContentTypes.WORDPROCESSINGML_DOCUMENT_MACROENABLED);
         } else {
            override.setContentType(org.docx4j.openpackaging.contenttype.ContentTypes.WORDPROCESSINGML_DOCUMENT);
         }

         // Now save it
         DocketReportHelper.prepare(wordMLPackage);

         List<Object> texts = DocketReportHelper.getAllElementFromObject(wordMLPackage.getMainDocumentPart(),
               Text.class);

         DocketReportHelper.replacePlaceholder(texts, dataRequest.getDocketNo(), PLACEHOLDER_DOCKET_NO);
         
         DocketReportHelper.replacePlaceholder(texts, dataRequest.getQuestion(), PLACEHOLDER_QUESTION); //html code text
         DocketReportHelper.replacePlaceholder(texts, dataRequest.getResponse(), PLACEHOLDER_RESPONSE); //html code text
         

         // Confidential Reports
         if ("yes".equalsIgnoreCase(dataRequest.getConfidential())) {

            // Get Confidential Header Footer template
            wordMLPackageMain = createConfHeaderFooter();
            List<Object> listParamMain = wordMLPackage.getMainDocumentPart().getContent();
            for (Object param : listParamMain) {
               if (param instanceof P) {
                  wordMLPackageMain.getMainDocumentPart().addObject((P) param);
               } else if(param instanceof JAXBElement) {
                  wordMLPackageMain.getMainDocumentPart().addObject((JAXBElement) param);
               }
            }
         } else {
            wordMLPackageMain = wordMLPackage;
         }


         baos = new ByteArrayOutputStream();
         SaveToZipFile saver = new SaveToZipFile(wordMLPackageMain);
         saver.save(baos);


replacePlaceholder method:

static void replacePlaceholder(List<Object> texts, String name, String placeholder) {
      log.debug("placeholder : " + placeholder);
      for (Object text : texts) {
         Text textElement = (Text) text;
         if (textElement != null && placeholder.equals(textElement.getValue())) {
            textElement.setValue(name);
            break;
         }
      }
   }


Prepare method:
public static void prepare(WordprocessingMLPackage wmlPackage) throws Exception {
      // Apply the filter
      WordprocessingMLPackage.FilterSettings filterSettings = new WordprocessingMLPackage.FilterSettings();
      filterSettings.setRemoveProofErrors(true);
      filterSettings.setRemoveContentControls(true);
      filterSettings.setRemoveRsids(true);
      wmlPackage.filter(filterSettings);

      log.debug(XmlUtils.marshaltoString(wmlPackage.getMainDocumentPart().getJaxbElement(), true, true));

      // Now clean up some more
      org.docx4j.wml.Document wmlDocumentEl = wmlPackage.getMainDocumentPart().getJaxbElement();
      Body body = wmlDocumentEl.getBody();

      SingleTraversalUtilVisitorCallback paragraphVisitor = new SingleTraversalUtilVisitorCallback(
            new TraversalUtilParagraphVisitor());
      paragraphVisitor.walkJAXBElements(body);

      log.debug(XmlUtils.marshaltoString(wmlPackage.getMainDocumentPart().getJaxbElement(), true, true));
   }

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.