org.jhotdraw.samples.odg.io
Class ODGStylesReader

java.lang.Object
  extended by org.jhotdraw.samples.odg.io.ODGStylesReader

public class ODGStylesReader
extends java.lang.Object

ODGStylesReader reads an ODG <document-styles> element, and creates a map of AttributeKey's and values.

Version:
$Id: ODGStylesReader.java 585 2009-11-24 21:53:05Z rawcoder $
Author:
Werner Randelshofer

Nested Class Summary
private static class ODGStylesReader.Style
           
 
Field Summary
private  java.util.HashMap<java.lang.String,ODGStylesReader.Style> automaticStyles
          An automatic style contains formatting properties that, in the user interface view of a document, are assigned to an object such as a paragraph.
private  java.util.HashMap<java.lang.String,ODGStylesReader.Style> commonStyles
          Most office applications support styles within their user interface.
private static boolean DEBUG
           
private  java.util.HashMap<java.lang.String,ODGStylesReader.Style> masterStyles
          A master style is a common style that contains formatting information and additional content that is displayed with the document content when the style is applied.
 
Constructor Summary
ODGStylesReader()
          Creates a new instance.
 
Method Summary
 java.util.Map<AttributeKey,java.lang.Object> getAttributes(java.lang.String styleName, java.lang.String familyName)
           
 void read(java.io.File file)
          Reads a <document-styles> element from the specified XML file.
 void read(java.io.InputStream in)
          Reads a <document-styles> element from the specified input stream.
 void read(IXMLElement root)
          Reads a <document-styles> element from the specified XML element.
private  void readAutomaticStylesElement(IXMLElement elem)
          Reads a <automatic-styles> element from the specified XML element.
