Skip to content

Commit

Permalink
Oobranch c : ootext and rangesort (#7788)
Browse files Browse the repository at this point in the history
* 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
antalk2 authored Jul 12, 2021
1 parent bd7fc7f commit b6a287f
Show file tree
Hide file tree
Showing 13 changed files with 1,667 additions and 0 deletions.
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.
*
* @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

0 comments on commit b6a287f

Please sign in to comment.