/**
   * This method trims down the position set to the position directives on the node info elements
   * still having a position directive. Any directives that violated restrictions were removed from
   * the node info objects so the position set should be made to match the order of those still
   * having one.
   */
  static void adjustPositionSet(
      List<NodeInfo> order, Element positionSet, IntegrationResult result) {
    Node nodeToMatch = positionSet.getFirstChild();
    Element nodeToInsertBefore = positionSet.getOwnerDocument().createElement("INSERT_POINT");
    positionSet.insertBefore(nodeToInsertBefore, nodeToMatch);

    for (Iterator iter = order.iterator(); iter.hasNext(); ) {
      NodeInfo ni = (NodeInfo) iter.next();

      if (ni.positionDirective != null) {
        // found one check it against the current one in the position
        // set to see if it is different. If so then indicate that
        // something (the position set) has changed in the plf
        if (ni.positionDirective != nodeToMatch) result.changedPLF = true;

        // now bump the insertion point forward prior to
        // moving on to the next position node to be evaluated
        if (nodeToMatch != null) nodeToMatch = nodeToMatch.getNextSibling();

        // now insert it prior to insertion point
        positionSet.insertBefore(ni.positionDirective, nodeToInsertBefore);
      }
    }

    // now for any left over after the insert point remove them.

    while (nodeToInsertBefore.getNextSibling() != null)
      positionSet.removeChild(nodeToInsertBefore.getNextSibling());

    // now remove the insertion point
    positionSet.removeChild(nodeToInsertBefore);
  }
 /** Efface le noeud DOM, et son parent s'il devient vide. */
 private void effacerNoeud(final boolean annulation, final CompoundEdit cedit1) {
   CompoundEdit cedit = null;
   if (!annulation) {
     final FormUndoableEdit fedit =
         new FormUndoableEdit(FormUndoableEdit.TypeEdition.SUPPRIMER, this);
     if (cedit1 != null) cedit1.addEdit(fedit);
     else {
       cedit = new CompoundEdit();
       cedit.addEdit(fedit);
     }
   }
   final Element elparent = (Element) affParent.getNoeud();
   if (attribut) {
     final String nom = cfg.nomAttribut(refNoeud);
     final String espace = cfg.espaceAttribut(refNoeud);
     elparent.removeAttributeNS(espace, nom);
   } else {
     final Node textNode = noeud.getNextSibling();
     elparent.removeChild(noeud);
     if (textNode.getNodeType() == Node.TEXT_NODE) elparent.removeChild(textNode);
   }
   noeud = null;
   if (!annulation) affParent.testEffacementParent(cedit1 != null ? cedit1 : cedit);
   else lireEnfants();
   doc.textPane.miseAJourArbre();
   if (cedit1 == null && cedit != null) {
     cedit.end();
     doc.textPane.addEdit(cedit);
   }
 }
Ejemplo n.º 3
0
  /** create node maps so that we can access node faster by their name */
  protected void createNodeMaps() {
    pkgMap = new Hashtable();
    classMap = new Hashtable();
    // create a map index of all packages by their name
    // @todo can be done faster by direct access.
    NodeList packages = report.getElementsByTagName("package");
    final int pkglen = packages.getLength();
    log("Indexing " + pkglen + " packages");
    for (int i = pkglen - 1; i > -1; i--) {
      Element pkg = (Element) packages.item(i);
      String pkgname = pkg.getAttribute("name");

      int nbclasses = 0;
      // create a map index of all classes by their fully
      // qualified name.
      NodeList classes = pkg.getElementsByTagName("class");
      final int classlen = classes.getLength();
      log("Indexing " + classlen + " classes in package " + pkgname);
      for (int j = classlen - 1; j > -1; j--) {
        Element clazz = (Element) classes.item(j);
        String classname = clazz.getAttribute("name");
        if (pkgname != null && pkgname.length() != 0) {
          classname = pkgname + "." + classname;
        }

        int nbmethods = 0;
        NodeList methods = clazz.getElementsByTagName("method");
        final int methodlen = methods.getLength();
        for (int k = methodlen - 1; k > -1; k--) {
          Element meth = (Element) methods.item(k);
          StringBuffer methodname = new StringBuffer(meth.getAttribute("name"));
          methodname.delete(methodname.toString().indexOf("("), methodname.toString().length());
          String signature = classname + "." + methodname + "()";
          if (filters.accept(signature)) {
            log("kept method:" + signature);
            nbmethods++;
          } else {
            clazz.removeChild(meth);
          }
        }
        // if we don't keep any method, we don't keep the class
        if (nbmethods != 0 && classFiles.containsKey(classname)) {
          log("Adding class '" + classname + "'");
          classMap.put(classname, clazz);
          nbclasses++;
        } else {
          pkg.removeChild(clazz);
        }
      }
      if (nbclasses != 0) {
        log("Adding package '" + pkgname + "'");
        pkgMap.put(pkgname, pkg);
      } else {
        pkg.getParentNode().removeChild(pkg);
      }
    }
    log("Indexed " + classMap.size() + " classes in " + pkgMap.size() + " packages");
  }