private  void readDefaultStyleElement(IXMLElement elem, java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
          Reads a <default-style> element from the specified XML element.
private  void readDocumentContentElement(IXMLElement elem)
          Reads a <document-content> element from the specified XML element.
private  void readDocumentStylesElement(IXMLElement elem)
          Reads a <document-styles> element from the specified XML element.
private  void readDrawingPagePropertiesElement(IXMLElement elem, java.util.HashMap<AttributeKey,java.lang.Object> a)
          Reads a <style:drawing-page-properties> element from the specified XML element.
private  void readGraphicPropertiesElement(IXMLElement elem, java.util.HashMap<AttributeKey,java.lang.Object> a)
          Reads a <style:graphic-properties> element from the specified XML element.
private  void readLayerSetElement(IXMLElement elem, java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
          Reads a <draw:layer-put> element from the specified XML element.
private  void readListStyleElement(IXMLElement elem, java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
          Reads a <text:list-style> element from the specified XML element.
private  void readMarkerElement(IXMLElement elem, java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
          Reads a <draw:marker> element from the specified XML element.
private  void readMasterPageElement(IXMLElement elem, java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
          Reads a <style:master-page> element from the specified XML element.
private  void readMasterStylesElement(IXMLElement elem)
          Reads a <master-styles> element from the specified XML element.
private  void readPageLayoutElement(IXMLElement elem, java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
          Reads a <style:page-layout> element from the specified XML element.
private  void readParagraphPropertiesElement(IXMLElement elem, java.util.HashMap<AttributeKey,java.lang.Object> a)
          Reads a <style:paragraph-properties> element from the specified XML element.
private  void readStyleElement(IXMLElement elem, java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
          Reads a <styles> element from the specified XML element.
private  void readStylesChildren(IXMLElement elem, java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
          Reads the children of a styles element.
private  void readStylesElement(IXMLElement elem)
          Reads a <styles> element from the specified XML element.
private  void readTextPropertiesElement(IXMLElement elem, java.util.HashMap<AttributeKey,java.lang.Object> a)
          Reads a <style:text-properties> element from the specified XML element.
private  void reset()
           
private  java.awt.Color toColor(java.lang.String value)
          Reads a color style attribute.
private  double toLength(java.lang.String str)
          Returns a value as a length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values

commonStyles

private java.util.HashMap<java.lang.String,ODGStylesReader.Style> commonStyles
Most office applications support styles within their user interface. Within this specification, the XML representations of such styles are referred to as styles. When a differentiation from the other types of styles is required, they are referred to as common styles. The term common indicates that this is the type of style that an office application user considers to be a style.


masterStyles

private java.util.HashMap<java.lang.String,ODGStylesReader.Style> masterStyles
A master style is a common style that contains formatting information and additional content that is displayed with the document content when the style is applied. An example of a master style are master pages. Master pages can be used in graphical applications. In this case, the additional content is any drawing shapes that are displayed as the background of the draw page. Master pages can also be used in text documents. In this case, the additional content is the headers and footers. Please note that the content that is contained within master styles is additional content that influences the representation of a document but does not change the content of a document.


automaticStyles

private java.util.HashMap<java.lang.String,ODGStylesReader.Style> automaticStyles
An automatic style contains formatting properties that, in the user interface view of a document, are assigned to an object such as a paragraph. The term automatic indicates that the style is generated automatically. In other words, formatting properties that are immediately assigned to a specific object are represented by an automatic style. This way, a separation of content and layout is achieved.

Constructor Detail

ODGStylesReader

public ODGStylesReader()
Creates a new instance.

Method Detail

getAttributes

public java.util.Map<AttributeKey,java.lang.Object> getAttributes(java.lang.String styleName,
                                                                  java.lang.String familyName)

read

public void read(java.io.File file)
          throws java.io.IOException
Reads a <document-styles> element from the specified XML file.

Parameters:
file - A XML file with a <document> root element or with a <document-styles> root element.
Throws:
java.io.IOException

read

public void read(java.io.InputStream in)
          throws java.io.IOException
Reads a <document-styles> element from the specified input stream.

Parameters:
in - A input stream with a <document> root element or with a <document-styles> root element.
Throws:
java.io.IOException

reset

private void reset()

read

public void read(IXMLElement root)
          throws java.io.IOException
Reads a <document-styles> element from the specified XML element.

Parameters:
root - A <document> element or a <document-styles> element.
Throws:
java.io.IOException

readDefaultStyleElement

private void readDefaultStyleElement(IXMLElement elem,
                                     java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
                              throws java.io.IOException
Reads a <default-style> element from the specified XML element.

A default style specifies default formatting properties for a certain style family. These defaults are used if a formatting property is neither specified by an automatic nor a common style. Default styles exist for all style families that are represented by the <style:style> element specified in section 14.1. Default styles are represented by the <style:default-style> element. The only attribute supported by this element is style:family. Its meaning equals the one of the same attribute for the <style:style> element, and the same properties child elements are supported depending on the style family.

Parameters:
elem - A <default-style> element.
styles - Style attributes to be filled in by this method.
Throws:
java.io.IOException

readDocumentContentElement

private void readDocumentContentElement(IXMLElement elem)
                                 throws java.io.IOException
Reads a <document-content> element from the specified XML element.

Parameters:
elem - A <document-content> element.
Throws:
java.io.IOException

readDocumentStylesElement

private void readDocumentStylesElement(IXMLElement elem)
                                throws java.io.IOException
Reads a <document-styles> element from the specified XML element.

The document-styles element contains all named styles of a document, along with the automatic styles needed for the named styles.

Parameters:
elem - A <document-styles> element.
Throws:
java.io.IOException

readDrawingPagePropertiesElement

private void readDrawingPagePropertiesElement(IXMLElement elem,
                                              java.util.HashMap<AttributeKey,java.lang.Object> a)
                                       throws java.io.IOException
Reads a <style:drawing-page-properties> element from the specified XML element.

Parameters:
elem - A <style:drawing-page-properties> element.
Throws:
java.io.IOException

readGraphicPropertiesElement

private void readGraphicPropertiesElement(IXMLElement elem,
                                          java.util.HashMap<AttributeKey,java.lang.Object> a)
                                   throws java.io.IOException
Reads a <style:graphic-properties> element from the specified XML element.

Parameters:
elem - A <style:graphic-properties> element.
Throws:
java.io.IOException

readStyleElement

private void readStyleElement(IXMLElement elem,
                              java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
                       throws java.io.IOException
Reads a <styles> element from the specified XML element.

The <style:style> element can represent paragraph, text, and graphic styles.

Parameters:
elem - A <style> element.
styles - Style attributes to be filled in by this method.
Throws:
java.io.IOException

readStylesElement

private void readStylesElement(IXMLElement elem)
                        throws java.io.IOException
Reads a <styles> element from the specified XML element.

The styles element contains common styles.

Parameters:
elem - A <styles> element.
Throws:
java.io.IOException

readStylesChildren

private void readStylesChildren(IXMLElement elem,
                                java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
                         throws java.io.IOException
Reads the children of a styles element.

Parameters:
elem - A <styles>, <automatic-styles>, <document-styles> or a <master-styles> element.
styles - Styles to be filled in by this method.
Throws:
java.io.IOException

readAutomaticStylesElement

private void readAutomaticStylesElement(IXMLElement elem)
                                 throws java.io.IOException
Reads a <automatic-styles> element from the specified XML element.

The automatic-styles element contains automatic styles.

Parameters:
elem - A <automatic-styles> element.
Throws:
java.io.IOException

readLayerSetElement

private void readLayerSetElement(IXMLElement elem,
                                 java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
                          throws java.io.IOException
Reads a <draw:layer-put> element from the specified XML element.

Parameters:
elem - A <layer-put> element.
styles - Style attributes to be filled in by this method.
Throws:
java.io.IOException

readListStyleElement

private void readListStyleElement(IXMLElement elem,
                                  java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
                           throws java.io.IOException
Reads a <text:list-style> element from the specified XML element.

Parameters:
elem - A <list-style> element.
styles - Style attributes to be filled in by this method.
Throws:
java.io.IOException

readMasterStylesElement

private void readMasterStylesElement(IXMLElement elem)
                              throws java.io.IOException
Reads a <master-styles> element from the specified XML element.

The master-styles element contains master styles.

Parameters:
elem - A <master-styles> element.
Throws:
java.io.IOException

readMarkerElement

private void readMarkerElement(IXMLElement elem,
                               java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
                        throws java.io.IOException
Reads a <draw:marker> element from the specified XML element.

The element <draw:marker> represents a marker, which is used to draw polygons at the start and end points of strokes. Markers are not available as automatic styles.

Parameters:
elem - A <master-styles> element.
styles - Style attributes to be filled in by this method.
Throws:
java.io.IOException

readMasterPageElement

private void readMasterPageElement(IXMLElement elem,
                                   java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
                            throws java.io.IOException
Reads a <style:master-page> element from the specified XML element.

Parameters:
elem - A <page-layout> element.
styles - Style attributes to be filled in by this method.
Throws:
java.io.IOException

readPageLayoutElement

private void readPageLayoutElement(IXMLElement elem,
                                   java.util.HashMap<java.lang.String,ODGStylesReader.Style> styles)
                            throws java.io.IOException
Reads a <style:page-layout> element from the specified XML element.

The <style:page-layout> element specifies the physical properties of a page. This element contains a <style:page-layout-properties> element which specifies the formatting properties of the page and two optional elements that specify the properties of headers and footers.

Parameters:
elem - A <page-layout> element.
styles - Style attributes to be filled in by this method.
Throws:
java.io.IOException

readParagraphPropertiesElement

private void readParagraphPropertiesElement(IXMLElement elem,
                                            java.util.HashMap<AttributeKey,java.lang.Object> a)
                                     throws java.io.IOException
Reads a <style:paragraph-properties> element from the specified XML element.

The properties described in this section can be contained within paragraph styles (see section 14.8.2), but also within other styles, like cell styles (see section 14.12.4) They are contained in a <style:paragraph-properties> element.

Parameters:
elem - A <paragraph-properties> element.
a - Style attributes to be filled in by this method.
Throws:
java.io.IOException

readTextPropertiesElement

private void readTextPropertiesElement(IXMLElement elem,
                                       java.util.HashMap<AttributeKey,java.lang.Object> a)
                                throws java.io.IOException
Reads a <style:text-properties> element from the specified XML element.

The properties described in this section can be contained within text styles (see section 14.8.1), but also within other styles, like paragraph styles (see section 14.8.2) or cell styles (see section 14.12.4) They are contained in a <style:text-properties> element.

Parameters:
elem - A <paragraph-properties> element.
a - Style attributes to be filled in by this method.
Throws:
java.io.IOException

toLength

private double toLength(java.lang.String str)
                 throws java.io.IOException
Returns a value as a length. <define name="length"> <data type="string"> <param name="pattern">-?([0-9]+(\.[0-9]*)?|\.[0-9]+)((cm)|(mm)|(in)| (pt)|(pc)|(px))</param>

Throws:
java.io.IOException

toColor

private java.awt.Color toColor(java.lang.String value)
                        throws java.io.IOException
Reads a color style attribute. <define name="color"> <data type="string"> <param name="pattern">#[0-9a-fA-F]{6}</param> </data> </define>

Throws:
java.io.IOException