コード例 #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;
 }
コード例 #2
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;
  }
コード例 #3
0
 /**
  * @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);
   }
 }
コード例 #4
0
ファイル: Context.java プロジェクト: StexX/KiWi-OSE
  /**
   * Creates bookmark elements in the document at the position of this context. The document has to
   * come from the same textcontent as the original context. (but since this method should not
   * modify the text coordinates itself, it should be possible to fragmentize multiple fragments
   * sequentially.)
   *
   * @param doc XOM document.
   * @param fragmentId The fragment ID for the fragment to create.
   * @return modified XOM document with the bookmark elements created.
   */
  public void fragmentize(Document doc, String fragmentId, int offset) {

    Element e_begin = new Element("kiwi:bookmarkstart", Constants.NS_KIWI_HTML);
    e_begin.addAttribute(new Attribute("id", fragmentId));

    KiWiXomUtils.insertNodeAtPos(doc, 0, inBegin + offset, e_begin);

    Element e_end = new Element("kiwi:bookmarkend", Constants.NS_KIWI_HTML);
    e_end.addAttribute(new Attribute("id", fragmentId));

    KiWiXomUtils.insertNodeAtPos(doc, 0, inEnd + offset, e_end);
  }
コード例 #5
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;
 }
コード例 #6
0
ファイル: PageCoPreparer.java プロジェクト: tolweb/tolweb-app
 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();
 }
コード例 #7
0
    @Override
    public void renderImage(ImageRenderInfo renderInfo) {
      try {
        PdfNumber width = (PdfNumber) renderInfo.getImage().get(PdfName.WIDTH);
        PdfNumber height = (PdfNumber) renderInfo.getImage().get(PdfName.HEIGHT);
        // data = data + "<image width=\"" + width + "\" height=\"" + height + "\">\n</image>\n";
        Element element = new Element("Image");
        element.addAttribute(new Attribute("Width", width.toString()));
        element.addAttribute(new Attribute("Height", height.toString()));
        elements.add(element);
      } catch (Exception e) {

      }
    }
コード例 #8
0
 public FileTreeBuilder(Element rootDirElement, WatchService watcher, int maxDepth) {
   this.rootDirElement = rootDirElement;
   this.watcher = watcher;
   currentDepth = maxDepth;
   Attribute depth = new Attribute("depth", String.valueOf(currentDepth));
   rootDirElement.addAttribute(depth);
 }
コード例 #9
0
 // Set file name to one of the attributes of the elements
 private void setName(Element element, Path path) {
   if (path.getNameCount() > 0) {
     String fileName = path.getFileName().toString();
     Attribute name = new Attribute("name", fileName);
     element.addAttribute(name);
   }
 }
コード例 #10
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;
  }
コード例 #11
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;
  }
コード例 #12
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;
  }
コード例 #13
0
  /**
   * 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;
  }
コード例 #14
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);
   }
 }
コード例 #15
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);
  }
コード例 #16
0
ファイル: FSImage.java プロジェクト: niktrop/remote-access
 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);
   }
 }
コード例 #17
0
  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());
    }
  }
コード例 #18
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);
  }
コード例 #19
0
ファイル: TemplateCreator.java プロジェクト: fregaham/KiWi
  /**
   * create a template for employees.
   *
   * @return XML that represents the template content.
   */
  public static Element createOrganizationalUnitTemplate() {
    Element root = new Element("div"); // The div as a root.

    // create elements for ontology
    Element employeeName = new Element("span");
    employeeName.addAttribute(
        new Attribute(
            "property", "http://www.kiwi-project.eu/kiwi/logica/ProjectParticipant#hasFullName"));
    employeeName.appendChild("@organizationalunit.responsible_manager.name@");

    Element organizationalUnit = new Element("span");
    // organizationalUnit.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/OrganizationalUnit#hasName"));
    organizationalUnit.appendChild("@organizationalunit.name@");

    Element organizationalUnitNo = new Element("span");
    // organizationalUnit.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/OrganizationalUnit#hasNumber"));
    organizationalUnitNo.appendChild("@organizationalunit.number@");

    Element organizationalUnitSuper = new Element("span");
    // organizationalUnitSuper.addAttribute(new Attribute("property",
    // "logica:organizational.unit.super"));
    organizationalUnitSuper.appendChild("@organizationalunit.belongs_to.name@");

    // Paragraph of text
    Element p1 = new Element("p");
    p1.appendChild("The Organizational Unit ");
    p1.appendChild(organizationalUnitNo);
    p1.appendChild(" carries the name ");
    p1.appendChild(organizationalUnit);
    p1.appendChild(" and belongs to the unit [[Template: OrganizationalUnit|");
    p1.appendChild(organizationalUnitSuper);
    p1.appendChild("]]. The responsible manager is  [[Template: Employee|");
    p1.appendChild(employeeName);
    p1.appendChild("]]."); // TODO make link property driven

    root.appendChild(p1);

    return root;
  }
