示例#1
0
  public static List<DomElement> getDefinedChildren(
      @NotNull final DomElement parent, final boolean tags, final boolean attributes) {
    if (parent instanceof MergedObject) {
      final SmartList<DomElement> result = new SmartList<>();
      parent.acceptChildren(
          new DomElementVisitor() {
            @Override
            public void visitDomElement(final DomElement element) {
              if (hasXml(element)) {
                result.add(element);
              }
            }
          });
      return result;
    }

    ProgressManager.checkCanceled();

    if (parent instanceof GenericAttributeValue) return Collections.emptyList();

    if (parent instanceof DomFileElement) {
      final DomFileElement element = (DomFileElement) parent;
      return tags ? Arrays.asList(element.getRootElement()) : Collections.<DomElement>emptyList();
    }

    final XmlElement xmlElement = parent.getXmlElement();
    if (xmlElement instanceof XmlTag) {
      XmlTag tag = (XmlTag) xmlElement;
      final DomManager domManager = parent.getManager();
      final SmartList<DomElement> result = new SmartList<>();
      if (attributes) {
        for (final XmlAttribute attribute : tag.getAttributes()) {
          if (!attribute.isValid()) {
            LOG.error("Invalid attr: parent.valid=" + tag.isValid());
            continue;
          }
          GenericAttributeValue element = domManager.getDomElement(attribute);
          if (checkHasXml(attribute, element)) {
            ContainerUtil.addIfNotNull(result, element);
          }
        }
      }
      if (tags) {
        for (final XmlTag subTag : tag.getSubTags()) {
          if (!subTag.isValid()) {
            LOG.error("Invalid subtag: parent.valid=" + tag.isValid());
            continue;
          }
          DomElement element = domManager.getDomElement(subTag);
          if (checkHasXml(subTag, element)) {
            ContainerUtil.addIfNotNull(result, element);
          }
        }
      }
      return result;
    }
    return Collections.emptyList();
  }
示例#2
0
 @NotNull
 public static List<XmlTag> getElementTags(@NotNull Collection<? extends DomElement> list) {
   ArrayList<XmlTag> result = new ArrayList<>(list.size());
   for (DomElement element : list) {
     XmlTag tag = element.getXmlTag();
     if (tag != null) {
       result.add(tag);
     }
   }
   return result;
 }
示例#3
0
 public static void acceptAvailableChildren(
     final DomElement element, final DomElementVisitor visitor) {
   final XmlTag tag = element.getXmlTag();
   if (tag != null) {
     for (XmlTag xmlTag : tag.getSubTags()) {
       final DomElement childElement = element.getManager().getDomElement(xmlTag);
       if (childElement != null) {
         childElement.accept(visitor);
       }
     }
   }
 }
示例#4
0
 @Nullable
 public static <T> T getParentOfType(
     final DomElement element, final Class<T> requiredClass, final boolean strict) {
   for (DomElement curElement = strict && element != null ? element.getParent() : element;
       curElement != null;
       curElement = curElement.getParent()) {
     if (requiredClass.isInstance(curElement)) {
       return (T) curElement;
     }
   }
   return null;
 }
示例#5
0
 @NotNull
 public static XmlTag[] getElementTags(@NotNull DomElement[] list) {
   XmlTag[] result = new XmlTag[list.length];
   int i = 0;
   for (DomElement element : list) {
     XmlTag tag = element.getXmlTag();
     if (tag != null) {
       result[i++] = tag;
     }
   }
   return result;
 }
示例#6
0
 @NotNull
 public static String[] getElementNames(@NotNull Collection<? extends DomElement> list) {
   ArrayList<String> result = new ArrayList<>(list.size());
   if (list.size() > 0) {
     for (DomElement element : list) {
       String name = element.getGenericInfo().getElementName(element);
       if (name != null) {
         result.add(name);
       }
     }
   }
   return ArrayUtil.toStringArray(result);
 }
示例#7
0
 private void renderSource(DomElement element, WAbstractMedia.Source source, boolean isLast) {
   element.setAttribute("src", resolveRelativeUrl(source.link.getUrl()));
   if (!source.type.equals("")) {
     element.setAttribute("type", source.type);
   }
   if (!source.media.equals("")) {
     element.setAttribute("media", source.media);
   }
   if (isLast && this.alternative_ != null) {
     element.setAttribute(
         "onerror",
         "var media = this.parentNode;if(media){while (media && media.children.length)if (Wt3_2_3.hasTag(media.firstChild,'SOURCE')){media.removeChild(media.firstChild);}else{media.parentNode.insertBefore(media.firstChild, media);}media.style.display= 'none';}");
   } else {
     element.setAttribute("onerror", "");
   }
 }
