protected Document generateAntTask() {
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      Document doc = factory.newDocumentBuilder().newDocument();
      Element root = doc.createElement("project"); // $NON-NLS-1$
      root.setAttribute("name", "build"); // $NON-NLS-1$ //$NON-NLS-2$
      root.setAttribute("default", "feature_export"); // $NON-NLS-1$ //$NON-NLS-2$
      doc.appendChild(root);

      Element target = doc.createElement("target"); // $NON-NLS-1$
      target.setAttribute("name", "feature_export"); // $NON-NLS-1$ //$NON-NLS-2$
      root.appendChild(target);

      Element export = doc.createElement("pde.exportFeatures"); // $NON-NLS-1$
      export.setAttribute("features", getFeatureIDs()); // $NON-NLS-1$
      export.setAttribute("destination", fPage.getDestination()); // $NON-NLS-1$
      String filename = fPage.getFileName();
      if (filename != null) export.setAttribute("filename", filename); // $NON-NLS-1$
      export.setAttribute("exportType", getExportOperation()); // $NON-NLS-1$
      export.setAttribute("useJARFormat", Boolean.toString(fPage.useJARFormat())); // $NON-NLS-1$
      export.setAttribute("exportSource", Boolean.toString(fPage.doExportSource())); // $NON-NLS-1$
      if (fPage.doExportSource()) {
        export.setAttribute(
            "exportSourceBundle", Boolean.toString(fPage.doExportSourceBundles())); // $NON-NLS-1$
      }
      String qualifier = fPage.getQualifier();
      if (qualifier != null) export.setAttribute("qualifier", qualifier); // $NON-NLS-1$
      target.appendChild(export);
      return doc;
    } catch (DOMException e) {
    } catch (FactoryConfigurationError e) {
    } catch (ParserConfigurationException e) {
    }
    return null;
  }
예제 #2
0
  /**
   * This method exports the single pattern decision instance to the XML. It MUST be called by an
   * XML exporter, as this will not have a complete header.
   *
   * @param ratDoc The ratDoc generated by the XML exporter
   * @return the SAX representation of the object.
   */
  public Element toXML(Document ratDoc) {
    Element decisionE;
    RationaleDB db = RationaleDB.getHandle();

    // Now, add pattern to doc
    String entryID = db.getRef(this);
    if (entryID == null) {
      entryID = db.addPatternDecisionRef(this);
    }

    decisionE = ratDoc.createElement("DR:patternDecision");
    decisionE.setAttribute("rid", entryID);
    decisionE.setAttribute("name", name);
    decisionE.setAttribute("type", type.toString());
    decisionE.setAttribute("phase", devPhase.toString());
    decisionE.setAttribute("status", status.toString());
    // decisionE.setAttribute("artifact", artifact);

    Element descE = ratDoc.createElement("description");
    Text descText = ratDoc.createTextNode(description);
    descE.appendChild(descText);
    decisionE.appendChild(descE);

    // Add child pattern references...
    Iterator<Pattern> cpi = candidatePatterns.iterator();
    while (cpi.hasNext()) {
      Pattern cur = cpi.next();
      Element curE = ratDoc.createElement("refChildPattern");
      Text curText = ratDoc.createTextNode("p" + new Integer(cur.getID()).toString());
      curE.appendChild(curText);
      decisionE.appendChild(curE);
    }

    return decisionE;
  }
예제 #3
0
  public void saveToXml(String fileName)
      throws ParserConfigurationException, FileNotFoundException, TransformerException,
          TransformerConfigurationException {
    System.out.println("Saving network topology to file " + fileName);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document doc = parser.newDocument();

    Element root = doc.createElement("neuralNetwork");
    root.setAttribute("dateOfExport", new Date().toString());
    Element layers = doc.createElement("structure");
    layers.setAttribute("numberOfLayers", Integer.toString(this.numberOfLayers()));

    for (int il = 0; il < this.numberOfLayers(); il++) {
      Element layer = doc.createElement("layer");
      layer.setAttribute("index", Integer.toString(il));
      layer.setAttribute("numberOfNeurons", Integer.toString(this.getLayer(il).numberOfNeurons()));

      for (int in = 0; in < this.getLayer(il).numberOfNeurons(); in++) {
        Element neuron = doc.createElement("neuron");
        neuron.setAttribute("index", Integer.toString(in));
        neuron.setAttribute(
            "NumberOfInputs", Integer.toString(this.getLayer(il).getNeuron(in).numberOfInputs()));
        neuron.setAttribute(
            "threshold", Double.toString(this.getLayer(il).getNeuron(in).threshold));

        for (int ii = 0; ii < this.getLayer(il).getNeuron(in).numberOfInputs(); ii++) {
          Element input = doc.createElement("input");
          input.setAttribute("index", Integer.toString(ii));
          input.setAttribute(
              "weight", Double.toString(this.getLayer(il).getNeuron(in).getInput(ii).weight));

          neuron.appendChild(input);
        }

        layer.appendChild(neuron);
      }

      layers.appendChild(layer);
    }

    root.appendChild(layers);
    doc.appendChild(root);

    // save
    File xmlOutputFile = new File(fileName);
    FileOutputStream fos;
    Transformer transformer;

    fos = new FileOutputStream(xmlOutputFile);
    // Use a Transformer for output
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(fos);
    // transform source into result will do save
    transformer.setOutputProperty("encoding", "iso-8859-2");
    transformer.setOutputProperty("indent", "yes");
    transformer.transform(source, result);
  }
예제 #4
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);
         }
       }
     }
   }
 }
예제 #5
0
  /** @see com.levelonelabs.aim.XMLizable#writeState(Element) */
  public void writeState(Element emptyStateElement) {
    Document doc = emptyStateElement.getOwnerDocument();
    emptyStateElement.setAttribute("name", this.getName());
    emptyStateElement.setAttribute("group", this.getGroup());
    emptyStateElement.setAttribute("isBanned", Boolean.toString(this.isBanned()));

    Iterator roleit = roles.keySet().iterator();
    while (roleit.hasNext()) {
      String role = (String) roleit.next();
      Element roleElem = doc.createElement("role");
      roleElem.setAttribute("name", role);
      emptyStateElement.appendChild(roleElem);
    }

    Iterator prefs = preferences.keySet().iterator();
    while (prefs.hasNext()) {
      String pref = (String) prefs.next();
      Element prefElem = doc.createElement("preference");
      prefElem.setAttribute("name", pref);
      prefElem.setAttribute("value", (String) preferences.get(pref));
      emptyStateElement.appendChild(prefElem);
    }

    for (int i = 0; i < messages.size(); i++) {
      String message = (String) messages.get(i);
      Element messElem = doc.createElement("message");
      CDATASection data = doc.createCDATASection(message);
      messElem.appendChild(data);
      emptyStateElement.appendChild(messElem);
    }
  }
 /**
  * Marshall an array of Genes to an XML Element representation.
  *
  * @param a_geneValues the genes to represent as an XML element
  * @param a_xmlDocument a Document instance that will be used to create the Element instance. Note
  *     that the element will NOT be added to the document by this method
  * @return an Element object representing the given genes
  * @author Neil Rotstan
  * @author Klaus Meffert
  * @since 1.0
  * @deprecated use XMLDocumentBuilder instead
  */
 public static Element representGenesAsElement(
     final Gene[] a_geneValues, final Document a_xmlDocument) {
   // Create the parent genes element.
   // --------------------------------
   Element genesElement = a_xmlDocument.createElement(GENES_TAG);
   // Now add gene sub-elements for each gene in the given array.
   // -----------------------------------------------------------
   Element geneElement;
   for (int i = 0; i < a_geneValues.length; i++) {
     // Create the allele element for this gene.
     // ----------------------------------------
     geneElement = a_xmlDocument.createElement(GENE_TAG);
     // Add the class attribute and set its value to the class
     // name of the concrete class representing the current Gene.
     // ---------------------------------------------------------
     geneElement.setAttribute(CLASS_ATTRIBUTE, a_geneValues[i].getClass().getName());
     // Create a text node to contain the string representation of
     // the gene's value (allele).
     // ----------------------------------------------------------
     Element alleleRepresentation = representAlleleAsElement(a_geneValues[i], a_xmlDocument);
     // And now add the text node to the gene element, and then
     // add the gene element to the genes element.
     // -------------------------------------------------------
     geneElement.appendChild(alleleRepresentation);
     genesElement.appendChild(geneElement);
   }
   return genesElement;
 }
 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);
 }
예제 #8
0
  /**
   * Creates an Element(or Node in XML in Document d) for single component
   *
   * @param x the component for which Element will be created
   * @param d Where the element will be added
   * @return the Element(for XML) created from component x
   */
  private Element createCmpEle(component x, Document d) {
    Element cmp_el = d.createElement("comp");
    cmp_el.setAttribute("id", String.valueOf(x.getId()));

    Element type_el = d.createElement("comp_type_id");
    Text type_txt = d.createTextNode(String.valueOf(x.getType().getId()));
    type_el.appendChild(type_txt);
    cmp_el.appendChild(type_el);

    Element pkg_el = d.createElement("pkg_name");
    Text pkg_txt = d.createTextNode(x.getType().getType_pkg_name());
    pkg_el.appendChild(pkg_txt);
    cmp_el.appendChild(pkg_el);

    Element pos_el = d.createElement("position");

    Element x_el = d.createElement("x");
    Text x_txt = d.createTextNode(String.valueOf(x.getPosition().x));
    x_el.appendChild(x_txt);
    pos_el.appendChild(x_el);

    Element y_el = d.createElement("y");
    Text y_txt = d.createTextNode(String.valueOf(x.getPosition().y));
    y_el.appendChild(y_txt);
    pos_el.appendChild(y_el);

    cmp_el.appendChild(pos_el);

    return cmp_el;
  }
예제 #9
0
  protected Element createCaseElement(Document doc, Case c) {
    Element elem = createElement(doc, CASE_NAME, null, null);

    int[] decomposition = c.getInput();
    elem.appendChild(createElement(doc, CASE_U_NAME, null, "" + decomposition[0]));
    elem.appendChild(createElement(doc, CASE_V_NAME, null, "" + decomposition[1]));
    elem.appendChild(createElement(doc, CASE_X_NAME, null, "" + decomposition[2]));
    elem.appendChild(createElement(doc, CASE_Y_NAME, null, "" + decomposition[3]));
    elem.appendChild(createElement(doc, CASE_I_NAME, null, "" + c.getI()));
    return elem;
  }
예제 #10
0
 public void toWrite(int size, String[] mycontent) {
   Element root = document.createElement("WorkShop");
   document.appendChild(root);
   Element title = document.createElement("Size");
   title.appendChild(document.createTextNode(size + ""));
   root.appendChild(title);
   for (int i = 0; i < size; i++) {
     Element content = document.createElement("Content" + i);
     content.appendChild(document.createTextNode(mycontent[i]));
     root.appendChild(content);
   }
 }
예제 #11
0
  /**
   * Converts value object to XML representation.
   *
   * @return Element.
   */
  public Element toXml(Document doc) {
    Element root = doc.createElement("InvoiceCustDetail");
    root.setAttribute("Id", String.valueOf(mOrderItemData));

    Element node;

    node = doc.createElement("InvoiceCustDetailData");
    node.appendChild(doc.createTextNode(String.valueOf(mInvoiceCustDetailData)));
    root.appendChild(node);

    return root;
  }
예제 #12
0
  private void addChannel(Document doc, Element root, Integer channel, HashSet<Integer> values) {
    Element el = doc.createElement(_channel);
    Attr attr = doc.createAttribute(_number);
    attr.setValue(Integer.toString(channel + 1));
    el.setAttributeNode(attr);
    Text txt;
    for (Integer x : values) {
      txt = doc.createTextNode(x.toString());
      el.appendChild(txt);
    }

    root.appendChild(el);
  }
예제 #13
0
  public Document toDOM(Serializable structure) {
    ContextFreePumpingLemma pl = (ContextFreePumpingLemma) structure;
    Document doc = newEmptyDocument();
    Element elem = doc.getDocumentElement();
    elem.appendChild(createElement(doc, LEMMA_NAME, null, pl.getTitle()));
    elem.appendChild(createElement(doc, FIRST_PLAYER, null, pl.getFirstPlayer()));
    elem.appendChild(createElement(doc, M_NAME, null, "" + pl.getM()));
    elem.appendChild(createElement(doc, W_NAME, null, "" + pl.getW()));
    elem.appendChild(createElement(doc, I_NAME, null, "" + pl.getI()));
    elem.appendChild(createElement(doc, U_NAME, null, "" + pl.getU().length()));
    elem.appendChild(createElement(doc, V_NAME, null, "" + pl.getV().length()));
    elem.appendChild(createElement(doc, X_NAME, null, "" + pl.getX().length()));
    elem.appendChild(createElement(doc, Y_NAME, null, "" + pl.getY().length()));

    // Encode the list of attempts.
    ArrayList attempts = pl.getAttempts();
    if (attempts != null && attempts.size() > 0)
      for (int i = 0; i < attempts.size(); i++)
        elem.appendChild(createElement(doc, ATTEMPT, null, (String) attempts.get(i)));

    // Encode the list of attempts.
    ArrayList cases = pl.getDoneCases();
    if (cases != null && cases.size() > 0)
      for (int i = 0; i < cases.size(); i++)
        elem.appendChild(createCaseElement(doc, (Case) cases.get(i)));

    return doc;
  }
예제 #14
0
  protected void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    try {
      DateFormat df = DateFormat.getDateTimeInstance();
      String titleStr = "C3P0 Status - " + df.format(new Date());

      DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = fact.newDocumentBuilder();
      Document doc = db.newDocument();

      Element htmlElem = doc.createElement("html");
      Element headElem = doc.createElement("head");

      Element titleElem = doc.createElement("title");
      titleElem.appendChild(doc.createTextNode(titleStr));

      Element bodyElem = doc.createElement("body");

      Element h1Elem = doc.createElement("h1");
      h1Elem.appendChild(doc.createTextNode(titleStr));

      Element h3Elem = doc.createElement("h3");
      h3Elem.appendChild(doc.createTextNode("PooledDataSources"));

      Element pdsDlElem = doc.createElement("dl");
      pdsDlElem.setAttribute("class", "PooledDataSources");
      for (Iterator ii = C3P0Registry.getPooledDataSources().iterator(); ii.hasNext(); ) {
        PooledDataSource pds = (PooledDataSource) ii.next();
        StatusReporter sr = findStatusReporter(pds, doc);
        pdsDlElem.appendChild(sr.reportDtElem());
        pdsDlElem.appendChild(sr.reportDdElem());
      }

      headElem.appendChild(titleElem);
      htmlElem.appendChild(headElem);

      bodyElem.appendChild(h1Elem);
      bodyElem.appendChild(h3Elem);
      bodyElem.appendChild(pdsDlElem);
      htmlElem.appendChild(bodyElem);

      res.setContentType("application/xhtml+xml");

      TransformerFactory tf = TransformerFactory.newInstance();
      Transformer transformer = tf.newTransformer();
      Source src = new DOMSource(doc);
      Result result = new StreamResult(res.getOutputStream());
      transformer.transform(src, result);
    } catch (IOException e) {
      throw e;
    } catch (Exception e) {
      throw new ServletException(e);
    }
  }
예제 #15
0
  public void generate() throws SAXException, ProcessingException {
    if (log.isDebugEnabled()) log.debug("begin generate");
    contentHandler.startDocument();
    Document doc = XercesHelper.getNewDocument();
    Element root = doc.createElement("authentication");
    doc.appendChild(root);
    try {
      LoginContext lc = new LoginContext(jaasRealm, new InternalCallbackHandler());
      lc.login();
      Subject s = lc.getSubject();
      if (log.isDebugEnabled()) log.debug("Subject is: " + s.getPrincipals().toString());
      Element idElement = doc.createElement("ID");
      root.appendChild(idElement);

      Iterator it = s.getPrincipals(java.security.Principal.class).iterator();
      while (it.hasNext()) {
        Principal prp = (Principal) it.next();
        if (prp.getName().equalsIgnoreCase("Roles")) {
          Element roles = doc.createElement("roles");
          root.appendChild(roles);
          Group grp = (Group) prp;
          Enumeration member = grp.members();
          while (member.hasMoreElements()) {
            Principal sg = (Principal) member.nextElement();
            Element role = doc.createElement("role");
            roles.appendChild(role);
            Text txt = doc.createTextNode(sg.getName());
            role.appendChild(txt);
          }
        } else {
          Node nde = doc.createTextNode(prp.getName());
          idElement.appendChild(nde);
        }
      }
      lc.logout();
    } catch (Exception exe) {
      log.warn("Could not login user \"" + userid + "\"");
    } finally {
      try {
        DOMStreamer ds = new DOMStreamer(contentHandler);
        ds.stream(doc.getDocumentElement());
        contentHandler.endDocument();
      } catch (Exception exe) {
        log.error("Error streaming to dom", exe);
      }
      if (log.isDebugEnabled()) log.debug("end generate");
    }
  }
예제 #16
0
    /** Turns a List<CubicCurve2D.Float> into a SVG Element representing a sketch of that spline. */
    Element splineToSketch(SVGDocument document, List<CubicCurve2D.Float> spline) {
      String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;

      // <g> is an SVG group
      // TODO: add a random(ish) rotation to the group
      Element group = document.createElementNS(svgNS, "g");

      // For each curve in the path, draw along it using a "brush".  In
      // our case the brush is a simple circle, but this could be changed
      // to something more advanced.
      for (CubicCurve2D.Float curve : spline) {
        // TODO: magic number & step in loop guard
        for (double i = 0.0; i <= 1.0; i += 0.01) {
          Point2D result = evalParametric(curve, i);

          // Add random jitter at some random positive or negative
          // distance along the unit normal to the tangent of the
          // curve
          Point2D n = vectorUnitNormal(evalParametricTangent(curve, i));
          float dx = (float) ((Math.random() - 0.5) * n.getX());
          float dy = (float) ((Math.random() - 0.5) * n.getY());

          Element brush = document.createElementNS(svgNS, "circle");
          brush.setAttribute("cx", Double.toString(result.getX() + dx));
          brush.setAttribute("cy", Double.toString(result.getY() + dy));
          // TODO: magic number for circle radius
          brush.setAttribute("r", Double.toString(1.0));
          brush.setAttribute("fill", "green");
          brush.setAttributeNS(null, "z-index", Integer.toString(zOrder.CONTOUR.ordinal()));
          group.appendChild(brush);
        }
      }

      return group;
    }
  /**
   * 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);
  }
  public IXArchElement cloneElement(int depth) {
    synchronized (DOMUtils.getDOMLock(elt)) {
      Document doc = elt.getOwnerDocument();
      if (depth == 0) {
        Element cloneElt = (Element) elt.cloneNode(false);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt);
        cloneImpl.setXArch(getXArch());
        return cloneImpl;
      } else if (depth == 1) {
        Element cloneElt = (Element) elt.cloneNode(false);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt);
        cloneImpl.setXArch(getXArch());

        NodeList nl = elt.getChildNodes();
        int size = nl.getLength();
        for (int i = 0; i < size; i++) {
          Node n = nl.item(i);
          Node cloneNode = (Node) n.cloneNode(false);
          cloneNode = doc.importNode(cloneNode, true);
          cloneElt.appendChild(cloneNode);
        }
        return cloneImpl;
      } else /* depth = infinity */ {
        Element cloneElt = (Element) elt.cloneNode(true);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt);
        cloneImpl.setXArch(getXArch());
        return cloneImpl;
      }
    }
  }
 /**
  * Adds a template to a xml file.
  *
  * @param language template that should be added.
  * @return Element
  */
 private Element createLanguage(Language language) {
   Element newLanguage = this.factory.createLanguageElement(language);
   Element languages = this.getLanguagesElement();
   languages.appendChild(newLanguage);
   writeDocument();
   return newLanguage;
 }
  public void addGroup(LanguageGroup group, LanguageGroup parent, Language language) {
    Element parentElement = getParentElement(parent, language);

    Element newGroup = this.factory.createGroupElement(group);
    parentElement.appendChild(newGroup);
    writeDocument();
  }
예제 #21
0
 public static Element appendNode(Element self, Object name, String value) {
   Document doc = self.getOwnerDocument();
   Element newChild;
   if (name instanceof QName) {
     QName qn = (QName) name;
     newChild = doc.createElementNS(qn.getNamespaceURI(), qn.getQualifiedName());
   } else {
     newChild = doc.createElement(name.toString());
   }
   if (value != null) {
     Text text = doc.createTextNode(value);
     newChild.appendChild(text);
   }
   self.appendChild(newChild);
   return newChild;
 }
  private static void exportThisSeries(
      String name,
      String target_sea_state_datum,
      NamedList thisList,
      String[] sea_state_headings,
      Element itt,
      Document doc) {
    // ok, put us into the element
    org.w3c.dom.Element datum = doc.createElement(target_sea_state_datum);

    datum.setAttribute("Type", name);

    // and step through its values
    Collection<Double> indices = thisList.getValues();
    int ctr = 0;
    for (Iterator<Double> iter = indices.iterator(); iter.hasNext(); ) {
      Double val = (Double) iter.next();
      if (val != null) {
        datum.setAttribute(sea_state_headings[ctr], writeThis(val.doubleValue()));
        ctr++;
      } else break;
    }

    itt.appendChild(datum);
  }
  public static void exportThis(
      String target_sea_state_set,
      String target_sea_state_datum,
      String[] sea_state_headings,
      IntegerTargetTypeLookup states,
      Element envElement,
      Document doc) {
    // ok, put us into the element
    org.w3c.dom.Element itt = doc.createElement(target_sea_state_set);

    // get on with the name attribute
    Double unknown = states.getUnknownResult();
    if (unknown != null) itt.setAttribute(UNKNOWN_TYPE, writeThis(unknown.doubleValue()));

    // now the matrix of sea states
    Collection<String> keys = states.getNames();
    for (Iterator<String> iter = keys.iterator(); iter.hasNext(); ) {
      String thisN = (String) iter.next();

      // ok, cycle through the sea states for this participant
      NamedList thisList = states.getThisSeries(thisN);
      exportThisSeries(thisN, target_sea_state_datum, thisList, sea_state_headings, itt, doc);
    }

    envElement.appendChild(itt);
  }
예제 #24
0
  /**
   * Appends one element to another's list of children.
   *
   * <p>If the child element is a {@link com.google.gwt.user.client.ui.PotentialElement}, it is
   * first resolved.
   *
   * @param parent the parent element
   * @param child its new child
   * @see com.google.gwt.user.client.ui.PotentialElement#resolve(Element)
   */
  public static void appendChild(Element parent, Element child) {
    assert !PotentialElement.isPotential(parent) : "Cannot append to a PotentialElement";

    // If child isn't a PotentialElement, resolve() returns
    // the Element itself.
    parent.appendChild(PotentialElement.resolve(child));
  }
예제 #25
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;
  }
예제 #26
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"));
  }
예제 #27
0
  public static void write() {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document doc;

    System.out.println("Writing patient data file\n");

    try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      doc = builder.newDocument();

      Element root = doc.createElement("patientdata");
      root.appendChild(XMLInterface.nl(doc));

      // get first PatientData from DataStore
      Iterator<PatientDataStore> pdsIt = GlobalVars.pds.iterator();
      while (pdsIt.hasNext()) {
        PatientDataStore pds = pdsIt.next();
        Node n = pds.createXMLNode(doc);

        XMLInterface.addNode(doc, root, n, 0);
      }

      root.normalize();
      // create junk to write it out (see java xml tutorial)
      TransformerFactory tFactory = TransformerFactory.newInstance();
      Transformer transformer = tFactory.newTransformer();
      DOMSource src = new DOMSource(root);
      StreamResult result = new StreamResult(new File(GlobalVars.XMLDataFile));
      transformer.transform(src, result);
    } catch (Exception e) {
      System.err.println("Error WRITING xml patient data file");
      e.printStackTrace();
    }
  }
예제 #28
0
 public void addElement(Element el, BoxBounds bounds) {
   Layer layer = new Layer(el, bounds);
   layers.add(layer);
   el.getStyle().setPosition(Style.Position.ABSOLUTE);
   presetLayerBounds(layer);
   container.appendChild(el);
 }
예제 #29
0
  /**
   * Writes a table to a XML-file
   *
   * @param t - Output Model
   * @param destination - File Destination
   */
  public static void writeXML(Model t, String destination) {

    try {
      // Create the XML document builder, and document that will be used
      DocumentBuilderFactory xmlBuilder = DocumentBuilderFactory.newInstance();
      DocumentBuilder Builder = xmlBuilder.newDocumentBuilder();
      Document xmldoc = Builder.newDocument();

      // create Document node, and get it into the file
      Element Documentnode = xmldoc.createElement("SPREADSHEET");
      xmldoc.appendChild(Documentnode);

      // create element nodes, and their attributes (Cells, and row/column
      // data) and their content
      for (int row = 1; row < t.getRows(); row++) {
        for (int col = 1; col < t.getCols(col); col++) {
          Element cell = xmldoc.createElement("CELL");
          // set attributes
          cell.setAttribute("column", Integer.toString(col));
          cell.setAttribute("row", Integer.toString(col));
          // set content
          cell.appendChild(xmldoc.createTextNode((String) t.getContent(row, col)));
          // append node to document node
          Documentnode.appendChild(cell);
        }
      }
      // Creating a datastream for the DOM tree
      TransformerFactory transformerFactory = TransformerFactory.newInstance();
      Transformer transformer = transformerFactory.newTransformer();
      // Indentation to make the XML file look better
      transformer.setOutputProperty(OutputKeys.METHOD, "xml");
      transformer.setOutputProperty(OutputKeys.INDENT, "yes");
      // remove the java version
      transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
      DOMSource stream = new DOMSource(xmldoc);
      StreamResult target = new StreamResult(new File(destination));
      // write the file
      transformer.transform(stream, target);

    } catch (ParserConfigurationException e) {
      System.out.println("Can't create the XML document builder");
    } catch (TransformerConfigurationException e) {
      System.out.println("Can't create transformer");
    } catch (TransformerException e) {
      System.out.println("Can't write to file");
    }
  }
예제 #30
0
 protected void setAttribute(String name, String attName, String attValue) {
   Element elt = getElement(name);
   if (elt == null) {
     elt = doc.createElement(name);
     docElt.appendChild(elt);
   }
   elt.setAttribute(attName, attValue);
 }