コード例 #1
0
 /**
  * *****************************************************************************************************************
  *
  * <p>Adds a tag to this <code>Directory</code>.
  *
  * @param tag the tag to add
  *     <p>****************************************************************************************************************
  */
 public void addTag(@Nonnull final AbstractTag tag) {
   if (tag != null) {
     final int key = tag.getCode();
     tagMapByKey.put(tagRegistry.getKey(key), tag);
     keyList.add(tagRegistry.getKey(key));
   }
 }
コード例 #2
0
  /** Process conditionals and non-repeat attributes on an element */
  private void processElementInner(Node result, Element element) {
    TagHandler handler = registry.getHandlerFor(element);

    // An ugly special-case:  <os:Repeat> will re-evaluate the "if" attribute
    // (as it should) for each loop of the repeat.  Don't evaluate it here.
    if (!(handler instanceof RepeatTagHandler)) {
      Attr ifAttribute = element.getAttributeNode(ATTRIBUTE_IF);
      if (ifAttribute != null) {
        if (!evaluate(ifAttribute.getValue(), Boolean.class, false)) {
          return;
        }
      }
    }

    // TODO: the spec is silent on order of evaluation of "cur" relative
    // to "if" and "repeat"
    Attr curAttribute = element.getAttributeNode(ATTRIBUTE_CUR);
    Object oldCur = templateContext.getCur();
    if (curAttribute != null) {
      templateContext.setCur(evaluate(curAttribute.getValue(), Object.class, null));
    }

    if (handler != null) {
      handler.process(result, element, this);
    } else {
      // Be careful cloning nodes! If a target node belongs to a different document than the
      // template node then use importNode rather than cloneNode as that avoids side-effects
      // in UserDataHandlers where the cloned template node would belong to its original
      // document before being adopted by the target document.
      Element resultNode;
      if (element.getOwnerDocument() != result.getOwnerDocument()) {
        resultNode = (Element) result.getOwnerDocument().importNode(element, false);
      } else {
        resultNode = (Element) element.cloneNode(false);
      }

      clearSpecialAttributes(resultNode);
      Node additionalNode = processAttributes(resultNode);

      processChildNodes(resultNode, element);
      result.appendChild(resultNode);

      if (additionalNode != null) {
        result.appendChild(additionalNode);
      }
    }

    if (curAttribute != null) {
      templateContext.setCur(oldCur);
    }
  }
コード例 #3
0
 /**
  * *****************************************************************************************************************
  *
  * <p>Customized deserialization code. This method restores the link to the registry this tag
  * belongs to.
  *
  * @param is
  * @throws IOException
  * @throws ClassNotFoundException
  *     <p>****************************************************************************************************************
  */
 private void readObject(@Nonnull final ObjectInputStream is)
     throws IOException, ClassNotFoundException {
   is.defaultReadObject();
   tagRegistry = TagRegistry.getRegistry(registryName);
 }
コード例 #4
0
 /**
  * *****************************************************************************************************************
  *
  * <p>Returns the name of the given tag. FIXME: is meaningful here?
  *
  * @param key the tag key
  * @return the tag name
  *     <p>****************************************************************************************************************
  */
 @Nonnull
 public String getTagName(@Nonnull final Object key) {
   return tagRegistry.getTagName(((Number) key).intValue());
 }
コード例 #5
0
 /**
  * *****************************************************************************************************************
  *
  * <p>Removes a given tag from this </code>Directory</code>
  *
  * @param key the tag key
  * @return the remove tag
  *     <p>****************************************************************************************************************
  */
 @CheckForNull
 public AbstractTag removeTag(@Nonnull final Object key) {
   keyList.remove(tagRegistry.getKey(key));
   return tagMapByKey.remove(tagRegistry.getKey(key));
 }
コード例 #6
0
 /**
  * *****************************************************************************************************************
  *
  * <p>Checks if this <code>Directory</code> contains a given tag.
  *
  * @param key the tag key
  * @return true if this <code>Directory</code> contains the tag
  *     <p>****************************************************************************************************************
  */
 public boolean containsTag(@Nonnull final Object key) {
   return (tagRegistry != null) && tagMapByKey.containsKey(tagRegistry.getKey(key));
 }
コード例 #7
0
 /**
  * *****************************************************************************************************************
  *
  * <p>Retrieves a contained tag given its key.
  *
  * @param key the tag key
  *     <p>****************************************************************************************************************
  */
 @CheckForNull
 public AbstractTag getTag(@Nonnull final Object key) {
   return tagMapByKey.get(tagRegistry.getKey(key));
 }
コード例 #8
0
 /**
  * *****************************************************************************************************************
  *
  * <p>Creates a new <code>Directory</code> whose getTags belong to the given registry.
  *
  * @param tagRegistry the registry
  *     <p>****************************************************************************************************************
  */
 protected Directory(@Nonnull final TagRegistry tagRegistry) {
   this.tagRegistry = tagRegistry;
   registryName = tagRegistry.getName();
 }