コード例 #20
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;
  }
コード例 #21
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());
  }
コード例 #22
0
ファイル: XMLWriter.java プロジェクト: vittau/Edools-RPS-XML
  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();
  }
コード例 #23
0
ファイル: TemplateCreator.java プロジェクト: fregaham/KiWi
  /**
   * create a template for employees.
   *
   * @return XML that represents the template content.
   */
  public static Element createEmployeeTemplate() {
    Element root = new Element("div"); // The div as a root.

    // create elements for ontology
    Element employeeName = new Element("span");
    employeeName.addAttribute(
        new Attribute(
            "property", "http://www.kiwi-project.eu/kiwi/logica/ProjectParticipant#hasFullName"));
    employeeName.appendChild("@employee.name@");

    Element employeeNo = new Element("span");
    // employeeNo.addAttribute(new Attribute("property", "logica:employee.no"));
    employeeNo.appendChild("@employee.number@");

    Element employeeInitials = new Element("span");
    employeeInitials.addAttribute(
        new Attribute(
            "property", "http://www.kiwi-project.eu/kiwi/logica/ProjectParticipant#hasInitials"));
    employeeInitials.appendChild("@employee.initials@");

    Element employeeWorkingHours = new Element("span");
    employeeWorkingHours.addAttribute(
        new Attribute(
            "property",
            "http://www.kiwi-project.eu/kiwi/logica/ProjectParticipant#workHoursPerWeek"));
    employeeWorkingHours.appendChild("@employee.work_hours_per_week@");

    Element employeeComments = new Element("span");
    // employeeComments.addAttribute(new Attribute("property", "logica:employee.comment"));
    employeeComments.appendChild("@employee.comment@");

    Element employeeSkill = new Element("span");
    employeeSkill.addAttribute(
        new Attribute(
            "property", "http://www.kiwi-project.eu/kiwi/logica/SkillPlan#hasActualLevel"));
    employeeSkill.appendChild("@employee.skill.level@");

    Element employeeSkillCategory = new Element("span");
    employeeSkillCategory.addAttribute(
        new Attribute("property", "http://www.kiwi-project.eu/kiwi/logica/SkillCatergory#hasName"));
    employeeSkillCategory.appendChild("@employee.skill.category@");

    Element employeeSkillComment = new Element("span");
    employeeSkillComment.addAttribute(
        new Attribute("property", "http://www.kiwi-project.eu/kiwi/logica/SkillPlan#hasComment"));
    employeeSkillComment.appendChild("@employee.skill.comment@");

    Element organizationalUnit = new Element("span");
    // organizationalUnit.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/OrganizationalUnit#hasName"));
    organizationalUnit.appendChild("@employee.organizationalunit.name@");

    Element organizationalUnitNo = new Element("span");
    // organizationalUnit.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/OrganizationalUnit#hasNumber"));
    organizationalUnitNo.appendChild("@employee.organizationalunit.number@");

    Element projectFrom = new Element("span");
    // projectFrom.addAttribute(new Attribute("property", "logica:project.from"));
    projectFrom.appendChild("@employee.project.start@");

    Element projectTo = new Element("span");
    // projectTo.addAttribute(new Attribute("property", "logica:project.to"));
    projectTo.appendChild("@employee.project.end@");

    Element projectName = new Element("span");
    projectName.addAttribute(
        new Attribute("property", "http://www.kiwi-project.eu/kiwi/logica/Project#hasName"));
    projectName.appendChild("@employee.project.name@");

    Element calendarFrom = new Element("span");
    // calendarFrom.addAttribute(new Attribute("property", "logica:calendar.from"));
    calendarFrom.appendChild("@employee.calendar.absent_from@");

    Element calendarTo = new Element("span");
    // calendarTo.addAttribute(new Attribute("property", "logica:calendar.to"));
    calendarTo.appendChild("@employee.calendar.absent_to@");

    Element calendarReason = new Element("span");
    // calendarReason.addAttribute(new Attribute("property", "logica:calendar.reason"));
    calendarReason.appendChild("@employee.calendar.cause@");

    // 1. paragraph: worker information
    Element p1 = new Element("p");
    p1.appendChild(employeeName);
    p1.appendChild(" (Employee No. ");
    p1.appendChild(employeeNo);
    p1.appendChild(") uses the initials ");
    p1.appendChild(employeeInitials);
    p1.appendChild(". He works ");
    p1.appendChild(employeeWorkingHours);
    p1.appendChild(" hours per week. Comments on him: ");
    p1.appendChild(employeeComments);
    p1.appendChild(new Element("br"));
    p1.appendChild("In ");
    p1.appendChild(employeeSkillCategory);
    p1.appendChild(" he is of level \"");
    p1.appendChild(employeeSkill);
    p1.appendChild("\". Comment: ");
    p1.appendChild(employeeSkillComment);

    // 2. paragraph: project information
    Element p2 = new Element("p");
    Element project = new Element("strong");
    project.appendChild("Projects:");
    p2.appendChild(project);
    p2.appendChild(new Element("br"));
    p2.appendChild(employeeName.copy());
    p2.appendChild(" is part of the organizational Unit [[Template: OrganizationalUnit|");
    p2.appendChild(organizationalUnitNo);
    p2.appendChild(": ");
    p2.appendChild(organizationalUnit);
    p2.appendChild("]]"); // TODO make link property driven
    p2.appendChild(new Element("br"));
    p2.appendChild("@(@From ");
    p2.appendChild(projectFrom);
    p2.appendChild(" to ");
    p2.appendChild(projectTo);
    p2.appendChild(" he works on the ");
    p2.appendChild(projectName);
    p2.appendChild(" project.");
    p2.appendChild(new Element("br"));
    p2.appendChild("@)@");

    // 3. paragraph: calendar
    Element p3 = new Element("p");
    Element calendar = new Element("strong");
    calendar.appendChild("Calendar:");
    p3.appendChild(calendar);
    p3.appendChild(new Element("br"));
    p3.appendChild("@(@From ");
    p3.appendChild(calendarFrom);
    p3.appendChild(" to ");
    p3.appendChild(calendarTo);
    p3.appendChild(" he is ");
    p3.appendChild(calendarReason);
    p3.appendChild(".");
    p3.appendChild(new Element("br"));
    p3.appendChild("@)@");

    root.appendChild(p1);
    root.appendChild(p2);
    root.appendChild(p3);

    return root;
  }
