private static void toXml(XmlWriter w, Resource resource) throws IOException {
    w.element(RepositoryParser.RESOURCE)
        .attribute(Resource.ID, resource.getId())
        .attribute(Resource.SYMBOLIC_NAME, resource.getSymbolicName())
        .attribute(Resource.PRESENTATION_NAME, resource.getPresentationName())
        .attribute(Resource.URI, getRelativeUri(resource, Resource.URI))
        .attribute(Resource.VERSION, resource.getVersion().toString());

    w.textElement(Resource.DESCRIPTION, resource.getProperties().get(Resource.DESCRIPTION))
        .textElement(Resource.SIZE, resource.getProperties().get(Resource.SIZE))
        .textElement(
            Resource.DOCUMENTATION_URI, getRelativeUri(resource, Resource.DOCUMENTATION_URI))
        .textElement(Resource.SOURCE_URI, getRelativeUri(resource, Resource.SOURCE_URI))
        .textElement(Resource.JAVADOC_URI, getRelativeUri(resource, Resource.JAVADOC_URI))
        .textElement(Resource.LICENSE_URI, getRelativeUri(resource, Resource.LICENSE_URI));

    String[] categories = resource.getCategories();
    for (int i = 0; categories != null && i < categories.length; i++) {
      w.element(RepositoryParser.CATEGORY).attribute(RepositoryParser.ID, categories[i]).end();
    }
    Capability[] capabilities = resource.getCapabilities();
    for (int i = 0; capabilities != null && i < capabilities.length; i++) {
      toXml(w, capabilities[i]);
    }
    Requirement[] requirements = resource.getRequirements();
    for (int i = 0; requirements != null && i < requirements.length; i++) {
      toXml(w, requirements[i]);
    }
    w.end();
  }
Beispiel #2
0
 public static Element ranking_Genes(Document doc, IndividualStat is, int number) {
   Element genes = doc.createElement(Consts.XML_TAG_GENES);
   doc.getElementsByTagName(Consts.DATA_ROOT).item(0).appendChild(genes);
   float[] scores = null;
   Integer[] index;
   if (number > Symbols.length) number = Symbols.length;
   if (is != null) {
     index = is.get_Order();
     scores = is.get_GeneScores(Symbols.length - 1, 0);
     for (int i = Symbols.length - 1; i >= Symbols.length - number; i--) {
       Element gene = doc.createElement(Consts.XML_TAG_GENE);
       gene.setAttribute(Consts.XML_TAG_ID, Symbols[index[i]]);
       XmlWriter.append_text_element(
           doc, gene, Consts.XML_TAG_CHROMOSOME, ChrList[Chrs[index[i]]]);
       XmlWriter.append_text_element(
           doc, gene, Consts.XML_TAG_FROM, Integer.toString(Starts[index[i]] + 1));
       XmlWriter.append_text_element(
           doc, gene, Consts.XML_TAG_TO, Integer.toString(Ends[index[i]]));
       XmlWriter.append_text_element(
           doc,
           gene,
           Consts.XML_TAG_SCORE,
           Float.toString(Math.round(scores[index[i]] * 10) / 10));
       genes.appendChild(gene);
     }
   }
   return genes;
 }
Beispiel #3
0
 public static Element overlap_Genes(
     Document doc, String chr, int start, int end, IndividualStat is) {
   Element genes = doc.createElement(Consts.XML_TAG_GENES);
   doc.getElementsByTagName(Consts.DATA_ROOT).item(0).appendChild(genes);
   if (ChrMap.containsKey(chr)) {
     int[] range = binarySearchOverlap(ChrMap.get(chr), start, end);
     if (range != null) {
       float[] scores = null;
       if (is != null) scores = is.get_GeneScores(range[1], range[0]);
       for (int i = range[0]; i <= range[1]; i++) {
         Element gene = doc.createElement(Consts.XML_TAG_GENE);
         gene.setAttribute(Consts.XML_TAG_ID, Symbols[i]);
         XmlWriter.append_text_element(
             doc, gene, Consts.XML_TAG_FROM, Integer.toString(Starts[i] + 1));
         XmlWriter.append_text_element(doc, gene, Consts.XML_TAG_TO, Integer.toString(Ends[i]));
         if (is != null)
           XmlWriter.append_text_element(
               doc,
               gene,
               Consts.XML_TAG_SCORE,
               Float.toString(Math.round(scores[i - range[0]] * 10) / 10));
         genes.appendChild(gene);
       }
     }
   }
   return genes;
 }
Beispiel #4
0
 public static Element find_Gene(Document doc, String prefix) {
   prefix = prefix.toUpperCase();
   if (prefix.matches("C[XY0-9]+ORF")) {
     prefix = prefix.replaceFirst("ORF", "orf");
   } else if (prefix.matches("C[XY0-9]+OR")) {
     prefix = prefix.replaceFirst("OR", "or");
   } else if (prefix.matches("^C[XY0-9]+O")) {
     prefix = prefix.replaceFirst("O", "o");
   }
   Element genes = doc.createElement(Consts.XML_TAG_GENES);
   doc.getElementsByTagName(Consts.DATA_ROOT).item(0).appendChild(genes);
   int match = binarySearchPrefix(prefix);
   if (match >= 0) {
     for (int i = match; i < match + 5; i++) {
       if (i >= Symbols_sorted.length || !Symbols_sorted[i].startsWith(prefix)) return genes;
       else {
         Element gene = doc.createElement(Consts.XML_TAG_GENE);
         gene.setAttribute(Consts.XML_TAG_ID, Symbols_sorted[i]);
         int index = SymbolMap.get(Symbols_sorted[i]);
         XmlWriter.append_text_element(doc, gene, Consts.XML_TAG_CHROMOSOME, ChrList[Chrs[index]]);
         XmlWriter.append_text_element(
             doc, gene, Consts.XML_TAG_FROM, Integer.toString(Starts[index] + 1));
         XmlWriter.append_text_element(
             doc, gene, Consts.XML_TAG_TO, Integer.toString(Ends[index]));
         genes.appendChild(gene);
       }
     }
   }
   return genes;
 }
 private static void toXml(XmlWriter w, Capability capability) throws IOException {
   w.element(RepositoryParser.CAPABILITY).attribute(RepositoryParser.NAME, capability.getName());
   Property[] props = capability.getProperties();
   for (int j = 0; props != null && j < props.length; j++) {
     toXml(w, props[j]);
   }
   w.end();
 }
Beispiel #6
0
 public static Element gene_Info(Document doc, String symbol) {
   Element genes = doc.createElement(Consts.XML_TAG_GENES);
   doc.getElementsByTagName(Consts.DATA_ROOT).item(0).appendChild(genes);
   if (SymbolMap.containsKey(symbol)) {
     int index = SymbolMap.get(symbol);
     Element gene = doc.createElement(Consts.XML_TAG_GENE);
     gene.setAttribute(Consts.XML_TAG_ID, Symbols[index]);
     genes.appendChild(gene);
     XmlWriter.append_text_element(doc, gene, Consts.XML_TAG_CHROMOSOME, ChrList[Chrs[index]]);
     XmlWriter.append_text_element(
         doc, gene, Consts.XML_TAG_FROM, Integer.toString(Starts[index] + 1));
     XmlWriter.append_text_element(doc, gene, Consts.XML_TAG_TO, Integer.toString(Ends[index]));
     if (!RefSeqs[index].equals(""))
       XmlWriter.append_text_element(doc, gene, Consts.XML_TAG_REFSEQ, RefSeqs[index]);
     if (!UCSCs[index].equals(""))
       XmlWriter.append_text_element(doc, gene, Consts.XML_TAG_UCSC, UCSCs[index]);
     if (!Ensembls[index].equals(""))
       XmlWriter.append_text_element(doc, gene, Consts.XML_TAG_ENSEMBL, Ensembls[index]);
     if (!Entrezs[index].equals(""))
       XmlWriter.append_text_element(doc, gene, Consts.XML_TAG_ENTREZ, Entrezs[index]);
     XmlWriter.append_text_element(doc, gene, Consts.XML_TAG_HGNC, HGNCs[index]);
     XmlWriter.append_text_element(doc, gene, Consts.XML_TAG_NAME, Names[index]);
   }
   return genes;
 }
  private void serializeValue(final HttpServletResponse pResponse, Object value)
      throws TransformerException, IOException, FactoryConfigurationError {
    if (value instanceof Source) {
      setContentType(pResponse, "application/binary"); // Unknown content type
      Sources.writeToStream((Source) value, pResponse.getOutputStream());
    } else if (value instanceof Node) {
      pResponse.setContentType("text/xml");
      Sources.writeToStream(new DOMSource((Node) value), pResponse.getOutputStream());
    } else if (value instanceof XmlSerializable) {
      pResponse.setContentType("text/xml");
      XMLOutputFactory factory = XMLOutputFactory.newInstance();
      factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
      try {
        XmlWriter out =
            XmlStreaming.newWriter(
                pResponse.getOutputStream(), pResponse.getCharacterEncoding(), true);
        try {
          out.startDocument(null, null, null);
          ((XmlSerializable) value).serialize(out);
          out.endDocument();
        } finally {
          out.close();
        }
      } catch (XmlException e) {
        throw new TransformerException(e);
      }
    } else if (value instanceof Collection) {
      final XmlElementWrapper annotation = getElementWrapper();
      if (annotation != null) {
        setContentType(pResponse, "text/xml");
        try (OutputStream outStream = pResponse.getOutputStream()) {

          writeCollection(
              outStream, getGenericReturnType(), (Collection<?>) value, getQName(annotation));
        }
      }
    } else if (value instanceof CharSequence) {
      setContentType(pResponse, "text/plain");
      pResponse.getWriter().append((CharSequence) value);
    } else {
      if (value != null) {
        try {
          final JAXBContext jaxbContext = JAXBContext.newInstance(getReturnType());
          setContentType(pResponse, "text/xml");

          final JAXBSource jaxbSource = new JAXBSource(jaxbContext, value);
          Sources.writeToStream(jaxbSource, pResponse.getOutputStream());

        } catch (final JAXBException e) {
          throw new MessagingException(e);
        }
      }
    }
  }
 private static void saveUserListWithoutLock()
     throws TransformerConfigurationException, SAXException, IOException, SearchLibException {
   ConfigFileRotation cfr =
       configFiles.get(StartStopListener.OPENSEARCHSERVER_DATA_FILE, "users.xml");
   try {
     XmlWriter xmlWriter = new XmlWriter(cfr.getTempPrintWriter("UTF-8"), "UTF-8");
     getUserList().writeXml(xmlWriter);
     xmlWriter.endDocument();
     cfr.rotate();
   } finally {
     cfr.abort();
   }
 }
 private static void toXml(XmlWriter w, Property property) throws IOException {
   w.element(RepositoryParser.P)
       .attribute(RepositoryParser.N, property.getName())
       .attribute(RepositoryParser.T, property.getType())
       .attribute(RepositoryParser.V, property.getValue())
       .end();
 }
