KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > server > notification > PlainBootstrapMessageBuilder


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package sync4j.server.notification;
19
20 import java.io.*;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
24 import java.util.logging.Level JavaDoc;
25 import java.util.logging.Logger JavaDoc;
26
27 import org.jibx.runtime.BindingDirectory;
28 import org.jibx.runtime.IBindingFactory;
29 import org.jibx.runtime.IMarshallingContext;
30
31 import sync4j.framework.core.*;
32 import sync4j.framework.core.dm.ddf.*;
33 import sync4j.framework.logging.Sync4jLogger;
34 import sync4j.framework.logging.Sync4jLoggerName;
35 import sync4j.framework.notification.BootstrapMessageBuilder;
36 import sync4j.framework.notification.NotificationException;
37 import sync4j.framework.tools.ArrayUtils;
38 import sync4j.framework.tools.Base64;
39 import sync4j.framework.tools.DbgTools;
40 import sync4j.framework.tools.WBXMLTools;
41
42
43 /**
44  * It's a builder for a bootstrap message for Plain Profile.
45  *
46  * @author Stefano Nichele @ Funambol
47  *
48  * @version $Id: PlainBootstrapMessageBuilder.java,v 1.1 2005/05/16 17:32:56 nichele Exp $
49  */

50 public class PlainBootstrapMessageBuilder implements BootstrapMessageBuilder {
51
52     // --------------------------------------------------------------- Constants
53

54     // -------------------------------------------------------------- Properties
55

56     // ------------------------------------------------------------ Private data
57
private Logger JavaDoc log = null;
58
59     // ------------------------------------------------------------- Constructor
60
public PlainBootstrapMessageBuilder() {
61         log = Sync4jLogger.getLogger(Sync4jLoggerName.SERVER_DM_BOOTSTRAP);
62     }
63
64     // ---------------------------------------------------------- Public Methods
65

66     /**
67      * Returns the wbxml representation of the bootstrap message for the given <code>SycnMLDM</code> object.
68      *
69      * @param serverUri the server URI
70      * @param deviceId the device id
71      * @param phoneNumber the phone number
72      * @param syncMLDM the SyncMLDM object
73      *
74      * @throws NotificationException if a error occurs during message creation
75      * @return byte[] the wbxml representation of the bootstrap messege
76      */

77     public byte[] buildMessage(String JavaDoc serverUri, String JavaDoc deviceId,
78                                String JavaDoc phoneNumber, SyncMLDM syncMLDM) throws NotificationException {
79
80         if (log.isLoggable(Level.INFO)) {
81             log.info("Calling buildMessage in PlainBootstrapMessageBuilder");
82         }
83
84         SyncML syncMLBootstrapMessage = getSyncMLBootstrapMessage(serverUri, deviceId, syncMLDM);
85
86         byte[] message = null;
87
88         try {
89
90             ByteArrayOutputStream bout = new ByteArrayOutputStream();
91
92             IBindingFactory f = BindingDirectory.getFactory(SyncML.class);
93             IMarshallingContext c = f.createMarshallingContext();
94             c.setIndent(0);
95             c.marshalDocument(syncMLBootstrapMessage, "UTF-8", null, bout);
96
97             String JavaDoc inputXml = new String JavaDoc(bout.toByteArray());
98             inputXml = metInfNamespaceHandler(inputXml);
99
100             if (log.isLoggable(Level.FINE)) {
101                 log.fine("PlainBootstrapMessage - xml: " + inputXml);
102             }
103
104
105             message = WBXMLTools.toWBXML(inputXml);
106
107             /**
108              * ONLY FOR TEST!
109              */

110             //writeBytesToFile("testwbxml.wbxml", message);
111

112         } catch (Exception JavaDoc ex) {
113             throw new NotificationException("Error during xml to wbxml transformation", ex);
114         }
115
116         return message;
117     }
118
119     // --------------------------------------------------------- Private Methods
120

121     /**
122      * Returns the <code>SyncML</code> object corresponds to the bootstrap message for the given <code>SycnMLDM</code> object.
123      * @param serverUri the server uri
124      * @param deviceId the device id
125      * @param syncMLDM the SyncMLDM object
126      *
127      * @throws NotificationException if a error occurs during message creation
128      * @return SyncML the <code>SyncML</code> corresponds to the bootstrap message
129      */

130     private SyncML getSyncMLBootstrapMessage(String JavaDoc serverUri, String JavaDoc deviceId, SyncMLDM syncMLDM) throws NotificationException {
131         SyncML syncMLBootstrapMessage = null;
132
133         SyncHdr syncHdrMessage = null;
134         SyncBody syncBodyMessage = null;
135
136         try {
137
138             syncHdrMessage = new SyncHdr(
139                 new VerDTD("1.1"),
140                 Constants.SYNCML_DM_1_1,
141                 new SessionID("0"),
142                 "0", // MsgID
143
new Target(deviceId),
144                 new Source(serverUri),
145                 null, /* response URI */
146                 false, /* no reponse */
147                 null, /* credentials */
148                 null
149                 /* metadata */
150                 );
151
152             Add addCommand = buildAddCommand(syncMLDM);
153
154             syncBodyMessage = new SyncBody(
155                 new AbstractCommand[] {addCommand}
156                 ,
157                 true
158                 /* final */
159                 );
160
161             syncMLBootstrapMessage = new SyncML(syncHdrMessage, syncBodyMessage);
162
163
164         } catch (RepresentationException ex) {
165             throw new NotificationException("Error during creation of the SyncML message", ex);
166         }
167
168         return syncMLBootstrapMessage;
169     }
170
171
172     /**
173      * Returns the Add command for the parameters of the given <code>SyncMLDM</code>
174      *
175      * @param syncMLDM the <code>SyncMLDM</code> object
176      * @return Add the add command for the parameters of the given <code>SyncMLDM</code>.
177      * The CmdID is equal to 1.
178      */

179     private Add buildAddCommand(SyncMLDM syncMLDM) {
180         Add addCommand = new Add(
181             new CmdID(1),
182             false, /* no response */
183             null, /* credential */
184             null,
185             getItemsToAdd(syncMLDM)
186         );
187
188         return addCommand;
189     }
190
191     /**
192      * Returns the <code>Item[]</code> for the parameters of the given <code>SyncMLDM</code>
193      * @param syncMLDM the <code>SyncMLDM</code> object
194      * @return Item[] the Item[] for the parameters of the given <code>SyncMLDM</code>.
195      */

196     private Item[] getItemsToAdd(SyncMLDM syncMLDM) {
197
198         // item for DMAcc tree
199
Item[] itemDMAcc = getItemsToAddForDMAcc(syncMLDM.getDmAcc());
200
201         // item for Con tree
202
Item[] itemCon = getItemsToAddForConNode(syncMLDM.getCon());
203
204         return (Item[])(ArrayUtils.mergeArrays(itemDMAcc, itemCon, itemDMAcc.getClass().getComponentType()));
205     }
206
207
208     /**
209      * Returns the <code>Item[]</code> for the parameters of the given <code>DMAcc</code>
210      * @param dmAcc the <code>DMAcc</code> object
211      * @return Item[] the Item[] for the parameters of the given <code>DMAcc</code>.
212      */

213     private Item[] getItemsToAddForDMAcc(DMAcc dmAcc) {
214
215         Set JavaDoc keys = dmAcc.getDMAccounts().keySet();
216
217         int numDMAcc = keys.size();
218
219         if (numDMAcc == 0) {
220             return new Item[0];
221         }
222
223         ArrayList JavaDoc listItems = new ArrayList JavaDoc();
224
225         java.util.Map JavaDoc accounts = dmAcc.getDMAccounts();
226         Iterator JavaDoc itAccounts = keys.iterator();
227
228         Meta metaInfoForInteriorNode = new Meta();
229         metaInfoForInteriorNode.setFormat("node");
230
231         DMAccount dmAccount = null;
232         String JavaDoc accountName = null;
233         while (itAccounts.hasNext()) {
234             accountName = (String JavaDoc)itAccounts.next();
235             dmAccount = (DMAccount)accounts.get(accountName);
236
237             /*
238              * Item for dm account
239              */

240             String JavaDoc localUri = SyncMLDM.SYNCML_DM_BASE_URI + SyncMLDM.SYNCML_DM_DMACC + "/" + accountName;
241             Item itemDMAccount = new Item(new Target(localUri),
242                                           null, /* Source */
243                                           metaInfoForInteriorNode,
244                                           null, /* ComplexData */
245                                           false
246                                           /* MoreData */
247                                  );
248
249             listItems.add(itemDMAccount);
250
251             /* Item for address */
252             listItems.add(getItem(localUri + DMAccount.DMACC_ADDR, dmAccount.getAddress(), false, false));
253
254             /* Item for addressType */
255             listItems.add(getItem(localUri + DMAccount.DMACC_ADDR_TYPE,
256                                   String.valueOf(dmAccount.getAddressType()), false, false));
257
258             /* Item for port number */
259             listItems.add(getItem(localUri + DMAccount.DMACC_PORT_NBR,
260                                   String.valueOf(dmAccount.getPortNumber()), false, false));
261
262             /* Item for conRef */
263             String JavaDoc conRef = dmAccount.getConRef();
264             if (conRef != null && !conRef.equals("")) {
265                 listItems.add(getItem(localUri + DMAccount.DMACC_CON_REF, conRef, false, false));
266             }
267
268
269             /* Item for serverId */
270             listItems.add(getItem(localUri + DMAccount.DMACC_SERVER_ID, dmAccount.getServerId(), false, false));
271
272             /* Item for serverPw */
273             listItems.add(getItem(localUri + DMAccount.DMACC_SERVER_PASSWORD,
274                                   dmAccount.getServerPassword(), false, false));
275
276             /* Item for serverNonce */
277             if (dmAccount.getServerNonce() != null) {
278                 String JavaDoc serverNonceB64 = new String JavaDoc(Base64.encode(dmAccount.getServerNonce()));
279                 if (log.isLoggable(Level.FINEST)) {
280                     log.finest("ServerNonce: " + DbgTools.bytesToHex(dmAccount.getServerNonce()));
281                     log.finest("ServerNonceB64: " + serverNonceB64);
282
283                 }
284                 listItems.add(getItem(localUri + DMAccount.DMACC_SERVER_NONCE,
285                                       serverNonceB64, false, false));
286             }
287
288             /* Item for userName */
289             listItems.add(getItem(localUri + DMAccount.DMACC_USERNAME, dmAccount.getUserName(), false, false));
290
291             /* Item for clientPw */
292             listItems.add(getItem(localUri + DMAccount.DMACC_CLIENT_PASSWORD,
293                                   dmAccount.getClientPassword(), false, false));
294
295             /* Item for clientNonce */
296             if (dmAccount.getClientNonce() != null) {
297                 String JavaDoc clientNonceB64 = new String JavaDoc(Base64.encode(dmAccount.getClientNonce()));
298                 if (log.isLoggable(Level.FINEST)) {
299                     log.finest("ClientNonce: " + DbgTools.bytesToHex(dmAccount.getClientNonce()));
300                     log.finest("ClientNonceB64: " + clientNonceB64);
301                 }
302                 listItems.add(getItem(localUri + DMAccount.DMACC_CLIENT_NONCE,
303                                       clientNonceB64, false, false));
304             }
305
306             /* Item for authPref */
307             listItems.add(getItem(localUri + DMAccount.DMACC_AUTH_PREF, dmAccount.getAuthPref(), false, false));
308
309             /* Item for name */
310             listItems.add(getItem(localUri + DMAccount.DMACC_NAME, dmAccount.getName(), false, false));
311         }
312
313         return (Item[])listItems.toArray(new Item[0]);
314     }
315
316
317     /**
318      * Returns the <code>Item[]</code> for the parameters of the given <code>ConNode</code>
319      * @param conNode the <code>ConNode</code> object
320      * @return Item[] the Item[] for the parameters of the given <code>ConNode</code>.
321      */

322     private Item[] getItemsToAddForConNode(ConNode conNode) {
323         if (conNode == null) {
324             return new Item[0];
325         }
326         Set JavaDoc keys = conNode.getConnections().keySet();
327         if (keys.size() == 0) {
328             return new Item[0];
329         }
330
331         ArrayList JavaDoc listItems = new ArrayList JavaDoc();
332         Iterator JavaDoc itKeys = keys.iterator();
333
334         Connection connection = null;
335         String JavaDoc connectionName = null;
336         while (itKeys.hasNext()) {
337             connectionName = (String JavaDoc)itKeys.next();
338             connection = conNode.getConnection(connectionName);
339             listItems.addAll( getItemsToAddForConnection(connection, connectionName));
340         }
341         return (Item[])listItems.toArray(new Item[0]);
342     }
343
344
345     /**
346      * Returns the <code>ArrayList</code> with the <code>Item</code> for the parameters of the given <code>Connection</code>
347      * @param con the <code>Connection</code> object
348      * @param connectionName the name of the connection
349      * @return ArrayList the items for the parameters of the given <code>Connection</code>.
350      */

351     private ArrayList JavaDoc getItemsToAddForConnection(Connection con, String JavaDoc connectionName) {
352        ArrayList JavaDoc listItems = new ArrayList JavaDoc();
353
354        Meta metaInfoForInteriorNode = new Meta();
355        metaInfoForInteriorNode.setFormat("node");
356
357        /*
358         * Item for connection node
359         */

360        String JavaDoc localUri = SyncMLDM.SYNCML_DM_BASE_URI + SyncMLDM.SYNCML_DM_CON + "/" + connectionName;
361        Item itemConnection = new Item(new Target(localUri),
362                                      null, /* Source */
363                                      metaInfoForInteriorNode,
364                                      null, /* ComplexData */
365                                      false /* MoreData */
366                                      );
367
368        listItems.add(itemConnection);
369
370        sync4j.framework.core.dm.ddf.Ext conExt = con.getExt();
371        NAP conNap = con.getNap();
372        PX conPX = con.getPX();
373
374        ArrayList JavaDoc itemConExt = getItemsToAddForConExt(conExt, connectionName);
375        ArrayList JavaDoc itemConNap = getItemsToAddForConNap(conNap, connectionName);
376        ArrayList JavaDoc itemConPX = getItemsToAddForConPX(conPX, connectionName);
377
378        listItems.addAll(itemConExt);
379        listItems.addAll(itemConNap);
380        listItems.addAll(itemConPX);
381
382        return listItems;
383     }
384
385     /**
386      * Returns the <code>ArrayList</code> with the <code>Item</code> for the parameters of the given <code>Ext</code>
387      * @param ext the <code>Ext</code> object
388      * @param connectionName the name of the connection of the given <code>Ext</code>
389      * @return ArrayList the items for the parameters of the given <code>Ext</code>.
390      */

391     private ArrayList JavaDoc getItemsToAddForConExt(sync4j.framework.core.dm.ddf.Ext ext, String JavaDoc connectionName) {
392         ArrayList JavaDoc listItems = new ArrayList JavaDoc();
393
394         if (ext == null) {
395             return listItems;
396         }
397
398         java.util.Map JavaDoc nodes = ext.getNodes();
399         int size = nodes.size();
400         if (size == 0) {
401             return listItems;
402         }
403
404         Meta metaInfoForInteriorNode = new Meta();
405         metaInfoForInteriorNode.setFormat("node");
406
407         /*
408          * Item for Ext node
409          */

410         String JavaDoc localUri = SyncMLDM.SYNCML_DM_BASE_URI + SyncMLDM.SYNCML_DM_CON + "/" + connectionName + Connection.CON_EXT;
411         Item itemConExt = new Item(new Target(localUri),
412                                    null, /* Source */
413                                    metaInfoForInteriorNode,
414                                    new ComplexData(), /* ComplexData */
415                                    false /* MoreData */
416                           );
417
418
419         listItems.add(itemConExt);
420
421         Iterator JavaDoc itNodes = nodes.keySet().iterator();
422
423         String JavaDoc name = null;
424         String JavaDoc value = null;
425         while (itNodes.hasNext()) {
426             name = (String JavaDoc)itNodes.next();
427             value = (String JavaDoc)nodes.get(name);
428             listItems.add(getItem(localUri + "/" + name,
429                             value, false, false));
430         }
431
432         return listItems;
433
434     }
435
436     /**
437      * Returns the <code>ArrayList</code> with the <code>Item</code> for the parameters of the given <code>NAP</code>
438      * @param nap the <code>NAP</code> object
439      * @param connectionName the name of the connection of the given <code>NAP</code>
440      * @return ArrayList the items for the parameters of the given <code>NAP</code>.
441      */

442     private ArrayList JavaDoc getItemsToAddForConNap(NAP nap, String JavaDoc connectionName) {
443         ArrayList JavaDoc listItems = new ArrayList JavaDoc();
444
445         if (nap == null) {
446             return listItems;
447         }
448
449
450         Meta metaInfoForInteriorNode = new Meta();
451         metaInfoForInteriorNode.setFormat("node");
452
453         /*
454          * Item for connection node
455          */

456         String JavaDoc localUri = SyncMLDM.SYNCML_DM_BASE_URI + SyncMLDM.SYNCML_DM_CON + "/" + connectionName + Connection.CON_NAP;
457         Item itemConNap = new Item(new Target(localUri),
458                                       null, /* Source */
459                                       metaInfoForInteriorNode,
460                                       new ComplexData(), /* ComplexData */
461                                       false /* MoreData */
462                                       );
463
464
465         listItems.add(itemConNap);
466
467         /* Item for bearer */
468         listItems.add(getItem(localUri + NAP.NAP_BEARER,
469                               nap.getBearer(), false, false));
470
471         /* Item for AddrType */
472         listItems.add(getItem(localUri + NAP.NAP_ADDR_TYPE,
473                               nap.getAddressType(), false, false));
474
475         /* Item for Addr */
476         listItems.add(getItem(localUri + NAP.NAP_ADDR, nap.getAddress(), false, false));
477
478
479         if (nap.getAuths().size() > 0) {
480             Item itemAuth = new Item(new Target(localUri + NAP.NAP_AUTH),
481                                      null, /* Source */
482                                      metaInfoForInteriorNode,
483                                      null, /* ComplexData */
484                                      false /* MoreData */
485                                      );
486
487             listItems.add(itemAuth);
488
489             Set JavaDoc keysAuths = nap.getAuths().keySet();
490             Iterator JavaDoc itKeys = keysAuths.iterator();
491             Auth conAuth = null;
492             String JavaDoc authName = null;
493             while (itKeys.hasNext()) {
494                 authName = (String JavaDoc)itKeys.next();
495                 conAuth = nap.getAuth(authName);
496                 listItems.addAll(getItemsToAddForConAuth(conAuth, localUri + NAP.NAP_AUTH + "/" + authName));
497             }
498         }
499
500        return listItems;
501     }
502
503     /**
504      * Returns the <code>ArrayList</code> with the <code>Item</code> for the parameters of the given <code>PX</code>
505      * @param px the <code>PX</code> object
506      * @param connectionName the name of the connection of the given <code>PX</code>
507      * @return ArrayList the items for the parameters of the given <code>PX</code>.
508      */

509     private ArrayList JavaDoc getItemsToAddForConPX(PX px, String JavaDoc connectionName) {
510         ArrayList JavaDoc listItems = new ArrayList JavaDoc();
511
512         if (px == null) {
513             return listItems;
514         }
515
516
517         Meta metaInfoForInteriorNode = new Meta();
518         metaInfoForInteriorNode.setFormat("node");
519
520         /*
521          * Item for connection node
522          */

523         String JavaDoc localUri = SyncMLDM.SYNCML_DM_BASE_URI + SyncMLDM.SYNCML_DM_CON + "/" + connectionName + Connection.CON_PX;
524         Item itemConPx = new Item(new Target(localUri),
525                                       null, /* Source */
526                                       metaInfoForInteriorNode,
527                                       new ComplexData(), /* ComplexData */
528                                       false /* MoreData */
529                                       );
530
531
532         listItems.add(itemConPx);
533
534         /* Item for PortNumber */
535         listItems.add(getItem(localUri + PX.PX_PORT_NBR,
536                               px.getPortNbr(), false, false));
537
538         /* Item for AddrType */
539         listItems.add(getItem(localUri + PX.PX_ADDR_TYPE,
540                               px.getAddressType(), false, false));
541
542         /* Item for Addr */
543         listItems.add(getItem(localUri + PX.PX_ADDR, px.getAddress(), false, false));
544
545         if (px.getAuths().size() > 0) {
546             Item itemAuth = new Item(new Target(localUri + PX.PX_AUTH),
547                                      null, /* Source */
548                                      metaInfoForInteriorNode,
549                                      null, /* ComplexData */
550                                      false /* MoreData */
551                                      );
552
553             listItems.add(itemAuth);
554
555             Set JavaDoc keysAuths = px.getAuths().keySet();
556             Iterator JavaDoc itKeys = keysAuths.iterator();
557             Auth conAuth = null;
558             String JavaDoc authName = null;
559             while (itKeys.hasNext()) {
560                 authName = (String JavaDoc)itKeys.next();
561                 conAuth = px.getAuth(authName);
562                 listItems.addAll(getItemsToAddForConAuth(conAuth, localUri + PX.PX_AUTH + "/" + authName));
563             }
564         }
565
566        return listItems;
567     }
568
569
570     /**
571      * Returns the <code>ArrayList</code> with the <code>Item</code> for the parameters of the given <code>Auth</code>
572      * @param auth the <code>Auth</code> object
573      * @param localUri the base uri for the items
574      * @return ArrayList the items for the parameters of the given <code>Auth</code>.
575      */

576     private ArrayList JavaDoc getItemsToAddForConAuth(Auth auth, String JavaDoc localUri) {
577         ArrayList JavaDoc listItems = new ArrayList JavaDoc();
578
579         Meta metaInfoForInteriorNode = new Meta();
580         metaInfoForInteriorNode.setFormat("node");
581
582         /*
583          * Item for auth node
584          */

585         Item itemConnection = new Item(new Target(localUri),
586                                       null, /* Source */
587                                       metaInfoForInteriorNode,
588                                       null, /* ComplexData */
589                                       false /* MoreData */
590                                       );
591
592
593         listItems.add(itemConnection);
594
595         /* Item for id */
596         listItems.add(getItem(localUri + Auth.AUTH_ID,
597                               auth.getId(), false, false));
598
599         /* Item for AddrType */
600         listItems.add(getItem(localUri + Auth.AUTH_SECRET,
601                               auth.getSecret(), false, false));
602
603
604        return listItems;
605     }
606
607
608     /**
609      * Returns a <code>Item</code> with the given localUri and data.
610      *
611      * @param localUri the local uri of the item
612      * @param data the data of the item
613      * @param interiorNode if <code>true</code> then the meta information is added to item in according
614      * with the SyncML DM standard object specification.
615      * @return Item
616      */

617     private Item getItem(String JavaDoc localUri, String JavaDoc data, boolean interiorNode, boolean formatB64) {
618
619         Meta meta = null;
620
621         if (interiorNode) {
622             meta = new Meta();
623             meta.setFormat("node");
624         }
625
626         if (formatB64) {
627             meta = new Meta();
628             meta.setFormat("b64");
629         }
630
631         Item item = new Item(new Target(localUri),
632                              null, /* Source */
633                              meta,
634                              new ComplexData(data),
635                              false /* MoreData */
636                              );
637
638         return item;
639     }
640
641     /**
642      * This is a solution in order to obviate to a JiBX bug: it does
643      * not allow to declare the namespace to level of structure.
644      *
645      * @param msg the server response
646      *
647      * @return the response with namespace correctly added into MetInf element
648      */

649     private String JavaDoc metInfNamespaceHandler(String JavaDoc msg) {
650         int s = 0;
651         int e = 0;
652
653         StringBuffer JavaDoc response = new StringBuffer JavaDoc();
654         while (( e = msg.indexOf("<Meta", s)) >= 0) {
655
656             response = response.append(msg.substring(s, e));
657
658             int a = msg.indexOf("</Meta>", e);
659             String JavaDoc meta = msg.substring(e, a);
660
661             meta = meta.replaceAll("<Type>" , "<Type xmlns='syncml:metinf'>");
662             meta = meta.replaceAll("<Format>" , "<Format xmlns='syncml:metinf'>");
663             meta = meta.replaceAll("<Mark>" , "<Mark xmlns='syncml:metinf'>");
664             meta = meta.replaceAll("<Size>" , "<Size xmlns='syncml:metinf'>");
665             meta = meta.replaceAll("<Anchor>" , "<Anchor xmlns='syncml:metinf'>");
666             meta = meta.replaceAll("<Version>", "<Version xmlns='syncml:metinf'>");
667             meta = meta.replaceAll("<NextNonce>" , "<NextNonce xmlns='syncml:metinf'>");
668             meta = meta.replaceAll("<MaxMsgSize>", "<MaxMsgSize xmlns='syncml:metinf'>");
669             meta = meta.replaceAll("<MaxObjSize>", "<MaxObjSize xmlns='syncml:metinf'>");
670             meta = meta.replaceAll("<EMI>" , "<EMI xmlns='syncml:metinf'>");
671             meta = meta.replaceAll("<Mem>" , "<Mem xmlns='syncml:metinf'>");
672
673             s = a + 7;
674             response.append(meta).append("</Meta>");
675         }
676         return response.append(msg.substring(s, msg.length())).toString();
677     }
678
679     /**
680      * THIS METHOD IS USES ONLY FOR TEST!!!
681      * <p>Writes the given byte[] in a file with the given fileName.
682      * @param fileName the name of the file
683      * @param bytes the byte[] to write
684      */

685     private void writeBytesToFile(String JavaDoc fileName, byte[] bytes) {
686         try {
687             File file = new File(fileName);
688             FileOutputStream fOut = new FileOutputStream(file);
689             fOut.write(bytes);
690         } catch (FileNotFoundException ex) {
691         } catch (IOException ex) {
692         }
693
694     }
695 }
Popular Tags