Package org.odftoolkit.odfdom.changes
Class JsonOperationConsumer
- java.lang.Object
-
- org.odftoolkit.odfdom.changes.JsonOperationConsumer
-
public class JsonOperationConsumer extends Object
ToDo: Is it more flexible to build a different queue for OperationQueue and create an JSON exporter? Can a JSONArray / JSONObject be initialized with an existing queue?- Author:
- svante.schubertATgmail.com
-
-
Constructor Summary
Constructors Constructor Description JsonOperationConsumer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addAnnotation(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, String id, String author, String date)
static void
addBorderProperties(String key, org.json.JSONObject attrs, OdfStylePropertiesBase propertiesElement, OdfStyleBase frameParentStyle)
static void
addCells(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, int count, Component parentComponent, OdfElement newCellElement, boolean isTextTable)
static void
addColumns(Component rootComponent, org.json.JSONArray start, org.json.JSONArray tableGrid, Integer referenceColumnGridPosition, String insertMode)
Inserts cells for a new column into a tableElement.static void
addDeleteHeaderFooter(OdfDocument doc, boolean insert, String id)
static void
addDrawing(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, String type, CollabTextDocument opsDoc)
static Component
addElementAsComponent(Component parentComponent, OdfElement newElement, int newPosition)
Adds the newElement to the parentComponent.static void
addField(Component rootComponent, OdfContentDom contentDom, org.json.JSONArray start, String type, String representation, org.json.JSONObject attrs)
Currently all fields are being mapped to a common text field, i.e.static void
addLineBreak(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs)
static void
addListStyle(String listStyleId, org.json.JSONObject listDefinition, OdfDocument doc)
static void
addNoteSelection(Component rootComponent, org.json.JSONArray start, String type, String position, org.json.JSONObject attrs, String id)
static void
addPaddingProperties(String key, org.json.JSONObject attrs, OdfStylePropertiesBase propertiesElement)
static TextParagraphElementBase
addParagraph(Component parentComponent, int newPosition, org.json.JSONObject attrs)
For the demo document "FruitDepot-SeasonalFruits.odt" the tableElement looks likestatic void
addParagraph(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs)
For the demo document "FruitDepot-SeasonalFruits.odt" the tableElement looks likestatic void
addRows(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, int count, boolean addDefaultCells, int referenceRow, boolean isTextTable)
addRows Inserts one or more new rows into a tableElement.static StyleStyleElement
addStyle(org.json.JSONObject attrs, OdfStylableElement newElement, OdfFileDom ownerDocument)
At the the given newElement from the given ownerDocument the given style changes from attrs are being applied.static void
addStyleNameAttribute(OdfElement newElement, OdfStyleFamily styleFamily, OdfFileDom ownerDocument, String styleName)
static void
addStyles(OdfDocument doc, String type, String styleId, String styleName, org.json.JSONObject attrs, String parent, Boolean hidden, Boolean custom)
static void
addTab(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs)
static void
addTable(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, org.json.JSONObject sizeExceeded, String tableName)
static void
addText(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, String newText)
static void
addText(TextParagraphElementBase paragraphElementBase, int startPos, org.json.JSONObject attrs, String newText)
static int
applyOperations(CollabTextDocument opsDoc, org.json.JSONArray ops)
static void
changeField(Component rootComponent, OdfContentDom contentDom, org.json.JSONArray start, String type, String representation, org.json.JSONObject attrs)
Modify field at the given positionstatic void
changeStyle(OdfDocument doc, String type, String styleId, String styleName, org.json.JSONObject attrs)
static void
delete(Component rootComponent, org.json.JSONArray start, org.json.JSONArray end)
static void
deleteColumns(Component rootComponent, org.json.JSONArray start, Integer startGrid, Integer endGrid)
Deletes the cells of a single column or multiple columns from a tableElement.static void
deleteStyle(OdfDocument doc, String styleId, String type)
Removes a template style from the documentstatic void
format(Component rootComponent, org.json.JSONArray start, org.json.JSONArray end, org.json.JSONObject attrs)
Setting attributes on text, require the text container, otherwise the character itself (as paragraph is not child of paragraphstatic String
getColor(org.json.JSONObject color, String autoColor)
static int
getListLevel(TextParagraphElementBase paragraphBaseElement)
ToDo after release: Move this to the paragraph of ODFDOMstatic void
handleParaOutline(StyleStyleElement style, org.json.JSONObject attrs)
static TextListElement
isolateListParagraph(TextParagraphElementBase paragraphBaseElement)
Isolates the paragraph as only paragraph of the list.static void
mapCellProperties(org.json.JSONObject attrs, StyleTableCellPropertiesElement propertiesElement)
static void
mapCharacterProperties(org.json.JSONObject attrs, StyleTextPropertiesElement propertiesElement, OdfDocument doc)
static void
mapChartProperties(org.json.JSONObject attrs, StyleChartPropertiesElement propertiesElement)
static void
mapColumnProperties(org.json.JSONObject attrs, StyleTableColumnPropertiesElement propertiesElement)
static void
mapDrawingProperties(org.json.JSONObject attrs, StyleDrawingPagePropertiesElement propertiesElement)
static void
mapGraphicProperties(org.json.JSONObject attrs, StyleGraphicPropertiesElement propertiesElement, OdfStyleBase frameParentStyle)
static void
mapHeaderFooterProperties(org.json.JSONObject attrs, StyleHeaderFooterPropertiesElement propertiesElement)
static void
mapListProperties(org.json.JSONObject attrs, StyleListLevelPropertiesElement propertiesElement)
static void
mapPageProperties(org.json.JSONObject attrs, StylePageLayoutPropertiesElement propertiesElement)
static void
mapParagraphProperties(org.json.JSONObject attrs, StyleParagraphPropertiesElement propertiesElement)
static void
mapProperties(OdfStyleFamily styleFamily, org.json.JSONObject attrs, OdfStyleBase style, OdfDocument doc)
static void
mapRowProperties(org.json.JSONObject attrs, StyleTableRowPropertiesElement propertiesElement)
static void
mapRubyProperties(org.json.JSONObject attrs, StyleRubyPropertiesElement propertiesElement)
static void
mapSectionProperties(org.json.JSONObject attrs, StyleSectionPropertiesElement propertiesElement)
static void
mapTableProperties(org.json.JSONObject attrs, StyleTablePropertiesElement propertiesElement)
static void
modifyListStyleName(org.json.JSONObject attrs, OdfStyleBase autoStyle)
Modifying the @style:list-style-name to the style:style of (an automatic) style, when the paragraph properties contain a "listStyleIdstatic void
modifyListStyleName(org.json.JSONObject attrs, TextListElement rootListElement)
Modifying the @style:list-style-name to the given text:list element, when the paragraph properties contain a "listStyleIdstatic void
modifyPages(OdfDocument doc, org.json.JSONObject attrs)
Modifys the page layout (ie.static void
move(Component rootComponent, org.json.JSONArray start, org.json.JSONArray to)
Move the pointed component to its new destination.static void
setColumnsWidth(Component tableComponent, org.json.JSONArray start, org.json.JSONArray tableGrid, boolean isTextTable)
static void
setFieldAttributes(OdfElement newFieldElement, org.json.JSONObject attrs, org.odftoolkit.odfdom.changes.FieldMap currentMap, OdfContentDom contentDom)
Currently all fields are being mapped to a common text field, i.e.static void
splitParagraph(Component rootComponent, org.json.JSONArray start)
Splits a paragraph into two splitting the text among the two.
-
-
-
Method Detail
-
applyOperations
public static int applyOperations(CollabTextDocument opsDoc, org.json.JSONArray ops) throws Exception
- Throws:
Exception
-
addParagraph
public static void addParagraph(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs) throws IndexOutOfBoundsException
For the demo document "FruitDepot-SeasonalFruits.odt" the tableElement looks like- Parameters:
rootComponent
- high level document structureparaPos
- position of the paragraph starting with 0 and one over the existing is allowed- Throws:
IndexOutOfBoundsException
- - if index is out of range (index < 0 || index > size()). One over size is allowed to append a paragraph.
-
addParagraph
public static TextParagraphElementBase addParagraph(Component parentComponent, int newPosition, org.json.JSONObject attrs) throws IndexOutOfBoundsException
For the demo document "FruitDepot-SeasonalFruits.odt" the tableElement looks like- Parameters:
rootComponent
- high level document structureparaPos
- position of the paragraph starting with 0 and one over the existing is allowed- Throws:
IndexOutOfBoundsException
- - if index is out of range (index < 0 || index > size()). One over size is allowed to append a paragraph.
-
addTab
public static void addTab(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs) throws IndexOutOfBoundsException
- Throws:
IndexOutOfBoundsException
-
addLineBreak
public static void addLineBreak(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs) throws IndexOutOfBoundsException
- Throws:
IndexOutOfBoundsException
-
addStyle
public static StyleStyleElement addStyle(org.json.JSONObject attrs, OdfStylableElement newElement, OdfFileDom ownerDocument)
At the the given newElement from the given ownerDocument the given style changes from attrs are being applied. In addition automatic styles might being created, as ODF does not apply hard styles directly to the element.- Parameters:
attrs
- Map with style changesnewElement
- the element the style changes will be applied toownerDocument
- the XML file the element belongs to- Returns:
- the prior given newElement after all style changes had been applied.
-
modifyListStyleName
public static void modifyListStyleName(org.json.JSONObject attrs, OdfStyleBase autoStyle)
Modifying the @style:list-style-name to the style:style of (an automatic) style, when the paragraph properties contain a "listStyleId
-
modifyListStyleName
public static void modifyListStyleName(org.json.JSONObject attrs, TextListElement rootListElement)
Modifying the @style:list-style-name to the given text:list element, when the paragraph properties contain a "listStyleId
-
addStyleNameAttribute
public static void addStyleNameAttribute(OdfElement newElement, OdfStyleFamily styleFamily, OdfFileDom ownerDocument, String styleName)
-
move
public static void move(Component rootComponent, org.json.JSONArray start, org.json.JSONArray to)
Move the pointed component to its new destination.- Parameters:
from
- the origin of the component to be movedthe
- the new destination
-
addText
public static void addText(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, String newText) throws IndexOutOfBoundsException
- Throws:
IndexOutOfBoundsException
-
addText
public static void addText(TextParagraphElementBase paragraphElementBase, int startPos, org.json.JSONObject attrs, String newText) throws IndexOutOfBoundsException
- Throws:
IndexOutOfBoundsException
-
delete
public static void delete(Component rootComponent, org.json.JSONArray start, org.json.JSONArray end) throws IndexOutOfBoundsException
- Throws:
IndexOutOfBoundsException
-
deleteColumns
public static void deleteColumns(Component rootComponent, org.json.JSONArray start, Integer startGrid, Integer endGrid)
Deletes the cells of a single column or multiple columns from a tableElement.- Parameters:
rootComponent
- high level document structurestart
- Integer[] The logical position of the tableElement whose columns will be removed.startGrid
- Integer Zero-based index of the first column to be removed, according to the tableGrid attribute of the tableElement.endGrid
- Integer (optional) Zero-based index of the last column to be removed (closed range). If omitted, only one column will be removed. Note: Each cell that is addressed by the specified column range will be removed completely. As a side effect, this op changes the tableGrid attribute of the parentComponentElement tableElement.
-
deleteStyle
public static void deleteStyle(OdfDocument doc, String styleId, String type)
Removes a template style from the document- Parameters:
doc
- temporary font properties taken into adapter
-
changeStyle
public static void changeStyle(OdfDocument doc, String type, String styleId, String styleName, org.json.JSONObject attrs)
-
addStyles
public static void addStyles(OdfDocument doc, String type, String styleId, String styleName, org.json.JSONObject attrs, String parent, Boolean hidden, Boolean custom)
-
handleParaOutline
public static void handleParaOutline(StyleStyleElement style, org.json.JSONObject attrs)
-
format
public static void format(Component rootComponent, org.json.JSONArray start, org.json.JSONArray end, org.json.JSONObject attrs)
Setting attributes on text, require the text container, otherwise the character itself (as paragraph is not child of paragraph
-
getListLevel
public static int getListLevel(TextParagraphElementBase paragraphBaseElement)
ToDo after release: Move this to the paragraph of ODFDOM
-
isolateListParagraph
public static TextListElement isolateListParagraph(TextParagraphElementBase paragraphBaseElement)
Isolates the paragraph as only paragraph of the list. For instance, required to be able to addChild a component before/behind that paragraph in the DOM.- Parameters:
paragraphBaseElement
- the paragraph within a list- Returns:
- the root text:list element of the list
-
addListStyle
public static void addListStyle(String listStyleId, org.json.JSONObject listDefinition, OdfDocument doc)
-
splitParagraph
public static void splitParagraph(Component rootComponent, org.json.JSONArray start) throws IndexOutOfBoundsException
Splits a paragraph into two splitting the text among the two. Special handling for paragraph within lists: In this case the list item will be split!- Throws:
IndexOutOfBoundsException
-
setFieldAttributes
public static void setFieldAttributes(OdfElement newFieldElement, org.json.JSONObject attrs, org.odftoolkit.odfdom.changes.FieldMap currentMap, OdfContentDom contentDom)
Currently all fields are being mapped to a common text field, i.e.
-
addField
public static void addField(Component rootComponent, OdfContentDom contentDom, org.json.JSONArray start, String type, String representation, org.json.JSONObject attrs)
Currently all fields are being mapped to a common text field, i.e.
-
changeField
public static void changeField(Component rootComponent, OdfContentDom contentDom, org.json.JSONArray start, String type, String representation, org.json.JSONObject attrs)
Modify field at the given position
-
addDrawing
public static void addDrawing(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, String type, CollabTextDocument opsDoc) throws IndexOutOfBoundsException, org.json.JSONException
- Throws:
IndexOutOfBoundsException
org.json.JSONException
-
addTable
public static void addTable(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, org.json.JSONObject sizeExceeded, String tableName) throws IndexOutOfBoundsException
- Parameters:
rootComponent
- high level document structurepos
- position of the tableElement starting with 0 and one over the existing is allowed- Throws:
IndexOutOfBoundsException
- - if index is out of range (index < 0 || index > size()). One over size is allowed to append a tableElement.
-
addAnnotation
public static void addAnnotation(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, String id, String author, String date)
-
addNoteSelection
public static void addNoteSelection(Component rootComponent, org.json.JSONArray start, String type, String position, org.json.JSONObject attrs, String id)
-
modifyPages
public static void modifyPages(OdfDocument doc, org.json.JSONObject attrs)
Modifys the page layout (ie. 4 margins, width, height) for all master styles
-
addDeleteHeaderFooter
public static void addDeleteHeaderFooter(OdfDocument doc, boolean insert, String id)
-
setColumnsWidth
public static void setColumnsWidth(Component tableComponent, org.json.JSONArray start, org.json.JSONArray tableGrid, boolean isTextTable)
-
addColumns
public static void addColumns(Component rootComponent, org.json.JSONArray start, org.json.JSONArray tableGrid, Integer referenceColumnGridPosition, String insertMode)
Inserts cells for a new column into a tableElement. Copies styles from the existing referenced grid cell and might adjust the width of all new cells.- Parameters:
rootComponent
- high level document structurestart
- Integer[] The logical position of the tableElement the new column will be inserted into.referenceColumnGridPosition
- Integer Zero-based column index, according to the tableGrid attribute of the tableElement.tableGrid
- Integer[] The complete array of relative widths for the entire tableElement, containing the new entry for the new column. Will be set to the tableGrid attribute of the tableElement.insertMode
- String (optional) If set to 'before', the new cells will be inserted before the existing cells, otherwise after the cells. Default is 'before'. Note: As a side effect, this op changes the tableGrid attribute of the parentComponentElement tableElement.
-
addRows
public static void addRows(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, int count, boolean addDefaultCells, int referenceRow, boolean isTextTable) throws IndexOutOfBoundsException, org.json.JSONException
addRows Inserts one or more new rows into a tableElement.- Parameters:
name
- 'addRows'start
- The logical position of the new row. The row will be inserted before a row that is currently located at this position.count
- (optional) The number of rows that will be inserted, default is 1.addDefaultCells
- (optional) If true, empty cells will be inserted into the new row. The number of inserted cells will be equal to the number of columns in the tableElement, as specified by the tableGrid attribute of the tableElement. The default is false.referenceRow
- (optional) If specified, the zero-based index of the existing row whose cells and their attributes will be cloned (but without the cell contents).attrs
- (optional) Initial row attributes. See Table Row Formatting Attributes. Note: The attributes addDefaultCells and referenceRow are mutually exclusive.- Throws:
IndexOutOfBoundsException
org.json.JSONException
-
addCells
public static void addCells(Component rootComponent, org.json.JSONArray start, org.json.JSONObject attrs, int count, Component parentComponent, OdfElement newCellElement, boolean isTextTable) throws IndexOutOfBoundsException
- Throws:
IndexOutOfBoundsException
-
addElementAsComponent
public static Component addElementAsComponent(Component parentComponent, OdfElement newElement, int newPosition)
Adds the newElement to the parentComponent. Creating a component for newElement Repeating the above in the number of the given count Adding components for all children of newElement * Unfortunately sometimes there is trailing boilerplate elements, that HAVE to be at the end. No new components are allowed to be appended, e.g.
-
mapProperties
public static void mapProperties(OdfStyleFamily styleFamily, org.json.JSONObject attrs, OdfStyleBase style, OdfDocument doc)
-
mapCharacterProperties
public static void mapCharacterProperties(org.json.JSONObject attrs, StyleTextPropertiesElement propertiesElement, OdfDocument doc)
-
mapParagraphProperties
public static void mapParagraphProperties(org.json.JSONObject attrs, StyleParagraphPropertiesElement propertiesElement)
-
mapTableProperties
public static void mapTableProperties(org.json.JSONObject attrs, StyleTablePropertiesElement propertiesElement)
-
mapPageProperties
public static void mapPageProperties(org.json.JSONObject attrs, StylePageLayoutPropertiesElement propertiesElement)
-
mapRowProperties
public static void mapRowProperties(org.json.JSONObject attrs, StyleTableRowPropertiesElement propertiesElement)
-
mapCellProperties
public static void mapCellProperties(org.json.JSONObject attrs, StyleTableCellPropertiesElement propertiesElement)
-
mapColumnProperties
public static void mapColumnProperties(org.json.JSONObject attrs, StyleTableColumnPropertiesElement propertiesElement)
-
mapListProperties
public static void mapListProperties(org.json.JSONObject attrs, StyleListLevelPropertiesElement propertiesElement)
-
mapSectionProperties
public static void mapSectionProperties(org.json.JSONObject attrs, StyleSectionPropertiesElement propertiesElement)
-
mapGraphicProperties
public static void mapGraphicProperties(org.json.JSONObject attrs, StyleGraphicPropertiesElement propertiesElement, OdfStyleBase frameParentStyle)
-
mapChartProperties
public static void mapChartProperties(org.json.JSONObject attrs, StyleChartPropertiesElement propertiesElement)
-
mapDrawingProperties
public static void mapDrawingProperties(org.json.JSONObject attrs, StyleDrawingPagePropertiesElement propertiesElement)
-
mapRubyProperties
public static void mapRubyProperties(org.json.JSONObject attrs, StyleRubyPropertiesElement propertiesElement)
-
mapHeaderFooterProperties
public static void mapHeaderFooterProperties(org.json.JSONObject attrs, StyleHeaderFooterPropertiesElement propertiesElement)
-
addBorderProperties
public static void addBorderProperties(String key, org.json.JSONObject attrs, OdfStylePropertiesBase propertiesElement, OdfStyleBase frameParentStyle)
-
addPaddingProperties
public static void addPaddingProperties(String key, org.json.JSONObject attrs, OdfStylePropertiesBase propertiesElement)
-
-