Ejemplo n.º 4
0
  /**
   * Carries out preprocessing that makes JEuclid handle the document better.
   *
   * @param doc Document
   */
  static void preprocessForJEuclid(Document doc) {
    // underbrace and overbrace
    NodeList list = doc.getElementsByTagName("mo");
    for (int i = 0; i < list.getLength(); i++) {
      Element mo = (Element) list.item(i);
      String parentName = ((Element) mo.getParentNode()).getTagName();
      if (parentName == null) {
        continue;
      }
      if (parentName.equals("munder") && isTextChild(mo, "\ufe38")) {
        mo.setAttribute("stretchy", "true");
        mo.removeChild(mo.getFirstChild());
        mo.appendChild(doc.createTextNode("\u23df"));
      } else if (parentName.equals("mover") && isTextChild(mo, "\ufe37")) {
        mo.setAttribute("stretchy", "true");
        mo.removeChild(mo.getFirstChild());
        mo.appendChild(doc.createTextNode("\u23de"));
      }
    }

    // menclose for long division doesn't allow enough top padding. Oh, and
    // <mpadded> isn't implemented. And there isn't enough padding to left of
    // the bar either. Solve by adding an <mover> with just an <mspace> over#
    // the longdiv, contained within an mrow that adds a <mspace> before it.
    list = doc.getElementsByTagName("menclose");
    for (int i = 0; i < list.getLength(); i++) {
      Element menclose = (Element) list.item(i);
      // Only for longdiv
      if (!"longdiv".equals(menclose.getAttribute("notation"))) {
        continue;
      }
      Element mrow = doc.createElementNS(WebMathsService.NS, "mrow");
      Element mover = doc.createElementNS(WebMathsService.NS, "mover");
      Element mspace = doc.createElementNS(WebMathsService.NS, "mspace");
      Element mspaceW = doc.createElementNS(WebMathsService.NS, "mspace");
      boolean previousElement = false;
      for (Node previous = menclose.getPreviousSibling();
          previous != null;
          previous = previous.getPreviousSibling()) {
        if (previous.getNodeType() == Node.ELEMENT_NODE) {
          previousElement = true;
          break;
        }
      }
      if (previousElement) {
        mspaceW.setAttribute("width", "4px");
      }
      menclose.getParentNode().insertBefore(mrow, menclose);
      menclose.getParentNode().removeChild(menclose);
      mrow.appendChild(mspaceW);
      mrow.appendChild(mover);
      mover.appendChild(menclose);
      mover.appendChild(mspace);
    }
  }
