1 package com.genimen.djeneric.web.renderers; 2 3 import java.util.Iterator ; 4 import java.util.TreeMap ; 5 6 import javax.xml.parsers.FactoryConfigurationError ; 7 import javax.xml.parsers.ParserConfigurationException ; 8 9 import org.w3c.dom.Document ; 10 import org.w3c.dom.Element ; 11 12 import com.genimen.djeneric.language.Messages; 13 import com.genimen.djeneric.repository.DjUid; 14 15 public class ImportRenderer extends AbstractRenderer 16 { 17 public static int _uidcounter = 1; 18 19 public ImportRenderer() 20 { 21 } 22 23 public Document asXml() throws FactoryConfigurationError , ParserConfigurationException 24 { 25 Document doc = createDocument(); 26 Element importelem = doc.createElement("import"); 27 importelem.setAttribute("id", "imp."+ String.valueOf(_uidcounter++)); 28 doc.appendChild(importelem); 29 30 return doc; 31 } 32 33 public Document asXml(TreeMap result) throws FactoryConfigurationError , ParserConfigurationException 34 { 35 Document doc = createDocument(); 36 Element importelem = doc.createElement("import"); 37 importelem.setAttribute("id", "imp."+ String.valueOf(_uidcounter++)); 38 doc.appendChild(importelem); 39 40 Iterator it = result.keySet().iterator(); 41 while (it.hasNext()) 42 { 43 Element file = doc.createElement("file"); 44 importelem.appendChild(file); 45 String fileName = (String ) it.next(); 46 file.setAttribute("name", fileName); 47 DjUid[] unresolved = (DjUid[]) result.get(fileName); 48 49 for (int i = 0; i < unresolved.length; i++) 50 { 51 file.appendChild(createUnresolvedElement(doc, unresolved[i])); 52 } 53 54 if (unresolved.length == 0) 55 { 56 file.setAttribute("message", Messages.getString("ObjectImporter.completed")); 57 file.setAttribute("successful", "true"); 58 } 59 else 60 { 61 file.setAttribute("message", Messages.getString("ObjectImporter.completed")); 62 file.setAttribute("successful", "false"); 63 } 64 } 65 66 return doc; 67 } 68 69 protected Element createUnresolvedElement(Document doc, DjUid uid) 70 { 71 Element unresolved = doc.createElement("unresolved"); 72 73 unresolved.setAttribute("id", String.valueOf(uid.getAssociatedObjectid())); 74 unresolved.setAttribute("extent", uid.getExtent().getName()); 75 unresolved.setAttribute("typename", uid.getExtent().getNameSingular()); 76 unresolved.setAttribute("descriptor", uid.getDescriptor()); 77 78 return unresolved; 79 } 80 } 81 | Popular Tags |