Package org.jfree.xmlns.writer

Examples of org.jfree.xmlns.writer.XmlWriter


    // derive section style ..

    // This is a rather cheap solution to the problem. In a sane world, we would have to feed the
    // footer multiple times. Right now, we simply rely on the balacing, which should make sure that
    // the column's content are evenly distributed.
    final XmlWriter writer = getXmlWriter();
    final AttributeList attrs = new AttributeList();
    attrs.setAttribute(OfficeNamespaces.TEXT_NS, "style-name", generateSectionStyle(numberOfColumns));
    attrs.setAttribute(OfficeNamespaces.TEXT_NS, "name", sectionNames.generateName("Section"));
    writer.writeTag(OfficeNamespaces.TEXT_NS, "section", attrs, XmlWriterSupport.OPEN);
    for (int i = 0; i < numberOfColumns; i++)
    {
      writer.writeStream(contents.getXmlAsReader());
    }

    writer.writeCloseTag();
    return finishBuffering();
  }
View Full Code Here


  }

  protected void startContent(final AttributeMap attrs)
      throws IOException, DataSourceException, ReportProcessingException
  {
    final XmlWriter xmlWriter = getXmlWriter();
    xmlWriter.writeTag(OfficeNamespaces.OFFICE_NS, "text", null, XmlWriterSupport.OPEN);

    // now start the buffering. We have to insert the variables declaration
    // later ..
    startBuffering(getStylesCollection(), true);
View Full Code Here

    {
      startTable(attrs);
      return;
    }

    final XmlWriter xmlWriter = getXmlWriter();
    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table-row", attrs))
    {
      startRow(attrs);
      return;
    }

    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TEXT_NS, "variable-set", attrs))
    {
      // update the variables-declaration thingie ..
      final String varName = (String) attrs.getAttribute(OfficeNamespaces.TEXT_NS, "name");
      final String varType = (String) attrs.getAttribute(OfficeNamespaces.OFFICE_NS, "value-type");
      final String newVarName = variablesDeclarations.produceVariable(varName, varType);
      attrs.setAttribute(OfficeNamespaces.TEXT_NS, "name", newVarName);
    }
    else if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TEXT_NS, "variable-get", attrs))
    {
      final String varName = (String) attrs.getAttribute(OfficeNamespaces.TEXT_NS, "name");
      final String varType = (String) attrs.getAttribute(OfficeNamespaces.OFFICE_NS, "value-type");
      final String newVarName = variablesDeclarations.produceVariable(varName, varType);
      attrs.setAttribute(OfficeNamespaces.TEXT_NS, "name", newVarName);
      // this one must not be written, as the DTD does not declare it.
      // attrs.setAttribute(OfficeNamespaces.OFFICE_NS, "value-type", null);
    }

    if (tableLayoutConfig == TABLE_LAYOUT_VARIABLES_PARAGRAPH && variables != null)
    {
      // This cannot happen as long as the report sections only contain tables. But at some point in the
      // future they will be made of paragraphs, and then we are prepared ..
      // Log.debug("Variables-Section in own paragraph " + variables);

      StyleUtilities.copyStyle("paragraph",
          TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT, getStylesCollection(),
          getGlobalStylesCollection(), getPredefinedStylesCollection());
      xmlWriter.writeTag(OfficeNamespaces.TEXT_NS, "p", "style-name",
          TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT, XmlWriterSupport.OPEN);
      xmlWriter.writeText(variables);
      xmlWriter.writeCloseTag();
      variables = null;
    }

    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table-cell", attrs))
    {
      cellEmpty = true;
    }

    boolean keepTogetherOnParagraph = true;

    if (keepTogetherOnParagraph)
    {
      if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TEXT_NS, "p", attrs))
      {
        cellEmpty = false;
        if (firstCellSeen == false && sectionKeepTogether)
        {
          final String styleName = (String) attrs.getAttribute(OfficeNamespaces.TEXT_NS, "style-name");
          final OfficeStyle style = deriveStyle("paragraph", styleName);
          // Lets set the 'keep-together' flag..

          Element paragraphProps = style.getParagraphProperties();
          if (paragraphProps == null)
          {
            paragraphProps = new Section();
            paragraphProps.setNamespace(OfficeNamespaces.STYLE_NS);
            paragraphProps.setType("paragraph-properties");
            style.addNode(paragraphProps);
          }
          paragraphProps.setAttribute(OfficeNamespaces.FO_NS, "keep-together", "always");
          final int keepTogetherState = getCurrentContext().getKeepTogether();
          // We prevent pagebreaks within the two adjacent rows (this one and the next one) if
          // either a group-wide keep-together is defined or if we haven't reached the end of the
          // current section yet.
          if (keepTogetherState == PageContext.KEEP_TOGETHER_GROUP || expectedTableRowCount > 0)
          {
            paragraphProps.setAttribute(OfficeNamespaces.FO_NS, "keep-with-next", "always");
          }

          attrs.setAttribute(OfficeNamespaces.TEXT_NS, "style-name", style.getStyleName());
        }
      }
    }
    else
    {
      if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table-cell", attrs))
      {
        cellEmpty = false;
        if (firstCellSeen == false && sectionKeepTogether)
        {
          final String styleName = (String) attrs.getAttribute(OfficeNamespaces.TABLE_NS, "style-name");
          final OfficeStyle style = deriveStyle("table-cell", styleName);
          // Lets set the 'keep-together' flag..

          Element paragraphProps = style.getParagraphProperties();
          if (paragraphProps == null)
          {
            paragraphProps = new Section();
            paragraphProps.setNamespace(OfficeNamespaces.STYLE_NS);
            paragraphProps.setType("paragraph-properties");
            style.addNode(paragraphProps);
          }
          paragraphProps.setAttribute(OfficeNamespaces.FO_NS, "keep-together", "always");
          final int keepTogetherState = getCurrentContext().getKeepTogether();
          // We prevent pagebreaks within the two adjacent rows (this one and the next one) if
          // either a group-wide keep-together is defined or if we haven't reached the end of the
          // current section yet.
          if (keepTogetherState == PageContext.KEEP_TOGETHER_GROUP || expectedTableRowCount > 0)
          {
            paragraphProps.setAttribute(OfficeNamespaces.FO_NS, "keep-with-next", "always");
          }

          attrs.setAttribute(OfficeNamespaces.TABLE_NS, "style-name", style.getStyleName());
        }
      }
    }

    // process the styles as usual
    performStyleProcessing(attrs);

    final AttributeList attrList = buildAttributeList(attrs);
    xmlWriter.writeTag(namespace, elementType, attrList, XmlWriterSupport.OPEN);

    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TEXT_NS, "p", attrs))
    {
      cellEmpty = false;
      if (tableLayoutConfig != TABLE_LAYOUT_VARIABLES_PARAGRAPH)
      {
        if (variables != null)
        {
          //Log.debug("Variables-Section in existing cell " + variables);
          xmlWriter.writeText(variables);
          variables = null;
        }
      }
    }
