Coverage Report - org.paneris.rimauresq.RimauresqServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
RimauresqServlet
0%
0/49
0%
0/20
3.6
 
 1  
 package org.paneris.rimauresq;
 2  
 
 3  
 import org.melati.Melati;
 4  
 import org.melati.PoemContext;
 5  
 import org.melati.poem.Column;
 6  
 import org.melati.poem.Persistent;
 7  
 import org.melati.poem.Table;
 8  
 import org.melati.servlet.PathInfoException;
 9  
 import org.melati.template.ServletTemplateContext;
 10  
 import org.melati.util.StringUtils;
 11  
 import org.paneris.melati.site.SiteServlet;
 12  
 
 13  
 import org.paneris.rimauresq.model.RimauresqDatabase;
 14  
 
 15  
 /**
 16  
  * @author timp
 17  
  *
 18  
  */
 19  0
 public abstract class RimauresqServlet extends SiteServlet {
 20  
 
 21  
   /** Where to find static content. */
 22  
   private static final String STATIC_ROOT = "/dist/rimauresq/rimauresq-webapp/src/main/webapp/";
 23  
   /** The DB we are using. */
 24  0
   private static String DB_NAME = "rimauresq";
 25  
 
 26  
   /**
 27  
    * @return the root
 28  
    */
 29  
   public String getSTATIC_ROOT() {
 30  0
     return STATIC_ROOT;
 31  
   }
 32  
 
 33  
   /**
 34  
    * @return Returns the dB_NAME.
 35  
    */
 36  
   public String getDB_NAME() {
 37  0
     return DB_NAME;
 38  
   }
 39  
 
 40  
   
 41  
   /**
 42  
    * Fullfill promise from SiteServlet, setup context.
 43  
    * 
 44  
    * @return Template name without path or extension
 45  
    */
 46  
   protected String reallyDoTemplateRequest(Melati melati,
 47  
       ServletTemplateContext templateContext)
 48  
       throws Exception {
 49  0
     templateContext.put("homePage", ((RimauresqDatabase) melati.getDatabase())
 50  
         .getHomePage());
 51  0
     String newsAdminName = getSetting(melati, "NewsAdminName");
 52  0
     String newsAdminEmail = getSetting(melati, "NewsAdminEmail");
 53  0
     templateContext.put("newsAdminName", newsAdminName);
 54  0
     templateContext.put("newsAdminEmail", newsAdminEmail);
 55  0
     return doRimauresqTemplateRequest(melati, templateContext);
 56  
   }
 57  
 
 58  
   protected PoemContext poemContext(Melati melati)
 59  
       throws PathInfoException {
 60  
 
 61  0
     PoemContext it = new PoemContext();
 62  
 
 63  0
     String initParameterPathInfo = getInitParameter("pathinfo");
 64  
     String[] parts;
 65  0
     if (initParameterPathInfo != null) {
 66  0
       parts = StringUtils.split(initParameterPathInfo, '/');
 67  
     } else { 
 68  0
       parts = melati.getPathInfoParts();
 69  
     }
 70  
     // set it to something in order to provoke meaningful error
 71  0
     it.setLogicalDatabase("");
 72  0
     if (parts.length > 0) {
 73  0
       it.setLogicalDatabase(parts[0]);
 74  
       // Display/en/table.html - might be needed
 75  
       // Display/en/ATemplate.html - template that is DB specific
 76  
       // or contains no template specific info at all
 77  0
       if (parts.length == 2)
 78  0
         it.setMethod(parts[1]);
 79  
       // Display/en/page/1.html
 80  
       // Display/en/page/TableSpecificSummaryTemplate.html
 81  
       // Display/en/page/Primary.Search.Criterion.content.html
 82  0
       if (parts.length == 3) {
 83  0
         String r = parts[2];
 84  0
         if (r.lastIndexOf(".htm") != -1) {
 85  0
           r = r.substring(0, r.lastIndexOf(".htm"));
 86  
           // it.method = "html";
 87  
         }
 88  0
         it.setTable(parts[1]);
 89  
         try {
 90  0
           it.setTroid(new Integer(r));
 91  0
         } catch (NumberFormatException e) {
 92  0
           it.setMethod(parts[2]);
 93  0
         }
 94  
         
 95  
       
 96  
       }
 97  
 
 98  
       // Display/en/page/1/SpecialTemplate.html
 99  
       // Display/en/page/Primary.Search.Criterion.content/SpecialTemplate.html
 100  
       // Display/en/page/Primary_Search_Criterion_content/SpecialTemplate.html
 101  
       
 102  0
       if (parts.length == 4) {
 103  0
         it.setTable(parts[1]);
 104  
         try {
 105  0
           it.setTroid(new Integer(parts[2]));
 106  0
         } catch (NumberFormatException e) {
 107  0
           String r = parts[2];
 108  0
           if (r.lastIndexOf(".htm") != -1) {
 109  0
             r = r.substring(0, r.lastIndexOf(".htm"));
 110  
           }
 111  0
           String value = StringUtils.tr(r, '.', ' ');
 112  0
           value = StringUtils.tr(r, '_', ' ');
 113  0
           Table t = melati.getTable();
 114  0
           if (t != null) {
 115  0
             Column c = t.primaryCriterionColumn();
 116  0
             if (c == null)
 117  0
               throw new NullPointerException("primaryCriterionColumn null");
 118  0
             Persistent o = c.firstWhereEq(value);
 119  0
             if (o != null)
 120  0
               it.setTroid(o.troid());
 121  
           }
 122  0
         }
 123  0
         it.setMethod(parts[3]);
 124  
       }
 125  
       /*
 126  
        * if (parts.length > 4) { 
 127  
        * String pathInfo = melati.getRequest().getPathInfo(); 
 128  
        * pathInfo = pathInfo.substring(1);
 129  
        * for (int i = 0; i< 2; i++) { 
 130  
        *   pathInfo = pathInfo.substring(pathInfo.indexOf("/") + 1); 
 131  
        * } 
 132  
        * it.method = pathInfo; 
 133  
        * }
 134  
        */
 135  
     }
 136  0
     return it;
 137  
   }
 138  
 
 139  
   /**
 140  
    * Override this method to build up output in individual servlets.
 141  
    * 
 142  
    * @return Template name without path or extension
 143  
    */
 144  
   protected abstract String doRimauresqTemplateRequest(Melati melati,
 145  
       ServletTemplateContext templateContext)
 146  
       throws Exception;
 147  
 
 148  
 }