Beispiel #10
0
  public static void main(String argv[]) {
    File file = new File("xml1.xml");
    XmlReader reader;
    XmlWriter writer;
    XmlDocument document;
    String xmlout;

    // Construct a document and parse it
    System.out.println("We are going to parse from " + file + ".");
    System.out.println("The parser will be set to verbose mode\n");

    document = new XmlDocument(file);
    reader = new XmlReader();
    reader.setVerbose(true);
    try {
      reader.parse(document);
    } catch (Exception e) {
      e.printStackTrace();
    }
    int errors = reader.getErrorCount();
    int warnings = reader.getWarningCount();

    System.err.println("Completed: " + errors + " errors, " + warnings + " warnings");
    if (errors > 0) {
      System.err.println("Unrecoverable errors in XML. Stop.");
      return;
    }

    // Now print it
    System.out.println("\nHaving parsed the document, we will print it out.");
    System.out.println("Here is the DTD:\n");

    writer = new XmlWriter();
    Writer out = new OutputStreamWriter(System.out);
    try {
      writer.writeDTD(document, out);
    } catch (Exception e) {
      e.printStackTrace();
    }

    System.out.println("\nHere is the XML:\n");
    try {
      writer.write(document, out);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #11
0
 private static void toXml(XmlWriter w, Requirement requirement) throws IOException {
   w.element(RepositoryParser.REQUIRE)
       .attribute(RepositoryParser.NAME, requirement.getName())
       .attribute(RepositoryParser.FILTER, requirement.getFilter())
       .attribute(RepositoryParser.EXTEND, Boolean.toString(requirement.isExtend()))
       .attribute(RepositoryParser.MULTIPLE, Boolean.toString(requirement.isMultiple()))
       .attribute(RepositoryParser.OPTIONAL, Boolean.toString(requirement.isOptional()))
       .text(requirement.getComment().trim())
       .end();
 }
Beispiel #12
0
  private static void toXml(XmlWriter w, Repository repository) throws IOException {
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss.SSS");
    w.element(RepositoryParser.REPOSITORY)
        .attribute(RepositoryParser.NAME, repository.getName())
        .attribute(
            RepositoryParser.LASTMODIFIED, format.format(new Date(repository.getLastModified())));

    if (repository instanceof RepositoryImpl) {
      Referral[] referrals = ((RepositoryImpl) repository).getReferrals();
      for (int i = 0; referrals != null && i < referrals.length; i++) {
        w.element(RepositoryParser.REFERRAL)
            .attribute(RepositoryParser.DEPTH, new Integer(referrals[i].getDepth()))
            .attribute(RepositoryParser.URL, referrals[i].getUrl())
            .end();
      }
    }

    Resource[] resources = repository.getResources();
    for (int i = 0; resources != null && i < resources.length; i++) {
      toXml(w, resources[i]);
    }

    w.end();
  }