1 23 24 package transactionsDiscRack.presentation.discMgmt; 25 26 import transactionsDiscRack.spec.*; 27 import transactionsDiscRack.presentation.BasePO; 28 import transactionsDiscRack.presentation.TransactionsDiscRackPresentationException; 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 TransactionsDiscRackPresentationException { 60 62 DiscCatalogHTML page = (DiscCatalogHTML)myComms.xmlcFactory.create(DiscCatalogHTML.class); 63 64 HTMLScriptElement script = ((DiscCatalogScriptHTML)myComms.xmlcFactory.create(DiscCatalogScriptHTML.class)).getElementRealScript(); 65 XMLCUtil.replaceNode(script, page.getElementDummyScript()); 67 68 73 74 try { 75 76 Disc[] discList = ((DiscGenerator)DiscGeneratorFactory.getDiscGenerator("transactionsDiscRack.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 HTMLTableRowElement templateRow = page.getElementTemplateRow(); 94 HTMLOptionElement templateOption = page.getElementTemplateOption(); 95 Node discTable = templateRow.getParentNode(); 96 Node discSelect = templateOption.getParentNode(); 97 98 templateRow.removeAttribute("id"); 100 templateOption.removeAttribute("id"); 101 102 HTMLElement artistCellTemplate = page.getElementArtist(); 104 HTMLElement titleCellTemplate = page.getElementTitle(); 105 HTMLElement genreCellTemplate = page.getElementGenre(); 106 HTMLElement likeThisDisc = page.getElementLikeThisDisc(); 107 108 artistCellTemplate.removeAttribute("id"); 109 titleCellTemplate.removeAttribute("id"); 110 genreCellTemplate.removeAttribute("id"); 111 likeThisDisc.removeAttribute("id"); 112 113 templateOption.removeChild(templateOption.getFirstChild()); 115 116 117 for(int numDiscs = 0; numDiscs < discList.length; numDiscs++) { 120 Disc currentDisc = discList[numDiscs]; 121 page.setTextArtist(currentDisc.getArtist()); 123 page.setTextTitle(currentDisc.getTitle()); 124 page.setTextGenre(currentDisc.getGenre()); 125 126 if(currentDisc.isLiked()) { 127 page.setTextLikeThisDisc("Yes"); 128 } else { 129 page.setTextLikeThisDisc("Not"); 130 } 131 132 Node clonedNode = templateRow.cloneNode(true); 134 discTable.appendChild(clonedNode); 135 139 HTMLOptionElement clonedOption = (HTMLOptionElement) templateOption.cloneNode(true); 147 clonedOption.setValue(currentDisc.getHandle()); 148 Node optionTextNode = clonedOption.getOwnerDocument(). 149 createTextNode(currentDisc.getArtist() + ": " + 150 currentDisc.getTitle()); 151 clonedOption.appendChild(optionTextNode); 152 discSelect.appendChild(clonedOption); 155 } 159 if (discList.length > 0) 160 discList[0].dbtRelease(); 161 162 templateRow.getParentNode().removeChild(templateRow); 165 templateOption.getParentNode().removeChild(templateOption); 166 167 }catch(NullPointerException ex){ 168 page.setTextErrorText("This is a default HTML page"); 169 } catch(Exception ex) { 170 this.writeDebugMsg("Error populating disc catalog: " + ex); 171 throw new TransactionsDiscRackPresentationException("Error getting discs for user: ", ex); 172 } 173 174 175 176 return page; 178 } 179 } 180 181 | Popular Tags |