/**
   * Creates a new <code>DOMStatusDetail</code> by parsing the given <code>Node</code> representing
   * a XACML StatusDetail element.
   *
   * @param nodeStatusDetail the <code>Node</code> representing the StatusDetail element
   * @return a new <code>DOMStatusDetail</code> parsed from the given <code>Node</code>
   * @throws DOMStructureException if the conversion cannot be made
   */
  public static StatusDetail newInstance(Node nodeStatusDetail) throws DOMStructureException {
    Element elementStatusDetail = DOMUtil.getElement(nodeStatusDetail);
    boolean bLenient = DOMProperties.isLenient();

    StdMutableStatusDetail mutableStatusDetail = new StdMutableStatusDetail();

    NodeList children = elementStatusDetail.getChildNodes();
    int numChildren;
    if (children != null && (numChildren = children.getLength()) > 0) {
      for (int i = 0; i < numChildren; i++) {
        Node child = children.item(i);
        if (DOMUtil.isElement(child)) {
          if (DOMUtil.isInNamespace(child, XACML3.XMLNS)
              && XACML3.ELEMENT_MISSINGATTRIBUTEDETAIL.equals(child.getLocalName())) {
            mutableStatusDetail.addMissingAttributeDetail(
                DOMMissingAttributeDetail.newInstance(child));
          } else {
            if (!bLenient) {
              throw DOMUtil.newUnexpectedElementException(child, nodeStatusDetail);
            }
          }
        }
      }
    }

    return new StdStatusDetail(mutableStatusDetail);
  }
 private void next(String name) throws NoSuchElementException {
   switch (state) {
     case STATE_BEFORE:
       // We are before the first sibling => go to first sibling.
       state = STATE_AT;
       break;
     case STATE_AT:
       // We are at a sibling => go to next sibling if any,
       //                        go after current if current is the last.
       Element t = DOMUtil.nextSiblingElement(__current);
       if (t != null) {
         __current = t;
       } else {
         // Changed 20011001: should never go STATE_AFTER, all calls
         // to next are followed by a call to current() which will then throw
         // an exception =>
         // TODO: remove STATE_AFTER completely
         // state = STATE_AFTER;
         throw new NoSuchElementException("No more sibling elements.");
       }
       break;
     case STATE_AFTER:
       // We are after the last sibling => this method call is "illegal".
       throw new NoSuchElementException("No more sibling elements.");
     case STATE_IN_EMPTY_SET:
       // We in the child set of an element without children => this method call is "illegal".
       throw new NoSuchElementException("No elements.");
     default:
       throw new RuntimeException("Illegal state.");
   }
   if (name != null && !name.equals(DOMUtil.getLocalName(__current))) {
     throw new NoSuchElementException(
         "Not at element " + name + ": " + __current.getNodeName() + ".");
   }
 }
  /**
   * Check if the next sibling of <a href="#last">&quot;last visited element&quot;</a> has local
   * name <code><i>name</i></code> (and if exists at all).
   *
   * @return true iff the <a href="#last">&quot;last visited element&quot;</a> has more siblings,
   *     and the next sibling has local name <code><i>name</i></code>.
   */
  public boolean hasNext(String name) {
    Element next =
        (state == STATE_BEFORE)
            ? __current
            : (state == STATE_AT) ? DOMUtil.nextSiblingElement(__current) : null;

    return next != null && DOMUtil.getLocalName(next).equals(name);
  }
Exemple #4
0
  /**
   * Gets the property name of this particle.
   *
   * @return always a non-null, valid string.
   */
  public final String getPropertyName() {
    String r = DOMUtil.getAttribute(element, "property");

    // in case of <element-ref>, @property is optional and
    // defaults to @name.
    // in all other cases, @property is mandatory.
    if (r != null) return r;
    return DOMUtil.getAttribute(element, "name");
  }
Exemple #5
0
 private void internalSetReference(Widget reference) {
   // this.reference = reference;
   if (reference == null || reference == RootPanel.get()) {
     referenceAdjustLeft = 0;
     referenceAdjustTop = 0;
   } else {
     referenceAdjustLeft =
         reference.getAbsoluteLeft() + DOMUtil.getBorderLeft(reference.getElement());
     referenceAdjustTop =
         reference.getAbsoluteTop() + DOMUtil.getBorderTop(reference.getElement());
   }
 }
  private String text(String name) throws NoSuchElementException {
    was_CDATA = false;
    Element t = current();

    NodeList l = t.getChildNodes();

    if (name != null && !name.equals(DOMUtil.getLocalName(t))) {
      throw new NoSuchElementException("Not at element " + name + ": " + t.getNodeName() + ".");
    }

    if (l.getLength() == 0) {
      return null;
    }
    StringBuffer s = new StringBuffer();
    was_CDATA = true;
    for (int i = 0; i < l.getLength(); i++) {
      Node n = l.item(i);
      short nt = n.getNodeType();
      if (nt != Node.TEXT_NODE && nt != Node.CDATA_SECTION_NODE) {
        throw new NoSuchElementException("Not at a Text/CDATA element: " + t.getNodeName() + ".");
      }
      if (nt == Node.TEXT_NODE) {
        was_CDATA = false;
      }
      s.append(n.getNodeValue());
    }
    return s.toString();
  }
  public WidgetArea(Widget widget, Widget reference) {
    setLeft(widget.getAbsoluteLeft());
    setTop(widget.getAbsoluteTop());

    if (reference != null) {
      setLeft(
          getLeft() - reference.getAbsoluteLeft() - DOMUtil.getBorderLeft(reference.getElement()));
      setTop(getTop() - reference.getAbsoluteTop() - DOMUtil.getBorderTop(reference.getElement()));
    }
    setRight(getLeft() + widget.getOffsetWidth());
    setBottom(getTop() + widget.getOffsetHeight());

    Element elem = widget.getElement().getOffsetParent();
    Element p;

    while (elem != null && (p = elem.getOffsetParent()) != null) {
      int left = elem.getAbsoluteLeft();

      if (getLeft() < left) {
        setLeft(left);
      }

      int top = elem.getAbsoluteTop();
      if (getTop() < top) {
        setTop(top);
      }

      int bottom = top + elem.getOffsetHeight();
      if (getBottom() > bottom) {
        setBottom(bottom);
      }

      int right = left + elem.getOffsetWidth();
      if (getRight() > right) {
        setRight(right);
      }

      elem = p;
    }
  }