Ejemplo n.º 5
0
  public void configureTemplateMessage(final String from, final String subject) {
    final String contextPath = getApplicationContextPath();
    final Document document = XmlUtils.readXml(fileManager.getInputStream(contextPath));
    final Element root = document.getDocumentElement();

    final Map<String, String> props = new HashMap<String, String>();

    if (StringUtils.hasText(from) || StringUtils.hasText(subject)) {
      Element smmBean = getSimpleMailMessageBean(root);
      if (smmBean == null) {
        smmBean = document.createElement("bean");
        smmBean.setAttribute("class", "org.springframework.mail.SimpleMailMessage");
        smmBean.setAttribute("id", "templateMessage");
      }

      if (StringUtils.hasText(from)) {
        Element smmProperty = XmlUtils.findFirstElement("//property[@name='from']", smmBean);
        if (smmProperty != null) {
          smmBean.removeChild(smmProperty);
        }
        smmProperty = document.createElement("property");
        smmProperty.setAttribute("value", "${email.from}");
        smmProperty.setAttribute("name", "from");
        smmBean.appendChild(smmProperty);
        props.put("email.from", from);
      }

      if (StringUtils.hasText(subject)) {
        Element smmProperty = XmlUtils.findFirstElement("//property[@name='subject']", smmBean);
        if (smmProperty != null) {
          smmBean.removeChild(smmProperty);
        }
        smmProperty = document.createElement("property");
        smmProperty.setAttribute("value", "${email.subject}");
        smmProperty.setAttribute("name", "subject");
        smmBean.appendChild(smmProperty);
        props.put("email.subject", subject);
      }

      root.appendChild(smmBean);

      DomUtils.removeTextNodes(root);

      fileManager.createOrUpdateTextFileIfRequired(
          contextPath, XmlUtils.nodeToString(document), false);
    }

    if (props.size() > 0) {
      propFileOperations.addProperties(
          Path.SPRING_CONFIG_ROOT, "email.properties", props, true, true);
    }
  }
  private String deleteComponentBindingFromXML(
      String componentXML, Integer entityId, String entityName) throws Exception {
    String entityNameTrigger = "Content";
    if (entityName.equals(SiteNode.class.getName())) entityNameTrigger = "SiteNode";

    Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8"));
    String componentPropertyXPath =
        "//component/properties/property/binding[@entityId='" + entityId + "']";
    // logger.info("componentPropertyXPath:" + componentPropertyXPath);
    String modifiedXML = null;

    NodeList anl =
        org.apache.xpath.XPathAPI.selectNodeList(
            document.getDocumentElement(), componentPropertyXPath);
    // logger.info("anl:" + anl.getLength());
    for (int i = 0; i < anl.getLength(); i++) {
      Element component = (Element) anl.item(i);
      String entity = component.getAttribute("entity");
      if (entity != null && entity.equalsIgnoreCase(entityNameTrigger)) {
        Element property = (Element) component.getParentNode();
        if (property.getChildNodes().getLength() > 1) {
          property.removeChild(component);
        } else {
          if (property != null && property.getParentNode() != null) {
            property.getParentNode().removeChild(property);
          }
        }
      }
    }

    modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString();

    return modifiedXML;
  }
  /**
   * Set a property of a resource to a value.
   *
   * @param name the property name
   * @param value the property value
   * @exception com.ibm.webdav.WebDAVException
   */
  public void setProperty(String name, Element value) throws WebDAVException {
    // load the properties
    Document propertiesDocument = resource.loadProperties();
    Element properties = propertiesDocument.getDocumentElement();
    String ns = value.getNamespaceURI();

    Element property = null;
    if (ns == null) {
      property = (Element) ((Element) properties).getElementsByTagName(value.getTagName()).item(0);
    } else {
      property = (Element) properties.getElementsByTagNameNS(ns, value.getLocalName()).item(0);
    }

    if (property != null) {
      try {
        properties.removeChild(property);
      } catch (DOMException exc) {
      }
    }

    properties.appendChild(propertiesDocument.importNode(value, true));

    // write out the properties
    resource.saveProperties(propertiesDocument);
  }
