Skip to content

Commit

Permalink
Optionally HTML-escaping captions and titles during upload.
Browse files Browse the repository at this point in the history
Fixed a problem with uploading pictures to Gallery when the Gallery's 'debug' flag was set.
Reformatted many source files using IdeaJ
  • Loading branch information
Pierre-Luc Paour committed May 7, 2003
1 parent bc2aa67 commit dbfc3e5
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions com/gallery/GalleryRemote/GalleryComm2.java
Expand Up @@ -21,12 +21,26 @@

package com.gallery.GalleryRemote;

import HTTPClient.*;
import java.util.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import com.gallery.GalleryRemote.model.*;
import java.io.IOException;
import java.io.StringBufferInputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;

import HTTPClient.Codecs;
import HTTPClient.HTTPConnection;
import HTTPClient.HTTPResponse;
import HTTPClient.ModuleException;
import HTTPClient.NVPair;

import com.gallery.GalleryRemote.model.Album;
import com.gallery.GalleryRemote.model.Gallery;
import com.gallery.GalleryRemote.model.Picture;
import com.gallery.GalleryRemote.util.HTMLEscaper;

/**
* The GalleryComm2 class implements the client side of the Gallery remote
Expand Down Expand Up @@ -289,13 +303,18 @@ Properties requestResponse( NVPair form_data[], byte[] data) throws GR2Exception
Log.log(Log.TRACE, MODULE, response);

// validate response
if ( response.startsWith( PROTOCOL_MAGIC ) ) {
Properties p = new Properties();
p.load( new StringBufferInputStream( response ) );
return p;
} else {
int i = response.indexOf(PROTOCOL_MAGIC);

if ( i == -1 ) {
throw new GR2Exception("Server contacted, but Gallery not found at this URL (" + galUrl.toString() + ")");
} else if ( i > 0 ) {
response = response.substring(i);
Log.log(Log.TRACE, MODULE, "Short response: " + response);
}

Properties p = new Properties();
p.load( new StringBufferInputStream( response ) );
return p;
}
}

Expand Down Expand Up @@ -397,7 +416,11 @@ boolean uploadPicture(Picture p) {
// can't set null as an NVPair value
String caption = p.getCaption();
caption = (caption == null) ? "" : caption;


if (GalleryRemote.getInstance().properties.getBooleanProperty("htmlEscapeCaptions")) {
caption = HTMLEscaper.escape(caption);
}

// setup the protocol parameters
NVPair[] opts = {
new NVPair("cmd", "add-item"),
Expand Down Expand Up @@ -607,7 +630,12 @@ void runTask() {
status(su, "Getting album information from " + g.toString());

String parentAlbumName = (parentAlbum == null) ? "" : parentAlbum.getName();


if (GalleryRemote.getInstance().properties.getBooleanProperty("htmlEscapeCaptions")) {
albumTitle = HTMLEscaper.escape(albumTitle);
albumDesc = HTMLEscaper.escape(albumDesc);
}

try {
// setup the protocol parameters
NVPair form_data[] = {
Expand Down

0 comments on commit dbfc3e5

Please sign in to comment.