コード例 #1
0
  public void testXmlSerializer() throws Exception {
    Format root = new DataFormat("root");
    Format person = root.addChild("Person", Format.Form.STRUCT);
    person.setProperty("test1", new Value("prop1"));
    person.setProperty("test2", new Value(119));
    person.setProperty("test3", new Value(true));
    person.setProperty("test4", new Value(3.1415926f));
    person.addChild("name", Format.Form.FIELD, Type.STRING);
    Format asset = person.addChild("asset", Format.Form.ARRAYOFSTRUCT);
    asset.addChild("test", Format.Form.ARRAYOFFIELD, Type.STRING);
    asset.addChild("name", Format.Form.FIELD, Type.STRING);
    asset.addChild("price", Format.Form.FIELD, Type.FLOAT);
    Format name =
        asset
            .addChild("vendor", Format.Form.STRUCT)
            .addChild("name", Format.Form.FIELD, Type.STRING);

    Element personData = new DataElement(person);
    Element nameData = personData.addChild("name");
    nameData.setValue("James wang");
    assertEquals("James wang", nameData.getValue().getString());
    Element assetData = personData.addChild("asset");
    Element assetDataItem = assetData.addArrayItem();
    assetDataItem.addChild("test").addArrayItem().setValue("test collection default index");
    assetDataItem.addChild("name").setValue("Mac air book");
    assetDataItem.addChild("price").setValue(12000.05f);
    assetDataItem.addChild("vendor").addChild("name").setValue("Apple");
    assetDataItem = assetData.addArrayItem();
    assetDataItem.addChild("name").setValue("HP computer");
    assetDataItem.addChild("price").setValue(15000.05f);
    assetDataItem.addChild("vendor").addChild("name").setValue("HP");

    ElementXmlSerializer serializer = new ElementXmlSerializer(personData, true);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    serializer.write(baos);
    System.out.println(baos.toString());
  }
コード例 #2
0
ファイル: Runen.java プロジェクト: EXMARaLDA/exmaralda
  /** @param args the command line arguments */
  public static void main(String args[]) {
    java.awt.Font runenfont = new java.awt.Font("Runenprojekt", java.awt.Font.PLAIN, 14);
    java.awt.Font unicodefont = new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 14);
    int i = 0;
    Format numberFormat = new Format();
    numberFormat.setProperty("font:name", "Arial Unicode MS");
    numberFormat.setProperty("chunk-border", "lrb");
    numberFormat.setID("nf");
    Format runenFormat = new Format();
    runenFormat.setProperty("chunk-border", "lrb");
    runenFormat.setProperty("font:name", "Runenprojekt");
    runenFormat.setID("rf");

    ItBundle itb = new ItBundle();
    ItLine numberLine = new ItLine();
    ItLabel numberLabel = new ItLabel();
    numberLabel.setFormat(numberFormat);
    Run nr = new Run();
    nr.setText("Unicode dezimal");
    numberLabel.addRun(nr);
    numberLine.setLabel(numberLabel);

    ItLine charLine1 = new ItLine();
    ItLabel charLabel1 = new ItLabel();
    charLabel1.setFormat(numberFormat);
    Run cr1 = new Run();
    cr1.setText("Runenfont");
    charLabel1.addRun(cr1);
    charLine1.setLabel(charLabel1);

    ItLine charLine2 = new ItLine();
    ItLabel charLabel2 = new ItLabel();
    charLabel2.setFormat(numberFormat);
    Run cr2 = new Run();
    cr2.setText("Arial Unicode MS");
    charLabel2.addRun(cr2);
    charLine2.setLabel(charLabel2);

    for (char c = 0; c < Character.MAX_VALUE; c++) {
      if ((c <= 255) || (runenfont.canDisplay(c))) {
        System.out.println(i + " " + c);
        SyncPoint sp = new SyncPoint();
        sp.setID("S" + Integer.toString(i));
        sp.setFormat(numberFormat);
        itb.getSyncPoints().addSyncPoint(sp);

        ItChunk itc = new ItChunk();
        Run run = new Run();
        run.setFormat(numberFormat);
        run.setText(Integer.toString(i));
        itc.setFormat(numberFormat);
        itc.setStart(sp);
        itc.addRun(run);
        numberLine.addItChunk(itc);

        itc = new ItChunk();
        run = new Run();
        run.setFormat(runenFormat);
        if (runenfont.canDisplay(c)) {
          run.setText(String.valueOf(c));
        } else {
          run.setText("no glyph");
        }
        itc.setStart(sp);
        itc.setFormat(runenFormat);
        itc.addRun(run);
        charLine1.addItChunk(itc);

        itc = new ItChunk();
        run = new Run();
        run.setFormat(numberFormat);
        if (unicodefont.canDisplay(c)) {
          run.setText(String.valueOf(c));
        } else {
          run.setText("no glyph");
        }
        itc.setStart(sp);
        itc.setFormat(numberFormat);
        itc.addRun(run);
        charLine2.addItChunk(itc);
      }
      i++;
    }
    InterlinearText it = new InterlinearText();
    it.getFormats().addFormat(numberFormat);
    it.getFormats().addFormat(runenFormat);
    itb.addItLine(numberLine);
    itb.addItLine(charLine1);
    itb.addItLine(charLine2);
    SyncPoint sp = new SyncPoint();
    sp.setID("END");
    sp.setFormat(numberFormat);
    itb.getSyncPoints().addSyncPoint(sp);
    itb.implyEnds();
    it.addItElement(itb);
    it.trim(new PageOutputParameters());
    try {
      it.writeHTMLToFile("c:\\out.html", new HTMLParameters());
      it.writeXMLToFile("c:\\out.xml");
      it.writeTestRTF("c:\\out.rtf", new RTFParameters());
    } catch (java.io.IOException ioe) {
      ioe.printStackTrace();
    }
  }