Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.model.openoffice.ootext

public Class OOTextIntoOO

extends Object
Class Inheritance
Annotations
@AllowedToUseLogic:Uses StringUtil temporarily
@AllowedToUseAwt:Requires AWT for changing document properties
Imports
java.util.ArrayDeque, .ArrayList, .Arrays, .Deque, .HashMap, .List, .Map, .Objects, .Optional, .Set, java.util.regex.Matcher, .Pattern, org.jabref.architecture.AllowedToUseAwt, .AllowedToUseLogic, org.jabref.logic.util.strings.StringUtil, org.jabref.model.openoffice.uno.CreationException, .UnoCast, .UnoCrossRef, org.jabref.model.openoffice.util.OOPair, com.sun.star.awt.FontSlant, com.sun.star.awt.FontStrikeout, com.sun.star.awt.FontUnderline, com.sun.star.awt.FontWeight, com.sun.star.beans.Property, com.sun.star.beans.PropertyAttribute, com.sun.star.beans.PropertyState, com.sun.star.beans.PropertyVetoException, com.sun.star.beans.UnknownPropertyException, com.sun.star.beans.XMultiPropertySet, com.sun.star.beans.XMultiPropertyStates, com.sun.star.beans.XPropertySet, com.sun.star.beans.XPropertySetInfo, com.sun.star.beans.XPropertyState, com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.Locale, com.sun.star.lang.WrappedTargetException, com.sun.star.style.CaseMap, com.sun.star.text.ControlCharacter, com.sun.star.text.XParagraphCursor, com.sun.star.text.XText, com.sun.star.text.XTextCursor, com.sun.star.text.XTextDocument, org.jspecify.annotations.NonNull, org.slf4j.Logger, .LoggerFactory

Interpret OOText into an OpenOffice or LibreOffice writer document.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final String
private static final Pattern
private static final String
private static final String
private static final String
private static final String
private static final byte
private static final short
private static final String
private static final String
private static final String
private static final Pattern
private static final Logger
private static final String
PARA_STYLE_NAME

"ParaStyleName" is an OpenOffice Property name.

private static final byte
private static final short
private static final byte
private static final short
private static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
insertParagraphBreak(com.sun.star.text.XText text, com.sun.star.text.XTextCursor cursor)

private static boolean
isPropertyDefault(com.sun.star.text.XTextCursor cursor, String propertyName)

We rely on property values being either DIRECT_VALUE or DEFAULT_VALUE (not AMBIGUOUS_VALUE).

private static List<OOPair<String, String>>
parseAttributes(String attributes)

Parse HTML-like attributes to a list of (name,value) pairs.

public static void
removeDirectFormatting(com.sun.star.text.XTextCursor cursor)

Purpose: in some cases we do not want to inherit direct formatting from the context.

public static void
removeEscapementFormatting(@NonNull com.sun.star.text.XTextCursor cursor)

Reset only direct superscript/subscript formatting before rewriting marked-up citation text.

private static List<OOPair<String, Object>>
setCharCaseMap(short value)

private static List<OOPair<String, Object>>
setCharEscapement(Optional<Short> value, Optional<Byte> height, boolean relative, OOTextIntoOO.MyPropertyStack formatStack)

private static List<OOPair<String, Object>>
setCharLocale(com.sun.star.lang.Locale value)

private static List<OOPair<String, Object>>
setCharLocale(String value)

Locale from string encoding: language, language-country or language-country-variant

private static List<OOPair<String, Object>>
setCharPosture(com.sun.star.awt.FontSlant value)

private static List<OOPair<String, Object>>
setCharStrikeout(short value)

private static List<OOPair<String, Object>>
private static List<OOPair<String, Object>>
setCharUnderline(short value)

private static List<OOPair<String, Object>>
setCharWeight(float value)

public static boolean
setParagraphStyle(com.sun.star.text.XTextCursor cursor, String paragraphStyle)

Returns: true on failure

private static List<OOPair<String, Object>>
private static List<OOPair<String, Object>>
public static void
write(@NonNull com.sun.star.text.XTextDocument doc, @NonNull com.sun.star.text.XTextCursor
The cursor giving the insert location. Not modified.
position
,
@NonNull OOText
The marked-up text to insert.
ootext
)

