Exemplo n.º 1
0
 private static Element makeVariables(SemIm semIm) {
   Element variablesElement = new Element(SemXmlConstants.SEM_VARIABLES);
   Element variable;
   Node measuredNode, latentNode;
   for (Node node1 : semIm.getSemPm().getMeasuredNodes()) {
     measuredNode = node1;
     variable = new Element(SemXmlConstants.CONTINUOUS_VARIABLE);
     variable.addAttribute(new Attribute(SemXmlConstants.NAME, measuredNode.getName()));
     variable.addAttribute(new Attribute(SemXmlConstants.IS_LATENT, "no"));
     variable.addAttribute(
         new Attribute(SemXmlConstants.MEAN, Double.toString(semIm.getMean(measuredNode))));
     variable.addAttribute(
         new Attribute(SemXmlConstants.X, Integer.toString(measuredNode.getCenterX())));
     variable.addAttribute(
         new Attribute(SemXmlConstants.Y, Integer.toString(measuredNode.getCenterY())));
     variablesElement.appendChild(variable);
   }
   for (Node node : semIm.getSemPm().getLatentNodes()) {
     latentNode = node;
     variable = new Element(SemXmlConstants.CONTINUOUS_VARIABLE);
     variable.addAttribute(new Attribute(SemXmlConstants.NAME, latentNode.getName()));
     variable.addAttribute(new Attribute(SemXmlConstants.IS_LATENT, "yes"));
     variable.addAttribute(
         new Attribute(SemXmlConstants.MEAN, Double.toString(semIm.getMean(latentNode))));
     variable.addAttribute(
         new Attribute(SemXmlConstants.X, Integer.toString(latentNode.getCenterX())));
     variable.addAttribute(
         new Attribute(SemXmlConstants.Y, Integer.toString(latentNode.getCenterY())));
     variablesElement.appendChild(variable);
   }
   return variablesElement;
 }
Exemplo n.º 2
0
 /**
  * Converts a Sem Im into xml.
  *
  * @param semIm the instantiated structural equation model to convert
  * @return xml representation
  */
 public static Element getElement(SemIm semIm) {
   Element semElement = new Element(SemXmlConstants.SEM);
   semElement.appendChild(makeVariables(semIm));
   semElement.appendChild(makeEdges(semIm));
   semElement.appendChild(makeMarginalErrorDistribution(semIm));
   semElement.appendChild(makeJointErrorDistribution(semIm));
   return semElement;
 }
Exemplo n.º 3
0
  public Element getXML() {

    Element subfunction = new Element("Subfunction");
    Element name = new Element("Name");
    Element code = new Element("Code");
    Element amount = new Element("Amount");
    name.appendChild(this.title);
    code.appendChild(this.code);
    amount.appendChild(String.valueOf(this.amount));
    return subfunction;
  }
  private Element createBrandElem(
      Brand brand,
      DateTime originalPublicationDate,
      DateTime brandEndDate,
      String lastModified,
      LakeviewContentGroup contentGroup,
      int addedSeasons) {

    Element element = createElement("TVSeries", LAKEVIEW);
    addIdElements(element, brandId(brand), providerMediaId(brand));
    addTitleElements(
        element, Strings.isNullOrEmpty(brand.getTitle()) ? "EMPTY BRAND TITLE" : brand.getTitle());

    appendCommonElements(
        element,
        brand,
        originalPublicationDate,
        lastModified,
        brandAtomUri(findTagAlias(brand)),
        brand.getGenres(),
        null);
    if (addedSeasons > 0) {
      element.appendChild(
          stringElement("TotalNumberOfSeasons", LAKEVIEW, String.valueOf(addedSeasons)));
    }

    element.appendChild(
        stringElement(
            "TotalNumberOfEpisodes", LAKEVIEW, String.valueOf(countEpisodes(contentGroup))));

    if (brand.getPresentationChannel() != null
        && channelResolver.fromKey(brand.getPresentationChannel()).hasValue()) {
      element.appendChild(
          stringElement(
              "Network",
              LAKEVIEW,
              channelResolver.fromKey(brand.getPresentationChannel()).requireValue().getTitle()));
    } else {
      List<Broadcast> broadcasts = extractBroadcasts(contentGroup.episodes());
      if (!broadcasts.isEmpty()) {
        element.appendChild(stringElement("Network", LAKEVIEW, extractNetwork(broadcasts)));
      } else {
        return null;
      }
    }

    if (brandEndDate != null) {
      element.appendChild(
          stringElement("EndYear", LAKEVIEW, String.valueOf(brandEndDate.getYear())));
    }

    return element;
  }
Exemplo n.º 5
0
  public void beforeParsing(Document document) {
    nu.xom.Element html = document.getRootElement();
    nu.xom.Element head = html.getFirstChildElement("head");
    Check.notNull(head, "<head> section is missing from document");
    script = new nu.xom.Element("script");
    script.addAttribute(new Attribute("type", "text/javascript"));

    // Fix for Issue #26: Strict XHTML DTD requires an explicit end tag for <script> element
    // Thanks to Matthias Schwegler for reporting and supplying a fix for this.
    script.appendChild("");

    head.appendChild(script);
  }
Exemplo n.º 6
0
 public final Node generateXML(Entity entity) throws ModelException {
   Element root = new Element("Entity", Entity.NAMESPACE);
   root.addAttribute(new Attribute("id", String.valueOf(entity.getId())));
   root.addAttribute(new Attribute("type", entity.getType()));
   Element name = new Element("name", Entity.NAMESPACE);
   name.appendChild(new Text(entity.getName()));
   root.appendChild(name);
   Node sub = generateSubXML(entity);
   if (sub != null) {
     root.appendChild(sub);
   }
   return root;
 }
