if(debug)
System.out.println("currentKey="+currentKey+ ' ' +keys);
if(buildDirectly){
PdfObject BDCobj=(PdfObject) dictionaries.get(currentKey);
boolean isBMC=(BDCobj==null);
if(debug)
System.out.println(isBMC+" "+currentKey+ ' ' +BDCobj+" markedContentSequence="+markedContentSequence);
//any custom tags
if(BDCobj!=null){
Map metadata=BDCobj.getOtherDictionaries();
if(metadata!=null){
Iterator customValues=metadata.keySet().iterator();
Object key;
while(customValues.hasNext()){
key=customValues.next();
root.setAttribute(key.toString(), metadata.get(key).toString());
//if(addCoordinates){
root.setAttribute("x1", String.valueOf((int) x1));
root.setAttribute("y1", String.valueOf((int) y1));
root.setAttribute("x2", String.valueOf((int) x2));
root.setAttribute("y2", String.valueOf((int) y2));
//}
}
}
}
//add node with name for BMC
if(isBMC){
if(currentKey!=null){
Node child=doc.createTextNode(stripEscapeChars(markedContentSequence.toString()));
root.appendChild(child);
if(addCoordinates){
root.setAttribute("x1", String.valueOf((int) x1));
root.setAttribute("y1", String.valueOf((int) y1));
root.setAttribute("x2", String.valueOf((int) x2));
root.setAttribute("y2", String.valueOf((int) y2));
}
Node oldRoot=root.getParentNode();
if(oldRoot instanceof Element)
root=(Element) oldRoot;
}
}else{
//get root key on dictionary (should only be 1)
//and create node
//Iterator keys=dict.keySet().iterator();
String S="p";//(String) keys.next();
//System.out.println("dict="+BDCobj.getObjectRefAsString());
if(S==null)
S="p";
Element tag = doc.createElement(S);
root.appendChild(tag);
//now add any attributes
/**
Map atts=(Map) dict.get(S);
if(atts==null)
atts=(Map)dict.get(null);
Iterator attribKeys=atts.keySet().iterator();
while(attribKeys.hasNext()){
String nextAtt=(String) attribKeys.next();
tag.setAttribute(nextAtt,stripEscapeChars(atts.get(nextAtt)));
}
*/
if(addCoordinates){
tag.setAttribute("x1", String.valueOf((int) x1));
tag.setAttribute("y1", String.valueOf((int) y1));
tag.setAttribute("x2", String.valueOf((int) x2));
tag.setAttribute("y2", String.valueOf((int) y2));
}
//add the text
Node child=doc.createTextNode(markedContentSequence.toString());
tag.appendChild(child);
}
//reset
markedContentSequence=new StringBuffer();
}else{
String ContentSequence = markedContentSequence.toString();
/*if(ContentSequence.indexOf("&")!= -1){
ContentSequence = ContentSequence.replaceAll("&","&");
}
if(ContentSequence.indexOf("<")!= -1){
ContentSequence = ContentSequence.replaceAll("<","<");
//System.out.print(">>>>>>>>>>>> Temp =="+ContentSequence);
}
if(ContentSequence.indexOf(">")!= -1){
ContentSequence = ContentSequence.replaceAll(">",">");
}
if(ContentSequence.indexOf("&#")!= -1){
//convert hex numbers to the char value
}*/
//System.out.println(currentKey+" "+markedContentSequence);
if(debug)
System.out.println("write out "+currentKey+" text="+markedContentSequence+ '<');
PdfObject BDCobj=(PdfObject) (dictionaries.get(String.valueOf(markedContentLevel)));
// System.out.println("BDCobj="+BDCobj+" currentKey="+currentKey);
//reset on MCID tag
int MCID=-1;
if(BDCobj!=null)
MCID=BDCobj.getInt(PdfDictionary.MCID);
if(MCID!=-1){
values.put(String.valueOf(MCID),ContentSequence);
//System.out.println(MCID+" "+ContentSequence);
markedContentSequence=new StringBuffer();