From 10698284d26968335be28f573b37094e517d4b5c Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Thu, 26 Apr 2018 12:46:56 -0400 Subject: [PATCH] Format-specific marshalling. --- .../com/lyndir/masterpassword/model/MPFileUserManager.java | 2 +- .../com/lyndir/masterpassword/model/MPFlatMarshaller.java | 2 +- .../com/lyndir/masterpassword/model/MPJSONMarshaller.java | 7 ++++--- .../java/com/lyndir/masterpassword/model/MPMarshaller.java | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPFileUserManager.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPFileUserManager.java index 0f450cd5..aeca0732 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPFileUserManager.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPFileUserManager.java @@ -126,7 +126,7 @@ public class MPFileUserManager extends MPUserManager { throws IOException { return new OutputStreamWriter( new FileOutputStream( getUserFile( user ) ), Charsets.UTF_8 ); } - }.write( new MPFlatMarshaller().marshall( user, masterKey, MPMarshaller.ContentMode.PROTECTED ) ); + }.write( user.getFormat().marshaller().marshall( user, masterKey, MPMarshaller.ContentMode.PROTECTED ) ); } catch (final IOException e) { logger.err( e, "Unable to save sites for user: %s", user ); diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPFlatMarshaller.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPFlatMarshaller.java index 4c4d426d..4ee4800d 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPFlatMarshaller.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPFlatMarshaller.java @@ -36,7 +36,7 @@ public class MPFlatMarshaller implements MPMarshaller { @Nonnull @Override public String marshall(final MPFileUser user, final MPMasterKey masterKey, final ContentMode contentMode) - throws MPInvalidatedException { + throws MPInvalidatedException, MPMarshalException { StringBuilder content = new StringBuilder(); content.append( "# Master Password site export\n" ); content.append( "# " ).append( contentMode.description() ).append( '\n' ); diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPJSONMarshaller.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPJSONMarshaller.java index ce714647..d833ec32 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPJSONMarshaller.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPJSONMarshaller.java @@ -18,6 +18,7 @@ package com.lyndir.masterpassword.model; +import com.lyndir.masterpassword.MPInvalidatedException; import com.lyndir.masterpassword.MPMasterKey; import javax.annotation.Nonnull; @@ -29,8 +30,8 @@ public class MPJSONMarshaller implements MPMarshaller { @Nonnull @Override - public String marshall(final MPFileUser user, final MPMasterKey masterKey, final ContentMode contentMode) { - // TODO - return null; + public String marshall(final MPFileUser user, final MPMasterKey masterKey, final ContentMode contentMode) + throws MPInvalidatedException, MPMarshalException { + throw new MPMarshalException( "Not yet implemented" ); } } diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPMarshaller.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPMarshaller.java index 467c58cd..0c287717 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPMarshaller.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPMarshaller.java @@ -30,7 +30,7 @@ public interface MPMarshaller { @Nonnull String marshall(MPFileUser user, MPMasterKey masterKey, ContentMode contentMode) - throws MPInvalidatedException; + throws MPInvalidatedException, MPMarshalException; enum ContentMode { PROTECTED( "Export of site names and stored passwords (unless device-private) encrypted with the master key." ),