示例#8
0
  public static <T extends DomElement> DomFileElement<T> getFileElement(
      @NotNull DomElement element) {

    if (element instanceof DomFileElement) {
      return (DomFileElement) element;
    }
    DomFileElement fileElement = element.getUserData(FILE_ELEMENT_KEY);
    if (fileElement == null) {
      DomElement parent = element.getParent();
      if (parent != null) {
        fileElement = getFileElement(parent);
      }
      element.putUserData(FILE_ELEMENT_KEY, fileElement);
    }
    return fileElement;
  }
示例#9
0
 @Nullable
 public static List<JavaMethod> getFixedPath(DomElement element) {
   assert element.isValid();
   final LinkedList<JavaMethod> methods = new LinkedList<>();
   while (true) {
     final DomElement parent = element.getParent();
     if (parent instanceof DomFileElement) {
       break;
     }
     final JavaMethod method = getGetterMethod(element, parent);
     if (method == null) {
       return null;
     }
     methods.addFirst(method);
     element = element.getParent();
   }
   return methods;
 }
示例#10
0
  @Nullable
  public static <T extends DomElement> T findDomElement(
      @Nullable final PsiElement element, final Class<T> beanClass, boolean strict) {
    if (element == null) return null;

    XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, strict);
    DomElement domElement;

    while (tag != null) {
      domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);

      if (domElement != null) {
        return domElement.getParentOfType(beanClass, false);
      }
      tag = tag.getParentTag();
    }
    return null;
  }
示例#11
0
 /**
  * @param domElement DomElement to search root of
  * @return the topmost valid DomElement being a parent of the given one. May be and may be not
  *     DomFileElement. If root tag has changed, file may lose its domness, so there will be no
  *     DomFileElement, but the inner DomElement's will be still alive because the underlying XML
  *     tags are valid
  */
 @NotNull
 public static DomElement getRoot(@NotNull DomElement domElement) {
   while (true) {
     final DomElement parent = domElement.getParent();
     if (parent == null) {
       return domElement;
     }
     domElement = parent;
   }
 }
示例#12
0
  @Nullable
  private static JavaMethod getGetterMethod(final DomElement element, final DomElement parent) {
    final String xmlElementName = element.getXmlElementName();
    final String namespace = element.getXmlElementNamespaceKey();
    final DomGenericInfo genericInfo = parent.getGenericInfo();

    if (element instanceof GenericAttributeValue) {
      final DomAttributeChildDescription description =
          genericInfo.getAttributeChildDescription(xmlElementName, namespace);
      assert description != null;
      return description.getGetterMethod();
    }

    final DomFixedChildDescription description =
        genericInfo.getFixedChildDescription(xmlElementName, namespace);
    return description != null
        ? description.getGetterMethod(description.getValues(parent).indexOf(element))
        : null;
  }
示例#13
0
 private DomElement createRow(int row, boolean withIds, WApplication app) {
   DomElement tr = DomElement.createNew(DomElementType.DomElement_TR);
   if (withIds) {
     tr.setId(this.rows_.get(row).getId());
   }
   this.rows_.get(row).updateDom(tr, true);
   tr.setWasEmpty(false);
   int spanCounter = 0;
   for (int col = 0; col < this.getColumnCount(); ++col) {
     WTableRow.TableData d = this.itemAt(row, col);
     if (!d.overSpanned) {
       DomElement td = d.cell.createSDomElement(app);
       if (col < this.headerColumnCount_ || row < this.headerRowCount_) {
         tr.addChild(td);
       } else {
         tr.insertChildAt(td, col - spanCounter);
       }
       for (int i = 0; i < d.cell.getRowSpan(); ++i) {
         for (int j = 0; j < d.cell.getColumnSpan(); ++j) {
           if (i + j > 0) {
             this.itemAt(row + i, col + j).overSpanned = true;
             this.itemAt(row + i, col + j).cell.setRendered(false);
           }
         }
       }
     } else {
       spanCounter++;
     }
   }
   return tr;
 }
