找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 2916|回复: 10

[webOS开发] Service 的修改方法

[复制链接]
发表于 2009-7-25 17:56 | 显示全部楼层 |阅读模式
谢谢捧场6 J% `0 h0 v: ~7 t+ P! I" A
( U+ d# S7 H7 _0 i' D. G$ @9 w
[ 本帖最后由 mfly 于 2009-7-31 16:09 编辑 ]

评分

参与人数 1威望 +50 收起 理由
CyberVsQ + 50 谢谢分享

查看全部评分

回复

使用道具 举报

发表于 2009-7-25 20:59 | 显示全部楼层
支持!!!
回复 支持 反对

使用道具 举报

发表于 2009-7-26 01:04 | 显示全部楼层
谢谢分享
回复 支持 反对

使用道具 举报

发表于 2009-7-26 01:09 | 显示全部楼层
Services 這一个我还是似懂非懂.
回复 支持 反对

使用道具 举报

发表于 2009-7-26 22:17 | 显示全部楼层
用这个方法,结果出现这样,哪里不对呢?请指教,谢谢
  1. package com.palm.messagingrouter;. Q: l) W1 K; D: c/ [
  2. 8 y# [* j6 K, G* [; ?# q8 {3 l
  3. import Association.Many;
    1 U; j: O# C8 _2 R2 [
  4. import com.palm.oasis.util.ZoneLogger;7 V* U9 R) p2 o& x. U
  5. ) O$ F/ I1 n2 ~2 i1 ^( j, }/ V
  6. public class SmsMessageSegmentContainer extends MessageSegmentContainer
    # A  @" X* L& w3 v
  7.   implements MessagingRouterJsonConstants, MessagingRouterTilConstants
    0 A+ T( O- Q5 G9 V
  8. {
    ; P4 @. U- k& E5 p( m% e, ]( X
  9.   private static final long serialVersionUID = 1L;
    2 A0 w- E; L' `4 |* N; x
  10.   private String completeMsgString;
    - j1 S' e$ ^& w$ e' {% B1 c, ^
  11.   private String bodyEncoding;0 |3 R2 R* {0 Q7 i" U% U
  12.   protected static ZoneLogger logger;7 x; ]. i( Z; ?. k3 y0 b
  13.   Many segments;' H& C- g! t( T$ `! U
  14. & a5 |  e: F$ k8 B: n* g
  15.   public SmsMessageSegmentContainer()! ~( c6 Q- G6 j& R& }1 [
  16.   {/ U- [2 f& t# B
  17.   }6 H: s* p. k5 S6 e; o( g& U

  18. / H+ `1 M, }7 d- |' X: Q
  19.   public SmsMessageSegmentContainer(long messageId, int totalSegments, String bodyEncoding)
    5 }; M7 R8 f, {3 H0 ]* \! E
  20.   {
    5 e# f' R+ q( x% Y" `; C$ [3 e
  21.   }' c; ]9 |8 R% J1 |! y! t7 t# ~0 u
  22. $ x- e0 x1 C, j- D
  23.   SmsMessageSegmentContainer(String messageId, int totalSegments, String bodyEncoding)( f4 H0 L5 m$ m1 c8 r% n, h
  24.   {+ x7 Q. y5 W3 a1 }
  25.   }
    - s. C6 F/ [: H% @$ N

  26. 1 ]0 @8 m+ l. }6 l+ E. i/ A+ `% q
  27.   public String getBodyEncoding()
    / D/ u& Z0 K9 C2 u& f
  28.   {
    # n+ I$ Y2 c' w; i  o# Q0 D3 S
  29.     throw new Error("Unresolved compilation problem: \n");
    ! p; v  c, A6 x: R& y9 @
  30.   }
    3 [+ J. V) o) D2 {/ o
  31. 1 S; ^2 ^0 q5 R5 B
  32.   protected boolean isPrintableChar(char ch)$ R' f) G4 t" b; i# O
  33.   {. H4 P$ F% P8 d9 |1 I
  34.     throw new Error("Unresolved compilation problem: \n");
    $ r4 K! W% s/ f6 `( O6 ~
  35.   }. T! I  |- Z7 H/ `1 t3 J& j/ w

  36. 9 i8 w. w0 F$ Q5 Y" [) s7 A- D9 q
  37.   public boolean isMessageComplete()
      l7 J  s# X" D, K! T4 P0 K
  38.   {9 ^3 _5 D$ y3 `- S  N5 Q
  39.     throw new Error("Unresolved compilation problem: \n\tMany cannot be resolved to a type\n");/ k4 ?( }5 E! h! `
  40.   }& k. g: X! j, ]! ^, q9 B  e' P& \

  41. % n/ ~4 L7 B' Q: {. x
  42.   public String getCompletedBody(), Z% g+ c  ~1 G# _2 T
  43.   {
    1 r- e% Q  E' o% p+ K& \
  44.     throw new Error("Unresolved compilation problem: \n");
    4 C5 T: n  [; ]# Z/ Y
  45.   }
    9 v4 ?! D; ?" `' P' G" u5 E

  46.   H) m# \" f7 j; B
  47.   public void addNewSegment(SmsMessageFromTil msgSegment)' O: t% m& k: ~8 g# C
  48.   {
    - b! j* \( k7 }: K' y
  49.     throw new Error("Unresolved compilation problems: \n\tMany cannot be resolved to a type\n\tMany cannot be resolved to a type\n");" B9 [2 O1 W  ?, s0 W! A/ U6 I
  50.   }- X0 `' h* q) ?3 W% k+ r
  51. " ?0 F' _8 E" _7 _' Z. g7 ~; z
  52.   private String convertToJson(boolean doHidePrivateData)8 M+ w  F3 ~1 R( f
  53.   {
    , {/ R0 Q) b: m) d) W
  54.     throw new Error("Unresolved compilation problems: \n\tMany cannot be resolved to a type\n\tSyntax error on token ":", ; expected\n\tSyntax error, insert "AssignmentOperator Expression" to complete Assignment\n\tSyntax error, insert ";" to complete Statement\n\tString cannot be resolved\n\tjsonString cannot be resolved\n\tjsonString cannot be resolved\n\tjsonString cannot be resolved\n");+ I6 [# H5 W% X2 B" u3 h
  55.   }+ m# V, b& }8 {1 H/ r+ W

  56. % |! o  s6 X! g2 F
  57.   public String toJSONString()
    6 W9 Q9 D9 w- V+ F  N. W+ \+ E
  58.   {
    * `6 w8 n, j# H! f
  59.     throw new Error("Unresolved compilation problem: \n");
    / z' g: G0 i3 I4 Q
  60.   }
    " j& b* a1 e3 p4 o$ \' O, Y- [' h

  61. 5 x4 W3 S$ D) [  Z' s
  62.   public String toDebugJSONString()
    : ^' w4 S- U. L" P0 a" ^0 G
  63.   {; c8 Y% E! h+ n# L& z" v7 j& K7 ~
  64.     throw new Error("Unresolved compilation problem: \n");. D: b! O4 H+ Y0 P% q
  65.   }$ m$ H% |& Z, R% J
  66. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2009-7-26 22:23 | 显示全部楼层

原始代码是这样的

  1. package com.palm.messagingrouter;% {$ G4 R7 I0 E" E4 w: _
  2. : j8 v9 ^  k! h. M
  3. import com.palm.oasis.activerecord.ActiveRecord;
    3 |8 i2 }+ t2 E+ P
  4. import com.palm.oasis.activerecord.ActiveRecordException;! g9 ^$ w6 A" o6 T+ e8 n
  5. import com.palm.oasis.activerecord.Association.Many;+ L( ], y% t; W2 @0 F6 c8 \
  6. import com.palm.oasis.activerecord.Batch;
    0 t* s, j( q$ M* Q
  7. import com.palm.oasis.activerecord.SqlFind;0 c6 T: q! r' u/ ]* K9 t* A
  8. import com.palm.oasis.util.Base64;3 {# s2 |9 k- R+ R1 @* m
  9. import com.palm.oasis.util.ServiceLogger;
    2 Y% R% ?/ O( Q" `1 l  I
  10. import com.palm.oasis.util.ZoneLogger;+ B$ }) C- z& r. |
  11. import java.io.ByteArrayOutputStream;
    & u/ R2 f3 g# l  ?
  12. import java.io.IOException;& I/ R$ u4 K& U! L5 K" O, V0 |
  13. import java.io.PrintStream;
    9 r( {  y. d5 r1 \: E3 N
  14. import java.util.Iterator;
    ! Y9 e( L: k7 x8 b
  15. import java.util.List;
    + s8 s0 b, E+ S* J+ G8 W) I
  16. import org.json.JSONException;
    9 p/ H. u7 S9 {4 q
  17. import org.json.JSONObject;, K8 {- }5 j6 B8 s
  18. ( @2 k" h# H8 D1 n
  19. public class SmsMessageSegmentContainer extends MessageSegmentContainer9 c1 L) X1 X! ~8 `/ K
  20.   implements MessagingRouterJsonConstants, MessagingRouterTilConstants7 `& x/ V4 l; G4 L: t
  21. {
    6 t/ {* E3 @" k# a, ]
  22.   private static final long serialVersionUID = 1L;1 i2 M1 e0 J& ^7 u0 ]
  23.   private String completeMsgString;' i2 b) f; F$ e0 K  d( R  `1 d
  24.   private String bodyEncoding;* i/ n/ p) x4 k# |- t8 d
  25.   protected static ZoneLogger logger = MessagingRouterService.getLogger(SmsMessageSegmentContainer.class.getSimpleName());, e3 A# l1 H, }) w" c
  26.   Association.Many segments;. Y1 m( I' ~5 H& R( K

  27. # U/ Z8 n- k7 ?& w( {( ^( k8 x
  28.   public SmsMessageSegmentContainer()# D( u  }+ w/ U
  29.   {
    4 L  ], f- f% b- X9 n6 \' O
  30.     this.completeMsgString = null;
    4 B- @* ~# m- q
  31.     this.bodyEncoding = null;
    2 K; ^- l8 B* B( V/ f
  32.     this.segments = hasMany(SmsMessageFromTil.class, 1);  T$ ^, C* o4 l' y% Q- ^* n
  33.   }
    / o" `& b: w* }1 l  \

  34. 7 R1 g( z7 \: t) g! ]/ O2 I& R
  35.   public SmsMessageSegmentContainer(long messageId, int totalSegments, String bodyEncoding)
    , G$ B5 n1 ]* j# b) @" x
  36.   {" ?+ J- O% H. z1 O* o3 \
  37.     super(System.currentTimeMillis(), messageId, totalSegments);
    3 X& c2 J2 S+ f4 Q" f
  38.     this.completeMsgString = null;
    ; Y6 y' S% m, _+ s7 g; W8 ^
  39.     this.bodyEncoding = null;& Y. s5 J6 S/ V" ~+ M
  40.     this.segments = hasMany(SmsMessageFromTil.class, 1);1 b' n, \" `, g: j6 s1 ?
  41.     this.bodyEncoding = bodyEncoding;" `5 w2 M0 O( p  q% {! ~3 H! S
  42.   }2 r/ c7 A; J1 p3 C- }" ~  ?  `

  43. % o+ B7 G* ], i' h
  44.   SmsMessageSegmentContainer(String messageId, int totalSegments, String bodyEncoding)
    + r$ i) D( V& @! j3 r) r
  45.   {
    " O; T9 n& ~+ ~7 k/ N% @
  46.     super(System.currentTimeMillis(), Integer.parseInt(messageId), totalSegments);
    , {+ \, H+ f" F6 A+ U% p
  47.     this.completeMsgString = null;1 n3 S) x$ V, D* b
  48.     this.bodyEncoding = null;
    # K3 W3 Y8 a! m
  49.     this.segments = hasMany(SmsMessageFromTil.class, 1);8 g; [- ^  J2 ^1 [6 R4 n& e4 O" a
  50.     this.bodyEncoding = bodyEncoding;
    / B" B! w+ U& D2 f& G
  51.   }
    ) X  b9 g$ ^4 Y" S1 O  N

  52. " f  J; P3 _5 g  [- B
  53.   public String getBodyEncoding()2 Z/ ^- J4 [5 _2 g! d+ y1 n
  54.   {% ^  u2 b5 P& |; s) l1 `- j
  55.     return this.bodyEncoding;  |- C" h/ `& F4 n+ T8 j. V
  56.   }8 c& ]! H6 K( r6 y, J5 q3 |
  57. + x) r% R4 i- V) j2 F
  58.   protected boolean isPrintableChar(char ch)
    ( u0 R; i, y* u& p6 q) |% j" H( b
  59.   {
    ' K# n: ^9 x# N. T
  60.     boolean isItPrintableChar = false;8 d& f/ X" Q; U5 U0 w8 C. _4 b
  61.     if ((ch >= ' ') && (ch <= '~')) {, j$ R9 p. h. `- j" }( w/ O
  62.       isItPrintableChar = true;
    ( t! t( ]& a9 s- |/ H" P1 j6 l" m
  63.     }
    1 m# ^2 `) S" J. d1 M7 K: q
  64.     else if ((ch >= 128) && (ch <= 168)) {3 U( t; p% j4 S# t
  65.       isItPrintableChar = true;, {# ^5 E7 h5 X$ d
  66.     }
    - e, Z3 I7 M* t/ t" d4 F/ m  C
  67.     else if ((ch >= 224) && (ch <= 247))
    0 h0 W/ S5 b( X& m7 ^
  68.       isItPrintableChar = true;$ d; L- x; r! ]: u' Q2 `, X5 J
  69.     return isItPrintableChar;; A3 x( S1 I, x9 h
  70.   }- H1 U4 |1 C! V. Z" V

  71. 9 l4 Z7 ]4 b8 h
  72.   public boolean isMessageComplete()
    1 p7 \" y$ Y/ e- ?5 d' e$ D8 Z: u
  73.   {
    , U# ~4 }" B, d: m! x
  74.     if (!(this.isMessageComplete))
    ' g* ?, {) U' v6 ]0 h+ _- |
  75.       try
    ! E  l" u* }! s6 n0 g
  76.       {
    ( q3 y0 o- D& p; H
  77.         synchronized (SmsMessageSegmentContainer.class)
    + s3 v/ v) h( }2 I) y
  78.         {3 l' V' i- u5 E& L2 ^$ P9 y* ~7 ]
  79.           List listSmsSegments = ActiveRecord.find(this.segments.sqlAll().orderBy("segmentNumber ASC"));9 [# A- E, t4 g. l
  80.           if ((listSmsSegments != null) && (listSmsSegments.size() == this.totalSegments))
    ! b  m% a& M% ?
  81.           {* e6 f  h: N( E2 D6 ?
  82.             this.isMessageComplete = true;
    5 d3 l2 N* I  F( y; j1 m+ Y% W
  83.             logger.fine("At this point all SMS message segments have been recieved so we are going to put it all together");% T+ M- w' [8 |2 V0 ?
  84.             StringBuilder msgString = new StringBuilder(160 * this.totalSegments);$ P) f7 W6 K4 l3 K
  85.             if (msgString != null)9 q% M2 _" U. X+ d: A  ?2 ?" c
  86.             {
      Y) x! o% L' W- k" A+ I* D
  87.               if ("bbin".equals(this.bodyEncoding))
    6 A- b- p7 q. D" D
  88.               {
    5 ]) f+ Q5 Z+ F
  89.                 ByteArrayOutputStream byteOut = new ByteArrayOutputStream();6 F: C6 o* F: l0 O* a' `3 v" q9 d
  90.                 Iterator i$ = listSmsSegments.iterator();
    $ a7 F1 C6 r! s8 Z/ ^9 i6 p

  91. / i1 u1 C  U# b
  92.                 while (i$.hasNext())
    4 o* Y6 W" N. O& o# B& v" n7 T% k. p
  93.                 {
    + G" k; R; G& \) G" q2 @
  94.                   SmsMessageFromTil msg = (SmsMessageFromTil)i$.next();
      ]0 K7 b7 B" l: {. x9 l5 W) \( H
  95.                   if ((msg.getBody() != null) && (msg.getBody().length() != 0));! Y. h) }! s8 n0 d
  96.                   byteOut.write(Base64.decode(msg.getBody()));& ~9 U- c" @7 l3 K
  97.                 }( Y1 S9 {' }6 H  C$ s/ {
  98.                 char[] testArray = byteOut.toString().toCharArray();, J1 I6 {- t) d% K
  99.                 boolean isAllCharsPrintable = true;
    4 K2 K* B- u: n" L' s6 T
  100.                 int i = 0;
    & X( Z+ R" `: _( O; K* [
  101.                 for (i = 0; (i < testArray.length) && (isAllCharsPrintable); ++i) {% v1 e* O0 g- A
  102.                   if (!(isPrintableChar(testArray[i])))
    1 W' F7 u; d; E( h3 O
  103.                     isAllCharsPrintable = false;
    6 g& V$ X' S6 h, |, W
  104.                 }
    " O1 E4 B& o2 D# f5 F
  105.                 if (isAllCharsPrintable)
    : H: z' e& ?% H4 y3 E
  106.                   this.completeMsgString = byteOut.toString() + "";
    ) j3 i  Y2 D" b. e5 r* w
  107.                 else
    - e9 {0 v7 y) k  x
  108.                   this.completeMsgString = Base64.encodeBytes(byteOut.toByteArray()) + "";' Z' p" y: [* D+ i. x5 d  F
  109.                 System.out.println(this.completeMsgString);
    * Q. P3 U3 m4 I0 u
  110.               }
    / C; a' C6 h) S+ A& e& _
  111.               else {( A; ~! P  Z  f* T
  112.                 Iterator i$ = listSmsSegments.iterator();
    8 S/ r0 s# ]: b+ {
  113. 2 j& W4 a: @; l
  114.                 while (i$.hasNext())  J" X* c8 f4 v& U) ]1 D
  115.                 {
    & D; @9 S* F' F) e. L
  116.                   SmsMessageFromTil msg = (SmsMessageFromTil)i$.next();
    0 u0 e% ?: y1 U. R- ?2 {( x2 W
  117.                   if ((msg.getBody() != null) && (msg.getBody().length() != 0));
    6 J6 W, y; L* ]+ i9 s1 P- A9 y
  118.                   msgString.append(TilUtils.decodeString(msg.getBodyEncoding(), msg.getBody()));
    7 p5 Y! }3 L1 a; h' g# k
  119.                 }4 Y* b1 `; J, w
  120.                 this.completeMsgString = msgString.toString() + "";
    # [# R& k7 H- h8 l0 @& B7 c
  121.               }
    ; {9 L- X# z. R) U
  122.             }0 ]. N9 z# P1 k" B. v
  123.             else {* s9 [% n2 s, U) `6 q: T  Y
  124.               logger.severe("Error allocating memory to put Segmented SMS Message Together");
    3 k/ j% P, z6 b# H* _0 ?  r+ N
  125.             }
    5 o/ v4 |* b# b8 @  r( o0 j6 g4 K
  126.           }3 {: N* o; J: M( a  H9 j+ l
  127.           else if ((listSmsSegments != null) && (listSmsSegments.size() > this.totalSegments)) {5 Y, H# S! O2 y
  128.             logger.severe("Too many SMS message segments found so assuming corrupted for " + this.segMsgContainerId + " in DB.  We found:" + listSmsSegments.size() + " but we expected: " + this.totalSegments); }
    2 s( r0 ~+ X6 F! T  ^% |' L
  129.           listSmsSegments = null;3 ]+ @" b; q( j4 L$ t8 X
  130.         }$ s( `" S7 O% N4 a* O' B  z% ~
  131.       }) ?* s, A1 I2 M4 ^6 F
  132.       catch (ActiveRecordException e)
    ! {: C0 D8 i8 Y+ M% s& S; J
  133.       {
    ( |) u; l2 v1 v% Q& |2 p* t2 D
  134.         logger.warning("SMS Message couldn't be retrieved from the database at this time.");
    , ^/ n& W+ o) T" l1 l# I8 [5 r
  135.       }
    8 M" X% U$ y$ ^/ c& J8 D; ~
  136.       catch (NullPointerException e)
    ; ?- `( Q( u  d: p8 o# N& d* p
  137.       {
    & I" ]0 G& V4 a! {( E
  138.         logger.severe("Null Pointer Error putting Segmented SMS Message Together");
    1 n7 Y! V' T7 n6 ?( b
  139.       }9 C6 F7 j: N9 w
  140.       catch (IOException e)2 K' S/ P( s' Z$ c; X
  141.       {
    + _, _3 G& ^' Z7 Y/ m2 {" g) e
  142.         logger.severe("Error Decoding Binary Message");4 v0 @# E2 b# N; f# @# S
  143.       }3 ^, q1 P8 B) h: K: N
  144.     return this.isMessageComplete;
    + ]% d* x+ C9 q' r
  145.   }! V0 d0 b- R" o- V% ]4 r
  146. 0 J: p$ ^, I# \$ }8 J
  147.   public String getCompletedBody()
    : I: |6 T/ A- G# y) ]
  148.   {
    $ b4 P+ o* H, R+ _# N
  149.     if (!(isMessageComplete()))
    + X$ y- T' J" `8 `7 |' e$ ?. y* Z
  150.       logger.warning("Message Not yet Complete so you should call this after testing with isMessageComplete");7 a+ M8 r% P: e9 Q! D
  151.     return this.completeMsgString;
    5 ^' v) G2 ^7 [3 m9 B4 Q
  152.   }7 }2 S+ o8 G  Z. H/ O' W
  153. / J7 Y) m6 g: w: W& Q; v  E
  154.   public void addNewSegment(SmsMessageFromTil msgSegment)
    ) G8 M9 Z5 C& c$ \' o
  155.   {
    5 o& ^$ q1 @* X
  156.     try
    ! |: o: N: Z: f& K* W- l7 v
  157.     {" r" \3 h' R* r* O
  158.       if (logger.getLogger().isFinerLoggable)" ^! n- o# b" \6 j# W, b: X$ w
  159.         logger.finer("Attempting to Adding new SMS Message with MessageId:" + msgSegment.getMessageId() + " with SegmentNo:" + msgSegment.getSegmentNumber() + " of Total Segments:" + msgSegment.getTotalNumberOfSegments());# l6 T1 U, D3 T( n) J, B
  160.       synchronized (SmsMessageSegmentContainer.class)
    ( u3 r4 F! c; R5 p' ]2 N
  161.       {
    4 A2 ]  Z9 D2 @
  162.         int numSegmentsAlreadyStoredWithThatSegNumber = ActiveRecord.count(this.segments.sqlAll().where("segmentNumber=?", new Object[] { 4 j' ~4 ~7 U4 A1 ?
  163.           Integer.valueOf(msgSegment.getSegmentNumber()) }));4 T8 E6 C& \& P3 x$ o
  164. . G2 n6 }! N  G0 H: x3 j/ m7 Z% ~
  165.         if (numSegmentsAlreadyStoredWithThatSegNumber == 0)2 R+ E! N- q1 g; [
  166.         {
    ' x2 C6 s" s! Q- N! P4 s9 a
  167.           logger.finer("New SMS Segmeted Accepted.  Adding it to SMS Container");, X5 T: P' Q* v9 O
  168.           logger.finer("saving segment to message holder");% y9 u) d. b# s& m4 Y9 @6 H, @
  169.           Batch batch = new Batch();" c" L" a) k. T! [4 p- ~/ w: A' _* D
  170.           this.segments.push(batch, msgSegment);5 \# w2 h/ y& q' H% ]4 G6 j
  171.           msgSegment.save(batch);
    & `# X8 X( M0 }4 J  @
  172.           if (0L != msgSegment.getTimeStamp())0 T( C  ^0 L7 `7 \5 N
  173.             setTimeStampLastReceivedSegment(msgSegment.getTimeStamp());2 u1 j$ R( _5 @0 B7 q/ A9 P
  174.           save(batch);
    & K0 r; }+ r' p" v/ x( k, V) ?! |
  175.           batch.execute();( U" ~' k2 N( M: c/ k
  176.         }7 C6 @5 z! F4 ?5 Q# C
  177.         else {& @/ h8 e" j; d& A
  178.           logger.warning("Found duplicate SMS Message segment already saved");; x2 Q% P& H) I9 \$ l, {
  179.         }& z9 Q! Q  c$ N2 g5 Y( _- y
  180.       }
    . x, q- E3 k# p
  181.     }+ e6 N2 g, E3 M2 D! [
  182.     catch (ActiveRecordException e)& M- q) z' k, |: x5 Q$ i
  183.     {& [4 }) B) n* k( L5 P8 H$ d0 l
  184.       logger.severe("Error saving SMS Message Segment.  Data will probably be lost.");# W1 a" u+ D! m2 g6 M1 ~' W2 n
  185.     }+ I4 j, t0 L/ V" M
  186.   }
    + s0 C+ a8 C7 C, e9 l  @3 p; w* |$ n0 k

  187. / n" c; \% ]5 Z$ |$ P5 @7 U& d
  188.   private String convertToJson(boolean doHidePrivateData)& R2 ?. m- w* V+ c
  189.   {# C2 a, m* E  g; `# B* y
  190.     JSONObject smsJson = new JSONObject();) u) P( g6 C+ b" G; ^5 `
  191.     SmsMessageFromTil msgSeg = null;
    6 ~: `+ B; u, b- F* ]( C
  192.     try" v: r) D7 @) p. |0 O$ k- L+ J
  193.     {: s- g# l& t: m& d
  194.       msgSeg = (SmsMessageFromTil)this.segments.findFirst();; r9 G- C( p  L( O  ^; U
  195.       if (msgSeg != null). M& `' k- H8 ]- Y, x  |% r2 r1 W
  196.       {
    % }4 B! M% g! |* d' \) R( V5 _
  197.         if (doHidePrivateData)( U5 N. J: a9 \4 i
  198.         {5 O- [% U5 C+ m/ Q% T0 V- P: @
  199.           smsJson.put("body", "This has been hidden for logging");3 l  d8 o! S: X; z/ l5 C; I
  200.           smsJson.put("address", "555-333-4444");
    , C! o( ]# l- {; J+ j
  201.           smsJson.put("callbackNumber", "555-333-4444");8 h4 V9 U9 ?/ V) x
  202.         }
    8 B% L/ i  }9 v$ i
  203.         else {
      V* c9 }9 n8 t% t6 |
  204.           smsJson.put("body", getCompletedBody());5 a9 D9 C, S4 a7 v- }, A
  205.           smsJson.put("address", msgSeg.getWhoIsItFrom());3 z% A) h. U3 o5 ?+ v
  206.           smsJson.put("callbackNumber", msgSeg.getCallbackNumber());: J6 G1 j- d5 a+ i: V+ R8 e
  207.         }
    + G2 \, U$ U& f) V
  208.         smsJson.put("networkMsgId", msgSeg.getMessageId());
    1 L7 G. b& r$ G/ ?& I0 B
  209.         smsJson.put("deliveryReportOptions", msgSeg.getDeliveryReportOptions());
    $ n  I( N& r# F+ F+ A" d& y
  210.         smsJson.put("timeStamp", msgSeg.getTimeStamp());2 z2 Y7 L% u1 \1 i6 a1 h
  211.         if (msgSeg.isThisMessageFromAGsmNetwork())
    1 E3 V' I3 T: q# Y' q
  212.         {
    ) {5 B( R: z' |+ z3 z1 K
  213.           smsJson.put("priority", msgSeg.getSmsClassInfo());
    2 i4 V: M1 P! y: \& [$ C
  214.           if (msgSeg.isFromSim())
    - ~& n6 T5 r# c' o
  215.             smsJson.put("isFromSim", true);3 h  K( n/ ~/ I
  216.         }
    2 q. K/ L. T" O: R/ B; O9 J- m% g
  217.         else {
    : J- {. K+ r& v8 d4 l" [
  218.           smsJson.put("priority", msgSeg.getPriority());5 \% W' b0 k4 ^: s  q
  219.         }* O3 M. A5 B5 e6 f( D7 u% v
  220.         smsJson.put("displayMode", msgSeg.getDisplayMode());
    ( R$ w* |5 ?. F9 O9 Z: X
  221.         smsJson.put("privacyMode", msgSeg.getPrivacyMode()); break label257:+ n+ [" v, F7 a1 S
  222.       }7 r, @: N# _/ ?; W! O& A& @' W

  223. # N4 f, l- ?! n% n1 m
  224.       logger.severe("Did not find Message Segment to generate JSON string");: u$ n: h$ u& N; |! q0 V: W# d7 N
  225.     }4 |$ J; a! @( [% o0 G
  226.     catch (ActiveRecordException e)
    . W. [) w7 a# T
  227.     {0 s+ u4 z; v* R0 f
  228.       logger.severe("Caught Exception", e);
    * \  c& e# F: ?( U) [
  229.     }
    2 K" r) Z0 U2 f; G* e  A7 D: w
  230.     catch (JSONException e)5 _4 ?: d: e; U
  231.     {% K2 n4 P# g+ ^+ K+ x
  232.       logger.severe("Caught Exception", e);! `+ c1 N5 ]8 ^  x
  233.     }
    , U, i9 T7 l1 c. u
  234.     label257: String jsonString = smsJson.toString();* w3 W" Z2 O1 }7 n( D" ]% y
  235.     logger.finer("toJSONString SMS Message: " + jsonString);
    ) l! i, e1 f9 F) C
  236.     return jsonString;
    ) [+ ^  t( e5 h; m+ [: d2 X% Q
  237.   }8 r& P- V6 u2 `

  238. ! X7 [" k6 |! R: c
  239.   public String toJSONString()
    ) H  t1 @- x% C; p
  240.   {
    ! r, [( {1 \0 b0 n1 Z
  241.     return convertToJson(false);0 R, E' B* i6 `, k
  242.   }
    9 {, L1 u5 J. u4 r' D
  243. + C0 ~6 j# p5 W/ y3 l+ k. D. Y
  244.   public String toDebugJSONString()
    ( J  \* U% D' q* W4 a. H% Z
  245.   {% M/ E. ]; J" q; K  f- k
  246.     return convertToJson(true);
    7 W1 N) k, n! q9 k( P9 t0 p
  247.   }
    4 t! P' G# v' l3 W
  248. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2009-7-26 22:23 | 显示全部楼层

回复 楼主1# mfly 的帖子

我把palm的Jar也都加入Library了啊,咋回事呢?报了好多错哎
回复 支持 反对

使用道具 举报

发表于 2009-7-26 22:50 | 显示全部楼层

回复 楼主1# mfly 的帖子

是不是因为我加入的是1.1ROM里的jar的关系呢?跟1.0.4的参数对不上了
回复 支持 反对

使用道具 举报

发表于 2009-7-27 00:28 | 显示全部楼层

回复 楼主1# mfly 的帖子

我试了下,编译你的那个文件就ok,我编译的是SmsMessageSegmentContainer,不灵,估计是SmsMessageSegmentContainer里面的一些函数在library里找不到吧,如何才能编译这个文件成功呢?请指点一下,谢谢
回复 支持 反对

使用道具 举报

发表于 2009-7-27 21:24 | 显示全部楼层
eclipse啊~像我们这种穷人,只能用Emacs....
回复 支持 反对

使用道具 举报

发表于 2009-8-18 22:01 | 显示全部楼层
其它的代码有吗?我用jd-gui 0.2.7反编译出来好像有点问题啊。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

QQ|Archiver|手机版|小黑屋|吹友吧 ( 京ICP备05078561号 )

GMT+8, 2025-4-4 06:01 , Processed in 0.306795 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表