예제 #1
0
  /**
   * Searches for embedded tags in the AttributeSet and writes them out. It also stores these tags
   * in a vector so that when appropriate the corresponding end tags can be written out.
   *
   * @exception IOException on any I/O error
   */
  protected void writeEmbeddedTags(AttributeSet attr) throws IOException {

    // translate css attributes to html
    attr = convertToHTML(attr, oConvAttr);

    Enumeration names = attr.getAttributeNames();
    while (names.hasMoreElements()) {
      Object name = names.nextElement();
      if (name instanceof HTML.Tag) {
        HTML.Tag tag = (HTML.Tag) name;
        if (tag == HTML.Tag.FORM || tags.contains(tag)) {
          continue;
        }
        write('<');
        write(tag.toString());
        Object o = attr.getAttribute(tag);
        if (o != null && o instanceof AttributeSet) {
          writeAttributes((AttributeSet) o);
        }
        write('>');
        tags.addElement(tag);
        tagValues.addElement(o);
      }
    }
  }
예제 #2
0
 private void displayElements(Element el, int level) {
   for (int x = 0; x < level; x++) System.err.print("-");
   System.err.println();
   System.err.println("Element name " + el.getName());
   AttributeSet attrSet = el.getAttributes();
   Enumeration enumAttr = attrSet.getAttributeNames();
   while (enumAttr != null && enumAttr.hasMoreElements()) {
     System.err.println(" attr value " + enumAttr.nextElement().toString());
   }
   int childElemCt = el.getElementCount();
   for (int ix = 0; ix < childElemCt; ix++) {
     Element el1 = el.getElement(ix);
     displayElements(el1, ++level);
   }
 }
예제 #3
0
 /**
  * Copies the given AttributeSet to a new set, converting any CSS attributes found to arguments of
  * an HTML style attribute.
  */
 private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
   Enumeration keys = from.getAttributeNames();
   String value = "";
   while (keys.hasMoreElements()) {
     Object key = keys.nextElement();
     if (key instanceof CSS.Attribute) {
       value = value + " " + key + "=" + from.getAttribute(key) + ";";
     } else {
       to.addAttribute(key, from.getAttribute(key));
     }
   }
   if (value.length() > 0) {
     to.addAttribute(HTML.Attribute.STYLE, value);
   }
 }
예제 #4
0
  private void printAtribute(Element elem) {
    logger.debug("--------------------------------------------");
    logger.debug("Elemn name : " + elem.getName());
    AttributeSet as = elem.getAttributes();
    Enumeration e = as.getAttributeNames();
    while (e.hasMoreElements()) {
      Object key = e.nextElement();
      if (key != null) {
        System.out.print("  atrName : " + key.toString() + " , ");
        Object val = as.getAttribute(key);
        if (val != null) System.out.print(" atrVal : " + val.toString());

        logger.debug(" ");
      }
    }
    logger.debug("--------------------------------------------");
  }
예제 #5
0
  private Map<String, String> getAtributes(Element element, List<String> questionReadAtrib) {
    Map<String, String> foundAtrib = new HashMap<String, String>();

    AttributeSet as = element.getAttributes();
    Enumeration e = as.getAttributeNames();
    while (e.hasMoreElements()) {
      Object keyObj = e.nextElement();
      if (keyObj != null) {
        Object valObj = as.getAttribute(keyObj);
        if (valObj != null)
          if (questionReadAtrib.contains(String.valueOf(keyObj)))
            foundAtrib.put(String.valueOf(keyObj), String.valueOf(valObj));
      }
    }

    return foundAtrib;
  }
예제 #6
0
  /** @return - true got all atributes */
  private boolean isElementAtribOk(Element element, Map<String, String> searchAtrib) {
    List<String> found = new ArrayList<String>();
    // serach for all atrib from key list
    AttributeSet attributeSet = element.getAttributes();
    Enumeration e = attributeSet.getAttributeNames();
    while (e.hasMoreElements()) {
      Object keyObj = e.nextElement();
      if (keyObj != null)
        if (keyObj instanceof HTML.Attribute) {
          Object valObj = attributeSet.getAttribute(keyObj);
          if (valObj != null)
            if (searchAtrib.get(String.valueOf(keyObj)) != null) {
              String valAtr = searchAtrib.get(String.valueOf(keyObj));
              if (valObj.equals(valAtr)) found.add(String.valueOf(keyObj));
            }
        }
    }

    // chek if got all
    if (found.size() != 0) if (found.containsAll(searchAtrib.keySet())) return true;

    return false;
  }
예제 #7
0
  /**
   * Create an older style of HTML attributes. This will convert character level attributes that
   * have a StyleConstants mapping over to an HTML tag/attribute. Other CSS attributes will be
   * placed in an HTML style attribute.
   */
  private static void convertToHTML32(AttributeSet from, MutableAttributeSet to) {
    if (from == null) {
      return;
    }
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
      Object key = keys.nextElement();
      if (key instanceof CSS.Attribute) {
        if ((key == CSS.Attribute.FONT_FAMILY)
            || (key == CSS.Attribute.FONT_SIZE)
            || (key == CSS.Attribute.COLOR)) {

          createFontAttribute((CSS.Attribute) key, from, to);
        } else if (key == CSS.Attribute.FONT_WEIGHT) {
          // add a bold tag is weight is bold
          CSS.FontWeight weightValue =
              (CSS.FontWeight) from.getAttribute(CSS.Attribute.FONT_WEIGHT);
          if ((weightValue != null) && (weightValue.getValue() > 400)) {
            addAttribute(to, HTML.Tag.B, SimpleAttributeSet.EMPTY);
          }
        } else if (key == CSS.Attribute.FONT_STYLE) {
          String s = from.getAttribute(key).toString();
          if (s.indexOf("italic") >= 0) {
            addAttribute(to, HTML.Tag.I, SimpleAttributeSet.EMPTY);
          }
        } else if (key == CSS.Attribute.TEXT_DECORATION) {
          String decor = from.getAttribute(key).toString();
          if (decor.indexOf("underline") >= 0) {
            addAttribute(to, HTML.Tag.U, SimpleAttributeSet.EMPTY);
          }
          if (decor.indexOf("line-through") >= 0) {
            addAttribute(to, HTML.Tag.STRIKE, SimpleAttributeSet.EMPTY);
          }
        } else if (key == CSS.Attribute.VERTICAL_ALIGN) {
          String vAlign = from.getAttribute(key).toString();
          if (vAlign.indexOf("sup") >= 0) {
            addAttribute(to, HTML.Tag.SUP, SimpleAttributeSet.EMPTY);
          }
          if (vAlign.indexOf("sub") >= 0) {
            addAttribute(to, HTML.Tag.SUB, SimpleAttributeSet.EMPTY);
          }
        } else if (key == CSS.Attribute.TEXT_ALIGN) {
          addAttribute(to, HTML.Attribute.ALIGN, from.getAttribute(key).toString());
        } else {
          // default is to store in a HTML style attribute
          if (value.length() > 0) {
            value = value + "; ";
          }
          value = value + key + ": " + from.getAttribute(key);
        }
      } else {
        Object attr = from.getAttribute(key);
        if (attr instanceof AttributeSet) {
          attr = ((AttributeSet) attr).copyAttributes();
        }
        addAttribute(to, key, attr);
      }
    }
    if (value.length() > 0) {
      to.addAttribute(HTML.Attribute.STYLE, value);
    }
  }