コード例 #24
0
ファイル: TemplateCreator.java プロジェクト: fregaham/KiWi
  /**
   * create a template for employees.
   *
   * @return XML that represents the template content.
   */
  public static Element createRiskTemplate() {
    Element root = new Element("div"); // The div as a root.

    // create elements for ontology
    Element riskName = new Element("span");
    riskName.addAttribute(
        new Attribute("property", "http://www.kiwi-project.eu/kiwi/logica/Risk#hasTitle"));
    riskName.appendChild("@risk.name@");

    Element riskPlan = new Element("span");
    riskPlan.addAttribute(
        new Attribute("property", "http://www.kiwi-project.eu/kiwi/logica/ProjectPlan#hasName"));
    riskPlan.appendChild("@risk.plan.name@");

    Element riskStatus = new Element("span");
    // riskStatus.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/Risk#hasFullName"));
    riskStatus.appendChild("@risk.status@");

    Element riskResponsibleEmployee = new Element("span");
    riskResponsibleEmployee.addAttribute(
        new Attribute(
            "property", "http://www.kiwi-project.eu/kiwi/logica/ProjectParticipant#hasFullName"));
    riskResponsibleEmployee.appendChild("@risk.responsible_employee.name@");

    Element riskCategory = new Element("span");
    // riskCategory.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/Risk#hasFullName"));
    riskCategory.appendChild("@risk.category.name@");

    Element likelihoodRating = new Element("span");
    // likelihoodRating.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/Risk#hasFullName"));
    likelihoodRating.appendChild("@risk.likelihood_rating.name@");

    Element impactRating = new Element("span");
    impactRating.addAttribute(
        new Attribute("property", "http://www.kiwi-project.eu/kiwi/logica/Risk#hasImpact"));
    impactRating.appendChild("@risk.impact_rating.name@");

    Element dateIdentified = new Element("span");
    dateIdentified.addAttribute(
        new Attribute("property", "http://www.kiwi-project.eu/kiwi/logica/Risk#wasIdentifiedAt"));
    dateIdentified.appendChild("@risk.date.identified@");

    Element dateLastReview = new Element("span");
    // dateLastReview.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/Risk#hasFullName"));
    dateLastReview.appendChild("@risk.date.last_review@");

    Element dateEarliestImpact = new Element("span");
    // dateEarliestImpact.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/Risk#hasFullName"));
    dateEarliestImpact.appendChild("@risk.date.earliest_impact@");

    Element thresoldForAction = new Element("span");
    // thresoldForAction.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/Risk#hasFullName"));
    thresoldForAction.appendChild("@risk.threshold_for_action@");

    Element riskDesc = new Element("span");
    riskDesc.addAttribute(
        new Attribute("property", "http://www.kiwi-project.eu/kiwi/logica/Risk#hasDescription"));
    riskDesc.appendChild("@risk.description@");

    Element riskImpactDesc = new Element("span");
    // riskImpactDesc.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/Risk#hasFullName"));
    riskImpactDesc.appendChild("@risk.impact_description@");

    Element riskRemarks = new Element("span");
    // riskRemarks.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/Risk#hasFullName"));
    riskRemarks.appendChild("@risk.remarks@");

    Element impactRS = new Element("span");
    // impactRS.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/Risk#hasFullName"));
    impactRS.appendChild("@risk.impact_reduction_stragegy@");

    Element likelihoodRS = new Element("span");
    // likelihoodRS.addAttribute(new Attribute("property",
    // "http://www.kiwi-project.eu/kiwi/logica/Risk#hasFullName"));
    likelihoodRS.appendChild("@risk.likelihood_reduction_strategy@");

    // Paragraph of text
    Element p1 = new Element("p");
    p1.appendChild("The Risk \"");
    p1.appendChild(riskName);
    p1.appendChild("\" is from the Project Plan \"[[ Template: ProjectPlan |");
    p1.appendChild(riskPlan);
    p1.appendChild(" ]]\" and has the Status ");
    p1.appendChild(riskStatus);
    p1.appendChild(". The responsible Project Participant is [[ Template: Employee |");
    p1.appendChild(riskResponsibleEmployee);
    p1.appendChild(" ]]. The Risk is of Category ");
    p1.appendChild(riskCategory);
    p1.appendChild(", the likelihood is ");
    p1.appendChild(likelihoodRating);
    p1.appendChild(" and the impact is ");
    p1.appendChild(impactRating);
    p1.appendChild(".");
    p1.appendChild(new Element("br"));
    p1.appendChild("This Risk was identified at ");
    p1.appendChild(dateIdentified);
    p1.appendChild(", the date for the last review is ");
    p1.appendChild(dateLastReview);
    p1.appendChild(" and the earliest impact might be at ");
    p1.appendChild(dateEarliestImpact);
    p1.appendChild(". The Threshold for action is ");
    p1.appendChild(thresoldForAction);
    p1.appendChild(".");

    // Paragraph of text
    Element p2 = new Element("p");
    p2.appendChild("Following brief descriptions...");
    p2.appendChild(new Element("br"));
    p2.appendChild("The Risk itself: ");
    p2.appendChild(riskDesc);
    p2.appendChild(new Element("br"));
    p2.appendChild("The Impact of the Risk: ");
    p2.appendChild(riskImpactDesc);
    p2.appendChild(new Element("br"));
    p2.appendChild("Remarks: ");
    p2.appendChild(riskRemarks);

    // Paragraph of text
    Element p3 = new Element("p");
    p3.appendChild("Strategy for reducing the Impact: ");
    p3.appendChild(impactRS);
    p3.appendChild(new Element("br"));
    p3.appendChild("Strategy for reducing the Likelihood: ");
    p3.appendChild(likelihoodRS);

    root.appendChild(p1);
    root.appendChild(p2);
    root.appendChild(p3);

    return root;
  }
