arathy nair Newbie Poster

Hi All,

I want to create the following xml from JAVA code. Can u please suggest me a way to write a JAVA code to generate the following xml.When I tried am not able to generate the title with xmlns.Please someone help me..I am very new to XML..... Even if u can provide me a way to generate the first three lines till user will do..Please help........


?xml version="1.0" encoding="UTF-8" ?> 
- <pierRecord xmlns="" xsi:schemaLocation="http://www.mywebsitecom/pier/schema/pier record.xsd" xmlns:xsi="">
- <user>
   <sourceDatabase>My System</sourceDatabase> 
  <accessLevel>General Access</accessLevel> 
  - <languages>
  </languages>?xml version="1.0" encoding="UTF-8" ?> 
- <pierRecord xmlns="" xsi:schemaLocation="http://www.mywebsitecom/pier/schema/pier record.xsd" xmlns:xsi="">
- <user>
   <sourceDatabase>My System</sourceDatabase> 
  <accessLevel>General Access</accessLevel> 
  - <languages>

arathy nair Newbie Poster

Hi all,

I actually need to use a sorted map.So i tried using Tree Map.But the problem is that This works well with sort key having values upto 9. With more than 10 items I see abrupt results with sort key arranged in the order = 1, 10, 11,12,--------17, 2, 3, 4, 5, 6, 7, 8, 9. I even tried using Comparator for this ....But the same way it is sorted...How to make it arrange in the correct order of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11?

Please find my code below

