File Source: RollerWeblogHandler.java

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   *  contributor license agreements.  The ASF licenses this file to You
     4   * under the Apache License, Version 2.0 (the "License"); you may not
     5   * use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.  For additional information regarding
    15   * copyright in this work, please see the NOTICE file in the top level
    16   * directory of this distribution.
    17   */
    18  
    19  package org.apache.roller.weblogger.webservices.adminprotocol;
    20  
    21  import java.io.Reader;
    22  import java.net.MalformedURLException;
    23  import java.util.ArrayList;
    24  import java.util.HashMap;
    25  import java.util.Iterator;
    26  import java.util.List;
    27  import java.util.Collections;
    28  import java.util.Date;
    29  import javax.servlet.http.HttpServletRequest;
    30  import org.apache.commons.logging.Log;
    31  import org.apache.commons.logging.LogFactory;
    32  import org.jdom.Document;
    33  import org.apache.roller.weblogger.WebloggerException;
    34  import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
    35  import org.apache.roller.weblogger.business.UserManager;
    36  import org.apache.roller.weblogger.pojos.WeblogPermission;
    37  import org.apache.roller.weblogger.pojos.User;
    38  import org.apache.roller.weblogger.pojos.Weblog;
    39  import org.apache.roller.weblogger.util.cache.CacheManager;
    40  import org.apache.roller.weblogger.util.Utilities;
    41  import org.apache.roller.weblogger.webservices.adminprotocol.sdk.Entry;
    42  import org.apache.roller.weblogger.webservices.adminprotocol.sdk.EntrySet;
    43  import org.apache.roller.weblogger.webservices.adminprotocol.sdk.UnexpectedRootElementException;
    44  import org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry;
    45  import org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntrySet;
    46  
    47  /**
    48   * This class handles requests concerning Roller weblog resources.
    49   */
    50  class RollerWeblogHandler extends Handler {
             /* 
    P/P       *  Method: org.apache.roller.weblogger.webservices.adminprotocol.RollerWeblogHandler__static_init
              * 
              *  Presumptions:
              *    org.apache.commons.logging.LogFactory:getFactory(...)@51 != null
              * 
              *  Postconditions:
              *    init'ed(log)
              */
    51      private static Log log =
    52              LogFactory.getFactory().getInstance(RollerWeblogHandler.class);
    53      
    54      /** Theme name used when creating weblogs */
    55      private static final String DEFAULT_THEME = "basic";
    56      
    57      public RollerWeblogHandler(HttpServletRequest request) throws HandlerException {
                 /* 
    P/P           *  Method: void org.apache.roller.weblogger.webservices.adminprotocol.RollerWeblogHandler(HttpServletRequest)
                  * 
                  *  Preconditions:
                  *    request != null
                  *    (soft) org/apache/roller/weblogger/webservices/adminprotocol/Handler$URI.PATHINFO_PATTERN != null
                  * 
                  *  Postconditions:
                  *    init'ed(java.lang.String:substring(...)._tainted)
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    this.request == request
                  *    this.request != null
                  *    init'ed(this.roller)
                  *    this.uri == &new Handler$URI(Handler#1)
                  *    this.urlPrefix == &java.lang.StringBuilder:toString(...)
                  *    this.userName == One-of{null, &java.lang.String:substring(...)}
                  *    this.userName in Addr_Set{null,&java.lang.String:substring(...)}
                  *    new Handler$URI(Handler#1) num objects == 1
                  *    ...
                  */
    58          super(request);
    59      }
    60      
    61      protected EntrySet getEntrySet(Document d) throws UnexpectedRootElementException {
                 /* 
    P/P           *  Method: EntrySet getEntrySet(Document)
                  * 
                  *  Preconditions:
                  *    d != null
                  *    init'ed(this.urlPrefix)
                  * 
                  *  Postconditions:
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &new WeblogEntrySet(getEntrySet#1)
                  *    new WeblogEntrySet(getEntrySet#1) num objects == 1
                  *    init'ed(return_value.entries)
                  *    return_value.href == &java.lang.StringBuilder:toString(...)
                  */
    62          return new WeblogEntrySet(d, getUrlPrefix());
    63      }
    64      
    65      public EntrySet processGet() throws HandlerException {
                 /* 
    P/P           *  Method: EntrySet processGet()
                  * 
                  *  Preconditions:
                  *    this.uri != null
                  *    init'ed(this.uri.entryId)
                  *    (soft) this.roller != null
                  *    (soft) this.uri.type != null
                  *    (soft) init'ed(this.urlPrefix)
                  * 
                  *  Postconditions:
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value in Addr_Set{&new WeblogEntrySet(toWeblogEntrySet#1),&new WeblogEntrySet(toWeblogEntrySet#1)}
                  *    new WeblogEntrySet(toWeblogEntrySet#1) num objects <= 1
                  *    init'ed(new WeblogEntrySet(toWeblogEntrySet#1).entries)
                  *    new WeblogEntrySet(toWeblogEntrySet#1).href == &java.lang.StringBuilder:toString(...)
                  * 
                  *  Test Vectors:
                  *    !(this.uri.entryId == null) | (this.uri.type == null & this.uri.entryId == null): {1}, {0}
                  *    !(this.uri.type == null) & this.uri.entryId == null: {0}, {1}
                  *    this.uri.entryId: Inverse{null}, Addr_Set{null}
                  */
    66          if (getUri().isCollection()) {
    67              return getCollection();
    68          } else if (getUri().isEntry()) {
    69              return getEntry();
    70          } else {
    71              throw new BadRequestException("ERROR: Unknown GET URI type");
    72          }
    73      }
    74      
    75      public EntrySet processPost(Reader r) throws HandlerException {
                 /* 
    P/P           *  Method: EntrySet processPost(Reader)
                  * 
                  *  Preconditions:
                  *    this.uri != null
                  *    this.uri.entryId == null
                  *    (soft) this.uri.type != null
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    init'ed(return_value)
                  *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == undefined
                  *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == 0, if init'ed
                  *    new WeblogEntrySet(toWeblogEntrySet#1).entries == undefined
                  *    new WeblogEntrySet(toWeblogEntrySet#1).entries == null
                  *    new WeblogEntrySet(toWeblogEntrySet#1).href == new WeblogEntrySet(toWeblogEntrySet#1).entries
                  */
    76          if (getUri().isCollection()) {
    77              return postCollection(r);
    78          } else {
    79              throw new BadRequestException("ERROR: Unknown POST URI type");
    80          }
    81      }
    82      
    83      public EntrySet processPut(Reader r) throws HandlerException {
                 /* 
    P/P           *  Method: EntrySet processPut(Reader)
                  * 
                  *  Preconditions:
                  *    this.uri != null
                  *    init'ed(this.uri.entryId)
                  *    (soft) this.uri.type != null
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    init'ed(return_value)
                  *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == undefined
                  *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == 0, if init'ed
                  *    new WeblogEntrySet(toWeblogEntrySet#1).entries == undefined
                  *    new WeblogEntrySet(toWeblogEntrySet#1).entries == null
                  *    new WeblogEntrySet(toWeblogEntrySet#1).href == new WeblogEntrySet(toWeblogEntrySet#1).entries
                  * 
                  *  Test Vectors:
                  *    !(this.uri.entryId == null) | (this.uri.type == null & this.uri.entryId == null): {1}, {0}
                  *    !(this.uri.type == null) & this.uri.entryId == null: {0}, {1}
                  *    this.uri.entryId: Inverse{null}, Addr_Set{null}
                  */
    84          if (getUri().isCollection()) {
    85              return putCollection(r);
    86          } else if (getUri().isEntry()) {
    87              return putEntry(r);
    88          } else {
    89              throw new BadRequestException("ERROR: Unknown PUT URI type");
    90          }
    91      }
    92      
    93      public EntrySet processDelete() throws HandlerException {
                 /* 
    P/P           *  Method: EntrySet processDelete()
                  * 
                  *  Preconditions:
                  *    this.roller != null
                  *    this.uri != null
                  *    this.uri.entryId != null
                  *    init'ed(this.urlPrefix)
                  *    (soft) this.uri.type != null
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == this.urlPrefix._tainted
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &new WeblogEntrySet(toWeblogEntrySet#1)
                  *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == 1
                  *    init'ed(new WeblogEntrySet(toWeblogEntrySet#1).entries)
                  *    new WeblogEntrySet(toWeblogEntrySet#1).href == &java.lang.StringBuilder:toString(...)
                  */
    94          if (getUri().isEntry()) {
    95              return deleteEntry();
    96          } else {
    97              throw new BadRequestException("ERROR: Unknown DELETE URI type");
    98          }
    99      }
   100      
   101      private EntrySet getCollection() throws HandlerException {
   102          try {
                     /* 
    P/P               *  Method: EntrySet getCollection()
                      * 
                      *  Preconditions:
                      *    this.roller != null
                      *    init'ed(this.urlPrefix)
                      * 
                      *  Presumptions:
                      *    init'ed(java.util.Collections.EMPTY_LIST)
                      *    java.util.List:toArray(...).length@107 <= 232-1
                      *    java.util.List:toArray(...)@107 != null
                      *    org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@103 != null
                      * 
                      *  Postconditions:
                      *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                      *    return_value == &new WeblogEntrySet(toWeblogEntrySet#1)
                      *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == 1
                      *    init'ed(new WeblogEntrySet(toWeblogEntrySet#1).entries)
                      *    new WeblogEntrySet(toWeblogEntrySet#1).href == &java.lang.StringBuilder:toString(...)
                      * 
                      *  Test Vectors:
                      *    org.apache.roller.weblogger.business.UserManager:getUsers(...)@103: Inverse{null}, Addr_Set{null}
                      */
   103              List users = getRoller().getUserManager().getUsers(null, null, null, null, 0, -1);
   104              if (users == null) {
   105                  users = Collections.EMPTY_LIST;
   106              }
   107              EntrySet c = toWeblogEntrySet((User[])users.toArray(new User[0]));
   108              
   109              return c;
   110          } catch (WebloggerException re) {
   111              throw new InternalException("ERROR: Could not get weblog collection", re);
   112          }
   113      }
   114          
   115      private EntrySet getEntry() throws HandlerException {
                 /* 
    P/P           *  Method: EntrySet getEntry()
                  * 
                  *  Preconditions:
                  *    this.roller != null
                  *    this.uri != null
                  *    init'ed(this.uri.entryId)
                  *    init'ed(this.urlPrefix)
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == this.urlPrefix._tainted
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &new WeblogEntrySet(toWeblogEntrySet#1)
                  *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == 1
                  *    init'ed(new WeblogEntrySet(toWeblogEntrySet#1).entries)
                  *    new WeblogEntrySet(toWeblogEntrySet#1).href == &java.lang.StringBuilder:toString(...)
                  */
   116          String handle = getUri().getEntryId();
   117          Weblog wd = getWebsiteData(handle);
   118          Weblog[] wds = new Weblog[] { wd };
   119          EntrySet c = toWeblogEntrySet(wds);
   120          
   121          return c;
   122      }
   123      
   124      private EntrySet postCollection(Reader r) throws HandlerException {
                 /* 
    P/P           *  Method: EntrySet postCollection(Reader)
                  * 
                  *  Preconditions:
                  *    this.roller != null
                  *    init'ed(this.urlPrefix)
                  *    (soft) log != null
                  * 
                  *  Presumptions:
                  *    c.entries@125 != null
                  *    c.entries@126 != null
                  *    java.util.List:size(...)@82 != 0
                  * 
                  *  Postconditions:
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &new WeblogEntrySet(toWeblogEntrySet#1)
                  *    new MemberEntrySet(getEntrySet#1*) num objects == 0
                  *    new MemberEntrySet(getEntrySet#1*)._tainted == 0
                  *    new UserEntrySet(getEntrySet#1*)._tainted == 0
                  *    new WeblogEntrySet(getEntrySet#1*)._tainted == 0
                  *    init'ed(new MemberEntrySet(getEntrySet#1*).entries)
                  *    init'ed(new MemberEntrySet(getEntrySet#1*).href)
                  *    new UserEntrySet(getEntrySet#1*) num objects == 0
                  *    init'ed(new UserEntrySet(getEntrySet#1*).entries)
                  *    ...
                  */
   125          EntrySet c = getEntrySet(r);
+  126          if (c.isEmpty()) {
   127              throw new BadRequestException("ERROR: No entries");
   128          }
   129          c = createWeblogs((WeblogEntrySet)c);
   130          
   131          return c;
   132      }
   133      
   134      private EntrySet putCollection(Reader r) throws HandlerException {
                 /* 
    P/P           *  Method: EntrySet putCollection(Reader)
                  * 
                  *  Preconditions:
                  *    this.roller != null
                  *    init'ed(this.urlPrefix)
                  * 
                  *  Presumptions:
                  *    c.entries@135 != null
                  *    c.entries@136 != null
                  *    java.util.List:size(...)@82 != 0
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == this.urlPrefix._tainted
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &new WeblogEntrySet(toWeblogEntrySet#1)
                  *    new MemberEntrySet(getEntrySet#1*) num objects == 0
                  *    init'ed(new MemberEntrySet(getEntrySet#1*).entries)
                  *    init'ed(new MemberEntrySet(getEntrySet#1*).href)
                  *    new UserEntrySet(getEntrySet#1*) num objects == 0
                  *    init'ed(new UserEntrySet(getEntrySet#1*).entries)
                  *    init'ed(new UserEntrySet(getEntrySet#1*).href)
                  *    new WeblogEntrySet(getEntrySet#1*) num objects == 1
                  *    ...
                  */
   135          EntrySet c = getEntrySet(r);
+  136          if (c.isEmpty()) {
   137              throw new BadRequestException("ERROR: No entries");
   138          }
   139          c = updateWeblogs((WeblogEntrySet)c);
   140          
   141          return c;
   142      }
   143      
   144      private EntrySet putEntry(Reader r) throws HandlerException {
                 /* 
    P/P           *  Method: EntrySet putEntry(Reader)
                  * 
                  *  Preconditions:
                  *    this.roller != null
                  *    this.uri != null
                  *    init'ed(this.uri.entryId)
                  *    init'ed(this.urlPrefix)
                  * 
                  *  Presumptions:
                  *    c.entries@145 != null
                  *    c.entries@146 != null
                  *    c.entries@149 != null
                  *    c.entries@153 != null
                  *    getEntries(...).length@149 <= 1
                  *    ...
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == this.urlPrefix._tainted
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &new WeblogEntrySet(toWeblogEntrySet#1)
                  *    new MemberEntrySet(getEntrySet#1*) num objects == 0
                  *    init'ed(new MemberEntrySet(getEntrySet#1*).entries)
                  *    init'ed(new MemberEntrySet(getEntrySet#1*).href)
                  *    new UserEntrySet(getEntrySet#1*) num objects == 0
                  *    init'ed(new UserEntrySet(getEntrySet#1*).entries)
                  *    init'ed(new UserEntrySet(getEntrySet#1*).href)
                  *    new WeblogEntrySet(getEntrySet#1*) num objects == 1
                  *    ...
                  */
   145          EntrySet c = getEntrySet(r);
+  146          if (c.isEmpty()) {
   147              throw new BadRequestException("ERROR: No entries");
   148          }
   149          if (c.getEntries().length > 1) {
   150              throw new BadRequestException("ERROR: Cannot put >1 entries per request");
   151          }
   152          
   153          WeblogEntry entry = (WeblogEntry)c.getEntries()[0];
+  154          if (entry.getHandle() != null && !entry.getHandle().equals(getUri().getEntryId())) {
   155              throw new BadRequestException("ERROR: Content handle does not match URI handle");
   156          }
+  157          entry.setHandle(getUri().getEntryId());
   158          c = updateWeblogs((WeblogEntrySet)c);
   159          
   160          return c;
   161      }
   162      
   163      private WeblogEntrySet createWeblogs(WeblogEntrySet c) throws HandlerException {
   164          try {
                     /* 
    P/P               *  Method: WeblogEntrySet createWeblogs(WeblogEntrySet)
                      * 
                      *  Preconditions:
                      *    c != null
                      *    c.entries != null
                      *    this.roller != null
                      *    init'ed(this.urlPrefix)
                      *    (soft) log != null
                      * 
                      *  Presumptions:
                      *    defs.length@196 >= 1
                      *    getEntries(...).length@169 <= 232-1
                      *    getEntries(...).length@170 >= 1
                      *    getEntries(...).length@169 <= getEntries(...).length@170
                      *    java.util.List:toArray(...).length@208 <= 232-1
                      *    ...
                      * 
                      *  Postconditions:
                      *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                      *    return_value == &new WeblogEntrySet(toWeblogEntrySet#1)
                      *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == 1
                      *    init'ed(new WeblogEntrySet(toWeblogEntrySet#1).entries)
                      *    new WeblogEntrySet(toWeblogEntrySet#1).href == &java.lang.StringBuilder:toString(...)
                      * 
                      *  Test Vectors:
                      *    getEntries(...).length@169: {1..232-1}, {0}
                      */
   165              UserManager mgr = getRoller().getUserManager();
   166              HashMap pages = null; //getRollerContext().readThemeMacros(form.getTheme());
   167              
   168              List websiteDatas = new ArrayList();
   169              for (int i = 0; i < c.getEntries().length; i++) {
   170                  WeblogEntry entry = (WeblogEntry)c.getEntries()[i];
+  171                  User user = mgr.getUserByUserName(entry.getCreatingUser());
+  172                  Weblog wd = new Weblog(
   173                          entry.getHandle(),
   174                          user,
   175                          entry.getName(),
   176                          entry.getDescription(),
   177                          entry.getEmailAddress(),
   178                          entry.getEmailAddress(),
   179                          DEFAULT_THEME,
   180                          entry.getLocale().toString(),
   181                          entry.getTimezone().getID());
   182                  
+  183                  Date dateCreated  = entry.getDateCreated();
+  184                  if (dateCreated == null) {
+  185                      dateCreated = new Date();
   186                  }
   187                  wd.setDateCreated(dateCreated);
   188                  
+  189                  Boolean enabled = entry.getEnabled();
+  190                  if (enabled != null) {
   191                      wd.setEnabled(enabled);
   192                  }
   193                  
   194                  try {
   195                      String def = WebloggerRuntimeConfig.getProperty("users.editor.pages");
   196                      String[] defs = Utilities.stringToStringArray(def,",");
   197                      wd.setEditorPage(defs[0]);
   198                  } catch (Exception ex) {
   199                      log.error("ERROR setting default editor page for weblog", ex);
   200                  }
   201                  
   202                  mgr.addWebsite(wd);
   203                  getRoller().flush();
   204                  CacheManager.invalidate(wd);
   205                  websiteDatas.add(wd);
   206              }
   207              
   208              return toWeblogEntrySet((Weblog[])websiteDatas.toArray(new Weblog[0]));
   209          } catch (WebloggerException re) {
   210              throw new InternalException("ERROR: Could not create weblogs: " + c, re);
   211          }
   212      }
   213      
   214      private WeblogEntrySet updateWeblogs(WeblogEntrySet c) throws HandlerException {
                 /* 
    P/P           *  Method: WeblogEntrySet updateWeblogs(WeblogEntrySet)
                  * 
                  *  Preconditions:
                  *    c != null
                  *    c.entries != null
                  *    this.roller != null
                  *    init'ed(this.urlPrefix)
                  * 
                  *  Presumptions:
                  *    getEntries(...).length@222 <= 232-1
                  *    getEntries(...).length@223 >= 1
                  *    getEntries(...).length@222 <= getEntries(...).length@223
                  *    java.util.List:toArray(...).length@228 <= 232-1
                  *    java.util.List:toArray(...)@228 != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == this.urlPrefix._tainted
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &new WeblogEntrySet(toWeblogEntrySet#1)
                  *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == 1
                  *    init'ed(new WeblogEntrySet(toWeblogEntrySet#1).entries)
                  *    new WeblogEntrySet(toWeblogEntrySet#1).href == &java.lang.StringBuilder:toString(...)
                  */
+  215          UserManager mgr = getRoller().getUserManager();
   216          
   217          //TODO: group blogging check?
   218          
   219          HashMap pages = null;
   220          
   221          List websiteDatas = new ArrayList();
   222          for (int i = 0; i < c.getEntries().length; i++) {
   223              WeblogEntry entry = (WeblogEntry)c.getEntries()[i];
+  224              Weblog wd = getWebsiteData(entry.getHandle());
+  225              updateWebsiteData(wd, entry);
   226              websiteDatas.add(wd);
   227          }
   228          return toWeblogEntrySet((Weblog[])websiteDatas.toArray(new Weblog[0]));
   229      }
   230      
   231      private void updateWebsiteData(Weblog wd, WeblogEntry entry) throws HandlerException {
                 /* 
    P/P           *  Method: void updateWebsiteData(Weblog, WeblogEntry)
                  * 
                  *  Preconditions:
                  *    entry != null
                  *    init'ed(entry.description)
                  *    init'ed(entry.emailAddress)
                  *    init'ed(entry.enabled)
                  *    init'ed(entry.locale)
                  *    init'ed(entry.name)
                  *    init'ed(entry.timezone)
                  *    this.roller != null
                  *    (soft) wd != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@252 != null
                  * 
                  *  Test Vectors:
                  *    entry.description: Addr_Set{null}, Inverse{null}
                  *    entry.emailAddress: Addr_Set{null}, Inverse{null}
                  *    entry.enabled: Addr_Set{null}, Inverse{null}
                  *    entry.locale: Addr_Set{null}, Inverse{null}
                  *    entry.name: Addr_Set{null}, Inverse{null}
                  *    entry.timezone: Addr_Set{null}, Inverse{null}
                  */
   232          if (entry.getName() != null) {
   233              wd.setName(entry.getName());
   234          }
   235          if (entry.getDescription() != null) {
   236              wd.setDescription(entry.getDescription());
   237          }
   238          if (entry.getLocale() != null) {
   239              wd.setLocale(entry.getLocale().toString());
   240          }
   241          if (entry.getTimezone() != null) {
   242              wd.setTimeZone(entry.getTimezone().getID());
   243          }
   244          if (entry.getEmailAddress() != null) {
   245              wd.setEmailAddress(entry.getEmailAddress());
   246          }
   247          if (entry.getEnabled() != null) {
   248              wd.setEnabled(entry.getEnabled());
   249          }
   250          
   251          try {
   252              UserManager mgr = getRoller().getUserManager();
   253              mgr.saveWebsite(wd);
   254              getRoller().flush();
   255              CacheManager.invalidate(wd);
   256          } catch (WebloggerException re) {
   257              throw new InternalException("ERROR: Could not update website data", re);
   258          }
   259      }
   260      
   261      private EntrySet deleteEntry() throws HandlerException {
                 /* 
    P/P           *  Method: EntrySet deleteEntry()
                  * 
                  *  Preconditions:
                  *    this.roller != null
                  *    this.uri != null
                  *    init'ed(this.uri.entryId)
                  *    init'ed(this.urlPrefix)
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@265 != null
                  * 
                  *  Postconditions:
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &new WeblogEntrySet(toWeblogEntrySet#1)
                  *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == 1
                  *    init'ed(new WeblogEntrySet(toWeblogEntrySet#1).entries)
                  *    new WeblogEntrySet(toWeblogEntrySet#1).href == &java.lang.StringBuilder:toString(...)
                  */
   262          String handle = getUri().getEntryId();
   263          
   264          try {
   265              UserManager mgr = getRoller().getUserManager();
   266              
   267              Weblog wd = getWebsiteData(handle);
   268              
   269              CacheManager.invalidate(wd);
   270  
   271              mgr.removeWebsite(wd);
   272              getRoller().flush();
   273  
   274              // return empty set, object deleted
   275              Weblog[] wds = new Weblog[0];
   276              EntrySet es = toWeblogEntrySet(wds);
   277              return es;
   278  
   279          } catch (WebloggerException re) {
   280              throw new InternalException("ERROR: Could not delete entry: " + handle, re);
   281          }
   282      }
   283      
   284      private WeblogEntry toWeblogEntry(Weblog wd) throws HandlerException {
                 /* 
    P/P           *  Method: WeblogEntry toWeblogEntry(Weblog)
                  * 
                  *  Preconditions:
                  *    init'ed(this.urlPrefix)
                  *    wd != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.pojos.Weblog:getCreator(...)@293 != null
                  *    org.apache.roller.weblogger.pojos.Weblog:getLocale(...)@291 == null
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == this.urlPrefix._tainted
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    java.net.URL:toString(...)._tainted == 0
                  *    return_value == &new WeblogEntry(toWeblogEntry#1)
                  *    new Locale(LocaleString#1) num objects == 0
                  *    new Locale(LocaleString#2) num objects == 0
                  *    new Locale(LocaleString#3) num objects == 0
                  *    new WeblogEntry(toWeblogEntry#1) num objects == 1
                  *    new WeblogEntry(toWeblogEntry#1).appEntriesUrl == &java.net.URL:toString(...)
                  *    new WeblogEntry(toWeblogEntry#1).appResourcesUrl == &java.net.URL:toString(...)
                  *    ...
                  */
   285          if (wd == null) {
   286              throw new NullPointerException("ERROR: Null website data not allowed");
   287          }
   288          WeblogEntry we = new WeblogEntry(wd.getHandle(), getUrlPrefix());
   289          we.setName(wd.getName());
   290          we.setDescription(wd.getDescription());
   291          we.setLocale(wd.getLocale());
   292          we.setTimezone(wd.getTimeZone());
   293          we.setCreatingUser(wd.getCreator().getUserName());
   294          we.setEmailAddress(wd.getEmailAddress());
   295          we.setDateCreated(wd.getDateCreated());
   296          we.setEnabled(wd.getEnabled());
   297          
   298          try {
   299              AppUrl appUrl = new AppUrl(WebloggerRuntimeConfig.getAbsoluteContextURL(), wd.getHandle());
   300              we.setAppEntriesUrl(appUrl.getEntryUrl().toString());
   301              we.setAppResourcesUrl(appUrl.getResourceUrl().toString());
   302          } catch (MalformedURLException mfue) {
   303              throw new InternalException("ERROR: Could not get APP URLs", mfue);
   304          }
   305          
   306          return we;
   307      }
   308      
   309      private WeblogEntrySet toWeblogEntrySet(User[] uds) throws HandlerException {
                 /* 
    P/P           *  Method: WeblogEntrySet toWeblogEntrySet(User[])
                  * 
                  *  Preconditions:
                  *    init'ed(this.urlPrefix)
                  *    uds != null
                  *    uds.length <= 232-1
                  *    (soft) uds[...] != null
                  * 
                  *  Presumptions:
                  *    java.util.Iterator:next(...)@320 != null
                  *    org.apache.roller.weblogger.pojos.User:getPermissions(...)@318 != null
                  *    org.apache.roller.weblogger.pojos.WeblogPermission:getWebsite(...)@321 != null
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == this.urlPrefix._tainted
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &new WeblogEntrySet(toWeblogEntrySet#1)
                  *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == 1
                  *    init'ed(return_value.entries)
                  *    return_value.href == &java.lang.StringBuilder:toString(...)
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@319: {0}, {1}
                  */
   310          if (uds == null) {
   311              throw new NullPointerException("ERROR: Null user data not allowed");
   312          }
   313          
   314          WeblogEntrySet wes = new WeblogEntrySet(getUrlPrefix());
   315          List entries = new ArrayList();
   316          for (int i = 0; i < uds.length; i++) {
   317              User ud = uds[i];
   318              List permissions = ud.getPermissions();
   319              for (Iterator j = permissions.iterator(); j.hasNext(); ) {
   320                  WeblogPermission pd = (WeblogPermission)j.next();
   321                  Weblog wd = pd.getWebsite();
+  322                  WeblogEntry we = toWeblogEntry(wd);
   323                  entries.add(we);
   324              }
   325          }
   326          wes.setEntries((Entry[])entries.toArray(new Entry[0]));
   327          
   328          return wes;
   329      }
   330      
   331      private WeblogEntrySet toWeblogEntrySet(Weblog[] wds) throws HandlerException {
                 /* 
    P/P           *  Method: WeblogEntrySet toWeblogEntrySet(Weblog[])
                  * 
                  *  Preconditions:
                  *    init'ed(this.urlPrefix)
                  *    wds != null
                  *    wds.length <= 232-1
                  *    (soft) wds[...] != null
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == this.urlPrefix._tainted
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &new WeblogEntrySet(toWeblogEntrySet#1)
                  *    new WeblogEntrySet(toWeblogEntrySet#1) num objects == 1
                  *    init'ed(return_value.entries)
                  *    return_value.href == &java.lang.StringBuilder:toString(...)
                  */
   332          if (wds == null) {
   333              throw new NullPointerException("ERROR: Null website datas not allowed");
   334          }
   335          
   336          WeblogEntrySet wes = new WeblogEntrySet(getUrlPrefix());
   337          List entries = new ArrayList();
   338          for (int i = 0; i < wds.length; i++) {
+  339              WeblogEntry we = toWeblogEntry(wds[i]);
   340              entries.add(we);
   341          }
   342          wes.setEntries((Entry[])entries.toArray(new Entry[0]));
   343          
   344          return wes;
   345      }
   346  }
   347  








SofCheck Inspector Build Version : 2.18479
RollerWeblogHandler.java 2009-Jan-02 14:25:40
RollerWeblogHandler.class 2009-Sep-04 03:12:46