View Full Code Here

        // If we have a manual pagebreak, then activate the current master-page again.
        masterPageName = currentMasterPage.getStyleName();
      }
    }

    final XmlWriter xmlWriter = getXmlWriter();
    if (detailBandProcessingState == DETAIL_SECTION_OTHER_PRINTED &&
        masterPageName != null)
    {
      // close the last table-tag, we will open a new one
      xmlWriter.writeCloseTag();
      // Reset the detail-state to 'started' so that the table's columns get printed now.
      detailBandProcessingState = DETAIL_SECTION_OTHER_STARTED;
    }

    if (tableLayoutConfig == TABLE_LAYOUT_VARIABLES_PARAGRAPH && variables != null)
    {
      if (masterPageName != null)
      {
        // write a paragraph that uses the VARIABLES_HIDDEN_STYLE as
        // primary style. Derive that one and add the manual pagebreak.
        // The predefined style already has the 'keep-together' flags set.
//        Log.debug("Variables-Section with new Master-Page " + variables + " " + masterPageName);

        final OfficeStyle style = deriveStyle("paragraph", TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT);
        style.setAttribute(OfficeNamespaces.STYLE_NS, "master-page-name", masterPageName);
        if (breakDefinition.isResetPageNumber())
        {
          final Element paragraphProps = produceFirstChild(style, OfficeNamespaces.STYLE_NS, "paragraph-properties");
          paragraphProps.setAttribute(OfficeNamespaces.STYLE_NS, "page-number", "1");
        }
        if (isColumnBreakPending())
        {
          final Element paragraphProps = produceFirstChild(style, OfficeNamespaces.STYLE_NS, "paragraph-properties");
          paragraphProps.setAttribute(OfficeNamespaces.FO_NS, "break-before", "column");
          setColumnBreakPending(false);
        }
        xmlWriter.writeTag(OfficeNamespaces.TEXT_NS, "p", "style-name", style.getStyleName(), XmlWriterSupport.OPEN);
        xmlWriter.writeText(variables);
        xmlWriter.writeCloseTag();
        variables = null;
        masterPageName = null;
        breakDefinition = null;
      }
      else if (isColumnBreakPending())
      {
        setColumnBreakPending(false);

        final OfficeStyle style = deriveStyle("paragraph", TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT);
        final Element paragraphProps = produceFirstChild(style, OfficeNamespaces.STYLE_NS, "paragraph-properties");
        paragraphProps.setAttribute(OfficeNamespaces.STYLE_NS, "page-number", "1");

        xmlWriter.writeTag(OfficeNamespaces.TEXT_NS, "p", "style-name", style.getStyleName(), XmlWriterSupport.OPEN);
        xmlWriter.writeText(variables);
        xmlWriter.writeCloseTag();
        variables = null;
      }
      else
      {
        // Write a paragraph without adding the pagebreak. We can reuse the global style, but we have to make
        // sure that the style is part of the current 'auto-style' collection.
//        Log.debug("Variables-Section " + variables);

        StyleUtilities.copyStyle("paragraph",
            TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT, getStylesCollection(),
            getGlobalStylesCollection(), getPredefinedStylesCollection());
        xmlWriter.writeTag(OfficeNamespaces.TEXT_NS, "p", "style-name",
            TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT, XmlWriterSupport.OPEN);
        xmlWriter.writeText(variables);
        xmlWriter.writeCloseTag();
        variables = null;
      }
    }

    final boolean keepWithNext = isKeepTableWithNext();
    final boolean localKeepTogether = "true".equals
        (attrs.getAttribute(OfficeNamespaces.OOREPORT_NS, "keep-together"));
    final boolean tableMergeActive = isTableMergeActive();
    if (tableMergeActive == false)
    {
      this.sectionKeepTogether = false;
    }
    else
    {
      this.sectionKeepTogether = localKeepTogether;
    }

    // Check, whether we have a reason to derive a style...
    if (masterPageName != null ||
        (tableMergeActive == false && (localKeepTogether || keepWithNext)) || isColumnBreakPending())
    {
      final String styleName = (String)
          attrs.getAttribute(OfficeNamespaces.TABLE_NS, "style-name");
      final OfficeStyle style = deriveStyle("table", styleName);

      if (masterPageName != null)
      {
//        Log.debug("Starting a new MasterPage: " + masterPageName);
        // Patch the current styles.
        // This usually only happens on Table-Styles or Paragraph-Styles
        style.setAttribute(OfficeNamespaces.STYLE_NS, "master-page-name", masterPageName);
        if (breakDefinition.isResetPageNumber())
        {
          final Element paragraphProps = produceFirstChild(style, OfficeNamespaces.STYLE_NS, "paragraph-properties");
          paragraphProps.setAttribute(OfficeNamespaces.STYLE_NS, "page-number", "1");
        }
      }
      if (isColumnBreakPending())
      {
        final Element paragraphProps = produceFirstChild(style, OfficeNamespaces.STYLE_NS, "paragraph-properties");
        paragraphProps.setAttribute(OfficeNamespaces.FO_NS, "break-before", "column");
        setColumnBreakPending(false);
      }

      // Inhibit breaks inside the table only if it has been defined and if we do not create one single
      // big detail section. In that case, this flag would be invalid and would cause layout-errors.
      if (tableMergeActive == false)
      {
        if (localKeepTogether)
        {
          final Element tableProps = produceFirstChild(style, OfficeNamespaces.STYLE_NS, "table-properties");
          tableProps.setAttribute(OfficeNamespaces.STYLE_NS, "may-break-between-rows", "false");
        }
      }
      else
      {
        if (detailBandProcessingState == DETAIL_SECTION_WAIT)
        {
          detailBandProcessingState = DETAIL_SECTION_FIRST_STARTED;
        }
        else if (detailBandProcessingState == DETAIL_SECTION_FIRST_PRINTED)
        {
          detailBandProcessingState = DETAIL_SECTION_OTHER_STARTED;
        }
      }
      if (keepWithNext)
      {
        final Element tableProps = produceFirstChild(style, OfficeNamespaces.STYLE_NS, "table-properties");
        tableProps.setAttribute(OfficeNamespaces.FO_NS, "keep-with-next", "always");
        // A keep-with-next does not work, if the may-break-betweek rows is not set to false ..
        tableProps.setAttribute(OfficeNamespaces.STYLE_NS, "may-break-between-rows", "false");
      }
      attrs.setAttribute(OfficeNamespaces.TABLE_NS, "style-name", style.getStyleName());
      // no need to copy the styles, this was done while deriving the
      // style ..
    }
    else
    {
      // Check, whether we may be able to skip the table.
      if (tableMergeActive)
      {
        if (detailBandProcessingState == DETAIL_SECTION_OTHER_PRINTED)
        {
          // Skip the whole thing ..
          return;
        }
        else if (detailBandProcessingState == DETAIL_SECTION_WAIT)
        {
          detailBandProcessingState = DETAIL_SECTION_FIRST_STARTED;
        }
        else if (detailBandProcessingState == DETAIL_SECTION_FIRST_PRINTED)
        {
          detailBandProcessingState = DETAIL_SECTION_OTHER_STARTED;
        }
      }

      // process the styles as usual
      performStyleProcessing(attrs);
    }

    final String namespace = ReportTargetUtil.getNamespaceFromAttribute(attrs);
    final String elementType = ReportTargetUtil.getElemenTypeFromAttribute(attrs);
    final AttributeList attrList = buildAttributeList(attrs);
    xmlWriter.writeTag(namespace, elementType, attrList, XmlWriterSupport.OPEN);
  }