Exemple #8
0
  /**
   * Gets the realization of this particle, if any.
   *
   * @return null if the "collection" attribute was not specified.
   */
  public final FieldRenderer getRealization() {
    String v = DOMUtil.getAttribute(element, "collection");
    if (v == null) return null;

    v = v.trim();
    if (v.equals("array")) return opts.getFieldRendererFactory().getArray();
    if (v.equals("list"))
      return opts.getFieldRendererFactory().getList(parent.parent.codeModel.ref(ArrayList.class));

    // the correctness of the attribute value must be
    // checked by the validator.
    throw new InternalError("unexpected collection value: " + v);
  }
Exemple #9
0
  /**
   * Gets the type of this property, if any.
   *
   * <p>{@code <element-ref>} particle doesn't have the type.
   *
   * @return null if none is specified.
   */
  public final JClass getType() {
    try {
      String type = DOMUtil.getAttribute(element, "supertype");
      if (type == null) return null;

      // TODO: does this attribute defaults to the current package?
      int idx = type.lastIndexOf('.');
      if (idx < 0) return parent.parent.codeModel.ref(type);
      else return parent.parent.getTargetPackage().ref(type);
    } catch (ClassNotFoundException e) {
      // TODO: better error handling
      throw new NoClassDefFoundError(e.getMessage());
    }
  }
 private Element levelDown() throws NoSuchElementException {
   if (state == STATE_AT || state == STATE_BEFORE) {
     Element t = DOMUtil.firstChildElement(__current);
     if (t != null) {
       state = STATE_BEFORE;
       return __current = t;
     } else {
       state = STATE_IN_EMPTY_SET;
       return null;
     }
   } else {
     throw new NoSuchElementException("Not at an element.");
   }
 }
  public static boolean repair(Node nodeStatusDetail) throws DOMStructureException {
    Element elementStatusDetail = DOMUtil.getElement(nodeStatusDetail);
    boolean result = false;

    NodeList children = elementStatusDetail.getChildNodes();
    int numChildren;
    if (children != null && (numChildren = children.getLength()) > 0) {
      for (int i = 0; i < numChildren; i++) {
        Node child = children.item(i);
        if (DOMUtil.isElement(child)) {
          if (DOMUtil.isInNamespace(child, XACML3.XMLNS)
              && XACML3.ELEMENT_MISSINGATTRIBUTEDETAIL.equals(child.getLocalName())) {
            result = DOMMissingAttributeDetail.repair(child) || result;
          } else {
            logger.warn("Unexpected element " + child.getNodeName());
            elementStatusDetail.removeChild(child);
            result = true;
          }
        }
      }
    }

    return result;
  }
 /**
  * Get the text contents of the current {@link Element Element}, if it exists, is non-empty and
  * has local name <i>name</i>, as an <code>boolean</code>.
  *
  * <p>The cursor will only be moved forward if the local element name matches <i>name</i>.
  *
  * @param name The local element name to test for.
  * @param defaultValue The <code>boolean</code> value to return if the element does not exist.
  * @return The text contents of the current {@link Element Element} as an <code>boolean</code>, if
  *     it exists, is non-empty and has local name <i>name</i>, <i>defaultValue</i> otherwise.
  * @throws NoSuchElementException If the current element has local name <i>name</i> but has
  *     non-text content.
  * @throws IllegalArgumentException If the current element has local name <i>name</i> and has
  *     text-only content that cannot be parsed as an <code>boolean</code>.
  */
 public boolean getBooleanConditional(String name, boolean defaultValue)
     throws NoSuchElementException {
   String s = getStringConditional(name);
   return s != null ? DOMUtil.booleanValue(s) : defaultValue;
 }
 /**
  * Get the text contents of the current {@link Element Element}, which must have local name
  * <i>name</i>, as an <code>boolean</code>.
  *
  * @param name The local element name expected.
  * @return The text contents of the current {@link Element Element}, as an <code>boolean</code>.
  * @throws NoSuchElementException if the current element has non-text content, if it's local name
  *     is not <i>name</i> or if there is no current element.
  * @throws IllegalArgumentException if the current element has local name <i>name</i> and is empty
  *     or has text-only content that cannot be parsed as an <code>boolean</code>.
  */
 public boolean getBoolean(String name) throws NoSuchElementException {
   return DOMUtil.booleanValue(getString(name));
 }
 public String getNamespace() {
   return DOMUtil.getDefiningNamespace(current());
 }
 /**
  * Check if the <a href="#last">&quot;last visited element&quot;</a> has more siblings.
  *
  * @return true iff the <a href="#last">&quot;last visited element&quot;</a> has more siblings.
  */
 public boolean hasNext() {
   return state == STATE_BEFORE
       || (state == STATE_AT && DOMUtil.nextSiblingElement(__current) != null);
 }