public CSSValue createValue(StyleKey name, LexicalUnit value) {
    if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      String ident = value.getStringValue();
      if (ident.equalsIgnoreCase("auto")) {
        return CSSAutoValue.getInstance();
      }
      final PageSize ps = PageSizeFactory.getInstance().getPageSizeByName(ident);
      if (ps == null) {
        return null;
      }

      value = value.getNextLexicalUnit();
      int pageOrientation = PageFormat.PORTRAIT;
      if (value != null) {
        if (value.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
          return null;
        }

        if (value.getStringValue().equalsIgnoreCase("landscape")) {
          pageOrientation = PageFormat.LANDSCAPE;
        } else if (value.getStringValue().equalsIgnoreCase("reverse-landscape")) {
          pageOrientation = PageFormat.REVERSE_LANDSCAPE;
        } else if (value.getStringValue().equalsIgnoreCase("portrait")) {
          pageOrientation = PageFormat.PORTRAIT;
        } else {
          return null;
        }
      }

      if (pageOrientation == PageFormat.LANDSCAPE
          || pageOrientation == PageFormat.REVERSE_LANDSCAPE) {
        return new CSSValuePair(
            CSSNumericValue.createPtValue(ps.getHeight()),
            CSSNumericValue.createPtValue(ps.getWidth()));
      } else {
        return new CSSValuePair(
            CSSNumericValue.createPtValue(ps.getWidth()),
            CSSNumericValue.createPtValue(ps.getHeight()));
      }
    } else {
      final CSSNumericValue horizontalWidth = (CSSNumericValue) parseWidth(value);
      if (horizontalWidth == null) {
        return null;
      }

      value = value.getNextLexicalUnit();

      final CSSNumericValue verticalWidth;
      if (value == null) {
        verticalWidth = horizontalWidth;
      } else {
        verticalWidth = (CSSNumericValue) parseWidth(value);
        if (verticalWidth == null) {
          return null;
        }
      }

      return new CSSValuePair(horizontalWidth, verticalWidth);
    }
  }
 public TextDecorationWidthResolveHandler() {
   addValue(BorderWidth.THIN, CSSNumericValue.createValue(CSSNumericType.PT, 0.5));
   addValue(BorderWidth.MEDIUM, CSSNumericValue.createValue(CSSNumericType.PT, 1));
   addValue(BorderWidth.THICK, CSSNumericValue.createValue(CSSNumericType.PT, 1.5));
   addValue(TextDecorationWidth.DASH, CSSNumericValue.createValue(CSSNumericType.PT, 0.75));
   addValue(TextDecorationWidth.BOLD, CSSNumericValue.createValue(CSSNumericType.PT, 1.25));
   setFallback(CSSNumericValue.ZERO_LENGTH);
 }
  protected CSSValue parseFirstPosition(final LexicalUnit value) {
    if (value == null) {
      return null;
    }

    if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      if ("left".equalsIgnoreCase(value.getStringValue())) {
        return LEFT;
      } else if ("center".equalsIgnoreCase(value.getStringValue())) {
        return CENTER;
      } else if ("right".equalsIgnoreCase(value.getStringValue())) {
        return RIGHT;
      } else if ("top".equalsIgnoreCase(value.getStringValue())) {
        return TOP;
      } else if ("bottom".equalsIgnoreCase(value.getStringValue())) {
        return BOTTOM;
      }

      // ignore this rule.
      return null;
    }

    if (value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE) {
      return CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, value.getFloatValue());
    }
    if (CSSValueFactory.isLengthValue(value)) {
      return CSSValueFactory.createLengthValue(value);
    }
    // contains errors, we ignore this rule.
    return null;
  }
  private CSSValue parseSingleSpacingValue(final LexicalUnit value) {
    if (value == null) {
      return null;
    }

    if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      if (value.getStringValue().equalsIgnoreCase("normal")) {
        return SpacingLimitReadHandler.NORMAL;
      }
      return null;
    }
    if (value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE) {
      return CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, value.getFloatValue());
    }

    return CSSValueFactory.createLengthValue(value);
  }
  public void testPieExplodePercentStyle() throws Exception {
    final ChartDocumentContext cdc =
        ChartFactory.generateChart(
            getClass().getResource("PieExplodePercentStyleTest.xml")); // $NON-NLS-1$
    final ChartDocument cd = cdc.getChartDocument();
    assertNotNull(cd);
    final ChartElement element = cd.getRootElement();
    assertNotNull(element);

    final CSSNumericValue[] passValues =
        new CSSNumericValue[] {
          CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, 0), // $NON-NLS-1$
          CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, 100), // $NON-NLS-1$
          CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, 75), // $NON-NLS-1$
          CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, 5), // $NON-NLS-1$
          CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, 0), // $NON-NLS-1$
          CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, 0), // $NON-NLS-1$
        };

    int counter = 0;
    final int lenArray = passValues.length;
    ChartElement child = element.getFirstChildItem();

    while (child != null) {
      final LayoutStyle layoutStyle = child.getLayoutStyle();
      assertNotNull(layoutStyle);
      System.out.println(
          "Expected: "
              + passValues[counter]
              + " - Got: "
              + layoutStyle.getValue(
                  ChartStyleKeys.PIE_EXPLODE_PERCENT)); // $NON-NLS-1$ //$NON-NLS-2$
      assertEquals(
          passValues[counter++].getCSSText(),
          layoutStyle.getValue(ChartStyleKeys.PIE_EXPLODE_PERCENT).getCSSText());
      child = child.getNextItem();
    }

    if (counter < lenArray - 1) {
      throw new IllegalStateException("Not all tests covered!"); // $NON-NLS-1$
    }
  }
