Esempio n. 1
0
  public int ajouterAlbum(String titreAlbum, String nomArtiste, int anneeAlbum) {

    if (!existeAlbum(titreAlbum, nomArtiste, anneeAlbum)) {
      ID++;
      Element id = document.createElement("id");
      id.setTextContent(Integer.toString(ID));
      Element titre = document.createElement("titre");
      titre.setTextContent(titreAlbum);
      Element artiste = document.createElement("artiste");
      artiste.setTextContent(nomArtiste);
      Element annee = document.createElement("annee");
      annee.setTextContent(Integer.toString(anneeAlbum));
      Element qte = document.createElement("qte");
      qte.setTextContent(Integer.toString(0));
      Element album = document.createElement("album");
      album.appendChild(id);
      album.appendChild(titre);
      album.appendChild(artiste);
      album.appendChild(annee);
      album.appendChild(qte);
      Element stock = (Element) document.getElementsByTagName("stock").item(0);
      stock.appendChild(album);
      try {
        save(encryptDocument(document), path);
      } catch (Exception ex) {
        Logger.getLogger(Inventaire.class.getName()).log(Level.SEVERE, null, ex);
      }
      return ID;
    }
    return -1;
  }
 public void addAppletElement(String appletAID, String className) {
   Element servlet = doc.createElement(XmlTagNames.XML_APPLET_TAG);
   Element sName = doc.createElement(XmlTagNames.XML_APPLET_AID_TAG);
   sName.setTextContent(appletAID);
   Element sClass = doc.createElement(XmlTagNames.XML_APPLET_CLASS_TAG);
   sClass.setTextContent(className);
   servlet.appendChild(sClass);
   servlet.appendChild(sName);
   getAppletAppNode().appendChild(servlet);
 }
Esempio n. 3
0
 private Element addSubelementImpl(Element element, String name, String textContent) {
   if (element != null) {
     Element subElement = m_document.createElement(name);
     subElement.setTextContent(textContent);
     element.appendChild(subElement);
     return subElement;
   } else return null;
 }
Esempio n. 4
0
 private Element addEventElementImpl(String name, String textContent) {
   if (m_currentEvent != null) {
     Element element = m_document.createElement(name);
     element.setTextContent(textContent);
     m_currentEvent.appendChild(element);
     return element;
   } else return null;
 }
Esempio n. 5
0
  /**
   * Gets XML string for this definition so that it may be printed.
   *
   * @return XML node that can be saved of this word.
   */
  public Element getWordXMLNode(Document doc) {
    try {
      Element rootWordElement = doc.createElement("WordDefinitions");
      rootWordElement.setAttribute("word", this.word);
      rootWordElement.setAttribute("mainDefinition", this.getMainDefinition());
      if (this.otherDefinitions == null) {
        this.getDefinitions();
      }
      for (int i = 0; i < this.otherDefinitions.length; i++) {
        // main definition node
        Element definition = doc.createElement("Definition");

        // word
        Element word = doc.createElement("Word");
        word.setTextContent(otherDefinitions[i].getWord());

        // dictionary
        Element dictionary = doc.createElement("Dictionary");
        Element id = doc.createElement("Id");
        id.setTextContent(otherDefinitions[i].getId());
        Element source = doc.createElement("Name");
        source.setTextContent(otherDefinitions[i].getSource());
        dictionary.appendChild(id);
        dictionary.appendChild(source);

        // definition
        Element wordDefinition = doc.createElement("WordDefinition");
        wordDefinition.setTextContent(otherDefinitions[i].getDefinition());

        // append all the children
        definition.appendChild(word);
        definition.appendChild(dictionary);
        definition.appendChild(wordDefinition);
        rootWordElement.appendChild(definition);
      }
      return rootWordElement;
    } catch (Exception ex) {
      ex.printStackTrace();
      return null;
    }
  }
Esempio n. 6
0
  /**
   * Create an event that can be populated using its reference.
   *
   * @param type The event's type.
   * @param t The event's time stamp.
   * @return The pointer to the event.
   */
  public Element newEvent(String source, String type, int t) {
    Element event = m_document.createElement("event");

    event.setAttribute("id", m_id + "");
    event.setAttribute("source", source);
    event.setAttribute("date", t + "");
    m_id++;

    Element ty = m_document.createElement("type");
    ty.setTextContent(type);
    event.appendChild(ty);

    m_sequence.appendChild(event);

    return event;
  }
Esempio n. 7
0
  public void addFightInfo(Element e) {
    NumberFormat nf = WLPNumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
    Element mergedElement = doc.createElement(mergedTag);
    mergedElement.setTextContent("" + fight.isMerged());
    e.appendChild(mergedElement);

    Element durationElement = doc.createElement(durationTag);
    durationElement.setTextContent(nf.format(fight.getEndTime() - fight.getStartTime()));
    e.appendChild(durationElement);

    Element activeDurationElement = doc.createElement(activeDurationTag);
    activeDurationElement.setTextContent(nf.format(fight.getActiveDuration()));
    e.appendChild(activeDurationElement);

    Element numMobsElement = doc.createElement(numMobsTag);
    if (fight.isMerged()) {
      numMobsElement.setTextContent(nf.format(fight.getMergedSourceFights().size()));
      Element npcsElement = doc.createElement(npcsTag);
      e.appendChild(npcsElement);
      List<Fight> sourceFights = fight.getMergedSourceFights();
      for (Fight f : sourceFights) {
        Element npcElement = createNpcElement(f, nf);
        npcsElement.appendChild(npcElement);
      }
    } else {
      numMobsElement.setTextContent(nf.format(1));
      Element npcsElement = doc.createElement(npcsTag);
      e.appendChild(npcsElement);
      Element npcElement = createNpcElement(fight, nf);
      npcsElement.appendChild(npcElement);
    }
    e.appendChild(numMobsElement);

    Element totalDamageElement = doc.createElement(totalDamageTag);
    Element totalHealingElement = doc.createElement(totalHealingTag);
    long damage = 0;
    long healing = 0;
    for (FightParticipant p : fight.getParticipants()) {
      AmountAndCount a = p.totalDamage(Constants.SCHOOL_ALL, FightParticipant.TYPE_ALL_DAMAGE);
      damage += a.amount;
      a = p.totalHealing(Constants.SCHOOL_ALL, FightParticipant.TYPE_ALL_HEALING);
      healing += a.amount;
    }
    totalDamageElement.setTextContent(nf.format(damage));
    e.appendChild(totalDamageElement);
    totalHealingElement.setTextContent(nf.format(healing));
    e.appendChild(totalHealingElement);

    Element dispellInfoElement = doc.createElement(dispellInfoTag);
    DispellEvents de = new DispellEvents(fight.getEvents());
    int numNames = de.getNumNames();
    for (int k = 0; k < numNames; k++) {
      String auraName = de.getName(k);
      Element auraElement = doc.createElement(auraDispelledTag);
      auraElement.setAttribute(nameTag, auraName);
      List<SpellAuraDispelledEvent> events = de.getEvents(auraName);
      for (SpellAuraDispelledEvent ev : events) {
        Element eventElement = doc.createElement(dispEventTag);
        ev.addXmlAttributes(eventElement);
        //                eventElement.setAttribute(sourceTag, ev.sourceName);
        //                eventElement.setAttribute(sourceGuidTag, ev.sourceGUID);
        //                eventElement.setAttribute(skillTag, ev.getName());
        //                eventElement.setAttribute(targetTag, ev.destinationName);
        //                eventElement.setAttribute(destinationGuidTag, ev.destinationGUID);
        //                eventElement.setAttribute(timeTag, ev.getTimeStringExact());
        auraElement.appendChild(eventElement);
      }
      dispellInfoElement.appendChild(auraElement);
    }
    e.appendChild(dispellInfoElement);

    Element interruptInfoElement = doc.createElement(interruptInfoTag);
    InterruptEvents ie = new InterruptEvents(fight.getEvents());
    numNames = ie.getNumNames();
    for (int k = 0; k < numNames; k++) {
      String spellName = ie.getName(k);
      Element spellElement = doc.createElement(spellInterruptedTag);
      spellElement.setAttribute(nameTag, spellName);
      List<SpellInterruptEvent> events = ie.getEvents(spellName);
      for (SpellInterruptEvent ev : events) {
        Element eventElement = doc.createElement(intEventTag);
        ev.addXmlAttributes(eventElement);
        //                eventElement.setAttribute(sourceTag, ev.sourceName);
        //                eventElement.setAttribute(skillTag, ev.getName());
        //                eventElement.setAttribute(targetTag, ev.destinationName);
        //                eventElement.setAttribute(timeTag, ev.getTimeStringExact());
        spellElement.appendChild(eventElement);
      }
      interruptInfoElement.appendChild(spellElement);
    }
    e.appendChild(interruptInfoElement);
  }
Esempio n. 8
0
  protected void getBeanElementProperties(Element element, Object bean, PropertyDescriptor pd)
      throws IntrospectionException, IllegalAccessException {
    Element propertyElement = null;
    Class classOfProperty = pd.getPropertyType();
    Object[] argsNone = {};
    // If the property is "class" and the type is java.lang.Class.class then
    // this is the class of the bean, which we've already encoded.
    // In this special case, return null.
    if (!((pd.getName().charAt(0) == 'c') && pd.getName().equals("class"))
        && !classOfProperty.equals(java.lang.Class.class)) {
      // Don't process property if it is in the list of fields to be ignored
      boolean omittedField = false;
      try {
        Field field = bean.getClass().getDeclaredField(pd.getName());
        omittedField = field.isAnnotationPresent(ObjectXmlOmitField.class);
      } catch (NoSuchFieldException nsfe) {
      }
      if (!omittedField) {
        String propertyName = formatName(pd.getName());
        // Hereafter, we're trying to create a representation of the property
        // based on the property's value.
        // The very first thing we need to do is get the value of the
        // property as an object. If we can't do that, we can't get any
        // representation of the property at all.
        Object propertyValue = null;
        try {
          Method getter = pd.getReadMethod();
          if (getter != null) {
            propertyValue = getter.invoke(bean, argsNone);
          }
        } catch (Exception ex) {
          // couldn't get value
          System.err.println(ex.getMessage());
        }
        // See if this property's value is something we can represent as a
        // standard data type that can be converted to an xsd type,
        // or if it's something that must be represented as a JavaBean.
        if (propertyElement == null) {

          PropertyEditor propEditor = PropertyEditorManager.findEditor(classOfProperty);
          // If the property editor is not null, pass the property's
          // value to the PropertyEditor, and then ask the PropertyEditor
          // for the object and then attempt to convert it to a standard type.

          if ((propEditor != null)
              || (classOfProperty == java.util.Calendar.class)
              || (classOfProperty == java.util.Date.class)) {
            // The object is a standard type
            // (e.g. a wrapper around a primitive type, a String, or a Date or Calendar object)
            try {
              Object object;
              if ((classOfProperty == java.util.Calendar.class)
                  || (classOfProperty == java.util.Date.class)) object = propertyValue;
              else {
                propEditor.setValue(propertyValue);
                object = propEditor.getValue();
              }
              Element childElement = getStandardObjectElement(document, object, propertyName);
              if (includeNullValues
                  || !childElement
                      .getAttribute(
                          NamespaceConstants.NSPREFIX_SCHEMA_XSI
                              + ":"
                              + org.apache.axis.Constants.ATTR_TYPE)
                      .equals("anyType")) {
                if (!includeTypeInfo) {
                  childElement.removeAttribute(
                      NamespaceConstants.NSPREFIX_SCHEMA_XSI
                          + ":"
                          + org.apache.axis.Constants.ATTR_TYPE);
                  childElement.removeAttribute(NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":null");
                }
                try {
                  Field field = bean.getClass().getDeclaredField(propertyName);
                  if (field.isAnnotationPresent(ObjectXmlAsAttribute.class)) {
                    String attrName = null;
                    if (includeTypeInfo) attrName = nsPrefix + ":" + propertyName;
                    else attrName = propertyName;
                    element.setAttribute(attrName, childElement.getFirstChild().getNodeValue());
                  } else if (field.isAnnotationPresent(ObjectXmlAsValue.class))
                    element.setTextContent(childElement.getFirstChild().getNodeValue());
                  else element.appendChild(childElement);
                } catch (NoSuchFieldException nfse) {
                  element.appendChild(childElement);
                }
              }
            } catch (Exception e) {
            }
          } else {
            // The object is not an XSD-encoded datatype, it must be a JavaBean
            try {
              String propertyTypeName = null;
              if (propertyValue != null) {
                // get object type
                Class propertyType = pd.getPropertyType();
                propertyTypeName = propertyType.getName();
              }
              getBeanElements(element, propertyName, propertyTypeName, propertyValue);
            } catch (Exception e) {
            }
          }
        }
      }
    }
  }
 void appendCellToRow(Element tableRow, String content) {
   Element newCell = document.createElement("td");
   newCell.setTextContent(content);
   tableRow.appendChild(newCell);
 }
  public boolean runTest(Test test) throws Exception {
    String filename = test.file.toString();
    if (this.verbose) {
      System.out.println(
          "Running "
              + filename
              + " against "
              + this.host
              + ":"
              + this.port
              + " with "
              + this.browser);
    }
    this.document = parseDocument(filename);

    if (this.baseUrl == null) {
      NodeList links = this.document.getElementsByTagName("link");
      if (links.getLength() != 0) {
        Element link = (Element) links.item(0);
        setBaseUrl(link.getAttribute("href"));
      }
    }
    if (this.verbose) {
      System.out.println("Base URL=" + this.baseUrl);
    }

    Node body = this.document.getElementsByTagName("body").item(0);
    Element resultContainer = document.createElement("div");
    resultContainer.setTextContent("Result: ");
    Element resultElt = document.createElement("span");
    resultElt.setAttribute("id", "result");
    resultElt.setIdAttribute("id", true);
    resultContainer.appendChild(resultElt);
    body.insertBefore(resultContainer, body.getFirstChild());

    Element executionLogContainer = document.createElement("div");
    executionLogContainer.setTextContent("Execution Log:");
    Element executionLog = document.createElement("div");
    executionLog.setAttribute("id", "log");
    executionLog.setIdAttribute("id", true);
    executionLog.setAttribute("style", "white-space: pre;");
    executionLogContainer.appendChild(executionLog);
    body.appendChild(executionLogContainer);

    NodeList tableRows = document.getElementsByTagName("tr");
    Element theadRow = (Element) tableRows.item(0);
    test.name = theadRow.getTextContent();
    appendCellToRow(theadRow, "Result");

    this.commandProcessor =
        new HtmlCommandProcessor(this.host, this.port, this.browser, this.baseUrl);
    String resultState;
    String resultLog;
    test.result = true;
    try {
      this.commandProcessor.start();
      test.commands = new Command[tableRows.getLength() - 1];
      for (int i = 1; i < tableRows.getLength(); i++) {
        Element stepRow = (Element) tableRows.item(i);
        Command command = executeStep(stepRow);
        appendCellToRow(stepRow, command.result);
        test.commands[i - 1] = command;
        if (command.error) {
          test.result = false;
        }
        if (command.failure) {
          test.result = false;
          // break;
        }
      }
      resultState = test.result ? "PASSED" : "FAILED";
      resultLog = (test.result ? "Test Complete" : "Error");
      this.commandProcessor.stop();
    } catch (Exception e) {
      test.result = false;
      resultState = "ERROR";
      resultLog = "Failed to initialize session\n" + e;
      e.printStackTrace();
    }
    document.getElementById("result").setTextContent(resultState);
    Element log = document.getElementById("log");
    log.setTextContent(log.getTextContent() + resultLog + "\n");
    return test.result;
  }
Esempio n. 11
0
  public void addPackageClass(PackageClass pClass) {

    Document doc;
    try {
      doc = getDocument();
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    String name = pClass.getName();

    // check if such class exists and remove duplicates
    Element rootEl = doc.getDocumentElement();
    NodeList classEls = rootEl.getElementsByTagName(EL_CLASS);
    for (int i = 0; i < classEls.getLength(); i++) {
      Element nameEl = getElementByName((Element) classEls.item(i), EL_NAME);
      if (name.equals(nameEl.getTextContent())) {
        rootEl.removeChild(classEls.item(i));
      }
    }

    Element classNode = doc.createElement(EL_CLASS);
    doc.getDocumentElement().appendChild(classNode);
    classNode.setAttribute(ATR_TYPE, PackageClass.ComponentType.SCHEME.getXmlName());
    classNode.setAttribute(ATR_STATIC, "false");

    Element className = doc.createElement(EL_NAME);
    className.setTextContent(name);
    classNode.appendChild(className);

    Element desrc = doc.createElement(EL_DESCRIPTION);
    desrc.setTextContent(pClass.getDescription());
    classNode.appendChild(desrc);

    Element icon = doc.createElement(EL_ICON);
    icon.setTextContent(pClass.getIcon());
    classNode.appendChild(icon);

    // graphics
    classNode.appendChild(generateGraphicsNode(doc, pClass.getGraphics()));

    // ports
    List<Port> ports = pClass.getPorts();
    if (!ports.isEmpty()) {
      Element portsEl = doc.createElement(EL_PORTS);
      classNode.appendChild(portsEl);

      for (Port port : ports) {
        portsEl.appendChild(generatePortNode(doc, port));
      }
    }

    // fields
    Collection<ClassField> fields = pClass.getFields();
    if (!fields.isEmpty()) {
      Element fieldsEl = doc.createElement(EL_FIELDS);
      classNode.appendChild(fieldsEl);

      for (ClassField cf : fields) {
        fieldsEl.appendChild(generateFieldNode(doc, cf));
      }
    }

    // write
    try {
      writeDocument(doc, new FileOutputStream(xmlFile));
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }