reuse (overwrite) existing custom profile file in editing session (id passed in URL)
This commit is contained in:
parent
8327fd4e24
commit
5651260691
2 changed files with 20 additions and 4 deletions
|
@ -26,6 +26,8 @@ import btools.server.request.ServerHandler;
|
||||||
|
|
||||||
public class RouteServer extends Thread
|
public class RouteServer extends Thread
|
||||||
{
|
{
|
||||||
|
public static final String PROFILE_UPLOAD_URL = "/brouter/profile";
|
||||||
|
|
||||||
public ServiceContext serviceContext;
|
public ServiceContext serviceContext;
|
||||||
|
|
||||||
private Socket clientSocket = null;
|
private Socket clientSocket = null;
|
||||||
|
@ -66,12 +68,19 @@ public class RouteServer extends Thread
|
||||||
{
|
{
|
||||||
handler = new ServerHandler( serviceContext, params );
|
handler = new ServerHandler( serviceContext, params );
|
||||||
}
|
}
|
||||||
else if ("/brouter/profile".equals(url))
|
else if ( url.startsWith( PROFILE_UPLOAD_URL ) )
|
||||||
{
|
{
|
||||||
writeHttpHeader(bw);
|
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 );
|
ProfileUploadHandler uploadHandler = new ProfileUploadHandler( serviceContext );
|
||||||
uploadHandler.handlePostRequest(br, bw);
|
uploadHandler.handlePostRequest( profileId, br, bw );
|
||||||
|
|
||||||
bw.flush();
|
bw.flush();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -26,13 +26,20 @@ public class ProfileUploadHandler
|
||||||
this.serviceContext = serviceContext;
|
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;
|
BufferedWriter fileWriter = null;
|
||||||
|
|
||||||
try
|
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" );
|
File file = new File( getOrCreateCustomProfileDir(), id + ".brf" );
|
||||||
fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream( file ) ) );
|
fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream( file ) ) );
|
||||||
//StringWriter sw = new StringWriter(); bw = new BufferedWriter(sw);
|
//StringWriter sw = new StringWriter(); bw = new BufferedWriter(sw);
|
||||||
|
|
Loading…
Reference in a new issue