Ejemplo n.º 8
0
 void updateProperties() {
   Config config = MCPatcherUtils.config;
   Element mods = config.getMods();
   if (mods == null) {
     return;
   }
   HashMap<String, Element> oldElements = new HashMap<String, Element>();
   while (mods.hasChildNodes()) {
     Node node = mods.getFirstChild();
     if (node instanceof Element) {
       Element element = (Element) node;
       String name = config.getText(element, Config.TAG_NAME);
       if (name != null) {
         oldElements.put(name, element);
       }
     }
     mods.removeChild(node);
   }
   for (Mod mod : modsByIndex) {
     if (mod.internal) {
       continue;
     }
     Element element = oldElements.get(mod.getName());
     if (element == null) {
       defaultModElement(mod);
     } else {
       config.setText(
           element, Config.TAG_ENABLED, Boolean.toString(mod.isEnabled() && mod.okToApply()));
       updateModElement(mod, element);
       mods.appendChild(element);
       oldElements.remove(mod.getName());
     }
   }
 }
Ejemplo n.º 9
0
 private void updateModElement(Mod mod, Element element) {
   Config config = MCPatcherUtils.config;
   if (mod instanceof ExternalMod) {
     ExternalMod extmod = (ExternalMod) mod;
     config.setText(element, Config.TAG_TYPE, Config.VAL_EXTERNAL_ZIP);
     config.setText(element, Config.TAG_PATH, extmod.zipFile.getName());
     Element files = config.getElement(element, Config.TAG_FILES);
     while (files.hasChildNodes()) {
       files.removeChild(files.getFirstChild());
     }
     for (Map.Entry<String, String> entry : extmod.fileMap.entrySet()) {
       Element fileElem = config.xml.createElement(Config.TAG_FILE);
       Element pathElem = config.xml.createElement(Config.TAG_FROM);
       pathElem.appendChild(config.xml.createTextNode(entry.getValue()));
       fileElem.appendChild(pathElem);
       pathElem = config.xml.createElement(Config.TAG_TO);
       pathElem.appendChild(config.xml.createTextNode(entry.getKey()));
       fileElem.appendChild(pathElem);
       files.appendChild(fileElem);
     }
   } else if (mod.customJar == null) {
     config.setText(element, Config.TAG_TYPE, Config.VAL_BUILTIN);
   } else {
     config.setText(element, Config.TAG_TYPE, Config.VAL_EXTERNAL_JAR);
     config.setText(element, Config.TAG_PATH, mod.customJar.getPath());
     config.setText(element, Config.TAG_CLASS, mod.getClass().getCanonicalName());
   }
 }
Ejemplo n.º 10
0
  protected static void trimEmptyTextNodes(Node node) {
    Element element = null;
    if (node instanceof Document) {
      element = ((Document) node).getDocumentElement();
    } else if (node instanceof Element) {
      element = (Element) node;
    } else {
      return;
    }

    List<Node> nodesToRemove = new ArrayList<Node>();
    NodeList children = element.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);
      if (child instanceof Element) {
        trimEmptyTextNodes(child);
      } else if (child instanceof Text) {
        Text t = (Text) child;
        if (t.getData().trim().length() == 0) {
          nodesToRemove.add(child);
        }
      }
    }

    for (Node n : nodesToRemove) {
      element.removeChild(n);
    }
  }
Ejemplo n.º 11
0
  public void clearValue() {
    synchronized (DOMUtils.getDOMLock(elt)) {
      // Get rid of any text nodes that are children of the element.
      elt.normalize();
    }
    NodeList nl = elt.getChildNodes();
    for (int i = (nl.getLength() - 1); i >= 0; i--) {
      Node n = nl.item(i);
      if (n.getNodeType() == Node.TEXT_NODE) {
        synchronized (DOMUtils.getDOMLock(elt)) {
          elt.removeChild(n);
        }

        IXArch context = getXArch();
        if (context != null) {
          context.fireXArchEvent(
              new XArchEvent(
                  this,
                  XArchEvent.CLEAR_EVENT,
                  XArchEvent.SIMPLE_TYPE_VALUE_CHANGED,
                  "$SIMPLETYPEVALUE$",
                  null,
                  XArchUtils.getDefaultXArchImplementation().isContainedIn(xArch, this)));
        }
      }
    }
  }
  private static void removeOldFiles(final Element recentElement) throws Exception {
    final NodeList allRecentDocs = recentElement.getElementsByTagName("*");

    while (allRecentDocs.getLength() > noOfRecentDocs) {
      recentElement.removeChild(allRecentDocs.item(0));
    }
  }