View Full Code Here

      rootAttributes.addNamespaceDeclaration("office", OfficeNamespaces.OFFICE_NS);
      rootAttributes.addNamespaceDeclaration("config", OfficeNamespaces.CONFIG);
      rootAttributes.addNamespaceDeclaration("ooo", OfficeNamespaces.OO2004_NS);
      rootAttributes.setAttribute(OfficeNamespaces.OFFICE_NS, "version", "1.0");
      final OutputStream outputStream = getOutputRepository().createOutputStream("settings.xml","text/xml");
      final XmlWriter xmlWriter = new XmlWriter(new OutputStreamWriter(outputStream, "UTF-8"), createTagDescription());
      xmlWriter.setAlwaysAddNamespace(true);
      xmlWriter.writeXmlDeclaration("UTF-8");
      xmlWriter.writeTag(OfficeNamespaces.OFFICE_NS, "document-settings", rootAttributes, XmlWriterSupport.OPEN);
      xmlWriter.writeTag(OfficeNamespaces.OFFICE_NS, "settings", XmlWriterSupport.OPEN);
      xmlWriter.writeTag(OfficeNamespaces.CONFIG, "config-item-set", "name", "ooo:configuration-settings", XmlWriterSupport.OPEN);

      final AttributeList configAttributes = new AttributeList();
      configAttributes.setAttribute(OfficeNamespaces.CONFIG, "name", "TableRowKeep");
      configAttributes.setAttribute(OfficeNamespaces.CONFIG, "type", "boolean");
      xmlWriter.writeTag(OfficeNamespaces.CONFIG, "config-item", configAttributes, XmlWriterSupport.OPEN);
      xmlWriter.writeText("true");
      xmlWriter.writeCloseTag();

      xmlWriter.writeCloseTag();
      xmlWriter.writeCloseTag();
      xmlWriter.writeCloseTag();
      xmlWriter.close();
    }
    catch (IOException ioe)
    {
      throw new ReportProcessingException("Failed to write settings document");
    }