コード例 #25
0
ファイル: FSImage.java プロジェクト: niktrop/remote-access
 public void setRootAlias(String rootAlias) {
   fileTree.addAttribute(new Attribute("alias", rootAlias));
 }
コード例 #26
0
ファイル: PageCoPreparer.java プロジェクト: tolweb/tolweb-app
  @SuppressWarnings("unchecked")
  public void processContent() {

    Element page = new Element(PageContentElements.PAGE, ContentPreparer.NS);
    page.addAttribute(new Attribute(PageContentAttributes.ID, "" + getMappedPage().getPageId()));

    String pageNodeNameUrl = getMappedPage().getMappedNode().getName();
    try {
      pageNodeNameUrl = URLEncoder.encode(pageNodeNameUrl, "UTF-8");
    } catch (Exception e) {
      e.printStackTrace();
    }
    String nodeIdString = "" + getMappedPage().getMappedNode().getId();
    pageNodeNameUrl =
        StringUtils.notEmpty(pageNodeNameUrl) ? pageNodeNameUrl + "/" + nodeIdString : nodeIdString;
    String pageUrl = "http://tolweb.org/" + pageNodeNameUrl;
    page.addAttribute(new Attribute(PageContentAttributes.PAGE_URL, pageUrl));
    page.addAttribute(
        new Attribute(PageContentAttributes.PAGE_STATUS, getMappedPage().getStatus()));
    page.addAttribute(
        new Attribute(
            PageContentAttributes.DATE_CREATED,
            getSafeString(getMappedPage().getFirstOnlineString())));
    page.addAttribute(
        new Attribute(
            PageContentAttributes.DATE_CHANGED,
            safeToString(getMappedPage().getContentChangedDate())));

    Element group = new Element(PageContentElements.GROUP, ContentPreparer.NS);
    page.appendChild(group);

    group.addAttribute(
        new Attribute(PageContentAttributes.NODE, "" + getMappedPage().getMappedNode().getId()));
    group.addAttribute(
        new Attribute(
            PageContentAttributes.EXTINCT,
            (getMappedPage().getMappedNode().getExtinct() == 2) ? "true" : "false"));
    group.addAttribute(
        new Attribute(
            PageContentAttributes.PHYLESIS,
            getPhylesisString(getMappedPage().getMappedNode().getPhylesis())));
    group.addAttribute(
        new Attribute(
            PageContentAttributes.LEAF,
            getMappedPage().getMappedNode().getIsLeaf() ? "true" : "false"));

    Element groupDesc = new Element(PageContentElements.GROUP_DESCRIPTION, ContentPreparer.NS);
    String groupDescText = getMappedPage().getMappedNode().getDescription();
    groupDesc.appendChild(new Text(groupDescText));

    if (StringUtils.notEmpty(groupDescText)) {
      group.appendChild(groupDesc);
    }

    Element groupCmt = new Element(PageContentElements.GROUP_COMMENT, ContentPreparer.NS);
    String groupCmtText = getMappedPage().getLeadText();
    groupCmt.appendChild(new Text(groupCmtText));

    if (StringUtils.notEmpty(groupCmtText)) {
      group.appendChild(groupCmt);
    }

    Element names = new Element(PageContentElements.NAMES, ContentPreparer.NS);
    page.appendChild(names);

    Element name = new Element(PageContentElements.NAME, ContentPreparer.NS);
    names.appendChild(name);

    name.appendChild(new Text(getMappedPage().getMappedNode().getName()));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.ITALICIZE_NAME,
            Boolean.valueOf(getMappedPage().getMappedNode().getItalicizeName()).toString()));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.AUTHORITY,
            getSafeString(getMappedPage().getMappedNode().getNameAuthority())));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.AUTH_DATE,
            safeToString(getMappedPage().getMappedNode().getAuthorityDate())));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.NAME_COMMENT,
            getSafeString(getMappedPage().getMappedNode().getNameComment())));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.NEW_COMBINATION,
            Boolean.valueOf(getMappedPage().getMappedNode().getIsNewCombination()).toString()));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.COMBINATION_AUTHOR,
            getSafeString(getMappedPage().getMappedNode().getCombinationAuthor())));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.COMBINATION_DATE,
            safeToString(getMappedPage().getMappedNode().getCombinationDate())));

    Element othernames = new Element(PageContentElements.OTHERNAMES, ContentPreparer.NS);

    SortedSet otherNamesSet = getMappedPage().getMappedNode().getSynonyms();

    for (Iterator itr = otherNamesSet.iterator(); itr.hasNext(); ) {
      MappedOtherName moname = (MappedOtherName) itr.next();
      Element othername = new Element(PageContentElements.OTHERNAME, ContentPreparer.NS);
      othername.addAttribute(new Attribute(PageContentAttributes.ID, "" + moname.getId()));
      othername.addAttribute(
          new Attribute(
              PageContentAttributes.ITALICIZE_NAME,
              Boolean.valueOf(moname.getItalicize()).toString()));
      othername.addAttribute(
          new Attribute(PageContentAttributes.AUTHORITY, getSafeString(moname.getAuthority())));
      othername.addAttribute(
          new Attribute(PageContentAttributes.AUTH_DATE, safeToString(moname.getAuthorityYear())));
      othername.addAttribute(
          new Attribute(PageContentAttributes.NAME_COMMENT, getSafeString(moname.getComment())));
      othername.addAttribute(
          new Attribute(
              PageContentAttributes.IS_IMPORTANT,
              Boolean.valueOf(moname.getIsImportant()).toString()));
      othername.addAttribute(
          new Attribute(
              PageContentAttributes.IS_PREFERRED,
              Boolean.valueOf(moname.getIsPreferred()).toString()));
      othername.addAttribute(
          new Attribute(PageContentAttributes.SEQUENCE, safeToString(moname.getOrder())));
    }

    if (!otherNamesSet.isEmpty()) {
      names.appendChild(othernames);
    }

    List children = getMappedPage().getMappedNode().getChildren();
    boolean isTerminal = children != null && children.isEmpty();

    // add this if not a leaf or writeaslist is false... or is terminal (e.g. no children)
    if (getMappedPage().getMappedNode().getIsLeaf() && !isTerminal) {
      Element subgroups = new Element(PageContentElements.SUBGROUPS, ContentPreparer.NS);
      page.appendChild(subgroups);

      if (!getMappedPage().getWriteAsList()) {
        Element treeimage = new Element(PageContentElements.TREEIMAGE, ContentPreparer.NS);
        ContributorLicenseInfo currDefault =
            new ContributorLicenseInfo(ContributorLicenseInfo.TREE_IMAGE_LICENSE);
        treeimage.addAttribute(
            new Attribute(PageContentAttributes.LICENSE, currDefault.toShortString()));
        String treeImageName = getMappedPage().getGroupName().replaceAll("\\s", "_");
        treeimage.appendChild(
            new Text("http://www.tolweb.org/Public/treeImages/" + treeImageName + ".png"));
        subgroups.appendChild(treeimage);
      }

      Element newicktree = new Element(PageContentElements.NEWICKTREE, ContentPreparer.NS);
      subgroups.appendChild(newicktree);

      Element taxonlist = new Element(PageContentElements.TAXON_LIST, ContentPreparer.NS);
      taxonlist.appendChild(new Text(StringEscapeUtils.escapeXml(getTaxonListAsHTML())));
      subgroups.appendChild(taxonlist);

      Element treecomment = new Element(PageContentElements.TREE_COMMENT, ContentPreparer.NS);
      subgroups.appendChild(treecomment);
      treecomment.appendChild(
          new Text(StringEscapeUtils.escapeXml(getMappedPage().getPostTreeText())));
    }

    Element sections = new Element(PageContentElements.SECTIONS, ContentPreparer.NS);
    page.appendChild(sections);

    SortedSet textSections = getMappedPage().getTextSections();
    for (Iterator itr = textSections.iterator(); itr.hasNext(); ) {
      MappedTextSection mtxt = (MappedTextSection) itr.next();
      Element section = new Element(PageContentElements.SECTION, ContentPreparer.NS);
      section.addAttribute(new Attribute(PageContentAttributes.ID, "" + mtxt.getTextSectionId()));
      section.addAttribute(new Attribute(PageContentAttributes.SECTION_TITLE, mtxt.getHeading()));
      section.addAttribute(
          new Attribute(PageContentAttributes.PAGE_ORDER, safeToString(mtxt.getOrder())));
      section.addAttribute(
          new Attribute(PageContentAttributes.COPYRIGHT_DATE, getMappedPage().getCopyrightDate()));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.LICENSE,
              getLicenseShortName(getMappedPage().getUsePermission())));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.AUTHORS,
              getAuthorsIdString(getMappedPage().getContributors())));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.CORRESPONDENTS,
              getCorrespondentsIdString(getMappedPage().getContributors())));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.COPYRIGHT_OWNERS,
              getCopyrightOwnersIdString(getMappedPage().getContributors())));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.OTHER_COPYRIGHT,
              getSafeString(getMappedPage().getCopyrightHolder())));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.CONTENT_CHANGED,
              safeToString(getMappedPage().getContentChangedDate())));

      // add the section-text text element
      Element sectionText = new Element(PageContentElements.SECTION_TEXT, ContentPreparer.NS);
      sectionText.appendChild(new Text(processSectionText(mtxt.getText(), pageUrl)));
      section.appendChild(sectionText);

      Element sectionMedia = new Element(PageContentElements.SECTION_MEDIA, ContentPreparer.NS);
      processSectionMedia(sectionMedia);
      section.appendChild(sectionMedia);

      // add the section-source element
      Element sectionSource = new Element(PageContentElements.SECTION_SOURCE, ContentPreparer.NS);
      // TODO add attribute data to section-source
      section.appendChild(sectionSource);

      String sectionAnchor = mtxt.getHeadingNoSpaces();
      sectionSource.addAttribute(new Attribute(PageContentAttributes.SOURCE_COLLECTION, "0"));
      sectionSource.addAttribute(
          new Attribute(PageContentAttributes.SOURCE_TITLE, mtxt.getHeading()));
      sectionSource.addAttribute(
          new Attribute(
              PageContentAttributes.SOURCE_URL,
              "http://tolweb.org/" + pageNodeNameUrl + "#" + sectionAnchor));
      sectionSource.addAttribute(new Attribute(PageContentAttributes.MORE_SOURCE, "[future-use]"));

      sections.appendChild(section);
    }

    Element refs = new Element(PageContentElements.REFERENCES, ContentPreparer.NS);
    page.appendChild(refs);
    TextPreparer txtPrep = new TextPreparer();
    List refsList = txtPrep.getNewlineSeparatedList(getMappedPage().getReferences());
    for (Iterator itr = refsList.iterator(); itr.hasNext(); ) {
      String ref = (String) itr.next();
      // only add the reference element if it's not empty
      if (StringUtils.notEmpty(ref)) {
        Element refEl = new Element(PageContentElements.REFERENCE, ContentPreparer.NS);
        refEl.appendChild(new Text(StringEscapeUtils.escapeXml(ref)));
        refs.appendChild(refEl);
      }
    }

    Element internetInfo = new Element(PageContentElements.INTERNET_INFO, ContentPreparer.NS);
    page.appendChild(internetInfo);
    internetInfo.appendChild(
        new Text(StringEscapeUtils.escapeXml(getMappedPage().getInternetInfo())));

    getElement().appendChild(page);
  }
コード例 #27
0
 public static MimeType addMimeType(String mimeId) {
   Element el = new Element("mime-type");
   el.addAttribute(new Attribute("id", mimeId));
   _root.appendChild(el);
   return new MimeType(el);
 }
コード例 #28
0
  private static Element toInputXML(CoreMap document) {
    // construct GUTime format XML
    Element doc = new Element("DOC");
    doc.appendChild("\n");
    // populate the date element
    Calendar dateCalendar = document.get(CoreAnnotations.CalendarAnnotation.class);
    if (dateCalendar != null) {
      Element date = new Element("date");
      date.appendChild(String.format("%TF", dateCalendar));
      doc.appendChild(date);
      doc.appendChild("\n");
    } else {
      String s = document.get(CoreAnnotations.DocDateAnnotation.class);
      if (s != null) {
        Element date = new Element("date");
        date.appendChild(s);
        doc.appendChild(date);
        doc.appendChild("\n");
      }
    }
    Element textElem = new Element("text");
    doc.appendChild(textElem);
    doc.appendChild("\n");

    // populate the text element
    String text = document.get(CoreAnnotations.TextAnnotation.class);
    int offset = 0;
    for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
      int sentBegin = sentence.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class);
      int sentEnd = sentence.get(CoreAnnotations.CharacterOffsetEndAnnotation.class);

      // add text before the first token
      textElem.appendChild(text.substring(offset, sentBegin));
      offset = sentBegin;

      // add one "s" element per sentence
      Element s = new Element("s");
      textElem.appendChild(s);
      for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
        int tokenBegin = token.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class);
        int tokenEnd = token.get(CoreAnnotations.CharacterOffsetEndAnnotation.class);
        s.appendChild(text.substring(offset, tokenBegin));
        offset = tokenBegin;

        // add one "lex" element per token
        Element lex = new Element("lex");
        s.appendChild(lex);
        String posTag = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
        if (posTag != null) {
          lex.addAttribute(new Attribute("pos", posTag));
        }
        assert token.word().equals(text.substring(offset, tokenEnd));
        lex.appendChild(text.substring(offset, tokenEnd));
        offset = tokenEnd;
      }

      // add text after the last token
      textElem.appendChild(text.substring(offset, sentEnd));
      offset = sentEnd;
    }

    // add text after the last sentence
    textElem.appendChild(text.substring(offset, text.length()));

    // return the document
    return doc;
  }