Ejemplo n.º 13
0
  public static void updateUser(User userToUpdate) throws Exception {
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.parse(Constants.USER_DATA_FILE_PATH);

    NodeList nodeList = document.getElementsByTagName("user");
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node user = nodeList.item(i);
      if (user.getNodeType() == Node.ELEMENT_NODE) {
        Element userElement = (Element) user;
        String userName = userElement.getElementsByTagName("username").item(0).getTextContent();
        if (userName.equalsIgnoreCase(userToUpdate.getUserName())) {
          Node oldAccessibleSheetsNode =
              userElement.getElementsByTagName("accessibleSheets").item(0);
          userElement.removeChild(oldAccessibleSheetsNode);

          // Add new accessibleSheetsNode
          Element newAccessibleSheets = document.createElement("accessibleSheets");
          for (String sheet : userToUpdate.getAccessibleSheets()) {
            Element sheet1 = document.createElement("sheet");
            sheet1.setAttribute("filename", sheet);
            newAccessibleSheets.appendChild(sheet1);
          }
          userElement.appendChild(newAccessibleSheets);
          transformDocumentToXml(document, Constants.USER_DATA_FILE_PATH);
          System.out.println("updated user");
          return;
        }
      }
    }
  }
Ejemplo n.º 14
0
  @Test
  public void testAddRemoveChild() throws Exception {
    //		builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);

    String xml =
        "<?xml version=\"1.0\"?>"
            + "<root>"
            + "<item id=\"a\"/>"
            + "<child id=\"1\"/>"
            + "<item id=\"b\"/>"
            + "<child id=\"2\"/>"
            + "</root>";

    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
    Element root = doc.getDocumentElement();

    Element newElem = doc.createElement("tail");
    newElem.setAttribute("id", "3");
    Node appended = root.appendChild(newElem);

    Assert.assertEquals("added element", "tail", root.getLastChild().getNodeName());
    Assert.assertEquals("added attribute", "3", ((Element) root.getLastChild()).getAttribute("id"));

    root.setAttribute("id", "root");
    Assert.assertEquals("root attribute set", "root", root.getAttribute("id"));
    root.removeAttribute("id");
    Assert.assertEquals("root attribute remove", null, root.getAttribute("id"));

    root.removeChild(appended);
    Assert.assertEquals("removed element", "child", root.getLastChild().getNodeName());
    Assert.assertEquals("removed element", "2", ((Element) root.getLastChild()).getAttribute("id"));
  }
Ejemplo n.º 15
0
 @Override
 public void apply(Element e) {
   if (e.getTagName().equals("property")) {
     Element parent = (Element) e.getParentNode();
     if (parent != null && parent.getTagName().equals("ndbx")) {
       Attr name = e.getAttributeNode("name");
       Attr value = e.getAttributeNode("value");
       if (name != null && name.getValue().equals("oscPort")) {
         if (value != null) {
           Element device = e.getOwnerDocument().createElement("device");
           device.setAttribute("name", "osc1");
           device.setAttribute("type", "osc");
           Element portProperty = e.getOwnerDocument().createElement("property");
           portProperty.setAttribute("name", "port");
           portProperty.setAttribute("value", value.getValue());
           device.appendChild(portProperty);
           Element autostartProperty = e.getOwnerDocument().createElement("property");
           autostartProperty.setAttribute("name", "autostart");
           autostartProperty.setAttribute("value", "true");
           device.appendChild(autostartProperty);
           parent.replaceChild(device, e);
         } else {
           parent.removeChild(e);
         }
       }
     }
   }
 }