示例#14
0
 void updateMediaDom(DomElement element, boolean all) {
   if (all && this.alternative_ != null) {
     element.setAttribute(
         "onerror",
         "if(event.target.error && event.target.error.code==event.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED){while (this.hasChildNodes())if (Wt3_2_3.hasTag(this.firstChild,'SOURCE')){this.removeChild(this.firstChild);}else{this.parentNode.insertBefore(this.firstChild, this);}this.style.display= 'none';}");
   }
   if (all || this.flagsChanged_) {
     if (!all || !EnumUtils.mask(this.flags_, WAbstractMedia.Options.Controls).isEmpty()) {
       element.setAttribute(
           "controls",
           !EnumUtils.mask(this.flags_, WAbstractMedia.Options.Controls).isEmpty()
               ? "controls"
               : "");
     }
     if (!all || !EnumUtils.mask(this.flags_, WAbstractMedia.Options.Autoplay).isEmpty()) {
       element.setAttribute(
           "autoplay",
           !EnumUtils.mask(this.flags_, WAbstractMedia.Options.Autoplay).isEmpty()
               ? "autoplay"
               : "");
     }
     if (!all || !EnumUtils.mask(this.flags_, WAbstractMedia.Options.Loop).isEmpty()) {
       element.setAttribute(
           "loop",
           !EnumUtils.mask(this.flags_, WAbstractMedia.Options.Loop).isEmpty() ? "loop" : "");
     }
   }
   if (all || this.preloadChanged_) {
     switch (this.preloadMode_) {
       case PreloadNone:
         element.setAttribute("preload", "none");
         break;
       default:
       case PreloadAuto:
         element.setAttribute("preload", "auto");
         break;
       case PreloadMetadata:
         element.setAttribute("preload", "metadata");
         break;
     }
   }
   this.updateEventSignals(element, all);
   if (all) {
     if (this.alternative_ != null) {
       element.addChild(this.alternative_.createSDomElement(WApplication.getInstance()));
     }
   }
   this.flagsChanged_ = this.preloadChanged_ = false;
 }
示例#15
0
 public static <T> List<T> getChildrenOfType(
     @NotNull final DomElement parent, final Class<T> type) {
   final List<T> result = new SmartList<>();
   parent.acceptChildren(
       new DomElementVisitor() {
         @Override
         public void visitDomElement(final DomElement element) {
           if (type.isInstance(element)) {
             result.add((T) element);
           }
         }
       });
   return result;
 }
示例#16
0
  @NotNull
  public static <T extends DomElement> T getOriginalElement(@NotNull final T domElement) {
    final XmlElement psiElement = domElement.getXmlElement();
    if (psiElement == null) return domElement;

    final PsiFile psiFile = psiElement.getContainingFile().getOriginalFile();
    final TextRange range = psiElement.getTextRange();
    final PsiElement element = psiFile.findElementAt(range.getStartOffset());
    final int maxLength = range.getLength();
    final boolean isAttribute = psiElement instanceof XmlAttribute;
    final Class<? extends XmlElement> clazz = isAttribute ? XmlAttribute.class : XmlTag.class;
    final DomManager domManager = domElement.getManager();
    DomElement current = null;
    for (XmlElement next = PsiTreeUtil.getParentOfType(element, clazz, false);
        next != null && next.getTextLength() <= maxLength;
        next = PsiTreeUtil.getParentOfType(next, clazz, true)) {
      current =
          isAttribute
              ? domManager.getDomElement((XmlAttribute) next)
              : domManager.getDomElement((XmlTag) next);
      if (current != null && domElement.getClass() != current.getClass()) current = null;
    }
    return (T) current;
  }
示例#17
0
 void getDomChanges(List<DomElement> result, WApplication app) {
   DomElement e = DomElement.getForUpdate(this, this.getDomElementType());
   if (!this.isStubbed() && this.flags_.get(BIT_GRID_CHANGED)) {
     DomElement newE = this.createDomElement(app);
     e.replaceWith(newE);
   } else {
     if (this.rowsChanged_ != null) {
       for (Iterator<WTableRow> i_it = this.rowsChanged_.iterator(); i_it.hasNext(); ) {
         WTableRow i = i_it.next();
         DomElement e2 = DomElement.getForUpdate(i, DomElementType.DomElement_TR);
         i.updateDom(e2, false);
         result.add(e2);
       }
       ;
       this.rowsChanged_ = null;
     }
     if (this.rowsAdded_ != 0) {
       DomElement etb =
           DomElement.getForUpdate(this.getId() + "tb", DomElementType.DomElement_TBODY);
       for (int i = 0; i < (int) this.rowsAdded_; ++i) {
         DomElement tr = this.createRow(this.getRowCount() - this.rowsAdded_ + i, true, app);
         etb.addChild(tr);
       }
       result.add(etb);
       this.rowsAdded_ = 0;
     }
     if (this.flags_.get(BIT_COLUMNS_CHANGED)) {
       for (int i = 0; i < this.columns_.size(); ++i) {
         DomElement e2 =
             DomElement.getForUpdate(this.columns_.get(i), DomElementType.DomElement_COL);
         this.columns_.get(i).updateDom(e2, false);
         result.add(e2);
       }
       this.flags_.clear(BIT_COLUMNS_CHANGED);
     }
     this.updateDom(e, false);
   }
   result.add(e);
 }