/**
 * Creation-Date: 27.11.2005, 21:48:44
 *
 * @author Thomas Morgner
 */
public class FitPositionReadHandler extends OneOfConstantsReadHandler {
  public static final CSSNumericValue CENTER =
      CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, 50);
  public static final CSSNumericValue TOP =
      CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, 0);
  public static final CSSNumericValue LEFT =
      CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, 0);
  public static final CSSNumericValue BOTTOM =
      CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, 100);
  public static final CSSNumericValue RIGHT =
      CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, 100);

  public FitPositionReadHandler() {
    super(false);
  }

  public CSSValue createValue(StyleKey name, LexicalUnit value) {
    if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      final String stringValue = value.getStringValue();
      if (stringValue.equalsIgnoreCase("auto")) {
        return CSSAutoValue.getInstance();
      }
    }

    final CSSValue firstPosition = parseFirstPosition(value);
    if (firstPosition == null) {
      return null;
    }

    value = value.getNextLexicalUnit();
    final CSSValue secondPosition = parseSecondPosition(value, firstPosition);
    if (secondPosition == null) {
      return null;
    }

    return createResultList(firstPosition, secondPosition);
  }

  protected CSSValue parseFirstPosition(final LexicalUnit value) {
    if (value == null) {
      return null;
    }

    if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      if ("left".equalsIgnoreCase(value.getStringValue())) {
        return LEFT;
      } else if ("center".equalsIgnoreCase(value.getStringValue())) {
        return CENTER;
      } else if ("right".equalsIgnoreCase(value.getStringValue())) {
        return RIGHT;
      } else if ("top".equalsIgnoreCase(value.getStringValue())) {
        return TOP;
      } else if ("bottom".equalsIgnoreCase(value.getStringValue())) {
        return BOTTOM;
      }

      // ignore this rule.
      return null;
    }

    if (value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE) {
      return CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, value.getFloatValue());
    }
    if (CSSValueFactory.isLengthValue(value)) {
      return CSSValueFactory.createLengthValue(value);
    }
    // contains errors, we ignore this rule.
    return null;
  }

  protected CSSValuePair createResultList(CSSValue firstPosition, CSSValue secondPosition) {
    if (firstPosition == TOP || firstPosition == BOTTOM) {
      return new CSSValuePair(secondPosition, firstPosition);
    } else if (secondPosition == LEFT || secondPosition == RIGHT) {
      return new CSSValuePair(secondPosition, firstPosition);
    } else {
      return new CSSValuePair(firstPosition, secondPosition);
    }
  }

  protected CSSValue parseSecondPosition(final LexicalUnit value, final CSSValue firstValue) {
    if (value == null) {
      return CENTER;
    }
    if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      if ("left".equalsIgnoreCase(value.getStringValue())) {
        return LEFT;
      } else if ("center".equalsIgnoreCase(value.getStringValue())) {
        return CENTER;
      } else if ("right".equalsIgnoreCase(value.getStringValue())) {
        return RIGHT;
      } else if ("top".equalsIgnoreCase(value.getStringValue())) {
        return TOP;
      } else if ("bottom".equalsIgnoreCase(value.getStringValue())) {
        return BOTTOM;
      }
      return null; // ignore this rule, it contains errors.
    }
    if (value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE) {
      return CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, value.getFloatValue());
    } else if (CSSValueFactory.isLengthValue(value)) {
      return CSSValueFactory.createLengthValue(value);
    }
    return CENTER;
  }
}