Ejemplo n.º 16
0
  public void logUpdate(final Update update) {
    Element updateElement = createOrGetUpdateElement(update);

    int attempt = 1;
    try {
      attempt = Integer.parseInt(updateElement.getAttribute("attempt")) + 1;
      updates.removeChild(updateElement);
      updateElements.remove(update);

      updateElement = createOrGetUpdateElement(update);
    } catch (NumberFormatException ignored) {
    }

    updateElement.setAttribute("attempt", String.valueOf(attempt));
    updateElement.setAttribute(
        "time", FormatHelper.dateTimeToString(dateTimeProvider.getCurrentDateTime()));

    final RpslObject updatedObject = update.getSubmittedObject();
    updateElement.appendChild(keyValue("key", updatedObject.getFormattedKey()));
    updateElement.appendChild(keyValue("operation", update.getOperation().name()));
    updateElement.appendChild(
        keyValue("reason", StringUtils.join(update.getDeleteReasons(), ", ")));
    updateElement.appendChild(keyValue("paragraph", update.getParagraph().getContent()));
    updateElement.appendChild(keyValue("object", updatedObject.toString()));
  }
  GeoTiffMetaDataStack(final Node tiffTree) {
    ensureNonNull("tiffTree", tiffTree);
    this.tiffTree = tiffTree;
    this.ifd = (Element) getNodeByLocalName(tiffTree, TAG_GEOTIFF_IFD);

    // remove previous tags if exists
    final Node nAscii = getNodeByNumber(ifd, getGeoAsciiParamsTag().getNumber());
    if (nAscii != null) {
      ifd.removeChild(nAscii);
    }

    final Node nDoubles = getNodeByNumber(ifd, getGeoDoubleParamsTag().getNumber());
    if (nDoubles != null) {
      ifd.removeChild(nDoubles);
    }
  }
Ejemplo n.º 18
0
  private void updateScreenArea(String pngFile, Area area) throws Exception {
    String xmlArea = "./workspace/" + file.substring(0, file.indexOf("/")) + "/screen_area.xml";
    XmlUtil xmlUtil = new XmlUtil(xmlArea);
    Document doc = xmlUtil.parse(xmlArea);
    Element root = doc.getDocumentElement();

    NodeList childs = root.getChildNodes();
    if (childs != null) {
      // del
      for (int i = 0; i < childs.getLength(); i++) {
        Node node = childs.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
          NamedNodeMap map = node.getAttributes();
          String fileName = map.getNamedItem("file").getNodeValue();
          if (fileName.equals(pngFile)) {
            root.removeChild(node);
            break;
          }
        }
      }
    }

    // add
    Hashtable<String, String> attri = new Hashtable();
    attri.put("file", area.getFile());
    attri.put("x", String.valueOf(area.getX()));
    attri.put("y", String.valueOf(area.getY()));
    attri.put("width", String.valueOf(area.getWidth()));
    attri.put("height", String.valueOf(area.getHeight()));
    xmlUtil.appendNode(root.getOwnerDocument(), "area", "", attri);
    xmlUtil.flush(doc);
  }
Ejemplo n.º 19
0
  /**
   * Get the parm edit set if any from the plf and process each edit command removing any that fail
   * from the set so that the set is self cleaning.
   *
   * @throws Exception
   */
  static void applyAndUpdateParmEditSet(Document plf, Document ilf, IntegrationResult result) {

    Element pSet = null;
    try {
      pSet = getParmEditSet(plf, null, false);
    } catch (Exception e) {
      LOG.error("Exception occurred while getting user's DLM " + "paramter-edit-set.", e);
    }

    if (pSet == null) return;

    NodeList edits = pSet.getChildNodes();

    for (int i = edits.getLength() - 1; i >= 0; i--) {
      if (applyEdit((Element) edits.item(i), ilf) == false) {
        pSet.removeChild(edits.item(i));
        result.changedPLF = true;
      } else {
        result.changedILF = true;
      }
    }

    if (pSet.getChildNodes().getLength() == 0) {
      plf.getDocumentElement().removeChild(pSet);
      result.changedPLF = true;
    }
  }
Ejemplo n.º 20
0
 public void remove(Track track) {
   synchronized (this) {
     docElt.removeChild(track.getElement());
     tracks.remove(track);
     hash.remove(track.getKey());
   }
 }
  /**
   * This method updates the positions recorded in a position set to reflect the ids of the nodes in
   * the composite view of the layout. Any position nodes already in existence are reused to reduce
   * database interaction needed to generate a new ID attribute. If any are left over after updating
   * those position elements are removed. If no position set existed a new one is created for the
   * parent. If no ILF nodes are found in the parent node then the position set as a whole is
   * reclaimed.
   */
  public static void updatePositionSet(Element compViewParent, Element plfParent, IPerson person)
      throws PortalException {
    if (LOG.isDebugEnabled()) LOG.debug("Updating Position Set");

    if (compViewParent.getChildNodes().getLength() == 0) {
      // no nodes to position. if set exists reclaim the space.
      if (LOG.isDebugEnabled()) LOG.debug("No Nodes to position");
      Element positions = getPositionSet(plfParent, person, false);
      if (positions != null) plfParent.removeChild(positions);
      return;
    }
    Element posSet = (Element) getPositionSet(plfParent, person, true);
    Element position = (Element) posSet.getFirstChild();
    Element viewNode = (Element) compViewParent.getFirstChild();
    boolean ilfNodesFound = false;

    while (viewNode != null) {
      String ID = viewNode.getAttribute(Constants.ATT_ID);
      String channelId = viewNode.getAttribute(Constants.ATT_CHANNEL_ID);
      String type = viewNode.getAttribute(Constants.ATT_TYPE);
      String hidden = viewNode.getAttribute(Constants.ATT_HIDDEN);

      if (ID.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) ilfNodesFound = true;

      if (!channelId.equals("")
          || // its a channel node or
          (type.equals("regular")
              && // a regular, visible folder
              hidden.equals("false"))) {
        if (position != null) position.setAttribute(Constants.ATT_NAME, ID);
        else position = createAndAppendPosition(ID, posSet, person);
        position = (Element) position.getNextSibling();
      }
      viewNode = (Element) viewNode.getNextSibling();
    }

    if (ilfNodesFound == false) // only plf nodes, no pos set needed
    plfParent.removeChild(posSet);
    else {
      // reclaim any leftover positions
      while (position != null) {
        Element nextPos = (Element) position.getNextSibling();
        posSet.removeChild(position);
        position = nextPos;
      }
    }
  }
Ejemplo n.º 22
0
  private void moveElementIntoElement(Element parentElement, Element movingElement) {
    // remove element from old parent
    Element oldParent = (Element) movingElement.getParentNode();
    oldParent.removeChild(movingElement);

    // append it into new parent
    parentElement.appendChild(movingElement);
  }
Ejemplo n.º 23
0
 private static void removeConnection(Element parent, String child, String input) {
   for (Element conn : childElementsWithName(parent, "conn")) {
     String inputPort = conn.getAttribute("input");
     if (inputPort.equals(String.format("%s.%s", child, input))) {
       parent.removeChild(conn);
     }
   }
 }
 public void deleteGroup(LanguageGroup group, LanguageGroup parent, Language language) {
   Element languageElement = this.getLanguageElement(language);
   Element parentElement = getParentElement(parent, language);
   Element groupElement = factory.getGroupElement(languageElement, group);
   if (parentElement != null && groupElement != null) {
     parentElement.removeChild(groupElement);
     writeDocument();
   }
 }
Ejemplo n.º 25
0
 /**
  * Löscht eine Karte aus dem Backlog.
  *
  * @param ca_id
  */
 public void deleteCard(int ca_id) {
   cardElement = searchCard(ca_id);
   if (cardElement != null) {
     // Element aus der Datei löschen
     rootElement.removeChild(cardElement);
     // XML Datei aktualisieren
     updateXML(xmlPath);
   }
 }
