Package org.pentaho.reporting.engine.classic.core.modules.output.table.html.helper

Examples of org.pentaho.reporting.engine.classic.core.modules.output.table.html.helper.StyleBuilder


    this.contentGenerator = contentGenerator;
    this.processStack = new FastStack();
    this.metaData = metaData;
    this.xmlWriter = xmlWriter;
    this.styleManager = styleManager;
    this.styleBuilder = new StyleBuilder();
    this.characterEntityParser = HtmlCharacterEntities.getEntityParser();
    this.safariLengthFix = ("true".equals(ClassicEngineBoot.getInstance().getGlobalConfig().getConfigProperty
        ("org.pentaho.reporting.engine.classic.core.modules.output.table.html.SafariLengthHack")));
    this.useWhitespacePreWrap = ("true".equals(ClassicEngineBoot.getInstance().getGlobalConfig().getConfigProperty
        ("org.pentaho.reporting.engine.classic.core.modules.output.table.html.UseWhitespacePreWrap")));
View Full Code Here


            // Write image reference ..
            final AttributeList attrList = new AttributeList();
            attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, SRC_ATTR, name);
            attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, "border", "0");
            // width and height and scaling and so on ..
            final StyleBuilder imgStyle = produceImageStyle(node);
            if (imgStyle == null)
            {
              final AttributeList clipAttrList = new AttributeList();
              final StyleBuilder divStyle = produceClipStyle(node);
              styleManager.updateStyle(divStyle, clipAttrList);

              xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, DIV_TAG, clipAttrList, XmlWriter.OPEN);
              xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, IMG_TAG, attrList, XmlWriter.CLOSE);
              xmlWriter.writeCloseTag();
            }
            else
            {
              styleManager.updateStyle(imgStyle, attrList);
              xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, IMG_TAG, attrList, XmlWriter.CLOSE);
            }

            contentGenerator.registerContent(source, name);
            result = true;
            return;
          }
          else
          {
            // Mark this object as non-readable. This way we dont retry the failed operation
            // over and over again.
            contentGenerator.registerFailure(source);
          }
        }
        else
        {
          final String cachedName = contentGenerator.getRegisteredName(source);
          if (cachedName != null)
          {
            final AttributeList attrList = new AttributeList();
            attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, SRC_ATTR, cachedName);
            attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, "border", "0");
            // width and height and scaling and so on ..
            final StyleBuilder imgStyle = produceImageStyle(node);
            if (imgStyle == null)
            {
              final AttributeList clipAttrList = new AttributeList();
              final StyleBuilder divStyle = produceClipStyle(node);
              styleManager.updateStyle(divStyle, clipAttrList);

              xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, DIV_TAG, clipAttrList, XmlWriter.OPEN);
              xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, IMG_TAG, attrList, XmlWriter.CLOSE);
              xmlWriter.writeCloseTag();
            }
            else
            {
              styleManager.updateStyle(imgStyle, attrList);
              xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, IMG_TAG, attrList, XmlWriter.CLOSE);
            }
            result = true;
            return;
          }
        }
      }
    }

    // Fallback: (At the moment, we only support drawables and images.)
    final ReportAttributeMap attributes = node.getAttributes();
    if (rawObject instanceof ImageContainer)
    {
      final String type = RenderUtility.getEncoderType(attributes);
      final float quality = RenderUtility.getEncoderQuality(attributes);

      // Make it a PNG file ..
      //xmlWriter.writeComment("Image content source:" + source);
      final String name = contentGenerator.writeImage((ImageContainer) rawObject, type, quality, true);
      if (name != null)
      {
        // Write image reference ..
        final AttributeList attrList = new AttributeList();
        attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, SRC_ATTR, name);
        attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, "border", "0");
        final Object titleText = attributes.getAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.TITLE);
        if (titleText != null)
        {
          attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, TITLE_ATTR, String.valueOf(titleText));
        }

        final Object altText = attributes.getAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.ALT);
        if (altText != null)
        {
          attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, ALT_ATTR, String.valueOf(altText));
        }
        // width and height and scaling and so on ..
        final StyleBuilder imgStyle = produceImageStyle(node);
        if (imgStyle == null)
        {
          final AttributeList clipAttrList = new AttributeList();
          final StyleBuilder divStyle = produceClipStyle(node);
          styleManager.updateStyle(divStyle, clipAttrList);

          xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, DIV_TAG, clipAttrList, XmlWriterSupport.OPEN);
          xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, IMG_TAG, attrList, XmlWriterSupport.CLOSE);
          xmlWriter.writeCloseTag();
        }
        else
        {
          styleManager.updateStyle(imgStyle, attrList);
          xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, IMG_TAG, attrList, XmlWriterSupport.CLOSE);
        }
        result = true;
      }

      return;
    }

    if (rawObject instanceof DrawableWrapper)
    {
      // render it into an Buffered image and make it a PNG file.
      final DrawableWrapper drawable = (DrawableWrapper) rawObject;
      final StrictBounds cb = new StrictBounds(node.getX(), node.getY(), node.getWidth(), node.getHeight());
      final ImageContainer image = RenderUtility.createImageFromDrawable(drawable, cb, node,
          metaData);
      if (image == null)
      {
        //xmlWriter.writeComment("Drawable content [No image generated]:" + source);
        return;
      }

      final String type = RenderUtility.getEncoderType(attributes);
      final float quality = RenderUtility.getEncoderQuality(attributes);

      final String name = contentGenerator.writeImage(image, type, quality, true);
      if (name == null)
      {
        //xmlWriter.writeComment("Drawable content [No image written]:" + source);
        return;
      }

      //xmlWriter.writeComment("Drawable content:" + source);
      // Write image reference ..
      final ImageMap imageMap;
      final AttributeList attrList = new AttributeList();
      attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, SRC_ATTR, name);
      attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, "border", "0");

      final Object imageMapNameOverride = attributes.getAttribute
          (AttributeNames.Html.NAMESPACE, AttributeNames.Html.IMAGE_MAP_OVERRIDE);
      if (imageMapNameOverride != null)
      {
        attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, USEMAP_ATTR, String.valueOf(imageMapNameOverride));
        imageMap = null;
      }
      else
      {
        // only generate a image map, if the user does not specify their own onw via the override.
        // Of course, they would have to provide the map by other means as well.
        imageMap = RenderUtility.extractImageMap(node);

        if (imageMap != null)
        {
          final String mapName = imageMap.getAttribute(HtmlPrinter.XHTML_NAMESPACE, "name");
          if (mapName != null)
          {
            attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, USEMAP_ATTR, "#" + mapName);
          }
          else
          {
            final String generatedName = "generated_" + name + "_map"; //NON-NLS
            imageMap.setAttribute(HtmlPrinter.XHTML_NAMESPACE, "name", generatedName);
            //noinspection MagicCharacter
            attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, USEMAP_ATTR, '#' + generatedName);//NON-NLS
          }
        }
      }

      final Object titleText = attributes.getAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.TITLE);
      if (titleText != null)
      {
        attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, TITLE_ATTR, String.valueOf(titleText));
      }

      final Object altText = attributes.getAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.ALT);
      if (altText != null)
      {
        attrList.setAttribute(HtmlPrinter.XHTML_NAMESPACE, ALT_ATTR, String.valueOf(altText));
      }
      // width and height and scaling and so on ..
      final StyleBuilder imgStyle = produceImageStyle(node);
      if (imgStyle == null)
      {
        final AttributeList clipAttrList = new AttributeList();
        final StyleBuilder divStyle = produceClipStyle(node);
        styleManager.updateStyle(divStyle, clipAttrList);

        xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, DIV_TAG, clipAttrList, XmlWriterSupport.OPEN);
        xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, IMG_TAG, attrList, XmlWriterSupport.CLOSE);
        xmlWriter.writeCloseTag();
