Added content negotiation and MarshallingView to petclinic
This commit is contained in:
parent
df563dfcd6
commit
fae0110536
|
|
@ -22,6 +22,7 @@
|
|||
<dependency org="com.sun.syndication" name="com.springsource.com.sun.syndication" rev="0.9.0" conf="compile->compile"/>
|
||||
<dependency org="javax.servlet" name="com.springsource.javax.servlet" rev="2.5.0" conf="provided->runtime"/>
|
||||
<dependency org="javax.servlet" name="com.springsource.javax.servlet.jsp.jstl" rev="1.1.2" conf="compile->runtime"/>
|
||||
<dependency org="javax.xml.bind" name="com.springsource.javax.xml.bind" rev="2.1.7" conf="compile->runtime"/>
|
||||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.logging" rev="1.1.1" conf="compile->compile"/>
|
||||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.dbcp" rev="1.2.2.osgi" conf="compile->runtime"/>
|
||||
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="compile->runtime"/>
|
||||
|
|
@ -30,6 +31,7 @@
|
|||
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm" rev="2.2.3" conf="compile->compile" />
|
||||
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm.commons" rev="2.2.3" conf="compile->compile" />
|
||||
<dependency org="org.springframework" name="org.springframework.orm" rev="latest.integration" conf="compile->compile"/>
|
||||
<dependency org="org.springframework" name="org.springframework.oxm" rev="latest.integration" conf="compile->compile"/>
|
||||
<dependency org="org.springframework" name="org.springframework.web.servlet" rev="latest.integration" conf="compile->compile"/>
|
||||
<dependency org="org.hsqldb" name="com.springsource.org.hsqldb" rev="1.8.0.9" conf="compile->runtime"/>
|
||||
<dependency org="javax.persistence" name="com.springsource.javax.persistence" rev="1.0.0" conf="compile->compile"/>
|
||||
|
|
|
|||
|
|
@ -169,158 +169,31 @@
|
|||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$IVY_CACHE$/javax.xml.bind/com.springsource.javax.xml.bind/2.1.7/com.springsource.javax.xml.bind-2.1.7.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$IVY_CACHE$/javax.xml.bind/com.springsource.javax.xml.bind/2.1.7/com.springsource.javax.xml.bind-sources-2.1.7.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$IVY_CACHE$/com.thoughtworks.xstream/com.springsource.com.thoughtworks.xstream/1.3.0/com.springsource.com.thoughtworks.xstream-1.3.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
<setting name="state" value="1" />
|
||||
</Base>
|
||||
<LanguageOptions name="HTML">
|
||||
<option name="templateOptions">
|
||||
<value>
|
||||
<option name="block" value="true" />
|
||||
<option name="separateBefore" value="false" />
|
||||
<option name="separateAfter" value="false" />
|
||||
<option name="prefixLines" value="true" />
|
||||
<option name="lenBefore" value="80" />
|
||||
<option name="lenAfter" value="80" />
|
||||
<option name="box" value="false" />
|
||||
<option name="filler" value=" " />
|
||||
</value>
|
||||
</option>
|
||||
<option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." />
|
||||
<option name="keyword" value="Copyright" />
|
||||
<option name="fileTypeOverride" value="1" />
|
||||
<option name="relativeBefore" value="true" />
|
||||
<option name="addBlankAfter" value="true" />
|
||||
<option name="fileLocation" value="1" />
|
||||
<option name="useAlternate" value="false" />
|
||||
</LanguageOptions>
|
||||
<LanguageOptions name="JAVA">
|
||||
<option name="templateOptions">
|
||||
<value>
|
||||
<option name="block" value="true" />
|
||||
<option name="separateBefore" value="false" />
|
||||
<option name="separateAfter" value="false" />
|
||||
<option name="prefixLines" value="true" />
|
||||
<option name="lenBefore" value="80" />
|
||||
<option name="lenAfter" value="80" />
|
||||
<option name="box" value="false" />
|
||||
<option name="filler" value=" " />
|
||||
</value>
|
||||
</option>
|
||||
<option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." />
|
||||
<option name="keyword" value="Copyright" />
|
||||
<option name="fileTypeOverride" value="2" />
|
||||
<option name="relativeBefore" value="true" />
|
||||
<option name="addBlankAfter" value="true" />
|
||||
<option name="fileLocation" value="1" />
|
||||
<option name="useAlternate" value="false" />
|
||||
</LanguageOptions>
|
||||
<LanguageOptions name="JSP">
|
||||
<option name="templateOptions">
|
||||
<value>
|
||||
<option name="block" value="true" />
|
||||
<option name="separateBefore" value="false" />
|
||||
<option name="separateAfter" value="false" />
|
||||
<option name="prefixLines" value="true" />
|
||||
<option name="lenBefore" value="80" />
|
||||
<option name="lenAfter" value="80" />
|
||||
<option name="box" value="false" />
|
||||
<option name="filler" value=" " />
|
||||
</value>
|
||||
</option>
|
||||
<option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." />
|
||||
<option name="keyword" value="Copyright" />
|
||||
<option name="fileTypeOverride" value="1" />
|
||||
<option name="relativeBefore" value="true" />
|
||||
<option name="addBlankAfter" value="true" />
|
||||
<option name="fileLocation" value="1" />
|
||||
<option name="useAlternate" value="false" />
|
||||
</LanguageOptions>
|
||||
<LanguageOptions name="JavaScript">
|
||||
<option name="templateOptions">
|
||||
<value>
|
||||
<option name="block" value="true" />
|
||||
<option name="separateBefore" value="false" />
|
||||
<option name="separateAfter" value="false" />
|
||||
<option name="prefixLines" value="true" />
|
||||
<option name="lenBefore" value="80" />
|
||||
<option name="lenAfter" value="80" />
|
||||
<option name="box" value="false" />
|
||||
<option name="filler" value=" " />
|
||||
</value>
|
||||
</option>
|
||||
<option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." />
|
||||
<option name="keyword" value="Copyright" />
|
||||
<option name="fileTypeOverride" value="1" />
|
||||
<option name="relativeBefore" value="true" />
|
||||
<option name="addBlankAfter" value="true" />
|
||||
<option name="fileLocation" value="1" />
|
||||
<option name="useAlternate" value="false" />
|
||||
</LanguageOptions>
|
||||
<LanguageOptions name="Properties">
|
||||
<option name="templateOptions">
|
||||
<value>
|
||||
<option name="block" value="true" />
|
||||
<option name="separateBefore" value="false" />
|
||||
<option name="separateAfter" value="false" />
|
||||
<option name="prefixLines" value="true" />
|
||||
<option name="lenBefore" value="80" />
|
||||
<option name="lenAfter" value="80" />
|
||||
<option name="box" value="false" />
|
||||
<option name="filler" value=" " />
|
||||
</value>
|
||||
</option>
|
||||
<option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." />
|
||||
<option name="keyword" value="Copyright" />
|
||||
<option name="fileTypeOverride" value="1" />
|
||||
<option name="relativeBefore" value="true" />
|
||||
<option name="addBlankAfter" value="true" />
|
||||
<option name="fileLocation" value="1" />
|
||||
<option name="useAlternate" value="false" />
|
||||
</LanguageOptions>
|
||||
<LanguageOptions name="XML">
|
||||
<option name="templateOptions">
|
||||
<value>
|
||||
<option name="block" value="true" />
|
||||
<option name="separateBefore" value="false" />
|
||||
<option name="separateAfter" value="false" />
|
||||
<option name="prefixLines" value="true" />
|
||||
<option name="lenBefore" value="80" />
|
||||
<option name="lenAfter" value="80" />
|
||||
<option name="box" value="false" />
|
||||
<option name="filler" value=" " />
|
||||
</value>
|
||||
</option>
|
||||
<option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." />
|
||||
<option name="keyword" value="Copyright" />
|
||||
<option name="fileTypeOverride" value="1" />
|
||||
<option name="relativeBefore" value="true" />
|
||||
<option name="addBlankAfter" value="true" />
|
||||
<option name="fileLocation" value="1" />
|
||||
<option name="useAlternate" value="false" />
|
||||
</LanguageOptions>
|
||||
<LanguageOptions name="__TEMPLATE__">
|
||||
<option name="templateOptions">
|
||||
<value>
|
||||
<option name="block" value="true" />
|
||||
<option name="separateBefore" value="false" />
|
||||
<option name="separateAfter" value="false" />
|
||||
<option name="prefixLines" value="true" />
|
||||
<option name="lenBefore" value="80" />
|
||||
<option name="lenAfter" value="80" />
|
||||
<option name="box" value="false" />
|
||||
<option name="filler" value=" " />
|
||||
</value>
|
||||
</option>
|
||||
<option name="notice" value="Copyright 2002-&#36;today.year the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." />
|
||||
<option name="keyword" value="Copyright" />
|
||||
<option name="fileTypeOverride" value="4" />
|
||||
<option name="relativeBefore" value="true" />
|
||||
<option name="addBlankAfter" value="true" />
|
||||
<option name="fileLocation" value="1" />
|
||||
<option name="useAlternate" value="false" />
|
||||
</LanguageOptions>
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.util.Collections;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
|
|
@ -15,6 +16,7 @@ import org.springframework.beans.support.PropertyComparator;
|
|||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class Vet extends Person {
|
||||
|
||||
|
|
@ -32,6 +34,7 @@ public class Vet extends Person {
|
|||
return this.specialties;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<Specialty> getSpecialties() {
|
||||
List<Specialty> sortedSpecs = new ArrayList<Specialty>(getSpecialtiesInternal());
|
||||
PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.samples.petclinic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing a list of veterinarians. Mostly here to be used for the 'vets'
|
||||
* {@link org.springframework.web.servlet.view.xml.MarshallingView}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@XmlRootElement
|
||||
public class Vets {
|
||||
|
||||
private List<Vet> vets;
|
||||
|
||||
@XmlElement
|
||||
public List<Vet> getVetList() {
|
||||
if (vets == null) {
|
||||
vets = new ArrayList<Vet>();
|
||||
}
|
||||
return vets;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package org.springframework.samples.petclinic.web;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.samples.petclinic.Clinic;
|
||||
import org.springframework.samples.petclinic.Vets;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
|
@ -53,7 +54,9 @@ public class ClinicController {
|
|||
*/
|
||||
@RequestMapping("/vets")
|
||||
public ModelMap vetsHandler() {
|
||||
return new ModelMap(this.clinic.getVets());
|
||||
Vets vets = new Vets();
|
||||
vets.getVetList().addAll(this.clinic.getVets());
|
||||
return new ModelMap(vets);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@
|
|||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
<spring:url value="{ownerId}/pets/{petId}/visits" var="feedUrl">
|
||||
<spring:url value="{ownerId}/pets/{petId}/visits.atom" var="feedUrl">
|
||||
<spring:param name="ownerId" value="${owner.id}"/>
|
||||
<spring:param name="petId" value="${pet.id}"/>
|
||||
</spring:url>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<th>Specialties</th>
|
||||
</thead>
|
||||
</tr>
|
||||
<c:forEach var="vet" items="${vetList}">
|
||||
<c:forEach var="vet" items="${vets.vetList}">
|
||||
<tr>
|
||||
<td>${vet.firstName} ${vet.lastName}</td>
|
||||
<td>
|
||||
|
|
@ -22,5 +22,12 @@
|
|||
</tr>
|
||||
</c:forEach>
|
||||
</table>
|
||||
<table class="table-buttons">
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<spring:url value="/clinic/vets.xml" escapeXml="true" />">View as XML</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<%@ include file="/WEB-INF/jsp/footer.jsp" %>
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@
|
|||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:oxm="http://www.springframework.org/schema/oxm"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
|
||||
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">
|
||||
|
||||
<!--
|
||||
- The controllers are autodetected POJOs labeled with the @Controller annotation.
|
||||
|
|
@ -49,26 +51,57 @@
|
|||
</bean>
|
||||
|
||||
<!--
|
||||
- This bean configures the 'prefix' and 'suffix' properties of
|
||||
- InternalResourceViewResolver, which resolves logical view names
|
||||
- returned by Controllers. For example, a logical view name of "vets"
|
||||
- will be mapped to "/WEB-INF/jsp/vets.jsp".
|
||||
- This view resolver delegates to the InternalResourceViewResolver and BeanNameViewResolver,
|
||||
- and uses the requested media type to pick a matching view. When the media type is 'text/html',
|
||||
- it will delegate to the InternalResourceViewResolver's JstlView, otherwise to the
|
||||
- BeanNameViewResolver. Note the use of the expression language to refer to the contentType
|
||||
- property of the vets view bean, setting it to 'application/vnd.springsource.samples.petclinic+xml'.
|
||||
-->
|
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
|
||||
p:suffix=".jsp"/>
|
||||
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
|
||||
<property name="mediaTypes">
|
||||
<map>
|
||||
<entry key="xml" value="application/vnd.springsource.samples.petclinic+xml"/>
|
||||
<entry key="atom" value="#{vets.contentType}"/>
|
||||
</map>
|
||||
</property>
|
||||
<property name="viewResolvers">
|
||||
<list>
|
||||
<!--
|
||||
- The BeanNameViewResolver is used to pick up the visits view name (below).
|
||||
- It has the order property set to 2, which means that this will
|
||||
- be the first view resolver to be used after the delegating content
|
||||
- negotiating view resolver.
|
||||
-->
|
||||
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="1"/>
|
||||
<!--
|
||||
|
||||
- This bean configures the 'prefix' and 'suffix' properties of
|
||||
- InternalResourceViewResolver, which resolves logical view names
|
||||
- returned by Controllers. For example, a logical view name of "vets"
|
||||
- will be mapped to "/WEB-INF/jsp/vets.jsp".
|
||||
-->
|
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
|
||||
p:suffix=".jsp" p:order="2"/>
|
||||
</list>
|
||||
|
||||
<!--
|
||||
- The BeanNameViewResolver is used to pick up the visits view name (below).
|
||||
- It has the order property set to 1, which means that this will
|
||||
- be the first view resolver to be used.
|
||||
-->
|
||||
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="1"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<!--
|
||||
- The AtomView rendering a Atom feed of the visits
|
||||
-->
|
||||
<bean id="visits" class="org.springframework.samples.petclinic.web.VisitsAtomView"/>
|
||||
|
||||
<bean id="vets" class="org.springframework.web.servlet.view.xml.MarshallingView">
|
||||
<property name="contentType" value="application/vnd.springsource.samples.petclinic+xml"/>
|
||||
<property name="marshaller" ref="marshaller"/>
|
||||
</bean>
|
||||
|
||||
<oxm:jaxb2-marshaller id="marshaller">
|
||||
<oxm:class-to-be-bound name="org.springframework.samples.petclinic.Vets"/>
|
||||
</oxm:jaxb2-marshaller>
|
||||
|
||||
<!--
|
||||
- Message source for this context, loaded from localized "messages_xx" files.
|
||||
- Could also reside in the root application context, as it is generic,
|
||||
|
|
|
|||
Loading…
Reference in New Issue