diff --git a/src/main/java/de/hamburgchimps/apple/notes/liberator/data/NoteData.java b/src/main/java/de/hamburgchimps/apple/notes/liberator/data/NoteData.java index f886ddb..206e462 100644 --- a/src/main/java/de/hamburgchimps/apple/notes/liberator/data/NoteData.java +++ b/src/main/java/de/hamburgchimps/apple/notes/liberator/data/NoteData.java @@ -6,8 +6,10 @@ import de.hamburgchimps.apple.notes.liberator.Constants; import de.hamburgchimps.apple.notes.liberator.ProtoUtils; import de.hamburgchimps.apple.notes.liberator.UserMessages; +import de.hamburgchimps.apple.notes.liberator.data.format.Link; import de.hamburgchimps.apple.notes.liberator.entity.Note; import de.hamburgchimps.apple.notes.liberator.entity.NotesCloudObject; +import io.quarkus.logging.Log; import java.util.ArrayList; import java.util.List; @@ -19,6 +21,7 @@ public class NoteData { private String folder; private String text; private List embeddedObjects; + private List links = new ArrayList<>(); private NoteStoreProto proto; private final List errors = new ArrayList<>(); @@ -37,14 +40,17 @@ public NoteData(Note n) { this.folder = noteObject.zFolder.zTitle2; this.text = this.getProtoNote().getNoteText(); this.parseEmbeddedObjects(); + this.parseLinks(); } public String getTitle() { return title; } + public String getFolder() { return folder; } + public String getText() { return text; } @@ -52,6 +58,11 @@ public String getText() { public List getEmbeddedObjects() { return embeddedObjects; } + + public List getLinks() { + return links; + } + @JsonIgnore public List getErrors() { return errors; @@ -87,6 +98,8 @@ private Optional parseEmbeddedObject(Notestore.AttachmentInf .firstResult(); if (notesCloudObject == null) { + // We are most likely dealing with a deleted note that has some dead references + // hanging around in the database still. There is not much we can do with these. this.errors.add(new RuntimeException(String.format(UserMessages.EMBEDDED_OBJECT_PARSE_ERROR_IDENTIFIER_DOES_NOT_EXIST, identifier))); return Optional.empty(); } @@ -107,6 +120,19 @@ private Optional parseEmbeddedObject(Notestore.AttachmentInf return Optional.of(new File(notesCloudObject)); } + private void parseLinks() { + // TODO this is hacky + var positionTracker = 0; + + for (var attributeRun : this.getProtoNote().getAttributeRunList()) { + if (attributeRun.hasLink()) { + var endOfLinkText = positionTracker + attributeRun.getLength(); + this.links.add(new Link(this.getText().substring(positionTracker, endOfLinkText), attributeRun.getLink())); + } + positionTracker += attributeRun.getLength(); + } + } + private Notestore.Note getProtoNote() { return this.proto.getDocument().getNote(); } diff --git a/src/main/java/de/hamburgchimps/apple/notes/liberator/data/format/Link.java b/src/main/java/de/hamburgchimps/apple/notes/liberator/data/format/Link.java new file mode 100644 index 0000000..d2244ce --- /dev/null +++ b/src/main/java/de/hamburgchimps/apple/notes/liberator/data/format/Link.java @@ -0,0 +1,3 @@ +package de.hamburgchimps.apple.notes.liberator.data.format; + +public record Link(String text, String url) { } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index d2cfdfe..372fd82 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,4 +6,4 @@ quarkus.hibernate-orm.validate-in-dev-mode=false %debug.quarkus.log.category."de.hamburgchimps".level=DEBUG %debug.quarkus.log.file.enable=true -%debug.quarkus.log.file.path=apple-notes-liberator.log +%debug.quarkus.log.file.path=liberated-notes/apple-notes-liberator.log