Exemplo n.º 7
0
  public Element toXML(String curNS) {
    Element top = new Element("entity", curNS);
    top.addAttribute(new Attribute("id", getObjectId()));
    Element type = new Element("type", curNS);
    type.appendChild(getType());
    top.appendChild(type);
    if (normalizedName != null) {
      Element nm = new Element("normalized", curNS);
      nm.appendChild(normalizedName);
      top.appendChild(nm);
    }

    if (getSubType() != null) {
      Element subtype = new Element("subtype", curNS);
      subtype.appendChild(getSubType());
      top.appendChild(subtype);
    }
    Element span = new Element("span", curNS);
    span.addAttribute(new Attribute("start", Integer.toString(getHeadTokenStart())));
    span.addAttribute(new Attribute("end", Integer.toString(getHeadTokenEnd())));
    top.appendChild(span);

    top.appendChild(makeProbabilitiesElement(curNS));
    return top;
  }
Exemplo n.º 8
0
 private static Element createResults0(Element element) {
   Element newElement = null;
   String tag = element.getLocalName();
   if (ResultsElement.TAG.equals(tag)) {
     newElement = new ResultsElement();
   } else if (ResultElement.TAG.equals(tag)) {
     newElement = new ResultElement();
   } else {
     LOG.error("Unknown element: " + tag);
   }
   XMLUtil.copyAttributes(element, newElement);
   for (int i = 0; i < element.getChildCount(); i++) {
     Node child = element.getChild(i);
     if (child instanceof Text) {
       child = child.copy();
     } else {
       child = ResultsElement.createResults0((Element) child);
     }
     if (newElement != null && child != null) {
       newElement.appendChild(child);
     }
   }
   LOG.trace("XML :" + newElement.toXML());
   return newElement;
 }
 private Element createAvailabilityElement(Episode episode, String platform, String titleId) {
   Element availability = createElement("Availability", LAKEVIEW);
   availability.appendChild(stringElement("DistributionRight", LAKEVIEW, "Free"));
   availability.appendChild(
       stringElement(
           "StartDateTime",
           LAKEVIEW,
           extractFirstAvailabilityDate(episode).toString(DATETIME_FORMAT)));
   availability.appendChild(
       stringElement(
           "EndDateTime",
           LAKEVIEW,
           extractLastAvailabilityDate(episode).toString(DATETIME_FORMAT)));
   availability.appendChild(stringElement("Platform", LAKEVIEW, platform));
   availability.appendChild(stringElement("TitleId", LAKEVIEW, titleId));
   return availability;
 }
  public void writeToFile(File file, ComponentSet set) {

    // add Components
    Element componentRoot = new Element("components");
    componentRoot.addAttribute(new Attribute("autoLocate", "false"));
    componentRoot.addAttribute(new Attribute("rows", Integer.toString(set.getSizeY())));
    componentRoot.addAttribute(new Attribute("cols", Integer.toString(set.getSizeX())));

    Map<Location, Component> componentPositions = set.getComponentPositions();
    for (Location loc : componentPositions.keySet()) {
      Component c = componentPositions.get(loc);

      Element componentElement = new Element("component");
      componentElement.addAttribute(new Attribute("type", c.getId()));
      componentElement.addAttribute(new Attribute("name", c.getName()));
      componentElement.addAttribute(new Attribute("row", Integer.toString(loc.getY())));
      componentElement.addAttribute(new Attribute("col", Integer.toString(loc.getX())));
      componentElement.addAttribute(new Attribute("inv", Boolean.toString(c.isInverted())));

      componentRoot.appendChild(componentElement);
    }

    // add Endpoints
    Set<Endpoint> endpointSet = set.getEndpoints();
    for (Endpoint e : endpointSet) {

      Element endpointElement = new Element("endpoint");
      endpointElement.addAttribute(new Attribute("type", e.getId()));
      endpointElement.addAttribute(new Attribute("name", e.getName()));

      componentRoot.appendChild(endpointElement);
    }

    Document doc = new Document(componentRoot);

    try {
      OutputStream os = new FileOutputStream(file);
      Serializer serializer = new Serializer(os, "ISO-8859-1");
      serializer.setIndent(4);
      serializer.setMaxLength(120);
      serializer.write(doc);
    } catch (IOException e) {
      System.err.println("io error : " + e.getMessage());
    }
  }
 /**
  * @param data
  * @param predecessors
  */
 private void appendPropabilities(TemporalProbabilityFeature data, Element predecessors) {
   for (DataType dtp : data.getPredecessors()) {
     Element probability = new Element("ts:element", Constants.URI);
     probability.addAttribute(new Attribute("type", "probability"));
     probability.addAttribute(new Attribute("eventType", String.valueOf(dtp.getEventType())));
     probability.addAttribute(new Attribute("value", String.valueOf(data.getProbabilityFor(dtp))));
     predecessors.appendChild(probability);
   }
 }
Exemplo n.º 12
0
  Element createSeriesElem(
      Series series, Brand parent, DateTime originalPublicationDate, String lastModified) {
    Element element = createElement("TVSeason", LAKEVIEW);
    String applicationSpecificData = seriesAtomUri(findTagAlias(series));
    String seriesId = seriesId(series);
    String providerMediaId = providerMediaId(series);
    addIdElements(element, seriesId, providerMediaId);

    if (genericTitlesEnabled) {
      if (series.getSeriesNumber() != null) {
        addTitleElements(element, String.format("Series %d", series.getSeriesNumber()));
      } else if (!Strings.isNullOrEmpty(series.getTitle())) {
        addTitleElements(element, String.format("Series %d", series.getTitle()));
      } else {
        addTitleElements(element, parent.getTitle());
      }
    } else if (Strings.isNullOrEmpty(series.getTitle())
        || series.getTitle().matches("(?i)series \\d+")) {
      addTitleElements(
          element, String.format("%s Series %s", parent.getTitle(), series.getSeriesNumber()));
    } else {
      addTitleElements(element, series.getTitle());
    }

    Set<String> genres =
        Iterables.isEmpty(series.getGenres()) ? parent.getGenres() : series.getGenres();
    appendCommonElements(
        element,
        series,
        originalPublicationDate,
        lastModified,
        applicationSpecificData,
        genres,
        null);

    element.appendChild(
        stringElement("SeasonNumber", LAKEVIEW, String.valueOf(series.getSeriesNumber())));
    element.appendChild(stringElement("SeriesId", LAKEVIEW, brandId(parent)));

    return element;
  }
  /**
   * Marshall the data in this object to an Element object.
   *
   * @return The data expressed in an Element.
   */
  public Element marshall() {
    Element element = new Element(getQualifiedName(), Namespaces.NS_ATOM);
    if (type != null) {
      Attribute typeAttribute = new Attribute(ATTRIBUTE_TYPE, type.toString());
      element.addAttribute(typeAttribute);
    }

    if (content != null) {
      element.appendChild(content);
    }
    return element;
  }
