Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add image selection step to create roll; add frameUrl JSP function

  • Loading branch information...
commit 998eab541cb7b798705739d85f991a298af62fd9 1 parent 360ee59
@ostewart authored
View
2  integration-test/src/test/java/com/trailmagic/photo/JavascriptTest.java
@@ -15,7 +15,7 @@
@Test
public void runJavascriptTestHarness() {
- driver = new FirefoxDriver();
+ driver = new FirefoxDriver("WebDriver");
driver.get("http://localhost:8081/photo/test-runner.html");
View
14 integration-test/src/test/java/com/trailmagic/photo/MoveImagesToNewRollAcceptanceTest.java
@@ -69,15 +69,17 @@ private void verifyCorrectImagesAppearOnNewRollPage() {
private void selectImage(String imageLink) {
- String path = null;
+ String path = getPathFromUrl(imageLink);
+ WebElement imageCheckbox = driver.findElement(By.xpath("//li[@id='" + path + "']/input"));
+ imageCheckbox.click();
+ }
+
+ private String getPathFromUrl(String imageLink) {
try {
- URL url = new URL(imageLink);
- path = url.getPath();
+ return new URL(imageLink).getPath();
} catch (MalformedURLException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ throw new RuntimeException("Couldn't extract path from URL", e);
}
-// WebElement imageCheckbox = driver.findElement(By.xpath("//a[@href='" + path + "']"));
-// imageCheckbox.click();
}
private void getUploadsInCreateNewRollState(WebElement createRollLink) {
View
21 photo/src/main/java/com/trailmagic/image/ui/ImageFrameLinkTag.java
@@ -13,14 +13,11 @@
*/
package com.trailmagic.image.ui;
-import javax.servlet.jsp.tagext.TagSupport;
+import com.trailmagic.image.ImageFrame;
+
import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;
-import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.context.support.WebApplicationContextUtils;
-import javax.servlet.http.HttpServletRequest;
-
-import com.trailmagic.image.*;
public class ImageFrameLinkTag extends TagSupport {
private ImageFrame frame;
@@ -34,7 +31,7 @@ public int doStartTag() throws JspException {
html.append("<a ");
html.append(formatAttribute("href", imageFrameUrl()));
if (id != null) {
- html.append(formatAttribute("id", id));
+ html.append(formatAttribute("id", id));
}
html.append(">");
@@ -46,15 +43,7 @@ public int doStartTag() throws JspException {
}
private String imageFrameUrl() {
- WebApplicationContext ctx =
- WebApplicationContextUtils
- .getRequiredWebApplicationContext(pageContext
- .getServletContext());
- LinkHelper helper =
- (LinkHelper)ctx.getBean("linkHelper");
- helper.setRequest((HttpServletRequest)pageContext.getRequest());
-
- return helper.getImageGroupFrameUrl(frame);
+ return JspFunctions.frameUri(pageContext, frame);
}
private String formatAttribute(String name, String value) {
View
20 photo/src/main/java/com/trailmagic/image/ui/ImageGroupLinkTag.java
@@ -84,24 +84,18 @@ public int doStartTag() throws JspException {
html.append("href=\"");
//XXX: yeek?
- WebApplicationContext ctx =
- WebApplicationContextUtils
- .getRequiredWebApplicationContext(pageContext
- .getServletContext());
- LinkHelper helper =
- (LinkHelper)ctx.getBean("linkHelper");
- // XXX: check for null bean
- // XXX: evil cast?
- helper.setRequest((HttpServletRequest)pageContext.getRequest());
+ WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(pageContext.getServletContext());
+ LinkHelper helper = ctx.getBean(LinkHelper.class);
+ HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
if ( m_image != null ) {
- html.append(helper.getImageGroupFrameUrl(m_imageGroup, m_image));
+ html.append(helper.getImageGroupFrameUrl(request, m_imageGroup, m_image));
} else if ( m_imageGroup != null ) {
- html.append(helper.getImageGroupUrl(m_imageGroup));
+ html.append(helper.getImageGroupUrl(request, m_imageGroup));
} else if ( m_owner != null ) {
- html.append(helper.getImageGroupsUrl(m_groupType, m_owner));
+ html.append(helper.getImageGroupsUrl(request, m_groupType, m_owner));
} else {
- html.append(helper.getImageGroupsRootUrl(m_groupType));
+ html.append(helper.getImageGroupsRootUrl(request, m_groupType));
}
html.append("\">");
pageContext.getOut().write(html.toString());
View
6 photo/src/main/java/com/trailmagic/image/ui/ImageTag.java
@@ -98,12 +98,8 @@ public int doStartTag() throws JspException {
.getServletContext());
LinkHelper helper =
(LinkHelper)ctx.getBean("linkHelper");
- // XXX: check for null bean
- // XXX: evil cast?
- helper.setRequest((HttpServletRequest)
- pageContext.getRequest());
- html.append(helper.getImageMFUrl(mf));
+ html.append(helper.getImageMFUrl((HttpServletRequest) pageContext.getRequest(), mf));
html.append("\" height=\"");
html.append(mf.getHeight());
html.append("\" width=\"");
View
17 photo/src/main/java/com/trailmagic/image/ui/JspFunctions.java
@@ -0,0 +1,17 @@
+package com.trailmagic.image.ui;
+
+import com.trailmagic.image.ImageFrame;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.jsp.PageContext;
+
+public class JspFunctions {
+ public static String frameUri(PageContext pageContext, ImageFrame frame) {
+ WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(pageContext.getServletContext());
+ LinkHelper helper = (LinkHelper) ctx.getBean("linkHelper");
+
+ return helper.getImageGroupFrameUrl((HttpServletRequest) pageContext.getRequest(), frame);
+ }
+}
View
83 photo/src/main/java/com/trailmagic/image/ui/LinkHelper.java
@@ -20,72 +20,51 @@
import javax.servlet.http.HttpServletRequest;
-
public class LinkHelper {
- private HttpServletRequest m_request;
- private String m_albumServletPath;
- /*
- public LinkHelper(HttpServletRequest req) {
- m_request = req;
- }
- */
public LinkHelper() {
}
- public void setAlbumServletPath(String path) {
- // XXX: trailing slash?
- m_albumServletPath = path;
- }
-
- public void setRequest(HttpServletRequest req) {
- m_request = req;
- }
-
- public String getImageGroupFrameUrl(ImageFrame frame) {
- return getImageGroupsRootUrl(frame.getImageGroup().getType()) +
- frame.getImage().getOwner().getScreenName() + "/" +
- frame.getImageGroup().getName() + "/" + frame.getImage().getId();
- }
-
- public String getImageGroupFrameUrl(ImageGroup imageGroup, Long imageId) {
- return getImageGroupsRootUrl(imageGroup.getType()) +
- imageGroup.getOwner().getScreenName() + "/" +
- imageGroup.getName() + "/" + imageId;
+ public String getImageGroupFrameUrl(HttpServletRequest request, ImageFrame frame) {
+ return getImageGroupsRootUrl(request, frame.getImageGroup().getType()) +
+ frame.getImage().getOwner().getScreenName() + "/" +
+ frame.getImageGroup().getName() + "/" + frame.getImage().getId();
}
- public String getImageGroupUrl(ImageGroup imageGroup) {
- return getImageGroupsRootUrl(imageGroup.getType()) +
- imageGroup.getOwner().getScreenName() + "/" +
- imageGroup.getName() + "/";
+ public String getImageGroupFrameUrl(HttpServletRequest request, ImageGroup imageGroup, Long imageId) {
+ return getImageGroupsRootUrl(request, imageGroup.getType()) +
+ imageGroup.getOwner().getScreenName() + "/" +
+ imageGroup.getName() + "/" + imageId;
}
- public String getImageGroupsUrl(ImageGroup.Type groupType, User owner) {
- return getImageGroupsRootUrl(groupType) +
- owner.getScreenName() + "/";
+ public String getImageGroupUrl(HttpServletRequest request, ImageGroup imageGroup) {
+ return getImageGroupsRootUrl(request, imageGroup.getType()) +
+ imageGroup.getOwner().getScreenName() + "/" +
+ imageGroup.getName() + "/";
}
- public String getAlbumsRootUrl() {
- return m_request.getContextPath() + m_albumServletPath;
+ public String getImageGroupsUrl(HttpServletRequest request, ImageGroup.Type groupType, User owner) {
+ return getImageGroupsRootUrl(request, groupType) +
+ owner.getScreenName() + "/";
}
- public String getImageGroupsRootUrl(ImageGroup.Type type) {
- String prettyType;
- switch (type) {
- case ROLL:
- prettyType = "roll";
- break;
- case ALBUM:
- prettyType = "album";
- break;
- default:
- throw new IllegalArgumentException();
- }
- return m_request.getContextPath() + "/" + prettyType + "s/";
+ public String getImageGroupsRootUrl(HttpServletRequest request, ImageGroup.Type type) {
+ String prettyType;
+ switch (type) {
+ case ROLL:
+ prettyType = "roll";
+ break;
+ case ALBUM:
+ prettyType = "album";
+ break;
+ default:
+ throw new IllegalArgumentException();
+ }
+ return request.getContextPath() + "/" + prettyType + "s/";
}
- public String getImageMFUrl(ImageManifestation imf) {
- return m_request.getContextPath() + "/mf/by-id/" +
- imf.getId();
+ public String getImageMFUrl(HttpServletRequest request, ImageManifestation imf) {
+ return request.getContextPath() + "/mf/by-id/" +
+ imf.getId();
}
}
View
8 photo/src/main/resources/applicationContext-photo.xml
@@ -18,11 +18,5 @@
<beans>
- <!-- moved from applicationContext-imagestore.xml -->
- <bean id="linkHelper"
- class="com.trailmagic.image.ui.LinkHelper">
- <property name="albumServletPath">
- <value>/albums/</value>
- </property>
- </bean>
+ <bean id="linkHelper" class="com.trailmagic.image.ui.LinkHelper"/>
</beans>
View
4 photo/src/main/webapp/WEB-INF/jsp/newGroup.jspx
@@ -48,8 +48,8 @@
<ul class="thumbnailList">
<c:forEach var="frame" items="${frames}">
- <li>
- <input type="checkbox">
+ <li id="${tm:frameUri(pageContext, frame)}">
+ <input type="checkbox" id="image_${frame.image.id}">
<tm:image image="${frame.image}" sizeLabel="thumbnail"/>
</input>
</li>
View
18 photo/src/main/webapp/WEB-INF/trailmagic-image.tld
@@ -14,20 +14,21 @@
-->
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
- version="2.0">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
+ version="2.0">
<description>trailmagic.com Image Manipulation/Display Tags</description>
<tlib-version>1.2</tlib-version>
<short-name>image</short-name>
<uri>http://trailmagic.com/taglibs/image</uri>
-
+
<tag>
<description>Display an image by substituting an IMG tag</description>
<name>image</name>
<tag-class>com.trailmagic.image.ui.ImageTag</tag-class>
- <body-content>empty</body-content> <!-- change to alt -->
+ <body-content>empty</body-content>
+ <!-- change to alt -->
<attribute>
<name>image</name>
<required>true</required>
@@ -105,4 +106,11 @@
</tag>
+ <function>
+ <description>Output the display URL of an ImageFrame</description>
+ <name>frameUri</name>
+ <function-class>com.trailmagic.image.ui.JspFunctions</function-class>
+ <function-signature>java.lang.String frameUri(javax.servlet.jsp.PageContext, com.trailmagic.image.ImageFrame)</function-signature>
+ <example>${tm:frameUri(frame)}</example>
+ </function>
</taglib>
View
20 photo/src/test/java/com/trailmagic/image/ui/ImageGroupDisplayControllerTest.java
@@ -1,19 +1,20 @@
package com.trailmagic.image.ui;
-import com.trailmagic.image.ImageFrame;
-import com.trailmagic.image.ImageGroup;
-import com.trailmagic.image.ImageGroupRepository;
-import com.trailmagic.image.Photo;
+import com.trailmagic.image.*;
import com.trailmagic.image.security.ImageSecurityService;
import com.trailmagic.user.User;
import com.trailmagic.user.UserRepository;
import com.trailmagic.web.util.WebRequestTools;
+import org.aspectj.lang.Aspects;
+import org.aspectj.lang.NoAspectBoundException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor;
+import org.springframework.security.access.method.MapBasedMethodSecurityMetadataSource;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
@@ -39,11 +40,22 @@
@Before
public void setUp() throws Exception {
+ disableSecurityInterceptor();
MockitoAnnotations.initMocks(this);
handlerAdapter = new AnnotationMethodHandlerAdapter();
controller = new ImageGroupDisplayController(imageGroupRepository, imageSecurityService, userRepository, webRequestTools);
}
+ private void disableSecurityInterceptor() {
+ try {
+ final AspectJMethodSecurityInterceptor interceptor = new AspectJMethodSecurityInterceptor();
+ interceptor.setSecurityMetadataSource(new MapBasedMethodSecurityMetadataSource());
+ Aspects.aspectOf(ImageSecurityAspect.class).setSecurityInterceptor(interceptor);
+ } catch (NoAspectBoundException e) {
+ // AspectJ isn't on
+ }
+ }
+
@Test
public void testPlainGetDisplaysGroup() throws Exception {
User tester = new User(SCREEN_NAME);
Please sign in to comment.
Something went wrong with that request. Please try again.