1 23 24 package barracudaDiscRack.presentation.discMgmt; 25 26 import barracudaDiscRack.business.person.*; 27 import barracudaDiscRack.business.disc.*; 28 import barracudaDiscRack.presentation.BasePO; 29 import barracudaDiscRack.presentation.DiscRackPresentationException; 30 import com.lutris.appserver.server.httpPresentation.*; 31 import com.lutris.appserver.server.session.*; 32 import com.lutris.util.*; 33 import org.enhydra.xml.xmlc.*; 34 import org.enhydra.xml.xmlc.html.*; 35 import org.enhydra.xml.xmlc.XMLObject; 36 import org.w3c.dom.*; 37 import org.w3c.dom.html.*; 38 39 45 public class DiscCatalog extends BasePO { 46 47 50 public boolean loggedInUserRequired() { 51 return true; 52 } 53 54 60 public XMLObject handleDefault() 61 throws DiscRackPresentationException { 62 64 DiscCatalogHTML page = (DiscCatalogHTML)myComms.xmlcFactory.create(DiscCatalogHTML.class); 65 HTMLScriptElement script = ((DiscCatalogScriptHTML)myComms.xmlcFactory.create(DiscCatalogScriptHTML.class)).getElementRealScript(); 66 XMLCUtil.replaceNode(script, page.getElementDummyScript()); 67 68 try { 69 page.setTextOwner(this.getUser().getFirstname() + " " + 70 this.getUser().getLastname() + "'s Discs"); 71 } catch(Exception ex) { 72 this.writeDebugMsg("Error getting user info: " + ex); 73 } 74 75 String errorMsg = this.getSessionData().getAndClearUserMessage(); 76 if(null == errorMsg) { 77 page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText()); 78 } else { 79 page.setTextErrorText(errorMsg); 80 } 81 82 HTMLTableRowElement templateRow = page.getElementTemplateRow(); 84 HTMLOptionElement templateOption = page.getElementTemplateOption(); 85 Node discTable = templateRow.getParentNode(); 86 Node discSelect = templateOption.getParentNode(); 87 88 templateRow.removeAttribute("id"); 90 templateOption.removeAttribute("id"); 91 92 HTMLElement artistCellTemplate = page.getElementArtist(); 94 HTMLElement titleCellTemplate = page.getElementTitle(); 95 HTMLElement genreCellTemplate = page.getElementGenre(); 96 HTMLElement likeThisDisc = page.getElementLikeThisDisc(); 97 98 artistCellTemplate.removeAttribute("id"); 99 titleCellTemplate.removeAttribute("id"); 100 genreCellTemplate.removeAttribute("id"); 101 likeThisDisc.removeAttribute("id"); 102 103 templateOption.removeChild(templateOption.getFirstChild()); 105 106 try { 107 Disc[] discList = DiscFactory.findDiscsForPerson(this.getUser()); 108 109 for(int numDiscs = 0; numDiscs < discList.length; numDiscs++) { 112 Disc currentDisc = discList[numDiscs]; 113 page.setTextArtist(currentDisc.getArtist()); 115 page.setTextTitle(currentDisc.getTitle()); 116 page.setTextGenre(currentDisc.getGenre()); 117 118 if(currentDisc.isLiked()) { 119 page.setTextLikeThisDisc("Yes"); 120 } else { 121 page.setTextLikeThisDisc("Not"); 122 } 123 124 Node clonedNode = templateRow.cloneNode(true); 126 discTable.appendChild(clonedNode); 127 131 HTMLOptionElement clonedOption = (HTMLOptionElement) templateOption.cloneNode(true); 139 clonedOption.setValue(currentDisc.getHandle()); 140 Node optionTextNode = clonedOption.getOwnerDocument(). 141 createTextNode(currentDisc.getArtist() + ": " + 142 currentDisc.getTitle()); 143 clonedOption.appendChild(optionTextNode); 144 discSelect.appendChild(clonedOption); 147 } 151 } catch(Exception ex) { 152 this.writeDebugMsg("Error populating disc catalog: " + ex); 153 throw new DiscRackPresentationException("Error getting discs for user: ", ex); 154 } 155 156 templateRow.getParentNode().removeChild(templateRow); 159 templateOption.getParentNode().removeChild(templateOption); 160 161 return page; 163 } 164 } 165 166 | Popular Tags |