Exemplo n.º 1
0
  protected final void command_set_textmode(String rest) {
    if (rest.equals("normalize")) {
      format.setTextMode(Format.TextMode.NORMALIZE);
    } else if (rest.equals("preserve")) {
      format.setTextMode(Format.TextMode.PRESERVE);
    } else if (rest.equals("trim")) {
      format.setTextMode(Format.TextMode.TRIM);
    } else if (rest.equals("trim_full_white")) {
      format.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
    } else {
      System.out.printf("Error: unknown text mode \"%s\"", rest);
      return;
    }

    // update outputter
    xmloutputter.setFormat(format);

    System.out.printf("Text mode set: %s\n", rest);
  } // command_set_textmode()
  @Override
  public void generate(final File reportsDir, final VersionManagerSession session)
      throws VManException {
    Map<VersionlessProjectKey, Set<Plugin>> missingPlugins = session.getUnmanagedPluginRefs();
    if (missingPlugins.isEmpty()) {
      return;
    }
    Element plugins = new Element("plugins");

    for (Map.Entry<VersionlessProjectKey, Set<Plugin>> pluginsEntry : missingPlugins.entrySet()) {
      if (plugins.getContentSize() > 0) {
        plugins.addContent("\n\n");
      }

      plugins.addContent(new Comment("START: " + pluginsEntry.getKey()));

      for (Plugin dep : pluginsEntry.getValue()) {
        Element d = new Element("plugin");
        plugins.addContent(d);

        d.addContent(new Element("groupId").setText(dep.getGroupId()));
        d.addContent(new Element("artifactId").setText(dep.getArtifactId()));
        d.addContent(new Element("version").setText(dep.getVersion()));
      }

      plugins.addContent(new Comment("END: " + pluginsEntry.getKey()));
    }

    Element build = new Element("build");
    build.addContent(new Element("pluginManagement").setContent(plugins));

    Document doc = new Document(build);

    Format fmt = Format.getPrettyFormat();
    fmt.setIndent("  ");
    fmt.setTextMode(TextMode.PRESERVE);

    XMLOutputter output = new XMLOutputter(fmt);

    File report = new File(reportsDir, ID + ".xml");
    FileWriter writer = null;
    try {
      reportsDir.mkdirs();

      writer = new FileWriter(report);
      output.output(doc, writer);
    } catch (IOException e) {
      throw new VManException("Failed to generate %s report! Error: %s", e, ID, e.getMessage());
    } finally {
      closeQuietly(writer);
    }
  }
Exemplo n.º 3
0
 public String getAsXML() {
   // following lines uses the old JDOM jar
   //        xmlOutputter.setIndent(true);
   //        xmlOutputter.setIndent("  ");
   //        xmlOutputter.setNewlines(true);
   //        xmlOutputter.setExpandEmptyElements(false);
   //        xmlOutputter.setOmitEncoding(true);
   //        xmlOutputter.setOmitDeclaration(true);
   //        xmlOutputter.setTextNormalize(true);
   final Format prettyFormat = Format.getPrettyFormat();
   prettyFormat.setExpandEmptyElements(false);
   prettyFormat.setOmitEncoding(true);
   prettyFormat.setOmitDeclaration(true);
   prettyFormat.setTextMode(Format.TextMode.NORMALIZE);
   final XMLOutputter xmlOutputter = new XMLOutputter(prettyFormat);
   return xmlOutputter.outputString(createRootTree("class name list template"));
 }
Exemplo n.º 4
0
  @SuppressWarnings("rawtypes")
  public void InstalarCerAF(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    System.out.println("Inicio de instalacion");
    short idmensaje = -1;
    String mensaje = "";

    idmensaje = 0;
    mensaje =
        JUtil.Msj(
            "SAF", "ADMIN_SSL", "DLG", "MSJ-PROCOK", 1); // "El certificado se instaló con exito";

    try {
      JAdmVariablesSet var = new JAdmVariablesSet(null);
      var.ConCat(true);
      var.m_Where = "ID_Variable = 'TOMCAT'";
      var.Open();

      if (var.getAbsRow(0).getVAlfanumerico().equals("NC")) {
        idmensaje = 1;
        mensaje =
            JUtil.Msj(
                "SAF",
                "ADMIN_SSL",
                "DLG",
                "MSJ-PROCERR",
                4); // "PRECAUCION: La variable TOMCAT (ruta de instalacion de tomcat) no está
                    // definida... No se puede instalar el certificado";
        getSesion(request).setID_Mensaje(idmensaje, mensaje);
        irApag("/forsetiadmin/administracion/adm_ssl_dlg_passport.jsp", request, response);
        return;
      }

      boolean cs = false;
      SAXBuilder builder = new SAXBuilder();
      String xml_path = var.getAbsRow(0).getVAlfanumerico() + "/conf/server.xml";
      Document XMLServer = builder.build(xml_path);
      // System.out.println(xml_path + "\narchivo: " + request.getParameter("id") + "\npassword: "******"password"));
      Element Server = XMLServer.getRootElement();
      Element Service = Server.getChild("Service");
      List lConnectors = Service.getChildren("Connector");
      Iterator iter = lConnectors.iterator();
      while (iter.hasNext()) {
        Element Connector = (Element) iter.next();
        String port = Connector.getAttributeValue("port");
        if (port != null && (port.equals("8443") || port.equals("443"))) {
          Connector.setAttribute(
              "keystoreFile", "/usr/local/forseti/bin/" + request.getParameter("id"));
          Connector.setAttribute("keystorePass", request.getParameter("password"));
          Connector.setAttribute("port", request.getParameter("puerto"));
          cs = true;
        }

        if (port != null && (port.equals("8080") || port.equals("80"))) {
          if (request.getParameter("puerto").equals("8443")) Connector.setAttribute("port", "8080");
          if (request.getParameter("puerto").equals("443")) Connector.setAttribute("port", "80");

          Connector.setAttribute("redirectPort", request.getParameter("puerto"));
        }
      }

      if (!cs) {
        Element Connector = new Element("Connector");
        Connector.setAttribute("protocol", "HTTP/1.1");
        Connector.setAttribute("port", request.getParameter("puerto"));
        Connector.setAttribute("maxThreads", "200");
        Connector.setAttribute("scheme", "https");
        Connector.setAttribute("secure", "true");
        Connector.setAttribute("SSLEnabled", "true");
        Connector.setAttribute(
            "keystoreFile", "/usr/local/forseti/bin/" + request.getParameter("id"));
        Connector.setAttribute("keystorePass", request.getParameter("password"));
        Connector.setAttribute("clientAuth", "false");
        Connector.setAttribute("sslProtocol", "TLS");
        Service.addContent(Connector);
        cs = true;
      }

      if (cs) {
        System.out.println("Prettyformat");

        Format format = Format.getPrettyFormat();
        format.setEncoding("utf-8");
        format.setTextMode(TextMode.NORMALIZE);
        XMLOutputter xmlOutputter = new XMLOutputter(format);
        FileWriter writer = new FileWriter(xml_path);
        xmlOutputter.output(XMLServer, writer);
        writer.close();
        // System.out.println("PrettyformatWrite");

        mensaje +=
            "<br>"
                + JUtil.Msj("SAF", "ADMIN_SSL", "DLG", "MSJ-PROCOK", 2)
                + " "
                + JUtil.Msj("SAF", "ADMIN_SSL", "DLG", "MSJ-PROCOK", 3)
                + " "
                + JUtil.Msj(
                    "SAF",
                    "ADMIN_SSL",
                    "DLG",
                    "MSJ-PROCOK",
                    4); // "<br>El archivo server.xml ha quedado modificado con los datos de este
                        // certificado. Nota: Si la contraseña esta mal, ya no se podra reiniciar el
                        // servidor de una manera segura, por lo tanto, deberas cambiar el archivo
                        // server.xml de manera manual para corregir la contraseña. Si no estas
                        // seguro que esta bien la contraseña, consulta este mismo certificado para
                        // ver si es correcta, de lo contrario vuelve a instalar inmediatamente este
                        // certificado con la contraseña correcta antes de reiniciar el servidor";

      } else {
        idmensaje = 3;
        mensaje =
            JUtil.Msj(
                "SAF",
                "ADMIN_SSL",
                "DLG",
                "MSJ-PROCERR2",
                2); // "ERROR: No se modifico el archivo server.xml debido a errores desconocidos";
      }
    } catch (JDOMException e) {
      idmensaje = 3;
      mensaje = "ERROR de JDOMException en archivo XML: " + e.getMessage();
    } catch (IOException e) {
      idmensaje = 3;
      mensaje = "ERROR de IOException en archivo XML: " + e.getMessage();
    } catch (Exception e) {
      idmensaje = 3;
      mensaje = "ERROR de Exception en archivo XML: " + e.getMessage();
    }

    RDP(
        "SAF",
        getSesion(request).getConBD(),
        (idmensaje == 1 ? "OK" : "ER"),
        getSesion(request).getID_Usuario(),
        "ADMIN_SSL_MANEJO",
        "ASSL|" + p(request.getParameter("id")) + "|||",
        p(mensaje));
    getSesion(request).setID_Mensaje(idmensaje, mensaje);
    irApag("/forsetiadmin/administracion/adm_ssl_dlg_passport.jsp", request, response);
    return;
  }
  @Override
  public void generate(final File reportsDir, final VersionManagerSession session)
      throws VManException {
    final Map<VersionlessProjectKey, Set<Dependency>> missingDependencies =
        session.getMissingDependencies();
    if (missingDependencies.isEmpty()) {
      return;
    }

    final Element deps = new Element("dependencies");

    for (final Map.Entry<VersionlessProjectKey, Set<Dependency>> depsEntry :
        missingDependencies.entrySet()) {
      if (deps.getContentSize() > 0) {
        deps.addContent("\n\n");
      }

      deps.addContent(new Comment("START: " + depsEntry.getKey()));

      for (final Dependency dep : depsEntry.getValue()) {
        final Element d = new Element("dependency");
        deps.addContent(d);

        d.addContent(new Element("groupId").setText(dep.getGroupId()));
        d.addContent(new Element("artifactId").setText(dep.getArtifactId()));
        d.addContent(new Element("version").setText(dep.getVersion()));

        if (isNotEmpty(dep.getType()) && !"jar".equals(dep.getType())) {
          d.addContent(new Element("type").setText(dep.getType()));
        }

        if (isNotEmpty(dep.getClassifier())) {
          d.addContent(new Element("classifier").setText(dep.getClassifier()));
        }

        // if ( dep.isOptional() )
        // {
        // d.addContent( new Element( "optional" ).setText( Boolean.toString( true ) ) );
        // }
        //
        // if ( dep.getExclusions() != null && !dep.getExclusions().isEmpty() )
        // {
        // Element ex = new Element( "exclusions" );
        // d.addContent( ex );
        //
        // for ( Exclusion exclusion : dep.getExclusions() )
        // {
        // ex.addContent( new Element( "groupId" ).setText( exclusion.getGroupId() ) );
        // ex.addContent( new Element( "artifactId" ).setText( exclusion.getArtifactId() ) );
        // }
        // }
      }

      deps.addContent(new Comment("END: " + depsEntry.getKey()));
    }

    final Element dm = new Element("dependencyManagement");
    dm.setContent(deps);

    final Document doc = new Document(dm);

    final Format fmt = Format.getPrettyFormat();
    fmt.setIndent("  ");
    fmt.setTextMode(TextMode.PRESERVE);

    final XMLOutputter output = new XMLOutputter(fmt);

    final File report = new File(reportsDir, ID);
    FileWriter writer = null;
    try {
      reportsDir.mkdirs();

      writer = new FileWriter(report);
      output.output(doc, writer);
    } catch (final IOException e) {
      throw new VManException("Failed to generate %s report! Error: %s", e, ID, e.getMessage());
    } finally {
      closeQuietly(writer);
    }
  }
  public void saveToFile(File dest) throws IOException {
    File temp = File.createTempFile(dest.getName(), ".tmp", dest.getParentFile());

    try {
      Element root = new Element("MarrsProject");
      root.setAttribute("title", title);
      root.setAttribute("schemaversion", "" + CURRENT_SCHEMAVERSION);

      for (MarrsQuery q : rows) {
        Element queryElt = new Element("Query");
        CDATA data = new CDATA(q.getQueryText());
        queryElt.addContent(data);

        queryElt.setAttribute("title", q.getTitle());
        queryElt.setAttribute("type", "" + q.getQueryType());

        if (q.getAskBefore() != null) {
          Element askElt = new Element("AskBefore");
          askElt.setAttribute("key", q.getAskBefore());
          queryElt.addContent(askElt);
        }

        for (Map.Entry<String, String> context : q.getContext().entrySet()) {
          Element contextElt = new Element("Context");
          contextElt.setAttribute(
              "key", context.getKey()); // for now, we only use "type" to filter context, so this is
          // hardcoded.
          contextElt.setAttribute("value", context.getValue());
          queryElt.addContent(contextElt);
        }

        for (String var : q.getPostProcessingVars()) {
          Element processElt = new Element("PostProcessing");
          processElt.setAttribute(
              "var", var); // for now, we only use "type" to filter context, so this is hardcoded.
          processElt.setAttribute("operation", q.getPostProcessingOperation(var));
          queryElt.addContent(processElt);
        }

        root.addContent(queryElt);
      }

      for (Map.Entry<String, String> param : parameters.entrySet()) {
        Element paramElt = new Element("Param");
        paramElt.setAttribute("key", param.getKey());
        paramElt.setAttribute("val", param.getValue());
        root.addContent(paramElt);
      }

      for (NodeAttribute attr : nodeAttributes) {
        Element nodeAttr = new Element("NodeAttribute");
        nodeAttr.setAttribute("key", attr.key);
        nodeAttr.setAttribute("value", attr.value);

        for (Map.Entry<String, String> e : attr.vizprops.entrySet()) {
          Element vizprop = new Element("Vizmap");
          vizprop.setAttribute("prop", e.getKey());
          vizprop.setAttribute("value", e.getValue());
          nodeAttr.addContent(vizprop);
        }
        root.addContent(nodeAttr);
      }

      Document doc = new Document(root);
      XMLOutputter xout = new XMLOutputter();
      Format format = Format.getPrettyFormat();
      format.setIndent("\t");
      format.setLineSeparator("\n");
      format.setTextMode(TextMode.PRESERVE);
      xout.setFormat(format);
      xout.output(doc, new FileOutputStream(temp));

      temp.renameTo(dest);
      dirty = false;
    } finally {
      temp.delete();
    }
  }