At line 15 changed 2 lines. |
* [4] Modify User Service Junit test |
* [5] Run User Service Junit test |
* [4] Modify UserManagerTest Junit test |
* [5] Run UserManagerTest Junit test |
At line 69 added 2 lines. |
|
|
At line 105 changed 1 line. |
import org.appfuse.util.AbstractObjectReader; |
import org.appfuse.fop.AbstractObjectReader; |
At line 146 added 3 lines. |
|
|
|
At line 173 changed 1 line. |
processUserDetails(user); |
processUserDetails(user); |
At line 197 added 1 line. |
|
At line 211 changed 1 line. |
Place the user2fo.xsl stylesheet in src/web/**/fop/user2fo.xsl. |
Place the user2fo.xsl stylesheet in src/service/**/fop/xsl/user2fo.xsl. |
At line 327 changed 1 line. |
!!Modify User Junit test [#4] |
!!Modify UserManagerTest.java Junit test [#4] |
At line 329 changed 1 line. |
To support the execution of the User service level test, we need another helper file. This file (attached at the end) is called FOPHelper.java and lives in src/service/**/utils. |
To support the execution of the User service level test, we need another helper file. This file (attached at the end) is called FOPHelper.java and lives in src/service/**/fop. |
At line 360 changed 1 line. |
import org.appfuse.utils.FOPHelper; |
import org.appfuse.fop.FOPHelper; |
At line 364 changed 32 lines. |
|
try { |
User testData = new User(); |
testData.setUsername("tomcat"); |
testData.getRoles().add(new Role("user")); |
// set expected behavior on dao |
userDAO.expects(once()).method("getUser") |
.with(eq("tomcat")).will(returnValue(testData)); |
|
user = userManager.getUser("tomcat"); |
|
File baseDir = new File("."); |
File xslFile = new File(baseDir, "./src/web/org/appfuse/webapp/fop/user2fo.xsl"); |
if (xslFile.exists()) { |
log.info("xslFile exists"); |
} |
File pdfFile = new File(baseDir, "user.pdf"); |
File xmlFile = new File(baseDir, "user.xml"); |
|
log.debug("Input: a User object"); |
log.debug("Stylesheet: " + xslFile); |
log.debug("Output: PDF (" + pdfFile + ")"); |
log.debug("Transforming..."); |
|
FOPHelper fopHelper = new FOPHelper(); |
fopHelper.convertUser2PDF(user, xslFile, pdfFile); |
fopHelper.convertUser2XML(user, xmlFile); |
|
} |
catch (Throwable e) { |
log.error("Error [" + e.getMessage() + "]", e); |
} |
|
log.info("Inside testGeneratePSF"); |
User testData = new User(); |
testData.setUsername("tomcat"); |
testData.getRoles().add(new Role("user")); |
// set expected behavior on dao |
userDAO.expects(once()).method("getUser") |
.with(eq("tomcat")).will(returnValue(testData)); |
|
user = userManager.getUser("tomcat"); |
UserInputSource uis = new UserInputSource(user); |
|
// Setup directories |
File baseDir = new File("."); |
File outDir = new File("."); |
outDir.mkdirs(); |
|
//Setup input and output |
File xslFile = new File(baseDir, "./src/service/org/appfuse/fop/xsl/user2fo.xsl"); |
File pdfFile = new File(outDir, "user.pdf"); |
File xmlFile = new File(outDir, "user.xml"); |
File foFile = new File(outDir, "user.fo"); |
|
log.debug("Input: a UserInputSource object"); |
log.debug("Stylesheet: " + xslFile); |
log.debug("Output: PDF (" + pdfFile + ")"); |
log.debug("Output: FO (" + foFile + ")"); |
log.debug("Transforming..."); |
|
FOPHelper fopHelper = new FOPHelper(); |
fopHelper.convertPOJO2PDF(uis, xslFile, pdfFile, foFile); |
fopHelper.convertPOJO2XML(uis, xmlFile); |
At line 408 changed 2 lines. |
[junit] [appfuse] DEBUG [main] UserManagerTest.testGeneratePDF(88) | Input: a User object |
[junit] [appfuse] DEBUG [main] UserManagerTest.testGeneratePDF(89) | Stylesheet: ././src/web/org/appfuse/webapp/fop/user2fo.xsl |
[junit] [appfuse] DEBUG [main] UserManagerTest.testGeneratePDF(88) | Input: a UserInputSource object |
[junit] [appfuse] DEBUG [main] UserManagerTest.testGeneratePDF(89) | Stylesheet: ././src/service/org/appfuse/fop/xsl/user2fo.xsl |
At line 423 changed 1 line. |
|
|
At line 427 changed 1 line. |
|
import org.appfuse.fop.UserXMLReader; |
import org.appfuse.fop.FOPHelper; |
|
At line 434 changed 5 lines. |
|
import java.io.ByteArrayOutputStream; |
import java.io.File; |
import java.io.IOException; |
|
|
import java.io.*; |
import java.util.Date; |
|
At line 444 changed 1 line. |
|
|
At line 446 removed 1 line. |
import org.springframework.core.io.ClassPathResource; |
At line 449 changed 1 line. |
|
import org.springframework.core.io.*; |
import org.xml.sax.InputSource; |
|
At line 463 added 1 line. |
import javax.xml.transform.sax.SAXSource; |
At line 456 changed 1 line. |
|
|
At line 461 changed 1 line. |
* <p><a href="FopServlet.java.html"><i>View Source</i></a></p> |
* <p><a href="FOPServlet.java.html"><i>View Source</i></a></p> |
At line 467 changed 1 line. |
* display-name="Fop Servlet" |
* display-name="FOP Servlet" |
At line 474 changed 4 lines. |
|
public class FopServlet extends HttpServlet { |
|
private Logger logger = null; |
|
public class FOPServlet extends HttpServlet { |
|
private Logger logger = null; |
At line 480 changed 2 lines. |
|
|
|
|
At line 483 changed 3 lines. |
this.servletContext = getServletContext(); |
this.ctx = |
WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); |
this.servletContext = getServletContext(); |
this.ctx = |
WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); |
At line 487 changed 1 line. |
|
|
At line 501 changed 1 line. |
|
|
At line 515 changed 1 line. |
|
|
At line 528 changed 4 lines. |
|
ByteArrayOutputStream out = null; |
|
try { |
|
ByteArrayOutputStream out = null; |
|
try { |
At line 533 changed 1 line. |
|
|
At line 536 changed 30 lines. |
|
Driver driver = new Driver(); |
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); |
driver.setLogger(logger); |
MessageHandler.setScreenLogger(logger); |
driver.setRenderer(Driver.RENDER_PDF); |
|
|
// Start with a bigger buffer to avoid too many buffer reallocations |
out = new ByteArrayOutputStream(16384); |
driver.setOutputStream(out); |
|
ClassPathResource resource = new |
ClassPathResource("/org/appfuse/webapp/fop/user2fo.xsl"); |
File xslFile = resource.getFile(); |
|
//Setup XSLT |
TransformerFactory factory = TransformerFactory.newInstance(); |
Transformer transformer = factory.newTransformer(new StreamSource(xslFile)); |
|
//Setup input for XSLT transformation |
Source src = new UserInputSource(user).getSource(); |
|
//Resulting SAX events (the generated FO) must be piped through to FOP |
Result res = new SAXResult(driver.getContentHandler()); |
|
//Start XSLT transformation and FOP processing |
transformer.transform(src, res); |
|
byte[] content = out.toByteArray(); |
UserInputSource uis = new UserInputSource(user); |
|
ClassPathResource resource = |
new ClassPathResource("/org/appfuse/fop/xsl/user2fo.xsl"); |
|
byte[] content = FOPHelper.createPDF(uis, resource); |
response.setHeader("Content-Disposition", |
"attachment; filename=user-" + user.getUsername() + ".pdf"); |
At line 567 removed 2 lines. |
response.setHeader("Content-Disposition", "attachment; filename=user-" + |
user.getUserName() + ".pdf"); |
At line 572 changed 1 line. |
|
|
At line 576 changed 3 lines. |
if (out!=null) { |
out.close(); |
} |
if (out!=null) { |
out.close(); |
} |
At line 582 removed 1 line. |
|
At line 622 removed 3 lines. |
# |
|
|
At line 672 changed 1 line. |
Also inside the package-web target add this line: |
Also inside the package-web target add this block: |
At line 675 changed 1 line. |
<include name="**/*.xsl"/> |
|
<fileset dir="src/service"> |
<include name="**/*.xsl"/> |
</fileset> |
|
At line 684 removed 1 line. |
<include name="**/*.xsl"/> |
At line 670 added 3 lines. |
<fileset dir="src/service"> |
<include name="**/*.xsl"/> |
</fileset> |
At line 688 removed 1 line. |
which ensures the xsl file is deployed. |
At line 676 added 2 lines. |
which ensures the xsl file is deployed into our runtime classpath. |
|
At line 694 changed 1 line. |
*src/web/org/appfuse/webapp/fop/user2fo.xsl |
|
At line 685 added 1 line. |
*src/service/org/appfuse/fop/xsl/user2fo.xsl |
At line 709 changed 2 lines. |
*Ensure the xsl file is within your webapps/appfuse/WEB-INF/classes/** runtime directory somewhere |
*Ensure the path to load the user2fo.xsl file, specified in FopServlet, is correct (in case you moved it) |
*Ensure the xsl file is within your webapps/appfuse/WEB-INF/classes/** runtime directory |
*Ensure the path to load the user2fo.xsl file, specified in FOPServlet, is correct (in case you moved it) |