Author: artdaw
Date: 2009-04-25 11:57:12 -0400 (Sat, 25 Apr 2009)
New Revision: 13874
Added:
trunk/docs/realworld_app_guide/en/src/main/docbook/includes/uploadImages.xml
Log:
https://jira.jboss.org/jira/browse/RF-5768 - Photo Album review
Added: trunk/docs/realworld_app_guide/en/src/main/docbook/includes/uploadImages.xml
===================================================================
--- trunk/docs/realworld_app_guide/en/src/main/docbook/includes/uploadImages.xml
(rev 0)
+++
trunk/docs/realworld_app_guide/en/src/main/docbook/includes/uploadImages.xml 2009-04-25
15:57:12 UTC (rev 13874)
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<section>
+ <title>Upload images</title>
+ <para>
+ In the previous chapter we have discussed how to create Navigation Panels
+ that represent "Shelves - Albums" hierarchy.
+ Now it is time to upload images.
+ </para>
+ <para>
+ The implementation of <emphasis
role="bold"><property><rich:fileUpload></property></emphasis>
+ in the Photo Album application uses the embedded Flash module
+ that adds extra functionality to the component:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>Multiple files choosing;</para>
+ </listitem>
+ <listitem>
+ <para>Definition of permitted file types in the "Open
File" dialog window;</para>
+ </listitem>
+ <listitem>
+ <para>A number of additional client side object properties.</para>
+ </listitem>
+ </itemizedlist>
+ <para>
+ The "/includes/fileUpload/fileUploader.xhtml" page
+ is responsible for the photos uploading functionality:
+ </para>
+ <programlisting role="XML"><![CDATA[...
+<rich:fileUpload
+ allowFlash="true" maxFilesQuantity="100"
autoclear="true"
+ fileUploadListener="#{fileUploadManager.listener}" id="fileUpload"
+ disabled="#{model.selectedAlbum == null}"
+ immediateUpload="false" acceptedTypes="jpg,jpeg">
+ <a4j:support event="onuploadcomplete" reRender="filesPanel,
treeform" actionListener="#{fileWrapper.setComplete(true)}"/>
+ <a4j:support event="onfileuploadcomplete" />
+</rich:fileUpload>
+...]]></programlisting>
+ <para>
+ The
<emphasis><property>"allowFlash"</property></emphasis>
attribute set to "true"
+ enables the Flash module.
+ </para>
+ <para>
+ The
<emphasis><property>"acceptedTypes"</property></emphasis>
attribute
+ specifies "jpg", "jpeg" as the permitted file types
you can upload.
+ </para>
+ <para>
+ The
<emphasis><property>"fileUploadListener"</property></emphasis>
attribute
+ represents the action listener method <code>listener()</code> of the
<code>fileUploadManager</code>
+ class that is notified after file is uploaded.
+ This method makes the main job on the upload:
+ </para>
+<programlisting role="JAVA"><![CDATA[...
+ public void listener(UploadEvent event) throws Exception {
+ UploadItem item = event.getUploadItem();
+ Image image = constructImage(item);
+ try {
+ extractMetadata(item, image);
+ } catch (Exception e1) {
+ addError(item, image, Constants.FILE_PROCESSING_ERROR);
+ return;
+ }
+ image.setAlbum(model.getSelectedAlbum());
+ if(image.getAlbum() == null){
+ addError(item, image, Constants.NO_ALBUM_TO_DOWNLOAD_ERROR);
+ return;
+ }
+ try{
+ if(imageAction.isImageWithThisPathExist(image)){
+ image.setPath(generateNewPath(image.getPath()));
+ }
+ imageAction.addImage(image);
+ }catch(Exception e){
+ addError(item, image, Constants.IMAGE_SAVING_ERROR);
+ return;
+ }
+ if(!fileManager.addImage(image.getFullPath(), item.getFile().getPath())){
+ addError(item, image, Constants.FILE_SAVE_ERROR);
+ return;
+ }
+ fileWrapper.getFiles().add(image);
+ Events.instance().raiseEvent(Constants.IMAGE_ADDED_EVENT, image);
+ item.getFile().delete();
+ }
+...]]></programlisting>
+ <para>
+ The <code>listener()</code> method is called at server side after every
file uploaded
+ and saves files in a temporary folder or in RAM.
+ In the Photo Album application the uploaded files are stored in the temporary folder
+ because the value of the <code>createTempFile</code> parameter is set to
<code>true</code>.
+ See the code from the <code>web.xml</code> descriptor:
+ </para>
+
+<programlisting role="XML"><![CDATA[...
+<filter>
+ <filter-name>Seam Filter</filter-name>
+ <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
+ <init-param>
+ <param-name>createTempFiles</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ ...
+</filter>
+...]]></programlisting>
+ <para>
+ After the image is stored in the temporary folder
+ the <code>listener()</code> method creates an
<code>Image</code> object
+ and extracts all image metadata such as Camera name, Image size, etc.
+ It saves six different sizes of the photo in order to create thumbnails
+ and perform images scaling.
+ After that the photo is added into the database
+ the temporary file is removed.
+ </para>
+</section>
Property changes on:
trunk/docs/realworld_app_guide/en/src/main/docbook/includes/uploadImages.xml
___________________________________________________________________
Name: svn:executable
+ *