View Javadoc

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