Ejemplo n.º 26
0
  public void removeExpired() {
    NodeList invitationList = invitationRoot.getElementsByTagName("invitation");

    if (invitationList == null) {
      return;
    }

    Vector expiredList = new Vector();

    int listLength = invitationList.getLength();

    for (int i = 0; i < listLength; i++) {
      Element invitationElement = (Element) invitationList.item(i);

      String expirationString = XmlUtil.getChildText(invitationElement, "expires");

      if (expirationString != null) {
        long expiration = 0L;

        try {
          expiration = Long.parseLong(expirationString);
        } catch (NumberFormatException nfe) {
        }

        if (System.currentTimeMillis() > expiration) {
          expiredList.add(invitationElement);
        }
      }
    }

    int expiredNum = expiredList.size();

    for (int i = expiredList.size() - 1; i >= 0; i--) {
      Element expiredElement = (Element) expiredList.elementAt(i);

      String type = XmlUtil.getChildText(expiredElement, "type");

      if ((type != null) && type.equals(INVITATION_TYPE_TREE)) {
        String virtualUser = XmlUtil.getChildText(expiredElement, "virtualUser");

        if ((virtualUser != null) && (virtualUser.trim().length() > 0)) {
          WebFileSys.getInstance().getUserMgr().removeUser(virtualUser);
          Logger.getLogger(getClass()).debug("expired virtual user " + virtualUser + " removed");
        }
      }

      invitationRoot.removeChild(expiredElement);
    }

    if (expiredNum > 0) {
      changed = true;
    }

    Logger.getLogger(getClass()).info(expiredNum + " expired invitations removed");
    Logger.getLogger(getClass()).info(expiredNum + " expired invitations removed");
  }
Ejemplo n.º 27
0
  private static void removeConnections(Element parent, String child) {
    for (Element conn : childElementsWithName(parent, "conn")) {
      String inputPort = conn.getAttribute("input");
      String inputNode = inputPort.split("\\.")[0];

      String outputNode = conn.getAttribute("output");

      if (inputNode.equals(child) || outputNode.equals(child)) parent.removeChild(conn);
    }
  }
Ejemplo n.º 28
0
  public boolean unsubscribe(String virtualUser, String subscriberEmail, String code) {
    Element watchedInvitation = getInvitationElementByVirtualUser(virtualUser);
    if (watchedInvitation == null) {
      return false;
    }

    Element subscriberListElem = XmlUtil.getChildByTagName(watchedInvitation, "subscriberList");
    if (subscriberListElem == null) {
      return false;
    }

    NodeList subscriberList = subscriberListElem.getElementsByTagName("subscriber");

    if (subscriberList != null) {
      int listLength = subscriberList.getLength();
      for (int i = 0; i < listLength; i++) {
        Element subscriberElement = (Element) subscriberList.item(i);
        String email = XmlUtil.getChildText(subscriberElement, "email");
        if ((email != null) && email.equals(subscriberEmail)) {
          String subscriptionCode = XmlUtil.getChildText(subscriberElement, "code");
          if ((subscriptionCode != null) && subscriptionCode.equals(code)) {
            subscriberListElem.removeChild(subscriberElement);
            if (listLength == 1) {
              watchedInvitation.removeChild(subscriberListElem);
            }
            changed = true;
            return true;
          } else {
            Logger.getLogger(getClass())
                .warn(
                    "unsubscribe attempt with invalid code, virtualUser="******" email="
                        + subscriberEmail
                        + " code="
                        + code);
          }
        }
      }
    }
    return false;
  }
Ejemplo n.º 29
0
 private static void removeWhitespaceInMixedContentElements(Element element) {
   List<Element> childEls = getChildElements(element);
   if (childEls.size() > 0) {
     for (Node node : getWhitespaceNodes(element)) {
       element.removeChild(node);
     }
     for (Element childEl : childEls) {
       removeWhitespaceInMixedContentElements(childEl);
     }
   }
 }
Ejemplo n.º 30
0
 public static void removeWhitespaceNodes(Element e) {
   NodeList children = e.getChildNodes();
   for (int i = children.getLength() - 1; i >= 0; i--) {
     Node child = children.item(i);
     if (child instanceof Text && ((Text) child).getData().trim().length() == 0) {
       e.removeChild(child);
     } else if (child instanceof Element) {
       removeWhitespaceNodes((Element) child);
     }
   }
 }