This project has retired. For details please refer to its Attic page.
RedbackKeyManagementJdoStaxWriter xref
View Javadoc

1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 1.7,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.archiva.redback.keys.jdo.io.stax;
7   
8     //---------------------------------/
9    //- Imported classes and packages -/
10  //---------------------------------/
11  
12  import java.io.IOException;
13  import java.io.OutputStream;
14  import java.io.StringWriter;
15  import java.io.Writer;
16  import java.text.DateFormat;
17  import java.util.Iterator;
18  import java.util.Locale;
19  import java.util.jar.Manifest;
20  import javax.xml.stream.*;
21  import org.apache.archiva.redback.keys.jdo.AuthenticationKeyDatabase;
22  import org.apache.archiva.redback.keys.jdo.JdoAuthenticationKey;
23  
24  /**
25   * Class RedbackKeyManagementJdoStaxWriter.
26   * 
27   * @version $Revision$ $Date$
28   */
29  public class RedbackKeyManagementJdoStaxWriter
30  {
31  
32        //--------------------------/
33       //- Class/Member Variables -/
34      //--------------------------/
35  
36      /**
37       * Field curId.
38       */
39      private int curId;
40  
41      /**
42       * Field idMap.
43       */
44      private java.util.Map idMap;
45  
46  
47        //----------------/
48       //- Constructors -/
49      //----------------/
50  
51      public RedbackKeyManagementJdoStaxWriter()
52      {
53          idMap = new java.util.HashMap();
54      } //-- org.apache.archiva.redback.keys.jdo.io.stax.RedbackKeyManagementJdoStaxWriter()
55  
56  
57        //-----------/
58       //- Methods -/
59      //-----------/
60  
61      /**
62       * Method write.
63       * 
64       * @param writer
65       * @param authenticationKeyDatabase
66       * @throws java.io.IOException
67       * @throws XMLStreamException
68       */
69      public void write( Writer writer, AuthenticationKeyDatabase authenticationKeyDatabase )
70          throws java.io.IOException, XMLStreamException
71      {
72          XMLOutputFactory factory = XMLOutputFactory.newInstance();
73          boolean supportWindowsLineEndings = false;
74          if ( factory.isPropertySupported( "com.ctc.wstx.outputEscapeCr" ) )
75          {
76              factory.setProperty( "com.ctc.wstx.outputEscapeCr", Boolean.FALSE );
77              supportWindowsLineEndings = true;
78          }
79          if ( factory.isPropertySupported( "org.codehaus.stax2.automaticEmptyElements" ) )
80          {
81              factory.setProperty( "org.codehaus.stax2.automaticEmptyElements", Boolean.FALSE );
82          }
83          IndentingXMLStreamWriter serializer = new IndentingXMLStreamWriter( factory.createXMLStreamWriter( writer ) );
84          if ( supportWindowsLineEndings )
85          {
86              serializer.setNewLine( serializer.getLineSeparator() );
87          }
88          serializer.writeStartDocument( authenticationKeyDatabase.getModelEncoding(), "1.0" );
89          writeAuthenticationKeyDatabase( authenticationKeyDatabase, "authenticationKeyDatabase", serializer );
90          serializer.writeEndDocument();
91      } //-- void write( Writer, AuthenticationKeyDatabase )
92  
93      /**
94       * Method write.
95       * 
96       * @param stream
97       * @param authenticationKeyDatabase
98       * @throws java.io.IOException
99       * @throws XMLStreamException
100      */
101     public void write( OutputStream stream, AuthenticationKeyDatabase authenticationKeyDatabase )
102         throws java.io.IOException, XMLStreamException
103     {
104         XMLOutputFactory factory = XMLOutputFactory.newInstance();
105         boolean supportWindowsLineEndings = false;
106         if ( factory.isPropertySupported( "com.ctc.wstx.outputEscapeCr" ) )
107         {
108             factory.setProperty( "com.ctc.wstx.outputEscapeCr", Boolean.FALSE );
109             supportWindowsLineEndings = true;
110         }
111         if ( factory.isPropertySupported( "org.codehaus.stax2.automaticEmptyElements" ) )
112         {
113             factory.setProperty( "org.codehaus.stax2.automaticEmptyElements", Boolean.FALSE );
114         }
115         IndentingXMLStreamWriter serializer = new IndentingXMLStreamWriter( factory.createXMLStreamWriter( stream, authenticationKeyDatabase.getModelEncoding() ) );
116         if ( supportWindowsLineEndings )
117         {
118             serializer.setNewLine( serializer.getLineSeparator() );
119         }
120         serializer.writeStartDocument( authenticationKeyDatabase.getModelEncoding(), "1.0" );
121         writeAuthenticationKeyDatabase( authenticationKeyDatabase, "authenticationKeyDatabase", serializer );
122         serializer.writeEndDocument();
123     } //-- void write( OutputStream, AuthenticationKeyDatabase )
124 
125     /**
126      * Method writeAuthenticationKeyDatabase.
127      * 
128      * @param authenticationKeyDatabase
129      * @param serializer
130      * @param tagName
131      * @throws java.io.IOException
132      * @throws XMLStreamException
133      */
134     private void writeAuthenticationKeyDatabase( AuthenticationKeyDatabase authenticationKeyDatabase, String tagName, XMLStreamWriter serializer )
135         throws java.io.IOException, XMLStreamException
136     {
137         if ( authenticationKeyDatabase != null )
138         {
139             serializer.writeStartElement( tagName );
140             if ( ( authenticationKeyDatabase.getKeys() != null ) && ( authenticationKeyDatabase.getKeys().size() > 0 ) )
141             {
142                 serializer.writeStartElement( "keys" );
143                 for ( Iterator iter = authenticationKeyDatabase.getKeys().iterator(); iter.hasNext(); )
144                 {
145                     JdoAuthenticationKey o = (JdoAuthenticationKey) iter.next();
146                     writeJdoAuthenticationKey( o, "key", serializer );
147                 }
148                 serializer.writeEndElement();
149             }
150             serializer.writeEndElement();
151         }
152     } //-- void writeAuthenticationKeyDatabase( AuthenticationKeyDatabase, String, XMLStreamWriter )
153 
154     /**
155      * Method writeJdoAuthenticationKey.
156      * 
157      * @param jdoAuthenticationKey
158      * @param serializer
159      * @param tagName
160      * @throws java.io.IOException
161      * @throws XMLStreamException
162      */
163     private void writeJdoAuthenticationKey( JdoAuthenticationKey jdoAuthenticationKey, String tagName, XMLStreamWriter serializer )
164         throws java.io.IOException, XMLStreamException
165     {
166         if ( jdoAuthenticationKey != null )
167         {
168             serializer.writeStartElement( tagName );
169             if ( jdoAuthenticationKey.getKey() != null )
170             {
171                 serializer.writeStartElement( "key" );
172                 serializer.writeCharacters( jdoAuthenticationKey.getKey() );
173                 serializer.writeEndElement();
174             }
175             if ( jdoAuthenticationKey.getForPrincipal() != null )
176             {
177                 serializer.writeStartElement( "forPrincipal" );
178                 serializer.writeCharacters( jdoAuthenticationKey.getForPrincipal() );
179                 serializer.writeEndElement();
180             }
181             if ( jdoAuthenticationKey.getPurpose() != null )
182             {
183                 serializer.writeStartElement( "purpose" );
184                 serializer.writeCharacters( jdoAuthenticationKey.getPurpose() );
185                 serializer.writeEndElement();
186             }
187             if ( jdoAuthenticationKey.getDateCreated() != null )
188             {
189                 serializer.writeStartElement( "dateCreated" );
190                 serializer.writeCharacters( String.valueOf( jdoAuthenticationKey.getDateCreated().getTime() ) );
191                 serializer.writeEndElement();
192             }
193             if ( jdoAuthenticationKey.getDateExpires() != null )
194             {
195                 serializer.writeStartElement( "dateExpires" );
196                 serializer.writeCharacters( String.valueOf( jdoAuthenticationKey.getDateExpires().getTime() ) );
197                 serializer.writeEndElement();
198             }
199             serializer.writeEndElement();
200         }
201     } //-- void writeJdoAuthenticationKey( JdoAuthenticationKey, String, XMLStreamWriter )
202 
203 }