Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
jorabin committed Aug 25, 2023
1 parent 324da07 commit 1bce2e1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@

package org.linguafranca.pwdb.kdbx.jackson;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import org.linguafranca.pwdb.Credentials;
import org.linguafranca.pwdb.StreamConfiguration;
import org.linguafranca.pwdb.StreamFormat;
Expand All @@ -32,17 +24,22 @@
import org.linguafranca.pwdb.kdbx.KdbxStreamFormat;
import org.linguafranca.pwdb.kdbx.jackson.model.KeePassFile;

import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.databind.DatabindException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import static org.linguafranca.pwdb.kdbx.jackson.JacksonSerializableDatabase.createEmptyDatabase;;
import static org.linguafranca.pwdb.kdbx.jackson.JacksonSerializableDatabase.createEmptyDatabase;

public class JacksonDatabase extends AbstractDatabase<JacksonDatabase, JacksonGroup, JacksonEntry, JacksonIcon> {

KeePassFile keePassFile;
StreamFormat<?> streamFormat;

public JacksonDatabase() throws StreamReadException, DatabindException, IOException {
public JacksonDatabase() throws IOException {
this(createEmptyDatabase(), null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,25 @@

package org.linguafranca.pwdb.kdbx.jackson;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import org.jetbrains.annotations.NotNull;
import org.linguafranca.pwdb.base.AbstractGroup;
import org.linguafranca.pwdb.kdbx.jackson.converter.StringToBooleanConverter;
import org.linguafranca.pwdb.kdbx.jackson.converter.UUIDToBase64Converter;
import org.linguafranca.pwdb.kdbx.jackson.converter.Base64ToUUIDConverter;
import org.linguafranca.pwdb.kdbx.jackson.converter.BooleanToStringConverter;
import org.linguafranca.pwdb.kdbx.jackson.model.Times;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import org.jetbrains.annotations.NotNull;
import org.linguafranca.pwdb.base.AbstractGroup;
import org.linguafranca.pwdb.kdbx.jackson.converter.Base64ToUUIDConverter;
import org.linguafranca.pwdb.kdbx.jackson.converter.BooleanToStringConverter;
import org.linguafranca.pwdb.kdbx.jackson.converter.StringToBooleanConverter;
import org.linguafranca.pwdb.kdbx.jackson.converter.UUIDToBase64Converter;
import org.linguafranca.pwdb.kdbx.jackson.model.Times;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@JsonPropertyOrder({
"uuid",
Expand Down Expand Up @@ -165,11 +163,7 @@ public void setParent(JacksonGroup group) {

@Override
public List<JacksonGroup> getGroups() {
List<JacksonGroup> result = new ArrayList<>();
for (JacksonGroup aGroup : groups) {
result.add(aGroup);
}
return result;
return new ArrayList<>(groups);
}

@Override
Expand Down Expand Up @@ -208,11 +202,7 @@ public JacksonGroup removeGroup(JacksonGroup group) {

@Override
public List<JacksonEntry> getEntries() {
List<JacksonEntry> result = new ArrayList<>();
for (JacksonEntry entry : this.entries) {
result.add(entry);
}
return result;
return new ArrayList<>(this.entries);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@
*/
package org.linguafranca.pwdb.kdbx.jackson;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;

import com.ctc.wstx.api.WstxInputProperties;
import com.ctc.wstx.api.WstxOutputProperties;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
import org.jetbrains.annotations.NotNull;
import org.linguafranca.pwdb.Entry;
import org.linguafranca.pwdb.SerializableDatabase;
Expand All @@ -37,29 +32,27 @@
import org.linguafranca.pwdb.kdbx.jackson.model.KeePassFile;
import org.linguafranca.pwdb.security.StreamEncryptor;

import com.ctc.wstx.api.WstxInputProperties;
import com.ctc.wstx.api.WstxOutputProperties;
import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.databind.DatabindException;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;

import static org.linguafranca.pwdb.Entry.STANDARD_PROPERTY_NAME_TITLE;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class JacksonSerializableDatabase implements SerializableDatabase {

public KeePassFile keePassFile;
private StreamEncryptor encryptor;

public static KeePassFile createEmptyDatabase() throws StreamReadException, DatabindException, IOException {
public static KeePassFile createEmptyDatabase() throws IOException {

InputStream inputStream = JacksonSerializableDatabase.class.getClassLoader()
.getResourceAsStream("base.kdbx.xml");
XmlMapper mapper = new XmlMapper();
KeePassFile res = mapper.readValue(inputStream, KeePassFile.class);
return res;
return mapper.readValue(inputStream, KeePassFile.class);

}

Expand All @@ -82,7 +75,7 @@ public JacksonSerializableDatabase load(InputStream inputStream) throws IOExcept


@Override
public void save(OutputStream outputStream) throws IOException {
public void save(OutputStream outputStream) {
prepareForSave(keePassFile.root.group);
try {

Expand Down

0 comments on commit 1bce2e1

Please sign in to comment.