示例#18
0
 @SuppressWarnings("ForLoopReplaceableByForEach")
 public static <T extends DomElement> List<T> getChildrenOf(
     DomElement parent, final Class<T> type) {
   final List<T> list = new SmartList<>();
   List<? extends AbstractDomChildrenDescription> descriptions =
       parent.getGenericInfo().getChildrenDescriptions();
   for (int i = 0, descriptionsSize = descriptions.size(); i < descriptionsSize; i++) {
     AbstractDomChildrenDescription description = descriptions.get(i);
     if (description.getType() instanceof Class
         && type.isAssignableFrom((Class<?>) description.getType())) {
       List<T> values = (List<T>) description.getValues(parent);
       for (int j = 0, valuesSize = values.size(); j < valuesSize; j++) {
         T value = values.get(j);
         if (value.exists()) {
           list.add(value);
         }
       }
     }
   }
   return list;
 }
示例#19
0
 void getDomChanges(List<DomElement> result, WApplication app) {
   if (this.mediaId_.length() != 0) {
     DomElement media = DomElement.getForUpdate(this.mediaId_, DomElementType.DomElement_DIV);
     this.updateMediaDom(media, false);
     if (this.sourcesChanged_) {
       for (int i = 0; i < this.sourcesRendered_; ++i) {
         media.callJavaScript(
             "Wt3_2_3.remove('" + this.mediaId_ + "s" + String.valueOf(i) + "');", true);
       }
       this.sourcesRendered_ = 0;
       for (int i = 0; i < this.sources_.size(); ++i) {
         DomElement src = DomElement.createNew(DomElementType.DomElement_SOURCE);
         src.setId(this.mediaId_ + "s" + String.valueOf(i));
         this.renderSource(src, this.sources_.get(i), i + 1 >= this.sources_.size());
         media.addChild(src);
       }
       this.sourcesRendered_ = this.sources_.size();
       this.sourcesChanged_ = false;
       media.callJavaScript(this.getJsMediaRef() + ".load();");
     }
     result.add(media);
   }
   super.getDomChanges(result, app);
 }
示例#20
0
  public static List<? extends DomElement> getIdentitySiblings(DomElement element) {
    final GenericDomValue nameDomElement = element.getGenericInfo().getNameDomElement(element);
    if (nameDomElement == null) return Collections.emptyList();

    final NameValue nameValue = nameDomElement.getAnnotation(NameValue.class);
    if (nameValue == null || !nameValue.unique()) return Collections.emptyList();

    final String stringValue = ElementPresentationManager.getElementName(element);
    if (stringValue == null) return Collections.emptyList();

    final DomElement scope = element.getManager().getIdentityScope(element);
    if (scope == null) return Collections.emptyList();

    final DomGenericInfo domGenericInfo = scope.getGenericInfo();
    final String tagName = element.getXmlElementName();
    final DomCollectionChildDescription childDescription =
        domGenericInfo.getCollectionChildDescription(tagName, element.getXmlElementNamespaceKey());
    if (childDescription != null) {
      final ArrayList<DomElement> list = new ArrayList<>(childDescription.getValues(scope));
      list.remove(element);
      return list;
    }
    return Collections.emptyList();
  }
示例#21
0
 public static boolean isAncestor(
     @NotNull DomElement ancestor, @NotNull DomElement descendant, boolean strict) {
   if (!strict && ancestor.equals(descendant)) return true;
   final DomElement parent = descendant.getParent();
   return parent != null && isAncestor(ancestor, parent, false);
 }
