Skip to main content
summaryrefslogtreecommitdiffstats
blob: c9e7dfe3a2ac6bbb7cda07e2cc62bda2f4848819 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*******************************************************************************
 * Copyright (c) 2002-2005 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsi.internal.core.log.impl;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.eclipse.wst.wsi.internal.core.WSIConstants;
import org.eclipse.wst.wsi.internal.core.log.MimePart;
import org.eclipse.wst.wsi.internal.core.xml.XMLUtils;

/**
 * @author lauzond
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class MimePartImpl implements MimePart 
{
  private String mimeContent;
  private String mimeHeaders;
  private String[] boundaryStrings = new String[0];
  
  public MimePartImpl ()
  {
  }
  
  /* (non-Javadoc)
   * @see org.wsi.test.log.MimePart#getContent()
   */
  public String getContent()
  {
    return this.mimeContent;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MimePart#setContent(String)
   */
  public void setContent(String mimeContent)
  {
  	this.mimeContent = mimeContent;
  }

  /**
  /* (non-Javadoc)
   * @see org.eclipse.wst.wsi.internal.core.log.MimePart#getHeaders()
   */
  public String getHeaders()
  {
  	return this.mimeHeaders;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MimePart#setHeaders(String)
   */
  public void setHeaders(String mimeHeaders)
  {
  	this.mimeHeaders = mimeHeaders;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MimePart#getBoundaryStrings()
   */
  public String[] getBoundaryStrings()
  {
  	return this.boundaryStrings;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MimePart#setBoundaryStrings(String[])
   */
  public void setBoundaryStrings(String[] boundaryStrings)
  {
  	this.boundaryStrings = boundaryStrings;
  }

  /**
   * Get string representation of this object.
   */
  public String toString()
  {
    return toXMLString(WSIConstants.NS_NAME_WSI_LOG);
  }

  /* (non-Javadoc)
   * @see org.wsi.test.document.DocumentElement#toXMLString(String)
   */
  public String toXMLString(String namespaceName)
  {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);

    String nsName = namespaceName;
    if ((!nsName.equals("") && (!nsName.endsWith(":"))))
      nsName += ":";

    // Add mimePart element
    pw.println("<" + nsName + WSIConstants.ELEM_MIME_PART  + ">");
    
    // Add boundary string element
     for (int i = 0; i < boundaryStrings.length; i++)
    {
        pw.print("<" + nsName + WSIConstants.ELEM_BOUNDARY_STRING + ">");
        pw.print(boundaryStrings[i]);
        pw.println("</" + nsName + WSIConstants.ELEM_BOUNDARY_STRING + ">");
    }
   
    // Add mimeHeaders element
    pw.print("<" + nsName + WSIConstants.ELEM_MIME_HEADERS + ">");
    pw.print(XMLUtils.xmlEscapedString(mimeHeaders));
    pw.println("</" + nsName + WSIConstants.ELEM_MIME_HEADERS + ">");

    // Add encoded content
    pw.print("<" + nsName + WSIConstants.ELEM_MIME_CONTENT + ">");
    if ((mimeContent.indexOf("<") != -1)  || 
        (mimeContent.indexOf(">") != -1)  || 
		(mimeContent.indexOf("\"") != -1) ||
		(mimeContent.indexOf("\'") != -1))
    	pw.print(XMLUtils.xmlEscapedString(mimeContent));
    else
        pw.print(getContent());
    pw.println("</" + nsName + WSIConstants.ELEM_MIME_CONTENT + ">");
 
    // Add end message element
    pw.println("</" + nsName + WSIConstants.ELEM_MIME_PART + ">");

    // Return string
    return sw.toString();
  }

}

Back to the top