Exemplo n.º 14
0
 private void processSectionMedia(Element sectionMedia) {
   // for each embedded media found in the text-section, add it to the media section as a media-set
   for (Map.Entry<Integer, String> entry : embeddedMedia.entrySet()) {
     Element sectionMediaSet = new Element(PageContentElements.MEDIA_SET, ContentPreparer.NS);
     sectionMediaSet.addAttribute(new Attribute(PageContentAttributes.ID, "" + entry.getKey()));
     sectionMediaSet.addAttribute(
         new Attribute(MediaContentAttributes.THUMBNAIL, entry.getValue()));
     sectionMedia.appendChild(sectionMediaSet);
   }
   // hey - we're in a loop, and it's got "text-section" locality, so we need to clear this
   // hashmap out before the next text-section is processed
   embeddedMedia.clear();
 }
Exemplo n.º 15
0
 private void addPathToTree(Path path, int currentDepth) throws IOException {
   Element element = getElement(path);
   Attribute depth = new Attribute("depth", String.valueOf(currentDepth));
   element.addAttribute(depth);
   Element parent = map.get(path.getParent());
   if (parent != null) {
     map.put(path, element);
     parent.appendChild(element);
   } else {
     map.put(path, rootDirElement);
     setName(rootDirElement, path);
   }
 }
Exemplo n.º 16
0
 public synchronized void addFile(PseudoPath path) {
   if (path.equals(new PseudoPath())) {
     throw new IllegalArgumentException("Adding empty path does not allowed.");
   }
   PseudoPath parent = path.getParent();
   Element parentElement = getElement(parent);
   if (parentElement == null) {
     throw new IllegalArgumentException("Parent directory does not exist.");
   } else {
     Element childElement = new Element(FileType.FILE.getName());
     String filename = path.getName(path.getNameCount() - 1);
     childElement.addAttribute(new Attribute("name", filename));
     parentElement.appendChild(childElement);
   }
 }
Exemplo n.º 17
0
  public synchronized void addToDirectory(PseudoPath dir, FSImage child) {
    if (!getType(dir).equals(FileType.DIR.getName())) {
      throw new IllegalArgumentException("Can add files only to directories.");
    }
    Element parent = getElement(dir);
    Element newChild = new Element(child.fileTree);

    String nameOfChildRoot = child.fileTree.getAttributeValue("name");
    PseudoPath pathToChild = dir.resolve(nameOfChildRoot);
    Element oldChild = getElement(pathToChild);
    if (oldChild != null) {
      parent.replaceChild(oldChild, newChild);
    } else {
      parent.appendChild(newChild);
    }
  }
Exemplo n.º 18
0
  private static Element makeMarginalErrorDistribution(SemIm semIm) {
    Element marginalErrorElement = new Element(SemXmlConstants.MARGINAL_ERROR_DISTRIBUTION);
    Element normal;

    SemGraph semGraph = semIm.getSemPm().getGraph();
    semGraph.setShowErrorTerms(true);

    for (Node node : getExogenousNodes(semGraph)) {
      normal = new Element(SemXmlConstants.NORMAL);
      normal.addAttribute(new Attribute(SemXmlConstants.VARIABLE, node.getName()));
      normal.addAttribute(new Attribute(SemXmlConstants.MEAN, "0.0"));
      normal.addAttribute(
          new Attribute(
              SemXmlConstants.VARIANCE, Double.toString(semIm.getParamValue(node, node))));
      marginalErrorElement.appendChild(normal);
    }
    return marginalErrorElement;
  }
Exemplo n.º 19
0
  private static Element makeJointErrorDistribution(SemIm semIm) {
    Element jointErrorElement = new Element(SemXmlConstants.JOINT_ERROR_DISTRIBUTION);
    Element normal;
    Parameter param;

    for (Parameter parameter : semIm.getSemPm().getParameters()) {
      param = parameter;
      if (param.getType() == ParamType.COVAR) {
        normal = new Element(SemXmlConstants.NORMAL);
        normal.addAttribute(new Attribute(SemXmlConstants.NODE_1, param.getNodeA().getName()));
        normal.addAttribute(new Attribute(SemXmlConstants.NODE_2, param.getNodeB().getName()));
        normal.addAttribute(
            new Attribute(SemXmlConstants.COVARIANCE, Double.toString(param.getStartingValue())));
        jointErrorElement.appendChild(normal);
      }
    }

    return jointErrorElement;
  }
Exemplo n.º 20
0
  public Document compile(List<LakeviewContentGroup> contents) {

    Element feed = createElement("Feed", LAKEVIEW);
    feed.addAttribute(new Attribute("ProviderName", PROVIDER_NAME));

    // This is specified. Don't use lastUpdated....
    String lastModified = DATETIME_FORMAT.print(clock.now());

    Set<String> seenItems = Sets.newHashSet();
    for (LakeviewContentGroup contentGroup : contents) {
      List<Element> groupElements = elementsForGroup(lastModified, contentGroup, seenItems);

      for (Element element : groupElements) {
        feed.appendChild(element);
      }
    }

    return new Document(feed);
  }
