Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oobranch f : add frontend #7791

Merged
merged 55 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a50cc79
step0 : start model/openoffice, logic/openoffice/style
antalk2 May 27, 2021
d93bd56
correction: import order
antalk2 May 27, 2021
c9b72e9
add general utilities
antalk2 May 27, 2021
381a549
add UNO utilities, move CreationException, NoDocumentException
antalk2 May 27, 2021
f94c1f6
Xlint:unchecked model/openoffice/util
antalk2 May 28, 2021
f9a8176
add ootext
antalk2 May 28, 2021
6d013f1
add rangesort
antalk2 May 28, 2021
0434579
add compareStartsUnsafe, compareStartsThenEndsUnsafe
antalk2 Jun 3, 2021
3c45a8a
add Tuple3
antalk2 Jun 3, 2021
32f7a43
add ootext
antalk2 May 28, 2021
6bae6b4
add rangesort
antalk2 May 28, 2021
314902c
delNamesArray size correction
antalk2 Jun 3, 2021
dfe18bc
rangeSort update
antalk2 Jun 3, 2021
c9f4e57
Merge remote-tracking branch 'origin/oobranch-C' into oobranch-C
antalk2 Jun 3, 2021
6e4c7c2
cleanup
antalk2 Jun 3, 2021
9388b2a
style additions
antalk2 Jun 3, 2021
d2a53c7
add backend
antalk2 Jun 3, 2021
0fed618
add frontend
antalk2 Jun 3, 2021
88cab9c
checkstyle on tests
antalk2 Jun 3, 2021
b7aaf2a
add missing message
antalk2 Jun 3, 2021
0fa9a4c
add backend
antalk2 Jun 3, 2021
946242f
Merge remote-tracking branch 'origin/oobranch-E' into oobranch-E
antalk2 Jun 3, 2021
a5b7a05
add frontend
antalk2 Jun 3, 2021
765f570
Merge remote-tracking branch 'origin/oobranch-F' into oobranch-F
antalk2 Jun 3, 2021
4f939b2
apply oobranch-[DEF]-update.patch
antalk2 Jun 19, 2021
e93ef46
Merge remote-tracking branch 'upstream/main' into oobranch-F
antalk2 Jun 19, 2021
9f5b148
not using RangeSet
antalk2 Jun 19, 2021
7fa8501
use StringUtil.isNullOrEmpty
antalk2 Jun 22, 2021
b31cfd7
no natural sort for ComparableMark
antalk2 Jun 22, 2021
a2d913a
in response to review
antalk2 Jul 7, 2021
ab6fbe1
use {@code }, PMD suggestions
antalk2 Jul 9, 2021
8d94e5b
Merge remote-tracking branch 'upstream/main' into oobranch-F
antalk2 Jul 13, 2021
daf64d4
update logic/style from improve-reversibility-rebased-03
antalk2 Jul 13, 2021
29d8555
update model/style from improve-reversibility-rebased-03
antalk2 Jul 13, 2021
76ded20
replaced single-character names in OOBibStyle.java (in changed part)
antalk2 Jul 18, 2021
9fa4e13
some longer names in OOBibStyleGetCitationMarker.java
antalk2 Jul 18, 2021
5d447ec
drop normalizePageInfos, use 'preferred' and 'fallback' in getAuthorL…
antalk2 Jul 18, 2021
43ac154
checkstyle
antalk2 Jul 18, 2021
c6fa7b6
use putIfAbsent
antalk2 Jul 18, 2021
b085f5e
use "{}" with LOGGER
antalk2 Jul 18, 2021
17886d0
use Objects.hash and Objects.equals in CitationLookupResult
antalk2 Jul 18, 2021
7d259e0
simplified CitedKey.getBibEntry
antalk2 Jul 18, 2021
6de9fe5
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
80ae0b1
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
eeb9a58
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
6c4aee6
Citation.lookup: use streams
antalk2 Jul 24, 2021
822dc05
Citation.lookup: Optional::get before findFirst
antalk2 Jul 24, 2021
9273932
Merge remote-tracking branch 'upstream/main' into oobranch-F
antalk2 Aug 2, 2021
75216e9
putIfAbsent returns null for new entry
antalk2 Aug 2, 2021
4dbb6cd
What is 52 in Backend52
antalk2 Aug 3, 2021
35c6c8f
apply 2021-08-20-a/oobranch-E-update.patch
antalk2 Aug 20, 2021
3eb7a7f
sync to improve-reversibility-rebased-03 cb132566f32cba17af24b41d0374…
antalk2 Aug 20, 2021
fefe7d8
Merge remote-tracking branch 'upstream/main' into oobranch-F
antalk2 Aug 23, 2021
131f386
longer name
antalk2 Aug 23, 2021
ed8fb0d
follow some PMD suggestions
antalk2 Aug 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
class ConnectionLostException extends RuntimeException {

public ConnectionLostException(String s) {
super(s);
public ConnectionLostException(String msg) {
super(msg);
}
}
15 changes: 7 additions & 8 deletions src/main/java/org/jabref/logic/openoffice/OOUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ public static void insertOOFormattedTextAtCurrentLocation(XText text, XTextCurso
List<Formatting> formatting = new ArrayList<>();
// We need to extract formatting. Use a simple regexp search iteration:
int piv = 0;
Matcher m = OOUtil.HTML_TAG.matcher(lText);
while (m.find()) {
String currentSubstring = lText.substring(piv, m.start());
Matcher matcher = OOUtil.HTML_TAG.matcher(lText);
while (matcher.find()) {
String currentSubstring = lText.substring(piv, matcher.start());
if (!currentSubstring.isEmpty()) {
OOUtil.insertTextAtCurrentLocation(text, cursor, currentSubstring, formatting);
}
String tag = m.group();
String tag = matcher.group();
// Handle tags:
if ("<b>".equals(tag)) {
formatting.add(Formatting.BOLD);
Expand Down Expand Up @@ -169,7 +169,7 @@ public static void insertOOFormattedTextAtCurrentLocation(XText text, XTextCurso
formatting.remove(Formatting.STRIKEOUT);
}

piv = m.end();
piv = matcher.end();
}

if (piv < lText.length()) {
Expand Down Expand Up @@ -276,10 +276,9 @@ public static void insertTextAtCurrentLocation(XText text, XTextCursor cursor, S
cursor.collapseToEnd();
}

public static Object getProperty(Object o, String property)
public static Object getProperty(Object object, String property)
throws UnknownPropertyException, WrappedTargetException {
XPropertySet props = UnoRuntime.queryInterface(
XPropertySet.class, o);
XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, object);
return props.getPropertyValue(property);
}
}
22 changes: 11 additions & 11 deletions src/main/java/org/jabref/logic/openoffice/backend/Backend52.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,6 @@ public CitationGroup createCitationGroup(XTextDocument doc,
throw new IllegalArgumentException();
}

/*
* Backend52 uses reference marks to (1) mark the location of the citation in the text and (2) to encode
* the citation keys and citation type in the name of the reference mark. The name of the reference mark
* has to be unique in the document.
*/
String markName = Codec52.getUniqueMarkName(new HashSet<>(citationStorageManager.getUsedNames(doc)),
citationKeys,
citationType);

CitationGroupId groupId = new CitationGroupId(markName);

final int numberOfCitations = citationKeys.size();
final int last = numberOfCitations - 1;

Expand Down Expand Up @@ -236,6 +225,17 @@ public CitationGroup createCitationGroup(XTextDocument doc,
}
}

/*
* Backend52 uses reference marks to (1) mark the location of the citation in the text and (2) to encode
* the citation keys and citation type in the name of the reference mark. The name of the reference mark
* has to be unique in the document.
*/
final String markName = Codec52.getUniqueMarkName(new HashSet<>(citationStorageManager.getUsedNames(doc)),
citationKeys,
citationType);

final CitationGroupId groupId = new CitationGroupId(markName);

/*
* Apply to document
*/
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/org/jabref/logic/openoffice/backend/Codec52.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ private Codec52() {
*/
public static class ParsedMarkName {
/** "", "0", "1" ... */
public final String i;
public final String index;
/** in-text-citation type */
public final CitationType citationType;
/** Citation keys embedded in the reference mark. */
public final List<String> citationKeys;

ParsedMarkName(String i, CitationType citationType, List<String> citationKeys) {
Objects.requireNonNull(i);
ParsedMarkName(String index, CitationType citationType, List<String> citationKeys) {
Objects.requireNonNull(index);
Objects.requireNonNull(citationKeys);
this.i = i;
this.index = index;
this.citationType = citationType;
this.citationKeys = citationKeys;
}
Expand All @@ -50,17 +50,17 @@ public static class ParsedMarkName {
/**
* Integer representation was written into the document in JabRef52, keep it for compatibility.
*/
private static CitationType citationTypeFromInt(int i) {
return switch (i) {
private static CitationType citationTypeFromInt(int code) {
return switch (code) {
case 1 -> CitationType.AUTHORYEAR_PAR;
case 2 -> CitationType.AUTHORYEAR_INTEXT;
case 3 -> CitationType.INVISIBLE_CIT;
default -> throw new IllegalArgumentException("Invalid CitationType code");
};
}

private static int citationTypeToInt(CitationType i) {
return switch (i) {
private static int citationTypeToInt(CitationType type) {
return switch (type) {
case AUTHORYEAR_PAR -> 1;
case AUTHORYEAR_INTEXT -> 2;
case INVISIBLE_CIT -> 3;
Expand All @@ -86,12 +86,12 @@ public static String getUniqueMarkName(Set<String> usedNames,

String citationKeysPart = String.join(",", citationKeys);

int i = 0;
int index = 0;
int citTypeCode = citationTypeToInt(citationType);
String name = BIB_CITATION + '_' + citTypeCode + '_' + citationKeysPart;
while (usedNames.contains(name)) {
name = BIB_CITATION + i + '_' + citTypeCode + '_' + citationKeysPart;
i++;
name = BIB_CITATION + index + '_' + citTypeCode + '_' + citationKeysPart;
index++;
}
return name;
}
Expand All @@ -110,10 +110,10 @@ public static Optional<ParsedMarkName> parseMarkName(String refMarkName) {
}

List<String> keys = Arrays.asList(citeMatcher.group(3).split(","));
String i = citeMatcher.group(1);
String index = citeMatcher.group(1);
int citTypeCode = Integer.parseInt(citeMatcher.group(2));
CitationType citationType = citationTypeFromInt(citTypeCode);
return (Optional.of(new Codec52.ParsedMarkName(i, citationType, keys)));
return (Optional.of(new Codec52.ParsedMarkName(index, citationType, keys)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class NamedRangeReferenceMark implements NamedRange {

private static final Logger LOGGER = LoggerFactory.getLogger(NamedRangeReferenceMark.class);

private String id; /* reference mark name */
private String rangeId; /* reference mark name */

private NamedRangeReferenceMark(String id) {
this.id = id;
private NamedRangeReferenceMark(String rangeId) {
this.rangeId = rangeId;
}

String getId() {
return id;
return rangeId;
}

/**
Expand Down Expand Up @@ -156,7 +156,7 @@ public void removeFromDocument(XTextDocument doc)

@Override
public String getRangeName() {
return id;
return rangeId;
}

/**
Expand Down Expand Up @@ -217,8 +217,6 @@ public XTextCursor getFillCursor(XTextDocument doc)

String name = this.getRangeName();

final String left = NamedRangeReferenceMark.REFERENCE_MARK_LEFT_BRACKET;
final String right = NamedRangeReferenceMark.REFERENCE_MARK_RIGHT_BRACKET;
final boolean debugThisFun = false;

XTextCursor full = null;
Expand Down Expand Up @@ -279,6 +277,8 @@ public XTextCursor getFillCursor(XTextDocument doc)
beta.goRight((short) (fullText.length() - 2), true);
LOGGER.debug("getFillCursor: beta(1) covers '{}'", beta.getString());

final String left = NamedRangeReferenceMark.REFERENCE_MARK_LEFT_BRACKET;
final String right = NamedRangeReferenceMark.REFERENCE_MARK_RIGHT_BRACKET;
final short rightLength = (short) right.length();
if (fullText.startsWith(left) && fullText.endsWith(right)) {
beta.setString("");
Expand Down Expand Up @@ -345,7 +345,6 @@ public XTextCursor getFillCursor(XTextDocument doc)
*/
public static void checkFillCursor(XTextCursor cursor) {
final String left = REFERENCE_MARK_LEFT_BRACKET;
final String right = REFERENCE_MARK_RIGHT_BRACKET;

XTextCursor alpha = cursor.getText().createTextCursorByRange(cursor);
alpha.collapseToStart();
Expand All @@ -364,6 +363,7 @@ public static void checkFillCursor(XTextCursor cursor) {
}
}

final String right = REFERENCE_MARK_RIGHT_BRACKET;
final short rightLength = (short) right.length();
if (rightLength > 0) {
omega.goRight(rightLength, true);
Expand Down Expand Up @@ -395,27 +395,26 @@ public void cleanFillCursor(XTextDocument doc)
// removeBracketsFromEmpty is intended to force removal if we are working on an "Empty citation" (INVISIBLE_CIT).
final boolean removeBracketsFromEmpty = false;

final String left = REFERENCE_MARK_LEFT_BRACKET;
final String right = REFERENCE_MARK_RIGHT_BRACKET;
final short leftLength = (short) left.length();
final short rightLength = (short) right.length();

String name = this.getRangeName();

XTextCursor full = this.getRawCursor(doc).orElseThrow(IllegalStateException::new);
final String fullText = full.getString();
final int fullTextLength = fullText.length();

final String left = REFERENCE_MARK_LEFT_BRACKET;
if (!fullText.startsWith(left)) {
String msg = String.format("cleanFillCursor: (%s) does not start with REFERENCE_MARK_LEFT_BRACKET", name);
throw new IllegalStateException(msg);
}

final String right = REFERENCE_MARK_RIGHT_BRACKET;
if (!fullText.endsWith(right)) {
String msg = String.format("cleanFillCursor: (%s) does not end with REFERENCE_MARK_RIGHT_BRACKET", name);
throw new IllegalStateException(msg);
}

final int fullTextLength = fullText.length();
final short leftLength = (short) left.length();
final short rightLength = (short) right.length();
final int contentLength = (fullTextLength - (leftLength + rightLength));
if (contentLength < 0) {
String msg = String.format("cleanFillCursor: length(%s) < 0", name);
Expand Down
Loading