예제 #1
0
  public static void save(final ArrayList elements, final String sFilename) {

    try {
      final File file = new File(sFilename);
      if (!file.exists()) {
        final String dir = file.getParent();
        new File(dir).mkdir();
        file.createNewFile();
      }
      final Writer writer = new FileWriter(file);
      final KXmlSerializer serializer = new KXmlSerializer();
      serializer.setOutput(writer);
      serializer.startDocument(encoding, new Boolean(true));
      serializer.text("\n\t");
      serializer.startTag(null, HELP);
      for (int i = 0; i < elements.size(); i++) {
        final HelpElement element = (HelpElement) elements.get(i);
        element.serialize(serializer);
      }
      serializer.text("\n\t");
      serializer.endTag(null, HELP);
      serializer.text("\n");
      serializer.startDocument(encoding, new Boolean(true));
      writer.close();
    } catch (final IOException e) {
      e.printStackTrace();
    }
  }
  /**
   * Si existe la version de paleta 1.0, la actualizara a la 1.1 y renombrará la antigua version.
   *
   * @param palettesBasePath
   * @param colorTable
   */
  public static void save_to_1_1(String palettesBasePath, ColorTable colorTable) {
    try {
      // Generar nuevo fichero
      KXmlSerializer parserOutput = new KXmlSerializer();
      FileOutputStream out =
          new FileOutputStream(palettesBasePath + File.separator + colorTable.getName() + ".xml");
      OutputStreamWriter writer = new OutputStreamWriter(out, "UTF8");
      parserOutput.setOutput(writer);
      parserOutput.startDocument("UTF-8", null);
      parserOutput.startTag(null, "ColorTable");
      parserOutput.attribute(null, "name", colorTable.getName());
      parserOutput.attribute(null, "version", "1.1");
      parserOutput.text("\n");

      ArrayList items = colorTable.getColorItems();
      for (int i = 0; i < items.size(); i++) {
        ColorItem colorItem = (ColorItem) items.get(i);
        parserOutput.startTag(null, "Color");
        parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue()));
        if (colorItem.getNameClass() != null)
          parserOutput.attribute(null, "name", String.valueOf(colorItem.getNameClass()));
        else parserOutput.attribute(null, "name", "");
        Color color = colorItem.getColor();
        parserOutput.attribute(
            null,
            "rgb",
            String.valueOf(color.getRed() + "," + color.getGreen() + "," + color.getBlue()));
        parserOutput.attribute(null, "interpolated", String.valueOf(colorItem.getInterpolated()));
        parserOutput.endTag(null, "Color");
        parserOutput.text("\n");
      }

      for (int i = 0; i < items.size(); i++) {
        ColorItem colorItem = (ColorItem) items.get(i);
        parserOutput.startTag(null, "Alpha");
        parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue()));
        parserOutput.attribute(null, "alpha", String.valueOf(colorItem.getColor().getAlpha()));
        parserOutput.attribute(null, "interpolated", String.valueOf(colorItem.getInterpolated()));
        parserOutput.endTag(null, "Alpha");
        parserOutput.text("\n");
      }

      parserOutput.endTag(null, "ColorTable");
      parserOutput.text("\n");
      parserOutput.endDocument();
      // Cerrar nuevo fichero
      writer.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #3
0
  @Override
  protected void serializeAttributes(final KXmlSerializer serializer)
      throws NullParameterAdditionalInfoException, IOException {

    final AdditionalInfoTableField aitf = (AdditionalInfoTableField) m_ParameterAdditionalInfo;
    if (aitf != null) {
      serializer.text("\n");
      serializer.text("\t\t\t");
      serializer.startTag(null, ATTRIBUTE);
      serializer.attribute(null, NAME, PARENT);
      serializer.attribute(null, VALUE, aitf.getParentParameterName());
      serializer.endTag(null, ATTRIBUTE);
      serializer.text("\n");
      serializer.text("\t\t\t");
      serializer.startTag(null, ATTRIBUTE);
      serializer.attribute(null, NAME, MANDATORY);
      serializer.attribute(null, VALUE, Boolean.valueOf(aitf.getIsMandatory()).toString());
      serializer.endTag(null, ATTRIBUTE);
    } else {
      throw new NullParameterAdditionalInfoException();
    }
  }
예제 #4
0
  private void writeTally() throws IllegalArgumentException, IllegalStateException, IOException {
    main_serial.startTag("pftt", "tally");

    main_serial.attribute(null, "test_pack_name_and_version", test_pack_name_and_version);
    main_serial.attribute(null, "os_name", host.getOSNameLong());
    main_serial.attribute(null, "test_count", Integer.toString(test_count));
    main_serial.attribute(null, "percent_total", Integer.toString(getTestCount()));
    main_serial.attribute(null, "pass", Integer.toString(count(EPhpUnitTestStatus.PASS)));
    main_serial.attribute(null, "pass_percent", Float.toString(passRate()));
    main_serial.attribute(null, "timeout", Integer.toString(count(EPhpUnitTestStatus.TIMEOUT)));
    main_serial.attribute(null, "failure", Integer.toString(count(EPhpUnitTestStatus.FAILURE)));
    main_serial.attribute(
        null,
        "failure_percent",
        Float.toString(
            100.0f * (((float) count(EPhpUnitTestStatus.FAILURE)) / ((float) getTestCount()))));
    main_serial.attribute(null, "error", Integer.toString(count(EPhpUnitTestStatus.ERROR)));
    main_serial.attribute(
        null,
        "error_percent",
        Float.toString(
            100.0f * (((float) count(EPhpUnitTestStatus.ERROR)) / ((float) getTestCount()))));
    main_serial.attribute(null, "crash", Integer.toString(count(EPhpUnitTestStatus.CRASH)));
    main_serial.attribute(
        null,
        "crash_percent",
        Float.toString(
            100.0f * (((float) count(EPhpUnitTestStatus.CRASH)) / ((float) getTestCount()))));
    main_serial.attribute(null, "skip", Integer.toString(count(EPhpUnitTestStatus.SKIP)));
    main_serial.attribute(null, "xskip", Integer.toString(count(EPhpUnitTestStatus.XSKIP)));
    main_serial.attribute(null, "warning", Integer.toString(count(EPhpUnitTestStatus.WARNING)));
    main_serial.attribute(null, "notice", Integer.toString(count(EPhpUnitTestStatus.NOTICE)));
    main_serial.attribute(
        null, "deprecated", Integer.toString(count(EPhpUnitTestStatus.DEPRECATED)));
    main_serial.attribute(
        null, "not_implemented", Integer.toString(count(EPhpUnitTestStatus.NOT_IMPLEMENTED)));
    main_serial.attribute(
        null, "unsupported", Integer.toString(count(EPhpUnitTestStatus.UNSUPPORTED)));
    main_serial.attribute(
        null, "test_exception", Integer.toString(count(EPhpUnitTestStatus.TEST_EXCEPTION)));
    main_serial.attribute(null, "bork", Integer.toString(count(EPhpUnitTestStatus.BORK)));

    if (ini != null) {
      main_serial.startTag("pftt", "ini");
      main_serial.text(ini.toString());
      main_serial.endTag("pftt", "ini");
    }

    main_serial.endTag("pftt", "tally");
  } // end private void writeTally
  /**
   * Crea los ficheros que forman la paleta de color de la version 1.1 a traves de un XML que se le
   * pasa por parametro
   *
   * @param palettesPath
   */
  private static void createVersionFromXML(String palettesBasePath, String xml) {
    new File(palettesBasePath).mkdir();
    KXmlParser parser = new KXmlParser();
    StringReader reader = new StringReader(xml);
    try {
      parser.setInput(reader);
      int tag = parser.nextTag();

      parser.require(KXmlParser.START_TAG, null, "palettes");
      tag = parser.nextTag();
      parser.require(KXmlParser.START_TAG, null, "palette_list");
      parser.skipSubTree();
      parser.require(KXmlParser.END_TAG, null, "palette_list");
      tag = parser.nextTag();

      while (tag == KXmlParser.START_TAG) {
        parser.require(KXmlParser.START_TAG, null, "palette");
        if (parser.getAttributeCount() == 2) {
          // Generar nuevo fichero
          KXmlSerializer parserOutput = new KXmlSerializer();
          FileOutputStream fileOutputStream =
              new FileOutputStream(
                  palettesBasePath + File.separator + parser.getAttributeValue(0) + ".xml");

          parserOutput.setOutput(fileOutputStream, null);
          parserOutput.startDocument("UTF-8", null);
          parserOutput.startTag(null, "ColorTable");
          parserOutput.attribute(null, "name", parser.getAttributeValue(0));
          parserOutput.attribute(null, "version", "1.1");

          tag = parser.nextTag();
          parser.require(KXmlParser.START_TAG, null, "table");
          tag = parser.nextTag();

          parserOutput.text("\n");
          ArrayList items = new ArrayList();
          while (tag == KXmlParser.START_TAG) {
            parser.require(KXmlParser.START_TAG, null, "entry");
            if (parser.getAttributeCount() == 3) {
              String rgb =
                  parser
                      .getAttributeValue(1)
                      .substring(
                          parser.getAttributeValue(1).indexOf(",") + 1,
                          parser.getAttributeValue(1).length());

              int a =
                  Integer.valueOf(
                          parser
                              .getAttributeValue(1)
                              .substring(0, parser.getAttributeValue(1).indexOf(",")))
                      .intValue();
              int r = Integer.valueOf(rgb.substring(0, rgb.indexOf(","))).intValue();
              int g =
                  Integer.valueOf(rgb.substring(rgb.indexOf(",") + 1, rgb.lastIndexOf(",")))
                      .intValue();
              int b =
                  Integer.valueOf(rgb.substring(rgb.lastIndexOf(",") + 1, rgb.length())).intValue();

              ColorItem colorItem = new ColorItem();
              colorItem.setColor(new Color(r, g, b, a));
              colorItem.setInterpolated(50);
              colorItem.setNameClass(parser.getAttributeValue(0));
              colorItem.setValue(Double.parseDouble(parser.getAttributeValue(2)));
              items.add(colorItem);
            }
            tag = parser.nextTag();
            parser.require(KXmlParser.END_TAG, null, "entry");
            tag = parser.nextTag();
          }
          parser.require(KXmlParser.END_TAG, null, "table");
          tag = parser.nextTag();

          ColorTable colorTable = new ColorTable();
          colorTable.createPaletteFromColorItems(items, true);
          items = colorTable.getColorItems();
          for (int i = 0; i < items.size(); i++) {
            ColorItem colorItem = (ColorItem) items.get(i);
            parserOutput.startTag(null, "Color");
            parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue()));
            parserOutput.attribute(null, "name", String.valueOf(colorItem.getNameClass()));
            Color color = colorItem.getColor();
            parserOutput.attribute(
                null,
                "rgb",
                String.valueOf(color.getRed() + "," + color.getGreen() + "," + color.getBlue()));
            parserOutput.attribute(
                null, "interpolated", String.valueOf(colorItem.getInterpolated()));
            parserOutput.endTag(null, "Color");
            parserOutput.text("\n");
          }

          for (int i = 0; i < items.size(); i++) {
            ColorItem colorItem = (ColorItem) items.get(i);
            parserOutput.startTag(null, "Alpha");
            parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue()));
            parserOutput.attribute(null, "alpha", String.valueOf(colorItem.getColor().getAlpha()));
            parserOutput.attribute(
                null, "interpolated", String.valueOf(colorItem.getInterpolated()));
            parserOutput.endTag(null, "Alpha");
            parserOutput.text("\n");
          }

          parserOutput.endTag(null, "ColorTable");
          parserOutput.text("\n");
          parserOutput.endDocument();
          // Cerrar nuevo fichero
          fileOutputStream.close();
        }
        parser.require(KXmlParser.END_TAG, null, "palette");
        tag = parser.nextTag();
      }
      parser.require(KXmlParser.END_TAG, null, "palettes");
    } catch (XmlPullParserException xmlEx) {
      System.out.println(
          "El fichero de paletas predeterminadas no tiene la estructura correcta:\n	"
              + xmlEx.getMessage());
    } catch (IOException e) {
    }
  }