コード例 #29
0
  public void handleHTTPRequest(HTTPRequest request, boolean isPost) {

    clear();

    boolean rename = request.isParameterSet("rename");

    if (request.isPartSet("submit")) {
      String name = request.getPartAsString("category-name", MAX_CATEGORY_NAME_LENGTH).trim();
      String catId = request.getParam("rename");

      if (!"".equals(name)) {
        if (!nodesManager.renameCategory(catId, name)) nodesManager.newCategory(name);
        try {
          nodesManager.writeCategories();
        } catch (IOException ioe) {
          appendError(ioe);
        }

        rename = false;

      } else {
        appendError("Fied \"name\" is empty");
      }
    }

    if (request.isParameterSet("delete")) {
      try {
        String cat = request.getParam("delete");
        if (!nodesManager.deleteCategory(cat))
          appendError("The category \"" + cat + "\" does not exist.");

        nodesManager.writeCategories();
      } catch (ParsingException pe) {
        appendError(pe);
      } catch (IOException ioe) {
        appendError(ioe);
      }
    }

    if (nodesManager.countCategories() > 0 && !rename) {

      Element table = new Element("table");
      Element tHeader = new Element("tr");
      table.appendChild(tHeader);
      HTMLHelper.i18nElement(tHeader, "th", "echo.common.name");
      Element actionCell = HTMLHelper.i18nElement(tHeader, "th", "echo.common.action");
      actionCell.addAttribute(new Attribute("colspan", "2"));

      String[] ids = nodesManager.getCategoriesIds();
      boolean alternate = false;
      for (String id : ids) {
        Element row = new Element("tr");
        if (alternate) row.addAttribute(new Attribute("class", "alternate"));

        HTMLHelper.element(row, "td", nodesManager.getCategoryNameById(id));
        HTMLHelper.element(row, "td", HTMLHelper.i18nLink("?rename=" + id, "echo.common.rename"));
        HTMLHelper.element(row, "td", HTMLHelper.i18nLink("?delete=" + id, "echo.common.delete"));

        table.appendChild(row);
        alternate = !alternate;
      }

      appendContent(table);
    }

    String action = "categories";
    if (request.isParameterSet("rename")) action += "?rename=" + request.getParam("rename");

    Element form = HTMLHelper.form(action, formPsw);
    form.addAttribute(new Attribute("class", "inline"));
    HTMLHelper.i18nLabel(
        form, "category-name", (rename) ? "echo.common.rename" : "echo.manage.newCategory");
    Element nameInput = HTMLHelper.input(form, "text", "category-name");
    if (rename)
      nameInput.addAttribute(
          new Attribute("value", nodesManager.getCategoryNameById(request.getParam("rename"))));

    HTMLHelper.input(form, "submit", "submit");

    appendContent(form);
  }
コード例 #30
0
 public void beforeProcessingSpecification(SpecificationProcessingEvent event) {
   Resource resource = event.getResource();
   script.addAttribute(new Attribute("src", resource.getRelativePath(javaScriptResource)));
 }