Exemplo n.º 21
0
  private static Element makeEdges(SemIm semIm) {
    Element edgesElement = new Element(SemXmlConstants.EDGES);
    Parameter param;
    Element edge;

    for (Parameter parameter : semIm.getSemPm().getParameters()) {
      param = parameter;
      if (param.getType() == ParamType.COEF) {
        edge = new Element(SemXmlConstants.EDGE);
        edge.addAttribute(new Attribute(SemXmlConstants.CAUSE_NODE, param.getNodeA().getName()));
        edge.addAttribute(new Attribute(SemXmlConstants.EFFECT_NODE, param.getNodeB().getName()));
        edge.addAttribute(
            new Attribute(SemXmlConstants.VALUE, Double.toString(semIm.getParamValue(param))));
        edge.addAttribute(
            new Attribute(SemXmlConstants.FIXED, Boolean.valueOf(param.isFixed()).toString()));
        edgesElement.appendChild(edge);
      }
    }
    return edgesElement;
  }
Exemplo n.º 22
0
  /**
   * Given an iText PDF Reader, extract image data from the PDF and store it in a XOM XML element.
   *
   * @param reader A reader for the given PDF.
   * @return A XOM element containing image data.
   */
  public static Element extractToXML(PdfReader reader) {
    Element root = new Element("Images");
    PdfReaderContentParser parser = new PdfReaderContentParser(reader);

    // Go through the PDF one page at a time, pulling images from each page.
    ImageRenderListener listener = new ImageRenderListener();
    for (int i = 1; i <= reader.getNumberOfPages(); i++) {
      try {
        listener = parser.processContent(i, new ImageRenderListener());
      } catch (IOException e) {
      }
      List<Element> images = listener.getImageData();

      // Add the current page number to each image, add it to the root.
      if (images != null) {
        for (Element image : images) {
          image.addAttribute(new Attribute("Page", Integer.toString(i)));
          root.appendChild(image);
        }
      }
    }

    return root;
  }
Exemplo n.º 23
0
 private void addTitleElements(Element element, String title) {
   element.appendChild(stringElement("Title", LAKEVIEW, title));
   element.appendChild(
       stringElement("SortTitle", LAKEVIEW, sortTitleGenerator.createSortTitle(title)));
 }
Exemplo n.º 24
0
  private void construeixModel(ParcAtraccions pParcAtraccions) throws ParcAtraccionsExcepcio {
    // Mètode on heu de construir el document XML
    Element raiz = new Element("parcAtraccions");
    raiz.addAttribute(new Attribute("codi", pParcAtraccions.getCodi().toString()));
    raiz.addAttribute(new Attribute("nom", pParcAtraccions.getNom()));
    raiz.addAttribute(new Attribute("adreca", pParcAtraccions.getAdreca()));
    Element coordinadores = new Element("coordinadores");
    raiz.appendChild(coordinadores);
    Element personasMantenimiento = new Element("personasMantenimiento");
    raiz.appendChild(personasMantenimiento);
    Element atracciones = new Element("atracciones");
    raiz.appendChild(atracciones);
    Element zonas = new Element("zonas");
    raiz.appendChild(zonas);
    for (int i = 0; i < pParcAtraccions.getComptaElements(); i++) {
      Element elemento;
      if (pParcAtraccions.getElements()[i] instanceof Atraccio) {
        elemento = new Element("atraccion");
        Element nombre = new Element("nombre");
        nombre.appendChild(((Atraccio) pParcAtraccions.getElements()[i]).getNom());
        elemento.appendChild(nombre);
        Element tipus = new Element("tipus");
        tipus.appendChild(((Atraccio) pParcAtraccions.getElements()[i]).getTipus());
        elemento.appendChild(tipus);
        Element restriccionEdad = new Element("restriccionEdad");
        restriccionEdad.appendChild(
            String.valueOf(((Atraccio) pParcAtraccions.getElements()[i]).getRestriccioEdat()));
        elemento.appendChild(restriccionEdad);
        Element restriccionAltura = new Element("restriccionAltura");
        restriccionAltura.appendChild(
            String.valueOf(((Atraccio) pParcAtraccions.getElements()[i]).getRestriccioAlcada()));
        elemento.appendChild(restriccionAltura);
        Element tieneProblema = new Element("tieneProblema");
        tieneProblema.appendChild(
            String.valueOf(((Atraccio) pParcAtraccions.getElements()[i]).getTeProblema()));
        elemento.appendChild(tieneProblema);
        Element codigoProblema = new Element("codigoProblema");
        codigoProblema.appendChild(
            String.valueOf(((Atraccio) pParcAtraccions.getElements()[i]).getCodiProblema()));
        elemento.appendChild(codigoProblema);
        Element estaSolucionado = new Element("estaSolucionado");
        estaSolucionado.appendChild(
            String.valueOf(((Atraccio) pParcAtraccions.getElements()[i]).getEstaSolucionat()));
        elemento.appendChild(estaSolucionado);
        atracciones.appendChild(elemento);
        continue;
      } else if (pParcAtraccions.getElements()[i] instanceof Zona) {
        Element raiz2 = new Element("zona");
        raiz2.addAttribute(new Attribute("nombre", pParcAtraccions.getCodi().toString()));
        Element coordinadores2 = new Element("coordinadores");
        raiz2.appendChild(coordinadores2);
        Element personasMantenimiento2 = new Element("personasMantenimiento");
        raiz2.appendChild(personasMantenimiento2);
        Element atracciones2 = new Element("atracciones");
        raiz2.appendChild(atracciones2);

        for (int j = 0; j < ((Zona) pParcAtraccions.getElements()[i]).getComptaElements(); j++) {
          Element elemento2;
          if (pParcAtraccions.getElements()[j] instanceof Atraccio) {
            elemento2 = new Element("atraccion");
            Element nombre = new Element("nombre");
            nombre.appendChild(((Atraccio) pParcAtraccions.getElements()[j]).getNom());
            elemento2.appendChild(nombre);
            Element tipus = new Element("tipus");
            tipus.appendChild(((Atraccio) pParcAtraccions.getElements()[j]).getTipus());
            elemento2.appendChild(tipus);
            Element restriccionEdad = new Element("restriccionEdad");
            restriccionEdad.appendChild(
                String.valueOf(((Atraccio) pParcAtraccions.getElements()[j]).getRestriccioEdat()));
            elemento2.appendChild(restriccionEdad);
            Element restriccionAltura = new Element("restriccionAltura");
            restriccionAltura.appendChild(
                String.valueOf(
                    ((Atraccio) pParcAtraccions.getElements()[j]).getRestriccioAlcada()));
            elemento2.appendChild(restriccionAltura);
            Element tieneProblema = new Element("tieneProblema");
            tieneProblema.appendChild(
                String.valueOf(((Atraccio) pParcAtraccions.getElements()[j]).getTeProblema()));
            elemento2.appendChild(tieneProblema);
            Element codigoProblema = new Element("codigoProblema");
            codigoProblema.appendChild(
                String.valueOf(((Atraccio) pParcAtraccions.getElements()[j]).getCodiProblema()));
            elemento2.appendChild(codigoProblema);
            Element estaSolucionado = new Element("estaSolucionado");
            estaSolucionado.appendChild(
                String.valueOf(((Atraccio) pParcAtraccions.getElements()[j]).getEstaSolucionat()));
            elemento2.appendChild(estaSolucionado);
            atracciones2.appendChild(elemento2);
            continue;
          }
          if (pParcAtraccions.getElements()[i] instanceof Coordinador) {
            elemento2 = new Element("coordinador");
            coordinadores2.appendChild(elemento2);
          } else {
            elemento2 = new Element("personaManteniment");
            personasMantenimiento2.appendChild(elemento2);
          }

          Element nif = new Element("nif");
          nif.appendChild(((Persona) pParcAtraccions.getElements()[i]).getNif());
          elemento2.appendChild(nif);
          Element nom = new Element("nom");
          nom.appendChild(((Persona) pParcAtraccions.getElements()[i]).getNom());
          elemento2.appendChild(nom);
          Element cognom = new Element("cognom");
          cognom.appendChild(((Persona) pParcAtraccions.getElements()[i]).getCognom());
          elemento2.appendChild(cognom);
        }
        zonas.appendChild(raiz2);
      } else if (pParcAtraccions.getElements()[i] instanceof Coordinador) {
        elemento = new Element("coordinador");
        coordinadores.appendChild(elemento);
      } else if (pParcAtraccions.getElements()[i] instanceof PersonaManteniment) {
        elemento = new Element("personaManteniment");
        personasMantenimiento.appendChild(elemento);
      }
      /*
      Element nif = new Element("nif");
      nif.appendChild(((Persona)pParcAtraccions.getElements()[i]).getNif());
      elemento.appendChild(nif);
      Element nom = new Element("nom");
      nom.appendChild(((Persona)pParcAtraccions.getElements()[i]).getNom());
      elemento.appendChild(nom);
      Element cognom = new Element("cognom");
      cognom.appendChild(((Persona)pParcAtraccions.getElements()[i]).getCognom());
      elemento.appendChild(cognom);
             */
    }
    doc.setRootElement(raiz);
    // System.out.println(doc.toXML());
  }
Exemplo n.º 25
0
  public static void generateXML(RPSBulk rpsBulk, String outputFile, String namespace)
      throws IOException {

    Element enviarLoteRpsEnvio = new Element(ENVIAR_LOTE_RPS_ENVIO, namespace);

    Element loteRps = new Element(LOTE_RPS, namespace);
    loteRps.addAttribute(new Attribute("Id", rpsBulk.getId()));

    Element numeroLote = new Element(NUMERO_LOTE, namespace);
    numeroLote.appendChild(rpsBulk.getNumeroLote());
    loteRps.appendChild(numeroLote);

    Element cnpj = new Element(CNPJ, namespace);
    cnpj.appendChild(rpsBulk.getCnpj());
    loteRps.appendChild(cnpj);

    Element inscricaoMunicipal = new Element(INSCRICAO_MUNICIPAL, namespace);
    inscricaoMunicipal.appendChild(rpsBulk.getInscricaoMunicipal());
    loteRps.appendChild(inscricaoMunicipal);

    Element quantidadeRps = new Element(QUANTIDADE_RPS, namespace);
    quantidadeRps.appendChild(Integer.toString(rpsBulk.getQuantidadeRps()));
    loteRps.appendChild(quantidadeRps);

    Element listaRps = new Element(LISTA_RPS, namespace);

    for (RPS rps : rpsBulk.getListaRps()) {
      Element rpsElement = new Element(RPS, namespace);

      Element infRps = new Element(INF_RPS, namespace);
      infRps.addAttribute(new Attribute("Id", rps.getId()));

      Element identificacaoRps = new Element(IDENTIFICACAO_RPS, namespace);

      Element numero = new Element(NUMERO, namespace);
      numero.appendChild(rps.getNumero());
      identificacaoRps.appendChild(numero);

      Element serie = new Element(SERIE, namespace);
      serie.appendChild(rps.getSerie());
      identificacaoRps.appendChild(serie);

      Element tipo = new Element(TIPO, namespace);
      tipo.appendChild(rps.getTipo());
      identificacaoRps.appendChild(tipo);

      infRps.appendChild(identificacaoRps);

      Element dataEmissao = new Element(DATA_EMISSAO, namespace);
      dataEmissao.appendChild(rps.getDataEmissao());
      infRps.appendChild(dataEmissao);

      Element naturezaOperacao = new Element(NATUREZAO_OPERACAO, namespace);
      naturezaOperacao.appendChild(rps.getNaturezaOperacao());
      infRps.appendChild(naturezaOperacao);

      Element optanteSimplesNacional = new Element(OPTANTE_SIMPLES_NACIONAL, namespace);
      optanteSimplesNacional.appendChild(rps.getOptanteSimplesNacional());
      infRps.appendChild(optanteSimplesNacional);

      Element incentivadorCultural = new Element(INCENTIVADOR_CULTURAL, namespace);
      incentivadorCultural.appendChild(rps.getIncentivadorCultural());
      infRps.appendChild(incentivadorCultural);

      Element status = new Element(STATUS, namespace);
      status.appendChild(rps.getStatus());
      infRps.appendChild(status);

      Element servico = new Element(SERVICO, namespace);

      Element valores = new Element(VALORES, namespace);

      Element valorServicos = new Element(VALOR_SERVICOS, namespace);
      valorServicos.appendChild(rps.getValorServicos());
      valores.appendChild(valorServicos);

      Element valorDeducoes = new Element(VALOR_DEDUCOES, namespace);
      valorDeducoes.appendChild(rps.getValorDeducoes());
      valores.appendChild(valorDeducoes);

      Element valorPis = new Element(VALOR_PIS, namespace);
      valorPis.appendChild(rps.getValorPis());
      valores.appendChild(valorPis);

      Element valorCofins = new Element(VALOR_COFINS, namespace);
      valorCofins.appendChild(rps.getValorCofins());
      valores.appendChild(valorCofins);

      Element valorInss = new Element(VALOR_INSS, namespace);
      valorInss.appendChild(rps.getValorInss());
      valores.appendChild(valorInss);

      Element valorIr = new Element(VALOR_IR, namespace);
      valorIr.appendChild(rps.getValorIr());
      valores.appendChild(valorIr);

      Element valorCsll = new Element(VALOR_CSLL, namespace);
      valorCsll.appendChild(rps.valorCsll);
      valores.appendChild(valorCsll);

      Element issRetido = new Element(ISS_RETIDO, namespace);
      issRetido.appendChild(rps.getIssRetido());
      valores.appendChild(issRetido);

      Element valorIss = new Element(VALOR_ISS, namespace);
      valorIss.appendChild(rps.getValorIss());
      valores.appendChild(valorIss);

      Element outrasRetencoes = new Element(OUTRAS_RETENCOES, namespace);
      outrasRetencoes.appendChild(rps.getOutrasRetencoes());
      valores.appendChild(outrasRetencoes);

      Element aliquota = new Element(ALIQUOTA, namespace);
      aliquota.appendChild(rps.getAliquota());
      valores.appendChild(aliquota);

      Element descontoIncondicionado = new Element(DESCONTO_INCONDICIONADO, namespace);
      descontoIncondicionado.appendChild(rps.getDescontoIncondicionado());
      valores.appendChild(descontoIncondicionado);

      Element descontoCondicionado = new Element(DESCONTO_CONDICIONADO, namespace);
      descontoCondicionado.appendChild(rps.getDescontoCondicionado());
      valores.appendChild(descontoCondicionado);

      servico.appendChild(valores);

      Element itemListaServico = new Element(ITEM_LISTA_SERVICO, namespace);
      itemListaServico.appendChild(rps.getItemListaServico());
      servico.appendChild(itemListaServico);

      Element codigoTributacaoMunicipio = new Element(CODIGO_TRIBUTACAO_MUNICIPIO, namespace);
      codigoTributacaoMunicipio.appendChild(rps.getCodigoTributacaoMunicipio());
      servico.appendChild(codigoTributacaoMunicipio);

      Element discriminacao = new Element(DISCRIMINACAO, namespace);
      discriminacao.appendChild(rps.getDiscriminacao());
      servico.appendChild(discriminacao);

      Element servicosCodigoMunicipio = new Element(CODIGO_MUNICIPIO, namespace);
      servicosCodigoMunicipio.appendChild(rps.getServicos_codigoMunicipio());
      servico.appendChild(servicosCodigoMunicipio);

      infRps.appendChild(servico);

      Element prestador = new Element(PRESTADOR, namespace);

      Element prestadorCnpj = new Element(CNPJ, namespace);
      prestadorCnpj.appendChild(rps.getPrestador_cnpj());
      prestador.appendChild(prestadorCnpj);

      Element prestadorInscricaoMunicipal = new Element(INSCRICAO_MUNICIPAL, namespace);
      prestadorInscricaoMunicipal.appendChild(rps.getInscricaoMunicipal());
      prestador.appendChild(prestadorInscricaoMunicipal);

      infRps.appendChild(prestador);

      Element tomador = new Element(TOMADOR, namespace);

      Element identificaoTomador = new Element(IDENTIFICACAO_TOMADOR, namespace);

      Element cpfCnpj = new Element(CPF_CNPJ, namespace);

      if (rps.getTomador_cpf() == null) {
        Element tomadorCnpj = new Element(CNPJ, namespace);
        tomadorCnpj.appendChild(rps.getTomador_cnpj());
        cpfCnpj.appendChild(tomadorCnpj);
      } else {
        Element tomadorCpf = new Element(CPF, namespace);
        tomadorCpf.appendChild(rps.getTomador_cpf());
        cpfCnpj.appendChild(tomadorCpf);
      }
      identificaoTomador.appendChild(cpfCnpj);

      tomador.appendChild(identificaoTomador);

      Element razaoSocial = new Element(RAZAO_SOCIAL, namespace);
      razaoSocial.appendChild(rps.getRazaoSocial());
      tomador.appendChild(razaoSocial);

      Element endereco = new Element(ENDERECO, namespace);

      if (!rps.getEndereco().isEmpty()) {
        Element enderecoEndereco = new Element(ENDERECO, namespace);
        enderecoEndereco.appendChild(rps.getEndereco());
        endereco.appendChild(enderecoEndereco);
      }

      if (!rps.getEndereco_numero().isEmpty()) {
        Element enderecoNumero = new Element(NUMERO, namespace);
        enderecoNumero.appendChild(rps.getEndereco_numero());
        endereco.appendChild(enderecoNumero);
      }

      if (!rps.getComplemento().isEmpty()) {
        Element complemento = new Element(COMPLEMENTO, namespace);
        complemento.appendChild(rps.getComplemento());
        endereco.appendChild(complemento);
      }

      if (!rps.getBairro().isEmpty()) {
        Element bairro = new Element(BAIRRO, namespace);
        bairro.appendChild(rps.getBairro());
        endereco.appendChild(bairro);
      }

      if (!rps.getEndereco_codigoMunicipio().isEmpty()) {
        Element enderecoCodigoMunicipio = new Element(CODIGO_MUNICIPIO, namespace);
        enderecoCodigoMunicipio.appendChild(rps.getEndereco_codigoMunicipio());
        endereco.appendChild(enderecoCodigoMunicipio);
      }

      if (!rps.getUf().isEmpty()) {
        Element uf = new Element(UF, namespace);
        uf.appendChild(rps.getUf());
        endereco.appendChild(uf);
      }

      if (!rps.getCep().isEmpty()) {
        Element cep = new Element(CEP, namespace);
        cep.appendChild(rps.getCep());
        endereco.appendChild(cep);
      }

      if (endereco.getChildElements().size() != 0) {
        tomador.appendChild(endereco);
      }

      Element contato = new Element(CONTATO, namespace);

      Element email = new Element(EMAIL, namespace);
      email.appendChild(rps.getEmail());
      contato.appendChild(email);

      tomador.appendChild(contato);

      infRps.appendChild(tomador);

      rpsElement.appendChild(infRps);
      listaRps.appendChild(rpsElement);
    }
    loteRps.appendChild(listaRps);
    enviarLoteRpsEnvio.appendChild(loteRps);

    // Document doc = new Document(enviarLoteRpsEnvio);

    // Writes to XML console.
    /*	Serializer serializer = new Serializer(System.out, OUTPUT_ENCODING);
    serializer.setIndent(2);
    serializer.setMaxLength(0);
    serializer.write(doc);*/

    // Writes XML to file.
    FileOutputStream fos = new FileOutputStream(outputFile, false);
    PrintWriter pw = new PrintWriter(fos);
    pw.write(enviarLoteRpsEnvio.toXML());
    pw.close();
    fos.close();
  }
  public String toXML() {
    Element root = new Element("testCaseTemplateParameter");

    for (String importName : imports) {
      Element importElement = new Element("import");
      importElement.appendChild(importName);
      root.appendChild(importElement);
    }

    for (Map.Entry<String, String> entry : classToMockInstanceNameMap.entrySet()) {
      Element classToMockElement = new Element("classToMock");

      // ClassName
      Element classNameElement = new Element("className");
      classNameElement.appendChild(entry.getKey());
      classToMockElement.appendChild(classNameElement);

      // InstanceName
      Element instanceNameElement = new Element("instanceName");
      instanceNameElement.appendChild(entry.getValue());
      classToMockElement.appendChild(instanceNameElement);

      // Invokes
      for (String invoke : jMockInvokeSequenceMap.get(entry.getKey())) {
        Element invokeElement = new Element("invoke");
        invokeElement.appendChild(invoke);
        classToMockElement.appendChild(invokeElement);
      }
      root.appendChild(classToMockElement);
    }

    Element packageNameElement = new Element("packageName");
    packageNameElement.appendChild(this.getPackageName());
    root.appendChild(packageNameElement);

    Element classUnderTestElement = new Element("classUnderTest");
    classUnderTestElement.appendChild(this.getClassUnderTest());
    root.appendChild(classUnderTestElement);

    for (Argument constructorArgument : constructorArguments) {
      Element constructorArgumentElement = new Element("constructorArgument");
      Element typeElement = new Element("type");
      typeElement.appendChild(constructorArgument.getType());
      Element valueElement = new Element("value");
      valueElement.appendChild(constructorArgument.getValue());
      constructorArgumentElement.appendChild(typeElement);
      constructorArgumentElement.appendChild(valueElement);
      root.appendChild(constructorArgumentElement);
    }

    Element methodUnderTestElement = new Element("methodUnderTest");
    methodUnderTestElement.appendChild(this.getMethodUnderTest());
    root.appendChild(methodUnderTestElement);

    for (Parameter methodParameter : methodParameters) {
      Element methodParameterElement = new Element("methodParameter");
      Element typeElement = new Element("type");
      typeElement.appendChild(methodParameter.getType());
      Element nameElement = new Element("name");
      nameElement.appendChild(methodParameter.getName());
      methodParameterElement.appendChild(typeElement);
      methodParameterElement.appendChild(nameElement);
      root.appendChild(methodParameterElement);
    }

    Element isStaticMethodElement = new Element("isStaticMethod");
    isStaticMethodElement.appendChild("" + this.isStaticMethod());
    root.appendChild(isStaticMethodElement);

    if (this.isSingleton()) {
      Element singletonMethodElement = new Element("singletonMethod");
      singletonMethodElement.appendChild(this.getSingletonMethod());
      root.appendChild(singletonMethodElement);
    }

    if (this.hasCheckStateMethod()) {
      Element checkStateMethodElement = new Element("checkStateMethod");
      checkStateMethodElement.appendChild(this.getCheckStateMethod());
      root.appendChild(checkStateMethodElement);
    }

    Element returnTypeElement = new Element("returnType");
    returnTypeElement.appendChild(this.getReturnType());
    root.appendChild(returnTypeElement);

    if (this.hasDelta()) {
      Element deltaElement = new Element("delta");
      deltaElement.appendChild("" + this.getDelta());
      root.appendChild(deltaElement);
    }

    Document doc = new Document(root);
    return doc.toXML();
  }
