⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elementfactory.java

📁 Java的Web报表库
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  {
  }

  /**
   * Ends the image element and adds it to the current band.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endImageFunction() throws SAXException
  {
  }

  /**
   * Ends the image element and adds it to the current band.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endImageURLField() throws SAXException
  {
  }

  /**
   * Ends the image element and adds it to the current band.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endImageURLFunction() throws SAXException
  {
  }

  /**
   * Ends the image element and adds it to the current band.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endImageRef() throws SAXException
  {
  }

  /**
   * Ends the drawable element.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endDrawableField() throws SAXException
  {
  }

  /**
   * Creates a resource label element, an text element with an static datasource attached.
   *
   * @param attrs  the attributes.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void startResourceLabel(final Attributes attrs)
      throws SAXException
  {
    getTextElementAttributes(attrs);
    textElementNullString = ParserUtil.parseString(attrs.getValue(NULLSTRING_ATT), "-");
    resourceBase = attrs.getValue(RESOURCEBASE_ATTR);

    if (resourceBase == null)
    {
      final ReportConfiguration config = getReport().getReportConfiguration();
      resourceBase = config.getConfigProperty(ReportConfiguration.REPORT_RESOURCE_BUNDLE);
      if (resourceBase == null)
      {
        throw new SAXException("Resourcebase is not defined for this report. " +
            "Use the configuration key 'com.jrefinery.report.ResourceBundle' to define it.");
      }
    }

    clearCurrentText();
  }

  /**
   * Creates a resource field element.
   *
   * @param attrs  the attributes.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void startResourceField(final Attributes attrs)
      throws SAXException
  {
    getDataElementAttributes(attrs);
    resourceBase = attrs.getValue(RESOURCEBASE_ATTR);

    if (resourceBase == null)
    {
      final ReportConfiguration config = getReport().getReportConfiguration();
      resourceBase = config.getConfigProperty(ReportConfiguration.REPORT_RESOURCE_BUNDLE);
      if (resourceBase == null)
      {
        throw new SAXException("Resourcebase is not defined for this report. " +
            "Use the configuration key 'com.jrefinery.report.ResourceBundle' to define it.");
      }
    }
  }

  /**
   * Ends a resource label tag, sets the static key for the resource label,
   * which was build during the parsing. The label is added to the current band.
   */
  protected void endResourceLabel()
  {
    final TextElement te = ItemFactory.createResourceLabel(textElementName,
        textElementBounds,
        textElementColor,
        textElementAlignment,
        textElementVerticalAlignment,
        null,
        textElementNullString,
        resourceBase,
        getCurrentText());
    FontFactory.applyFontInformation(te.getStyle(), textElementFont);
    te.getStyle().setBooleanStyleProperty
        (ElementStyleSheet.DYNAMIC_HEIGHT, textElementDynamic);
    getCurrentBand().addElement(te);
  }

  /**
   * Ends the resource field and adds it to the current band.
   */
  protected void endResourceField()
  {
    final TextElement te = ItemFactory.createResourceElement(textElementName,
        textElementBounds,
        textElementColor,
        textElementAlignment,
        textElementVerticalAlignment,
        null,
        textElementNullString,
        resourceBase,
        textElementSourceName);
    FontFactory.applyFontInformation(te.getStyle(), textElementFont);
    te.getStyle().setBooleanStyleProperty
        (ElementStyleSheet.DYNAMIC_HEIGHT, textElementDynamic);
    getCurrentBand().addElement(te);
  }


  /**
   * Ends the multiline text element and adds it to the current band.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endMultilineField() throws SAXException
  {
    final TextElement te = ItemFactory.createStringElement(textElementName,
        textElementBounds,
        textElementColor,
        textElementAlignment,
        textElementVerticalAlignment,
        null,
        textElementNullString,
        textElementSourceName);
    FontFactory.applyFontInformation(te.getStyle(), textElementFont);
    te.getStyle().setBooleanStyleProperty
        (ElementStyleSheet.DYNAMIC_HEIGHT, textElementDynamic);
    getCurrentBand().addElement(te);
  }

  /**
   * Ends the String field and adds it to the current band.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endStringField() throws SAXException
  {
    final TextElement te = ItemFactory.createStringElement(textElementName,
        textElementBounds,
        textElementColor,
        textElementAlignment,
        textElementVerticalAlignment,
        null,
        textElementNullString,
        textElementSourceName);
    FontFactory.applyFontInformation(te.getStyle(), textElementFont);
    te.getStyle().setBooleanStyleProperty
        (ElementStyleSheet.DYNAMIC_HEIGHT, textElementDynamic);
    getCurrentBand().addElement(te);
  }

  /**
   * Ends the number field and adds it to the current band.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endNumberField() throws SAXException
  {
    final TextElement te = ItemFactory.createNumberElement(textElementName,
        textElementBounds,
        textElementColor,
        textElementAlignment,
        textElementVerticalAlignment,
        null,
        textElementNullString,
        textElementFormatString,
        textElementSourceName);
    FontFactory.applyFontInformation(te.getStyle(), textElementFont);
    te.getStyle().setBooleanStyleProperty
        (ElementStyleSheet.DYNAMIC_HEIGHT, textElementDynamic);
    getCurrentBand().addElement(te);
  }

  /**
   * Ends the date field and adds it to the current band.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endDateField() throws SAXException
  {
    final TextElement te = ItemFactory.createDateElement(textElementName,
        textElementBounds,
        textElementColor,
        textElementAlignment,
        textElementVerticalAlignment,
        null,
        textElementNullString,
        textElementFormatString,
        textElementSourceName);
    FontFactory.applyFontInformation(te.getStyle(), textElementFont);
    te.getStyle().setBooleanStyleProperty
        (ElementStyleSheet.DYNAMIC_HEIGHT, textElementDynamic);
    getCurrentBand().addElement(te);
  }

  /**
   * Ends the number function and adds it to the current band.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endNumberFunction() throws SAXException
  {
    final TextElement te = ItemFactory.createNumberElement(textElementName,
        textElementBounds,
        textElementColor,
        textElementAlignment,
        textElementVerticalAlignment,
        null,
        textElementNullString,
        textElementFormatString,
        textElementSourceName);
    FontFactory.applyFontInformation(te.getStyle(), textElementFont);
    te.getStyle().setBooleanStyleProperty
        (ElementStyleSheet.DYNAMIC_HEIGHT, textElementDynamic);
    getCurrentBand().addElement(te);
  }

  /**
   * Ends the string function and adds it to the current band.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endStringFunction() throws SAXException
  {
    final TextElement te = ItemFactory.createStringElement(textElementName,
        textElementBounds,
        textElementColor,
        textElementAlignment,
        textElementVerticalAlignment,
        null,
        textElementNullString,
        textElementSourceName);
    FontFactory.applyFontInformation(te.getStyle(), textElementFont);
    te.getStyle().setBooleanStyleProperty
        (ElementStyleSheet.DYNAMIC_HEIGHT, textElementDynamic);
    getCurrentBand().addElement(te);
  }

  /**
   * Ends the date function and adds it to the current band.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void endDateFunction() throws SAXException
  {
    final TextElement te = ItemFactory.createDateElement(textElementName,
        textElementBounds,
        textElementColor,
        textElementAlignment,
        textElementVerticalAlignment,
        null,
        textElementNullString,
        textElementFormatString,
        textElementSourceName);
    FontFactory.applyFontInformation(te.getStyle(), textElementFont);
    te.getStyle().setBooleanStyleProperty
        (ElementStyleSheet.DYNAMIC_HEIGHT, textElementDynamic);
    getCurrentBand().addElement(te);
  }

  /**
   * Reads the attributes that are base for all band-elements, as
   * name, x, y, width, height, font, fontstyle, fontsize and alignment.
   *
   * @param atts  the attributes.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void getTextElementAttributes(final Attributes atts) throws SAXException
  {
    this.textElementName = getNameGenerator().generateName(atts.getValue(NAME_ATT));
    this.textElementBounds = ParserUtil.getElementPosition(atts);
    this.textElementFont = fontFactory.createFont(atts);
    this.textElementAlignment = parseTextAlignment(atts.getValue(ALIGNMENT_ATT),
        ElementAlignment.LEFT.getOldAlignment());
    this.textElementVerticalAlignment = parseTextVerticalAlignment(atts.getValue(VALIGNMENT_ATT),
        ElementAlignment.BOTTOM.getOldAlignment());
    this.textElementColor = ParserUtil.parseColor(atts.getValue(COLOR_ATT));
    this.textElementDynamic = ParserUtil.parseBoolean(atts.getValue("dynamic"), false);
  }

  /**
   * Parses the text looking for a text alignment, which is one of "left", "center" or "right".
   * <p>
   * The method returns one of the values:  Element.LEFT, Element.CENTER and Element.RIGHT.
   *
   * @param alignment  the alignment.
   * @param defaultAlignment  the default alignment.
   *
   * @return an alignment code.
   */
  protected int parseTextAlignment(final String alignment, final int defaultAlignment)
  {
    int elementAlignment = defaultAlignment;
    if (alignment != null)
    {
      if (alignment.equals("left"))
      {
        elementAlignment = ElementAlignment.LEFT.getOldAlignment();
      }
      if (alignment.equals("center"))
      {
        elementAlignment = ElementAlignment.CENTER.getOldAlignment();
      }
      if (alignment.equals("right"))
      {
        elementAlignment = ElementAlignment.RIGHT.getOldAlignment();
      }
    }
    return elementAlignment;
  }

  /**
   * Parses the text looking for a text alignment, which is one of "top", "middle"/"center"
   * or "bottom".
   * <p>
   * The method returns one of the values:  Element.TOP, Element.BOTTOM and Element.MIDDLE.
   *
   * @param alignment  the alignment.
   * @param defaultAlignment  the default alignment.
   *
   * @return an alignment code.
   */
  protected int parseTextVerticalAlignment(final String alignment, final int defaultAlignment)
  {
    int elementAlignment = defaultAlignment;
    if (alignment != null)
    {
      if (alignment.equals("top"))
      {
        elementAlignment = ElementAlignment.TOP.getOldAlignment();
      }
      if ((alignment.equals("center")) || (alignment.equals("middle")))
      {
        elementAlignment = ElementAlignment.MIDDLE.getOldAlignment();
      }
      if (alignment.equals("bottom"))
      {
        elementAlignment = ElementAlignment.BOTTOM.getOldAlignment();
      }
    }
    return elementAlignment;
  }

  /**
   * Appends all data element relevant attributes to the data element parsed.
   *
   * @param atts  the attributes.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void getDataElementAttributes(final Attributes atts) throws SAXException
  {
    getTextElementAttributes(atts);
    textElementNullString = ParserUtil.parseString(atts.getValue(NULLSTRING_ATT), "-");
    textElementSourceName = atts.getValue(FIELDNAME_ATT);
    if (textElementSourceName == null)
    {
      throw new ParseException("The fieldname-attribute is required.", getLocator());
    }
  }

  /**
   * Appends all function element relevant attributes to the data element parsed.
   *
   * @param atts  the attributes.
   *
   * @throws SAXException if there is a SAX problem.
   */
  protected void getFunctionElementAttributes(final Attributes atts) throws SAXException
  {
    getTextElementAttributes(atts);
    textElementNullString = ParserUtil.parseString(atts.getValue(NULLSTRING_ATT), "-");
    textElementSourceName = atts.getValue(FUNCTIONNAME_ATT);
    if (textElementSourceName == null)
    {
      throw new ParseException("The function-attribute is required.", getLocator());
    }
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -