Announcement Announcement Module
Collapse
No announcement yet.
Lost in XML Space Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lost in XML Space

    Through general misunderstanding I have arrived at a place I know isn't quite right.
    Code:
    @Controller
    public class SearchController
      {
    
      public final static String FORM_SEARCH_LENGTH = "dino_length" ;
      public final static String FORM_SEARCH_OFFSET = "dino_offset" ;
    
    
      /** Logger for this class and subclasses */
      protected final Log logger = LogFactory.getLog (getClass ()) ;
      @Autowired
      // searcher
      @Qualifier("searcher")
      private ISearcher searcher ;
      @Autowired
      @Qualifier("clipPropertiesListMarshaller")
      private Marshaller marshaller ;
    
      @Transactional
      @RequestMapping("/search.html")
      public ModelAndView handleRequest (HttpServletRequest request, HttpServletResponse response)
          throws Exception
        {
        String s, v ;
    
        s = request.getParameter (FORM_SEARCH_LENGTH) ;
        s = StringUtils.requiredWebArg (InputRegExp.POSITIVE_NUMBER, FORM_SEARCH_LENGTH, s) ;
        int len = StringUtils.toInt ("results per page", s) ;
    
    
        s = request.getParameter (FORM_SEARCH_OFFSET) ;
        s = StringUtils.requiredWebArg (InputRegExp.ZERO_POSITIVE_NUMBER, FORM_SEARCH_OFFSET, s) ;
        int offset = StringUtils.toInt ("offset", s) ;
    
        @SuppressWarnings("unchecked")
        Map<String, String[]> params = request.getParameterMap () ;
    
        HashMap<String, String> filter = new HashMap<String, String> () ;
        for (Object k : params.keySet ())
          {
          s = ((String) k).trim () ;
          if (FORM_SEARCH_LENGTH.equals (s) || FORM_SEARCH_OFFSET.equals (s))
            continue ;
          String[] vals = params.get (k) ;
          v = (vals[0] == null ? "" : vals[0].trim ()) ;
          filter.put (s, v) ;
          }
    
        if (filter.size () == 0)
          throw new IllegalArgumentException ("you must specify search criteria") ;
    
        Map<UUID, Map<String, String>> r = searcher.getFullClipProperties (filter, offset, len) ;
        ClipPropertiesList out = convertForWeb (r) ;
    
        String xml = MarshallerUtils.convertObjectToXML (marshaller, out) ;
    
        response.reset () ;
        response.setContentType ("text/xml") ;
    
        OutputStream os = response.getOutputStream () ;
        StringUtils.deliverString (xml, os) ;
    
        return null ;
        }
    Code:
    <context:component-scan base-package="com.mycomp"/>
    
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/views/"/>
      <property name="suffix" value=".jsp"/>
    </bean>
    As you can see I've fallen into several of the trappings of newbie misunderstanding. Namely generating content in the Controller, not sure that the transaction boundary is supposed to be here, I'm parsing my own request parameters, and probably a whole host of other errors.

    The first thing I would like to do is to separate out the controller from the viewer. I heard that you can have 1 controller that creates the model and then depending on the extension renders it differently.
    My hope is that when a person calls /mysevlet/search.html the above controller is used and the model is sent down to a jsp. Alternatively if someone calls /mysevlet/search.xml it is rendered differently by some other class using my marshallers.

    I'm stuck, I don't understand how I can chain ViewResolvers together such that I get a different thing at the end of the same controller, or have I missed the plot?
Working...
X