Exemplo n.º 27
0
 protected Element stringElement(String name, XMLNamespace ns, String value) {
   Element elem = createElement(name, ns);
   elem.appendChild(value);
   return elem;
 }
Exemplo n.º 28
0
  private void appendCommonElements(
      Element element,
      Content content,
      DateTime originalPublicationDate,
      String lastModified,
      String applicationSpecificData,
      Iterable<String> genres,
      Element instances) {

    if (!Strings.isNullOrEmpty(content.getDescription())) {
      element.appendChild(stringElement("Description", LAKEVIEW, content.getDescription()));
    }

    if (applicationSpecificData != null) {
      element.appendChild(
          stringElement("ApplicationSpecificData", LAKEVIEW, applicationSpecificData));
    }

    element.appendChild(stringElement("LastModifiedDate", LAKEVIEW, lastModified));
    element.appendChild(stringElement("ApplicableLocale", LAKEVIEW, LOCALE));

    if (content instanceof Brand && content.getImage() != null) {

      Element imageElem = createElement("Image", LAKEVIEW);
      imageElem.appendChild(stringElement("ImagePurpose", LAKEVIEW, "BoxArt"));
      imageElem.appendChild(stringElement("Url", LAKEVIEW, content.getImage()));

      Element imagesElement = createElement("Images", LAKEVIEW);
      imagesElement.appendChild(imageElem);
      element.appendChild(imagesElement);
    }

    if (!Iterables.isEmpty(genres)) {
      Element genresElem = createElement("Genres", LAKEVIEW);
      for (String genre : genres) {
        if (genre.startsWith("http://www.channel4.com")) {
          genresElem.appendChild(stringElement("Genre", LAKEVIEW, C4GenreTitles.title(genre)));
        }
      }
      element.appendChild(genresElem);
    }

    Element pc = createElement("ParentalControl", LAKEVIEW);
    pc.appendChild(stringElement("HasGuidance", LAKEVIEW, String.valueOf(true)));
    element.appendChild(pc);
    element.appendChild(
        stringElement("PublicWebUri", LAKEVIEW, String.format("%s.atom", webUriRoot(content))));

    if (instances != null) {
      element.appendChild(instances);
    }

    element.appendChild(
        stringElement(
            "OriginalPublicationDate",
            LAKEVIEW,
            originalPublicationDate.toString(DATETIME_FORMAT)));
  }
