@Test public void testStartParsing() { StringWriter stringWriter = new StringWriter(); XmlWriter writer = new XmlWriter( stringWriter ); writer.addImpliedNamespace( "http: ElementStyleSheet sheet = new ElementStyleSheet(); sheet.setBooleanStyleProperty( TextStyleKeys.WORDBREAK, false ); try { StyleWriterUtility.writeTextStyles( writer, sheet ); } catch (IOException e) { e.printStackTrace(); Assert.fail(); } String res = stringWriter.toString().replace( "\r", "" ).replace( "\n", "" ); Assert.assertEquals( "<rep:text-styles word-break=\"false\"/>", res ); }
public static void writeTextStyles( final XmlWriter writer, final ElementStyleSheet style ) throws IOException { if ( writer == null ) { throw new NullPointerException(); } if ( style == null ) { throw new NullPointerException(); } final AttributeList bandStyleAtts = new AttributeList(); if ( style.isLocalKey( TextStyleKeys.FONT ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-face", value ); } if ( style.isLocalKey( TextStyleKeys.BOLD ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.BOLD ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "bold", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.ITALIC ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.ITALIC ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "italic", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.EMBEDDED_FONT ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.EMBEDDED_FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "embedded", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.UNDERLINED ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.UNDERLINED ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "underline", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.STRIKETHROUGH ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.STRIKETHROUGH ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "strikethrough", String.valueOf( value ) ); } if ( style.isLocalKey( ElementStyleKeys.EXCEL_WRAP_TEXT ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.EXCEL_WRAP_TEXT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "excel-text-wrapping", String.valueOf( value ) ); } if ( style.isLocalKey( ElementStyleKeys.EXCEL_INDENTION ) ) { final int value = style.getIntStyleProperty( ElementStyleKeys.EXCEL_INDENTION, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "excel-text-indention", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.TRIM_TEXT_CONTENT ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.TRIM_TEXT_CONTENT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "trim-text-content", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.FONTENCODING ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.FONTENCODING ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "encoding", value ); } if ( style.isLocalKey( TextStyleKeys.RESERVED_LITERAL ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.RESERVED_LITERAL ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "ellipsis", value ); } if ( style.isLocalKey( TextStyleKeys.FONTSIZE ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.FONTSIZE, 0 ); if ( value > 0 ) { bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-size", String.valueOf( value ) ); } } if ( style.isLocalKey( TextStyleKeys.LINEHEIGHT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.LINEHEIGHT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "line-height", formatLength( value ) ); } if ( style.isLocalKey( TextStyleKeys.WORD_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.WORD_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "word-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_MIN_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_MIN_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "min-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_OPTIMUM_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_OPTIMUM_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "optimum-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_MAX_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_MAX_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "max-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.FONT_SMOOTH ) ) { final Object value = style.getStyleProperty( TextStyleKeys.FONT_SMOOTH ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-smooth", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.TEXT_WRAP ) ) { final Object value = style.getStyleProperty( TextStyleKeys.TEXT_WRAP ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "text-wrap", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.WORDBREAK ) ) { final Object value = style.getStyleProperty( TextStyleKeys.WORDBREAK ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "word-break", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.DIRECTION ) ) { final Object value = style.getStyleProperty( TextStyleKeys.DIRECTION ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "direction", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.WHITE_SPACE_COLLAPSE ) ) { final Object value = style.getStyleProperty( TextStyleKeys.WHITE_SPACE_COLLAPSE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "whitespace-collapse", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.VERTICAL_TEXT_ALIGNMENT ) ) { final Object value = style.getStyleProperty( TextStyleKeys.VERTICAL_TEXT_ALIGNMENT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "whitespace-collapse", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.TEXT_INDENT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.TEXT_INDENT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "text-indent", formatFloat( value ) ); } if ( style.isLocalKey( TextStyleKeys.FIRST_LINE_INDENT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.FIRST_LINE_INDENT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "first-line-indent", formatFloat( value ) ); } if ( bandStyleAtts.isEmpty() == false ) { writer.writeTag( BundleNamespaces.STYLE, "text-styles", bandStyleAtts, XmlWriterSupport.CLOSE ); } }
StyleWriterUtility { public static void writeTextStyles( final XmlWriter writer, final ElementStyleSheet style ) throws IOException { if ( writer == null ) { throw new NullPointerException(); } if ( style == null ) { throw new NullPointerException(); } final AttributeList bandStyleAtts = new AttributeList(); if ( style.isLocalKey( TextStyleKeys.FONT ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-face", value ); } if ( style.isLocalKey( TextStyleKeys.BOLD ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.BOLD ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "bold", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.ITALIC ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.ITALIC ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "italic", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.EMBEDDED_FONT ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.EMBEDDED_FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "embedded", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.UNDERLINED ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.UNDERLINED ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "underline", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.STRIKETHROUGH ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.STRIKETHROUGH ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "strikethrough", String.valueOf( value ) ); } if ( style.isLocalKey( ElementStyleKeys.EXCEL_WRAP_TEXT ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.EXCEL_WRAP_TEXT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "excel-text-wrapping", String.valueOf( value ) ); } if ( style.isLocalKey( ElementStyleKeys.EXCEL_INDENTION ) ) { final int value = style.getIntStyleProperty( ElementStyleKeys.EXCEL_INDENTION, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "excel-text-indention", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.TRIM_TEXT_CONTENT ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.TRIM_TEXT_CONTENT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "trim-text-content", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.FONTENCODING ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.FONTENCODING ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "encoding", value ); } if ( style.isLocalKey( TextStyleKeys.RESERVED_LITERAL ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.RESERVED_LITERAL ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "ellipsis", value ); } if ( style.isLocalKey( TextStyleKeys.FONTSIZE ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.FONTSIZE, 0 ); if ( value > 0 ) { bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-size", String.valueOf( value ) ); } } if ( style.isLocalKey( TextStyleKeys.LINEHEIGHT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.LINEHEIGHT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "line-height", formatLength( value ) ); } if ( style.isLocalKey( TextStyleKeys.WORD_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.WORD_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "word-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_MIN_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_MIN_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "min-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_OPTIMUM_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_OPTIMUM_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "optimum-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_MAX_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_MAX_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "max-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.FONT_SMOOTH ) ) { final Object value = style.getStyleProperty( TextStyleKeys.FONT_SMOOTH ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-smooth", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.TEXT_WRAP ) ) { final Object value = style.getStyleProperty( TextStyleKeys.TEXT_WRAP ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "text-wrap", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.WORDBREAK ) ) { final Object value = style.getStyleProperty( TextStyleKeys.WORDBREAK ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "word-break", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.DIRECTION ) ) { final Object value = style.getStyleProperty( TextStyleKeys.DIRECTION ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "direction", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.WHITE_SPACE_COLLAPSE ) ) { final Object value = style.getStyleProperty( TextStyleKeys.WHITE_SPACE_COLLAPSE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "whitespace-collapse", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.VERTICAL_TEXT_ALIGNMENT ) ) { final Object value = style.getStyleProperty( TextStyleKeys.VERTICAL_TEXT_ALIGNMENT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "whitespace-collapse", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.TEXT_INDENT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.TEXT_INDENT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "text-indent", formatFloat( value ) ); } if ( style.isLocalKey( TextStyleKeys.FIRST_LINE_INDENT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.FIRST_LINE_INDENT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "first-line-indent", formatFloat( value ) ); } if ( bandStyleAtts.isEmpty() == false ) { writer.writeTag( BundleNamespaces.STYLE, "text-styles", bandStyleAtts, XmlWriterSupport.CLOSE ); } } }
StyleWriterUtility { public static void writeTextStyles( final XmlWriter writer, final ElementStyleSheet style ) throws IOException { if ( writer == null ) { throw new NullPointerException(); } if ( style == null ) { throw new NullPointerException(); } final AttributeList bandStyleAtts = new AttributeList(); if ( style.isLocalKey( TextStyleKeys.FONT ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-face", value ); } if ( style.isLocalKey( TextStyleKeys.BOLD ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.BOLD ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "bold", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.ITALIC ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.ITALIC ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "italic", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.EMBEDDED_FONT ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.EMBEDDED_FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "embedded", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.UNDERLINED ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.UNDERLINED ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "underline", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.STRIKETHROUGH ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.STRIKETHROUGH ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "strikethrough", String.valueOf( value ) ); } if ( style.isLocalKey( ElementStyleKeys.EXCEL_WRAP_TEXT ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.EXCEL_WRAP_TEXT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "excel-text-wrapping", String.valueOf( value ) ); } if ( style.isLocalKey( ElementStyleKeys.EXCEL_INDENTION ) ) { final int value = style.getIntStyleProperty( ElementStyleKeys.EXCEL_INDENTION, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "excel-text-indention", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.TRIM_TEXT_CONTENT ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.TRIM_TEXT_CONTENT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "trim-text-content", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.FONTENCODING ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.FONTENCODING ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "encoding", value ); } if ( style.isLocalKey( TextStyleKeys.RESERVED_LITERAL ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.RESERVED_LITERAL ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "ellipsis", value ); } if ( style.isLocalKey( TextStyleKeys.FONTSIZE ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.FONTSIZE, 0 ); if ( value > 0 ) { bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-size", String.valueOf( value ) ); } } if ( style.isLocalKey( TextStyleKeys.LINEHEIGHT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.LINEHEIGHT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "line-height", formatLength( value ) ); } if ( style.isLocalKey( TextStyleKeys.WORD_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.WORD_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "word-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_MIN_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_MIN_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "min-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_OPTIMUM_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_OPTIMUM_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "optimum-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_MAX_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_MAX_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "max-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.FONT_SMOOTH ) ) { final Object value = style.getStyleProperty( TextStyleKeys.FONT_SMOOTH ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-smooth", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.TEXT_WRAP ) ) { final Object value = style.getStyleProperty( TextStyleKeys.TEXT_WRAP ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "text-wrap", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.WORDBREAK ) ) { final Object value = style.getStyleProperty( TextStyleKeys.WORDBREAK ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "word-break", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.DIRECTION ) ) { final Object value = style.getStyleProperty( TextStyleKeys.DIRECTION ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "direction", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.WHITE_SPACE_COLLAPSE ) ) { final Object value = style.getStyleProperty( TextStyleKeys.WHITE_SPACE_COLLAPSE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "whitespace-collapse", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.VERTICAL_TEXT_ALIGNMENT ) ) { final Object value = style.getStyleProperty( TextStyleKeys.VERTICAL_TEXT_ALIGNMENT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "whitespace-collapse", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.TEXT_INDENT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.TEXT_INDENT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "text-indent", formatFloat( value ) ); } if ( style.isLocalKey( TextStyleKeys.FIRST_LINE_INDENT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.FIRST_LINE_INDENT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "first-line-indent", formatFloat( value ) ); } if ( bandStyleAtts.isEmpty() == false ) { writer.writeTag( BundleNamespaces.STYLE, "text-styles", bandStyleAtts, XmlWriterSupport.CLOSE ); } } private  StyleWriterUtility(); }
StyleWriterUtility { public static void writeTextStyles( final XmlWriter writer, final ElementStyleSheet style ) throws IOException { if ( writer == null ) { throw new NullPointerException(); } if ( style == null ) { throw new NullPointerException(); } final AttributeList bandStyleAtts = new AttributeList(); if ( style.isLocalKey( TextStyleKeys.FONT ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-face", value ); } if ( style.isLocalKey( TextStyleKeys.BOLD ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.BOLD ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "bold", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.ITALIC ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.ITALIC ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "italic", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.EMBEDDED_FONT ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.EMBEDDED_FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "embedded", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.UNDERLINED ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.UNDERLINED ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "underline", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.STRIKETHROUGH ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.STRIKETHROUGH ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "strikethrough", String.valueOf( value ) ); } if ( style.isLocalKey( ElementStyleKeys.EXCEL_WRAP_TEXT ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.EXCEL_WRAP_TEXT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "excel-text-wrapping", String.valueOf( value ) ); } if ( style.isLocalKey( ElementStyleKeys.EXCEL_INDENTION ) ) { final int value = style.getIntStyleProperty( ElementStyleKeys.EXCEL_INDENTION, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "excel-text-indention", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.TRIM_TEXT_CONTENT ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.TRIM_TEXT_CONTENT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "trim-text-content", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.FONTENCODING ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.FONTENCODING ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "encoding", value ); } if ( style.isLocalKey( TextStyleKeys.RESERVED_LITERAL ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.RESERVED_LITERAL ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "ellipsis", value ); } if ( style.isLocalKey( TextStyleKeys.FONTSIZE ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.FONTSIZE, 0 ); if ( value > 0 ) { bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-size", String.valueOf( value ) ); } } if ( style.isLocalKey( TextStyleKeys.LINEHEIGHT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.LINEHEIGHT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "line-height", formatLength( value ) ); } if ( style.isLocalKey( TextStyleKeys.WORD_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.WORD_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "word-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_MIN_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_MIN_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "min-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_OPTIMUM_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_OPTIMUM_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "optimum-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_MAX_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_MAX_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "max-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.FONT_SMOOTH ) ) { final Object value = style.getStyleProperty( TextStyleKeys.FONT_SMOOTH ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-smooth", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.TEXT_WRAP ) ) { final Object value = style.getStyleProperty( TextStyleKeys.TEXT_WRAP ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "text-wrap", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.WORDBREAK ) ) { final Object value = style.getStyleProperty( TextStyleKeys.WORDBREAK ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "word-break", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.DIRECTION ) ) { final Object value = style.getStyleProperty( TextStyleKeys.DIRECTION ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "direction", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.WHITE_SPACE_COLLAPSE ) ) { final Object value = style.getStyleProperty( TextStyleKeys.WHITE_SPACE_COLLAPSE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "whitespace-collapse", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.VERTICAL_TEXT_ALIGNMENT ) ) { final Object value = style.getStyleProperty( TextStyleKeys.VERTICAL_TEXT_ALIGNMENT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "whitespace-collapse", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.TEXT_INDENT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.TEXT_INDENT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "text-indent", formatFloat( value ) ); } if ( style.isLocalKey( TextStyleKeys.FIRST_LINE_INDENT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.FIRST_LINE_INDENT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "first-line-indent", formatFloat( value ) ); } if ( bandStyleAtts.isEmpty() == false ) { writer.writeTag( BundleNamespaces.STYLE, "text-styles", bandStyleAtts, XmlWriterSupport.CLOSE ); } } private  StyleWriterUtility(); static void writeStyleRule( final String namespace, final String tagName, final XmlWriter writer,
      final ElementStyleSheet style ); static void writeBorderStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeSpatialStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeTextStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeContentStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeCommonStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writePageBandStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeBandStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeRotationStyles( final XmlWriter writer, final ElementStyleSheet style ); }
StyleWriterUtility { public static void writeTextStyles( final XmlWriter writer, final ElementStyleSheet style ) throws IOException { if ( writer == null ) { throw new NullPointerException(); } if ( style == null ) { throw new NullPointerException(); } final AttributeList bandStyleAtts = new AttributeList(); if ( style.isLocalKey( TextStyleKeys.FONT ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-face", value ); } if ( style.isLocalKey( TextStyleKeys.BOLD ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.BOLD ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "bold", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.ITALIC ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.ITALIC ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "italic", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.EMBEDDED_FONT ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.EMBEDDED_FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "embedded", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.UNDERLINED ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.UNDERLINED ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "underline", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.STRIKETHROUGH ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.STRIKETHROUGH ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "strikethrough", String.valueOf( value ) ); } if ( style.isLocalKey( ElementStyleKeys.EXCEL_WRAP_TEXT ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.EXCEL_WRAP_TEXT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "excel-text-wrapping", String.valueOf( value ) ); } if ( style.isLocalKey( ElementStyleKeys.EXCEL_INDENTION ) ) { final int value = style.getIntStyleProperty( ElementStyleKeys.EXCEL_INDENTION, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "excel-text-indention", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.TRIM_TEXT_CONTENT ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.TRIM_TEXT_CONTENT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "trim-text-content", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.FONTENCODING ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.FONTENCODING ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "encoding", value ); } if ( style.isLocalKey( TextStyleKeys.RESERVED_LITERAL ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.RESERVED_LITERAL ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "ellipsis", value ); } if ( style.isLocalKey( TextStyleKeys.FONTSIZE ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.FONTSIZE, 0 ); if ( value > 0 ) { bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-size", String.valueOf( value ) ); } } if ( style.isLocalKey( TextStyleKeys.LINEHEIGHT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.LINEHEIGHT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "line-height", formatLength( value ) ); } if ( style.isLocalKey( TextStyleKeys.WORD_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.WORD_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "word-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_MIN_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_MIN_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "min-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_OPTIMUM_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_OPTIMUM_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "optimum-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.X_MAX_LETTER_SPACING ) ) { final int value = style.getIntStyleProperty( TextStyleKeys.X_MAX_LETTER_SPACING, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "max-letter-spacing", String.valueOf( value ) ); } if ( style.isLocalKey( TextStyleKeys.FONT_SMOOTH ) ) { final Object value = style.getStyleProperty( TextStyleKeys.FONT_SMOOTH ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-smooth", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.TEXT_WRAP ) ) { final Object value = style.getStyleProperty( TextStyleKeys.TEXT_WRAP ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "text-wrap", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.WORDBREAK ) ) { final Object value = style.getStyleProperty( TextStyleKeys.WORDBREAK ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "word-break", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.DIRECTION ) ) { final Object value = style.getStyleProperty( TextStyleKeys.DIRECTION ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "direction", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.WHITE_SPACE_COLLAPSE ) ) { final Object value = style.getStyleProperty( TextStyleKeys.WHITE_SPACE_COLLAPSE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "whitespace-collapse", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.VERTICAL_TEXT_ALIGNMENT ) ) { final Object value = style.getStyleProperty( TextStyleKeys.VERTICAL_TEXT_ALIGNMENT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "whitespace-collapse", value.toString() ); } if ( style.isLocalKey( TextStyleKeys.TEXT_INDENT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.TEXT_INDENT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "text-indent", formatFloat( value ) ); } if ( style.isLocalKey( TextStyleKeys.FIRST_LINE_INDENT ) ) { final double value = style.getDoubleStyleProperty( TextStyleKeys.FIRST_LINE_INDENT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "first-line-indent", formatFloat( value ) ); } if ( bandStyleAtts.isEmpty() == false ) { writer.writeTag( BundleNamespaces.STYLE, "text-styles", bandStyleAtts, XmlWriterSupport.CLOSE ); } } private  StyleWriterUtility(); static void writeStyleRule( final String namespace, final String tagName, final XmlWriter writer,
      final ElementStyleSheet style ); static void writeBorderStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeSpatialStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeTextStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeContentStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeCommonStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writePageBandStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeBandStyles( final XmlWriter writer, final ElementStyleSheet style ); static void writeRotationStyles( final XmlWriter writer, final ElementStyleSheet style );  }