File Source: AppModuleGenerator.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  package org.apache.roller.weblogger.webservices.atomprotocol;
    19  
    20  import java.util.Collections;
    21  import java.util.HashSet;
    22  import java.util.Set;
    23  import org.apache.roller.util.DateUtil;
    24  import org.apache.roller.weblogger.util.Utilities;
    25  
    26  import org.jdom.Element;
    27  import org.jdom.Namespace;
    28  
    29  import com.sun.syndication.feed.module.Module;
    30  import com.sun.syndication.io.ModuleGenerator;
    31  
         /* 
    P/P   *  Method: void org.apache.roller.weblogger.webservices.atomprotocol.AppModuleGenerator()
          */
    32  public class AppModuleGenerator implements ModuleGenerator {
             /* 
    P/P       *  Method: org.apache.roller.weblogger.webservices.atomprotocol.AppModuleGenerator__static_init
              * 
              *  Postconditions:
              *    init'ed(APP_NS)
              *    init'ed(NAMESPACES)
              */
    33      private static final Namespace APP_NS  = 
    34          Namespace.getNamespace("app", AppModule.URI);
    35  
    36      public String getNamespaceUri() {
                 /* 
    P/P           *  Method: String getNamespaceUri()
                  * 
                  *  Postconditions:
                  *    return_value == &"http:..www.w3.org.2007.app"
                  */
    37          return AppModule.URI;
    38      }
    39  
    40      private static final Set NAMESPACES;
    41  
    42      static {
    43          Set nss = new HashSet();
    44          nss.add(APP_NS);
    45          NAMESPACES = Collections.unmodifiableSet(nss);
    46      }
    47  
    48      public Set getNamespaces() {
                 /* 
    P/P           *  Method: Set getNamespaces()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    49          return NAMESPACES;
    50      }
    51  
    52      public void generate(Module module, Element element) {
                 /* 
    P/P           *  Method: void generate(Module, Element)
                  * 
                  *  Preconditions:
                  *    element != null
                  *    module != null
                  *    init'ed(module.draft)
                  *    init'ed(module.edited)
                  * 
                  *  Test Vectors:
                  *    module.edited: Addr_Set{null}, Inverse{null}
                  */
    53          AppModule m = (AppModule)module;
    54          
    55          String draft = m.getDraft() ? "yes" : "no";
    56          Element control = new Element("control", APP_NS);
    57          control.addContent(generateSimpleElement("draft", draft));
    58          element.addContent(control);
    59          
    60          if (m.getEdited() != null) {
    61              Element edited = new Element("edited", APP_NS);
    62              edited.addContent(DateUtil.formatIso8601(m.getEdited()));
    63              element.addContent(edited);
    64          }
    65      }
    66  
    67      protected Element generateSimpleElement(String name, String value)  {
                 /* 
    P/P           *  Method: Element generateSimpleElement(String, String)
                  * 
                  *  Postconditions:
                  *    return_value == &new Element(generateSimpleElement#1)
                  *    new Element(generateSimpleElement#1) num objects == 1
                  */
    68          Element element = new Element(name, APP_NS);
    69          element.addContent(value);
    70          return element;
    71      }
    72  }








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