implemented user photos! (imagestore table, ImageRetrieve servlet, a lot of
the underlying support) - incidentally, this is a lot of support for the SIG logo as well, just need some front end work for that in the future (of course, we now require JAI 1.1.1)
This commit is contained in:
parent
a900d9d51f
commit
6397f4212c
7
INSTALL
7
INSTALL
|
@ -4,9 +4,8 @@ INSTALLATION INSTRUCTIONS
|
||||||
Software requirements:
|
Software requirements:
|
||||||
You must install the following software on your system:
|
You must install the following software on your system:
|
||||||
|
|
||||||
* Java 2 SDK version 1.2.2. Venice is normally run with the Blackdown
|
* Java 2 SDK version 1.3.0/1.3.1. Venice is normally run with the Blackdown
|
||||||
JDK port, available at http://www.blackdown.org. Version 1.3.0 is
|
JDK port, available at http://www.blackdown.org.
|
||||||
being tested, and will likely be required sometime in the future.
|
|
||||||
* Java API for XML Parsing (JAXP) version 1.0.1, available from
|
* Java API for XML Parsing (JAXP) version 1.0.1, available from
|
||||||
http://java.sun.com.
|
http://java.sun.com.
|
||||||
* Java Secure Socket Extension (JSSE) version 1.0.2, available from
|
* Java Secure Socket Extension (JSSE) version 1.0.2, available from
|
||||||
|
@ -15,6 +14,8 @@ Software requirements:
|
||||||
* JavaMail API version 1.2, available from http://java.sun.com.
|
* JavaMail API version 1.2, available from http://java.sun.com.
|
||||||
* JavaBeans Activation Framework (JAF) version 1.0.1, available from
|
* JavaBeans Activation Framework (JAF) version 1.0.1, available from
|
||||||
http://java.sun.com. (Required by JavaMail.)
|
http://java.sun.com. (Required by JavaMail.)
|
||||||
|
* Java Advanced Imaging (JAI) version 1.1.1, available from
|
||||||
|
http://java.sun.com.
|
||||||
* Apache Jakarta LOG4J library 1.1.x, available from
|
* Apache Jakarta LOG4J library 1.1.x, available from
|
||||||
http://jakarta.apache.org.
|
http://jakarta.apache.org.
|
||||||
* MySQL 3.23.x (get the most recent 3.23 version), available from
|
* MySQL 3.23.x (get the most recent 3.23 version), available from
|
||||||
|
|
4
TODO
4
TODO
|
@ -47,10 +47,6 @@ Lots!
|
||||||
- Unimplemented functions on the Top page:
|
- Unimplemented functions on the Top page:
|
||||||
Customize Sideboxes
|
Customize Sideboxes
|
||||||
|
|
||||||
- Not everybody likes purple. Provide a way to change the default colors.
|
|
||||||
Probably via entries in render-config.xml. Of course, if we go to a
|
|
||||||
different rendering system eventually, we won't need this.
|
|
||||||
|
|
||||||
- Javadocs. Lots of javadocs.
|
- Javadocs. Lots of javadocs.
|
||||||
|
|
||||||
- Continue pressing on. "Failure is not an option."
|
- Continue pressing on. "Failure is not an option."
|
||||||
|
|
26
etc/web.xml
26
etc/web.xml
|
@ -206,6 +206,22 @@
|
||||||
<servlet-class>com.silverwrist.venice.servlets.PostShortcut</servlet-class>
|
<servlet-class>com.silverwrist.venice.servlets.PostShortcut</servlet-class>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>imageretrieve</servlet-name>
|
||||||
|
<description>
|
||||||
|
Retrieves images from the database image store and displays them.
|
||||||
|
</description>
|
||||||
|
<servlet-class>com.silverwrist.venice.servlets.ImageRetrieve</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>userphoto</servlet-name>
|
||||||
|
<description>
|
||||||
|
Changes the photo in a user's profile (uploads a new one).
|
||||||
|
</description>
|
||||||
|
<servlet-class>com.silverwrist.venice.servlets.UserPhoto</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
<!-- the following are test servlets, they should go away -->
|
<!-- the following are test servlets, they should go away -->
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
|
@ -309,6 +325,16 @@
|
||||||
<url-pattern>/go/*</url-pattern>
|
<url-pattern>/go/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>imageretrieve</servlet-name>
|
||||||
|
<url-pattern>/imagedata/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>userphoto</servlet-name>
|
||||||
|
<url-pattern>/userphoto</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<!-- the following are test servlets, they should go away -->
|
<!-- the following are test servlets, they should go away -->
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>testformdata</servlet-name>
|
<servlet-name>testformdata</servlet-name>
|
||||||
|
|
|
@ -414,6 +414,16 @@ CREATE TABLE adverts (
|
||||||
linkurl VARCHAR(255)
|
linkurl VARCHAR(255)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# Storage space for uploaded images.
|
||||||
|
CREATE TABLE imagestore (
|
||||||
|
imgid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
typecode SMALLINT DEFAULT 0,
|
||||||
|
ownerid INT,
|
||||||
|
mimetype VARCHAR(128) NOT NULL,
|
||||||
|
length INT NOT NULL,
|
||||||
|
data MEDIUMBLOB
|
||||||
|
);
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# Set table access rights
|
# Set table access rights
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
61
src/com/silverwrist/util/image/ImageLengthPair.java
Normal file
61
src/com/silverwrist/util/image/ImageLengthPair.java
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util.image;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public final class ImageLengthPair
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private int length;
|
||||||
|
private InputStream data;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public ImageLengthPair(int length, InputStream data)
|
||||||
|
{
|
||||||
|
this.length = length;
|
||||||
|
this.data = data;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public final int getLength()
|
||||||
|
{
|
||||||
|
return length;
|
||||||
|
|
||||||
|
} // end getLength
|
||||||
|
|
||||||
|
public final InputStream getData()
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
|
||||||
|
} // end getData
|
||||||
|
|
||||||
|
} // end class ImageLengthPair
|
153
src/com/silverwrist/util/image/ImageNormalizer.java
Normal file
153
src/com/silverwrist/util/image/ImageNormalizer.java
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util.image;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.image.*;
|
||||||
|
import java.awt.image.renderable.ParameterBlock;
|
||||||
|
import java.io.*;
|
||||||
|
import javax.media.jai.*;
|
||||||
|
import com.sun.media.jai.codec.*;
|
||||||
|
|
||||||
|
public class ImageNormalizer
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static ImageLengthPair normalizeImage(InputStream raw_data, int width, int height, String out_format)
|
||||||
|
throws ImageNormalizerException
|
||||||
|
{
|
||||||
|
PlanarImage img1;
|
||||||
|
try
|
||||||
|
{ // Start by loading the image we're working with.
|
||||||
|
SeekableStream istm = new ForwardSeekableStream(raw_data);
|
||||||
|
RenderedOp rop1 = JAI.create("stream",istm);
|
||||||
|
img1 = rop1.getRendering();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (RuntimeException re)
|
||||||
|
{ // unable to get the rendering here!
|
||||||
|
throw new ImageNormalizerException("Image data not a valid image format",re);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // Compute the scaling factors required to get the image down to the appropriate size, then choose
|
||||||
|
// the smaller of the two to use as the final scaling factor.
|
||||||
|
Float scale_width = null, scale_height = null;
|
||||||
|
if (img1.getWidth()>width)
|
||||||
|
scale_width = new Float((float)width / (float)(img1.getWidth()));
|
||||||
|
if (img1.getHeight()>height)
|
||||||
|
scale_height = new Float((float)height / (float)(img1.getHeight()));
|
||||||
|
Float scale = null;
|
||||||
|
if (scale_width!=null)
|
||||||
|
{ // we can scale by width, how about height?
|
||||||
|
if (scale_height!=null)
|
||||||
|
{ // yes, height too...pick the smaller of the two
|
||||||
|
if (scale_width.floatValue()<scale_height.floatValue())
|
||||||
|
scale = scale_width;
|
||||||
|
else
|
||||||
|
scale = scale_height;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else // no, just width
|
||||||
|
scale = scale_width;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else if (scale_height!=null) // can only scale by height
|
||||||
|
scale = scale_height;
|
||||||
|
|
||||||
|
// If we need to scale the image now, do so.
|
||||||
|
PlanarImage img2;
|
||||||
|
if (scale!=null)
|
||||||
|
{ // scale the image down!
|
||||||
|
ParameterBlock pb1 = new ParameterBlock();
|
||||||
|
pb1.addSource(img1);
|
||||||
|
pb1.add(scale.floatValue());
|
||||||
|
pb1.add(scale.floatValue());
|
||||||
|
pb1.add(0.0F);
|
||||||
|
pb1.add(0.0F);
|
||||||
|
pb1.add(Interpolation.getInstance(Interpolation.INTERP_BILINEAR));
|
||||||
|
img2 = JAI.create("scale",pb1);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else // just use this as the next image
|
||||||
|
img2 = img1;
|
||||||
|
|
||||||
|
// Figure out the offsets required to center the new image within the "frame."
|
||||||
|
int offset_x = (width - img2.getWidth()) / 2;
|
||||||
|
int offset_y = (height - img2.getHeight()) / 2;
|
||||||
|
|
||||||
|
// If we need to translate the image now, do so.
|
||||||
|
PlanarImage img3;
|
||||||
|
if ((offset_x!=0) || (offset_y!=0))
|
||||||
|
{ // set up a translation to move the image to the right location
|
||||||
|
ParameterBlock pb2 = new ParameterBlock();
|
||||||
|
pb2.addSource(img2);
|
||||||
|
pb2.add((float)offset_x);
|
||||||
|
pb2.add((float)offset_y);
|
||||||
|
pb2.add(Interpolation.getInstance(Interpolation.INTERP_NEAREST));
|
||||||
|
img3 = JAI.create("translate",pb2);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else // just take the image as it is
|
||||||
|
img3 = img2;
|
||||||
|
|
||||||
|
// To set up the backdrop, first we need to create an image of the right size but with the same
|
||||||
|
// sample model and color model as our transformed image.
|
||||||
|
TiledImage back1 = new TiledImage(0,0,width,height,0,0,img3.getSampleModel(),img3.getColorModel());
|
||||||
|
|
||||||
|
// Now we need to make that image black. The easiest way to do that is multiply all pixel
|
||||||
|
// values in the image by 0.
|
||||||
|
ParameterBlock pb = new ParameterBlock();
|
||||||
|
pb.addSource(back1);
|
||||||
|
double[] parms = new double[1];
|
||||||
|
parms[0] = 0.0;
|
||||||
|
pb.add(parms);
|
||||||
|
PlanarImage back2 = JAI.create("multiplyconst",pb);
|
||||||
|
|
||||||
|
// Now overlay the scaled/translated image on top of the background to get the final image.
|
||||||
|
PlanarImage final_img = JAI.create("overlay",back2,img3);
|
||||||
|
|
||||||
|
// With our final image in hand, we can now encode it in the desired output format and turn
|
||||||
|
// it into a streamful of data.
|
||||||
|
ByteArrayOutputStream ostm = new ByteArrayOutputStream(4096);
|
||||||
|
JAI.create("encode",final_img,ostm,out_format,null);
|
||||||
|
byte[] odata = ostm.toByteArray();
|
||||||
|
ostm.close();
|
||||||
|
return new ImageLengthPair(odata.length,new ByteArrayInputStream(odata));
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (Exception e)
|
||||||
|
{ // catchall exception
|
||||||
|
throw new ImageNormalizerException("unspecified error in scaling or translation",e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end normalizeImage
|
||||||
|
|
||||||
|
public static ImageLengthPair normalizeImage(InputStream raw_data, Dimension dim, String out_format)
|
||||||
|
throws ImageNormalizerException
|
||||||
|
{
|
||||||
|
return normalizeImage(raw_data,dim.width,dim.height,out_format);
|
||||||
|
|
||||||
|
} // end normalizeImage
|
||||||
|
|
||||||
|
} // end class ImageNormalizer
|
109
src/com/silverwrist/util/image/ImageNormalizerException.java
Normal file
109
src/com/silverwrist/util/image/ImageNormalizerException.java
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util.image;
|
||||||
|
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
|
public class ImageNormalizerException extends Exception
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Throwable inner = null; // internal "root cause" exception
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructors
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public ImageNormalizerException()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
public ImageNormalizerException(String msg)
|
||||||
|
{
|
||||||
|
super(msg);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
public ImageNormalizerException(Throwable t)
|
||||||
|
{
|
||||||
|
super(t.getMessage());
|
||||||
|
inner = t;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
public ImageNormalizerException(String msg, Throwable t)
|
||||||
|
{
|
||||||
|
super(msg);
|
||||||
|
inner = t;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class Throwable
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void printStackTrace()
|
||||||
|
{
|
||||||
|
this.printStackTrace(System.err);
|
||||||
|
|
||||||
|
} // end printStackTrace
|
||||||
|
|
||||||
|
public void printStackTrace(PrintStream s)
|
||||||
|
{
|
||||||
|
super.printStackTrace(s);
|
||||||
|
if (inner!=null)
|
||||||
|
{ // print the inner stack trace
|
||||||
|
s.print("Root cause: ");
|
||||||
|
inner.printStackTrace(s);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
} // end printStackTrace
|
||||||
|
|
||||||
|
public void printStackTrace(PrintWriter s)
|
||||||
|
{
|
||||||
|
super.printStackTrace(s);
|
||||||
|
if (inner!=null)
|
||||||
|
{ // print the inner stack trace
|
||||||
|
s.print("Root cause: ");
|
||||||
|
inner.printStackTrace(s);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
} // end printStackTrace
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Throwable getException()
|
||||||
|
{
|
||||||
|
return inner;
|
||||||
|
|
||||||
|
} // end getException
|
||||||
|
|
||||||
|
} // end class ImageNormalizerException
|
32
src/com/silverwrist/venice/core/BinaryData.java
Normal file
32
src/com/silverwrist/venice/core/BinaryData.java
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.venice.core;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public interface BinaryData
|
||||||
|
{
|
||||||
|
public abstract String getMIMEType();
|
||||||
|
|
||||||
|
public abstract String getFilename();
|
||||||
|
|
||||||
|
public abstract int getLength();
|
||||||
|
|
||||||
|
public abstract InputStream getData() throws DataException;
|
||||||
|
|
||||||
|
} // end interface BinaryData
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package com.silverwrist.venice.core;
|
package com.silverwrist.venice.core;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
|
||||||
|
@ -92,6 +93,8 @@ public interface ContactInfo
|
||||||
|
|
||||||
public abstract void setPhotoURL(String addr);
|
public abstract void setPhotoURL(String addr);
|
||||||
|
|
||||||
|
public abstract void setPhotoData(String prefix, String mimetype, int length, InputStream data);
|
||||||
|
|
||||||
public abstract String getURL();
|
public abstract String getURL();
|
||||||
|
|
||||||
public abstract void setURL(String addr);
|
public abstract void setURL(String addr);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package com.silverwrist.venice.core;
|
package com.silverwrist.venice.core;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
@ -81,4 +82,8 @@ public interface VeniceEngine extends SearchMode
|
||||||
|
|
||||||
public abstract Advertisement selectAd();
|
public abstract Advertisement selectAd();
|
||||||
|
|
||||||
|
public abstract BinaryData loadImage(int id) throws DataException;
|
||||||
|
|
||||||
|
public abstract Dimension getUserPhotoSize();
|
||||||
|
|
||||||
} // end interface VeniceEngine
|
} // end interface VeniceEngine
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package com.silverwrist.venice.core.impl;
|
package com.silverwrist.venice.core.impl;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.apache.log4j.*;
|
import org.apache.log4j.*;
|
||||||
|
@ -25,6 +26,74 @@ import com.silverwrist.venice.db.*;
|
||||||
|
|
||||||
class ContactInfoImpl implements ContactInfo, Stashable
|
class ContactInfoImpl implements ContactInfo, Stashable
|
||||||
{
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* "Hook" classes used to store an image in the image store and modify the image
|
||||||
|
* URL prior to saving contact info
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
abstract class ImageHook
|
||||||
|
{
|
||||||
|
protected String mimetype;
|
||||||
|
protected int length;
|
||||||
|
protected InputStream data;
|
||||||
|
|
||||||
|
protected ImageHook(String mimetype, int length, InputStream data)
|
||||||
|
{
|
||||||
|
this.mimetype = mimetype;
|
||||||
|
this.length = length;
|
||||||
|
this.data = data;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
public abstract String doImage(Connection conn) throws SQLException;
|
||||||
|
|
||||||
|
} // end class ImageHook
|
||||||
|
|
||||||
|
class NewImageHook extends ImageHook
|
||||||
|
{
|
||||||
|
private String prefix;
|
||||||
|
private short type;
|
||||||
|
private int ownerid;
|
||||||
|
|
||||||
|
public NewImageHook(String prefix, short type, int ownerid, String mimetype, int length, InputStream data)
|
||||||
|
{
|
||||||
|
super(mimetype,length,data);
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.type = type;
|
||||||
|
this.ownerid = ownerid;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
public String doImage(Connection conn) throws SQLException
|
||||||
|
{
|
||||||
|
int id = ImageStore.storeNewImage(conn,type,ownerid,mimetype,length,data);
|
||||||
|
return prefix + id;
|
||||||
|
|
||||||
|
} // end doImage
|
||||||
|
|
||||||
|
} // end class NewImageHook
|
||||||
|
|
||||||
|
class ExistingImageHook extends ImageHook
|
||||||
|
{
|
||||||
|
private int imgid;
|
||||||
|
|
||||||
|
public ExistingImageHook(int imgid, String mimetype, int length, InputStream data)
|
||||||
|
{
|
||||||
|
super(mimetype,length,data);
|
||||||
|
this.imgid = imgid;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
public String doImage(Connection conn) throws SQLException
|
||||||
|
{
|
||||||
|
ImageStore.replaceImage(conn,imgid,mimetype,length,data);
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end doImage
|
||||||
|
|
||||||
|
} // end class ExistingImageHook
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Static data members
|
* Static data members
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
|
@ -64,6 +133,7 @@ class ContactInfoImpl implements ContactInfo, Stashable
|
||||||
private int owner_sigid; // SIGID this contact record is in (-1 for none)
|
private int owner_sigid; // SIGID this contact record is in (-1 for none)
|
||||||
private java.util.Date last_update; // date of last update
|
private java.util.Date last_update; // date of last update
|
||||||
private boolean is_modified = false; // have we modified this ContactInfo?
|
private boolean is_modified = false; // have we modified this ContactInfo?
|
||||||
|
private ImageHook image_hook = null; // image hook object
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Constructors
|
* Constructors
|
||||||
|
@ -502,10 +572,32 @@ class ContactInfoImpl implements ContactInfo, Stashable
|
||||||
photo_url = addr.substring(0,255);
|
photo_url = addr.substring(0,255);
|
||||||
else
|
else
|
||||||
photo_url = addr;
|
photo_url = addr;
|
||||||
|
image_hook = null;
|
||||||
is_modified = true;
|
is_modified = true;
|
||||||
|
|
||||||
} // end setPhotoURL
|
} // end setPhotoURL
|
||||||
|
|
||||||
|
public void setPhotoData(String prefix, String mimetype, int length, InputStream data)
|
||||||
|
{
|
||||||
|
if ((photo_url!=null) && (photo_url.startsWith(prefix)))
|
||||||
|
{ // extract the image ID and create an image hook object
|
||||||
|
int img_id = Integer.parseInt(photo_url.substring(prefix.length()));
|
||||||
|
image_hook = new ExistingImageHook(img_id,mimetype,length,data);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else
|
||||||
|
{ // figure out how to create the image hook object
|
||||||
|
if (owner_sigid>=0)
|
||||||
|
image_hook = new NewImageHook(prefix,ImageStore.TYPE_SIG_LOGO,owner_sigid,mimetype,length,data);
|
||||||
|
else
|
||||||
|
image_hook = new NewImageHook(prefix,ImageStore.TYPE_USER_PHOTO,owner_uid,mimetype,length,data);
|
||||||
|
|
||||||
|
} // end else
|
||||||
|
|
||||||
|
is_modified = true;
|
||||||
|
|
||||||
|
} // end setPhotoData
|
||||||
|
|
||||||
public String getURL()
|
public String getURL()
|
||||||
{
|
{
|
||||||
return url;
|
return url;
|
||||||
|
@ -617,6 +709,15 @@ class ContactInfoImpl implements ContactInfo, Stashable
|
||||||
Statement stmt = conn.createStatement();
|
Statement stmt = conn.createStatement();
|
||||||
StringBuffer buf;
|
StringBuffer buf;
|
||||||
|
|
||||||
|
if (image_hook!=null)
|
||||||
|
{ // call the image hook to store an image and get a new photo URL (where applicable)
|
||||||
|
String new_photo_url = image_hook.doImage(conn);
|
||||||
|
if (new_photo_url!=null)
|
||||||
|
photo_url = new_photo_url;
|
||||||
|
image_hook = null;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
if (contactid>=0)
|
if (contactid>=0)
|
||||||
{ // this involves updating an existing record
|
{ // this involves updating an existing record
|
||||||
buf = new StringBuffer("UPDATE contacts SET given_name = ");
|
buf = new StringBuffer("UPDATE contacts SET given_name = ");
|
||||||
|
|
296
src/com/silverwrist/venice/core/impl/ImageStore.java
Normal file
296
src/com/silverwrist/venice/core/impl/ImageStore.java
Normal file
|
@ -0,0 +1,296 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.venice.core.impl;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.*;
|
||||||
|
import org.apache.log4j.*;
|
||||||
|
import com.silverwrist.venice.db.*;
|
||||||
|
import com.silverwrist.venice.core.*;
|
||||||
|
|
||||||
|
class ImageStore implements BinaryData
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static final short TYPE_USER_PHOTO = 1;
|
||||||
|
public static final short TYPE_SIG_LOGO = 2;
|
||||||
|
|
||||||
|
private static Category logger = Category.getInstance(ImageStore.class);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private DataPool datapool;
|
||||||
|
private int imgid;
|
||||||
|
private String type;
|
||||||
|
private int length;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected ImageStore(DataPool datapool, int imgid, String type, int length)
|
||||||
|
{
|
||||||
|
this.datapool = datapool;
|
||||||
|
this.imgid = imgid;
|
||||||
|
this.type = type;
|
||||||
|
this.length = length;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface BinaryData
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getMIMEType()
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
|
||||||
|
} // end getMIMEType
|
||||||
|
|
||||||
|
public String getFilename()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end getFilename
|
||||||
|
|
||||||
|
public int getLength()
|
||||||
|
{
|
||||||
|
return length;
|
||||||
|
|
||||||
|
} // end getLength
|
||||||
|
|
||||||
|
public InputStream getData() throws DataException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
InputStream rc = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // open up a database connection
|
||||||
|
conn = datapool.getConnection();
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
|
||||||
|
// Create the SQL we need to retrieve the image.
|
||||||
|
StringBuffer sql = new StringBuffer("SELECT data FROM imagestore WHERE imgid = ");
|
||||||
|
sql.append(imgid).append(';');
|
||||||
|
|
||||||
|
// Execute the query!
|
||||||
|
ResultSet rs = stmt.executeQuery(sql.toString());
|
||||||
|
if (!(rs.next()))
|
||||||
|
{ // there is no attachment data!
|
||||||
|
logger.error("no image data to get");
|
||||||
|
throw new DataException("There is no image data present.");
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
// Since the InputStream we get from JDBC will probably go away when the connection is dropped, we
|
||||||
|
// need to make a temporary copy of it, to a ByteArrayOutputStream.
|
||||||
|
InputStream sqldata = rs.getBinaryStream(1);
|
||||||
|
ByteArrayOutputStream copy = new ByteArrayOutputStream(length);
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int rd = sqldata.read(buffer);
|
||||||
|
while (rd>=0)
|
||||||
|
{ // write, then read again
|
||||||
|
if (rd>0)
|
||||||
|
copy.write(buffer,0,rd);
|
||||||
|
rd = sqldata.read(buffer);
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
// Close both our streams, making sure we create the stream we need for the return value.
|
||||||
|
sqldata.close();
|
||||||
|
rc = new ByteArrayInputStream(copy.toByteArray());
|
||||||
|
copy.close();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // turn this into a DataException
|
||||||
|
logger.error("DB error retrieving image: " + e.getMessage(),e);
|
||||||
|
throw new DataException("unable to retrieve image data: " + e.getMessage(),e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (IOException e)
|
||||||
|
{ // turn this into a DataException too
|
||||||
|
logger.error("I/O error copying image data: " + e.getMessage(),e);
|
||||||
|
throw new DataException("unable to retrieve image data: " + e.getMessage(),e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // make sure we release the connection before we go
|
||||||
|
if (conn!=null)
|
||||||
|
datapool.releaseConnection(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end getData
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static ImageStore loadImageByID(DataPool datapool, int id) throws DataException
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("loadImageByID # " + id);
|
||||||
|
|
||||||
|
Connection conn = null; // pooled database connection
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // get a database connection
|
||||||
|
conn = datapool.getConnection();
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
|
||||||
|
StringBuffer sql = new StringBuffer("SELECT mimetype, length FROM imagestore WHERE imgid = ");
|
||||||
|
sql.append(id).append(';');
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("SQL: " + sql.toString());
|
||||||
|
ResultSet rs = stmt.executeQuery(sql.toString());
|
||||||
|
|
||||||
|
if (rs.next()) // create an object reference and return it
|
||||||
|
return new ImageStore(datapool,id,rs.getString(1),rs.getInt(2));
|
||||||
|
|
||||||
|
return null; // no such image
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // turn SQLException into data exception
|
||||||
|
logger.error("DB error reading image entry: " + e.getMessage(),e);
|
||||||
|
throw new DataException("unable to retrieve image entry: " + e.getMessage(),e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // make sure we release the connection before we go
|
||||||
|
if (conn!=null)
|
||||||
|
datapool.releaseConnection(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end loadImageByID
|
||||||
|
|
||||||
|
static int storeNewImage(Connection conn, short type, int owner, String mime, int length, InputStream data)
|
||||||
|
throws SQLException
|
||||||
|
{
|
||||||
|
// Create the SQL statement that inserts the image into the store.
|
||||||
|
StringBuffer sql =
|
||||||
|
new StringBuffer("INSERT INTO imagestore (typecode, ownerid, mimetype, length, data) VALUES (");
|
||||||
|
sql.append(type).append(", ").append(owner).append(", '").append(mime).append("', ").append(length);
|
||||||
|
sql.append(", ?);");
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("SQL: " + sql.toString());
|
||||||
|
|
||||||
|
// Prepare the statement, set the BLOB parameter, and execute it.
|
||||||
|
PreparedStatement stmt = conn.prepareStatement(sql.toString());
|
||||||
|
stmt.setBinaryStream(1,data,length);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
// Get the ID of the new image and return it.
|
||||||
|
Statement stmt2 = conn.createStatement();
|
||||||
|
ResultSet rs = stmt2.executeQuery("SELECT LAST_INSERT_ID();");
|
||||||
|
if (!(rs.next()))
|
||||||
|
throw new InternalStateError("storeNewImage(): Unable to get new image ID!");
|
||||||
|
return rs.getInt(1);
|
||||||
|
|
||||||
|
} // end storeNewImage
|
||||||
|
|
||||||
|
static int storeNewImage(DataPool datapool, short type, int owner, String mime, int length, InputStream data)
|
||||||
|
throws DataException
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("storeNewImage: type " + type + ", owner " + owner + ", mime " + mime + ", len " + length);
|
||||||
|
|
||||||
|
Connection conn = null; // pooled database connection
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // get a database connection
|
||||||
|
conn = datapool.getConnection();
|
||||||
|
return storeNewImage(conn,type,owner,mime,length,data);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // turn SQLException into data exception
|
||||||
|
logger.error("DB error storing image entry: " + e.getMessage(),e);
|
||||||
|
throw new DataException("unable to store image entry: " + e.getMessage(),e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // make sure we release the connection before we go
|
||||||
|
if (conn!=null)
|
||||||
|
datapool.releaseConnection(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end storeNewImage
|
||||||
|
|
||||||
|
static void replaceImage(Connection conn, int imgid, String mime, int length, InputStream data)
|
||||||
|
throws SQLException
|
||||||
|
{
|
||||||
|
// Create the SQL statement that inserts the image into the store.
|
||||||
|
StringBuffer sql = new StringBuffer("UPDATE imagestore SET mimetype = '");
|
||||||
|
sql.append(mime).append("', length = ").append(length).append(", data = ? WHERE imgid = ").append(imgid);
|
||||||
|
sql.append(';');
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("SQL: " + sql.toString());
|
||||||
|
|
||||||
|
// Prepare the statement, set the BLOB parameter, and execute it.
|
||||||
|
PreparedStatement stmt = conn.prepareStatement(sql.toString());
|
||||||
|
stmt.setBinaryStream(1,data,length);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} // end replaceImage
|
||||||
|
|
||||||
|
static void replaceImage(DataPool datapool, int imgid, String mime, int length, InputStream data)
|
||||||
|
throws DataException
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("replaceImage: imgid " + imgid + ", mime " + mime + ", len " + length);
|
||||||
|
|
||||||
|
Connection conn = null; // pooled database connection
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // get a database connection
|
||||||
|
conn = datapool.getConnection();
|
||||||
|
replaceImage(conn,imgid,mime,length,data);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // turn SQLException into data exception
|
||||||
|
logger.error("DB error storing image entry: " + e.getMessage(),e);
|
||||||
|
throw new DataException("unable to store image entry: " + e.getMessage(),e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // make sure we release the connection before we go
|
||||||
|
if (conn!=null)
|
||||||
|
datapool.releaseConnection(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end replaceImage
|
||||||
|
|
||||||
|
} // end class ImageStore
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package com.silverwrist.venice.core.impl;
|
package com.silverwrist.venice.core.impl;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.apache.log4j.*;
|
import org.apache.log4j.*;
|
||||||
|
@ -388,6 +389,8 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./";
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./";
|
||||||
private static final int AUTH_STRING_LEN = 32;
|
private static final int AUTH_STRING_LEN = 32;
|
||||||
|
|
||||||
|
private static final Dimension DEFAULT_DIM_USERPHOTO = new Dimension(100,100);
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Attributes
|
* Attributes
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
|
@ -1580,6 +1583,18 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
|
|
||||||
} // end selectAd
|
} // end selectAd
|
||||||
|
|
||||||
|
public BinaryData loadImage(int id) throws DataException
|
||||||
|
{
|
||||||
|
return ImageStore.loadImageByID(datapool,id);
|
||||||
|
|
||||||
|
} // end loadImage
|
||||||
|
|
||||||
|
public Dimension getUserPhotoSize()
|
||||||
|
{
|
||||||
|
return DEFAULT_DIM_USERPHOTO;
|
||||||
|
|
||||||
|
} // end getUserPhotoSize
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Implementations from interface EngineBackend
|
* Implementations from interface EngineBackend
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
|
|
98
src/com/silverwrist/venice/servlets/ImageRetrieve.java
Normal file
98
src/com/silverwrist/venice/servlets/ImageRetrieve.java
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.venice.servlets;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
import javax.servlet.*;
|
||||||
|
import javax.servlet.http.*;
|
||||||
|
import org.apache.log4j.*;
|
||||||
|
import com.silverwrist.venice.core.*;
|
||||||
|
import com.silverwrist.venice.servlets.format.*;
|
||||||
|
|
||||||
|
public class ImageRetrieve extends VeniceServlet
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static Category logger = Category.getInstance(ImageRetrieve.class);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class HttpServlet
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getServletInfo()
|
||||||
|
{
|
||||||
|
String rc = "ImageRetrieve servlet - Displays images from the database image store\n"
|
||||||
|
+ "Part of the Venice Web Communities System\n";
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end getServletInfo
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class VeniceServlet
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected VeniceContent doVeniceGet(HttpServletRequest request, VeniceEngine engine,
|
||||||
|
UserContext user, RenderData rdat)
|
||||||
|
throws ServletException, IOException, VeniceServletResult
|
||||||
|
{
|
||||||
|
int imgid; // image ID to retrieve.
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // parse the image ID
|
||||||
|
imgid = Integer.parseInt(request.getPathInfo().substring(1));
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{ // invalid image URL
|
||||||
|
return new ErrorBox(null,"Invalid image URL.",null);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
// the parameters of the response
|
||||||
|
String type, filename;
|
||||||
|
int length;
|
||||||
|
InputStream data;
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // load the image from the database
|
||||||
|
BinaryData image = engine.loadImage(imgid);
|
||||||
|
|
||||||
|
type = image.getMIMEType();
|
||||||
|
filename = image.getFilename();
|
||||||
|
length = image.getLength();
|
||||||
|
data = image.getData();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (DataException de)
|
||||||
|
{ // unable to get the user name
|
||||||
|
return new ErrorBox("Database Error","Database error retrieving image: " + de.getMessage(),null);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
// now we want to send that data back to the user!
|
||||||
|
throw new SendFileResult(type,filename,length,data);
|
||||||
|
|
||||||
|
} // end doVeniceGet
|
||||||
|
|
||||||
|
} // end class ImageRetrieve
|
|
@ -62,7 +62,7 @@ public class UserDisplay extends VeniceServlet
|
||||||
UserProfile prof = user.getProfile(uname);
|
UserProfile prof = user.getProfile(uname);
|
||||||
changeMenuTop(request);
|
changeMenuTop(request);
|
||||||
setMyLocation(request,"user" + request.getPathInfo());
|
setMyLocation(request,"user" + request.getPathInfo());
|
||||||
return new UserProfileData(prof);
|
return new UserProfileData(engine,prof);
|
||||||
|
|
||||||
} // end try
|
} // end try
|
||||||
catch (DataException de)
|
catch (DataException de)
|
||||||
|
@ -134,7 +134,7 @@ public class UserDisplay extends VeniceServlet
|
||||||
logger.debug("redisplaying profile window");
|
logger.debug("redisplaying profile window");
|
||||||
changeMenuTop(request);
|
changeMenuTop(request);
|
||||||
setMyLocation(request,"user" + request.getPathInfo());
|
setMyLocation(request,"user" + request.getPathInfo());
|
||||||
return new UserProfileData(prof);
|
return new UserProfileData(engine,prof);
|
||||||
|
|
||||||
} // end doVenicePost
|
} // end doVenicePost
|
||||||
|
|
||||||
|
|
173
src/com/silverwrist/venice/servlets/UserPhoto.java
Normal file
173
src/com/silverwrist/venice/servlets/UserPhoto.java
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.venice.servlets;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.*;
|
||||||
|
import javax.servlet.*;
|
||||||
|
import javax.servlet.http.*;
|
||||||
|
import org.apache.log4j.*;
|
||||||
|
import com.silverwrist.util.StringUtil;
|
||||||
|
import com.silverwrist.util.ServletMultipartHandler;
|
||||||
|
import com.silverwrist.util.ServletMultipartException;
|
||||||
|
import com.silverwrist.util.image.*;
|
||||||
|
import com.silverwrist.venice.core.*;
|
||||||
|
import com.silverwrist.venice.servlets.format.*;
|
||||||
|
|
||||||
|
public class UserPhoto extends VeniceServlet
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static Category logger = Category.getInstance(UserPhoto.class);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class HttpServlet
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getServletInfo()
|
||||||
|
{
|
||||||
|
String rc = "UserPhoto servlet - changes the user photo for a user\n"
|
||||||
|
+ "Part of the Venice Web Communities System\n";
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end getServletInfo
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class VeniceServlet
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected VeniceContent doVeniceGet(HttpServletRequest request, VeniceEngine engine,
|
||||||
|
UserContext user, RenderData rdat)
|
||||||
|
throws ServletException, IOException, VeniceServletResult
|
||||||
|
{
|
||||||
|
String tgt = request.getParameter("tgt"); // target location
|
||||||
|
if (tgt==null)
|
||||||
|
tgt = "top"; // go back to the Top screen if nothing else
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // create the display
|
||||||
|
return new UserPhotoData(engine,user,rdat,tgt);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (DataException de)
|
||||||
|
{ // error getting at the data stream from the attachment
|
||||||
|
return new ErrorBox("Database Error","Database error generating display: " + de.getMessage(),null);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end doVeniceGet
|
||||||
|
|
||||||
|
protected VeniceContent doVenicePost(HttpServletRequest request, ServletMultipartHandler mphandler,
|
||||||
|
VeniceEngine engine, UserContext user, RenderData rdat)
|
||||||
|
throws ServletException, IOException, VeniceServletResult
|
||||||
|
{
|
||||||
|
// Get target URL for the operation
|
||||||
|
if (mphandler.isFileParam("tgt"))
|
||||||
|
{ // bogus target URL
|
||||||
|
logger.error("Internal Error: 'tgt' should be a normal param");
|
||||||
|
return new ErrorBox(null,"Internal Error: 'tgt' should be a normal param","top");
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
String tgt = mphandler.getValue("tgt");
|
||||||
|
if (tgt==null)
|
||||||
|
tgt = "top"; // go back to the Top screen if nothing else
|
||||||
|
|
||||||
|
if (isImageButtonClicked(mphandler,"cancel"))
|
||||||
|
throw new RedirectResult("account?cmd=P&tgt=" + URLEncoder.encode(tgt));
|
||||||
|
|
||||||
|
if (isImageButtonClicked(mphandler,"upload"))
|
||||||
|
{ // uploading the image here!
|
||||||
|
// also check on file parameter status
|
||||||
|
if (!(mphandler.isFileParam("thepic")))
|
||||||
|
{ // bogus file parameter
|
||||||
|
logger.error("Internal Error: 'thepic' should be a file param");
|
||||||
|
return new ErrorBox(null,"Internal Error: 'thepic' should be a file param",
|
||||||
|
"account?cmd=P&tgt=" + URLEncoder.encode(tgt));
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
if (!(mphandler.getContentType("thepic").startsWith("image/")))
|
||||||
|
{ // must be an image type we uploaded!
|
||||||
|
logger.error("Error: 'thepic' not an image type");
|
||||||
|
return new ErrorBox(null,"You did not upload an image file. Try again.",
|
||||||
|
"userphoto?tgt=" + URLEncoder.encode(tgt));
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // get the real picture (normalized to 100x100 size)
|
||||||
|
ImageLengthPair real_pic = ImageNormalizer.normalizeImage(mphandler.getFileContentStream("thepic"),
|
||||||
|
engine.getUserPhotoSize(),"jpeg");
|
||||||
|
|
||||||
|
// set the user photo data!
|
||||||
|
ContactInfo ci = user.getContactInfo();
|
||||||
|
ci.setPhotoData(request.getContextPath() + "/imagedata/","image/jpeg",real_pic.getLength(),
|
||||||
|
real_pic.getData());
|
||||||
|
user.putContactInfo(ci);
|
||||||
|
|
||||||
|
// Jump back to the profile form.
|
||||||
|
throw new RedirectResult("account?cmd=P&tgt=" + URLEncoder.encode(tgt));
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (ServletMultipartException smpe)
|
||||||
|
{ // the servlet multipart parser screwed up
|
||||||
|
logger.error("Servlet multipart error:",smpe);
|
||||||
|
return new ErrorBox(null,"Internal Error: " + smpe.getMessage(),
|
||||||
|
"account?cmd=P&tgt=" + URLEncoder.encode(tgt));
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (ImageNormalizerException ine)
|
||||||
|
{ // the image was not valid
|
||||||
|
logger.error("Image normalizer error:",ine);
|
||||||
|
return new ErrorBox(null,ine.getMessage(),"userphoto?tgt=" + URLEncoder.encode(tgt));
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (DataException de)
|
||||||
|
{ // error in the database!
|
||||||
|
logger.error("DataException:",de);
|
||||||
|
return new ErrorBox("Database Error","Database error storing user photo: " + de.getMessage(),
|
||||||
|
"account?cmd=P&tgt=" + URLEncoder.encode(tgt));
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (EmailException ee)
|
||||||
|
{ // email exception (WTF?)
|
||||||
|
logger.error("Email exception (shouldn't happen):",ee);
|
||||||
|
return new ErrorBox(null,"Internal Error: " + ee.getMessage(),
|
||||||
|
"account?cmd=P&tgt=" + URLEncoder.encode(tgt));
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else
|
||||||
|
{ // the button must be wrong!
|
||||||
|
logger.error("no known button click on UserPhoto.doPost");
|
||||||
|
return new ErrorBox("Internal Error","Unknown command button pressed",
|
||||||
|
"account?cmd=P&tgt=" + URLEncoder.encode(tgt));
|
||||||
|
|
||||||
|
} // end else
|
||||||
|
|
||||||
|
} // end doVenicePost
|
||||||
|
|
||||||
|
} // end class UserPhoto
|
|
@ -292,6 +292,13 @@ public abstract class VeniceServlet extends HttpServlet
|
||||||
|
|
||||||
} // end isImageButtonClicked
|
} // end isImageButtonClicked
|
||||||
|
|
||||||
|
protected static final boolean isImageButtonClicked(ServletMultipartHandler mphandler, String name)
|
||||||
|
{
|
||||||
|
String val = mphandler.getValue(name + ".x");
|
||||||
|
return (val!=null);
|
||||||
|
|
||||||
|
} // end isImageButtonClicked
|
||||||
|
|
||||||
protected final void putUserContext(HttpServletRequest request, UserContext ctxt)
|
protected final void putUserContext(HttpServletRequest request, UserContext ctxt)
|
||||||
{
|
{
|
||||||
Variables.putUserContext(request.getSession(true),ctxt);
|
Variables.putUserContext(request.getSession(true),ctxt);
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
*/
|
*/
|
||||||
package com.silverwrist.venice.servlets.format;
|
package com.silverwrist.venice.servlets.format;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.silverwrist.util.LocaleFactory;
|
import com.silverwrist.util.LocaleFactory;
|
||||||
import com.silverwrist.util.StringUtil;
|
import com.silverwrist.util.StringUtil;
|
||||||
|
@ -25,6 +27,66 @@ import com.silverwrist.venice.core.*;
|
||||||
|
|
||||||
public class EditProfileDialog extends ContentDialog
|
public class EditProfileDialog extends ContentDialog
|
||||||
{
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* The photo URL control class.
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static class CDUserPhotoControl extends CDBaseFormField
|
||||||
|
{
|
||||||
|
private String linkURL;
|
||||||
|
|
||||||
|
public CDUserPhotoControl(String name, String caption, String linkURL)
|
||||||
|
{
|
||||||
|
super(name,caption,"(click to change)",false);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
protected CDUserPhotoControl(CDUserPhotoControl other)
|
||||||
|
{
|
||||||
|
super(other);
|
||||||
|
this.linkURL = other.linkURL;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
protected void renderActualField(Writer out, RenderData rdat) throws IOException
|
||||||
|
{
|
||||||
|
if (isEnabled())
|
||||||
|
out.write("<A HREF=\"" + rdat.getEncodedServletPath(linkURL) + "\">");
|
||||||
|
String photo = getValue();
|
||||||
|
if (StringUtil.isStringEmpty(photo))
|
||||||
|
photo = rdat.getFullImagePath("photo_not_avail.gif");
|
||||||
|
out.write("<IMG SRC=\"" + photo + "\" ALT=\"\" BORDER=0 WIDTH=100 HEIGHT=100></A>");
|
||||||
|
if (isEnabled())
|
||||||
|
out.write("</A>");
|
||||||
|
|
||||||
|
} // end renderActualField
|
||||||
|
|
||||||
|
protected void validateContents(String value) throws ValidationException
|
||||||
|
{ // this is a do-nothing value
|
||||||
|
} // end validateContents
|
||||||
|
|
||||||
|
public CDFormField duplicate()
|
||||||
|
{
|
||||||
|
return new CDUserPhotoControl(this);
|
||||||
|
|
||||||
|
} // end clone
|
||||||
|
|
||||||
|
public void setLinkURL(String s)
|
||||||
|
{
|
||||||
|
linkURL = s;
|
||||||
|
|
||||||
|
} // end setLinkURL
|
||||||
|
|
||||||
|
} // end class CDUserPhotoControl
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private CDUserPhotoControl photo_control;
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Constructors
|
* Constructors
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
|
@ -67,7 +129,8 @@ public class EditProfileDialog extends ContentDialog
|
||||||
addFormField(new CDTextFormField("url","Home page","(URL)",false,32,255));
|
addFormField(new CDTextFormField("url","Home page","(URL)",false,32,255));
|
||||||
addFormField(new CDFormCategoryHeader("Personal"));
|
addFormField(new CDFormCategoryHeader("Personal"));
|
||||||
addFormField(new CDTextFormField("descr","Personal description",null,false,32,255));
|
addFormField(new CDTextFormField("descr","Personal description",null,false,32,255));
|
||||||
// TODO: add photo selection/uploading method here
|
photo_control = new CDUserPhotoControl("photo","User Photo","userphoto");
|
||||||
|
addFormField(photo_control);
|
||||||
addFormField(new CDFormCategoryHeader("User Preferences"));
|
addFormField(new CDFormCategoryHeader("User Preferences"));
|
||||||
addFormField(new CDLocaleListFormField("locale","Default locale","(for formatting dates/times)",true));
|
addFormField(new CDLocaleListFormField("locale","Default locale","(for formatting dates/times)",true));
|
||||||
addFormField(new CDTimeZoneListFormField("tz","Default time zone",null,true));
|
addFormField(new CDTimeZoneListFormField("tz","Default time zone",null,true));
|
||||||
|
@ -79,6 +142,7 @@ public class EditProfileDialog extends ContentDialog
|
||||||
protected EditProfileDialog(EditProfileDialog other)
|
protected EditProfileDialog(EditProfileDialog other)
|
||||||
{
|
{
|
||||||
super(other);
|
super(other);
|
||||||
|
photo_control = (CDUserPhotoControl)modifyField("photo");
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
|
@ -162,6 +226,8 @@ public class EditProfileDialog extends ContentDialog
|
||||||
setFieldValue("pvt_email","Y");
|
setFieldValue("pvt_email","Y");
|
||||||
setFieldValue("url",ci.getURL());
|
setFieldValue("url",ci.getURL());
|
||||||
setFieldValue("descr",uc.getDescription());
|
setFieldValue("descr",uc.getDescription());
|
||||||
|
setFieldValue("photo",ci.getPhotoURL());
|
||||||
|
photo_control.setLinkURL("userphoto?tgt=" + URLEncoder.encode(target));
|
||||||
setFieldValue("locale",uc.getLocale().toString());
|
setFieldValue("locale",uc.getLocale().toString());
|
||||||
setFieldValue("tz",uc.getTimeZone().getID());
|
setFieldValue("tz",uc.getTimeZone().getID());
|
||||||
|
|
||||||
|
|
126
src/com/silverwrist/venice/servlets/format/UserPhotoData.java
Normal file
126
src/com/silverwrist/venice/servlets/format/UserPhotoData.java
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.venice.servlets.format;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import javax.servlet.*;
|
||||||
|
import javax.servlet.http.*;
|
||||||
|
import com.silverwrist.util.StringUtil;
|
||||||
|
import com.silverwrist.venice.core.*;
|
||||||
|
|
||||||
|
public class UserPhotoData implements JSPRender
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Attribute name for request attribute
|
||||||
|
protected static final String ATTR_NAME = "com.silverwrist.venice.content.UserPhotoData";
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Dimension photo_dims;
|
||||||
|
private String photo_url;
|
||||||
|
private String target;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public UserPhotoData(VeniceEngine engine, UserContext user, RenderData rdat, String target)
|
||||||
|
throws DataException
|
||||||
|
{
|
||||||
|
photo_dims = engine.getUserPhotoSize();
|
||||||
|
photo_url = user.getContactInfo().getPhotoURL();
|
||||||
|
if (StringUtil.isStringEmpty(photo_url))
|
||||||
|
photo_url = rdat.getFullImagePath("photo_not_avail.gif");
|
||||||
|
this.target = target;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External static functions
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static UserPhotoData retrieve(ServletRequest request)
|
||||||
|
{
|
||||||
|
return (UserPhotoData)(request.getAttribute(ATTR_NAME));
|
||||||
|
|
||||||
|
} // end retrieve
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface VeniceContent
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getPageTitle(RenderData rdat)
|
||||||
|
{
|
||||||
|
return "Set User Photo";
|
||||||
|
|
||||||
|
} // end getPageTitle
|
||||||
|
|
||||||
|
public String getPageQID()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end getPageQID
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface JSPRender
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void store(ServletRequest request)
|
||||||
|
{
|
||||||
|
request.setAttribute(ATTR_NAME,this);
|
||||||
|
|
||||||
|
} // end store
|
||||||
|
|
||||||
|
public String getTargetJSPName()
|
||||||
|
{
|
||||||
|
return "user_photo.jsp";
|
||||||
|
|
||||||
|
} // end getTargetJSPName
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getTarget()
|
||||||
|
{
|
||||||
|
return target;
|
||||||
|
|
||||||
|
} // end getTarget
|
||||||
|
|
||||||
|
public String getPhotoTag(RenderData rdat)
|
||||||
|
{
|
||||||
|
StringBuffer buf = new StringBuffer("<IMG SRC=\"");
|
||||||
|
buf.append(photo_url).append("\" ALT=\"\" ALIGN=LEFT WIDTH=").append(photo_dims.width).append(" HEIGHT=");
|
||||||
|
buf.append(photo_dims.height).append(" HSPACE=6 VSPACE=0 BORDER=0>");
|
||||||
|
return buf.toString();
|
||||||
|
|
||||||
|
} // end getPhotoTag
|
||||||
|
|
||||||
|
} // end class UserPhotoData
|
|
@ -17,8 +17,10 @@
|
||||||
*/
|
*/
|
||||||
package com.silverwrist.venice.servlets.format;
|
package com.silverwrist.venice.servlets.format;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
import com.silverwrist.util.StringUtil;
|
import com.silverwrist.util.StringUtil;
|
||||||
|
import com.silverwrist.venice.core.VeniceEngine;
|
||||||
import com.silverwrist.venice.core.UserProfile;
|
import com.silverwrist.venice.core.UserProfile;
|
||||||
|
|
||||||
public class UserProfileData implements JSPRender
|
public class UserProfileData implements JSPRender
|
||||||
|
@ -36,6 +38,7 @@ public class UserProfileData implements JSPRender
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
private VeniceEngine engine;
|
||||||
private UserProfile prof;
|
private UserProfile prof;
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
|
@ -43,8 +46,9 @@ public class UserProfileData implements JSPRender
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public UserProfileData(UserProfile prof)
|
public UserProfileData(VeniceEngine engine, UserProfile prof)
|
||||||
{
|
{
|
||||||
|
this.engine = engine;
|
||||||
this.prof = prof;
|
this.prof = prof;
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
@ -143,13 +147,17 @@ public class UserProfileData implements JSPRender
|
||||||
|
|
||||||
} // end getFullName
|
} // end getFullName
|
||||||
|
|
||||||
public String getPhotoURL(RenderData rdat)
|
public String getPhotoTag(RenderData rdat)
|
||||||
{
|
{
|
||||||
|
Dimension dim = engine.getUserPhotoSize();
|
||||||
|
StringBuffer buf = new StringBuffer("<IMG SRC=\"");
|
||||||
String tmp = prof.getPhotoURL();
|
String tmp = prof.getPhotoURL();
|
||||||
if (StringUtil.isStringEmpty(tmp))
|
if (StringUtil.isStringEmpty(tmp))
|
||||||
tmp = rdat.getFullImagePath("photo_not_avail.gif");
|
tmp = rdat.getFullImagePath("photo_not_avail.gif");
|
||||||
return tmp;
|
buf.append(tmp).append("\" ALT=\"\" ALIGN=LEFT WIDTH=").append(dim.width).append(" HEIGHT=");
|
||||||
|
buf.append(dim.height).append(" BORDER=0>");
|
||||||
|
return buf.toString();
|
||||||
|
|
||||||
} // end getPhotoURL
|
} // end getPhotoTag
|
||||||
|
|
||||||
} // end class UserProfileData
|
} // end class UserProfileData
|
||||||
|
|
42
web/format/user_photo.jsp
Normal file
42
web/format/user_photo.jsp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<%--
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
--%>
|
||||||
|
<%@ page import = "java.util.*" %>
|
||||||
|
<%@ page import = "com.silverwrist.util.StringUtil" %>
|
||||||
|
<%@ page import = "com.silverwrist.venice.core.*" %>
|
||||||
|
<%@ page import = "com.silverwrist.venice.servlets.Variables" %>
|
||||||
|
<%@ page import = "com.silverwrist.venice.servlets.format.*" %>
|
||||||
|
<%
|
||||||
|
UserPhotoData data = UserPhotoData.retrieve(request);
|
||||||
|
Variables.failIfNull(data);
|
||||||
|
RenderData rdat = RenderConfig.createRenderData(application,request,response);
|
||||||
|
%>
|
||||||
|
<% rdat.writeContentHeader(out,"Change User Photo",null); %>
|
||||||
|
<%= rdat.getStdFontTag(ColorSelectors.CONTENT_FOREGROUND,2) %>
|
||||||
|
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="<%= rdat.getEncodedServletPath("userphoto") %>">
|
||||||
|
<INPUT TYPE=HIDDEN NAME="tgt" VALUE="<%= data.getTarget() %>">
|
||||||
|
<%= data.getPhotoTag(rdat) %>
|
||||||
|
New user photo:<BR>
|
||||||
|
<INPUT TYPE="FILE" NAME="thepic"><P>
|
||||||
|
<INPUT TYPE=IMAGE SRC="<%= rdat.getFullImagePath("bn_upload.gif") %>" NAME="upload" ALT="Upload"
|
||||||
|
WIDTH=80 HEIGHT=24 BORDER=0>
|
||||||
|
<INPUT TYPE=IMAGE SRC="<%= rdat.getFullImagePath("bn_cancel.gif") %>" NAME="cancel" ALT="Cancel"
|
||||||
|
WIDTH=80 HEIGHT=24 BORDER=0><BR CLEAR=LEFT>
|
||||||
|
</FORM>
|
||||||
|
</FONT>
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,7 @@
|
||||||
<TABLE BORDER=0 CELLPADDING=6 CELLSPACING=0>
|
<TABLE BORDER=0 CELLPADDING=6 CELLSPACING=0>
|
||||||
<TR VALIGN=TOP>
|
<TR VALIGN=TOP>
|
||||||
<TD ALIGN=LEFT><%= rdat.getStdFontTag(ColorSelectors.CONTENT_FOREGROUND,1) %>
|
<TD ALIGN=LEFT><%= rdat.getStdFontTag(ColorSelectors.CONTENT_FOREGROUND,1) %>
|
||||||
<IMG SRC="<%= data.getPhotoURL(rdat) %>" ALT="" ALIGN=LEFT WIDTH=100
|
<%= data.getPhotoTag(rdat) %><BR CLEAR=LEFT><BR>
|
||||||
HEIGHT=100 BORDER=0><BR CLEAR=LEFT><BR>
|
|
||||||
|
|
||||||
<% Date tmpd = prof.getCreateDate(); %>
|
<% Date tmpd = prof.getCreateDate(); %>
|
||||||
<% if (tmpd!=null) { %>
|
<% if (tmpd!=null) { %>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user