1 40 package org.dspace.app.webui.jsptag; 41 42 import java.io.IOException ; 43 import java.util.ArrayList ; 44 import java.util.List ; 45 46 import javax.servlet.RequestDispatcher ; 47 import javax.servlet.ServletConfig ; 48 import javax.servlet.ServletException ; 49 import javax.servlet.ServletRequest ; 50 import javax.servlet.ServletResponse ; 51 import javax.servlet.http.HttpServletResponse ; 52 import javax.servlet.jsp.JspException ; 53 import javax.servlet.jsp.jstl.fmt.LocaleSupport; 54 import javax.servlet.jsp.tagext.TagSupport ; 55 56 import org.apache.log4j.Logger; 57 import org.dspace.content.Collection; 58 import org.dspace.content.Community; 59 import org.dspace.core.ConfigurationManager; 60 import org.dspace.app.webui.servlet.FeedServlet; 61 62 101 public class LayoutTag extends TagSupport 102 { 103 104 private static Logger log = Logger.getLogger(LayoutTag.class); 105 106 107 private String style; 108 109 110 private String title; 111 112 113 private String titleKey; 114 115 116 private String navbar; 117 118 119 private String locbar; 120 121 122 private String parentTitle; 123 124 125 private String parentTitleKey; 126 127 128 private String parentLink; 129 130 131 private String sidebar; 132 133 134 private String noCache; 135 136 137 private String feedData; 138 139 public LayoutTag() 140 { 141 super(); 142 } 143 144 public int doStartTag() throws JspException 145 { 146 ServletRequest request = pageContext.getRequest(); 147 148 String header = "/layout/header-default.jsp"; 150 151 if (style != null) 153 { 154 header = "/layout/header-" + style.toLowerCase() + ".jsp"; 155 } 156 157 if (locbar == null) 159 { 160 locbar = "auto"; 161 } 162 163 List parents = new ArrayList (); 166 List parentLinks = new ArrayList (); 167 168 if (locbar.equalsIgnoreCase("off")) 169 { 170 request.setAttribute("dspace.layout.locbar", new Boolean (false)); 172 } 173 else 174 { 175 parents.add(ConfigurationManager.getProperty("dspace.name")); 177 178 if (locbar.equalsIgnoreCase("nolink")) 179 { 180 parentLinks.add(""); 181 } 182 else 183 { 184 parentLinks.add("/"); 185 } 186 187 if (locbar.equalsIgnoreCase("link")) 189 { 190 if (parentTitle != null) 193 { 194 parents.add(parentTitle); 195 parentLinks.add(parentLink); 196 } 197 else if (parentTitleKey != null) 198 { 199 parents.add(LocaleSupport.getLocalizedMessage(pageContext, 200 parentTitleKey)); 201 parentLinks.add(parentLink); 202 } 203 204 } 205 else if (locbar.equalsIgnoreCase("commLink")) 206 { 207 Community[] comms = (Community[]) request 209 .getAttribute("dspace.communities"); 210 211 if (comms != null) 212 { 213 for (int i = 0; i < comms.length; i++) 214 { 215 parents.add(comms[i].getMetadata("name")); 216 parentLinks.add("/handle/" + comms[i].getHandle()); 217 } 218 } 219 } 220 else if (locbar.equalsIgnoreCase("nolink")) 221 { 222 if (parentTitle != null) 225 { 226 parents.add(parentTitle); 227 parentLinks.add(""); 228 } 229 } 230 else 231 { 232 Collection col = (Collection) request 235 .getAttribute("dspace.collection"); 236 Community[] comms = (Community[]) request 237 .getAttribute("dspace.communities"); 238 239 if (comms != null) 240 { 241 for (int i = 0; i < comms.length; i++) 242 { 243 parents.add(comms[i].getMetadata("name")); 244 parentLinks.add("/handle/" + comms[i].getHandle()); 245 } 246 247 if (col != null) 248 { 249 parents.add(col.getMetadata("name")); 250 parentLinks.add("/handle/" + col.getHandle()); 251 } 252 } 253 } 254 255 request.setAttribute("dspace.layout.locbar", new Boolean (true)); 256 } 257 258 request.setAttribute("dspace.layout.parenttitles", parents); 259 request.setAttribute("dspace.layout.parentlinks", parentLinks); 260 261 if (navbar == null) 263 { 264 navbar = "default"; 265 } 266 267 if (navbar.equals("off")) 268 { 269 request.setAttribute("dspace.layout.navbar", "off"); 270 } 271 else 272 { 273 request.setAttribute("dspace.layout.navbar", "/layout/navbar-" 274 + navbar + ".jsp"); 275 } 276 277 if (title != null) 279 { 280 request.setAttribute("dspace.layout.title", title); 281 } 282 else if (titleKey != null) 283 { 284 request.setAttribute("dspace.layout.title", LocaleSupport 285 .getLocalizedMessage(pageContext, titleKey)); 286 } 287 else 288 { 289 request.setAttribute("dspace.layout.title", "NO TITLE"); 290 } 291 292 if (feedData != null && ! "NONE".equals(feedData)) 294 { 295 boolean commLinks = feedData.startsWith("comm:"); 297 boolean collLinks = feedData.startsWith("coll:"); 298 if ( commLinks ) 299 { 300 Community com = (Community)request.getAttribute("dspace.community"); 301 request.setAttribute("dspace.layout.feedref", com.getHandle()); 302 } 303 else if( collLinks ) 304 { 305 Collection col = (Collection)request.getAttribute("dspace.collection"); 306 request.setAttribute("dspace.layout.feedref", col.getHandle()); 307 } 308 else { 310 request.setAttribute("dspace.layout.feedref", FeedServlet.SITE_FEED_KEY); 311 } 312 313 String [] formats = feedData.substring(feedData.indexOf(":")+1).split(","); 315 List linkParts = new ArrayList (); 316 for (int i = 0; i < formats.length; i++) 318 { 319 if("rss_1.0".equals(formats[i])) 320 { 321 linkParts.add("rdf+xml"); 322 } 323 else 324 { 325 linkParts.add("rss+xml"); 326 } 327 328 if (commLinks) 329 { 330 linkParts.add("Items in Community"); 331 } 332 else if(collLinks) 333 { 334 linkParts.add("Items in Collection"); 335 } 336 else 337 { 338 linkParts.add("Items in " + ConfigurationManager.getProperty("dspace.name")); 339 } 340 341 linkParts.add(formats[i]); 342 } 343 request.setAttribute("dspace.layout.linkparts", linkParts); 344 } 345 else 346 { 347 request.setAttribute("dspace.layout.feedref", "NONE" ); 348 } 349 350 try 352 { 353 HttpServletResponse response = (HttpServletResponse ) pageContext 354 .getResponse(); 355 356 if ((noCache != null) && noCache.equalsIgnoreCase("true")) 358 { 359 response.addDateHeader("expires", 1); 360 response.addHeader("Pragma", "no-cache"); 361 response.addHeader("Cache-control", "no-store"); 362 } 363 364 response.setContentType("text/html; charset=UTF-8"); 367 368 ServletConfig config = pageContext.getServletConfig(); 369 370 RequestDispatcher rd = config.getServletContext() 371 .getRequestDispatcher(header); 372 373 rd.include(request, response); 374 } 375 catch (IOException ioe) 376 { 377 throw new JspException ("Got IOException: " + ioe); 378 } 379 catch (ServletException se) 380 { 381 log.warn("Exception", se.getRootCause()); 382 throw new JspException ("Got ServletException: " + se); 383 } 384 385 return EVAL_BODY_INCLUDE; 386 } 387 388 public int doEndTag() throws JspException 389 { 390 String footer = "/layout/footer-default.jsp"; 392 393 if (style != null) 395 { 396 footer = "/layout/footer-" + style.toLowerCase() + ".jsp"; 397 } 398 399 try 400 { 401 pageContext.getOut().flush(); 403 404 ServletRequest request = pageContext.getRequest(); 406 ServletResponse response = pageContext.getResponse(); 407 ServletConfig config = pageContext.getServletConfig(); 408 409 if (sidebar != null) 410 { 411 request.setAttribute("dspace.layout.sidebar", sidebar); 412 } 413 414 RequestDispatcher rd = config.getServletContext() 415 .getRequestDispatcher(footer); 416 417 rd.include(request, response); 418 } 419 catch (ServletException se) 420 { 421 throw new JspException ("Got ServletException: " + se); 422 } 423 catch (IOException ioe) 424 { 425 throw new JspException ("Got IOException: " + ioe); 426 } 427 428 return EVAL_PAGE; 429 } 430 431 436 public String getTitle() 437 { 438 return title; 439 } 440 441 447 public void setTitle(String v) 448 { 449 this.title = v; 450 } 451 452 455 public String getTitlekey() 456 { 457 return titleKey; 458 } 459 460 463 public void setTitlekey(String titleKey) 464 { 465 this.titleKey = titleKey; 466 } 467 468 473 public String getNavbar() 474 { 475 return navbar; 476 } 477 478 484 public void setNavbar(String v) 485 { 486 this.navbar = v; 487 } 488 489 494 public String getLocbar() 495 { 496 return locbar; 497 } 498 499 505 public void setLocbar(String v) 506 { 507 this.locbar = v; 508 } 509 510 515 public String getParenttitle() 516 { 517 return parentTitle; 518 } 519 520 526 public void setParenttitle(String v) 527 { 528 this.parentTitle = v; 529 } 530 531 536 public String getParenttitlekey() 537 { 538 return parentTitleKey; 539 } 540 541 546 public void setParenttitlekey(String parentTitleKey) 547 { 548 this.parentTitleKey = parentTitleKey; 549 } 550 551 556 public String getParentlink() 557 { 558 return parentLink; 559 } 560 561 567 public void setParentlink(String v) 568 { 569 this.parentLink = v; 570 } 571 572 577 public String getStyle() 578 { 579 return style; 580 } 581 582 588 public void setStyle(String v) 589 { 590 this.style = v; 591 } 592 593 598 public String getSidebar() 599 { 600 return sidebar; 601 } 602 603 609 public void setSidebar(String v) 610 { 611 this.sidebar = v; 612 } 613 614 619 public String getNocache() 620 { 621 return noCache; 622 } 623 624 630 public void setNocache(String v) 631 { 632 this.noCache = v; 633 } 634 635 640 public String getFeedData() 641 { 642 return feedData; 643 } 644 645 651 public void setFeedData(String v) 652 { 653 this.feedData = v; 654 } 655 656 public void release() 657 { 658 style = null; 659 title = null; 660 sidebar = null; 661 navbar = null; 662 locbar = null; 663 parentTitle = null; 664 parentLink = null; 665 noCache = null; 666 feedData = null; 667 } 668 } 669 | Popular Tags |