Exemplo n.º 29
0
 private void addIdElements(Element element, String id, String providerMediaId) {
   element.appendChild(stringElement("ItemId", LAKEVIEW, id));
   element.appendChild(stringElement("ProviderMediaId", LAKEVIEW, providerMediaId));
 }
Exemplo n.º 30
0
  Element createEpisodeElem(
      Episode episode,
      Brand container,
      Series series,
      DateTime originalPublicationDate,
      String lastModified) {
    Element element = createElement("TVEpisode", LAKEVIEW);

    Comment comment = new Comment("Atlas ID: " + episode.getCanonicalUri());
    element.appendChild(comment);

    String assetId = extractAssetId(episode);
    String programmedId = extractProgrammedId(episode);
    String applicationSpecificData =
        episodeAtomUri(brandAtomUri(findTagAlias(container)), programmedId);

    String providerMediaId;
    if (series != null) {
      providerMediaId = providerMediaId(series) + "#" + assetId;
    } else {
      providerMediaId = providerMediaId(container) + "#" + assetId;
    }
    addIdElements(element, episodeId(episode), providerMediaId);

    if (genericTitlesEnabled) {
      if (episode.getEpisodeNumber() != null) {
        addTitleElements(element, String.format("Episode %d", episode.getEpisodeNumber()));
      } else if (!Strings.isNullOrEmpty(episode.getTitle())) {
        addTitleElements(element, episode.getTitle());
      } else {
        addTitleElements(element, container.getTitle());
      }
    } else if (Strings.isNullOrEmpty(episode.getTitle())
        || episode.getTitle().matches("(?i)(series \\d+)? episode \\d+")) {
      addTitleElements(
          element,
          String.format(
              "%s Series %s Episode %s",
              container.getTitle(), episode.getSeriesNumber(), episode.getEpisodeNumber()));
    } else {
      addTitleElements(element, episode.getTitle());
    }

    Element instances = createElement("Instances", LAKEVIEW);
    Element videoInstance = createElement("VideoInstance", LAKEVIEW);

    Element availabilities = createElement("Availabilities", LAKEVIEW);
    Element availability = createAvailabilityElement(episode, "Xbox360", PROVIDER_ID);

    if (addXboxOneAvailability) {
      availabilities.appendChild(
          createAvailabilityElement(episode, "XboxOne", XBOX_ONE_PROVIDER_ID));
    }

    availabilities.appendChild(availability);
    videoInstance.appendChild(availabilities);
    videoInstance.appendChild(stringElement("ResolutionFormat", LAKEVIEW, "SD"));
    videoInstance.appendChild(stringElement("DeliveryFormat", LAKEVIEW, "Streaming"));
    videoInstance.appendChild(stringElement("PrimaryAudioLanguage", LAKEVIEW, "en-GB"));
    videoInstance.appendChild(stringElement("VideoInstanceType", LAKEVIEW, "Full"));

    instances.appendChild(videoInstance);

    appendCommonElements(
        element,
        episode,
        originalPublicationDate,
        lastModified,
        applicationSpecificData,
        episode.getGenres(),
        instances);

    element.appendChild(
        stringElement("EpisodeNumber", LAKEVIEW, String.valueOf(episode.getEpisodeNumber())));
    element.appendChild(
        stringElement("DurationInSeconds", LAKEVIEW, String.valueOf(duration(episode))));
    element.appendChild(stringElement("SeriesId", LAKEVIEW, brandId(container)));
    if (episode.getSeriesRef() != null) {
      element.appendChild(stringElement("SeasonId", LAKEVIEW, seriesId(series)));
    }

    return element;
  }