Package java.io

Examples of java.io.StringWriter


  /**
   * Convert an XML document to a latin-1 string
   */
  public static String serializeXML(Document document) throws GUIException {
    try {
      StringWriter stringWriter = new StringWriter();
      OutputFormat format = new OutputFormat("XML", "ISO-8859-1", true);
      format.setLineWidth(0);
      XMLSerializer serializer = new XMLSerializer(stringWriter, format);
      serializer.asDOMSerializer().serialize(document);
      /* We don't want the newline character at the end */
      String string = stringWriter.toString();
      return string.substring(0, string.length() - 1);
    } catch (Exception e) {
      throw new GUIException("Could not serialize XML", e);
    }
  }
View Full Code Here


     *
     * @param vctx
     * @return problem text
     */
    protected String getProblemText(ValidationContext vctx) {
        StringWriter writer = new StringWriter();
        writer.append("Problems found in schema definition");
        ArrayList problems = vctx.getProblems();
        for (int i = 0; i < problems.size(); i++) {
            writer.append('\n');
            ValidationProblem prob = (ValidationProblem)problems.get(i);
            writer.append(prob.getDescription());
        }
        return writer.toString();
    }
View Full Code Here

     * @param schema schema element
     * @return output schema text
     * @throws Exception
     */
    protected String writeSchema(SchemaElement schema) throws Exception {
        StringWriter writer = new StringWriter();
        IMarshallingContext ictx = m_bindingFactory.createMarshallingContext();
        ictx.setOutput(writer);
        ictx.setIndent(2);
        ictx.marshalDocument(schema);
        return writer.toString();
    }
View Full Code Here

        doAppend(text == null ? "null" : text.toString());
        return this;
    }

    public StyledTextOutput exception(Throwable throwable) {
        StringWriter out = new StringWriter();
        PrintWriter writer = new PrintWriter(out);
        throwable.printStackTrace(writer);
        writer.close();
        text(out.toString());
        return this;
    }
View Full Code Here

     * @param document the Document to format
     * @return a String containing XML
     */
    private static String formatDocument(Document document) throws IOException {       
        final XMLOutputter outputter = new XMLOutputter();
        final StringWriter writer = new StringWriter();
       
        outputter.output(document, writer);
       
        return writer.getBuffer().toString();
    }
View Full Code Here

          {
            if ( str.length() > 0 ){
              view_model.getLogArea().appendText( str + "\n" );
            }
           
            StringWriter sw = new StringWriter();
           
            PrintWriter  pw = new PrintWriter( sw );
           
            error.printStackTrace( pw );
           
            pw.flush();
           
            view_model.getLogArea().appendText( sw.toString() + "\n" );
          }
        });   
   
    status_field = view_model.getStatus();
   
View Full Code Here

  }

  public static void
  dumpThreads()
  {
    StringWriter  sw = new StringWriter();
   
    IndentWriter iw = new IndentWriter( new PrintWriter( sw ));
   
    dumpThreads( iw );
   
    iw.close();
   
    Debug.out( sw.toString());
  }
View Full Code Here

      final File selFile = fileChooser.getSelectedFile();
      // now load the file
      try
      {
        final BufferedReader in = new BufferedReader(new FileReader(selFile));
        final StringWriter out = new StringWriter((int) selFile.length());
        IOUtils.getInstance().copyWriter(in, out);
        in.close();
        txDataArea.setText(out.toString());
      }
      catch (IOException ioe)
      {
        controller.getStatusBar().setStatusText("Failed to load CSV file: " + ioe.getLocalizedMessage());
      }
View Full Code Here

  /**
   * Initializes all component for the module editor and creates and layouts all keyeditors.
   */
  protected void build()
  {
    final StringWriter writer = new StringWriter();
    writer.write("<html><head><title></title></head><body>"); //$NON-NLS-1$

    final JTextArea mangleInfo = new JTextArea();
    mangleInfo.setText(messages.getString("DefaultModuleEditor.USER_GUIDE", modulePackage)); //$NON-NLS-1$
    mangleInfo.setName("DescriptionArea"); //$NON-NLS-1$
    mangleInfo.setMinimumSize(new Dimension(100, 10));
    mangleInfo.setEditable(false);
    mangleInfo.setLineWrap(true);
    mangleInfo.setWrapStyleWord(true);
    mangleInfo.setOpaque(false);
    contentpane.add(mangleInfo);

    final ConfigDescriptionEntry[] keyNames = getKeyNames();
    if (keyNames == null)
    {
      throw new IllegalStateException(messages.getString("DefaultModuleEditor.ERROR_0001_NO_KEYS_DEFINED")); //$NON-NLS-1$
    }

    activeEditors = new EditorCarrier[keyNames.length];
    for (int i = 0; i < keyNames.length; i++)
    {
      final KeyEditor editor;
      final String displayName = createDisplayName(keyNames[i].getKeyName());

      if (keyNames[i] instanceof EnumConfigDescriptionEntry)
      {
        final EnumConfigDescriptionEntry entry = (EnumConfigDescriptionEntry) keyNames[i];
        editor = new EnumKeyEditor(getConfig(), entry, displayName);
      }
      else if (keyNames[i] instanceof ClassConfigDescriptionEntry)
      {
        final ClassConfigDescriptionEntry entry = (ClassConfigDescriptionEntry) keyNames[i];
        editor = new ClassKeyEditor(getConfig(), entry, displayName);
      }
      else
      {
        editor = new TextKeyEditor(getConfig(), keyNames[i], displayName);
      }

      final JCheckBox enableCB = new JCheckBox();
      enableCB.addActionListener(new EnableAction(editor, enableCB));
      final JPanel panel = new JPanel();
      panel.setLayout(new BorderLayout());
      panel.add(enableCB, BorderLayout.WEST);
      panel.add(editor.getComponent(), BorderLayout.CENTER);

      contentpane.add(panel);
      activeEditors[i] = new EditorCarrier(editor, enableCB);

      writer.write("<h3><b>"); //$NON-NLS-1$
      writer.write(keyNames[i].getKeyName());
      writer.write("</b></h3>"); //$NON-NLS-1$
      writer.write("<p>"); //$NON-NLS-1$
      writer.write(keyNames[i].getDescription());
      writer.write("</p><hr>"); //$NON-NLS-1$
    }

    int width = 0;
    for (int i = 0; i < activeEditors.length; i++)
    {
      width = Math.max(width, activeEditors[i].getEditor().getLabelWidth());
    }
    for (int i = 0; i < activeEditors.length; i++)
    {
      activeEditors[i].getEditor().setLabelWidth(width);
    }
    writer.write("</body></html>"); //$NON-NLS-1$

    helpPane.setText(writer.toString());

  }
View Full Code Here

        Assert.assertEquals(2, list.size());

        String query1 = "fn:collection('/" + COLLECTION_NAME + "/1.xml')//author[1]";
        XQueryProcessor proc = new XQueryProcessor();
        XQueryModule compiled1 = proc.parse(query1);
        StringWriter sw = new StringWriter();
        SAXWriter handler = new SAXWriter(sw);
        SAXSerializer ser = new SAXSerializer(handler);

        proc.execute(compiled1, ser);
        handler.flush();
        String result1 = sw.toString();

        System.err.println(result1);

        Author author1 = (Author) xstream.fromXML(result1);
        Assert.assertEquals("anonymous", author1.getName());
View Full Code Here

TOP

Related Classes of java.io.StringWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.