Changeset 660 for Core


Ignore:
Timestamp:
02/07/12 09:59:36 (3 months ago)
Author:
niko
Message:

change to maven project

Location:
Core/trunk/src/main/java/corinis
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Core/trunk/src/main/java/corinis/modules/DynamicFields.java

    r563 r660  
    1919 
    2020public class DynamicFields extends EntryManipulate { 
    21      
    22     /** 
    23     * A basic String with a maximum length 255. 
    24     */ 
    25     public final static int TYPE_STRING = 0; 
    26     /** 
    27     * A signed number without comma. 
    28     */ 
    29     public final static int TYPE_INT = 1; 
    30     /** 
    31     * A signed number with comma. 
    32     */ 
    33     public final static int TYPE_NUMBER = 2; 
    34     /** 
    35     * A signed number with two decimal places. 
    36     */ 
    37     public final static int TYPE_TWODEC = 3; 
    38     /** 
    39     * A Date. 
    40     */ 
    41     public final static int TYPE_DATE = 4; 
    42     /** 
    43     * A Date+Time. 
    44     */ 
    45     public final static int TYPE_DATETIME = 5; 
    46     /** 
    47     * A Time. 
    48     */ 
    49     public final static int TYPE_TIME = 6; 
    50     /** 
    51     * Any File. 
    52     */ 
    53     public final static int TYPE_FILE = 7; 
    54     /** 
    55     * An image (png, gif, jpg, bmp, etc) 
    56     * Images will be resized. 
    57     */ 
    58     public final static int TYPE_IMAGE = 8; 
    59     /** 
    60     * A PDF File. 
    61     */ 
    62     public final static int TYPE_PDF = 9; 
    63     /** 
    64     * Any Document: core.getDoc(), pdf, etc. 
    65     */ 
    66     public final static int TYPE_DOC = 10; 
    67      
    68     /** 
    69     * The data View saves the actual data. 
    70     */ 
    71     private DynamicFieldDataView dataView; 
    72      
    73     /** 
    74     * The defView stores the definition of the field. 
    75     * <br> (f.e. type, name, module) 
    76     */ 
    77     public DynamicFieldDefinitionsView defView; 
    78      
    79     /** 
    80     * Stores the relation between definitions and (Main-)Entries in another module. 
    81     */ 
    82     private DynamicFieldRelationView relView; 
    83      
    84     public DynamicFields(Core core) { 
    85         super(core,"CorePro"); 
    86     } 
    87      
    88     /* (non-Javacore.getDoc()) 
    89     * @see corinis.modules.abstracts.Module#init(org.w3c.dom.Node) 
    90     */ 
    91     protected void init(Node config) { 
    92         defView = new DynamicFieldDefinitionsView(core); 
    93         relView = new DynamicFieldRelationView(core); 
    94         dataView = new DynamicFieldDataView(core); 
    95         dataViews.add(dataView); 
    96         dataViews.add(defView); 
    97         dataViews.add(relView); 
    98          
    99         moduleName = "DynamicFields"; 
    100     } 
    101      
    102          
    103      
    104     /** 
    105     * Return DOM: </br> 
    106     * <pre> 
    107     * &lt;MAINENTRY&gt; 
    108     *   &lt;ID&gt;Id of the entry&lt;/ID&gt; 
    109     *   &lt;NAME&gt;Name of the definition&lt;/NAME&gt; 
    110     *   &lt;DESCRIPTION&gt;The discription of the Field&lt;/SHORTNAME&gt; 
    111     *   &lt;DATATYPE&gt;The datatype for this field&lt;/DATATYPE&gt; 
    112     *   &lt;MODULE&gt;The module this field is connected to&lt;/MODULE&gt; 
    113     * &lt;/MAINENTRY&gt; 
    114     * </pre> 
    115     * @param cur the result from a database query 
    116     * @return the above tree 
    117     */ 
    118     private Element getMainEntryTree(Element cur) { 
    119         Element sub = core.getDoc().createElement("MAINENTRY"); 
    120         sub.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",DomUtil.getResultString(cur,"ID"))); 
    121         sub.appendChild(DomUtil.CreateNode(core.getDoc(),"NAME",DomUtil.getResultString(cur,"NAME"))); 
    122         sub.appendChild(DomUtil.CreateNode(core.getDoc(),"DESCRIPTION", DomUtil.getResultString(cur,"DESCRIPTION"))); 
    123         sub.appendChild(DomUtil.CreateNode(core.getDoc(),"DATATYPE", DomUtil.getResultString(cur, "DATATYPE"))); 
    124         sub.appendChild(DomUtil.CreateNode(core.getDoc(),"MODULE", DomUtil.getResultString(cur,"MODULE"))); 
    125         return sub; 
    126     } 
    127  
    128  
    129      
    130      
    131     /** 
    132     * Creates an an Entry. 
    133     * Within DynamicFields an Entry consists in the definition of the field, including it's module. 
    134     * @return standard return tree. 
    135     */ 
    136     public Element createMainEntry() { 
    137         if (!defView.createMainEntry)  
    138             return null; 
    139          
    140         String[] parameter = {"name", "module"}; 
    141         ArrayList<String> al = defView.generateVariableResponseTree(parameter); 
    142          
    143         if (al != null) 
    144             return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
    145          
    146         try { 
    147                 // see if a NAME/MODULE combination already exists 
    148                 Element where = core.getDoc().createElement("WHERE"); 
    149                 where.appendChild(DomUtil.CreateNode(core.getDoc(),"NAME",defView.name)); 
    150                 where.appendChild(DomUtil.CreateNode(core.getDoc(),"MODULE",defView.module)); 
    151                 if (defView.selectEntry(where, pool) != null) { 
    152                         return eventer.nosuccess(Eventer.ENTRY_ALREADY_EXISTS); 
    153          } 
    154  
    155                 Element insert = core.getDoc().createElement("INSERT"); 
    156             insert.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",conf.getId())); 
    157             insert.appendChild(DomUtil.CreateNode(core.getDoc(),"NAME",defView.name)); 
    158             insert.appendChild(DomUtil.CreateNode(core.getDoc(),"DATATYPE",defView.datatype)); 
    159             insert.appendChild(DomUtil.CreateNode(core.getDoc(),"DESCRIPTION",defView.description)); 
    160             insert.appendChild(DomUtil.CreateNode(core.getDoc(),"MODULE",defView.module)); 
    161              
    162             defView.startChange(this); 
    163             defView.createEntry(pool,insert); 
    164             defView.commitChange(this); 
    165         } catch (Exception e) { 
    166             eventer.fatalError(e.getMessage()); 
    167             e.printStackTrace(); 
    168             defView.rollbackChange(this); 
    169         } 
    170         return eventer.success(); 
    171     } 
    172      
    173      
    174     /** 
    175     * Creates a relation between a dynmic field of a module and a foreign id 
    176     * @return success or nosuccess 
    177     */ 
    178     public Element createEntry() { 
    179         if (!defView.createEntry)  
    180             return null; 
    181          
    182         String[] parameter = {"foreignId", "mainId"}; 
    183         ArrayList<String> al = defView.generateVariableResponseTree(parameter); 
    184         if (al != null)  
    185             return eventer.nosuccess(Eventer.FIELD_MISSING,al); 
    186          
    187         try { 
    188             // first check if the current relation has already been created 
    189             Element select = core.getDoc().createElement("SELECT"); 
    190             Element wheres = core.getDoc().createElement("WHERE"); 
    191             wheres.appendChild(DomUtil.CreateNode(core.getDoc(),"FIELDID",defView.mainId)); 
    192             wheres.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID",defView.foreignMainId)); 
    193             select.appendChild(wheres); 
    194             Element results = relView.selectEntriesWhereClause(pool,select); 
    195              
    196             if (results == null) {  
    197                 // can only be inserted if relation doesn't exist 
    198                 Element insert = core.getDoc().createElement("INSERT"); 
    199                 insert.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",conf.getId())); 
    200                 insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FIELDID",defView.mainId)); 
    201                 insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID",defView.foreignMainId)); 
    202                 relView.createEntry(pool,insert); 
    203             } 
    204             else 
    205                 return eventer.nosuccess(Eventer.ENTRY_ALREADY_EXISTS, String.valueOf(defView.mainId)); 
    206              
    207         } catch (Exception e) { 
    208             eventer.fatalError(e.getMessage()); 
    209             e.printStackTrace(); 
    210         } 
    211         return eventer.success(); 
    212     } 
    213  
    214     /** 
    215     * Recreates relations between a dynmic field of a module and a foreign id 
    216     * @return success or nosuccess 
    217     */ 
    218     public Element recreateEntries() { 
    219         if (!defView.createEntry)  
    220             return null; 
    221          
    222         String[] parameter = {"foreignMainId", "mainIds"}; 
    223         ArrayList<String> al = defView.generateVariableResponseTree(parameter); 
    224         if (al != null)  
    225             return eventer.nosuccess(Eventer.FIELD_MISSING,al); 
    226          
    227         try { 
    228             // first delete all current Relations 
    229             Element delete = core.getDoc().createElement("DELETE"); 
    230             delete.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID",defView.foreignMainId)); 
    231             relView.deleteEntry(pool, delete); 
    232              
    233             for (int i = 0; i < defView.mainIds.length; i++) 
    234                 if (defView.mainIds[i] != null) 
    235                 { 
    236                         // can only be inserted if relation doesn't exist 
    237                         Element insert = core.getDoc().createElement("INSERT"); 
    238                         insert.appendChild(DomUtil.CreateNode(core.getDoc(), "ID", conf.getId())); 
    239                         insert.appendChild(DomUtil.CreateNode(core.getDoc(), "FIELDID", defView.mainIds[i])); 
    240                         insert.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", defView.foreignMainId)); 
    241                         relView.createEntry(pool,insert); 
    242                 } 
    243         } catch (Exception e) { 
    244             eventer.fatalError(e.getMessage()); 
    245             e.printStackTrace(); 
    246         } 
    247         return eventer.success(); 
    248     }     
    249      
    250      
    251      
    252     public Element deleteMainEntry() { 
    253         if (!defView.deleteMainEntry)  
    254                 return null; 
    255          
    256         String[] parameter = {"mainId"}; 
    257         ArrayList<String> al = defView.generateVariableResponseTree(parameter); 
    258         if (al!=null)    
    259                 return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
    260          
    261         try { 
    262             //first delete the definition itself 
    263             Element delete = core.getDoc().createElement("DELETE"); 
    264             delete.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",defView.mainId)); 
    265             defView.deleteEntry(pool,delete); 
    266              
    267             // then delete the relation 
    268             delete = core.getDoc().createElement("DELETE"); 
    269             delete.appendChild(DomUtil.CreateNode(core.getDoc(),"FIELDID",defView.mainId)); 
    270             relView.deleteEntry(pool,delete); 
    271              
    272             // and the the data 
    273             dataView.deleteEntry(pool,delete); 
    274                  
    275         } catch (Exception e) { 
    276             eventer.fatalError(e.getMessage()); 
    277             e.printStackTrace(); 
    278         } 
    279         return eventer.success(); 
    280     } 
    281      
    282      
    283     /** 
    284     * Should be called if an entry is assigned to another MainEntry. So new Data will be 
    285     * created which are masked with the relations of the MainEntry. 
    286     * If this Data already exists, only the maskid will be added 
    287     * @return successtree 
    288     */ 
    289     public Element addDataToRelation() { 
    290         String[] parameter = {"moduleName", "foreignMainId"}; 
    291         ArrayList<String> al = relView.generateVariableResponseTree(parameter); 
    292         if (al != null) 
    293             return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
    294         String[] parameter1 = {"foreignId"}; 
    295         al = dataView.generateVariableResponseTree(parameter1); 
    296         if (al!=null) 
    297             return eventer.nosuccess(Eventer.FIELD_MISSING,al); 
    298         try { 
    299             // First get the mask_ids 
    300             Element select = core.getDoc().createElement("SELECT"); 
    301             Element wheres = core.getDoc().createElement("WHERE"); 
    302             wheres.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNMAINID",defView.foreignMainId)); 
    303             select.appendChild(wheres); 
    304             Element results = relView.selectEntriesWhereClause(pool,select); 
    305  
    306             for (Element cur : new ChildElementAdapter(results)) 
    307             { 
    308                 long definition = DomUtil.getResultLong(cur, "ITEMID"); 
    309  
    310                 // otherwise the relation AND a field has to be created 
    311  
    312                 // add the field 
    313                 long dataid = conf.getId(); 
    314                 Element insert = core.getDoc().createElement("INSERT"); 
    315                 insert.appendChild(DomUtil.CreateNode(core.getDoc(), "ID", dataid)); 
    316                 insert.appendChild(DomUtil.CreateNode(core.getDoc(), "ITEMID", definition)); 
    317                 insert.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", defView.foreignMainId)); 
    318                 insert.appendChild(DomUtil.CreateNode(core.getDoc(), "VALUE", "")); 
    319                 dataView.startChange(this); 
    320                 dataView.createEntry(pool, insert); 
    321                 dataView.commitChange(this); 
    322  
    323  
    324             } 
    325  
    326         }   catch (Exception e) { 
    327             eventer.fatalError(e.getMessage()); 
    328             e.printStackTrace(); 
    329         } 
    330         return eventer.success(); 
    331     } 
    332      
    333      
    334     /** 
    335     * @return all foreign id's to given mainentry  
    336     */ 
    337     public Element getEntries () { 
    338  
    339         // check request parameter 
    340         String[] parameter = {"mainId"}; 
    341         ArrayList<String> al = defView.generateVariableResponseTree(parameter); 
    342         if (al != null)  
    343             return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
    344  
    345         Element root = getMainEntry(); 
    346         Element results; 
    347         Element iroot = core.getDoc().createElement("SELECT"); 
    348         // filter ónly by module if we do have a given module 
    349         Element wheres = core.getDoc().createElement("WHERE"); 
    350         wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FIELDID", defView.mainId)); 
    351         iroot.appendChild(wheres); 
    352          
    353         results = relView.selectEntriesWhereClause(pool, iroot); 
    354         for (Element cur : new ChildElementAdapter(results)) 
    355                 root.appendChild(DomUtil.createDuplicateNode(core.getDoc(), "FOREIGNID", cur)); 
    356          
    357         return root; 
    358     } 
    359      
    360     // gets the definition & possible data of an Entry  
    361     protected Element getEntryData() 
    362     { 
    363         Element root = core.getDoc().createElement("ENTRY"); 
    364         Element iroot = core.getDoc().createElement("SELECT"); 
    365         // filter ónly by module if we do have a given module 
    366         Element wheres = core.getDoc().createElement("WHERE"); 
    367         wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "ID", defView.id)); 
    368         iroot.appendChild(wheres); 
    369                 
    370         Element results = defView.selectEntriesWhereClause(pool, iroot); 
    371         for (Element cur : new ChildElementAdapter(results)) 
    372         { 
    373           root.appendChild(DomUtil.CreateNode(core.getDoc(), "ID", DomUtil.getResultLong(cur, "id"))); 
    374           root.appendChild(DomUtil.CreateNode(core.getDoc(), "NAME", DomUtil.getResultString(cur, "name"))); 
    375           root.appendChild(DomUtil.CreateNode(core.getDoc(), "DESCRIPTION", DomUtil.getResultString(cur, "description"))); 
    376           root.appendChild(DomUtil.CreateNode(core.getDoc(), "DATATYPE", DomUtil.getResultLong(cur, "datatype")));               
    377         } 
    378          
    379         // data 
    380         if (defView.foreignId > 0) 
    381         { 
    382                 iroot = core.getDoc().createElement("SELECT"); 
    383             // filter ónly by module if we do have a given module 
    384             wheres = core.getDoc().createElement("WHERE"); 
    385             wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FIELDID", defView.id)); 
    386             wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", defView.foreignId)); 
    387             iroot.appendChild(wheres); 
    388                     
    389             results = dataView.selectEntriesWhereClause(pool, iroot); 
    390             if (results != null) 
    391             { 
    392                 Element cur = (Element)results.getFirstChild(); 
    393                 root.appendChild(DomUtil.CreateNode(core.getDoc(), "VALUE",DomUtil.getResultString(cur, "value")));                 
    394             } 
    395         } 
    396          
    397         return root; 
    398     } 
    399      
    400      
    401      
    402   /** 
    403   * gets a mainentry. 
    404   * <p> 
    405   * <b>Authorities checked: </b> <br> 
    406   * DYNAMICFIELDS_VIEW <br> 
    407   * <b>Request parameter: </b> <br> 
    408   * DynamicFields_mainId - The id of the field to view <br> 
    409   * <b>Events thrown: </b> getMainEntry <br> 
    410   * <b>Possible Errors: </b> <br> 
    411   * Authority missing <br> 
    412   * Field missing <br> 
    413   * </p> 
    414   * <b>Return DOM </b> <br> 
    415   *  &lt;DYNAMICFIELDS&gt; 
    416   *    &lt;MAINENTRY&gt; 
    417   *    &lt;/MAINENTRY&gt; 
    418   *  &lt;/DYNAMICFIELDS&gt; 
    419     * @return a given Field definition  
    420     */ 
    421     public Element getMainEntry () { 
    422         Element root = core.getDoc().createElement("DYNAMICFIELDS"); 
    423  
    424         // check request parameter 
    425         if (defView.mainId == -1)  
    426             return eventer.nosuccess(Eventer.FIELD_MISSING, "foreignMainId"); 
    427          
    428         try 
    429         { 
    430             Element results; 
    431             Element iroot = core.getDoc().createElement("SELECT"); 
    432             // filter ónly by module if we do have a given module 
    433             Element wheres = core.getDoc().createElement("WHERE"); 
    434             wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "ID", defView.mainId)); 
    435             iroot.appendChild(wheres); 
    436              
    437             results = defView.selectEntriesWhereClause(pool, iroot); 
    438             if (results == null) 
    439                 return eventer.nosuccess(Eventer.ENTRY_NOT_EXIST, String.valueOf(defView.mainId)); 
    440              
    441             Element cur = (Element) results.getFirstChild(); 
    442             root.appendChild(getMainEntryTree(cur)); 
    443         } catch (Exception e) { 
    444             eventer.fatalError(e.getMessage()); 
    445             e.printStackTrace(); 
    446         } 
    447          
    448         return root; 
    449     } 
    450      
    451   /** 
    452   * <p> 
    453   * If a foreignMainId is given, selected="true" will be set. 
    454   * <b>Authorities checked: </b> <br> 
    455   * DYNAMICFIELDS_VIEW <br> 
    456   * <b>Request parameter: </b> <br> 
    457   * none <br> 
    458   * <b>Events thrown: </b> getMainEntries <br> 
    459   * <b>Possible Errors: </b> <br> 
    460   * Authority missing <br> 
    461   * Field missing <br> 
    462   * </p> 
    463   * <b>Return DOM </b> <br> 
    464   *  &lt;DYNAMICFIELDS&gt; 
    465   *    &lt;MAINENTRY&gt; 
    466   *    &lt;/MAINENTRY&gt; 
    467   *  &lt;/DYNAMICFIELDS&gt; 
    468   * @return all Field definitions filtered for a specified module if module is given 
    469   */ 
    470     public Element getMainEntries() { 
    471         Element root = core.getDoc().createElement("DYNAMICFIELDS"); 
    472         try 
    473         { 
    474             Element results; 
    475             Element iroot = core.getDoc().createElement("SELECT"); 
    476             // filter ónly by module if we do have a given module 
    477             if (defView.module != null) 
    478             { 
    479                 Element wheres = core.getDoc().createElement("WHERE"); 
    480                 wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "MODULE", defView.module)); 
    481                 iroot.appendChild(wheres); 
    482             } 
    483              
    484             results = defView.selectEntriesWhereClause(pool, iroot); 
    485             if (results != null) 
    486             { 
    487                 long relation[] = null; 
    488                 // we got a foreignMainId - so get the info 
    489                 if (defView.foreignMainId != -1) 
    490                 { 
    491                     Element subresults = relView.selectEntry(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", defView.foreignMainId), pool); 
    492                     if (subresults != null) 
    493                     { 
    494                         NodeList nl = subresults.getChildNodes(); 
    495                         relation = new long[nl.getLength()]; 
    496                         for (int i = 0; nl != null && i < nl.getLength(); i++) { 
    497                                 relation[i] = DomUtil.getResultLong(nl.item(i), "FIELDID"); 
    498                         } 
    499                     } 
    500                 } 
    501                 for (Element cur : new ChildElementAdapter(results)) 
    502                 { 
    503                       Element e = getMainEntryTree(cur); 
    504                       root.appendChild(e); 
    505                       if (relation != null) 
    506                       { 
    507                         for (int j=0; j < relation.length; j++) 
    508                                 if (relation[j] == DomUtil.getResultLong(e, "ID")) 
    509                                 { 
    510                                         e.setAttribute("selected", "true"); 
    511                                         break; 
    512                                 } 
    513                       } 
    514                     } 
    515             } 
    516         } catch (Exception e) { 
    517             eventer.fatalError(e.getMessage()); 
    518             e.printStackTrace(); 
    519         } 
    520          
    521         return root; 
    522     } 
    523      
    524     /** 
    525     * Search for dynamic entries.  
    526     * Return DOM: </br> 
    527     * <pre> 
    528     * &lt;DATA&gt; 
    529     *   &lt;ID&gt;Id of the entry&lt;/ID&gt; 
    530     *   &lt;ITEMID&gt;Id of one Fielditem&lt;/ITEMID&gt; 
    531     *   &lt;FOREIGNID&gt;Id of the depending Entry&lt;/FOREIGNID&gt; 
    532     *   &lt;MODULENAME&gt;Name of the foreign Module&lt;/MODULENAME&gt; 
    533     *   &lt;VALUE&gt;value of the dynamicField&lt;/VALUE&gt; 
    534     *   &lt;MASKID&gt;id of the mask&lt;/MASKID&gt; 
    535     * &lt;/DATA&gt; 
    536     * </pre> 
    537     * @return all Entries in case foreignId is not set. Otherwise it only returns the Entries for the specified foreignId 
    538     */ 
    539     public Element searchEntries() { 
    540         String[] parameter = { "search" }; 
    541         Element root = core.getDoc().createElement("DYNAMICFIELDS"); 
    542         ArrayList<String> al = dataView.generateVariableResponseTree(parameter); 
    543         if (al != null) 
    544             return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
    545         try { 
    546             Element iroot = core.getDoc().createElement("SELECT"); 
    547             // filter ónly by module if we do have a given module 
    548             Element wheres = core.getDoc().createElement("WHERE"); 
    549             wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "VALUE", "%"+ defView.search +"%")); 
    550             iroot.appendChild(wheres); 
    551              
    552             Element results = dataView.selectEntriesWhereClause(pool, iroot); 
    553              
    554             for (Element cur : new ChildElementAdapter(results)) 
    555             { 
    556                 Element sub = core.getDoc().createElement("DATA"); 
    557                 root.appendChild(sub); 
    558                 sub.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",DomUtil.getResultLong(cur,"ID"))); 
    559                 sub.appendChild(DomUtil.CreateNode(core.getDoc(),"ITEMID", DomUtil.getResultLong(cur, "ITEMID"))); 
    560                 sub.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID",DomUtil.getResultLong(cur,"FOREIGNID"))); 
    561                 sub.appendChild(DomUtil.CreateNode(core.getDoc(),"MODULENAME",DomUtil.getResultString(cur,"MODULENAME"))); 
    562                 sub.appendChild(DomUtil.CreateNode(core.getDoc(),"VALUE",DomUtil.getResultString(cur,"VALUE"))); 
    563             } 
    564         } catch (Exception e) { 
    565             eventer.fatalError(e.getMessage()); 
    566             e.printStackTrace(); 
    567         } 
    568         return root; 
    569     } 
    570          
    571     /** 
    572     * Creates the given Fields in the Dynamic Field Data View. The data hashtable 
    573     * must contain the apropriate value field class (either String or File. The type checking is done within here 
    574     * if the value does not contain f.e. an integer etc.) 
    575     * @return a success or failure tree 
    576     */ 
    577     protected Element createEntryData(long foreignMainId, String module, long foreignId)  
    578     { 
    579         try { 
    580             Element results; 
    581             Element iroot = core.getDoc().createElement("SELECT"); 
    582             // filter ónly by module if we do have a given module 
    583             Element wheres = core.getDoc().createElement("WHERE"); 
    584             if (foreignMainId != -1) 
    585                 wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", foreignMainId)); 
    586             if (module != null) 
    587                 wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "MODULE", module)); 
    588             iroot.appendChild(wheres); 
    589              
    590             results = relView.selectEntriesWhereClause(pool, iroot); 
    591             dataView.startChange(this); 
    592             for (Element cur : new ChildElementAdapter(results)) 
    593             { 
    594                 String value = null; 
    595                 // TODO this: String value = view.getParamAsString("f"+DomUtil.getResultString(cur, "FIELDID")); 
    596                 if (value != null) 
    597                 { 
    598                         Element insert = core.getDoc().createElement("INSERT"); 
    599                         insert.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",conf.getId())); 
    600                         insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID", foreignId)); 
    601                         insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FIELDID", DomUtil.getResultString(cur, "FIELDID"))); 
    602                         insert.appendChild(DomUtil.CreateNode(core.getDoc(),"VALUE",value)); 
    603                         dataView.createEntry(pool,insert); 
    604                 } 
    605             } 
    606             dataView.commitChange(this); 
    607  
    608         } catch (Exception e) { 
    609             dataView.rollbackChange(this); 
    610             eventer.fatalError(e.getMessage()); 
    611             e.printStackTrace(); 
    612         } 
    613         return eventer.success(); 
    614     } 
    615      
    616  
    617     /** 
    618     * Updates the dynamic field values of a given entry.  
    619     * @return a success or failure tree 
    620     */ 
    621     protected Element updateEntryData(long foreignId, HashMap<String,String> dynamicFields)  
    622     { 
    623         try { 
    624             dataView.startChange(this); 
    625              
    626             // delete all current values 
    627             Element delete = core.getDoc().createElement("DELETE"); 
    628             delete.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID", foreignId)); 
    629             dataView.deleteEntry(pool, delete); 
    630              
    631             for (String key : (Set<String>)dynamicFields.keySet()) 
    632             { 
    633                         String value = (String)dynamicFields.get(key); 
    634                         if (value == null || value.length() ==0) 
    635                                 continue; 
    636                          
    637                     long field = Long.parseLong(key.substring(1)); 
    638                 Element insert = core.getDoc().createElement("INSERT"); 
    639                 insert.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",conf.getId())); 
    640                 insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID", foreignId)); 
    641                 insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FIELDID", field)); 
    642                 insert.appendChild(DomUtil.CreateNode(core.getDoc(),"VALUE",value)); 
    643                 dataView.createEntry(pool,insert); 
    644             } 
    645  
    646              
    647             dataView.commitChange(this); 
    648  
    649         } catch (Exception e) { 
    650             dataView.rollbackChange(this); 
    651             eventer.fatalError(e.getMessage()); 
    652             e.printStackTrace(); 
    653         } 
    654         return eventer.success(); 
    655     } 
    656      
    657          
    658     /** 
    659     * Deletes all Entries for the specified foreignId. <br> 
    660     * <b>!! Should only be called, if the entry with the specified foreignId is deleted too!!</b> 
    661     * @return successtree 
    662     */ 
    663     public Element deleteEntries() { 
    664         if (!defView.deleteEntry)  
    665             return null; 
    666         if (defView.foreignMainId != -1) { 
    667             try { 
    668                 Element delete = core.getDoc().createElement("DELETE"); 
    669                 delete.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID",defView.foreignMainId)); 
    670                 dataView.deleteEntry(pool,delete); 
    671             } catch (Exception e) { 
    672                 eventer.fatalError(e.getMessage()); 
    673                 e.printStackTrace(); 
    674             } 
    675             return eventer.success(); 
    676         } 
    677         return eventer.nosuccess(Eventer.INCORRECT_FIELD_VALUE,"foreignId"); 
    678     } 
    679      
    680  
    681      
    682     /** 
    683     * @return all dynamic fields to a given foreign mainId, if a foreign Id is also given, the value (if applicable)   
    684     */ 
    685     public Element getEntry() { 
    686         Element root = core.getDoc().createElement("DYNAMICFIELDS"); 
    687  
    688         // check request parameter 
    689         if (defView.foreignId == -1)  
    690             return eventer.nosuccess(Eventer.FIELD_MISSING, "foreignId"); 
    691  
    692         Element results; 
    693         Element iroot = core.getDoc().createElement("SELECT"); 
    694         // filter ónly by module if we do have a given module 
    695         Element wheres = core.getDoc().createElement("WHERE"); 
    696         wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", defView.foreignId)); 
    697         iroot.appendChild(wheres); 
    698          
    699         results = dataView.selectEntriesWhereClause(pool, iroot); 
    700         long oldMainId = defView.mainId; 
    701         for (Element cur : new ChildElementAdapter(results)) 
    702         { 
    703                 // set the mainID of the entry we want next 
    704                 defView.mainId = DomUtil.getResultLong(cur, "FIELDID"); 
    705                 // add the tree 
    706                 Element entry = (Element)getMainEntry().getFirstChild(); 
    707                 entry.appendChild(DomUtil.CreateNode(core.getDoc(), "VALUE", DomUtil.getResultString(cur, "VALUE"))); 
    708                 root.appendChild(entry); 
    709         } 
    710         defView.mainId = oldMainId; 
    711         return root; 
    712     } 
    713  
    714         /** 
    715     * Set main entry request fields dynamically. 
     21 
     22        /** 
     23        * A basic String with a maximum length 255. 
     24        */ 
     25        public final static int TYPE_STRING = 0; 
     26        /** 
     27        * A signed number without comma. 
     28        */ 
     29        public final static int TYPE_INT = 1; 
     30        /** 
     31        * A signed number with comma. 
     32        */ 
     33        public final static int TYPE_NUMBER = 2; 
     34        /** 
     35        * A signed number with two decimal places. 
     36        */ 
     37        public final static int TYPE_TWODEC = 3; 
     38        /** 
     39        * A Date. 
     40        */ 
     41        public final static int TYPE_DATE = 4; 
     42        /** 
     43        * A Date+Time. 
     44        */ 
     45        public final static int TYPE_DATETIME = 5; 
     46        /** 
     47        * A Time. 
     48        */ 
     49        public final static int TYPE_TIME = 6; 
     50        /** 
     51        * Any File. 
     52        */ 
     53        public final static int TYPE_FILE = 7; 
     54        /** 
     55        * An image (png, gif, jpg, bmp, etc) 
     56        * Images will be resized. 
     57        */ 
     58        public final static int TYPE_IMAGE = 8; 
     59        /** 
     60        * A PDF File. 
     61        */ 
     62        public final static int TYPE_PDF = 9; 
     63        /** 
     64        * Any Document: core.getDoc(), pdf, etc. 
     65        */ 
     66        public final static int TYPE_DOC = 10; 
     67 
     68        /** 
     69        * The data View saves the actual data. 
     70        */ 
     71        private DynamicFieldDataView dataView; 
     72 
     73        /** 
     74        * The defView stores the definition of the field. 
     75        * <br> (f.e. type, name, module) 
     76        */ 
     77        public DynamicFieldDefinitionsView defView; 
     78 
     79        /** 
     80        * Stores the relation between definitions and (Main-)Entries in another module. 
     81        */ 
     82        private DynamicFieldRelationView relView; 
     83 
     84        public DynamicFields(Core core) { 
     85                super(core,"CorePro"); 
     86        } 
     87 
     88        /* (non-Javacore.getDoc()) 
     89        * @see corinis.modules.abstracts.Module#init(org.w3c.dom.Node) 
     90        */ 
     91        protected void init(Node config) { 
     92                defView = new DynamicFieldDefinitionsView(core); 
     93                relView = new DynamicFieldRelationView(core); 
     94                dataView = new DynamicFieldDataView(core); 
     95                dataViews.add(dataView); 
     96                dataViews.add(defView); 
     97                dataViews.add(relView); 
     98 
     99                moduleName = "DynamicFields"; 
     100        } 
     101 
     102 
     103 
     104        /** 
     105        * Return DOM: </br> 
     106        * <pre> 
     107        * &lt;MAINENTRY&gt; 
     108        *   &lt;ID&gt;Id of the entry&lt;/ID&gt; 
     109        *   &lt;NAME&gt;Name of the definition&lt;/NAME&gt; 
     110        *   &lt;DESCRIPTION&gt;The discription of the Field&lt;/SHORTNAME&gt; 
     111        *   &lt;DATATYPE&gt;The datatype for this field&lt;/DATATYPE&gt; 
     112        *   &lt;MODULE&gt;The module this field is connected to&lt;/MODULE&gt; 
     113        * &lt;/MAINENTRY&gt; 
     114        * </pre> 
     115        * @param cur the result from a database query 
     116        * @return the above tree 
     117        */ 
     118        private Element getMainEntryTree(Element cur) { 
     119                Element sub = core.getDoc().createElement("MAINENTRY"); 
     120                sub.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",DomUtil.getResultString(cur,"ID"))); 
     121                sub.appendChild(DomUtil.CreateNode(core.getDoc(),"NAME",DomUtil.getResultString(cur,"NAME"))); 
     122                sub.appendChild(DomUtil.CreateNode(core.getDoc(),"DESCRIPTION", DomUtil.getResultString(cur,"DESCRIPTION"))); 
     123                sub.appendChild(DomUtil.CreateNode(core.getDoc(),"DATATYPE", DomUtil.getResultString(cur, "DATATYPE"))); 
     124                sub.appendChild(DomUtil.CreateNode(core.getDoc(),"MODULE", DomUtil.getResultString(cur,"MODULE"))); 
     125                return sub; 
     126        } 
     127 
     128 
     129 
     130 
     131        /** 
     132        * Creates an an Entry. 
     133        * Within DynamicFields an Entry consists in the definition of the field, including it's module. 
     134        * @return standard return tree. 
     135        */ 
     136        public Element createMainEntry() { 
     137                if (!defView.createMainEntry)  
     138                        return null; 
     139 
     140                String[] parameter = {"name", "module"}; 
     141                ArrayList<String> al = defView.generateVariableResponseTree(parameter); 
     142 
     143                if (al != null) 
     144                        return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
     145 
     146                try { 
     147                        // see if a NAME/MODULE combination already exists 
     148                        Element where = core.getDoc().createElement("WHERE"); 
     149                        where.appendChild(DomUtil.CreateNode(core.getDoc(),"NAME",defView.name)); 
     150                        where.appendChild(DomUtil.CreateNode(core.getDoc(),"MODULE",defView.module)); 
     151                        if (defView.selectEntry(where, pool) != null) { 
     152                                return eventer.nosuccess(Eventer.ENTRY_ALREADY_EXISTS); 
     153                        } 
     154 
     155                        Element insert = core.getDoc().createElement("INSERT"); 
     156                        insert.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",conf.getId())); 
     157                        insert.appendChild(DomUtil.CreateNode(core.getDoc(),"NAME",defView.name)); 
     158                        insert.appendChild(DomUtil.CreateNode(core.getDoc(),"DATATYPE",defView.datatype)); 
     159                        insert.appendChild(DomUtil.CreateNode(core.getDoc(),"DESCRIPTION",defView.description)); 
     160                        insert.appendChild(DomUtil.CreateNode(core.getDoc(),"MODULE",defView.module)); 
     161 
     162                        defView.startChange(this); 
     163                        defView.createEntry(pool,insert); 
     164                        defView.commitChange(this); 
     165                } catch (Exception e) { 
     166                        eventer.fatalError(e.getMessage()); 
     167                        e.printStackTrace(); 
     168                        defView.rollbackChange(this); 
     169                } 
     170                return eventer.success(); 
     171        } 
     172 
     173 
     174        /** 
     175        * Creates a relation between a dynmic field of a module and a foreign id 
     176        * @return success or nosuccess 
     177        */ 
     178        public Element createEntry() { 
     179                if (!defView.createEntry)  
     180                        return null; 
     181 
     182                String[] parameter = {"foreignId", "mainId"}; 
     183                ArrayList<String> al = defView.generateVariableResponseTree(parameter); 
     184                if (al != null)  
     185                        return eventer.nosuccess(Eventer.FIELD_MISSING,al); 
     186 
     187                try { 
     188                        // first check if the current relation has already been created 
     189                        Element select = core.getDoc().createElement("SELECT"); 
     190                        Element wheres = core.getDoc().createElement("WHERE"); 
     191                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(),"FIELDID",defView.mainId)); 
     192                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID",defView.foreignMainId)); 
     193                        select.appendChild(wheres); 
     194                        Element results = relView.selectEntriesWhereClause(pool,select); 
     195 
     196                        if (results == null) {  
     197                                // can only be inserted if relation doesn't exist 
     198                                Element insert = core.getDoc().createElement("INSERT"); 
     199                                insert.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",conf.getId())); 
     200                                insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FIELDID",defView.mainId)); 
     201                                insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID",defView.foreignMainId)); 
     202                                relView.createEntry(pool,insert); 
     203                        } 
     204                        else 
     205                                return eventer.nosuccess(Eventer.ENTRY_ALREADY_EXISTS, String.valueOf(defView.mainId)); 
     206 
     207                } catch (Exception e) { 
     208                        eventer.fatalError(e.getMessage()); 
     209                        e.printStackTrace(); 
     210                } 
     211                return eventer.success(); 
     212        } 
     213 
     214        /** 
     215        * Recreates relations between a dynmic field of a module and a foreign id 
     216        * @return success or nosuccess 
     217        */ 
     218        public Element recreateEntries() { 
     219                if (!defView.createEntry)  
     220                        return null; 
     221 
     222                String[] parameter = {"foreignMainId", "mainIds"}; 
     223                ArrayList<String> al = defView.generateVariableResponseTree(parameter); 
     224                if (al != null)  
     225                        return eventer.nosuccess(Eventer.FIELD_MISSING,al); 
     226 
     227                try { 
     228                        // first delete all current Relations 
     229                        Element delete = core.getDoc().createElement("DELETE"); 
     230                        delete.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID",defView.foreignMainId)); 
     231                        relView.deleteEntry(pool, delete); 
     232 
     233                        for (int i = 0; i < defView.mainIds.length; i++) 
     234                                if (defView.mainIds[i] != null) 
     235                                { 
     236                                        // can only be inserted if relation doesn't exist 
     237                                        Element insert = core.getDoc().createElement("INSERT"); 
     238                                        insert.appendChild(DomUtil.CreateNode(core.getDoc(), "ID", conf.getId())); 
     239                                        insert.appendChild(DomUtil.CreateNode(core.getDoc(), "FIELDID", defView.mainIds[i])); 
     240                                        insert.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", defView.foreignMainId)); 
     241                                        relView.createEntry(pool,insert); 
     242                                } 
     243                } catch (Exception e) { 
     244                        eventer.fatalError(e.getMessage()); 
     245                        e.printStackTrace(); 
     246                } 
     247                return eventer.success(); 
     248        }     
     249 
     250 
     251 
     252        public Element deleteMainEntry() { 
     253                if (!defView.deleteMainEntry)  
     254                        return null; 
     255 
     256                String[] parameter = {"mainId"}; 
     257                ArrayList<String> al = defView.generateVariableResponseTree(parameter); 
     258                if (al!=null)    
     259                        return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
     260 
     261                try { 
     262                        //first delete the definition itself 
     263                        Element delete = core.getDoc().createElement("DELETE"); 
     264                        delete.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",defView.mainId)); 
     265                        defView.deleteEntry(pool,delete); 
     266 
     267                        // then delete the relation 
     268                        delete = core.getDoc().createElement("DELETE"); 
     269                        delete.appendChild(DomUtil.CreateNode(core.getDoc(),"FIELDID",defView.mainId)); 
     270                        relView.deleteEntry(pool,delete); 
     271 
     272                        // and the the data 
     273                        dataView.deleteEntry(pool,delete); 
     274 
     275                } catch (Exception e) { 
     276                        eventer.fatalError(e.getMessage()); 
     277                        e.printStackTrace(); 
     278                } 
     279                return eventer.success(); 
     280        } 
     281 
     282 
     283        /** 
     284        * Should be called if an entry is assigned to another MainEntry. So new Data will be 
     285        * created which are masked with the relations of the MainEntry. 
     286        * If this Data already exists, only the maskid will be added 
     287        * @return successtree 
     288        */ 
     289        public Element addDataToRelation() { 
     290                String[] parameter = {"moduleName", "foreignMainId"}; 
     291                ArrayList<String> al = relView.generateVariableResponseTree(parameter); 
     292                if (al != null) 
     293                        return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
     294                String[] parameter1 = {"foreignId"}; 
     295                al = dataView.generateVariableResponseTree(parameter1); 
     296                if (al!=null) 
     297                        return eventer.nosuccess(Eventer.FIELD_MISSING,al); 
     298                try { 
     299                        // First get the mask_ids 
     300                        Element select = core.getDoc().createElement("SELECT"); 
     301                        Element wheres = core.getDoc().createElement("WHERE"); 
     302                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNMAINID",defView.foreignMainId)); 
     303                        select.appendChild(wheres); 
     304                        Element results = relView.selectEntriesWhereClause(pool,select); 
     305 
     306                        for (Element cur : new ChildElementAdapter(results)) 
     307                        { 
     308                                long definition = DomUtil.getResultLong(cur, "ITEMID"); 
     309 
     310                                // otherwise the relation AND a field has to be created 
     311 
     312                                // add the field 
     313                                long dataid = conf.getId(); 
     314                                Element insert = core.getDoc().createElement("INSERT"); 
     315                                insert.appendChild(DomUtil.CreateNode(core.getDoc(), "ID", dataid)); 
     316                                insert.appendChild(DomUtil.CreateNode(core.getDoc(), "ITEMID", definition)); 
     317                                insert.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", defView.foreignMainId)); 
     318                                insert.appendChild(DomUtil.CreateNode(core.getDoc(), "VALUE", "")); 
     319                                dataView.startChange(this); 
     320                                dataView.createEntry(pool, insert); 
     321                                dataView.commitChange(this); 
     322 
     323 
     324                        } 
     325 
     326                }   catch (Exception e) { 
     327                        eventer.fatalError(e.getMessage()); 
     328                        e.printStackTrace(); 
     329                } 
     330                return eventer.success(); 
     331        } 
     332 
     333 
     334        /** 
     335        * @return all foreign id's to given mainentry  
     336        */ 
     337        public Element getEntries () { 
     338 
     339                // check request parameter 
     340                String[] parameter = {"mainId"}; 
     341                ArrayList<String> al = defView.generateVariableResponseTree(parameter); 
     342                if (al != null)  
     343                        return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
     344 
     345                Element root = getMainEntry(); 
     346                Element results; 
     347                Element iroot = core.getDoc().createElement("SELECT"); 
     348                // filter ᅵnly by module if we do have a given module 
     349                Element wheres = core.getDoc().createElement("WHERE"); 
     350                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FIELDID", defView.mainId)); 
     351                iroot.appendChild(wheres); 
     352 
     353                results = relView.selectEntriesWhereClause(pool, iroot); 
     354                for (Element cur : new ChildElementAdapter(results)) 
     355                        root.appendChild(DomUtil.createDuplicateNode(core.getDoc(), "FOREIGNID", cur)); 
     356 
     357                                return root; 
     358        } 
     359 
     360        // gets the definition & possible data of an Entry  
     361        protected Element getEntryData() 
     362        { 
     363                Element root = core.getDoc().createElement("ENTRY"); 
     364                Element iroot = core.getDoc().createElement("SELECT"); 
     365                // filter ᅵnly by module if we do have a given module 
     366                Element wheres = core.getDoc().createElement("WHERE"); 
     367                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "ID", defView.id)); 
     368                iroot.appendChild(wheres); 
     369 
     370                Element results = defView.selectEntriesWhereClause(pool, iroot); 
     371                for (Element cur : new ChildElementAdapter(results)) 
     372                { 
     373                        root.appendChild(DomUtil.CreateNode(core.getDoc(), "ID", DomUtil.getResultLong(cur, "id"))); 
     374                        root.appendChild(DomUtil.CreateNode(core.getDoc(), "NAME", DomUtil.getResultString(cur, "name"))); 
     375                        root.appendChild(DomUtil.CreateNode(core.getDoc(), "DESCRIPTION", DomUtil.getResultString(cur, "description"))); 
     376                        root.appendChild(DomUtil.CreateNode(core.getDoc(), "DATATYPE", DomUtil.getResultLong(cur, "datatype")));               
     377                } 
     378 
     379                // data 
     380                if (defView.foreignId > 0) 
     381                { 
     382                        iroot = core.getDoc().createElement("SELECT"); 
     383                        // filter ᅵnly by module if we do have a given module 
     384                        wheres = core.getDoc().createElement("WHERE"); 
     385                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FIELDID", defView.id)); 
     386                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", defView.foreignId)); 
     387                        iroot.appendChild(wheres); 
     388 
     389                        results = dataView.selectEntriesWhereClause(pool, iroot); 
     390                        if (results != null) 
     391                        { 
     392                                Element cur = (Element)results.getFirstChild(); 
     393                                root.appendChild(DomUtil.CreateNode(core.getDoc(), "VALUE",DomUtil.getResultString(cur, "value")));                 
     394                        } 
     395                } 
     396 
     397                return root; 
     398        } 
     399 
     400 
     401 
     402        /** 
     403        * gets a mainentry. 
     404        * <p> 
     405        * <b>Authorities checked: </b> <br> 
     406        * DYNAMICFIELDS_VIEW <br> 
     407        * <b>Request parameter: </b> <br> 
     408        * DynamicFields_mainId - The id of the field to view <br> 
     409        * <b>Events thrown: </b> getMainEntry <br> 
     410        * <b>Possible Errors: </b> <br> 
     411        * Authority missing <br> 
     412        * Field missing <br> 
     413        * </p> 
     414        * <b>Return DOM </b> <br> 
     415        *  &lt;DYNAMICFIELDS&gt; 
     416        *      &lt;MAINENTRY&gt; 
     417        *      &lt;/MAINENTRY&gt; 
     418        *  &lt;/DYNAMICFIELDS&gt; 
     419        * @return a given Field definition  
     420        */ 
     421        public Element getMainEntry () { 
     422                Element root = core.getDoc().createElement("DYNAMICFIELDS"); 
     423 
     424                // check request parameter 
     425                if (defView.mainId == -1)  
     426                        return eventer.nosuccess(Eventer.FIELD_MISSING, "foreignMainId"); 
     427 
     428                try 
     429                { 
     430                        Element results; 
     431                        Element iroot = core.getDoc().createElement("SELECT"); 
     432                        // filter ᅵnly by module if we do have a given module 
     433                        Element wheres = core.getDoc().createElement("WHERE"); 
     434                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "ID", defView.mainId)); 
     435                        iroot.appendChild(wheres); 
     436 
     437                        results = defView.selectEntriesWhereClause(pool, iroot); 
     438                        if (results == null) 
     439                                return eventer.nosuccess(Eventer.ENTRY_NOT_EXIST, String.valueOf(defView.mainId)); 
     440 
     441                        Element cur = (Element) results.getFirstChild(); 
     442                        root.appendChild(getMainEntryTree(cur)); 
     443                } catch (Exception e) { 
     444                        eventer.fatalError(e.getMessage()); 
     445                        e.printStackTrace(); 
     446                } 
     447 
     448                return root; 
     449        } 
     450 
     451        /** 
     452        * <p> 
     453        * If a foreignMainId is given, selected="true" will be set. 
     454        * <b>Authorities checked: </b> <br> 
     455        * DYNAMICFIELDS_VIEW <br> 
     456        * <b>Request parameter: </b> <br> 
     457        * none <br> 
     458        * <b>Events thrown: </b> getMainEntries <br> 
     459        * <b>Possible Errors: </b> <br> 
     460        * Authority missing <br> 
     461        * Field missing <br> 
     462        * </p> 
     463        * <b>Return DOM </b> <br> 
     464        *  &lt;DYNAMICFIELDS&gt; 
     465        *      &lt;MAINENTRY&gt; 
     466        *      &lt;/MAINENTRY&gt; 
     467        *  &lt;/DYNAMICFIELDS&gt; 
     468        * @return all Field definitions filtered for a specified module if module is given 
     469        */ 
     470        public Element getMainEntries() { 
     471                Element root = core.getDoc().createElement("DYNAMICFIELDS"); 
     472                try 
     473                { 
     474                        Element results; 
     475                        Element iroot = core.getDoc().createElement("SELECT"); 
     476                        // filter ᅵnly by module if we do have a given module 
     477                        if (defView.module != null) 
     478                        { 
     479                                Element wheres = core.getDoc().createElement("WHERE"); 
     480                                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "MODULE", defView.module)); 
     481                                iroot.appendChild(wheres); 
     482                        } 
     483 
     484                        results = defView.selectEntriesWhereClause(pool, iroot); 
     485                        if (results != null) 
     486                        { 
     487                                long relation[] = null; 
     488                                // we got a foreignMainId - so get the info 
     489                                if (defView.foreignMainId != -1) 
     490                                { 
     491                                        Element subresults = relView.selectEntry(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", defView.foreignMainId), pool); 
     492                                        if (subresults != null) 
     493                                        { 
     494                                                NodeList nl = subresults.getChildNodes(); 
     495                                                relation = new long[nl.getLength()]; 
     496                                                for (int i = 0; nl != null && i < nl.getLength(); i++) { 
     497                                                        relation[i] = DomUtil.getResultLong(nl.item(i), "FIELDID"); 
     498                                                } 
     499                                        } 
     500                                } 
     501                                for (Element cur : new ChildElementAdapter(results)) 
     502                                { 
     503                                        Element e = getMainEntryTree(cur); 
     504                                        root.appendChild(e); 
     505                                        if (relation != null) 
     506                                        { 
     507                                                for (int j=0; j < relation.length; j++) 
     508                                                        if (relation[j] == DomUtil.getResultLong(e, "ID")) 
     509                                                        { 
     510                                                                e.setAttribute("selected", "true"); 
     511                                                                break; 
     512                                                        } 
     513                                        } 
     514                                } 
     515                        } 
     516                } catch (Exception e) { 
     517                        eventer.fatalError(e.getMessage()); 
     518                        e.printStackTrace(); 
     519                } 
     520 
     521                return root; 
     522        } 
     523 
     524        /** 
     525        * Search for dynamic entries.  
     526        * Return DOM: </br> 
     527        * <pre> 
     528        * &lt;DATA&gt; 
     529        *   &lt;ID&gt;Id of the entry&lt;/ID&gt; 
     530        *   &lt;ITEMID&gt;Id of one Fielditem&lt;/ITEMID&gt; 
     531        *   &lt;FOREIGNID&gt;Id of the depending Entry&lt;/FOREIGNID&gt; 
     532        *   &lt;MODULENAME&gt;Name of the foreign Module&lt;/MODULENAME&gt; 
     533        *   &lt;VALUE&gt;value of the dynamicField&lt;/VALUE&gt; 
     534        *   &lt;MASKID&gt;id of the mask&lt;/MASKID&gt; 
     535        * &lt;/DATA&gt; 
     536        * </pre> 
     537        * @return all Entries in case foreignId is not set. Otherwise it only returns the Entries for the specified foreignId 
     538        */ 
     539        public Element searchEntries() { 
     540                String[] parameter = { "search" }; 
     541                Element root = core.getDoc().createElement("DYNAMICFIELDS"); 
     542                ArrayList<String> al = dataView.generateVariableResponseTree(parameter); 
     543                if (al != null) 
     544                        return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
     545                try { 
     546                        Element iroot = core.getDoc().createElement("SELECT"); 
     547                        // filter ᅵnly by module if we do have a given module 
     548                        Element wheres = core.getDoc().createElement("WHERE"); 
     549                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "VALUE", "%"+ defView.search +"%")); 
     550                        iroot.appendChild(wheres); 
     551 
     552                        Element results = dataView.selectEntriesWhereClause(pool, iroot); 
     553 
     554                        for (Element cur : new ChildElementAdapter(results)) 
     555                        { 
     556                                Element sub = core.getDoc().createElement("DATA"); 
     557                                root.appendChild(sub); 
     558                                sub.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",DomUtil.getResultLong(cur,"ID"))); 
     559                                sub.appendChild(DomUtil.CreateNode(core.getDoc(),"ITEMID", DomUtil.getResultLong(cur, "ITEMID"))); 
     560                                sub.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID",DomUtil.getResultLong(cur,"FOREIGNID"))); 
     561                                sub.appendChild(DomUtil.CreateNode(core.getDoc(),"MODULENAME",DomUtil.getResultString(cur,"MODULENAME"))); 
     562                                sub.appendChild(DomUtil.CreateNode(core.getDoc(),"VALUE",DomUtil.getResultString(cur,"VALUE"))); 
     563                        } 
     564                } catch (Exception e) { 
     565                        eventer.fatalError(e.getMessage()); 
     566                        e.printStackTrace(); 
     567                } 
     568                return root; 
     569        } 
     570 
     571        /** 
     572        * Creates the given Fields in the Dynamic Field Data View. The data hashtable 
     573        * must contain the apropriate value field class (either String or File. The type checking is done within here 
     574        * if the value does not contain f.e. an integer etc.) 
     575        * @return a success or failure tree 
     576        */ 
     577        protected Element createEntryData(long foreignMainId, String module, long foreignId)  
     578        { 
     579                try { 
     580                        Element results; 
     581                        Element iroot = core.getDoc().createElement("SELECT"); 
     582                        // filter ᅵnly by module if we do have a given module 
     583                        Element wheres = core.getDoc().createElement("WHERE"); 
     584                        if (foreignMainId != -1) 
     585                                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", foreignMainId)); 
     586                        if (module != null) 
     587                                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "MODULE", module)); 
     588                        iroot.appendChild(wheres); 
     589 
     590                        results = relView.selectEntriesWhereClause(pool, iroot); 
     591                        dataView.startChange(this); 
     592                        for (Element cur : new ChildElementAdapter(results)) 
     593                        { 
     594                                String value = null; 
     595                                // TODO this: String value = view.getParamAsString("f"+DomUtil.getResultString(cur, "FIELDID")); 
     596                                if (value != null) 
     597                                { 
     598                                        Element insert = core.getDoc().createElement("INSERT"); 
     599                                        insert.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",conf.getId())); 
     600                                        insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID", foreignId)); 
     601                                        insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FIELDID", DomUtil.getResultString(cur, "FIELDID"))); 
     602                                        insert.appendChild(DomUtil.CreateNode(core.getDoc(),"VALUE",value)); 
     603                                        dataView.createEntry(pool,insert); 
     604                                } 
     605                        } 
     606                        dataView.commitChange(this); 
     607 
     608                } catch (Exception e) { 
     609                        dataView.rollbackChange(this); 
     610                        eventer.fatalError(e.getMessage()); 
     611                        e.printStackTrace(); 
     612                } 
     613                return eventer.success(); 
     614        } 
     615 
     616 
     617        /** 
     618        * Updates the dynamic field values of a given entry.  
     619        * @return a success or failure tree 
     620        */ 
     621        protected Element updateEntryData(long foreignId, HashMap<String,String> dynamicFields)  
     622        { 
     623                try { 
     624                        dataView.startChange(this); 
     625 
     626                        // delete all current values 
     627                        Element delete = core.getDoc().createElement("DELETE"); 
     628                        delete.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID", foreignId)); 
     629                        dataView.deleteEntry(pool, delete); 
     630 
     631                        for (String key : (Set<String>)dynamicFields.keySet()) 
     632                        { 
     633                                String value = (String)dynamicFields.get(key); 
     634                                if (value == null || value.length() ==0) 
     635                                        continue; 
     636 
     637                                long field = Long.parseLong(key.substring(1)); 
     638                                Element insert = core.getDoc().createElement("INSERT"); 
     639                                insert.appendChild(DomUtil.CreateNode(core.getDoc(),"ID",conf.getId())); 
     640                                insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID", foreignId)); 
     641                                insert.appendChild(DomUtil.CreateNode(core.getDoc(),"FIELDID", field)); 
     642                                insert.appendChild(DomUtil.CreateNode(core.getDoc(),"VALUE",value)); 
     643                                dataView.createEntry(pool,insert); 
     644                        } 
     645 
     646 
     647                        dataView.commitChange(this); 
     648 
     649                } catch (Exception e) { 
     650                        dataView.rollbackChange(this); 
     651                        eventer.fatalError(e.getMessage()); 
     652                        e.printStackTrace(); 
     653                } 
     654                return eventer.success(); 
     655        } 
     656 
     657 
     658        /** 
     659        * Deletes all Entries for the specified foreignId. <br> 
     660        * <b>!! Should only be called, if the entry with the specified foreignId is deleted too!!</b> 
     661        * @return successtree 
     662        */ 
     663        public Element deleteEntries() { 
     664                if (!defView.deleteEntry)  
     665                        return null; 
     666                if (defView.foreignMainId != -1) { 
     667                        try { 
     668                                Element delete = core.getDoc().createElement("DELETE"); 
     669                                delete.appendChild(DomUtil.CreateNode(core.getDoc(),"FOREIGNID",defView.foreignMainId)); 
     670                                dataView.deleteEntry(pool,delete); 
     671                        } catch (Exception e) { 
     672                                eventer.fatalError(e.getMessage()); 
     673                                e.printStackTrace(); 
     674                        } 
     675                        return eventer.success(); 
     676                } 
     677                return eventer.nosuccess(Eventer.INCORRECT_FIELD_VALUE,"foreignId"); 
     678        } 
     679 
     680 
     681 
     682        /** 
     683        * @return all dynamic fields to a given foreign mainId, if a foreign Id is also given, the value (if applicable)   
     684        */ 
     685        public Element getEntry() { 
     686                Element root = core.getDoc().createElement("DYNAMICFIELDS"); 
     687 
     688                // check request parameter 
     689                if (defView.foreignId == -1)  
     690                        return eventer.nosuccess(Eventer.FIELD_MISSING, "foreignId"); 
     691 
     692                Element results; 
     693                Element iroot = core.getDoc().createElement("SELECT"); 
     694                // filter ᅵnly by module if we do have a given module 
     695                Element wheres = core.getDoc().createElement("WHERE"); 
     696                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", defView.foreignId)); 
     697                iroot.appendChild(wheres); 
     698 
     699                results = dataView.selectEntriesWhereClause(pool, iroot); 
     700                long oldMainId = defView.mainId; 
     701                for (Element cur : new ChildElementAdapter(results)) 
     702                { 
     703                        // set the mainID of the entry we want next 
     704                        defView.mainId = DomUtil.getResultLong(cur, "FIELDID"); 
     705                        // add the tree 
     706                        Element entry = (Element)getMainEntry().getFirstChild(); 
     707                        entry.appendChild(DomUtil.CreateNode(core.getDoc(), "VALUE", DomUtil.getResultString(cur, "VALUE"))); 
     708                        root.appendChild(entry); 
     709                } 
     710                defView.mainId = oldMainId; 
     711                return root; 
     712        } 
     713 
     714        /** 
     715        * Set main entry request fields dynamically. 
    716716         * The Fields are named F&lt;ID&gt; - the F is necessary to get valid dom nodes 
    717717         * @param fieldsVariable the fieldid hashmap to fill 
     
    721721        public void setMainEntryRequestFields(HashMap<String, String> fieldsVariable, int foreignMainId, String module)  
    722722        { 
    723         Element results; 
    724         Element iroot = core.getDoc().createElement("SELECT"); 
    725         // filter ónly by module if we do have a given module 
    726         Element wheres = core.getDoc().createElement("WHERE"); 
    727         // request parameters from mainid 
    728         if (foreignMainId != -1) 
    729         { 
    730                 wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", foreignMainId)); 
    731                 iroot.appendChild(wheres); 
    732                  
    733                 results = relView.selectEntriesWhereClause(pool, iroot); 
    734                 for (Element cur : new ChildElementAdapter(results)) 
    735                       // set thy type 
    736                       fieldsVariable.put("f" + DomUtil.getResultString(cur, "FIELDID"), null); 
    737         } 
    738         // request parameters by module 
    739         else 
    740         { 
    741             wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "MODULE", module)); 
    742             iroot.appendChild(wheres); 
    743             results = defView.selectEntriesWhereClause(pool, iroot); 
    744             for (Element cur : new ChildElementAdapter(results)) 
    745                       // set the type 
    746                       fieldsVariable.put("f" + DomUtil.getResultString(cur, "ID"), null); 
    747         } 
    748         } 
    749          
    750          
     723                Element results; 
     724                Element iroot = core.getDoc().createElement("SELECT"); 
     725                // filter ᅵnly by module if we do have a given module 
     726                Element wheres = core.getDoc().createElement("WHERE"); 
     727                // request parameters from mainid 
     728                if (foreignMainId != -1) 
     729                { 
     730                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", foreignMainId)); 
     731                        iroot.appendChild(wheres); 
     732 
     733                        results = relView.selectEntriesWhereClause(pool, iroot); 
     734                        for (Element cur : new ChildElementAdapter(results)) 
     735                                // set thy type 
     736                                fieldsVariable.put("f" + DomUtil.getResultString(cur, "FIELDID"), null); 
     737                } 
     738                // request parameters by module 
     739                else 
     740                { 
     741                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "MODULE", module)); 
     742                        iroot.appendChild(wheres); 
     743                        results = defView.selectEntriesWhereClause(pool, iroot); 
     744                        for (Element cur : new ChildElementAdapter(results)) 
     745                                // set the type 
     746                                fieldsVariable.put("f" + DomUtil.getResultString(cur, "ID"), null); 
     747                } 
     748        } 
     749 
     750 
    751751        /** 
    752752         * Get all fields related to the given foreignids. 
     
    757757         * @return all the fields related to the given foreignIds 
    758758         */ 
    759     public long[] getRelations(long[] foreignIds) { 
    760  
    761         HashMap<String, String> dynf = new HashMap<String, String>(); 
    762         long[] dynfields = null; 
    763         try 
    764         { 
    765             Element results = null; 
    766             Element iroot = core.getDoc().createElement("SELECT"); 
    767             Element wheres = core.getDoc().createElement("WHERE"); 
    768                 iroot.appendChild(wheres); 
    769                  
    770                 if (foreignIds!= null && foreignIds.length > 1) 
    771                 { 
    772                 Element or = core.getDoc().createElement("OR"); 
    773                 wheres.appendChild(or); 
    774                          
    775                     for (int i = 0; i < foreignIds.length; i++) 
    776                     { 
    777                         or.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", foreignIds[i])); 
    778                     } 
    779                     results = relView.selectEntriesWhereExtended(pool, iroot); 
    780                 } 
    781                 else if (foreignIds != null) 
    782                 { 
    783                         wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", foreignIds[0])); 
    784                         results = relView.selectEntriesWhereClause(pool, iroot); 
    785                 } 
    786                  
    787             if (results != null) 
    788             { 
    789                 NodeList nl = results.getChildNodes(); 
    790                 if (nl != null) 
    791                    dynfields = new long[nl.getLength()]; 
    792                 for (int i = 0; nl != null && i < nl.getLength(); i++) { 
    793                         // no doubles 
    794                         if (!dynf.containsKey(DomUtil.getResultString(nl.item(i), "FIELDID"))) 
    795                         { 
    796                            dynfields[i] = DomUtil.getResultLong(nl.item(i), "FIELDID"); 
    797                            dynf.put(DomUtil.getResultString(nl.item(i), "FIELDID"), ""); 
    798                         } 
    799                 } 
    800             } 
    801         } catch (Exception e) { 
    802             eventer.fatalError(e.getMessage()); 
    803             e.printStackTrace(); 
    804         } 
    805         return dynfields; 
    806     } 
    807  
    808          
    809          
     759        public long[] getRelations(long[] foreignIds) { 
     760 
     761                HashMap<String, String> dynf = new HashMap<String, String>(); 
     762                long[] dynfields = null; 
     763                try 
     764                { 
     765                        Element results = null; 
     766                        Element iroot = core.getDoc().createElement("SELECT"); 
     767                        Element wheres = core.getDoc().createElement("WHERE"); 
     768                        iroot.appendChild(wheres); 
     769 
     770                        if (foreignIds!= null && foreignIds.length > 1) 
     771                        { 
     772                                Element or = core.getDoc().createElement("OR"); 
     773                                wheres.appendChild(or); 
     774 
     775                                for (int i = 0; i < foreignIds.length; i++) 
     776                                { 
     777                                        or.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", foreignIds[i])); 
     778                                } 
     779                                results = relView.selectEntriesWhereExtended(pool, iroot); 
     780                        } 
     781                        else if (foreignIds != null) 
     782                        { 
     783                                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "FOREIGNID", foreignIds[0])); 
     784                                results = relView.selectEntriesWhereClause(pool, iroot); 
     785                        } 
     786 
     787                        if (results != null) 
     788                        { 
     789                                NodeList nl = results.getChildNodes(); 
     790                                if (nl != null) 
     791                                        dynfields = new long[nl.getLength()]; 
     792                                for (int i = 0; nl != null && i < nl.getLength(); i++) { 
     793                                        // no doubles 
     794                                        if (!dynf.containsKey(DomUtil.getResultString(nl.item(i), "FIELDID"))) 
     795                                        { 
     796                                                dynfields[i] = DomUtil.getResultLong(nl.item(i), "FIELDID"); 
     797                                                dynf.put(DomUtil.getResultString(nl.item(i), "FIELDID"), ""); 
     798                                        } 
     799                                } 
     800                        } 
     801                } catch (Exception e) { 
     802                        eventer.fatalError(e.getMessage()); 
     803                        e.printStackTrace(); 
     804                } 
     805                return dynfields; 
     806        } 
     807 
     808 
     809 
    810810 
    811811} 
  • Core/trunk/src/main/java/corinis/modules/Login.java

    r632 r660  
    7171public class Login extends EntryManipulate implements IThrowsEvents { 
    7272 
    73     public UsersOnlineView loginView; 
    74     /** 
    75     * @deprecated use loginView instead 
    76     */ 
    77     public UsersOnlineView uoview; 
    78  
    79     private UsersView usersView; 
    80     private byte[] challenge; 
     73        public UsersOnlineView loginView; 
     74        /** 
     75        * @deprecated use loginView instead 
     76        */ 
     77        public UsersOnlineView uoview; 
     78 
     79        private UsersView usersView; 
     80        private byte[] challenge; 
    8181 
    8282        /** Login variables */ 
     
    9292        private String passswordRetrievalReplySubject; 
    9393        private String passswordRetrievalReplyBody; 
    94          
     94 
    9595        /** NTLM config **/ 
    9696        private boolean ntDomainAuth; 
     
    101101 
    102102 
    103     /** 
    104     *  Inits the class 
    105     * @param score the core class, has to be initialized first 
    106     */ 
    107     public Login(Core score) { 
    108         super(score, "Login"); 
    109     } 
    110  
    111     /** 
    112     * function to get the Authorities needed for this module 
    113     * @return Authority/Description String 
    114     */ 
    115  
    116     public String[][] getModuleAuthorities() { 
    117         return null; 
    118     } 
    119  
    120     /** 
    121     * function to get the Events which are thrown in the module 
    122     * @return Event/Description String 
    123     */ 
    124  
    125     public String[][] getEvents() { 
    126         String[][] s = new String[1][2]; 
    127  
    128         s[0][0] = "createEntry"; 
    129         s[0][1] = "Thrown when a user is logging on"; 
    130  
    131         return s; 
    132     } 
    133  
    134     /* Configuration: 
    135     * * LOGIN 
    136     *   * GUESTUSERS 
    137     *   * ALLOWECMAILLOGIN 
    138     *   * PASSWORDRETRIEVAL 
    139     *   * PASSWORDREPLYNAME 
    140     *   * PASSWORDREPLYEMAIL 
    141     *   * PASSWORDREPLYSUBJECT 
    142     *   * PASSWORDREPLYBODY 
    143     *   * USENTDOMAINAUTH 
    144     *   * DOMAIN 
    145     *   * DOMAINCONTROLLER 
    146     *   * DEFAULTGROUP (multiply) 
    147     */ 
    148     protected void init(Node config) { 
    149         moduleData = uoview = loginView = new UsersOnlineView(core); 
    150         usersView = new UsersView(core); 
    151         dataViews.add(loginView); 
    152         challenge = null; 
    153         //Config.setProperty("jcifs.smb.lmCompatibility", "3"); 
    154          
    155         // Configuration 
    156         guestUserAllowed ="TRUE".equalsIgnoreCase(DomUtil.getResultString(config, "GUESTUSERS")); 
    157          
    158         allowEmailLogin = "TRUE".equalsIgnoreCase(DomUtil.getResultString(config, "ALLOWEMAILLOGIN")); 
    159  
    160         saltPassword = "TRUE".equalsIgnoreCase(DomUtil.getResultString(config, "SALT")); 
    161  
    162         passswordRetrieval = DomUtil.getResultBool(config, "PASSWORDRETRIEVAL"); 
    163         passswordRetrievalReplyName = DomUtil.getResultString(config, "PASSWORDREPLYNAME"); 
    164         passswordRetrievalReplyEMail = DomUtil.getResultString(config, "PASSWORDREPLYEMAIL"); 
    165         passswordRetrievalReplySubject = DomUtil.getResultString(config, "PASSWORDREPLYSUBJECT"); 
    166         passswordRetrievalReplyBody = DomUtil.getResultString(config, "PASSWORDREPLYBODY"); 
    167         if (passswordRetrievalReplyBody == null || "auto".equals(passswordRetrievalReplyBody)) 
    168         { 
    169             if (core.getServletContext() != null) 
    170                 passswordRetrievalReplyBody = core.getRealPath("/WEB-INF/password.txt"); 
    171         } 
    172          
    173         if (passswordRetrievalReplyBody != null) 
    174         { 
    175             try 
    176             { 
    177                 passswordRetrievalReplyBody = FileUtils.file2String(new File(passswordRetrievalReplyBody)); 
    178                 passswordRetrieval = true; 
    179             } 
    180             catch (Exception e) 
    181             { 
    182                 passswordRetrievalReplyBody = "UNABLE TO FIND REPLY BODY - CHECK CONFIGURATION FILE!"; 
    183             } 
    184         } 
    185         
    186        // basic auth 
    187        basicAuth = "TRUE".equalsIgnoreCase(DomUtil.getResultString(config, "USENTDOMAINAUTH")); 
    188  
    189         // ntlm config 
    190         if ("TRUE".equalsIgnoreCase(DomUtil.getResultString(config, "USENTDOMAINAUTH"))) 
    191         { 
    192             ntDomainAuth = true; 
    193             ntDomain = DomUtil.getResultString(config, "DOMAIN"); 
    194             ntDomainController = DomUtil.getResultString(config, "DOMAINCONTROLLER"); 
    195             //addGroups = DomUtil.getResultStrings(config, "DEFAULTGROUP"); 
    196         } 
    197         else 
    198             ntDomainAuth = false; 
    199  
    200     } 
    201  
    202     public boolean verifyUser() { 
    203         Element iroot = core.getDoc().createElement("SELECT"); 
    204         Element wheres = core.getDoc().createElement("WHERE"); 
    205  
    206         iroot.appendChild(wheres); 
    207         wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "localusername", loginView.userName)); 
    208         wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "verify", loginView.verify)); 
    209         wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", 2)); 
    210  
    211         Element results = usersView.selectEntriesWhereClause(pool, iroot); 
    212  
    213         // registered user 
    214         // Check if username / pw are all right 
    215         if (results != null) { 
    216             Element cur = (Element) results.getFirstChild(); 
    217             iroot = core.getDoc().createElement("UPDATE"); 
    218  
    219             iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", DomUtil.getResultString(cur, "LOCALUSERID"))); 
    220             iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "VERIFY", "")); 
    221             iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", String.valueOf(1))); 
    222             usersView.updateEntry(pool, iroot); 
    223             return true; 
    224         } 
    225         return false; 
    226     } 
    227  
    228     /** 
    229     * Creates an Authenticated based on Basic or NTLM auth. This creates a login box in 
    230     * Browser (or if using NTLM not in IE). Applications using this functions 
    231     * do NOT allow guest logins! <br> 
    232     * Usage:<br> 
    233     * <code> 
    234     * &lt;%@ page language="java" import="corinis.*,corinis.modules.*,..." %&gt;&lt;% 
    235     *   // init the core module<br> 
    236     *    Core core = new Core ("applicationname", request, response, getServletContext());<br> 
    237     *    Login Login login = (Login)core.getModule(Login.class);<br> 
    238     *    if (!login.doBasicAuth()) return;<br> 
    239     *    // you are logged in from here<br> 
    240     * %&gt; ... The actual jsp code ..<br> 
    241     * </code> 
    242     * <b>IMPORTANT:</b> this can only work if there is NO CHARACTER OUTPUT before the call of 
    243     * doBasicAuth() (not even whitespace)! 
    244     * @return true if authentication was successfull 
    245     */ 
    246     public boolean doBasicAuth() { 
    247             String realm = ntDomain; 
    248             if (ntDomain == null || ntDomain.length() < 3) 
    249                 realm = core.getApp(); 
    250             if (realm == null) 
    251                 realm = core.getApp(); 
    252             return doBasicAuth(realm); 
    253     } 
    254  
    255     public boolean doBasicAuth(String realm) { 
    256         // in case we are already logged in - skip the rest 
    257         if (core.isLoggedOn()) 
    258             return true; 
    259  
    260         try 
    261         { 
    262         UniAddress dc; 
    263         // always offer Basic too 
    264         boolean offerBasic = true; 
    265         String msg = request.getHeader("Authorization"); 
    266         System.out.println("AUTH - checking header: " + msg);  
    267         if (msg != null && (msg.startsWith("NTLM ") || (offerBasic && msg.startsWith("Basic ")))) { 
    268              
    269             NtlmPasswordAuthentication ntlm; 
    270             if (ntDomainAuth && msg.startsWith("NTLM ")) { 
    271                 dc = UniAddress.getByName(ntDomainController, true); 
    272                 challenge = SmbSession.getChallenge(dc); 
    273                 ntlm = NtlmSsp.authenticate(request, core.getServletResponse(), challenge); 
    274                  
    275                 if (ntlm == null) 
    276                     return false; 
    277             } else { 
    278                  
    279                 // basic auth - decode the username/password 
    280                 String auth = new String(Base64.decode(msg.substring(6)), "ISO-8859-1"); 
    281                 int index = auth.indexOf(':'); 
    282                 String user = (index != -1) ? auth.substring(0, index) : auth; 
    283                 String password = (index != -1) ? auth.substring(index + 1) : ""; 
    284                 index = user.indexOf('\\'); 
    285                 if (index == -1) 
    286                     index = user.indexOf('/'); 
    287                 String domain = (index != -1) ? user.substring(0, index) : ntDomain; 
    288                 user = (index != -1) ? user.substring(index + 1) : user; 
    289                 System.out.println("AUTH: checking for user: " + user); 
    290                 ntlm = new NtlmPasswordAuthentication(domain, user, password); 
    291             } 
    292              
    293              // the the actual login NOW 
    294              loginView.userName = ntlm.getUsername(); 
    295              loginView.userAuth = ntlm.getPassword(); 
    296              System.out.println("AUTH: checking: " + loginView.userAuth + " encryped: " +  core.encryptString(loginView.userAuth));  
    297                  
    298              if (!createLogin()) 
    299              { 
    300                 // ok we got to authenticate again - something did not work as planned 
    301                 if (offerBasic) { 
    302                         core.getServletResponse().addHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\""); 
    303                 } else { 
    304                         core.getServletResponse().setHeader("WWW-Authenticate", "NTLM"); 
    305                 } 
    306                 core.getServletResponse().setHeader("Connection", "close"); 
    307                 core.getServletResponse().setStatus(HttpServletResponse.SC_UNAUTHORIZED); 
    308                 core.getServletResponse().flushBuffer(); 
    309                 return false; 
    310             } 
    311             // login ok 
    312         } else { 
    313             // step 1: authenticate with NTLM and/or Basic 
    314             core.getServletResponse().setHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\""); 
    315             core.getServletResponse().setHeader("Connection", "close"); 
    316             core.getServletResponse().setStatus(HttpServletResponse.SC_UNAUTHORIZED); 
    317             core.getServletResponse().flushBuffer(); 
    318             return false; 
    319         } 
    320         } 
    321         catch (IOException ioe) 
    322         { 
    323             ioe.printStackTrace(); 
    324         } catch (ServletException e) { 
    325             e.printStackTrace(); 
    326         } 
    327         return true; 
    328     } 
    329  
    330     /** 
    331     * Actually Creates the Login 
    332     * @return true if successfull 
    333     */ 
    334     public boolean createLogin() { 
    335         java.util.Date datum = new java.util.Date(); 
    336         try { 
    337             boolean isNtUser = false; 
    338 //            boolean wasNtUser = true; 
    339             if (ntDomainAuth) { 
    340                 NtlmPasswordAuthentication ntlm; 
    341                 if (challenge != null) 
    342                     ntlm = NtlmSsp.authenticate(request, core.getServletResponse(), challenge); 
    343                 else 
    344                     ntlm = new NtlmPasswordAuthentication(ntDomain, loginView.userName, loginView.userAuth); 
    345                 UniAddress dc = UniAddress.getByName(ntDomainController); 
    346                 //Config.setProperty("jcifs.netbios.hostname", "PC0020"); 
    347                 try { 
    348                     SmbSession.logon(dc, ntlm); 
    349                     isNtUser = true; 
    350                 } catch (SmbAuthException sae) { 
    351                     if (sae.getNtStatus() == NtStatus.NT_STATUS_NO_SUCH_USER) { 
    352                         //wasNtUser = false; 
    353                         System.out.println(sae.getMessage()); 
    354                     } 
    355                 } 
    356             } 
    357  
    358             boolean isCorinisUser = false; 
    359  
    360             Element iroot = core.getDoc().createElement("SELECT"); 
    361             Element wheres = core.getDoc().createElement("WHERE"); 
    362  
    363             iroot.appendChild(wheres); 
    364             wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "localusername", loginView.userName)); 
    365             wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", "1")); 
    366  
    367             Element results = usersView.selectEntriesWhereClause(pool, iroot); 
    368  
    369             if (loginView.userAuth != null && !loginView.userAuth.equals("")) { 
    370                 // registered user 
    371                 // Check if username / pw are all right 
    372                 if (results != null) { 
    373                         System.out.println("AUTH: ENCRYPTED PW: " + core.encryptString(loginView.userAuth)); 
    374  
    375                     if (DomUtil.getResultString(results.getFirstChild(), "LOCALUSERAUTH").equals(core.encryptString(loginView.userAuth))) { 
    376                         isCorinisUser = true; 
    377                     } 
    378                 } 
    379             } 
    380  
    381             // ok we use nt authentication 
    382             if (ntDomainAuth) { 
    383                 // we got a valid nt user 
    384                 if (isNtUser) { 
    385                     // but not a valid corinis use 
    386                     if (!isCorinisUser) { 
    387                         // lets see if the user REALLY does not exist 
    388                         if (results == null) { 
    389                             // create him 
    390                             UserManager um = (UserManager)core.getModule(UserManager.class); 
    391                             um.usersView.localusername = loginView.userName; 
    392                             um.usersView.localuserauthconf = um.usersView.localuserauth = loginView.userAuth; 
    393                             um.usersView.needNtAuth = true; 
    394                             //if (uoview.userAuth == null) 
    395                                 um.allowNullPw(); 
    396                             um.skipAuthorityCheck(); 
    397                             um.usersView.createEntry = true;                             
    398                             um.createEntry(); 
    399  
    400                             // requery 
    401                             iroot = core.getDoc().createElement("SELECT"); 
    402                             wheres = core.getDoc().createElement("WHERE"); 
    403  
    404                             iroot.appendChild(wheres); 
    405                             wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "localusername", loginView.userName)); 
    406                             wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", "1")); 
    407  
    408                             results = usersView.selectEntriesWhereClause(pool, iroot); 
    409                              
    410                             isCorinisUser = true; 
    411                             System.out.println("User " + loginView.userName + " created"); 
    412                         } else 
    413                             // he exists, but with the wrong password - bugger: lets change it 
    414                             // make sure to check for chalenge auth (then userAuth is alway null) 
    415                             if (loginView.userAuth != null) 
    416                             { 
    417                              
    418                                 UserManager um = (UserManager)core.getModule(UserManager.class); 
    419                                     um.skipAuthorityCheck(); 
    420                                     um.usersView.changePwd = true; 
    421                                     um.usersView.id = core.getUserIdbyName(loginView.userName); 
    422                                     um.usersView.localuserauth = loginView.userAuth; 
    423                                     um.changePwd(); 
    424                                     isCorinisUser = true; 
    425                                 } 
    426                     } 
    427                 } else { 
    428                     if (isCorinisUser) { 
    429                         // check if we can login altough we are not in the domain 
    430                         if (!DomUtil.getResultBool(results.getFirstChild(), "needntauth")) { 
    431                             isNtUser = true; 
    432                         } //else 
    433                         // ok this used to be a nt user, but now we can delete him 
    434                         // NOT goot untested! rather some zombies than creating a new user every time a wrong pw is entered 
    435                         /*if (!wasNtUser) { 
     103        /** 
     104        *  Inits the class 
     105        * @param score the core class, has to be initialized first 
     106        */ 
     107        public Login(Core score) { 
     108                super(score, "Login"); 
     109        } 
     110 
     111        /** 
     112        * function to get the Authorities needed for this module 
     113        * @return Authority/Description String 
     114        */ 
     115 
     116        public String[][] getModuleAuthorities() { 
     117                return null; 
     118        } 
     119 
     120        /** 
     121        * function to get the Events which are thrown in the module 
     122        * @return Event/Description String 
     123        */ 
     124 
     125        public String[][] getEvents() { 
     126                String[][] s = new String[1][2]; 
     127 
     128                s[0][0] = "createEntry"; 
     129                s[0][1] = "Thrown when a user is logging on"; 
     130 
     131                return s; 
     132        } 
     133 
     134        /* Configuration: 
     135        * * LOGIN 
     136        *   * GUESTUSERS 
     137        *   * ALLOWECMAILLOGIN 
     138        *   * PASSWORDRETRIEVAL 
     139        *   * PASSWORDREPLYNAME 
     140        *   * PASSWORDREPLYEMAIL 
     141        *   * PASSWORDREPLYSUBJECT 
     142        *   * PASSWORDREPLYBODY 
     143        *   * USENTDOMAINAUTH 
     144        *   * DOMAIN 
     145        *   * DOMAINCONTROLLER 
     146        *   * DEFAULTGROUP (multiply) 
     147        */ 
     148        protected void init(Node config) { 
     149                moduleData = uoview = loginView = new UsersOnlineView(core); 
     150                usersView = new UsersView(core); 
     151                dataViews.add(loginView); 
     152                challenge = null; 
     153                //Config.setProperty("jcifs.smb.lmCompatibility", "3"); 
     154 
     155                // Configuration 
     156                guestUserAllowed ="TRUE".equalsIgnoreCase(DomUtil.getResultString(config, "GUESTUSERS")); 
     157 
     158                allowEmailLogin = "TRUE".equalsIgnoreCase(DomUtil.getResultString(config, "ALLOWEMAILLOGIN")); 
     159 
     160                saltPassword = "TRUE".equalsIgnoreCase(DomUtil.getResultString(config, "SALT")); 
     161 
     162                passswordRetrieval = DomUtil.getResultBool(config, "PASSWORDRETRIEVAL"); 
     163                passswordRetrievalReplyName = DomUtil.getResultString(config, "PASSWORDREPLYNAME"); 
     164                passswordRetrievalReplyEMail = DomUtil.getResultString(config, "PASSWORDREPLYEMAIL"); 
     165                passswordRetrievalReplySubject = DomUtil.getResultString(config, "PASSWORDREPLYSUBJECT"); 
     166                passswordRetrievalReplyBody = DomUtil.getResultString(config, "PASSWORDREPLYBODY"); 
     167                if (passswordRetrievalReplyBody == null || "auto".equals(passswordRetrievalReplyBody)) 
     168                { 
     169                        if (core.getServletContext() != null) 
     170                                passswordRetrievalReplyBody = core.getRealPath("/WEB-INF/password.txt"); 
     171                } 
     172 
     173                if (passswordRetrievalReplyBody != null) 
     174                { 
     175                        try 
     176                        { 
     177                                passswordRetrievalReplyBody = FileUtils.file2String(new File(passswordRetrievalReplyBody)); 
     178                                passswordRetrieval = true; 
     179                        } 
     180                        catch (Exception e) 
     181                        { 
     182                                passswordRetrievalReplyBody = "UNABLE TO FIND REPLY BODY - CHECK CONFIGURATION FILE!"; 
     183                        } 
     184                } 
     185 
     186                // basic auth 
     187                basicAuth = "TRUE".equalsIgnoreCase(DomUtil.getResultString(config, "USENTDOMAINAUTH")); 
     188 
     189                // ntlm config 
     190                if ("TRUE".equalsIgnoreCase(DomUtil.getResultString(config, "USENTDOMAINAUTH"))) 
     191                { 
     192                        ntDomainAuth = true; 
     193                        ntDomain = DomUtil.getResultString(config, "DOMAIN"); 
     194                        ntDomainController = DomUtil.getResultString(config, "DOMAINCONTROLLER"); 
     195                        //addGroups = DomUtil.getResultStrings(config, "DEFAULTGROUP"); 
     196                } 
     197                else 
     198                        ntDomainAuth = false; 
     199 
     200        } 
     201 
     202        public boolean verifyUser() { 
     203                Element iroot = core.getDoc().createElement("SELECT"); 
     204                Element wheres = core.getDoc().createElement("WHERE"); 
     205 
     206                iroot.appendChild(wheres); 
     207                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "localusername", loginView.userName)); 
     208                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "verify", loginView.verify)); 
     209                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", 2)); 
     210 
     211                Element results = usersView.selectEntriesWhereClause(pool, iroot); 
     212 
     213                // registered user 
     214                // Check if username / pw are all right 
     215                if (results != null) { 
     216                        Element cur = (Element) results.getFirstChild(); 
     217                        iroot = core.getDoc().createElement("UPDATE"); 
     218 
     219                        iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", DomUtil.getResultString(cur, "LOCALUSERID"))); 
     220                        iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "VERIFY", "")); 
     221                        iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", String.valueOf(1))); 
     222                        usersView.updateEntry(pool, iroot); 
     223                        return true; 
     224                } 
     225                return false; 
     226        } 
     227 
     228        /** 
     229        * Creates an Authenticated based on Basic or NTLM auth. This creates a login box in 
     230        * Browser (or if using NTLM not in IE). Applications using this functions 
     231        * do NOT allow guest logins! <br> 
     232        * Usage:<br> 
     233        * <code> 
     234        * &lt;%@ page language="java" import="corinis.*,corinis.modules.*,..." %&gt;&lt;% 
     235        *   // init the core module<br> 
     236        *    Core core = new Core ("applicationname", request, response, getServletContext());<br> 
     237        *    Login Login login = (Login)core.getModule(Login.class);<br> 
     238        *    if (!login.doBasicAuth()) return;<br> 
     239        *    // you are logged in from here<br> 
     240        * %&gt; ... The actual jsp code ..<br> 
     241        * </code> 
     242        * <b>IMPORTANT:</b> this can only work if there is NO CHARACTER OUTPUT before the call of 
     243        * doBasicAuth() (not even whitespace)! 
     244        * @return true if authentication was successfull 
     245        */ 
     246        public boolean doBasicAuth() { 
     247                String realm = ntDomain; 
     248                if (ntDomain == null || ntDomain.length() < 3) 
     249                        realm = core.getApp(); 
     250                if (realm == null) 
     251                        realm = core.getApp(); 
     252                return doBasicAuth(realm); 
     253        } 
     254 
     255        public boolean doBasicAuth(String realm) { 
     256                // in case we are already logged in - skip the rest 
     257                if (core.isLoggedOn()) 
     258                        return true; 
     259 
     260                try 
     261                { 
     262                        UniAddress dc; 
     263                        // always offer Basic too 
     264                        boolean offerBasic = true; 
     265                        String msg = request.getHeader("Authorization"); 
     266                        System.out.println("AUTH - checking header: " + msg);  
     267                        if (msg != null && (msg.startsWith("NTLM ") || (offerBasic && msg.startsWith("Basic ")))) { 
     268 
     269                                NtlmPasswordAuthentication ntlm; 
     270                                if (ntDomainAuth && msg.startsWith("NTLM ")) { 
     271                                        dc = UniAddress.getByName(ntDomainController, true); 
     272                                        challenge = SmbSession.getChallenge(dc); 
     273                                        ntlm = NtlmSsp.authenticate(request, core.getServletResponse(), challenge); 
     274 
     275                                        if (ntlm == null) 
     276                                                return false; 
     277                                } else { 
     278 
     279                                        // basic auth - decode the username/password 
     280                                        String auth = new String(Base64.decode(msg.substring(6)), "ISO-8859-1"); 
     281                                        int index = auth.indexOf(':'); 
     282                                        String user = (index != -1) ? auth.substring(0, index) : auth; 
     283                                        String password = (index != -1) ? auth.substring(index + 1) : ""; 
     284                                        index = user.indexOf('\\'); 
     285                                        if (index == -1) 
     286                                                index = user.indexOf('/'); 
     287                                        String domain = (index != -1) ? user.substring(0, index) : ntDomain; 
     288                                        user = (index != -1) ? user.substring(index + 1) : user; 
     289                                        System.out.println("AUTH: checking for user: " + user); 
     290                                        ntlm = new NtlmPasswordAuthentication(domain, user, password); 
     291                                } 
     292 
     293                                // the the actual login NOW 
     294                                loginView.userName = ntlm.getUsername(); 
     295                                loginView.userAuth = ntlm.getPassword(); 
     296                                System.out.println("AUTH: checking: " + loginView.userAuth + " encryped: " +  core.encryptString(loginView.userAuth));  
     297 
     298                                if (!createLogin()) 
     299                                { 
     300                                        // ok we got to authenticate again - something did not work as planned 
     301                                        if (offerBasic) { 
     302                                                core.getServletResponse().addHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\""); 
     303                                        } else { 
     304                                                core.getServletResponse().setHeader("WWW-Authenticate", "NTLM"); 
     305                                        } 
     306                                        core.getServletResponse().setHeader("Connection", "close"); 
     307                                        core.getServletResponse().setStatus(HttpServletResponse.SC_UNAUTHORIZED); 
     308                                        core.getServletResponse().flushBuffer(); 
     309                                        return false; 
     310                                } 
     311                                // login ok 
     312                        } else { 
     313                                // step 1: authenticate with NTLM and/or Basic 
     314                                core.getServletResponse().setHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\""); 
     315                                core.getServletResponse().setHeader("Connection", "close"); 
     316                                core.getServletResponse().setStatus(HttpServletResponse.SC_UNAUTHORIZED); 
     317                                core.getServletResponse().flushBuffer(); 
     318                                return false; 
     319                        } 
     320                } 
     321                catch (IOException ioe) 
     322                { 
     323                        ioe.printStackTrace(); 
     324                } catch (ServletException e) { 
     325                        e.printStackTrace(); 
     326                } 
     327                return true; 
     328        } 
     329 
     330        /** 
     331        * Actually Creates the Login 
     332        * @return true if successfull 
     333        */ 
     334        public boolean createLogin() { 
     335                java.util.Date datum = new java.util.Date(); 
     336                try { 
     337                        boolean isNtUser = false; 
     338                        //            boolean wasNtUser = true; 
     339                        if (ntDomainAuth) { 
     340                                NtlmPasswordAuthentication ntlm; 
     341                                if (challenge != null) 
     342                                        ntlm = NtlmSsp.authenticate(request, core.getServletResponse(), challenge); 
     343                                else 
     344                                        ntlm = new NtlmPasswordAuthentication(ntDomain, loginView.userName, loginView.userAuth); 
     345                                UniAddress dc = UniAddress.getByName(ntDomainController); 
     346                                //Config.setProperty("jcifs.netbios.hostname", "PC0020"); 
     347                                try { 
     348                                        SmbSession.logon(dc, ntlm); 
     349                                        isNtUser = true; 
     350                                } catch (SmbAuthException sae) { 
     351                                        if (sae.getNtStatus() == NtStatus.NT_STATUS_NO_SUCH_USER) { 
     352                                                //wasNtUser = false; 
     353                                                System.out.println(sae.getMessage()); 
     354                                        } 
     355                                } 
     356                        } 
     357 
     358                        boolean isCorinisUser = false; 
     359 
     360                        Element iroot = core.getDoc().createElement("SELECT"); 
     361                        Element wheres = core.getDoc().createElement("WHERE"); 
     362 
     363                        iroot.appendChild(wheres); 
     364                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "localusername", loginView.userName)); 
     365                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", "1")); 
     366 
     367                        Element results = usersView.selectEntriesWhereClause(pool, iroot); 
     368 
     369                        if (loginView.userAuth != null && !loginView.userAuth.equals("")) { 
     370                                // registered user 
     371                                // Check if username / pw are all right 
     372                                if (results != null) { 
     373                                        System.out.println("AUTH: ENCRYPTED PW: " + core.encryptString(loginView.userAuth)); 
     374 
     375                                        if (DomUtil.getResultString(results.getFirstChild(), "LOCALUSERAUTH").equals(core.encryptString(loginView.userAuth))) { 
     376                                                isCorinisUser = true; 
     377                                        } 
     378                                } 
     379                        } 
     380 
     381                        // ok we use nt authentication 
     382                        if (ntDomainAuth) { 
     383                                // we got a valid nt user 
     384                                if (isNtUser) { 
     385                                        // but not a valid corinis use 
     386                                        if (!isCorinisUser) { 
     387                                                // lets see if the user REALLY does not exist 
     388                                                if (results == null) { 
     389                                                        // create him 
     390                                                        UserManager um = (UserManager)core.getModule(UserManager.class); 
     391                                                        um.usersView.localusername = loginView.userName; 
     392                                                        um.usersView.localuserauthconf = um.usersView.localuserauth = loginView.userAuth; 
     393                                                        um.usersView.needNtAuth = true; 
     394                                                        //if (uoview.userAuth == null) 
     395                                                        um.allowNullPw(); 
     396                                                        um.skipAuthorityCheck(); 
     397                                                        um.usersView.createEntry = true;                             
     398                                                        um.createEntry(); 
     399 
     400                                                        // requery 
     401                                                        iroot = core.getDoc().createElement("SELECT"); 
     402                                                        wheres = core.getDoc().createElement("WHERE"); 
     403 
     404                                                        iroot.appendChild(wheres); 
     405                                                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "localusername", loginView.userName)); 
     406                                                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", "1")); 
     407 
     408                                                        results = usersView.selectEntriesWhereClause(pool, iroot); 
     409 
     410                                                        isCorinisUser = true; 
     411                                                        System.out.println("User " + loginView.userName + " created"); 
     412                                                } else 
     413                                                        // he exists, but with the wrong password - bugger: lets change it 
     414                                                        // make sure to check for chalenge auth (then userAuth is alway null) 
     415                                                        if (loginView.userAuth != null) 
     416                                                        { 
     417 
     418                                                                UserManager um = (UserManager)core.getModule(UserManager.class); 
     419                                                                um.skipAuthorityCheck(); 
     420                                                                um.usersView.changePwd = true; 
     421                                                                um.usersView.id = core.getUserIdbyName(loginView.userName); 
     422                                                                um.usersView.localuserauth = loginView.userAuth; 
     423                                                                um.changePwd(); 
     424                                                                isCorinisUser = true; 
     425                                                        } 
     426                                        } 
     427                                } else { 
     428                                        if (isCorinisUser) { 
     429                                                // check if we can login altough we are not in the domain 
     430                                                if (!DomUtil.getResultBool(results.getFirstChild(), "needntauth")) { 
     431                                                        isNtUser = true; 
     432                                                } //else 
     433                                                // ok this used to be a nt user, but now we can delete him 
     434                                                // NOT goot untested! rather some zombies than creating a new user every time a wrong pw is entered 
     435                                                /*if (!wasNtUser) { 
    436436                            UserManager UserManager um = (UserManager)core.getModule(UserManager.class); 
    437437                            um.skipAuthorityCheck(); 
     
    442442                            isCorinisUser = false; 
    443443                        }*/ 
    444                     } 
    445                 } 
    446  
    447             } 
    448             // ok this is valid normal 
    449             if (isCorinisUser && (!ntDomainAuth || isNtUser)) { 
    450                 Element cur = (Element) results.getFirstChild(); 
    451                 // logon user 
    452                 String remc = null; 
    453                 // get a random string 
    454                 remc = Utils.randomString(50); 
    455  
    456                 // set a cookie with that and the user name 
    457                 Cookie remcookie = new Cookie("autologin", remc); 
    458                 remcookie.setMaxAge(3600 * 24 * 1000); 
    459                 core.getServletResponse().addCookie(remcookie); 
    460                 remcookie = new Cookie("loginname", DomUtil.getResultString(cur, "LOCALUSERNAME")); 
    461                 remcookie.setMaxAge(3600 * 24 * 1000); 
    462                 core.getServletResponse().addCookie(remcookie); 
    463  
    464                 // create insert tree 
    465                 iroot = core.getDoc().createElement("USER"); 
    466  
    467                 iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", DomUtil.getResultString(cur, "LOCALUSERID"))); 
    468                 iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "COUNTLOGINS", String.valueOf(DomUtil.getResultLong(cur, "COUNTLOGINS") + 1))); 
    469                 iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "AUTOLOGIN", remc)); 
    470                 iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LASTLOGIN", String.valueOf(datum.getTime()))); 
    471                 usersView.updateEntry(pool, iroot); 
    472  
    473                 // create session object 
    474                 core.getSession().activateMe(DomUtil.getResultString(cur, "LOCALUSERNAME"), DomUtil.getResultString(cur, "LOCALUSERID")); 
    475  
    476                  
    477                 return true; 
    478             } 
    479         } catch (Exception e) { 
    480             // not used here 
    481         } 
    482         return false; 
    483     } 
    484  
    485     /** 
    486     * Helper function to se the username. 
    487     * This is the same as loginView.userName = user 
    488     * @param user the user 
    489     */ 
    490     public void setUser(String user) { 
    491         loginView.userName = user; 
    492     } 
    493  
    494     /** 
    495     * Helper function to se the password. 
    496     * This is the same as loginView.userAuth = pass 
    497     * @param pass the password 
    498     */ 
    499     public void setPass(String pass) { 
    500         loginView.userAuth = pass; 
    501     } 
    502      
    503     /** 
    504     * Sends a password to the email associated with a user. 
    505     * Make sure it is enabled a configurated in the xml. 
    506     * @return sucesstree 
    507     */ 
    508     public Element sendPassword () { 
    509         // logged in - no password 
    510         if (core.isLoggedOn() || !passswordRetrieval) 
    511                 return null; 
    512          
    513         // get the user id 
    514         String[] parameter = { "username"}; 
    515  
    516         ArrayList<String> al = loginView.generateVariableResponseTree(parameter); 
    517  
    518         if (al != null) 
    519             return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
    520  
    521         Element iroot = core.getDoc().createElement("SELECT"); 
    522         Element wheres = core.getDoc().createElement("WHERE"); 
    523  
    524         iroot.appendChild(wheres); 
    525         wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "localusername", loginView.userName)); 
    526         wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", "1")); 
    527  
    528         Element results = usersView.selectEntriesWhereClause(pool, iroot); 
    529          
    530         if (results == null || !DomUtil.getResultString(results.getFirstChild(), "EMAIL").matches("^.+@([a-zA-Z0-9_-])+.[a-zA-Z]{2,10}+")) 
    531             return eventer.nosuccess(Eventer.INCORRECT_FIELD_VALUE, "email"); 
    532          
    533         // generatte and set the new password 
    534         String password = new Generator().generate(); 
    535          
    536         // set the new password 
    537         usersView.startChange(this); 
    538          
    539         // update Entry 
    540         iroot = core.getDoc().createElement("USER"); 
    541         iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", DomUtil.getResultString(results.getFirstChild(), "LOCALUSERID"))); 
    542         iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERAUTH", core.encryptString(password))); 
    543          
    544         usersView.updateEntry(pool, iroot); 
    545         usersView.commitChange(this); 
    546          
    547         // now send the password by email 
    548         String s = Utils.replaceString(passswordRetrievalReplyBody, "&password;", password); 
    549         try { 
     444                                        } 
     445                                } 
     446 
     447                        } 
     448                        // ok this is valid normal 
     449                        if (isCorinisUser && (!ntDomainAuth || isNtUser)) { 
     450                                Element cur = (Element) results.getFirstChild(); 
     451                                // logon user 
     452                                String remc = null; 
     453                                // get a random string 
     454                                remc = Utils.randomString(50); 
     455 
     456                                // set a cookie with that and the user name 
     457                                Cookie remcookie = new Cookie("autologin", remc); 
     458                                remcookie.setMaxAge(3600 * 24 * 1000); 
     459                                core.getServletResponse().addCookie(remcookie); 
     460                                remcookie = new Cookie("loginname", DomUtil.getResultString(cur, "LOCALUSERNAME")); 
     461                                remcookie.setMaxAge(3600 * 24 * 1000); 
     462                                core.getServletResponse().addCookie(remcookie); 
     463 
     464                                // create insert tree 
     465                                iroot = core.getDoc().createElement("USER"); 
     466 
     467                                iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", DomUtil.getResultString(cur, "LOCALUSERID"))); 
     468                                iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "COUNTLOGINS", String.valueOf(DomUtil.getResultLong(cur, "COUNTLOGINS") + 1))); 
     469                                iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "AUTOLOGIN", remc)); 
     470                                iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LASTLOGIN", String.valueOf(datum.getTime()))); 
     471                                usersView.updateEntry(pool, iroot); 
     472 
     473                                // create session object 
     474                                core.getSession().activateMe(DomUtil.getResultString(cur, "LOCALUSERNAME"), DomUtil.getResultString(cur, "LOCALUSERID")); 
     475 
     476 
     477                                return true; 
     478                        } 
     479                } catch (Exception e) { 
     480                        // not used here 
     481                } 
     482                return false; 
     483        } 
     484 
     485        /** 
     486        * Helper function to se the username. 
     487        * This is the same as loginView.userName = user 
     488        * @param user the user 
     489        */ 
     490        public void setUser(String user) { 
     491                loginView.userName = user; 
     492        } 
     493 
     494        /** 
     495        * Helper function to se the password. 
     496        * This is the same as loginView.userAuth = pass 
     497        * @param pass the password 
     498        */ 
     499        public void setPass(String pass) { 
     500                loginView.userAuth = pass; 
     501        } 
     502 
     503        /** 
     504        * Sends a password to the email associated with a user. 
     505        * Make sure it is enabled a configurated in the xml. 
     506        * @return sucesstree 
     507        */ 
     508        public Element sendPassword () { 
     509                // logged in - no password 
     510                if (core.isLoggedOn() || !passswordRetrieval) 
     511                        return null; 
     512 
     513                // get the user id 
     514                String[] parameter = { "username"}; 
     515 
     516                ArrayList<String> al = loginView.generateVariableResponseTree(parameter); 
     517 
     518                if (al != null) 
     519                        return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
     520 
     521                Element iroot = core.getDoc().createElement("SELECT"); 
     522                Element wheres = core.getDoc().createElement("WHERE"); 
     523 
     524                iroot.appendChild(wheres); 
     525                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "localusername", loginView.userName)); 
     526                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", "1")); 
     527 
     528                Element results = usersView.selectEntriesWhereClause(pool, iroot); 
     529 
     530                if (results == null || !DomUtil.getResultString(results.getFirstChild(), "EMAIL").matches("^.+@([a-zA-Z0-9_-])+.[a-zA-Z]{2,10}+")) 
     531                        return eventer.nosuccess(Eventer.INCORRECT_FIELD_VALUE, "email"); 
     532 
     533                // generatte and set the new password 
     534                String password = new Generator().generate(); 
     535 
     536                // set the new password 
     537                usersView.startChange(this); 
     538 
     539                // update Entry 
     540                iroot = core.getDoc().createElement("USER"); 
     541                iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", DomUtil.getResultString(results.getFirstChild(), "LOCALUSERID"))); 
     542                iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERAUTH", core.encryptString(password))); 
     543 
     544                usersView.updateEntry(pool, iroot); 
     545                usersView.commitChange(this); 
     546 
     547                // now send the password by email 
     548                String s = Utils.replaceString(passswordRetrievalReplyBody, "&password;", password); 
     549                try { 
    550550                        SendMail.createEntryExternal(passswordRetrievalReplyName, passswordRetrievalReplyEMail,  
    551551                                        DomUtil.getResultString(results.getFirstChild(), "EMAIL"),  
     
    555555                } 
    556556 
    557         return eventer.success(); 
    558     } 
    559  
    560  
    561     /** 
    562     * Logs the current user out 
    563     * @return the parsed xml tree 
    564     */ 
    565     public Element deleteEntry() { 
    566         if (loginView == null) { 
    567             return null; 
    568         } 
    569         if (!loginView.deleteEntry) 
    570             return null; 
    571  
    572         if (!core.isLoggedOn()) 
    573             return null; 
    574  
    575         // remove autologin cookie and from the db 
    576         Element iroot = core.getDoc().createElement("UPDATE"); 
    577  
    578         iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", core.getUserId())); 
    579         iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "AUTOLOGIN", "")); 
    580         usersView.updateEntry(pool, iroot); 
    581  
    582         // build the tree 
    583          
    584         core.getSession().deactivateMe(); 
    585         return eventer.success(); 
    586     } 
    587  
    588     /** 
    589     * Logs in using a unique key stored in a cookie. 
    590     * @return true if login successfull 
    591     */ 
    592     public boolean createAutoLogin() { 
    593         // get some cookie stuff :) 
    594         Cookie[] ck = request.getCookies(); 
    595         String autocookie = null; 
    596         String cookiename = null; 
     557                return eventer.success(); 
     558        } 
     559 
     560 
     561        /** 
     562        * Logs the current user out 
     563        * @return the parsed xml tree 
     564        */ 
     565        public Element deleteEntry() { 
     566                if (loginView == null) { 
     567                        return null; 
     568                } 
     569                if (!loginView.deleteEntry) 
     570                        return null; 
     571 
     572                if (!core.isLoggedOn()) 
     573                        return null; 
     574 
     575                // remove autologin cookie and from the db 
     576                Element iroot = core.getDoc().createElement("UPDATE"); 
     577 
     578                iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", core.getUserId())); 
     579                iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "AUTOLOGIN", "")); 
     580                usersView.updateEntry(pool, iroot); 
     581 
     582                // build the tree 
     583 
     584                core.getSession().deactivateMe(); 
     585                return eventer.success(); 
     586        } 
     587 
     588        /** 
     589        * Logs in using a unique key stored in a cookie. 
     590        * @return true if login successfull 
     591        */ 
     592        public boolean createAutoLogin() { 
     593                // get some cookie stuff :) 
     594                Cookie[] ck = request.getCookies(); 
     595                String autocookie = null; 
     596                String cookiename = null; 
    597597                if (ck == null) 
    598598                        return false; 
    599                          
    600         for (int i = 0; i < ck.length; i++) { 
    601             if (ck[i].getName().equals("loginname")) { 
    602                 cookiename = ck[i].getValue(); 
    603             } else if (ck[i].getName().equals("autologin")) { 
    604                 autocookie = ck[i].getValue(); 
    605             } 
    606         } 
    607  
    608         // no autologin cookie 
    609         if (cookiename == null || autocookie == null) 
    610             return false; 
    611  
    612         if (autocookie.length() < 40) 
    613             return false; 
    614  
    615         Element iroot = core.getDoc().createElement("SELECT"); 
    616         Element wheres = core.getDoc().createElement("WHERE"); 
    617  
    618         iroot.appendChild(wheres); 
    619         wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERNAME", cookiename)); 
    620         wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "AUTOLOGIN", autocookie)); 
    621  
    622         Element results = usersView.selectEntriesWhereClause(pool, iroot); 
    623         if (results != null) { 
    624             // logon user 
    625             // create insert tree 
    626             iroot = core.getDoc().createElement("UPDATE"); 
    627  
    628             iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", DomUtil.getResultString(results.getFirstChild(), "LOCALUSERID"))); 
    629             iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "COUNTLOGINS", String.valueOf(Utils.parseLong(DomUtil.getResultString(results.getFirstChild(), "COUNTLOGINS")) + 1))); 
    630             iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LASTLOGIN", String.valueOf(new java.util.Date().getTime()))); 
    631             usersView.updateEntry(pool, iroot); 
    632  
    633             // create session object 
    634             session.setUserId(DomUtil.getResultLong(results.getFirstChild(), "LOCALUSERID")); 
    635             session.setUserName(DomUtil.getResultString(results.getFirstChild(), "LOCALUSERNAME")); 
    636             session.setUserState(CorinisSession.ONLINE); 
    637             session.activateMe(); 
    638  
    639             return true; 
    640         } 
    641         return false; 
    642     } 
    643  
    644     /** 
    645     * Logs a user in. 
    646     * 
    647     */ 
    648     public Element createEntry() { 
    649         if (!loginView.createEntry) 
    650             return null; 
    651  
    652         if (core.isLoggedOn()) 
    653             return null; 
    654  
    655         String[] parameter = { "username"}; 
    656  
    657         try { 
    658             ArrayList<String> al = loginView.generateVariableResponseTree(parameter); 
    659  
    660             if (al != null) 
    661                 return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
    662  
    663             // check if we find the username 
    664             Element iroot = core.getDoc().createElement("SELECT"); 
    665             Element wheres = core.getDoc().createElement("WHERE"); 
    666  
    667             iroot.appendChild(wheres); 
    668             // check the email if email is given 
    669             if (allowEmailLogin && loginView.userName.matches("^.+@([a-zA-Z0-9_-])+.[a-zA-Z]{2,10}+")) 
    670                 wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "email", loginView.userName)); 
    671             else 
    672                 wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "localusername", loginView.userName)); 
    673             wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", "1")); 
    674  
    675             Element results = usersView.selectEntriesWhereClause(pool, iroot); 
    676  
    677             if (loginView.userAuth != null && !loginView.userAuth.equals("")) { 
    678                 // registered user 
    679                 // Check if username / pw are all right 
    680                 if (results != null) { 
    681                     Element cur = (Element) results.getFirstChild(); 
    682                     if (DomUtil.getResultString(cur, "LOCALUSERAUTH").startsWith(core.encryptString(loginView.userAuth))) { 
    683                         // set remember cookie 
    684                         String remc = null; 
    685                         if (loginView.remember && core.getServletResponse() != null) { 
    686                             // get a random string 
    687                             remc = Utils.randomString(50); 
    688  
    689                             // set a cookie with that and the user name 
    690                             Cookie remcookie = new Cookie("autologin", remc); 
    691                             remcookie.setMaxAge(3600 * 24 * 100); 
    692                             core.getServletResponse().addCookie(remcookie); 
    693                             remcookie = new Cookie("loginname", DomUtil.getResultString(cur, "LOCALUSERNAME")); 
    694                             remcookie.setMaxAge(3600 * 24 * 100); 
    695                             core.getServletResponse().addCookie(remcookie); 
    696                         } 
    697  
    698                         // logon user 
    699                         // create insert tree 
    700                         iroot = core.getDoc().createElement("USER"); 
    701  
    702                         iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", DomUtil.getResultString(cur, "LOCALUSERID"))); 
    703                         iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "COUNTLOGINS", String.valueOf(Utils.parseLong(DomUtil.getResultString(cur, "COUNTLOGINS")) + 1))); 
    704                         iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LASTLOGIN", System.currentTimeMillis())); 
    705                         if (remc != null) { 
    706                             iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "AUTOLOGIN", remc)); 
    707                         } 
    708                         usersView.updateEntry(pool, iroot); 
    709  
    710                         // create session object 
    711                         System.out.println("Creating session..."); 
    712                         session.setUserId(DomUtil.getResultLong(cur, "LOCALUSERID")); 
    713                         session.setUserName(DomUtil.getResultString(cur, "LOCALUSERNAME")); 
    714                         session.setUserState(CorinisSession.ONLINE); 
    715                         session.activateMe(DomUtil.getResultString(cur, "LOCALUSERNAME"), DomUtil.getResultString(cur, "LOCALUSERID")); 
    716  
    717                         return eventer.success(); 
    718  
    719                     } 
    720                     core.printLog(" INVALID PASSWORD FROM IP " + core.getUserIP() + ": User " + DomUtil.getResultString(results.getFirstChild(), "LOCALUSERNAME") + " Password:" + loginView.userAuth + " - " + core.encryptString(loginView.userAuth) + " vs. " + DomUtil.getResultString(cur, "LOCALUSERAUTH"), null, Core.LOG_DEBUG); 
    721                     return eventer.nosuccess(Eventer.INCORRECT_FIELD_VALUE, "Username/Password"); 
    722                 } 
    723                 core.printLog("INVALID USER FROM IP " + core.getUserIP() + ": User " + loginView.userName + " Password:" + loginView.userAuth, null, Core.LOG_DEBUG); 
    724                 return eventer.nosuccess(Eventer.LOGIN_WRONG_FREEZED); 
    725  
    726             } 
    727             if (results != null) 
    728                 return eventer.nosuccess(Eventer.ENTRY_ALREADY_EXISTS,"Username"); 
    729             if (guestUserAllowed) 
    730                 core.getSession().activateMe(loginView.userName, "1"); 
    731             else 
    732                 return eventer.nosuccess(Eventer.INCORRECT_FIELD_VALUE, "Username/Password"); 
    733         } catch (Exception e) { 
    734             eventer.fatalError(e.getMessage()); 
    735             e.printStackTrace(); 
    736         } 
    737  
    738         return null; 
    739     } 
    740  
    741     /** 
    742     * Help function that returns hidden fields 
    743     * required for forms. 
    744     * 
    745     * @return the Html form fields 
    746     */ 
    747     public String getHiddenFields() { 
    748         return ""; 
    749     } 
    750  
    751     /* (non-Javacore.getDoc()) 
    752     * @see corinis.modules.interfaces.IEntry#getElement(long) 
    753     */ 
    754     public Element getEntry() { 
    755         return null; 
    756     } 
    757  
    758     /* (non-Javacore.getDoc()) 
    759     * @see corinis.modules.abstracts.Module#getEntries() 
    760     */ 
    761     public Element getEntries() { 
    762         return null; 
    763     } 
     599 
     600                for (int i = 0; i < ck.length; i++) { 
     601                        if (ck[i].getName().equals("loginname")) { 
     602                                cookiename = ck[i].getValue(); 
     603                        } else if (ck[i].getName().equals("autologin")) { 
     604                                autocookie = ck[i].getValue(); 
     605                        } 
     606                } 
     607 
     608                // no autologin cookie 
     609                if (cookiename == null || autocookie == null) 
     610                        return false; 
     611 
     612                if (autocookie.length() < 40) 
     613                        return false; 
     614 
     615                Element iroot = core.getDoc().createElement("SELECT"); 
     616                Element wheres = core.getDoc().createElement("WHERE"); 
     617 
     618                iroot.appendChild(wheres); 
     619                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERNAME", cookiename)); 
     620                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "AUTOLOGIN", autocookie)); 
     621 
     622                Element results = usersView.selectEntriesWhereClause(pool, iroot); 
     623                if (results != null) { 
     624                        // logon user 
     625                        // create insert tree 
     626                        iroot = core.getDoc().createElement("UPDATE"); 
     627 
     628                        iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", DomUtil.getResultString(results.getFirstChild(), "LOCALUSERID"))); 
     629                        iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "COUNTLOGINS", String.valueOf(Utils.parseLong(DomUtil.getResultString(results.getFirstChild(), "COUNTLOGINS")) + 1))); 
     630                        iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LASTLOGIN", String.valueOf(new java.util.Date().getTime()))); 
     631                        usersView.updateEntry(pool, iroot); 
     632 
     633                        // create session object 
     634                        session.setUserId(DomUtil.getResultLong(results.getFirstChild(), "LOCALUSERID")); 
     635                        session.setUserName(DomUtil.getResultString(results.getFirstChild(), "LOCALUSERNAME")); 
     636                        session.setUserState(CorinisSession.ONLINE); 
     637                        session.activateMe(); 
     638 
     639                        return true; 
     640                } 
     641                return false; 
     642        } 
     643 
     644        /** 
     645        * Logs a user in. 
     646        * 
     647        */ 
     648        public Element createEntry() { 
     649                if (!loginView.createEntry) 
     650                        return null; 
     651 
     652                if (core.isLoggedOn()) 
     653                        return null; 
     654 
     655                String[] parameter = { "username"}; 
     656 
     657                try { 
     658                        ArrayList<String> al = loginView.generateVariableResponseTree(parameter); 
     659 
     660                        if (al != null) 
     661                                return eventer.nosuccess(Eventer.FIELD_MISSING, al); 
     662 
     663                        // check if we find the username 
     664                        Element iroot = core.getDoc().createElement("SELECT"); 
     665                        Element wheres = core.getDoc().createElement("WHERE"); 
     666 
     667                        iroot.appendChild(wheres); 
     668                        // check the email if email is given 
     669                        if (allowEmailLogin && loginView.userName.matches("^.+@([a-zA-Z0-9_-])+.[a-zA-Z]{2,10}+")) 
     670                                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "email", loginView.userName)); 
     671                        else 
     672                                wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "localusername", loginView.userName)); 
     673                        wheres.appendChild(DomUtil.CreateNode(core.getDoc(), "activestatus", "1")); 
     674 
     675                        Element results = usersView.selectEntriesWhereClause(pool, iroot); 
     676 
     677                        if (loginView.userAuth != null && !loginView.userAuth.equals("")) { 
     678                                // registered user 
     679                                // Check if username / pw are all right 
     680                                if (results != null) { 
     681                                        Element cur = (Element) results.getFirstChild(); 
     682                                        if (DomUtil.getResultString(cur, "LOCALUSERAUTH").startsWith(core.encryptString(loginView.userAuth))) { 
     683                                                // set remember cookie 
     684                                                String remc = null; 
     685                                                if (loginView.remember && core.getServletResponse() != null) { 
     686                                                        // get a random string 
     687                                                        remc = Utils.randomString(50); 
     688 
     689                                                        // set a cookie with that and the user name 
     690                                                        Cookie remcookie = new Cookie("autologin", remc); 
     691                                                        remcookie.setMaxAge(3600 * 24 * 100); 
     692                                                        core.getServletResponse().addCookie(remcookie); 
     693                                                        remcookie = new Cookie("loginname", DomUtil.getResultString(cur, "LOCALUSERNAME")); 
     694                                                        remcookie.setMaxAge(3600 * 24 * 100); 
     695                                                        core.getServletResponse().addCookie(remcookie); 
     696                                                } 
     697 
     698                                                // logon user 
     699                                                // create insert tree 
     700                                                iroot = core.getDoc().createElement("USER"); 
     701 
     702                                                iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LOCALUSERID", DomUtil.getResultString(cur, "LOCALUSERID"))); 
     703                                                iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "COUNTLOGINS", String.valueOf(Utils.parseLong(DomUtil.getResultString(cur, "COUNTLOGINS")) + 1))); 
     704                                                iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "LASTLOGIN", System.currentTimeMillis())); 
     705                                                if (remc != null) { 
     706                                                        iroot.appendChild(DomUtil.CreateNode(core.getDoc(), "AUTOLOGIN", remc)); 
     707                                                } 
     708                                                usersView.updateEntry(pool, iroot); 
     709 
     710                                                // create session object 
     711                                                System.out.println("Creating session..."); 
     712                                                session.setUserId(DomUtil.getResultLong(cur, "LOCALUSERID")); 
     713                                                session.setUserName(DomUtil.getResultString(cur, "LOCALUSERNAME")); 
     714                                                session.setUserState(CorinisSession.ONLINE); 
     715                                                session.activateMe(DomUtil.getResultString(cur, "LOCALUSERNAME"), DomUtil.getResultString(cur, "LOCALUSERID")); 
     716 
     717                                                return eventer.success(); 
     718 
     719                                        } 
     720                                        core.printLog(" INVALID PASSWORD FROM IP " + core.getUserIP() + ": User " + DomUtil.getResultString(results.getFirstChild(), "LOCALUSERNAME") + " Password:" + loginView.userAuth + " - " + core.encryptString(loginView.userAuth) + " vs. " + DomUtil.getResultString(cur, "LOCALUSERAUTH"), null, Core.LOG_DEBUG); 
     721                                        return eventer.nosuccess(Eventer.INCORRECT_FIELD_VALUE, "Username/Password"); 
     722                                } 
     723                                core.printLog("INVALID USER FROM IP " + core.getUserIP() + ": User " + loginView.userName + " Password:" + loginView.userAuth, null, Core.LOG_DEBUG); 
     724                                return eventer.nosuccess(Eventer.LOGIN_WRONG_FREEZED); 
     725 
     726                        } 
     727                        if (results != null) 
     728                                return eventer.nosuccess(Eventer.ENTRY_ALREADY_EXISTS,"Username"); 
     729                        if (guestUserAllowed) 
     730                                core.getSession().activateMe(loginView.userName, "1"); 
     731                        else 
     732                                return eventer.nosuccess(Eventer.INCORRECT_FIELD_VALUE, "Username/Password"); 
     733                } catch (Exception e) { 
     734                        eventer.fatalError(e.getMessage()); 
     735                        e.printStackTrace(); 
     736                } 
     737 
     738                return null; 
     739        } 
     740 
     741        /** 
     742        * Help function that returns hidden fields 
     743        * required for forms. 
     744        * 
     745        * @return the Html form fields 
     746        */ 
     747        public String getHiddenFields() { 
     748                return ""; 
     749        } 
     750 
     751        /* (non-Javacore.getDoc()) 
     752        * @see corinis.modules.interfaces.IEntry#getElement(long) 
     753        */ 
     754        public Element getEntry() { 
     755                return null; 
     756        } 
     757 
     758        /* (non-Javacore.getDoc()) 
     759        * @see corinis.modules.abstracts.Module#getEntries() 
     760        */ 
     761        public Element getEntries() { 
     762                return null; 
     763        } 
    764764} 
  • Core/trunk/src/main/java/corinis/util/images/Thumbnailer.java

    r659 r660  
    5353{ 
    5454 
    55   public static final String TYPE_JPEG = "image/jpeg"; 
    56   public static final String TYPE_GIF = "image/gif"; 
    57   public static final String TYPE_PNG = "image/png"; 
    58   public static final String TYPE_BMP = "image/x-bmp"; 
    59    
    60   public static final String TYPE_VIDEO = "video/flv"; 
    61  
    62     public Thumbnailer(){ 
    63         // basic init 
    64     } 
    65  
    66     // This method returns true if the specified image has transparent pixels 
    67     public static boolean hasAlpha(Image image) { 
    68         // If buffered image, the color model is readily available 
    69         if (image instanceof BufferedImage) { 
    70             BufferedImage bimage = (BufferedImage)image; 
    71             return bimage.getColorModel().hasAlpha(); 
    72         } 
    73  
    74         // Use a pixel grabber to retrieve the image's color model; 
    75         // grabbing a single pixel is usually sufficient 
    76          PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); 
    77         try { 
    78             pg.grabPixels(); 
    79         } catch (InterruptedException e) { 
    80             // ignore this 
    81         } 
    82  
    83         // Get the image's color model 
    84         ColorModel cm = pg.getColorModel(); 
    85         return cm.hasAlpha(); 
    86     } 
    87  
    88     /** 
    89     * This method returns a buffered image with the contents of an image 
    90     * @param image the original image 
    91     * @return a buffered image 
    92     */ 
    93     public static BufferedImage toBufferedImage(Image image) { 
    94         if (image instanceof BufferedImage) { 
    95             return (BufferedImage)image; 
    96         } 
    97  
    98         // This code ensures that all the pixels in the image are loaded 
    99         image = new ImageIcon(image).getImage(); 
    100  
    101         // Determine if the image has transparent pixels; for this method's 
    102         // implementation, see e665 Determining If an Image Has Transparent Pixels 
    103         boolean hasAlpha = hasAlpha(image); 
    104  
    105         // Create a buffered image with a format that's compatible with the screen 
    106         BufferedImage bimage = null; 
    107         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
    108         try { 
    109             // Determine the type of transparency of the new buffered image 
    110             int transparency = Transparency.OPAQUE; 
    111             if (hasAlpha) { 
    112                 transparency = Transparency.BITMASK; 
    113             } 
    114  
    115             // Create the buffered image 
    116             GraphicsDevice gs = ge.getDefaultScreenDevice(); 
    117             GraphicsConfiguration gc = gs.getDefaultConfiguration(); 
    118             bimage = gc.createCompatibleImage( 
    119                 image.getWidth(null), image.getHeight(null), transparency); 
    120         } catch (HeadlessException e) { 
    121             // The system does not have a screen 
    122         } 
    123  
    124         if (bimage == null) { 
    125             // Create a buffered image using the default color model 
    126             int type = BufferedImage.TYPE_INT_RGB; 
    127             if (hasAlpha) { 
    128                 type = BufferedImage.TYPE_INT_ARGB; 
    129             } 
    130             bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); 
    131         } 
    132  
    133         // Copy image to buffered image 
    134         Graphics g = bimage.createGraphics(); 
    135  
    136         // Paint the image onto the buffered image 
    137         g.drawImage(image, 0, 0, null); 
    138         g.dispose(); 
    139  
    140         return bimage; 
    141     } 
    142  
    143  
    144     public static String getImageTypeFromExt (String ext) 
    145     { 
    146         // only display images, no other junk 
     55        public static final String TYPE_JPEG = "image/jpeg"; 
     56        public static final String TYPE_GIF = "image/gif"; 
     57        public static final String TYPE_PNG = "image/png"; 
     58        public static final String TYPE_BMP = "image/x-bmp"; 
     59 
     60        public static final String TYPE_VIDEO = "video/flv"; 
     61 
     62        public Thumbnailer(){ 
     63                // basic init 
     64        } 
     65 
     66        // This method returns true if the specified image has transparent pixels 
     67        public static boolean hasAlpha(Image image) { 
     68                // If buffered image, the color model is readily available 
     69                if (image instanceof BufferedImage) { 
     70                        BufferedImage bimage = (BufferedImage)image; 
     71                        return bimage.getColorModel().hasAlpha(); 
     72                } 
     73 
     74                // Use a pixel grabber to retrieve the image's color model; 
     75                // grabbing a single pixel is usually sufficient 
     76                PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); 
     77                try { 
     78                        pg.grabPixels(); 
     79                } catch (InterruptedException e) { 
     80                        // ignore this 
     81                } 
     82 
     83                // Get the image's color model 
     84                ColorModel cm = pg.getColorModel(); 
     85                return cm.hasAlpha(); 
     86        } 
     87 
     88        /** 
     89        * This method returns a buffered image with the contents of an image 
     90        * @param image the original image 
     91        * @return a buffered image 
     92        */ 
     93        public static BufferedImage toBufferedImage(Image image) { 
     94                if (image instanceof BufferedImage) { 
     95                        return (BufferedImage)image; 
     96                } 
     97 
     98                // This code ensures that all the pixels in the image are loaded 
     99                image = new ImageIcon(image).getImage(); 
     100 
     101                // Determine if the image has transparent pixels; for this method's 
     102                // implementation, see e665 Determining If an Image Has Transparent Pixels 
     103                boolean hasAlpha = hasAlpha(image); 
     104 
     105                // Create a buffered image with a format that's compatible with the screen 
     106                BufferedImage bimage = null; 
     107                GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
     108                try { 
     109                        // Determine the type of transparency of the new buffered image 
     110                        int transparency = Transparency.OPAQUE; 
     111                        if (hasAlpha) { 
     112                                transparency = Transparency.BITMASK; 
     113                        } 
     114 
     115                        // Create the buffered image 
     116                        GraphicsDevice gs = ge.getDefaultScreenDevice(); 
     117                        GraphicsConfiguration gc = gs.getDefaultConfiguration(); 
     118                        bimage = gc.createCompatibleImage( 
     119                                        image.getWidth(null), image.getHeight(null), transparency); 
     120                } catch (HeadlessException e) { 
     121                        // The system does not have a screen 
     122                } 
     123 
     124                if (bimage == null) { 
     125                        // Create a buffered image using the default color model 
     126                        int type = BufferedImage.TYPE_INT_RGB; 
     127                        if (hasAlpha) { 
     128                                type = BufferedImage.TYPE_INT_ARGB; 
     129                        } 
     130                        bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); 
     131                } 
     132 
     133                // Copy image to buffered image 
     134                Graphics g = bimage.createGraphics(); 
     135 
     136                // Paint the image onto the buffered image 
     137                g.drawImage(image, 0, 0, null); 
     138                g.dispose(); 
     139 
     140                return bimage; 
     141        } 
     142 
     143 
     144        public static String getImageTypeFromExt (String ext) 
     145        { 
     146                // only display images, no other junk 
    147147                if (ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg")) 
    148148                { 
     
    156156                }       
    157157                return null; 
    158     } 
    159      
     158        } 
     159 
    160160 
    161161 
     
    178178 
    179179                                // rotate the image correctly 
    180                     String rotate = ""; 
    181                     if (autorotate) 
    182                     { 
    183                         rotate = getRotate(in); 
    184                     } 
     180                                String rotate = ""; 
     181                                if (autorotate) 
     182                                { 
     183                                        rotate = getRotate(in); 
     184                                } 
    185185 
    186186                                // mogrify it 
    187187                                Process p = Runtime.getRuntime().exec(mogrify +  
    188188                                                " -size "+maxDim+"x"+maxDim + " -resize "+maxDim+"x"+maxDim+" "+rotate+ 
    189                                                         out.getAbsolutePath());                          
     189                                                out.getAbsolutePath());                          
    190190                                if (wait) 
    191                                     p.waitFor(); 
     191                                        p.waitFor(); 
    192192                        } catch (Exception e) { 
    193193                                // Print out Error if available 
     
    199199                } 
    200200        } 
    201          
     201 
    202202        // get the file rotation 
    203203        private static String getRotate (File in) 
    204204        { 
    205         String rotate = ""; 
    206  
    207         try 
    208         { 
    209             // get EXIF information from original image 
    210             Metadata metadata = com.drew.imaging.jpeg.JpegMetadataReader.readMetadata(in); 
    211             Directory exif = metadata.getDirectory(ExifDirectory.class); 
    212             //out.println("Datetime: " +  exif.getString(ExifDirectory.TAG_DATETIME)); 
    213             //out.println("GPS: " +   exif.getString(ExifDirectory.TAG_GPS_INFO )); 
    214             //out.println("Orientation: " +   exif.getString(ExifDirectory.TAG_ORIENTATION )); 
    215             int orientation = exif.getInt(ExifDirectory.TAG_ORIENTATION ); 
    216  
    217             /* 
    218             *  case 1: return "Top, left side (Horizontal / normal)"; 
    219             *  case 2: return "Top, right side (Mirror horizontal)"; 
    220             *  case 3: return "Bottom, right side (Rotate 180)"; 
    221             *  case 4: return "Bottom, left side (Mirror vertical)"; 
    222             *  case 5: return "Left side, top (Mirror horizontal and rotate 270 CW)"; 
    223             *  case 6: return "Right side, top (Rotate 90 CW)"; 
    224             *  case 7: return "Right side, bottom (Mirror horizontal and rotate 90 CW)"; 
    225             *  case 8: return "Left side, bottom (Rotate 270 CW)"; 
    226             */ 
    227             switch (orientation) 
    228             { 
    229                     case 3: rotate = "-rotate 180 "; break; 
    230                     case 6: rotate = "-rotate 90 "; break; 
    231                     case 8: rotate = "-rotate 270 "; break; 
    232             } 
    233          
    234         } catch (Exception e) 
    235         { //ignore 
    236         } 
    237         return rotate; 
     205                String rotate = ""; 
     206 
     207                try 
     208                { 
     209                        // get EXIF information from original image 
     210                        Metadata metadata = com.drew.imaging.jpeg.JpegMetadataReader.readMetadata(in); 
     211                        Directory exif = metadata.getDirectory(ExifDirectory.class); 
     212                        //out.println("Datetime: " +  exif.getString(ExifDirectory.TAG_DATETIME)); 
     213                        //out.println("GPS: " +   exif.getString(ExifDirectory.TAG_GPS_INFO )); 
     214                        //out.println("Orientation: " +   exif.getString(ExifDirectory.TAG_ORIENTATION )); 
     215                        int orientation = exif.getInt(ExifDirectory.TAG_ORIENTATION ); 
     216 
     217                        /* 
     218                        *  case 1: return "Top, left side (Horizontal / normal)"; 
     219                        *  case 2: return "Top, right side (Mirror horizontal)"; 
     220                        *  case 3: return "Bottom, right side (Rotate 180)"; 
     221                        *  case 4: return "Bottom, left side (Mirror vertical)"; 
     222                        *  case 5: return "Left side, top (Mirror horizontal and rotate 270 CW)"; 
     223                        *  case 6: return "Right side, top (Rotate 90 CW)"; 
     224                        *  case 7: return "Right side, bottom (Mirror horizontal and rotate 90 CW)"; 
     225                        *  case 8: return "Left side, bottom (Rotate 270 CW)"; 
     226                        */ 
     227                        switch (orientation) 
     228                        { 
     229                        case 3: rotate = "-rotate 180 "; break; 
     230                        case 6: rotate = "-rotate 90 "; break; 
     231                        case 8: rotate = "-rotate 270 "; break; 
     232                        } 
     233 
     234                } catch (Exception e) 
     235                { //ignore 
     236                } 
     237                return rotate; 
    238238        } 
    239239 
     
    255255                                // copy file 
    256256                                org.apache.commons.io.FileUtils.copyFile(in, out); 
    257                                  
     257 
    258258                                // rotate the image correctly 
    259                     String rotate = ""; 
    260                     if (autorotate) 
    261                     { 
    262                         rotate = getRotate(in); 
    263                     } 
     259                                String rotate = ""; 
     260                                if (autorotate) 
     261                                { 
     262                                        rotate = getRotate(in); 
     263                                } 
    264264 
    265265                                // mogrify it  
    266266                                Process p = Runtime.getRuntime().exec(mogrify +  
    267267                                                " -size "+width+"x"+height+" -resize "+width+"x"+height+"! "+ rotate + 
    268                                                         out.getAbsolutePath()); 
     268                                                out.getAbsolutePath()); 
    269269                                if (wait) 
    270                                     p.waitFor(); 
     270                                        p.waitFor(); 
    271271                        } catch (Exception e) { 
    272272                                // Print out Error if available 
     
    279279        } 
    280280 
    281     /** 
    282     * @param image the original image 
    283     * @param maxDim the maximum Dimension (the maximum size of the larger side) 
    284     * @return the dimension of the new image, where either width or height is equal to maxDim 
    285     */ 
    286     public static Dimension getThumbnailSize (Image image, int maxDim) 
    287     { 
    288       double scale = (double) maxDim / (double) image.getHeight(null); 
    289       if (image.getWidth(null) > image.getHeight(null)) { 
    290         scale = (double) maxDim / (double) image.getWidth(null); 
    291       } 
    292       // Determine size of new image. 
    293       // One of them 
    294       // should equal maxDim. 
    295       return new Dimension((int) (scale * image.getWidth(null)), (int) (scale * image.getHeight(null))); 
    296     } 
    297  
    298     /** 
    299     * @param image the original file 
    300     * @return an image object 
    301     */ 
    302     public static Image getImage(File image){ 
    303       return new ImageIcon(image.getPath()).getImage(); 
    304     } 
    305  
    306  
    307     /** 
    308     * @param image the image object 
    309     * @return the dimension of the image 
    310     */ 
    311     public static Dimension getImageDimension(Image image){ 
    312       int w = image.getWidth(null); 
    313       int h = image.getHeight(null); 
    314       Dimension d = new Dimension(w,h); 
    315       return d; 
    316     } 
     281        /** 
     282        * @param image the original image 
     283        * @param maxDim the maximum Dimension (the maximum size of the larger side) 
     284        * @return the dimension of the new image, where either width or height is equal to maxDim 
     285        */ 
     286        public static Dimension getThumbnailSize (Image image, int maxDim) 
     287        { 
     288                double scale = (double) maxDim / (double) image.getHeight(null); 
     289                if (image.getWidth(null) > image.getHeight(null)) { 
     290                        scale = (double) maxDim / (double) image.getWidth(null); 
     291                } 
     292                // Determine size of new image. 
     293                // One of them 
     294                // should equal maxDim. 
     295                return new Dimension((int) (scale * image.getWidth(null)), (int) (scale * image.getHeight(null))); 
     296        } 
     297 
     298        /** 
     299        * @param image the original file 
     300        * @return an image object 
     301        */ 
     302        public static Image getImage(File image){ 
     303                return new ImageIcon(image.getPath()).getImage(); 
     304        } 
     305 
     306 
     307        /** 
     308        * @param image the image object 
     309        * @return the dimension of the image 
     310        */ 
     311        public static Dimension getImageDimension(Image image){ 
     312                int w = image.getWidth(null); 
     313                int h = image.getHeight(null); 
     314                Dimension d = new Dimension(w,h); 
     315                return d; 
     316        } 
    317317} 
Note: See TracChangeset for help on using the changeset viewer.