001    package hirondelle.web4jtools.codegenerator.output;
002    
003    import hirondelle.web4j.action.ActionImpl;
004    import hirondelle.web4j.action.ResponsePage;
005    import hirondelle.web4j.model.AppException;
006    import hirondelle.web4j.request.RequestParser;
007    import hirondelle.web4jtools.codegenerator.feature.FeatureAction;
008    import hirondelle.web4jtools.codegenerator.field.FieldAction;
009    import hirondelle.web4jtools.util.SaveToFile;
010    
011    /**
012    * Present links for generating your feature's source code.
013    * 
014    * <P>When you click on each link, the corresponding source code is generated and served as plain text.
015    * There are two ways to place the generated source code into your development environment:
016    *<ul>
017    * <li>a manual copy and paste operation
018    * <li>automatic file generation, if enabled by settings in <tt>web.xml</tt>. This will create files 
019    * directly in your development directory, as a side-effect of serving the plain text.
020    * See the overview for more information on this option.
021    *</ul>
022    *
023    *<P>If the necessary items are not found in session scope, then an error message is displayed as a warning.
024    */
025    public final class OutputAction extends ActionImpl {
026      
027      public OutputAction(RequestParser aRequestParser){
028        super(FORWARD, aRequestParser);
029      }
030      
031      @Override public ResponsePage execute() throws AppException {
032        if ( SaveToFile.isEnabled() ) {
033          addMessage("Clicking on these links will save a file to the server's file system.");
034        }
035        ensurePresentInSession(FeatureAction.FEATURE_KEY);
036        ensurePresentInSession(FieldAction.FIELDS_KEY);
037        return getResponsePage();
038      }
039      
040      // PRIVATE //
041      private static final ResponsePage FORWARD =  new ResponsePage("Select Output", "view.jsp", OutputAction.class);
042    
043      private void ensurePresentInSession(String aKey){
044        Object object = getFromSession(aKey);
045        if ( object == null ) {
046          addError("Required item is not in session : " + aKey + ". Please enter before proceeding with generating output.");
047        }
048      }
049    }