View Full Code Here

    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, "image", attrs))
    {
      return;
    }

    final XmlWriter xmlWriter = getXmlWriter();
    if (tableLayoutConfig != TABLE_LAYOUT_VARIABLES_PARAGRAPH &&
        ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table-cell", attrs))
    {
      if (variables != null)
      {
        // This cannot happen as long as the report sections only contain tables. But at some point in the
        // future they will be made of paragraphs, and then we are prepared ..
        //Log.debug("Variables-Section " + variables);
        if (sectionKeepTogether == true && expectedTableRowCount > 0)
        {
          StyleUtilities.copyStyle("paragraph",
              TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT, getStylesCollection(),
              getGlobalStylesCollection(), getPredefinedStylesCollection());
          xmlWriter.writeTag(OfficeNamespaces.TEXT_NS, "p", "style-name",
              TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT, XmlWriterSupport.OPEN);
          xmlWriter.writeText(variables);
          xmlWriter.writeCloseTag();
          variables = null;
        }
        else
        {
          StyleUtilities.copyStyle("paragraph",
              TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITHOUT_KEEPWNEXT, getStylesCollection(),
              getGlobalStylesCollection(), getPredefinedStylesCollection());
          xmlWriter.writeTag(OfficeNamespaces.TEXT_NS, "p", "style-name",
              TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITHOUT_KEEPWNEXT, XmlWriterSupport.OPEN);
          xmlWriter.writeText(variables);
          xmlWriter.writeCloseTag();
          variables = null;
        }
      }
      // Only generate the empty paragraph, if we have to add the keep-together ..
      else if (cellEmpty && expectedTableRowCount > 0 &&
          sectionKeepTogether == true && firstCellSeen == false)
      {
        // we have no variables ..
        StyleUtilities.copyStyle("paragraph",
            TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT, getStylesCollection(),
            getGlobalStylesCollection(), getPredefinedStylesCollection());
        xmlWriter.writeTag(OfficeNamespaces.TEXT_NS, "p", "style-name",
            TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT, XmlWriterSupport.CLOSE);
      }
    }

    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table-cell", attrs))
    {
      firstCellSeen = true;
    }
    else if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "covered-table-cell", attrs))
    {
      firstCellSeen = true;
    }

    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table", attrs))
    {
      if (getCurrentRole() == ROLE_DETAIL)
      {
        if (isTableMergeActive() == false)
        {
          // We do not merge the detail bands, so an ordinary close will do.
          xmlWriter.writeCloseTag();
        }
        else if (detailBandProcessingState == DETAIL_SECTION_FIRST_STARTED)
        {
          final int keepTogetherState = getCurrentContext().getKeepTogether();
          if (keepTogetherState == PageContext.KEEP_TOGETHER_FIRST_DETAIL)
          {
            xmlWriter.writeCloseTag();
            detailBandProcessingState = DETAIL_SECTION_FIRST_PRINTED;
          }
          else
          {
            detailBandProcessingState = DETAIL_SECTION_OTHER_PRINTED;
          }
        }
        else if (detailBandProcessingState == DETAIL_SECTION_OTHER_STARTED)
        {
          detailBandProcessingState = DETAIL_SECTION_OTHER_PRINTED;
        }
      }
      else
      {
        xmlWriter.writeCloseTag();
      }
      if (isSectionPagebreakAfter(attrs))
      {
        setPagebreakDefinition(new PageBreakDefinition(false));
      }
    }
    else
    {
      xmlWriter.writeCloseTag();
    }
  }
