Class 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 Detail

      • JsonOperationConsumer

        public JsonOperationConsumer()
    • Method Detail

      • 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 structure
        paraPos - 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 structure
        paraPos - 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.
      • 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 changes
        newElement - the element the style changes will be applied to
        ownerDocument - 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
      • 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 moved
        the - the new destination
      • 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 structure
        start - 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)
      • 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
      • 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 structure
        pos - 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 structure
        start - 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
      • 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.
      • mapTableProperties

        public static void mapTableProperties​(org.json.JSONObject attrs,
                                              StyleTablePropertiesElement propertiesElement)
      • mapSectionProperties

        public static void mapSectionProperties​(org.json.JSONObject attrs,
                                                StyleSectionPropertiesElement propertiesElement)
      • mapChartProperties

        public static void mapChartProperties​(org.json.JSONObject attrs,
                                              StyleChartPropertiesElement propertiesElement)
      • mapRubyProperties

        public static void mapRubyProperties​(org.json.JSONObject attrs,
                                             StyleRubyPropertiesElement propertiesElement)
      • getColor

        public static String getColor​(org.json.JSONObject color,
                                      String autoColor)
      • addPaddingProperties

        public static void addPaddingProperties​(String key,
                                                org.json.JSONObject attrs,
                                                OdfStylePropertiesBase propertiesElement)