Insert a text with formatting indicated by HTML-like tags, into a text at the position given by a cursor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ATTRIBUTE_NAME_REGEXPback to summary
private static final String ATTRIBUTE_NAME_REGEXP
ATTRIBUTE_PATTERNback to summary
private static final Pattern ATTRIBUTE_PATTERN
ATTRIBUTE_VALUE_REGEXPback to summary
private static final String ATTRIBUTE_VALUE_REGEXP
CHAR_AUTO_ESCAPEMENTback to summary
private static final String CHAR_AUTO_ESCAPEMENT
CHAR_ESCAPEMENTback to summary
private static final String CHAR_ESCAPEMENT
CHAR_ESCAPEMENT_HEIGHTback to summary
private static final String CHAR_ESCAPEMENT_HEIGHT
CHAR_ESCAPEMENT_HEIGHT_DEFAULTback to summary
private static final byte CHAR_ESCAPEMENT_HEIGHT_DEFAULT
CHAR_ESCAPEMENT_VALUE_DEFAULTback to summary
private static final short CHAR_ESCAPEMENT_VALUE_DEFAULT
CHAR_STRIKEOUTback to summary
private static final String CHAR_STRIKEOUT
CHAR_STYLE_NAMEback to summary
private static final String CHAR_STYLE_NAME
CHAR_UNDERLINEback to summary
private static final String CHAR_UNDERLINE
HTML_TAGback to summary
private static final Pattern HTML_TAG
LOGGERback to summary
private static final Logger LOGGER
PARA_STYLE_NAMEback to summary
private static final String PARA_STYLE_NAME

"ParaStyleName" is an OpenOffice Property name.

SUBSCRIPT_HEIGHTback to summary
private static final byte SUBSCRIPT_HEIGHT
SUBSCRIPT_VALUEback to summary
private static final short SUBSCRIPT_VALUE
SUPERSCRIPT_HEIGHTback to summary
private static final byte SUPERSCRIPT_HEIGHT
SUPERSCRIPT_VALUEback to summary
private static final short SUPERSCRIPT_VALUE
TAG_NAME_REGEXPback to summary
private static final String TAG_NAME_REGEXP

Constructor Detail

OOTextIntoOOback to summary
private OOTextIntoOO()

Method Detail

insertParagraphBreakback to summary
private static void insertParagraphBreak(com.sun.star.text.XText text, com.sun.star.text.XTextCursor cursor)
isPropertyDefaultback to summary
private static boolean isPropertyDefault(com.sun.star.text.XTextCursor cursor, String propertyName) throws com.sun.star.beans.UnknownPropertyException

We rely on property values being either DIRECT_VALUE or DEFAULT_VALUE (not AMBIGUOUS_VALUE). If the cursor covers a homogeneous region, or is collapsed, then this is true.

parseAttributesback to summary
private static List<OOPair<String, String>> parseAttributes(String attributes)

Parse HTML-like attributes to a list of (name,value) pairs.

removeDirectFormattingback to summary
public static void removeDirectFormatting(com.sun.star.text.XTextCursor cursor)

Purpose: in some cases we do not want to inherit direct formatting from the context.

In particular, when filling the bibliography title and body.

removeEscapementFormattingback to summary
public static void removeEscapementFormatting(@NonNull com.sun.star.text.XTextCursor cursor)

Reset only direct superscript/subscript formatting before rewriting marked-up citation text.

setCharCaseMapback to summary
private static List<OOPair<String, Object>> setCharCaseMap(short value)
setCharEscapementback to summary
private static List<OOPair<String, Object>> setCharEscapement(Optional<Short> value, Optional<Byte> height, boolean relative, OOTextIntoOO.MyPropertyStack formatStack)
setCharLocaleback to summary
private static List<OOPair<String, Object>> setCharLocale(com.sun.star.lang.Locale value)
setCharLocaleback to summary
private static List<OOPair<String, Object>> setCharLocale(String value)

Locale from string encoding: language, language-country or language-country-variant

setCharPostureback to summary
private static List<OOPair<String, Object>> setCharPosture(com.sun.star.awt.FontSlant value)
setCharStrikeoutback to summary
private static List<OOPair<String, Object>> setCharStrikeout(short value)
setCharStyleNameback to summary
private static List<OOPair<String, Object>> setCharStyleName(String value)
setCharUnderlineback to summary
private static List<OOPair<String, Object>> setCharUnderline(short value)
setCharWeightback to summary
private static List<OOPair<String, Object>> setCharWeight(float value)
setParagraphStyleback to summary
public static boolean setParagraphStyle(com.sun.star.text.XTextCursor cursor, String paragraphStyle)
Returns:boolean

true on failure