示例#22
0
 DomElement createDomElement(WApplication app) {
   DomElement result = null;
   if (this.isInLayout()) {
     this.setJavaScriptMember(WT_RESIZE_JS, "function() {}");
   }
   if (app.getEnvironment().agentIsIElt(9)
       || app.getEnvironment().getAgent() == WEnvironment.UserAgent.MobileWebKitAndroid) {
     result = DomElement.createNew(DomElementType.DomElement_DIV);
     if (this.alternative_ != null) {
       result.addChild(this.alternative_.createSDomElement(app));
     }
   } else {
     DomElement media = this.createMediaDomElement();
     DomElement wrap = null;
     if (this.isInLayout()) {
       media.setProperty(Property.PropertyStylePosition, "absolute");
       media.setProperty(Property.PropertyStyleLeft, "0");
       media.setProperty(Property.PropertyStyleRight, "0");
       wrap = DomElement.createNew(DomElementType.DomElement_DIV);
       wrap.setProperty(Property.PropertyStylePosition, "relative");
     }
     result = wrap != null ? wrap : media;
     if (wrap != null) {
       this.mediaId_ = this.getId() + "_media";
       media.setId(this.mediaId_);
     } else {
       this.mediaId_ = this.getId();
     }
     this.updateMediaDom(media, true);
     for (int i = 0; i < this.sources_.size(); ++i) {
       DomElement src = DomElement.createNew(DomElementType.DomElement_SOURCE);
       src.setId(this.mediaId_ + "s" + String.valueOf(i));
       this.renderSource(src, this.sources_.get(i), i + 1 >= this.sources_.size());
       media.addChild(src);
     }
     this.sourcesRendered_ = this.sources_.size();
     this.sourcesChanged_ = false;
     if (wrap != null) {
       wrap.addChild(media);
     }
   }
   if (this.isInLayout()) {
     StringWriter ss = new StringWriter();
     ss.append("function(self, w, h) {");
     if (this.mediaId_.length() != 0) {
       ss.append(
           "v="
               + this.getJsMediaRef()
               + ";if(v){v.setAttribute('width', w);v.setAttribute('height', h);}");
     }
     if (this.alternative_ != null) {
       ss.append("a=" + this.alternative_.getJsRef() + ";if(a && a.")
           .append(WT_RESIZE_JS)
           .append(")a.")
           .append(WT_RESIZE_JS)
           .append("(a, w, h);");
     }
     ss.append("}");
     this.setJavaScriptMember(WT_RESIZE_JS, ss.toString());
   }
   this.setId(result, app);
   this.updateDom(result, true);
   if (this.isInLayout()) {
     result.setEvent(PLAYBACKSTARTED_SIGNAL, "");
     result.setEvent(PLAYBACKPAUSED_SIGNAL, "");
     result.setEvent(ENDED_SIGNAL, "");
     result.setEvent(TIMEUPDATED_SIGNAL, "");
     result.setEvent(VOLUMECHANGED_SIGNAL, "");
   }
   this.setJavaScriptMember("mediaId", "'" + this.mediaId_ + "'");
   return result;
 }
示例#23
0
 public static boolean hasXml(@NotNull DomElement element) {
   return element.exists();
 }
示例#24
0
 DomElement createDomElement(WApplication app) {
   boolean withIds = !app.getEnvironment().agentIsSpiderBot();
   DomElement table = DomElement.createNew(this.getDomElementType());
   this.setId(table, app);
   DomElement thead = null;
   if (this.headerRowCount_ != 0) {
     thead = DomElement.createNew(DomElementType.DomElement_THEAD);
     if (withIds) {
       thead.setId(this.getId() + "th");
     }
   }
   DomElement tbody = DomElement.createNew(DomElementType.DomElement_TBODY);
   if (withIds) {
     tbody.setId(this.getId() + "tb");
   }
   for (int col = 0; col < this.columns_.size(); ++col) {
     DomElement c = DomElement.createNew(DomElementType.DomElement_COL);
     if (withIds) {
       c.setId(this.columns_.get(col).getId());
     }
     this.columns_.get(col).updateDom(c, true);
     table.addChild(c);
   }
   this.flags_.clear(BIT_COLUMNS_CHANGED);
   for (int row = 0; row < (int) this.getRowCount(); ++row) {
     for (int col = 0; col < (int) this.getColumnCount(); ++col) {
       this.itemAt(row, col).overSpanned = false;
     }
   }
   for (int row = 0; row < (int) this.getRowCount(); ++row) {
     DomElement tr = this.createRow(row, withIds, app);
     if (row < (int) this.headerRowCount_) {
       thead.addChild(tr);
     } else {
       tbody.addChild(tr);
     }
   }
   this.rowsAdded_ = 0;
   if (thead != null) {
     table.addChild(thead);
   }
   table.addChild(tbody);
   this.updateDom(table, true);
   this.flags_.clear(BIT_GRID_CHANGED);
   ;
   this.rowsChanged_ = null;
   return table;
 }