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 c : ootext and rangesort #7788

Merged
merged 25 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 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
66ac767
Merge remote-tracking branch 'upstream/main' into oobranch-C
antalk2 Jun 18, 2021
24375e9
ootext changes from improve-reversibility-rebased-03
antalk2 Jun 18, 2021
8c92db7
rangesort changes from improve-reversibility-rebased-03
antalk2 Jun 18, 2021
119149c
rangesort update from improve-reversibility-rebased-03
antalk2 Jun 19, 2021
91a3086
use longer lines in comments
antalk2 Jun 19, 2021
7533e8f
deleted src/main/java/org/jabref/model/openoffice/rangesort/RangeS…
antalk2 Jun 19, 2021
5fe0c36
use StringUtil.isNullOrEmpty
antalk2 Jun 22, 2021
65e1781
no natural sort for ComparableMark
antalk2 Jun 22, 2021
89f9aa6
in response to review
antalk2 Jul 7, 2021
373f467
use {@code }, PMD suggestions
antalk2 Jul 9, 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
84 changes: 84 additions & 0 deletions src/main/java/org/jabref/model/openoffice/ootext/OOFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.jabref.model.openoffice.ootext;

import org.jabref.model.strings.StringUtil;

/**
* Helper functions to produce some of the markup as understood by OOTextIntoOO.write
*
* These do not cover all tags, only those needed to embed markup
* from Layout and citation marker formatters into citation markers and
* bibliography.
*/
public class OOFormat {

private OOFormat() {
/* */
}

/**
* Mark {@code ootext} as using a character locale known to OO.
k3KAW8Pnf7mkmdSMPHz27 marked this conversation as resolved.
Show resolved Hide resolved
*
* @param locale language[-country[-territory]]
*
* https://www.openoffice.org/api/docs/common/ref/com/sun/star/lang/Locale.html
*
* The country part is optional.
*
* The territory part is not only optional, the allowed "codes are vendor and browser-specific",
* so probably best to avoid them if possible.
*
*/
public static OOText setLocale(OOText ootext, String locale) {
return OOText.fromString(String.format("<span lang=\"%s\">", locale) + ootext.toString() + "</span>");
}

/**
* Mark {@code ootext} as using the character locale "zxx", which means "no language", "no
* linguistic content".
*
* Used around citation marks, probably to turn off spellchecking.
*
*/
public static OOText setLocaleNone(OOText ootext) {
return OOFormat.setLocale(ootext, "zxx");
}

/**
* Mark {@code ootext} using a character style {@code charStyle}
*
* @param charStyle Name of a character style known to OO. May be empty for "Standard", which in
* turn means do not override any properties.
*
*/
public static OOText setCharStyle(OOText ootext, String charStyle) {
return OOText.fromString(String.format("<span oo:CharStyleName=\"%s\">", charStyle)
+ ootext.toString()
+ "</span>");
}

/**
* Mark {@code ootext} as part of a paragraph with style {@code paraStyle}
*/
public static OOText paragraph(OOText ootext, String paraStyle) {
if (StringUtil.isNullOrEmpty(paraStyle)) {
return paragraph(ootext);
}
String startTag = String.format("<p oo:ParaStyleName=\"%s\">", paraStyle);
return OOText.fromString(startTag + ootext.toString() + "</p>");
}

/**
* Mark {@code ootext} as part of a paragraph.
*/
public static OOText paragraph(OOText ootext) {
return OOText.fromString("<p>" + ootext.toString() + "</p>");
}

/**
* Format an OO cross-reference showing the target's page number as label to a reference mark.
*/
public static OOText formatReferenceToPageNumberOfReferenceMark(String referenceMarkName) {
String string = String.format("<oo:referenceToPageNumberOfReferenceMark target=\"%s\">", referenceMarkName);
return OOText.fromString(string);
}
}
61 changes: 61 additions & 0 deletions src/main/java/org/jabref/model/openoffice/ootext/OOText.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.jabref.model.openoffice.ootext;

import java.util.Objects;

/**
* Text with HTML-like markup as understood by OOTextIntoOO.write
*
* Some of the tags can be added using OOFormat methods. Others come from the layout engine, either
* by interpreting LaTeX markup or from settings in the jstyle file.
*/
public class OOText {

private final String data;

private OOText(String data) {
Objects.requireNonNull(data);
this.data = data;
}

/** @return null for null input, otherwise the argument wrapped into a new OOText */
public static OOText fromString(String string) {
if (string == null) {
return null;
}
return new OOText(string);
}

/** @return null for null input, otherwise the string inside the argument */
public static String toString(OOText ootext) {
if (ootext == null) {
return null;
}
return ootext.data;
}

@Override
public String toString() {
return data;
}

@Override
public boolean equals(Object object) {

if (object == this) {
return true;
}

if (!(object instanceof OOText)) {
return false;
}

OOText other = (OOText) object;

return data.equals(other.data);
}

@Override
public int hashCode() {
return data.hashCode();
}
}
Loading