@Override
    public void startElement(String uri, String localName, String qName, Attributes origAttrs)
        throws SAXException {
      // If we have an image tag, re-write the src attribute
      //  if required
      if ("img".equals(localName)) {
        AttributesImpl attrs;
        if (origAttrs instanceof AttributesImpl) {
          attrs = (AttributesImpl) origAttrs;
        } else {
          attrs = new AttributesImpl(origAttrs);
        }

        for (int i = 0; i < attrs.getLength(); i++) {
          if ("src".equals(attrs.getLocalName(i))) {
            String src = attrs.getValue(i);
            if (src.startsWith("embedded:")) {
              String newSrc = "";
              if (imageFolder != null) newSrc += imageFolder + "/";
              if (imagePrefix != null) newSrc += imagePrefix;
              newSrc += src.substring(src.indexOf(':') + 1);
              attrs.setValue(i, newSrc);
            }
          }
        }
        super.startElement(uri, localName, qName, attrs);
      } else {
        // For any other tag, pass through as-is
        super.startElement(uri, localName, qName, origAttrs);
      }
    }
  private void handleDuplicate(final String qName, final String value) {
    if (pageDirective) {
      if (IMPORT.equalsIgnoreCase(qName)) {
        // Always merge imports
        final int index = super.getIndex(IMPORT);
        super.setValue(index, super.getValue(index) + "," + value);
        return;
      } else if (PAGE_ENCODING.equalsIgnoreCase(qName)) {
        // Page encoding can only occur once per file so a second
        // attribute - even one with a duplicate value - is an error
        return;
      } else {
        // Other attributes can be repeated if and only if the values
        // are identical
        if (super.getValue(qName).equals(value)) {
          return;
        }
      }
    }

    // Ordinary tag attributes can't be repeated, even with identical values
    throw new IllegalArgumentException(
        MessageFormat.format(
            MessageUtil.getResourceString(this.getClass().getName() + ".err.illegalarg"), qName));
  }
Example #3
0
  /**
   * タグ内容部分出力処理。
   *
   * <OL>
   *   <LI>upperタグ書き込み
   *   <LI>lowerタグ書き込み
   * </OL>
   *
   * @param writer XMLライター
   * @throws SAXException XML出力例外
   */
  @Override
  protected void outputBody(XMLWriter writer) throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    String attName = AttributeType.EQ.toString();
    String elementName;

    // upperタグ書き込み
    elementName = ElementType.UPPER.toString();

    // アトリビュート情報のキー項目を初期化
    atts.addAttribute(
        PDSConstants.EMPTY.toString(),
        attName,
        attName,
        PDSConstants.CDATA.toString(),
        String.valueOf(upperFlg));

    writer.dataElement(elementName, atts, upper);

    // lowerタグ書き込み
    elementName = ElementType.LOWER.toString();

    atts.setValue(0, String.valueOf(lowerFlg));

    writer.dataElement(elementName, atts, lower);
  }
  /**
   * {@inheritDoc}
   *
   * @see org.xml.sax.helpers.XMLFilterImpl#startElement(java.lang.String, java.lang.String,
   *     java.lang.String, org.xml.sax.Attributes)
   */
  @Override
  public void startElement(String uri, String localName, String qName, Attributes attrs)
      throws SAXException {
    AttributesImpl attributes =
        (attrs instanceof AttributesImpl) ? (AttributesImpl) attrs : new AttributesImpl(attrs);

    int length = attributes.getLength();
    for (int i = 0; i < length; ++i) {
      attributes.setValue(i, this.replace(attributes.getValue(i)));
    }

    super.startElement(uri, localName, qName, attributes);
  }
Example #5
0
  /**
   * Append an attribute value to existing mutable attributes.
   *
   * @param attributes existing attributes
   * @param attributeName attribute name
   * @param attributeValue value to set or append
   */
  public static void addOrAppendToAttribute(
      AttributesImpl attributes, String attributeName, String attributeValue) {
    final int oldAttributeIndex = attributes.getIndex(attributeName);

    if (oldAttributeIndex == -1) {
      // No existing class attribute

      // Add
      attributes.addAttribute(
          "", attributeName, attributeName, ContentHandlerHelper.CDATA, attributeValue);
    } else {
      // Existing attribute
      final String oldAttributeValue = attributes.getValue(oldAttributeIndex);
      final String newAttributeValue = oldAttributeValue + ' ' + attributeValue;

      // Replace value
      attributes.setValue(oldAttributeIndex, newAttributeValue);
    }
  }