SPR-5460: Add AtomView sample to PetClinic
This commit is contained in:
parent
ce83ebf0de
commit
b96a7a7a8c
|
|
@ -19,6 +19,7 @@
|
|||
</publications>
|
||||
|
||||
<dependencies>
|
||||
<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="org.apache.commons" name="com.springsource.org.apache.commons.logging" rev="1.1.1" conf="compile->compile"/>
|
||||
|
|
|
|||
|
|
@ -73,17 +73,6 @@
|
|||
<orderEntry type="module" module-name="context" />
|
||||
<orderEntry type="module" module-name="jdbc" />
|
||||
<orderEntry type="module" module-name="test" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$IVY_CACHE$/org.junit/com.springsource.org.junit/4.4.0/com.springsource.org.junit-4.4.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$IVY_CACHE$/org.junit/com.springsource.org.junit/4.4.0/com.springsource.org.junit-sources-4.4.0.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
|
|
@ -96,15 +85,6 @@
|
|||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module" module-name="orm" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$IVY_CACHE$/org.aspectj/com.springsource.org.aspectj.weaver/1.5.4/com.springsource.org.aspectj.weaver-1.5.4.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
|
|
@ -145,6 +125,202 @@
|
|||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$IVY_CACHE$/com.sun.syndication/com.springsource.com.sun.syndication/0.9.0/com.springsource.com.sun.syndication-0.9.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$IVY_CACHE$/com.sun.syndication/com.springsource.com.sun.syndication/0.9.0/com.springsource.com.sun.syndication-sources-0.9.0.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$IVY_CACHE$/org.aspectj/com.springsource.org.aspectj.weaver/1.6.2.RELEASE/com.springsource.org.aspectj.weaver-1.6.2.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$IVY_CACHE$/org.aspectj/com.springsource.org.aspectj.weaver/1.6.2.RELEASE/com.springsource.org.aspectj.weaver-sources-1.6.2.RELEASE.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$IVY_CACHE$/org.apache.commons/com.springsource.org.apache.commons.dbcp/1.2.2.osgi/com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$IVY_CACHE$/org.apache.commons/com.springsource.org.apache.commons.dbcp/1.2.2.osgi/com.springsource.org.apache.commons.dbcp-sources-1.2.2.osgi.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$IVY_CACHE$/org.junit/com.springsource.org.junit/4.5.0/com.springsource.org.junit-4.5.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$IVY_CACHE$/org.junit/com.springsource.org.junit/4.5.0/com.springsource.org.junit-sources-4.5.0.jar!/" />
|
||||
</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>
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class Visit extends BaseEntity {
|
|||
/** Setter for property pet.
|
||||
* @param pet New value of property pet.
|
||||
*/
|
||||
protected void setPet(Pet pet) {
|
||||
public void setPet(Pet pet) {
|
||||
this.pet = pet;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.samples.petclinic.Clinic;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
|
|
@ -42,8 +43,8 @@ public class ClinicController {
|
|||
|
||||
/**
|
||||
* Custom handler for displaying vets.
|
||||
* <p>
|
||||
* Note that this handler returns a plain {@link ModelMap} object instead of
|
||||
*
|
||||
* <p>Note that this handler returns a plain {@link ModelMap} object instead of
|
||||
* a ModelAndView, thus leveraging convention-based model attribute names.
|
||||
* It relies on the RequestToViewNameTranslator to determine the logical
|
||||
* view name based on the request URL: "/vets.do" -> "vets".
|
||||
|
|
@ -68,4 +69,17 @@ public class ClinicController {
|
|||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom handler for displaying an list of visits.
|
||||
*
|
||||
* @param petId the ID of the pet whose visits to display
|
||||
* @return a ModelMap with the model attributes for the view
|
||||
*/
|
||||
@RequestMapping(value="/owners/*/pets/{petId}/visits", method=RequestMethod.GET)
|
||||
public ModelAndView visitsHandler(@PathVariable int petId) {
|
||||
ModelAndView mav = new ModelAndView("visits");
|
||||
mav.addObject("visits", this.clinic.loadPet(petId).getVisits());
|
||||
return mav;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* 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.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.sun.syndication.feed.atom.Content;
|
||||
import com.sun.syndication.feed.atom.Entry;
|
||||
import com.sun.syndication.feed.atom.Feed;
|
||||
|
||||
import org.springframework.samples.petclinic.Visit;
|
||||
import org.springframework.web.servlet.view.feed.AbstractAtomFeedView;
|
||||
|
||||
/**
|
||||
* A view creating a Atom representation from a list of Visit objects.
|
||||
*
|
||||
* @author Alef Arendsen
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class VisitsAtomView extends AbstractAtomFeedView {
|
||||
|
||||
@Override
|
||||
protected void buildFeedMetadata(Map<String, Object> model, Feed feed, HttpServletRequest request) {
|
||||
feed.setId("tag:springsource.com");
|
||||
feed.setTitle("Pet Clinic Visits");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Visit> visits = (List<Visit>) model.get("visits");
|
||||
for (Visit visit : visits) {
|
||||
Date date = visit.getDate();
|
||||
if (feed.getUpdated() == null || date.compareTo(feed.getUpdated()) > 0) {
|
||||
feed.setUpdated(date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Entry> buildFeedEntries(Map<String, Object> model,
|
||||
HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Visit> visits = (List<Visit>) model.get("visits");
|
||||
List<Entry> entries = new ArrayList<Entry>(visits.size());
|
||||
|
||||
for (Visit visit : visits) {
|
||||
Entry entry = new Entry();
|
||||
String date = String.format("%1$tY-%1$tm-%1$td", visit.getDate());
|
||||
// see http://diveintomark.org/archives/2004/05/28/howto-atom-id#other
|
||||
entry.setId(String.format("tag:springsource.com,%s:%d", date, visit.getId()));
|
||||
entry.setTitle(String.format("%s visit on %s", visit.getPet().getName(), date));
|
||||
entry.setUpdated(visit.getDate());
|
||||
|
||||
Content summary = new Content();
|
||||
summary.setValue(visit.getDescription());
|
||||
entry.setSummary(summary);
|
||||
|
||||
entries.add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -94,6 +94,14 @@
|
|||
</spring:url>
|
||||
<a href="${fn:escapeXml(visitUrl)}">Add Visit</a>
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
<spring:url value="{ownerId}/pets/{petId}/visits" var="feedUrl">
|
||||
<spring:param name="ownerId" value="${owner.id}"/>
|
||||
<spring:param name="petId" value="${pet.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(feedUrl)}" rel="alternate" type="application/atom+xml">Atom Feed</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</c:forEach>
|
||||
|
|
|
|||
|
|
@ -57,6 +57,18 @@
|
|||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
|
||||
p:suffix=".jsp"/>
|
||||
|
||||
<!--
|
||||
- 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"/>
|
||||
|
||||
<!--
|
||||
- The AtomView rendering a Atom feed of the visits
|
||||
-->
|
||||
<bean id="visits" class="org.springframework.samples.petclinic.web.VisitsAtomView"/>
|
||||
|
||||
<!--
|
||||
- Message source for this context, loaded from localized "messages_xx" files.
|
||||
- Could also reside in the root application context, as it is generic,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* 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.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.syndication.feed.atom.Entry;
|
||||
import com.sun.syndication.feed.atom.Feed;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.samples.petclinic.Pet;
|
||||
import org.springframework.samples.petclinic.PetType;
|
||||
import org.springframework.samples.petclinic.Visit;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class VisitsAtomViewTest {
|
||||
|
||||
private VisitsAtomView visitView;
|
||||
|
||||
private Map<String, Object> model;
|
||||
|
||||
private Feed feed;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
visitView = new VisitsAtomView();
|
||||
PetType dog = new PetType();
|
||||
dog.setName("dog");
|
||||
Pet bello = new Pet();
|
||||
bello.setName("Bello");
|
||||
bello.setType(dog);
|
||||
Visit belloVisit = new Visit();
|
||||
belloVisit.setPet(bello);
|
||||
belloVisit.setDate(new Date(2009, 0, 1));
|
||||
belloVisit.setDescription("Bello visit");
|
||||
Pet wodan = new Pet();
|
||||
wodan.setName("Wodan");
|
||||
wodan.setType(dog);
|
||||
Visit wodanVisit = new Visit();
|
||||
wodanVisit.setPet(wodan);
|
||||
wodanVisit.setDate(new Date(2009, 0, 2));
|
||||
wodanVisit.setDescription("Wodan visit");
|
||||
List<Visit> visits = new ArrayList<Visit>();
|
||||
visits.add(belloVisit);
|
||||
visits.add(wodanVisit);
|
||||
|
||||
model = new HashMap<String, Object>();
|
||||
model.put("visits", visits);
|
||||
feed = new Feed();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildFeedMetadata() {
|
||||
visitView.buildFeedMetadata(model, feed, null);
|
||||
|
||||
assertNotNull("No id set", feed.getId());
|
||||
assertNotNull("No title set", feed.getTitle());
|
||||
assertEquals("Invalid update set", new Date(2009, 0, 2), feed.getUpdated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildFeedEntries() throws Exception {
|
||||
List<Entry> entries = visitView.buildFeedEntries(model, null, null);
|
||||
assertEquals("Invalid amount of entries", 2, entries.size());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue