示例#1
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;
  }
示例#2
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);
    }
  }
示例#3
0
  /**
   * Converts value object to XML representation.
   *
   * @return Element.
   */
  public Element toXml(Document doc) {
    Element root = doc.createElement("OrderAssoc");

    Element node;

    root.setAttribute("Id", String.valueOf(mOrderAssocId));

    node = doc.createElement("Order1Id");
    node.appendChild(doc.createTextNode(String.valueOf(mOrder1Id)));
    root.appendChild(node);

    node = doc.createElement("Order2Id");
    node.appendChild(doc.createTextNode(String.valueOf(mOrder2Id)));
    root.appendChild(node);

    node = doc.createElement("OrderAssocCd");
    node.appendChild(doc.createTextNode(String.valueOf(mOrderAssocCd)));
    root.appendChild(node);

    node = doc.createElement("OrderAssocStatusCd");
    node.appendChild(doc.createTextNode(String.valueOf(mOrderAssocStatusCd)));
    root.appendChild(node);

    node = doc.createElement("AddDate");
    node.appendChild(doc.createTextNode(String.valueOf(mAddDate)));
    root.appendChild(node);

    node = doc.createElement("AddBy");
    node.appendChild(doc.createTextNode(String.valueOf(mAddBy)));
    root.appendChild(node);

    node = doc.createElement("ModDate");
    node.appendChild(doc.createTextNode(String.valueOf(mModDate)));
    root.appendChild(node);

    node = doc.createElement("ModBy");
    node.appendChild(doc.createTextNode(String.valueOf(mModBy)));
    root.appendChild(node);

    node = doc.createElement("WorkOrderItemId");
    node.appendChild(doc.createTextNode(String.valueOf(mWorkOrderItemId)));
    root.appendChild(node);

    node = doc.createElement("ServiceTicketId");
    node.appendChild(doc.createTextNode(String.valueOf(mServiceTicketId)));
    root.appendChild(node);

    return root;
  }
示例#4
0
  /**
   * Converts value object to XML representation.
   *
   * @return Element.
   */
  public Element toXml(Document doc) {
    Element root = doc.createElement("Event");

    Element node;

    root.setAttribute("Id", String.valueOf(mEventId));

    node = doc.createElement("Type");
    node.appendChild(doc.createTextNode(String.valueOf(mType)));
    root.appendChild(node);

    node = doc.createElement("Status");
    node.appendChild(doc.createTextNode(String.valueOf(mStatus)));
    root.appendChild(node);

    node = doc.createElement("Cd");
    node.appendChild(doc.createTextNode(String.valueOf(mCd)));
    root.appendChild(node);

    node = doc.createElement("Attempt");
    node.appendChild(doc.createTextNode(String.valueOf(mAttempt)));
    root.appendChild(node);

    node = doc.createElement("AddDate");
    node.appendChild(doc.createTextNode(String.valueOf(mAddDate)));
    root.appendChild(node);

    node = doc.createElement("AddBy");
    node.appendChild(doc.createTextNode(String.valueOf(mAddBy)));
    root.appendChild(node);

    node = doc.createElement("ModDate");
    node.appendChild(doc.createTextNode(String.valueOf(mModDate)));
    root.appendChild(node);

    node = doc.createElement("ModBy");
    node.appendChild(doc.createTextNode(String.valueOf(mModBy)));
    root.appendChild(node);

    node = doc.createElement("EventPriority");
    node.appendChild(doc.createTextNode(String.valueOf(mEventPriority)));
    root.appendChild(node);

    node = doc.createElement("ProcessTime");
    node.appendChild(doc.createTextNode(String.valueOf(mProcessTime)));
    root.appendChild(node);

    return root;
  }
  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");
    }
  }
示例#6
0
 public static Node indent(Document doc, int level) {
   StringBuffer sb = new StringBuffer();
   final String basicIndent = "    ";
   int x;
   for (x = 0; x < level; x++) {
     sb.append(basicIndent);
   }
   return doc.createTextNode(sb.toString());
 }
  /**
   * 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;
  }
示例#8
0
    public Element reportDtElem() {
      StringBuffer sb = new StringBuffer(255);
      sb.append(shortTypeName);
      sb.append(" [ dataSourceName: ");
      sb.append(pds.getDataSourceName());
      sb.append("; identityToken: ");
      sb.append(pds.getIdentityToken());
      sb.append(" ]");

      Element dtElem = doc.createElement("dt");
      dtElem.appendChild(doc.createTextNode(sb.toString()));
      return dtElem;
    }
  /**
   * @param chkKeys List of String objects with the shas
   * @param targetFile target file
   * @return true if write was successful
   */
  public static boolean writeRequestFile(
      final FileRequestFileContent content, final File targetFile) {

    final Document doc = XMLTools.createDomDocument();
    if (doc == null) {
      logger.severe("Error - writeRequestFile: factory could'nt create XML Document.");
      return false;
    }

    final Element rootElement = doc.createElement(TAG_FrostFileRequestFile);
    doc.appendChild(rootElement);

    final Element timeStampElement = doc.createElement(TAG_timestamp);
    final Text timeStampText = doc.createTextNode(Long.toString(content.getTimestamp()));
    timeStampElement.appendChild(timeStampText);
    rootElement.appendChild(timeStampElement);

    final Element rootChkElement = doc.createElement(TAG_shaList);
    rootElement.appendChild(rootChkElement);

    for (final String chkKey : content.getShaStrings()) {

      final Element nameElement = doc.createElement(TAG_sha);
      final Text text = doc.createTextNode(chkKey);
      nameElement.appendChild(text);

      rootChkElement.appendChild(nameElement);
    }

    boolean writeOK = false;
    try {
      writeOK = XMLTools.writeXmlFile(doc, targetFile);
    } catch (final Throwable t) {
      logger.log(Level.SEVERE, "Exception in writeRequestFile/writeXmlFile", t);
    }

    return writeOK;
  }
  /**
   * Converts value object to XML representation.
   *
   * @return Element.
   */
  public Element toXml(Document doc) {
    Element root = doc.createElement("InboundPollockOrderGuideLoader");
    root.setAttribute("Id", String.valueOf(mEditType));

    Element node;

    node = doc.createElement("RecordType");
    node.appendChild(doc.createTextNode(String.valueOf(mRecordType)));
    root.appendChild(node);

    node = doc.createElement("RecordValue1");
    node.appendChild(doc.createTextNode(String.valueOf(mRecordValue1)));
    root.appendChild(node);

    node = doc.createElement("RecordValue2");
    node.appendChild(doc.createTextNode(String.valueOf(mRecordValue2)));
    root.appendChild(node);

    node = doc.createElement("RecordValue3");
    node.appendChild(doc.createTextNode(String.valueOf(mRecordValue3)));
    root.appendChild(node);

    return root;
  }
示例#11
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;
 }
示例#12
0
 static XmlNode newElementWithText(
     XmlProcessor processor, XmlNode reference, XmlNode.QName qname, String value) {
   if (reference instanceof org.w3c.dom.Document)
     throw new IllegalArgumentException("Cannot use Document node as reference");
   Document document = null;
   if (reference != null) {
     document = reference.dom.getOwnerDocument();
   } else {
     document = processor.newDocument();
   }
   Node referenceDom = (reference != null) ? reference.dom : null;
   Element e = document.createElementNS(qname.getUri(), qname.qualify(referenceDom));
   if (value != null) {
     e.appendChild(document.createTextNode(value));
   }
   return XmlNode.createImpl(e);
 }
  /**
   * Converts an <code>EppResponseDataRenewXriNumber</code> object into an XML element.
   *
   * @param doc the XML <code>Document</code> object
   * @param tag the tag/element name for the <code>EppResponseDataRenewXriNumber</code> object
   * @return an <code>Element</code> object
   */
  public Element toXML(Document doc, String tag) {
    Element elm;
    Element body = doc.createElement(tag);
    ElementNSImpl data = EppUtil.createElementNS(doc, "xriINU", "renData");
    body.appendChild(data);

    if (inumber != null) {
      elm = doc.createElement("inumber");
      elm.appendChild(doc.createTextNode(inumber));
      data.appendChild(elm);
    }
    if (exDate != null) {
      elm = doc.createElement("exDate");
      elm.appendChild(EppUtil.createTextNode(doc, exDate));
      data.appendChild(elm);
    }

    return body;
  }
  /**
   * Converts the <code>EppCommandRenewXriName</code> object into an XML element
   *
   * @param doc the XML <code>Document</code> object
   * @param tag the tag/element name for the <code>EppCommandRenewXriName</code> object
   * @return an <code>Element</code> object
   */
  public Element toXML(Document doc, String tag) {
    Element elm;
    Element body = EppUtil.createElementNS(doc, "xriINA", tag);

    if (iname != null) {
      elm = doc.createElement("iname");
      elm.appendChild(doc.createTextNode(iname));
      body.appendChild(elm);
    }
    if (curExpDate != null) {
      elm = doc.createElement("curExpDate");
      elm.appendChild(EppUtil.createTextNode(doc, curExpDate, true));
      body.appendChild(elm);
    }
    if (period != null) {
      body.appendChild(period.toXML(doc, "period"));
    }

    return toXMLCommon(doc, tag, body);
  }
示例#15
0
  public void createAndAddIndexGroups(
      final IndexEntry[] theIndexEntries,
      final IndexConfiguration theConfiguration,
      final Document theDocument,
      final Locale theLocale) {
    final IndexComparator indexEntryComparator = new IndexComparator(theLocale);

    final IndexGroup[] indexGroups =
        indexGroupProcessor.process(theIndexEntries, theConfiguration, theLocale);

    final Element rootElement = theDocument.getDocumentElement();

    final Element indexGroupsElement = theDocument.createElementNS(namespace_url, "index.groups");
    indexGroupsElement.setPrefix(prefix);

    for (final IndexGroup group : indexGroups) {
      // Create group element
      final Node groupElement = theDocument.createElementNS(namespace_url, "index.group");
      groupElement.setPrefix(prefix);
      // Create group label element and index entry childs
      final Element groupLabelElement = theDocument.createElementNS(namespace_url, "label");
      groupLabelElement.setPrefix(prefix);
      groupLabelElement.appendChild(theDocument.createTextNode(group.getLabel()));
      groupElement.appendChild(groupLabelElement);

      final Node[] entryNodes =
          transformToNodes(group.getEntries(), theDocument, indexEntryComparator);
      for (final Node entryNode : entryNodes) {
        groupElement.appendChild(entryNode);
      }

      indexGroupsElement.appendChild(groupElement);
    }

    rootElement.appendChild(indexGroupsElement);
  }
示例#16
0
  public void CollectData(String link) {

    try {
      // Creating an empty XML Document

      DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
      DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
      Document doc = docBuilder.newDocument();
      int flag = 0;
      // create the root element and add it to the document
      Element movie = doc.createElement("movie");
      doc.appendChild(movie);
      movie.setAttribute("id", String.valueOf(n));
      n++;
      // create sub elements
      Element genres = doc.createElement("genres");
      Element actors = doc.createElement("actors");
      Element reviews = doc.createElement("reviews");

      URL movieUrl = new URL(link);
      URL reviewsURL = new URL(link + "reviews/#type=top_critics");
      BufferedWriter bw3 = new BufferedWriter(new FileWriter("movies.xml", true));
      int count = -1;
      String auth = "";
      BufferedReader br3 = new BufferedReader(new InputStreamReader(movieUrl.openStream()));
      String str2 = "";
      String info = "";
      while (null != (str2 = br3.readLine())) {
        // start reading the html document
        if (str2.isEmpty()) continue;
        if (count == 14) break;
        if (count == 12) {
          if (!str2.contains("<h3>Cast</h3>")) continue;
          else count++;
        }
        if (count == 13) {
          if (str2.contains(">ADVERTISEMENT</p>")) {
            count++;
            movie.appendChild(actors);
            continue;
          } else {
            if (str2.contains("itemprop=\"name\">")) {
              Element actor = doc.createElement("actor");
              actors.appendChild(actor);
              Text text = doc.createTextNode(Jsoup.parse(str2.toString()).text());
              actor.appendChild(text);
            } else continue;
          }
        }

        if (count <= 11) {
          switch (count) {
            case -1:
              {
                if (!str2.contains("property=\"og:image\"")) continue;
                else {
                  Pattern image =
                      Pattern.compile("http://.*.jpg", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
                  Matcher match = image.matcher(str2);
                  while (match.find()) {

                    Element imageLink = doc.createElement("imageLink");
                    movie.appendChild(imageLink);
                    Text text = doc.createTextNode(match.group());
                    imageLink.appendChild(text);
                    count++;
                  }
                }
                break;
              }
            case 0:
              {
                if (str2.contains("<title>")) {

                  Element name = doc.createElement("name");
                  movie.appendChild(name);
                  Text text =
                      doc.createTextNode(
                          Jsoup.parse(str2.toString().replace(" - Rotten Tomatoes", "")).text());
                  name.appendChild(text);
                  count++;
                }
                break;
              }
            case 1:
              {
                if (!str2.contains("itemprop=\"ratingValue\"")) break;
                else {
                  Element score = doc.createElement("score");
                  movie.appendChild(score);
                  Text text = doc.createTextNode(Jsoup.parse(str2.toString()).text());
                  score.appendChild(text);
                  count++;
                }
                break;
              }
            case 2:
              {
                if (!str2.contains("itemprop=\"description\">")) continue;
                else count++;
                break;
              }
            case 3:
              {
                if (!str2.contains("itemprop=\"duration\"")) info = info.concat(str2);
                else {
                  Element MovieInfo = doc.createElement("MovieInfo");
                  movie.appendChild(MovieInfo);
                  Text text = doc.createTextNode(Jsoup.parse(info.toString()).text());
                  MovieInfo.appendChild(text);
                  info = str2;
                  count++;
                }
                break;
              }
            case 4:
              {
                if (!str2.contains("itemprop=\"genre\"")) info = info.concat(str2);
                else {
                  Element duration = doc.createElement("duration");
                  movie.appendChild(duration);
                  Text text = doc.createTextNode(Jsoup.parse(info.toString()).text());
                  duration.appendChild(text);
                  info = str2;
                  count++;
                }
                break;
              }
            case 5:
              {
                if (info.contains("itemprop=\"genre\"")) {
                  Element genre = doc.createElement("genre");
                  genres.appendChild(genre);
                  Text text = doc.createTextNode(Jsoup.parse(info.toString()).text());
                  genre.appendChild(text);
                  info = "";
                }
                if (str2.contains(">Directed By:<")) {
                  count++;
                  movie.appendChild(genres);
                  continue;
                } else {

                  if (str2.contains("itemprop=\"genre\"")) {
                    Element genre = doc.createElement("genre");
                    genres.appendChild(genre);
                    Text text = doc.createTextNode(Jsoup.parse(str2.toString()).text());
                    genre.appendChild(text);
                  } else continue;
                }
                break;
              }
            case 6:
              {
                if (!str2.contains(">Written By:<")) {
                  if (str2.contains(">In Theaters:<")) {
                    Element director = doc.createElement("director");
                    movie.appendChild(director);
                    Text text =
                        doc.createTextNode(
                            Jsoup.parse(info.toString().replace("Directed By: ", "")).text());
                    director.appendChild(text);
                    info = str2;
                    count += 2;
                    break;
                  }
                  info = info.concat(str2);
                } else {
                  Element director = doc.createElement("director");
                  movie.appendChild(director);
                  Text text =
                      doc.createTextNode(
                          Jsoup.parse(info.toString().replace("Directed By: ", "")).text());
                  director.appendChild(text);
                  info = "";
                  count++;
                }
                break;
              }
            case 7:
              {
                if (!str2.contains(">In Theaters:<")) {
                  if (str2.contains(">On DVD:<")) {
                    Element writer = doc.createElement("writer");
                    movie.appendChild(writer);
                    Text text = doc.createTextNode(Jsoup.parse(info.toString()).text());
                    writer.appendChild(text);
                    info = str2;
                    count += 2;
                    break;
                  }
                  info = info.concat(str2);
                } else {
                  Element writer = doc.createElement("writer");
                  movie.appendChild(writer);
                  Text text = doc.createTextNode(Jsoup.parse(info.toString()).text());
                  writer.appendChild(text);
                  info = str2;
                  count++;
                }
                break;
              }
            case 8:
              {
                if (!str2.contains(">On DVD:<")) info = info.concat(str2);
                else {
                  Element TheatreRelease = doc.createElement("TheatreRelease");
                  movie.appendChild(TheatreRelease);
                  Text text =
                      doc.createTextNode(
                          Jsoup.parse(info.toString().replace("In Theaters:", "")).text());
                  TheatreRelease.appendChild(text);
                  info = str2;
                  count++;
                }
                break;
              }
            case 9:
              {
                if (!str2.contains(">US Box Office:<")) {
                  if (str2.contains("itemprop=\"productionCompany\"")) {
                    Element DvdRelease = doc.createElement("DvdRelease");
                    movie.appendChild(DvdRelease);
                    Text text =
                        doc.createTextNode(
                            Jsoup.parse(info.toString().replace("On DVD:", "")).text());
                    DvdRelease.appendChild(text);
                    info = str2;
                    count += 2;
                    break;
                  }
                  info = info.concat(str2);
                } else {
                  Element DvdRelease = doc.createElement("DvdRelease");
                  movie.appendChild(DvdRelease);
                  Text text =
                      doc.createTextNode(
                          Jsoup.parse(info.toString().replace("On DVD:", "")).text());
                  DvdRelease.appendChild(text);
                  info = str2;
                  count++;
                }
                break;
              }
            case 10:
              {
                if (!str2.contains("itemprop=\"productionCompany\"")) info = info.concat(str2);
                else {
                  Element BOCollection = doc.createElement("BOCollection");
                  movie.appendChild(BOCollection);
                  Text text =
                      doc.createTextNode(
                          Jsoup.parse(info.toString().replace("US Box Office:", "")).text());
                  BOCollection.appendChild(text);
                  info = str2;
                  count++;
                }
                break;
              }
            case 11:
              {
                if (!str2.contains(">Official Site")) info = info.concat(str2);
                else {
                  Element Production = doc.createElement("Production");
                  movie.appendChild(Production);
                  Text text = doc.createTextNode(Jsoup.parse(info.toString()).text());
                  Production.appendChild(text);
                  info = str2;
                  count++;
                }
                break;
              }

            default:
              break;
          }
        }
      }
      BufferedReader br4 = new BufferedReader(new InputStreamReader(reviewsURL.openStream()));
      String str3 = "";
      String info2 = "";
      int count2 = 0;
      while (null != (str3 = br4.readLine())) {
        if (count2 == 0) {

          if (!str3.contains("<div class=\"reviewsnippet\">")) continue;
          else count2++;
        }
        if (count2 == 1) {
          if (!str3.contains("<p class=\"small subtle\">")) info2 = info2.concat(str3);
          else {
            Element review = doc.createElement("review");
            reviews.appendChild(review);
            Text text = doc.createTextNode(Jsoup.parse(info2.toString()).text());
            review.appendChild(text);
            info2 = "";
            count2 = 0;
          }
        }
      }
      movie.appendChild(reviews);
      TransformerFactory transfac = TransformerFactory.newInstance();
      Transformer trans = transfac.newTransformer();
      trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
      trans.setOutputProperty(OutputKeys.INDENT, "yes");

      // create string from xml tree
      StringWriter sw = new StringWriter();
      StreamResult result = new StreamResult(sw);
      DOMSource source = new DOMSource(doc);
      trans.transform(source, result);
      String xmlString = sw.toString();
      bw3.write(xmlString);
      br3.close();
      br4.close();
      bw3.close();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  /**
   * Converts the <code>EppXriAuthority</code> object into an XML element
   *
   * @param doc the XML <code>Document</code> object
   * @param tag the tag/element name for the <code>EppXriAuthority</code> object
   * @return an <code>Element</code> object
   */
  public Element toXML(Document doc, String tag) {
    Element elm;
    Element body = EppUtil.createElementNS(doc, "xriAU", tag);
    boolean isCreate = tag.equals("create");

    // the order of the tags for create is:
    //
    // authId/isEscrow/isContact/escrowAgent/contactAgent/socialData/authInfo
    //
    // the order of the tags for info is
    //
    // authId/isEscrow/isContact/escrowAgent/contactAgent/
    // roid/status/socialData/trustee/ref/redirect/equivID/canonicalEquivID/
    // sep/iname/inumber/iservice/extension/
    // clID/crID/crDate/upDate/trDate/authInfo
    //

    if (authId != null) {
      elm = doc.createElement("authId");
      elm.appendChild(doc.createTextNode(authId));
      body.appendChild(elm);
    }

    if (isEscrow != null) {
      elm = doc.createElement("isEscrow");
      elm.appendChild(doc.createTextNode(isEscrow.toString()));
      body.appendChild(elm);
    }

    if (isContact != null) {
      elm = doc.createElement("isContact");
      elm.appendChild(doc.createTextNode(isContact.toString()));
      body.appendChild(elm);
    }

    if (escrowAgent != null) {
      body.appendChild(escrowAgent.toXML(doc, "escrowAgent"));
    }

    if (contactAgent != null) {
      body.appendChild(contactAgent.toXML(doc, "contactAgent"));
    }
    if (contactHands != null) {
      for (int i = 0; i < contactHands.size(); i++) {
        EppXriContactData t = (EppXriContactData) contactHands.elementAt(i);
        body.appendChild(t.toXML(doc, "contactId"));
      }
    }
    if (isCreate) {
      if (socialData != null) {
        body.appendChild(socialData.toXML(doc, "socialData"));
      }
      if (authInfo != null) {
        body.appendChild(authInfo.toXML(doc, "authInfo"));
      }

      return body;
    }
    if (roid != null) {
      elm = doc.createElement("roid");
      elm.appendChild(doc.createTextNode(roid));
      body.appendChild(elm);
    }
    if (status != null) {
      for (int i = 0; i < status.size(); i++) {
        EppStatus s = (EppStatus) status.elementAt(i);
        body.appendChild(s.toXML(doc, "status"));
      }
    }
    if (socialData != null) {
      body.appendChild(socialData.toXML(doc, "socialData"));
    }
    if (trustee != null) {
      for (int i = 0; i < trustee.size(); i++) {
        EppXriTrustee t = (EppXriTrustee) trustee.elementAt(i);
        body.appendChild(t.toXML(doc, "trustee"));
      }
    }
    if (ref != null) {
      for (int i = 0; i < ref.size(); i++) {
        EppXriRef t = (EppXriRef) ref.elementAt(i);
        body.appendChild(t.toXML(doc, "ref"));
      }
    }
    if (redirect != null) {
      for (int i = 0; i < redirect.size(); i++) {
        EppXriURI t = (EppXriURI) redirect.elementAt(i);
        body.appendChild(t.toXML(doc, "redirect"));
      }
    }
    if (equivIDs != null) {
      for (int i = 0; i < equivIDs.size(); i++) {
        EppXriSynonym id = (EppXriSynonym) equivIDs.elementAt(i);
        body.appendChild(id.toXML(doc, "equivID"));
      }
    }
    if (canonicalEquivID != null) {
      elm = doc.createElement("canonicalEquivID");
      elm.appendChild(doc.createTextNode(canonicalEquivID));
      body.appendChild(elm);
    }
    if (sep != null) {
      for (int i = 0; i < sep.size(); i++) {
        EppXriServiceEndpoint t = (EppXriServiceEndpoint) sep.elementAt(i);
        body.appendChild(t.toXML(doc, "sep"));
      }
    }
    if (iname != null) {
      for (int i = 0; i < iname.size(); i++) {
        String s = (String) iname.elementAt(i);
        elm = doc.createElement("iname");
        elm.appendChild(doc.createTextNode(s));
        body.appendChild(elm);
      }
    }
    if (inumber != null) {
      for (int i = 0; i < inumber.size(); i++) {
        EppXriNumberAttribute xin = (EppXriNumberAttribute) inumber.elementAt(i);
        body.appendChild(xin.toXML(doc, "inumber"));
      }
    }
    if (iservice != null) {
      for (int i = 0; i < iservice.size(); i++) {
        String s = (String) iservice.elementAt(i);
        elm = doc.createElement("iservice");
        elm.appendChild(doc.createTextNode(s));
        body.appendChild(elm);
      }
    }
    if (extension != null) {
      elm = doc.createElement("extension");
      elm.appendChild(doc.createTextNode(extension));
      body.appendChild(elm);
    }

    toXMLCommon(doc, body);

    return body;
  }
示例#18
0
  /**
   * Converts value object to XML representation.
   *
   * @return Element.
   */
  public Element toXml(Document doc) {
    Element root = doc.createElement("NscUs");
    root.setAttribute("Id", String.valueOf(mUserName));

    Element node;

    node = doc.createElement("Password");
    node.appendChild(doc.createTextNode(String.valueOf(mPassword)));
    root.appendChild(node);

    node = doc.createElement("CustomerNumber");
    node.appendChild(doc.createTextNode(String.valueOf(mCustomerNumber)));
    root.appendChild(node);

    node = doc.createElement("ContactName");
    node.appendChild(doc.createTextNode(String.valueOf(mContactName)));
    root.appendChild(node);

    node = doc.createElement("EmailAddress");
    node.appendChild(doc.createTextNode(String.valueOf(mEmailAddress)));
    root.appendChild(node);

    node = doc.createElement("CatalogName");
    node.appendChild(doc.createTextNode(String.valueOf(mCatalogName)));
    root.appendChild(node);

    node = doc.createElement("LocationNumber");
    node.appendChild(doc.createTextNode(String.valueOf(mLocationNumber)));
    root.appendChild(node);

    node = doc.createElement("MemberNumber");
    node.appendChild(doc.createTextNode(String.valueOf(mMemberNumber)));
    root.appendChild(node);

    node = doc.createElement("FirstName");
    node.appendChild(doc.createTextNode(String.valueOf(mFirstName)));
    root.appendChild(node);

    node = doc.createElement("LastName");
    node.appendChild(doc.createTextNode(String.valueOf(mLastName)));
    root.appendChild(node);

    node = doc.createElement("UserId");
    node.appendChild(doc.createTextNode(String.valueOf(mUserId)));
    root.appendChild(node);

    node = doc.createElement("UserAction");
    node.appendChild(doc.createTextNode(String.valueOf(mUserAction)));
    root.appendChild(node);

    node = doc.createElement("StoreId");
    node.appendChild(doc.createTextNode(String.valueOf(mStoreId)));
    root.appendChild(node);

    node = doc.createElement("StoreAssocId");
    node.appendChild(doc.createTextNode(String.valueOf(mStoreAssocId)));
    root.appendChild(node);

    node = doc.createElement("StoreAssocAction");
    node.appendChild(doc.createTextNode(String.valueOf(mStoreAssocAction)));
    root.appendChild(node);

    node = doc.createElement("AccountId");
    node.appendChild(doc.createTextNode(String.valueOf(mAccountId)));
    root.appendChild(node);

    node = doc.createElement("AccountAssocId");
    node.appendChild(doc.createTextNode(String.valueOf(mAccountAssocId)));
    root.appendChild(node);

    node = doc.createElement("AccountAssocAction");
    node.appendChild(doc.createTextNode(String.valueOf(mAccountAssocAction)));
    root.appendChild(node);

    node = doc.createElement("SiteId");
    node.appendChild(doc.createTextNode(String.valueOf(mSiteId)));
    root.appendChild(node);

    node = doc.createElement("SiteAssocId");
    node.appendChild(doc.createTextNode(String.valueOf(mSiteAssocId)));
    root.appendChild(node);

    node = doc.createElement("SiteAssocAction");
    node.appendChild(doc.createTextNode(String.valueOf(mSiteAssocAction)));
    root.appendChild(node);

    node = doc.createElement("EmailId");
    node.appendChild(doc.createTextNode(String.valueOf(mEmailId)));
    root.appendChild(node);

    node = doc.createElement("EmailAction");
    node.appendChild(doc.createTextNode(String.valueOf(mEmailAction)));
    root.appendChild(node);

    node = doc.createElement("MemberId");
    node.appendChild(doc.createTextNode(String.valueOf(mMemberId)));
    root.appendChild(node);

    node = doc.createElement("CatalogId");
    node.appendChild(doc.createTextNode(String.valueOf(mCatalogId)));
    root.appendChild(node);

    return root;
  }
  /**
   * @param list
   * @param document
   * @param parent
   */
  void addAttributesFromListToNode(AttributeList list, Document document, Node parent) {
    DicomDictionary dictionary = list.getDictionary();
    Iterator i = list.values().iterator();
    while (i.hasNext()) {
      Attribute attribute = (Attribute) i.next();
      AttributeTag tag = attribute.getTag();

      String elementName = dictionary.getNameFromTag(tag);
      if (elementName == null) {
        elementName = makeElementNameFromHexadecimalGroupElementValues(tag);
      }
      Node node = document.createElement(elementName);
      parent.appendChild(node);

      {
        Attr attr = document.createAttribute("group");
        attr.setValue(HexDump.shortToPaddedHexString(tag.getGroup()));
        node.getAttributes().setNamedItem(attr);
      }
      {
        Attr attr = document.createAttribute("element");
        attr.setValue(HexDump.shortToPaddedHexString(tag.getElement()));
        node.getAttributes().setNamedItem(attr);
      }
      {
        Attr attr = document.createAttribute("vr");
        attr.setValue(ValueRepresentation.getAsString(attribute.getVR()));
        node.getAttributes().setNamedItem(attr);
      }

      if (attribute instanceof SequenceAttribute) {
        int count = 0;
        Iterator si = ((SequenceAttribute) attribute).iterator();
        while (si.hasNext()) {
          SequenceItem item = (SequenceItem) si.next();
          Node itemNode = document.createElement("Item");
          Attr numberAttr = document.createAttribute("number");
          numberAttr.setValue(Integer.toString(++count));
          itemNode.getAttributes().setNamedItem(numberAttr);
          node.appendChild(itemNode);
          addAttributesFromListToNode(item.getAttributeList(), document, itemNode);
        }
      } else {
        // Attr attr = document.createAttribute("value");
        // attr.setValue(attribute.getDelimitedStringValuesOrEmptyString());
        // node.getAttributes().setNamedItem(attr);

        // node.appendChild(document.createTextNode(attribute.getDelimitedStringValuesOrEmptyString()));

        String values[] = null;
        try {
          values = attribute.getStringValues();
        } catch (DicomException e) {
          // e.printStackTrace(System.err);
        }
        if (values != null) {
          for (int j = 0; j < values.length; ++j) {
            Node valueNode = document.createElement("value");
            Attr numberAttr = document.createAttribute("number");
            numberAttr.setValue(Integer.toString(j + 1));
            valueNode.getAttributes().setNamedItem(numberAttr);
            valueNode.appendChild(document.createTextNode(values[j]));
            node.appendChild(valueNode);
          }
        }
      }
    }
  }
示例#20
0
  /**
   * Converts value object to XML representation.
   *
   * @return Element.
   */
  public Element toXml(Document doc) {
    Element root = doc.createElement("ProductViewDef");

    Element node;

    root.setAttribute("Id", String.valueOf(mProductViewDefId));

    node = doc.createElement("StatusCd");
    node.appendChild(doc.createTextNode(String.valueOf(mStatusCd)));
    root.appendChild(node);

    node = doc.createElement("AccountId");
    node.appendChild(doc.createTextNode(String.valueOf(mAccountId)));
    root.appendChild(node);

    node = doc.createElement("Attributename");
    node.appendChild(doc.createTextNode(String.valueOf(mAttributename)));
    root.appendChild(node);

    node = doc.createElement("SortOrder");
    node.appendChild(doc.createTextNode(String.valueOf(mSortOrder)));
    root.appendChild(node);

    node = doc.createElement("Width");
    node.appendChild(doc.createTextNode(String.valueOf(mWidth)));
    root.appendChild(node);

    node = doc.createElement("StyleClass");
    node.appendChild(doc.createTextNode(String.valueOf(mStyleClass)));
    root.appendChild(node);

    node = doc.createElement("ProductViewCd");
    node.appendChild(doc.createTextNode(String.valueOf(mProductViewCd)));
    root.appendChild(node);

    node = doc.createElement("AddDate");
    node.appendChild(doc.createTextNode(String.valueOf(mAddDate)));
    root.appendChild(node);

    node = doc.createElement("AddBy");
    node.appendChild(doc.createTextNode(String.valueOf(mAddBy)));
    root.appendChild(node);

    node = doc.createElement("ModDate");
    node.appendChild(doc.createTextNode(String.valueOf(mModDate)));
    root.appendChild(node);

    node = doc.createElement("ModBy");
    node.appendChild(doc.createTextNode(String.valueOf(mModBy)));
    root.appendChild(node);

    return root;
  }
示例#21
0
 public static Node nl(Document doc) {
   return doc.createTextNode("\n");
 }
示例#22
0
  /**
   * Creates nodes from index entries
   *
   * @param theIndexEntries index entries
   * @param theTargetDocument target document
   * @param theIndexEntryComparator comparator to sort the index entries. if it is null the index
   *     entries will be unsorted
   * @return nodes for the target document
   */
  private Node[] transformToNodes(
      final IndexEntry[] theIndexEntries,
      final Document theTargetDocument,
      final Comparator<IndexEntry> theIndexEntryComparator) {
    if (null != theIndexEntryComparator) {
      Arrays.sort(theIndexEntries, theIndexEntryComparator);
    }

    final List<Element> result = new ArrayList<Element>();
    for (final IndexEntry indexEntry : theIndexEntries) {
      final Element indexEntryNode = createElement(theTargetDocument, "index.entry");

      final Element formattedStringElement = createElement(theTargetDocument, "formatted-value");
      if (indexEntry.getContents() != null) {
        for (final Iterator<Node> i = indexEntry.getContents().iterator(); i.hasNext(); ) {
          final Node child = i.next();
          final Node clone = theTargetDocument.importNode(child, true);
          if (!i.hasNext() && clone.getNodeType() == Node.TEXT_NODE) {
            final Text t = (Text) clone;
            t.setData(t.getData().replaceAll("[\\s\\n]+$", ""));
          }
          formattedStringElement.appendChild(clone);
        }
      } else {
        final Text textNode = theTargetDocument.createTextNode(indexEntry.getFormattedString());
        textNode.normalize();
        formattedStringElement.appendChild(textNode);
      }
      indexEntryNode.appendChild(formattedStringElement);

      final String[] refIDs = indexEntry.getRefIDs();
      for (final String refID : refIDs) {
        final Element referenceIDElement = createElement(theTargetDocument, "refID");
        referenceIDElement.setAttribute("value", refID);
        indexEntryNode.appendChild(referenceIDElement);
      }

      final String val = indexEntry.getValue();
      if (null != val) {
        indexEntryNode.setAttribute("value", val);
      }

      final String sort = indexEntry.getSortString();
      if (null != sort) {
        indexEntryNode.setAttribute("sort-string", sort);
      }

      if (indexEntry.isStartingRange()) {
        indexEntryNode.setAttribute("start-range", "true");
      } else if (indexEntry.isEndingRange()) {
        indexEntryNode.setAttribute("end-range", "true");
      }
      if (indexEntry.isSuppressesThePageNumber()) {
        indexEntryNode.setAttribute("no-page", "true");
      } else if (indexEntry.isRestoresPageNumber()) {
        indexEntryNode.setAttribute("single-page", "true");
      }

      final IndexEntry[] childIndexEntries = indexEntry.getChildIndexEntries();

      final Node[] nodes =
          transformToNodes(childIndexEntries, theTargetDocument, theIndexEntryComparator);

      for (final Node node : nodes) {
        indexEntryNode.appendChild(node);
      }

      final IndexEntry[] seeChildIndexEntries = indexEntry.getSeeChildIndexEntries();
      if (seeChildIndexEntries != null) {
        final Element seeElement = createElement(theTargetDocument, "see-childs");
        final Node[] seeNodes =
            transformToNodes(seeChildIndexEntries, theTargetDocument, theIndexEntryComparator);
        for (final Node node : seeNodes) {
          seeElement.appendChild(node);
        }

        indexEntryNode.appendChild(seeElement);
      }

      final IndexEntry[] seeAlsoChildIndexEntries = indexEntry.getSeeAlsoChildIndexEntries();
      if (seeAlsoChildIndexEntries != null) {
        final Element seeAlsoElement = createElement(theTargetDocument, "see-also-childs");
        final Node[] seeAlsoNodes =
            transformToNodes(seeAlsoChildIndexEntries, theTargetDocument, theIndexEntryComparator);
        for (final Node node : seeAlsoNodes) {
          seeAlsoElement.appendChild(node);
        }

        indexEntryNode.appendChild(seeAlsoElement);
      }

      result.add(indexEntryNode);
    }
    return (Node[]) result.toArray(new Node[result.size()]);
  }