1 23 24 package discRack.presentation.discMgmt; 25 26 import discRack.spec.*; 27 import discRack.presentation.BasePO; 28 import discRack.presentation.DiscRackPresentationException; 29 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 43 public class DiscCatalog extends BasePO { 44 45 48 public boolean loggedInUserRequired() { 49 return true; 50 } 51 52 58 public XMLObject handleDefault() 59 throws DiscRackPresentationException { 60 62 DiscCatalogHTML page = (DiscCatalogHTML)myComms.xmlcFactory.create(DiscCatalogHTML.class); 63 HTMLScriptElement script = ((DiscCatalogScriptHTML)myComms.xmlcFactory.create(DiscCatalogScriptHTML.class)).getElementRealScript(); 64 XMLCUtil.replaceNode(script, page.getElementDummyScript()); 66 67 68 73 74 try { 75 76 Disc[] discList = ((DiscGenerator)DiscGeneratorFactory.getDiscGenerator("discRack.business.disc.DiscGeneratorImpl")).findDiscsForPerson(this.getUser()); 77 78 try { 79 page.setTextOwner(this.getUser().getFirstname() + " " + 80 this.getUser().getLastname() + "'s Discs"); 81 } catch(Exception ex) { 82 this.writeDebugMsg("Error getting user info: " + ex); 83 } 84 85 String errorMsg = this.getSessionData().getAndClearUserMessage(); 86 if(null == errorMsg) { 87 page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText()); 88 } else { 89 page.setTextErrorText(errorMsg); 90 } 91 92 93 HTMLTableRowElement templateRow = page.getElementTemplateRow(); 95 HTMLOptionElement templateOption = page.getElementTemplateOption(); 96 Node discTable = templateRow.getParentNode(); 97 Node discSelect = templateOption.getParentNode(); 98 99 100 101 templateRow.removeAttribute("id"); 103 templateOption.removeAttribute("id"); 104 105 HTMLElement artistCellTemplate = page.getElementArtist(); 107 HTMLElement titleCellTemplate = page.getElementTitle(); 108 HTMLElement genreCellTemplate = page.getElementGenre(); 109 HTMLElement likeThisDisc = page.getElementLikeThisDisc(); 110 111 artistCellTemplate.removeAttribute("id"); 112 titleCellTemplate.removeAttribute("id"); 113 genreCellTemplate.removeAttribute("id"); 114 likeThisDisc.removeAttribute("id"); 115 116 templateOption.removeChild(templateOption.getFirstChild()); 118 119 120 121 for(int numDiscs = 0; numDiscs < discList.length; numDiscs++) { 124 Disc currentDisc = discList[numDiscs]; 125 page.setTextArtist(currentDisc.getArtist()); 127 page.setTextTitle(currentDisc.getTitle()); 128 page.setTextGenre(currentDisc.getGenre()); 129 130 if(currentDisc.isLiked()) { 131 page.setTextLikeThisDisc("Yes"); 132 } else { 133 page.setTextLikeThisDisc("Not"); 134 } 135 136 Node clonedNode = templateRow.cloneNode(true); 138 discTable.appendChild(clonedNode); 139 143 HTMLOptionElement clonedOption = (HTMLOptionElement) templateOption.cloneNode(true); 151 clonedOption.setValue(currentDisc.getHandle()); 152 Node optionTextNode = clonedOption.getOwnerDocument(). 153 createTextNode(currentDisc.getArtist() + ": " + 154 currentDisc.getTitle()); 155 clonedOption.appendChild(optionTextNode); 156 discSelect.appendChild(clonedOption); 159 } 163 164 templateRow.getParentNode().removeChild(templateRow); 167 templateOption.getParentNode().removeChild(templateOption); 168 169 }catch(NullPointerException ex){ 170 page.setTextErrorText("This is a default HTML page"); 171 } catch(Exception ex) { 172 this.writeDebugMsg("Error populating disc catalog: " + ex); 173 throw new DiscRackPresentationException("Error getting discs for user: ", ex); 174 } 175 176 177 return page; 179 } 180 } 181 182 | Popular Tags |