Пример #1
0
  private Element getParent(TextMapElement item) {
    Element parent = (Element) item.n.getParent();
    while (sm.getSemanticsTable().getSemanticTypeFromAttribute(parent) == null
        || sm.getSemanticsTable().getSemanticTypeFromAttribute(parent).equals("action")) {
      parent = (Element) parent.getParent();
    }

    return parent;
  }
Пример #2
0
  public synchronized void deletePath(PseudoPath path) {
    if (path.getNameCount() == 0) {
      throw new IllegalArgumentException("Empty path can not be deleted.");
    }

    Element toBeDeleted = getElement(path);
    if (toBeDeleted != null) {
      ParentNode parent = toBeDeleted.getParent();
      parent.removeChild(toBeDeleted);
    }
  }
Пример #3
0
 /**
  * Retrieve the nearest ancestor element that has the given name, or null if no such ancestor
  * exists.
  */
 public Element getAncestor(Element element, String localName, String namespaceURI) {
   ParentNode parent = element.getParent();
   if (parent != null && parent instanceof Element) {
     Element eparent = (Element) parent;
     if (eparent.getLocalName().equals(localName)
         && eparent.getNamespaceURI().equals(namespaceURI)) {
       return eparent;
     }
     return getAncestor(eparent, localName, namespaceURI);
   }
   return null;
 }
Пример #4
0
  /**
   * In the given glosslist (assuming 1 per doc) 1) collect all glossentries that are referenced
   * from outside the current glosslist 2) collect all glossentries that are referenced from the
   * entries in 1
   */
  private Document process(Document doc) {

    Nodes linkends = doc.getRootElement().query("//db:*[@linkend]", con);
    Nodes glosslists = doc.getRootElement().query("//db:glosslist", con);

    if (glosslists.size() > 1) throw new IllegalArgumentException("only one glosslist per doc");
    if (glosslists.size() == 0) return doc;

    Element glosslist = (Element) glosslists.get(0);

    // 1) collect all glossentries that are referenced from outside the current glosslist
    List<Element> usedGlossEntries = new LinkedList<Element>();
    Elements allGlossentries = glosslist.getChildElements("glossentry", dbns);

    for (int k = 0; k < allGlossentries.size(); k++) {
      Element glossentry = allGlossentries.get(k);
      String id = glossentry.getAttributeValue("id", xmlns);
      if (referencedFromOutside(id, linkends, glosslist)) {
        if (!contains(usedGlossEntries, glossentry)) {
          usedGlossEntries.add(glossentry);
        }
      }
    }

    // 2: go through usedEntries nested linkends, and add any referenced glossEntries
    // recursively until list stops growing
    while (true) {
      List<Element> moreUsedGlossEntries = recurse(glosslist, allGlossentries, usedGlossEntries);
      if (moreUsedGlossEntries.size() == 0) {
        break;
      }
      for (Element more : moreUsedGlossEntries) {
        if (!contains(usedGlossEntries, more)) {
          usedGlossEntries.add(more);
        }
      }
    }

    // finally, remove any unused glossentries
    for (int k = 0; k < allGlossentries.size(); k++) {
      Element glossentry = allGlossentries.get(k);
      if (!contains(usedGlossEntries, glossentry)) {
        glossentry.getParent().removeChild(glossentry);
      }
    }

    return doc;
  }
Пример #5
0
  public void setSelection(TextMapElement item) {
    Element parent = (Element) item.n.getParent();
    String text;
    if (item instanceof BrlOnlyMapElement && isBoxLine(item.parentElement())) {
      text = "boxline";
    } else {
      while (sm.getSemanticsTable().getSemanticTypeFromAttribute(parent) == null
          || sm.getSemanticsTable().getSemanticTypeFromAttribute(parent).equals("action")) {
        parent = (Element) parent.getParent();
      }
      text = sm.getSemanticsTable().getKeyFromAttribute(parent);

      if (text.contains("local_")) {
        String[] tokens = text.split("_");
        text = tokens[1];
      }
    }

    setSelection(searchTree(text));
  }
Пример #6
0
  /**
   * Removes a model. Removes extension and any files.
   *
   * @param model
   */
  public void removeModel(IDSTest model, String pluginID) {

    // Remove from DSBusinessModel
    dsBusinessModel.getTests().remove(model);
    for (Endpoint ep : dsBusinessModel.getEndpoints()) {
      if (ep.getTests() != null) {
        ep.getTests().remove(model);
        logger.debug("Removed model " + model.getName() + " from EP " + ep.getName());
      }
    }

    // Remove extensions in models.container plugin
    // =============================================
    File pluginXMLfile;
    try {
      pluginXMLfile = new File(FileUtil.getFilePath("plugin.xml", pluginID));

      Builder parser = new Builder();
      Document doc = parser.build(pluginXMLfile);
      Element root = doc.getRootElement();

      Element extension = null;

      // Find extension in plugin.xml, if exists
      Elements existingExtensions = root.getChildElements("extension");
      if (existingExtensions != null && existingExtensions.size() > 0) {
        for (int i = 0; i < existingExtensions.size(); i++) {
          extension = existingExtensions.get(i);

          // If exists a model with same name, remove it
          Elements existingTests = extension.getChildElements("test");
          if (existingTests != null && existingTests.size() > 0) {
            for (int j = 0; j < existingTests.size(); j++) {
              Element test = existingTests.get(j);
              String testName = test.getAttribute("name").getValue();

              // Remove spaces included by XML serialization
              while (testName.contains("  ")) testName = testName.replace("  ", " ");

              if (model.getName().equals(testName)) {
                test.getParent().removeChild(test);
                logger.debug("Removing existing model extension: " + model.getName());

                // Also remove the files
                Elements resources = test.getChildElements("resource");
                for (int rescnt = 0; rescnt < resources.size(); rescnt++) {
                  Element resource = resources.get(rescnt);
                  String path = resource.getAttribute("path").getValue();
                  try {
                    File reFile = new File(FileUtil.getFilePath(path, pluginID));
                    if (reFile.exists()) {
                      logger.debug("Removing file: " + reFile);
                      reFile.delete();
                    } else logger.debug("Unable to locate file to remove: " + path);
                  } catch (Exception e) {
                    logger.error("Problems removing file: " + path);
                  }
                }
              }
            }
          }
        }
      }

      // Serialize the updated plugin.xml to file
      Serializer serializer = new Serializer(new FileOutputStream(pluginXMLfile));
      serializer.setIndent(4);
      serializer.setMaxLength(64);
      serializer.write(doc);

    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ValidityException e) {
      e.printStackTrace();
    } catch (ParsingException e) {
      e.printStackTrace();
    }
  }