View Full Code Here

    }

    this.resourceManager = resourceManager;
    this.knownResources = new HashMap<ResourceKey, String>();
    this.knownImages = new HashMap<String, String>();
    this.styleBuilder = new StyleBuilder();

    this.validRawTypes = new HashSet<String>();
    this.validRawTypes.add("image/gif");
    this.validRawTypes.add("image/x-xbitmap");
    this.validRawTypes.add("image/gi_");
View Full Code Here

    {
      throw new NullPointerException();
    }
    if (styleBuilder == null)
    {
      styleBuilder = new StyleBuilder();
    }

    final StyleSheet styleSheet = box.getStyleSheet();
    final Color textColor = (Color) styleSheet.getStyleProperty(ElementStyleKeys.PAINT);
    final Color backgroundColor = (Color) styleSheet.getStyleProperty(ElementStyleKeys.BACKGROUND_COLOR);
View Full Code Here

        xmlWriter = writer.getXmlWriter();
      }

      final int colCount = sheetLayout.getColumnCount();
      final boolean emptyCellsUseCSS = getTagHelper().isEmptyCellsUseCSS();
      StyleBuilder styleBuilder = getStyleBuilder();
      DefaultStyleBuilderFactory styleBuilderFactory = getStyleBuilderFactory();

      if (textExtractor == null)
      {
        textExtractor = new HtmlTextExtractor(metaData, xmlWriter, contentGenerator, getTagHelper());
      }

      for (int row = startRow; row < finishRow; row++)
      {
        final int rowHeight = (int) StrictGeomUtility.toExternalValue(sheetLayout.getRowHeight(row));
        final HtmlRowBackgroundStruct struct = getCommonBackground(logicalPage, sheetLayout, row, contentProducer);
        xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "tr",
            getTagHelper().createRowAttributes(rowHeight, struct), XmlWriterSupport.OPEN);

        for (int col = 0; col < colCount; col++)
        {
          final RenderBox content = contentProducer.getContent(row, col);
          final CellMarker.SectionType sectionType = contentProducer.getSectionType(row, col);
          if (content == null)
          {
            final RenderBox backgroundBox = contentProducer.getBackground(row, col);
            final CellBackground background;
            if (backgroundBox != null)
            {
              background = cellBackgroundProducer.getBackgroundForBox
                  (logicalPage, sheetLayout, col, row, 1, 1, true, sectionType, backgroundBox);
            }
            else
            {
              background = cellBackgroundProducer.getBackgroundAt(logicalPage, sheetLayout, col, row, true, sectionType);
            }
            writeBackgroundCell(background, xmlWriter);
            continue;
          }

          if (content.isCommited() == false)
          {
            throw new InvalidReportStateException(
                "Uncommited content encountered: " + row + ", " + col + ' ' + content);
          }

          final long contentOffset = contentProducer.getContentOffset(row, col);

          final long colPos = sheetLayout.getXPosition(col);
          final long rowPos = sheetLayout.getYPosition(row);
          if (content.getX() != colPos || (content.getY() + contentOffset) != rowPos)
          {
            // A spanned cell ..
            if (content.isFinishedTable())
            {
              continue;
            }
          }

          final int colSpan = sheetLayout.getColSpan(col, content.getX() + content.getWidth());
          final int rowSpan = sheetLayout.getRowSpan(row, content.getY() + content.getHeight() + contentOffset);

          final CellBackground realBackground = cellBackgroundProducer.getBackgroundForBox
              (logicalPage, sheetLayout, col, row, colSpan, rowSpan, true, sectionType, content);

          final StyleBuilder cellStyle = styleBuilderFactory.createCellStyle(styleBuilder,
              content.getStyleSheet(), content.getBoxDefinition(), realBackground, null, null);
          final AttributeList cellAttributes = getTagHelper().createCellAttributes
              (colSpan, rowSpan, content.getAttributes(), content.getStyleSheet(), realBackground, cellStyle);
          xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "td", cellAttributes, XmlWriterSupport.OPEN);

          final Object rawContent = content.getAttributes().getAttribute(AttributeNames.Html.NAMESPACE,
              AttributeNames.Html.EXTRA_RAW_CONTENT);
          if (rawContent != null)
          {
            xmlWriter.writeText(String.valueOf(rawContent));
          }

          if (realBackground != null)
          {
            final String[] anchors = realBackground.getAnchors();
            for (int i = 0; i < anchors.length; i++)
            {
              final String anchor = anchors[i];
              xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "a", "name", anchor, XmlWriterSupport.CLOSE);
            }
          }

          if (Boolean.TRUE.equals(content.getAttributes().getAttribute(AttributeNames.Html.NAMESPACE,
              AttributeNames.Html.SUPPRESS_CONTENT)) == false)
          {
            // the style of the content-box itself is already contained in the <td> tag. So there is no need
            // to duplicate the style here
            if (textExtractor.performOutput(content, cellStyle.toArray()) == false)
            {
              if (emptyCellsUseCSS == false)
              {
                xmlWriter.writeText("&nbsp;");
              }
View Full Code Here

                                              final int row,
                                              final int col,
                                              final FastGridLayout.GridCell gridCell,
                                              final ReportElement content)
  {
    StyleBuilder styleBuilder = getStyleBuilder();
    DefaultStyleBuilderFactory styleBuilderFactory = getStyleBuilderFactory();
    FastHtmlStyleCache.CellStyle cellStyleCache = styleCache.getCellAttributes(row, col);
    if (cellStyleCache == null)
    {
      final CellBackground realBackground = gridCell.getLayoutInfo().getBackground();
      final int colSpan = gridCell.getLayoutInfo().getColumnSpan();
      final int rowSpan = gridCell.getLayoutInfo().getRowSpan();

      if (content == null)
      {
        final StyleBuilder cellStyle = styleBuilderFactory.createCellStyle(styleBuilder, realBackground, null, null);
        final AttributeList cellAttributes = getTagHelper().createCellAttributes
            (colSpan, rowSpan, null, null, realBackground, cellStyle);
        cellStyleCache = new FastHtmlStyleCache.CellStyle(cellAttributes, cellStyle.toArray());
      }
      else
      {
        BoxDefinition boxDefinition = boxDefinitionFactory.getBoxDefinition(content.getComputedStyle());
        final StyleBuilder cellStyle = styleBuilderFactory.createCellStyle(styleBuilder,
            content.getComputedStyle(), boxDefinition, realBackground, null, null);
        final AttributeList cellAttributes = getTagHelper().createCellAttributes
            (colSpan, rowSpan, content.getAttributes(), content.getComputedStyle(), realBackground, cellStyle);
        cellStyleCache = new FastHtmlStyleCache.CellStyle(cellAttributes, cellStyle.toArray());
      }
      styleCache.putCellAttributes(row, col, cellStyleCache);
    }
    return cellStyleCache;
  }
View Full Code Here

TOP

Related Classes of org.pentaho.reporting.engine.classic.core.modules.output.table.html.helper.StyleBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.