reuse (overwrite) existing custom profile file in editing session (id passed in URL)

This commit is contained in:
Norbert Renner 2014-05-22 17:55:17 +02:00
parent 8327fd4e24
commit 5651260691
2 changed files with 20 additions and 4 deletions

View file

@ -26,6 +26,8 @@ import btools.server.request.ServerHandler;
public class RouteServer extends Thread
{
public static final String PROFILE_UPLOAD_URL = "/brouter/profile";
public ServiceContext serviceContext;
private Socket clientSocket = null;
@ -66,12 +68,19 @@ public class RouteServer extends Thread
{
handler = new ServerHandler( serviceContext, params );
}
else if ("/brouter/profile".equals(url))
else if ( url.startsWith( PROFILE_UPLOAD_URL ) )
{
writeHttpHeader(bw);
String profileId = null;
if ( url.length() > PROFILE_UPLOAD_URL.length() + 1 )
{
// e.g. /brouter/profile/custom_1400767688382
profileId = url.substring(PROFILE_UPLOAD_URL.length() + 1);
}
ProfileUploadHandler uploadHandler = new ProfileUploadHandler( serviceContext );
uploadHandler.handlePostRequest(br, bw);
uploadHandler.handlePostRequest( profileId, br, bw );
bw.flush();
return;

View file

@ -26,13 +26,20 @@ public class ProfileUploadHandler
this.serviceContext = serviceContext;
}
public void handlePostRequest(BufferedReader br, BufferedWriter response) throws IOException
public void handlePostRequest(String profileId, BufferedReader br, BufferedWriter response) throws IOException
{
BufferedWriter fileWriter = null;
try
{
String id = "" + System.currentTimeMillis();
String id;
if ( profileId != null )
{
// update existing file when id appended
id = profileId.substring( ProfileUploadHandler.CUSTOM_PREFIX.length() );
} else {
id = "" + System.currentTimeMillis();
}
File file = new File( getOrCreateCustomProfileDir(), id + ".brf" );
fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream( file ) ) );
//StringWriter sw = new StringWriter(); bw = new BufferedWriter(sw);