setSubScriptback to summary
private static List<OOPair<String, Object>> setSubScript(OOTextIntoOO.MyPropertyStack formatStack)
setSuperScriptback to summary
private static List<OOPair<String, Object>> setSuperScript(OOTextIntoOO.MyPropertyStack formatStack)
writeback to summary
public static void write(@NonNull com.sun.star.text.XTextDocument doc, @NonNull com.sun.star.text.XTextCursor position, @NonNull OOText ootext) throws com.sun.star.lang.WrappedTargetException, CreationException

Insert a text with formatting indicated by HTML-like tags, into a text at the position given by a cursor.

Limitation: understands no entities. It does not receive any either, unless the user provides it.

To limit the damage TAG_NAME_REGEXP and ATTRIBUTE_NAME_REGEXP explicitly lists the names we care about.

Notable changes w.r.t insertOOFormattedTextAtCurrentLocation:

  • new tags:

  • <span lang="zxx"> - earlier was applied from code

  • <span oo:CharStyleName="CharStylename"> - earlier was applied from code, for "CitationCharacterFormat"

  • <p> start new paragraph - earlier was applied from code

  • <p oo:ParaStyleName="ParStyleName"> : start new paragraph and apply ParStyleName - earlier was applied from code

  • <tt> - earlier: known, but ignored - now: equivalent to <span oo:CharStyleName="Example"> - <oo:referenceToPageNumberOfReferenceMark> (self-closing)

  • closing tags try to properly restore state (in particular, the "not directly set" state) instead of dictating an "off" state. This makes a difference when the value inherited from another level (for example the paragraph) is not the "off" state.

An example: a style with ReferenceParagraphFormat="JR_bibentry" Assume JR_bibentry in LibreOffice is a paragraph style that prescribes "bold" font. LAYOUT only prescribes bold around year. Which parts of the bibliography entries should come out as bold?

  • The user can format citation marks (it is enough to format their start) and the properties not (everywhere) dictated by the style are preserved (where they are not).
Parameters
position:@NonNull com.sun.star.text.XTextCursor

The cursor giving the insert location. Not modified.

ootext:@NonNull OOText

The marked-up text to insert.

org.jabref.model.openoffice.ootext back to summary

pack-priv Class OOTextIntoOO.MyPropertyStack

extends Object
Class Inheritance
  • java.lang.Object
  • org.jabref.model.openoffice.ootext.OOTextIntoOO.MyPropertyStack

Field Summary

Modifier and TypeField and Description
pack-priv static final Set<String>
pack-priv final String[]
goodNames

From index to property name.

pack-priv final Map<String, Integer>
goodNameToIndex

From property name to index in goodNames.

pack-priv final int
goodSize

The number of properties actually controlled.

pack-priv final Deque<ArrayList<Optional<Object>>>
layers

Maintain a stack of layers, each containing a description of the desired state of properties.

Constructor Summary

AccessConstructor and Description
pack-priv
MyPropertyStack(com.sun.star.text.XTextCursor cursor)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
apply(com.sun.star.text.XTextCursor cursor)

Apply the current desired formatting state to a cursor.

pack-priv Optional<Object>
pack-priv void
popLayer()

Closing tags just pop a layer.

pack-priv void
pushLayer(List<OOPair<String, Object>> settings)

Given a list of property name, property value pairs, construct and push a new layer describing the intended state after these have been applied.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CONTROLLED_PROPERTIESback to summary
pack-priv static final Set<String> CONTROLLED_PROPERTIES
goodNamesback to summary
pack-priv final String[] goodNames

From index to property name.

goodNameToIndexback to summary
pack-priv final Map<String, Integer> goodNameToIndex

From property name to index in goodNames.

goodSizeback to summary
pack-priv final int goodSize

The number of properties actually controlled.

layersback to summary
pack-priv final Deque<ArrayList<Optional<Object>>> layers

Maintain a stack of layers, each containing a description of the desired state of properties. Each description is an ArrayList of property values, Optional.empty() encoding "not directly set".

Constructor Detail

MyPropertyStackback to summary
pack-priv MyPropertyStack(com.sun.star.text.XTextCursor cursor)

Method Detail

applyback to summary
pack-priv void apply(com.sun.star.text.XTextCursor cursor)

Apply the current desired formatting state to a cursor.

The idea is to minimize the number of calls to OpenOffice.

getPropertyValueback to summary
pack-priv Optional<Object> getPropertyValue(String name)
popLayerback to summary
pack-priv void popLayer()

Closing tags just pop a layer.

pushLayerback to summary
pack-priv void pushLayer(List<OOPair<String, Object>> settings)

Given a list of property name, property value pairs, construct and push a new layer describing the intended state after these have been applied.

Opening tags usually call this.