View Full Code Here

    if (tableLayoutConfig == TABLE_LAYOUT_SINGLE_DETAIL_TABLE)
    {
      if (detailBandProcessingState == DETAIL_SECTION_OTHER_PRINTED)
      {
        // closes the table ..
        final XmlWriter xmlWriter = getXmlWriter();
        xmlWriter.writeCloseTag();
        detailBandProcessingState = DETAIL_SECTION_WAIT;
      }
    }

  }
View Full Code Here

  protected void endContent(final AttributeMap attrs)
      throws IOException, DataSourceException, ReportProcessingException
  {
    finishSection();
    final BufferState bodyText = finishBuffering();
    final XmlWriter writer = getXmlWriter();

    final Map definedMappings = variablesDeclarations.getDefinedMappings();
    if (definedMappings.isEmpty() == false)
    {
      writer.writeTag(OfficeNamespaces.TEXT_NS, "variable-decls", XmlWriterSupport.OPEN);
      final Iterator mappingsIt = definedMappings.entrySet().iterator();
      while (mappingsIt.hasNext())
      {
        final Map.Entry entry = (Map.Entry) mappingsIt.next();
        final AttributeList entryList = new AttributeList();
        entryList.setAttribute(OfficeNamespaces.TEXT_NS, "name", (String) entry.getKey());
        entryList.setAttribute(OfficeNamespaces.OFFICE_NS, "value-type", (String) entry.getValue());
        writer.writeTag(OfficeNamespaces.TEXT_NS, "variable-decl", entryList, XmlWriterSupport.CLOSE);
      }
      writer.writeCloseTag();
    }

    writer.writeStream(bodyText.getXmlAsReader());
    writer.setLineEmpty(true);
    writer.writeCloseTag();
  }
View Full Code Here

  {
    final DefaultTagDescription tagDescription = new DefaultTagDescription();
    tagDescription.configure (JFreeReportBoot.getInstance().getGlobalConfig(),
        OfficeDocumentReportTarget.TAG_DEF_PREFIX);

    this.xmlWriter = new XmlWriter(writer, tagDescription);
    this.xmlWriter.setAlwaysAddNamespace(true);
    this.writeOpeningTag = true;
  }
View Full Code Here

        try
        {
            final OutputStream outputStream = outputRepository.createOutputStream(target, "text/xml");
            final Writer writer = new OutputStreamWriter(outputStream, "UTF-8");

            this.rootXmlWriter = new XmlWriter(writer, tagDescription);
            this.rootXmlWriter.setAlwaysAddNamespace(true);

            final AttributeList rootAttributes = new AttributeList();
            rootAttributes.addNamespaceDeclaration("office", OfficeNamespaces.OFFICE_NS);
            rootAttributes.addNamespaceDeclaration("style", OfficeNamespaces.STYLE_NS);
View Full Code Here

TOP

Related Classes of org.jfree.xmlns.writer.XmlWriter

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.