public static TreeMap sortByComparator(TreeMap unsortMap) {

            List list = new LinkedList(unsortMap.entrySet());
            System.out.println("the list value is "+list);

            //sort list based on comparator
        Collections.sort(list, new Comparator() {
              public int compare(Object o1, Object o2) {
                   return ((Comparable) ((Map.Entry) (o2)).getKey())
                   .compareTo(((Map.Entry) (o1)).getKey());

            //put sorted list into map again
        TreeMap sortedMap = new TreeMap();
        for (Iterator it = list.iterator(); it.hasNext();) {
             Map.Entry entry = (Map.Entry);
             sortedMap.put(entry.getKey(), entry.getValue());
        return sortedMap;

arathy nair

try {

            CURRENT_SESSION = new CommonHandlers().connect();

            //query to fetch all the MUI Finding objects based on status type
            IQuery query =(IQuery)CURRENT_SESSION.createObject(IQuery.OBJECT_TYPE,QualityChangeRequestConstants.CLASS_AUDITS_CLASS); 
            String sCriteria = "[Audit.Audit ID] contains ('L2') AND [Audit.Status] Equal To ('$STATUSTYPE.RELEASED') OR [Audit.Status] Equal To ('$STATUSTYPE.COMPLETE')";
            ITable results = query.execute(); 

            // If Result  is obtained iterate through the result table.
              if(results != null && !results.isEmpty()){

                  Iterator objIt = results.iterator();
                  IDataObject auditObj = null;
                  boolean relFlag = false;
                  int relCount = 0;
                   while(objIt.hasNext()) {
                     // load the object
                    auditObj = (IDataObject)((IRow);
                    // System.out.println("printing the audit objects "+auditObj.getAgileClass());
                    IQualityChangeRequest affObj = (IQualityChangeRequest)auditObj;
                     String baseName = affObj.getName();
                     IDataObject baseObject = auditObj;
                     String status =  ( affObj).getStatus().toString();
                     IAgileClass cls = affObj.getAgileClass();
                     String newStatus ="";
                     String strStatus ="";

                     if(cls.toString().equalsIgnoreCase("Audit - Level 2")) {

                         strStatus = RESOURCE_DATA.getString("Status_Audit");

                     StringTokenizer st =new StringTokenizer(strStatus,",");
                         newStatus = st.nextToken();
                             String fndName = null;
                             //Getting the file path and checking whether the directory exists or not
                                String NewFile = FILE+baseObject.getAgileClass()+"\\";
                                String dirName = NewFile + baseName;
                                File dir2 = new File(dirName);
                                 System.out.println("directory exists");
                                 File[] files = dir2.listFiles();
                                 System.out.println("file length :"+files.length);
                                 for(int i =0;i<files.length;i++){
                                     System.out.println("the file name is "+files[i].getName());
                                     //checking if an objectname_error folder exists or not?
                                         System.out.println("Error folder exists");
                                        //if there is no audit error folder checking for its findings
                                //if the directory does not exist before fetching the objects and creating the new folder structure


        } catch (APIException ae) {
            // Catch API Exception if ...

arathy nair Newbie Poster


I am having a code which fetches say 200 records,after 6 records i got an exception..So after my exception is caught in catch block i have 2 call a method which can help continuing the exception starting from the 7th object.
Can anyone help with some piece of code that can help me do this??? Hoping for a favorable response

Arathy Nair

arathy nair Newbie Poster

Hi all,

I have a situation where am using String conditions(say if(name.equalsIgnoreCase(Arathy)).
I want to replace this if-else loop with Switch cases..What way i can do to accomplish this?

arathy nair

[QUOTE=stultuske;1757035]have you googled "add watermark to pdf java" yet?[/QUOTE]
yes i googled

arathy nair Newbie Poster

Hi All,

I have PDFs that are to be watermarked. I need to know whether there exists the below options

1 Option is : Whether we can rewrite the same file with the logo instead of taking the existing pdf and writing this pdf into watermarked file
option2 : Whether we can add the watermark upon creating the file first time itself?

Pleaase do help....

Hoping for a favorable response

Thanks in Advance

arathy nair Newbie Poster

Hi Friends,
I am having a pdf which has to be watermarked.But the code below I use is writing contents of my PDF into another PDf which is being watermarked.Please suggest any ideas which helps me watermark the same pdf without creating a new one.
Please find the code below.

[code]PdfReader Read_PDF_To_Watermark = new PdfReader(RESOURCE_DATA.getString("FILE_PATH"));
int number_of_pages = Read_PDF_To_Watermark.getNumberOfPages();
PdfStamper stamp = new PdfStamper(Read_PDF_To_Watermark, [COLOR="Red"]new FileOutputStream(RESOURCE_DATA.getString("FILE_PATH2")));[/COLOR]
int i = 0;
Image watermark_image = Image.getInstance(RESOURCE_DATA.getString("LOGO"));
watermark_image.setAbsolutePosition(200, 400);
PdfContentByte add_watermark;
while (i < number_of_pages) {
add_watermark = stamp.getUnderContent(i);

arathy nair

Thanks a lot.I got now what u meant.I was able to delete the files after merging. Thank You stultuske

[QUOTE=stultuske;1748095]no, I'm saying whether and how you have a filename stored has nothing to do with whether there (still) is a physical file on your hard drive.[/QUOTE]

arathy nair

but the problem is that am storing these file names in a string.R u telling me to change this and store it in a file

[QUOTE=stultuske;1748087]this has nothing to do with the String objects.
you should check out the delete method of the [URL=""]File[/URL] class.[/QUOTE]

arathy nair

Hi Thanks for your reply.I have tried by assigning string file1 ="";
But its not working.

[QUOTE=47pirates;1748073]you can simply assign null value to the variable string variable = ""; after the data has been merged.[/QUOTE]

arathy nair

Thanks for your reply.What I mean by delting is that I dont want these files in the folder after these files are merged to a single pdf merge12.

[QUOTE=stultuske;1748070]file1 = null;
file2 = null;

what exactly do you mean by 'delete the strings'?[/QUOTE]

arathy nair Newbie Poster

I want to delete the strings file1 and file2 after its merged to a single pdf merge12.
Please suggest your valuable ideas.. Thanks in advance

package com;

import java.util.ArrayList;

import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;

 * author 
 * @282532

public class PdfMerger {
public static void main(String args[]){
    String file1 = "d:\\PR00002.PDF";
    String file2 = "d:\\PR00003.PDF";
    String mergedFileLocation = "d:\\merge12.pdf";

    String filesTobeMerges[] = new String[] { file1, file2 }; 
    mergeMyFiles(filesTobeMerges, mergedFileLocation); 

public static void mergeMyFiles(String filesTobeMerged[],String mergedFileLocation){
    System.out.println("Starting to merge files...");
    System.out.println("total number of files to be merged"+filesTobeMerged.length +"\n");
        int pageOffset = 0;
        ArrayList masterBookMarkList = new ArrayList();

        String outFile = mergedFileLocation; 
        Document document = null; 
        PdfCopy writer = null; 
        PdfReader reader = null;  
        for (int fileIndex = 0; fileIndex< filesTobeMerged.length; fileIndex++) {
            reader = new PdfReader(filesTobeMerged[fileIndex]);
            System.out.println("Reading file" +filesTobeMerged[fileIndex]);

            /** * Replace all the local named links with the actual destinations.
             * *
            int totalPages = reader.getNumberOfPages(); 

            /** * Merging the files to the first file.
             *  * If we are passing file1, file2 and file3, 
             *  * we will merge file2 and file3 to file1.
             *   */
            if (fileIndex == 0) {
                /** * Create the document object from the reader */
                document = new Document(reader.getPageSizeWithRotation(1));

                /** * Create a pdf write that listens to this document.
                 *  * Any changes to this document will be written the file 
                 *  * * outFile is a location where the final merged document * will be written to. */

                System.out.println("Creating ...