-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Oobranch c : ootext and rangesort (#7788)
* step0 : start model/openoffice, logic/openoffice/style * correction: import order * add general utilities * add UNO utilities, move CreationException, NoDocumentException * Xlint:unchecked model/openoffice/util * add ootext * add rangesort * add compareStartsUnsafe, compareStartsThenEndsUnsafe * add Tuple3 * add ootext * add rangesort * delNamesArray size correction * rangeSort update * cleanup * ootext changes from improve-reversibility-rebased-03 * rangesort changes from improve-reversibility-rebased-03 * rangesort update from improve-reversibility-rebased-03 add comment on RangeSet.add costs use UnoTextRange.compareXXXUnsafe * use longer lines in comments * deleted src/main/java/org/jabref/model/openoffice/rangesort/RangeSet.java * use StringUtil.isNullOrEmpty * no natural sort for ComparableMark * in response to review #7788 (review) - more use of StringUtil.isNullOrEmpty - private final XTextRangeCompare cmp; - List<V> partition = partitions.computeIfAbsent(partitionKey, _key -> new ArrayList<>()); - visualSort does not throw WrappedTargetException, NoDocumentException - set renamed to comparableMarks * use {@code }, PMD suggestions
- Loading branch information
Showing
13 changed files
with
1,667 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
src/main/java/org/jabref/model/openoffice/ootext/OOFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
* | ||
* @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
61
src/main/java/org/jabref/model/openoffice/ootext/OOText.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.