Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: Java  |  size: 3.20 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.                 XMLDocument newdoc = new XMLDocument(createDocument(),"");             
  2.                 //if there are more than one schedule nodes
  3.                 Node previousSchedule = null;
  4.                
  5. //              HashMap<String,Node> schedules = new HashMap<String,Node>();
  6.                
  7.                 for(int i = 0; i < telecasts.size(); i++) {
  8.                        
  9.                         //check size of references
  10.                         ArrayList<String> inforefs = telecasts.get(i).getInformationDocumentReferences();
  11.                         ArrayList<String> locrefs = telecasts.get(i).getLocationDocumentReferences();
  12.                        
  13.                         //just if both lists aren't empty we can extract data out of locationtable
  14.                         //and extract the programinformation out of the informationtable
  15.                         if(inforefs.size() != 0 && locrefs.size() != 0) {
  16.                                                                
  17.                                 //initialize root and parent nodes
  18.                                 if(newdoc.getRoot() == null) {
  19.                                         newdoc.initializeNodes(false, true, false);
  20.                                 }                      
  21.                                
  22.                                 //for all location references - normally 1
  23.                                 for(int j = 0; j < locrefs.size(); j++) {
  24.                                        
  25.                                         //get location document
  26.                                         XMLDocument doc = memory.getDocument(locrefs.get(j));
  27.                                         //get the scheduleevent for this telecast and the parent schedule for that node
  28.                                         Node scheduleEvent = doc.getXPathExpression("//ScheduleEvent[Program/@crid=\""+telecasts.get(i).getCrid()+"\"]").item(0);
  29.                                         Node schedule = doc.getXPathExpression("//ScheduleEvent[Program/@crid=\""+telecasts.get(i).getCrid()+"\"]/..").item(0);
  30.                                        
  31.                                         //import it and create a new schedule (otherwise it stores scheduleevents two times)
  32.                                         Node cloneScheduleEvent = newdoc.getDocument().importNode(scheduleEvent, true);
  33.                                         Element cloneSchedule = newdoc.getDocument().createElement("Schedule");
  34.                                         //add attributes
  35. //                                      String key ="";
  36.                                         for(int x = 0; x < schedule.getAttributes().getLength(); x++) {
  37.                                                 cloneSchedule.setAttribute(schedule.getAttributes().item(x).getNodeName(), schedule.getAttributes().item(x).getTextContent());
  38. //                                              key += schedule.getAttributes().item(x).getTextContent();
  39.                                         }
  40. //                                      schedules.put(key, cloneSchedule);
  41.                                        
  42.                                         //set programurl to scheduleEvent
  43.                                         for(int k = 0; k < cloneScheduleEvent.getChildNodes().getLength(); k++) {
  44.                                                 if(cloneScheduleEvent.getChildNodes().item(k).getNodeName().equals("ProgramURL")) {
  45.                                                         cloneScheduleEvent.getChildNodes().item(k).setTextContent(telecasts.get(i).getProgramURL_to_telecast());
  46.                                                         break;
  47.                                                 }
  48.                                         }
  49.                                         //initialize
  50.                                         if(previousSchedule == null)
  51.                                                 previousSchedule = cloneSchedule;
  52.                                                                                
  53.                                         //if a new schedule node occurs, append the old one to the table
  54.                                         //set the new one
  55.                                         if(! ( ((Element)cloneSchedule).getAttribute("serviceIDRef").equals(((Element)previousSchedule).getAttribute("serviceIDRef")) ) ) {
  56.  
  57.                                                 newdoc.appendChild("loc",previousSchedule);                                            
  58.                                                 previousSchedule = cloneSchedule;
  59.                                         }
  60.                                        
  61.                                         previousSchedule.appendChild(cloneScheduleEvent);
  62.                                 }
  63.                         }
  64.                         //else don't add it to list
  65.                 }
  66.                 if(newdoc.getRoot() != null) {
  67.                         newdoc.appendChild("loc",previousSchedule);
  68.                         newdoc.appendChild("root",null);
  69.                         String ret = newdoc.getXMLContent();
  70.                         return Response.status(200).entity(ret).build();
  71.                 }
  72.                 else
  73.                         return new ResponsePage("Sorry maybe there is no programinformation available, or no dates were found.",true).buildResponse(404);
  74.         }