Package org.jfree.xmlns.writer

Examples of org.jfree.xmlns.writer.XmlWriter


  {
    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


    documentContentItem = contentLocation.createItem
        (contentNameGenerator.generateName(null, "text/html"));
    final OutputStream out = documentContentItem.getOutputStream();

    final OutputStreamWriter writer = new OutputStreamWriter(out, encoding);
    xmlWriter = new XmlWriter(writer, tagDescription);
    xmlWriter.setAlwaysAddNamespace(false);
    xmlWriter.setAssumeDefaultNamespace(true);

    if (generateFragment == false)
    {
View Full Code Here

  {
    try
    {
      final OutputStreamWriter osw =
          new OutputStreamWriter(outputStream, encoding);
      final XmlWriter writer = new XmlWriter(osw);
      writer.writeXmlDeclaration(encoding);
      return new XmlPrintReportTarget(job, writer);
    }
    catch (IOException e)
    {
      throw new ReportProcessingException("Failed to create writer", e);
View Full Code Here

    final OutputStream manifestOutputStream =
        outputRepository.createOutputStream("META-INF/manifest.xml", "text/xml");

    final OutputStreamWriter writer = new OutputStreamWriter(manifestOutputStream, "UTF-8");
    final XmlWriter xmlWriter = new XmlWriter(writer, tagDescription);
    xmlWriter.setAlwaysAddNamespace(true);
    xmlWriter.writeXmlDeclaration("UTF-8");

    final AttributeList rootAttributes = new AttributeList();
    rootAttributes.addNamespaceDeclaration("manifest", MANIFEST_NS);
    xmlWriter.writeTag(MANIFEST_NS, "manifest", rootAttributes, XmlWriterSupport.OPEN);

    final Iterator iterator = entries.entrySet().iterator();
    while (iterator.hasNext())
    {
      final Map.Entry entry = (Map.Entry) iterator.next();
      final AttributeList entryAttrs = new AttributeList();
      entryAttrs.setAttribute(MANIFEST_NS, "media-type", (String) entry.getValue());
      entryAttrs.setAttribute(MANIFEST_NS, "full-path", (String) entry.getKey());
      xmlWriter.writeTag(MANIFEST_NS, "file-entry", entryAttrs, XmlWriterSupport.CLOSE);
    }

    xmlWriter.writeCloseTag();
    xmlWriter.close();
  }
View Full Code Here

    documentContentItem = contentLocation.createItem
        (contentNameGenerator.generateName(null, "text/html"));
    final OutputStream out = documentContentItem.getOutputStream();

    final OutputStreamWriter writer = new OutputStreamWriter(out, encoding);
    xmlWriter = new XmlWriter(writer, tagDescription);
    xmlWriter.setAlwaysAddNamespace(false);
    xmlWriter.setAssumeDefaultNamespace(true);

    if (generateFragment == false)
    {
View Full Code Here

  {
    try
    {
      final OutputStreamWriter osw =
          new OutputStreamWriter(outputStream, encoding);
      final XmlWriter writer = new XmlWriter(osw);
      writer.writeXmlDeclaration(encoding);
      return new XmlPrintReportTarget(job, writer);
    }
    catch (IOException e)
    {
      throw new ReportProcessingException("Failed to create writer", e);
View Full Code Here

    // 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

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.