找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 2859|回复: 10

[webOS开发] Service 的修改方法

[复制链接]
发表于 2009-7-25 17:56 | 显示全部楼层 |阅读模式
谢谢捧场
( _+ q( y' U( ?$ `, a* a
! [0 _8 Y0 J& h6 D! s3 n[ 本帖最后由 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;
    . }' `7 E' ?- N  H0 r% V0 V
  2. - r8 q+ N% a8 p
  3. import Association.Many;% q$ E7 u* e! }4 w5 r  s! Y( t
  4. import com.palm.oasis.util.ZoneLogger;
    . f- T" e; |& w% J/ W. b$ \3 |
  5. : t  n4 Y. _$ b  E8 @4 I
  6. public class SmsMessageSegmentContainer extends MessageSegmentContainer
    4 p& F. z, {1 Q* ]5 \" L
  7.   implements MessagingRouterJsonConstants, MessagingRouterTilConstants
    # N0 {3 i& J! E# u' r4 T9 M
  8. {
    - k; G7 A( O! x9 p; V' l6 J: `1 L
  9.   private static final long serialVersionUID = 1L;! S* O4 B! ^: y2 O& E) J" ~
  10.   private String completeMsgString;
    " k$ S  H0 F: X( N+ R9 N, H
  11.   private String bodyEncoding;
    $ b) f; N. c$ _- i7 w& O/ M. B3 }
  12.   protected static ZoneLogger logger;
    5 f$ v1 e" Q1 k  M* M. O
  13.   Many segments;
    - q* C% G. S. Z5 H

  14. / L: ^$ M5 O$ _: L  j, k: ~
  15.   public SmsMessageSegmentContainer()
    ' B+ V6 c4 o, v- Z
  16.   {
    1 V/ L% G5 T- s" Y# r  b" M
  17.   }
    8 r/ H* g" h- E% z* r7 G, o

  18. . j  w: c; a* S+ y. V
  19.   public SmsMessageSegmentContainer(long messageId, int totalSegments, String bodyEncoding)8 t+ T# ?+ \  R
  20.   {
    8 {9 i" H3 J. C2 T% a
  21.   }" b# ^4 |9 B- t9 X0 m

  22. # k$ l9 |9 i# w! F, D
  23.   SmsMessageSegmentContainer(String messageId, int totalSegments, String bodyEncoding); `. x' o: B- A! ~( {
  24.   {7 h8 `& O" c  N$ B# o
  25.   }
    - w! p% }: @. j; s
  26. 8 R) {) e! `* b% Z
  27.   public String getBodyEncoding()
    0 @3 M# ~% W" M8 Z. ^. o3 ?
  28.   {
    4 c. o3 q9 [1 ?
  29.     throw new Error("Unresolved compilation problem: \n");
    + A8 C4 ^! [4 D* o& M' i" Z2 l
  30.   }& N7 e! b; v. p  Q. D* ^  l; n
  31. # v# X4 c+ D. h, K7 @
  32.   protected boolean isPrintableChar(char ch)
    : I8 K# G8 r5 `2 I/ b: J6 p4 u, T
  33.   {4 m0 ^# ?7 n1 y8 P
  34.     throw new Error("Unresolved compilation problem: \n");9 l8 c/ v# h  z, h6 P( [3 I' l) B; H
  35.   }
    + f) B# Z; R( A) N, U
  36. , t; h4 S$ Y# `4 x( e6 {
  37.   public boolean isMessageComplete()3 a3 h% ^2 s# t
  38.   {
    8 _; F+ _, u6 m& a  c" ?! x
  39.     throw new Error("Unresolved compilation problem: \n\tMany cannot be resolved to a type\n");7 \$ K. C, l6 A' V: i( H/ p1 S4 g
  40.   }
    ) C) G( }* I1 c3 U: \

  41. 5 [. @1 P0 q, k1 P3 _. W, }7 f
  42.   public String getCompletedBody()5 n& W) K: u" ?
  43.   {
    ) J) t3 \. W4 l
  44.     throw new Error("Unresolved compilation problem: \n");
    # `  n! Z% n  T+ m, g
  45.   }5 l4 a  [* s6 L$ {+ v- ]! O5 w/ e7 ]

  46. ' y2 o8 x7 n: m3 W
  47.   public void addNewSegment(SmsMessageFromTil msgSegment)/ z. T- K) K3 u+ ~2 |1 x
  48.   {9 J7 T+ q! {, b5 ^
  49.     throw new Error("Unresolved compilation problems: \n\tMany cannot be resolved to a type\n\tMany cannot be resolved to a type\n");" r% `* m8 V  y" d3 I' x2 @/ D6 \
  50.   }) s! @' z# v3 {) \% }
  51. 3 m( {9 O! M+ Y! S3 }7 _
  52.   private String convertToJson(boolean doHidePrivateData)
    $ k# {" I9 W; m; ]& o# `5 Z' R3 V
  53.   {
      G) }9 @% N6 @1 `# u6 h
  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");0 |! [0 \9 q2 d1 ]5 T! h
  55.   }, J2 p8 D' B0 `% |( ]
  56. + _6 F3 Q! j$ x! a3 P
  57.   public String toJSONString()2 l3 Q$ V) M+ f$ S# \
  58.   {0 Y2 B# c1 J4 k( v+ c: w4 t
  59.     throw new Error("Unresolved compilation problem: \n");
    : Z/ D7 V  X2 ^, l2 V) C
  60.   }( B5 [& U1 h& f) t3 `
  61. $ H9 p( P9 M* S9 D4 e9 h
  62.   public String toDebugJSONString()2 ]* Q7 [* f. Q! w
  63.   {
    / L  A8 ?7 R9 ~# Y) P* w5 ~
  64.     throw new Error("Unresolved compilation problem: \n");
    4 V. ^- r% P, s$ s: D
  65.   }' A& ~7 d( q5 Q9 g, }
  66. }
复制代码
回复 支持 反对

使用道具 举报

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

原始代码是这样的

  1. package com.palm.messagingrouter;
    5 A$ p4 L  ^; [, G) ]& z8 G

  2. & S! ~- v0 b7 s( d6 J2 g
  3. import com.palm.oasis.activerecord.ActiveRecord;3 l& ^4 }/ c; |/ {3 ^! C' j
  4. import com.palm.oasis.activerecord.ActiveRecordException;
    - r. g" L9 w% r  H; a; E- C
  5. import com.palm.oasis.activerecord.Association.Many;
    ) R4 X5 u/ w" V; f+ V
  6. import com.palm.oasis.activerecord.Batch;
    4 }2 ~: I4 x- t/ R; y  r
  7. import com.palm.oasis.activerecord.SqlFind;# V& h+ k5 N# l9 A9 l  E% u# W! W. @
  8. import com.palm.oasis.util.Base64;  }+ O- i* F9 Z7 c% K
  9. import com.palm.oasis.util.ServiceLogger;
      z! t3 x1 w9 N& r
  10. import com.palm.oasis.util.ZoneLogger;
    3 W8 o1 y  i7 f% O4 b7 `9 o( M
  11. import java.io.ByteArrayOutputStream;/ q9 e% V, }9 C6 t7 c
  12. import java.io.IOException;
    ) i4 o+ c8 Y! [
  13. import java.io.PrintStream;
    ( n7 z1 {/ o! B/ n  Q* V
  14. import java.util.Iterator;
    1 p0 W. g$ `" |) n- }, ~- A- [
  15. import java.util.List;8 j1 @# `* l+ w4 N+ Q
  16. import org.json.JSONException;
    . Y% P. I8 u8 i+ U) _
  17. import org.json.JSONObject;; l. N# V! j! O, C" x# o
  18. ! }* F; _1 S8 m% Q
  19. public class SmsMessageSegmentContainer extends MessageSegmentContainer
    " Z8 @- D" U+ }8 n0 j' l3 J
  20.   implements MessagingRouterJsonConstants, MessagingRouterTilConstants
    9 Q( c, F! I8 B
  21. {: `" D' w# H) \" d6 x6 i3 y6 b
  22.   private static final long serialVersionUID = 1L;
    8 Y3 q/ {) A# k  N
  23.   private String completeMsgString;
    0 A! W5 [# f: v
  24.   private String bodyEncoding;
    " @" u, O: [1 G- i, H
  25.   protected static ZoneLogger logger = MessagingRouterService.getLogger(SmsMessageSegmentContainer.class.getSimpleName());
      |' `7 w, H6 P* ~* c! i  Z( T
  26.   Association.Many segments;
    * K) f2 E9 \) E: f. i/ R/ ]
  27. ( |1 G+ B, U2 S) J
  28.   public SmsMessageSegmentContainer()
    % t0 i+ z' R7 d
  29.   {" W' B4 J2 f: v5 |! Z* e3 a
  30.     this.completeMsgString = null;
    % t7 h$ R9 O3 h! @
  31.     this.bodyEncoding = null;% Z* `) N1 u% v1 z
  32.     this.segments = hasMany(SmsMessageFromTil.class, 1);+ t+ p8 a; E! n
  33.   }
    1 h1 _6 g, p1 R; v$ \
  34. - ^4 c. P2 L" y3 v2 T
  35.   public SmsMessageSegmentContainer(long messageId, int totalSegments, String bodyEncoding)0 G% E; @2 H# V: e7 O  M0 k1 R
  36.   {
    # u& r4 g; T( g# ~, P
  37.     super(System.currentTimeMillis(), messageId, totalSegments);
    ( \" W0 b" {- N: e6 Q0 l- ]
  38.     this.completeMsgString = null;1 s* Q( \- J" m$ L  j7 V/ p& w
  39.     this.bodyEncoding = null;
    8 F$ Q+ l, o& g$ q0 n
  40.     this.segments = hasMany(SmsMessageFromTil.class, 1);9 R6 y" U# p( P9 i
  41.     this.bodyEncoding = bodyEncoding;
    ! w* H$ W6 y+ E+ r
  42.   }
    5 Q0 ]0 W3 R* G* l& K1 x
  43. 4 H% F$ x4 }7 Y9 {( T
  44.   SmsMessageSegmentContainer(String messageId, int totalSegments, String bodyEncoding)
    9 A3 o: @1 C4 z2 u
  45.   {4 b8 m: R8 p, D( B" `
  46.     super(System.currentTimeMillis(), Integer.parseInt(messageId), totalSegments);! |0 b- _9 [; ]- ?
  47.     this.completeMsgString = null;7 k0 }3 b& ]7 Y0 f4 I( h
  48.     this.bodyEncoding = null;
    % A. @0 p( y* \* M; c
  49.     this.segments = hasMany(SmsMessageFromTil.class, 1);
    # F2 A2 t8 o! t, b2 _9 u
  50.     this.bodyEncoding = bodyEncoding;
    & d/ x, h# Z' t5 x+ S9 [# K( r
  51.   }- N. j( l8 M: B! u% S: u& Y. u; {

  52. ' e6 u; _5 X6 U, I
  53.   public String getBodyEncoding()
    6 `; ~2 h9 h: F8 B4 D) q
  54.   {
    ( C" F1 H; n0 N4 L2 L) i2 y# g2 s
  55.     return this.bodyEncoding;$ ?7 h3 R$ O+ _; a& j" ^' J
  56.   }
    . Z9 T& B9 {! `' l9 L5 Q
  57. ' C  p& d: C+ K; P
  58.   protected boolean isPrintableChar(char ch)
    + Q# I) D, }5 h  A
  59.   {
    6 r! I. p+ }* j2 M
  60.     boolean isItPrintableChar = false;  [5 E$ y3 K5 x0 h, G
  61.     if ((ch >= ' ') && (ch <= '~')) {! T2 X! M8 K/ X2 b& _
  62.       isItPrintableChar = true;
    ! z. V  a; w& T: b
  63.     }4 |* d; E) X: O8 @1 v6 ?
  64.     else if ((ch >= 128) && (ch <= 168)) {6 y! h! [! v. r( `( `
  65.       isItPrintableChar = true;
    % b4 J8 j6 q0 C$ Y) n
  66.     }% r2 f8 R- J6 }4 y4 H7 k( ?! k
  67.     else if ((ch >= 224) && (ch <= 247))6 ?- ]5 X0 d" Z4 z. ^$ N7 f  [. b8 l
  68.       isItPrintableChar = true;
    / m/ @+ B* e; O5 K$ \  K
  69.     return isItPrintableChar;
    ! }5 L( x0 x8 |: q
  70.   }
    0 S6 r, z/ K, |

  71. ! o0 [- p% V; s# f' s+ J1 k
  72.   public boolean isMessageComplete(): o9 Z8 g% [* `3 Y' P; P
  73.   {
    7 o) v! ~( W2 O' @+ x
  74.     if (!(this.isMessageComplete))
    ( a6 x. p  S: Q% S4 q6 P' N
  75.       try
    ' u; Z$ W* n/ r# \$ J
  76.       {1 Y1 B* P+ x; e
  77.         synchronized (SmsMessageSegmentContainer.class)) F) S/ j; c1 [, B( ^- K, E
  78.         {
    3 _2 }6 m. L" C- @! {
  79.           List listSmsSegments = ActiveRecord.find(this.segments.sqlAll().orderBy("segmentNumber ASC"));& f2 k/ ~& u: X8 j6 G
  80.           if ((listSmsSegments != null) && (listSmsSegments.size() == this.totalSegments))
    ' c. N8 Z- |- [
  81.           {" _& \# z$ m3 r0 ^8 F: s
  82.             this.isMessageComplete = true;
    # ]9 i: U; Q' j; D7 m5 z" }
  83.             logger.fine("At this point all SMS message segments have been recieved so we are going to put it all together");- x; \( Y; v! p- A+ T7 p+ D/ t
  84.             StringBuilder msgString = new StringBuilder(160 * this.totalSegments);
    ; W8 `; R& ]$ m0 t, i
  85.             if (msgString != null)6 `1 u' x0 \/ K- T
  86.             {8 v& _( y4 _& O% o0 u& j9 u% U% G% _
  87.               if ("bbin".equals(this.bodyEncoding))
    - x- ?9 \  L$ k! R- b( I
  88.               {4 _" M- P4 U6 N% f
  89.                 ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    , b: v& Y% m3 U  g  T6 p
  90.                 Iterator i$ = listSmsSegments.iterator();
    * m) g* j( D7 |/ G' A
  91. " n& }6 O1 n/ I' Z8 j2 h
  92.                 while (i$.hasNext()), V. L4 ~& Q. [% {4 I! f7 W
  93.                 {
    6 l) S& u, k- A3 g6 c
  94.                   SmsMessageFromTil msg = (SmsMessageFromTil)i$.next();
    # j) j1 D+ i9 q- O- P$ t3 Q* m
  95.                   if ((msg.getBody() != null) && (msg.getBody().length() != 0));
    1 q7 J$ e* f3 S9 B' d3 |
  96.                   byteOut.write(Base64.decode(msg.getBody()));
    % U4 C6 T  r0 U  K% d
  97.                 }
      _2 }$ y/ x) I0 e7 {* ]- V( c* P" G
  98.                 char[] testArray = byteOut.toString().toCharArray();
    * X( g' H! Q# t. G/ Y3 Q- o
  99.                 boolean isAllCharsPrintable = true;  }4 P: l. r, {- D+ X  B; E
  100.                 int i = 0;
    * l0 v  O- O$ O; a# C1 A
  101.                 for (i = 0; (i < testArray.length) && (isAllCharsPrintable); ++i) {6 g, ~7 L7 A% Q5 R
  102.                   if (!(isPrintableChar(testArray[i])))
    % M2 c- O- d0 Q7 H, U7 J
  103.                     isAllCharsPrintable = false;# Y+ w5 U( O" z( ^/ _5 x5 E
  104.                 }  E* t- D$ X2 T/ f' m" E' |3 Y
  105.                 if (isAllCharsPrintable)
    $ M& b% ~( V" K" x: ]- H
  106.                   this.completeMsgString = byteOut.toString() + "";+ A* s) C7 O2 J5 l! `
  107.                 else9 z# W" D. T4 }2 }/ m% F5 i" V
  108.                   this.completeMsgString = Base64.encodeBytes(byteOut.toByteArray()) + "";
    " E! _4 w' N& E2 b# f$ t) M  U# u+ {$ |
  109.                 System.out.println(this.completeMsgString);
    9 M2 m' o! e! _; Q
  110.               }
    ( j6 G% A, }$ F& [% R5 D0 Z
  111.               else {( @  d, p6 h4 U! v7 `2 p" x
  112.                 Iterator i$ = listSmsSegments.iterator();: ]/ S  M8 |+ x5 ?- C0 C9 |4 N& v

  113. " o% [; {: A' I% f* G3 T
  114.                 while (i$.hasNext())3 t. P5 p& }6 n$ _6 Z  v) _/ \
  115.                 {
    ) E$ C" @( W: V! E; ?( ]
  116.                   SmsMessageFromTil msg = (SmsMessageFromTil)i$.next();
    8 W% m% G4 B+ y1 W* Q
  117.                   if ((msg.getBody() != null) && (msg.getBody().length() != 0));4 d4 n- J% f# Y" |* p
  118.                   msgString.append(TilUtils.decodeString(msg.getBodyEncoding(), msg.getBody()));: Z) b0 L4 M9 W) a0 j7 K. q' h8 L
  119.                 }) o$ `: R& z* I
  120.                 this.completeMsgString = msgString.toString() + "";5 v9 Z7 f. ~  v# m: a6 v6 r" M
  121.               }
    & x( I/ \( Y+ }7 x
  122.             }1 ]) X( k$ |% T) Z4 g
  123.             else {
    ' t# C+ n$ ]' u  d  q
  124.               logger.severe("Error allocating memory to put Segmented SMS Message Together");
    ! |6 L$ G. N+ F  C+ X0 J
  125.             }8 n% J$ q6 S* ~4 v9 I0 D+ Y
  126.           }
    " ~* A' A6 v, Y/ m. _* h# ?
  127.           else if ((listSmsSegments != null) && (listSmsSegments.size() > this.totalSegments)) {9 i2 J$ `8 w: o& k3 H
  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 Z; _" p  j9 y& B3 J
  129.           listSmsSegments = null;9 q, {- E0 k4 a5 d3 @
  130.         }
    8 n, a  o1 ~! t. e$ N3 H
  131.       }
    - A7 e* F- g: m$ D. K1 U3 m
  132.       catch (ActiveRecordException e). `- O1 O. g' z# r+ t: l
  133.       {
    # k# Y, H9 [* l; e7 i
  134.         logger.warning("SMS Message couldn't be retrieved from the database at this time.");* u* {. \7 n. B/ V1 u& Y- v4 p5 s
  135.       }' \/ {  X1 R  _
  136.       catch (NullPointerException e): V( }0 S; ]6 Y$ j+ y4 H
  137.       {$ o, b% w" I9 I- @4 z
  138.         logger.severe("Null Pointer Error putting Segmented SMS Message Together");
    ( v: s, f5 L: H
  139.       }
    5 S6 W6 V6 H/ o' Z2 C2 ?9 ^
  140.       catch (IOException e)" g; `4 ?( m- o; j
  141.       {
    6 P$ V! `0 g- }% J8 t* D( ]  a, e
  142.         logger.severe("Error Decoding Binary Message");; `4 b3 _9 l5 j+ W/ Q* @3 L( Y
  143.       }
      w+ ~4 E1 j( [! n2 w
  144.     return this.isMessageComplete;
    * V- \( _( D( v0 e
  145.   }
    , A. D& c. n. F+ ]  v$ B
  146. 3 i' t& l  e1 ]( M
  147.   public String getCompletedBody()+ U7 ~+ o: o; D+ K( ^( W
  148.   {/ {  u8 Y- N. h0 y* @% o3 P
  149.     if (!(isMessageComplete()))) m3 U* Q# u* @! \( p
  150.       logger.warning("Message Not yet Complete so you should call this after testing with isMessageComplete");
    ) J: z2 j& D. w2 A( x7 q
  151.     return this.completeMsgString;
    2 g% K/ w( M: g" t1 M
  152.   }& V" q$ l2 b8 ?3 F$ N
  153. 4 y  {  Z: ?- H2 {/ R- I
  154.   public void addNewSegment(SmsMessageFromTil msgSegment), p. ?% }5 }% |) ]
  155.   {
    6 P! E/ q/ p- r6 W; ]/ r( d
  156.     try2 ^: H3 E4 g# D( `* [
  157.     {
    ) A" M9 N) `& h: G8 V0 i
  158.       if (logger.getLogger().isFinerLoggable)3 j1 k0 i8 O8 m% Q0 o+ G  k
  159.         logger.finer("Attempting to Adding new SMS Message with MessageId:" + msgSegment.getMessageId() + " with SegmentNo:" + msgSegment.getSegmentNumber() + " of Total Segments:" + msgSegment.getTotalNumberOfSegments());1 A8 E0 e9 x2 T: x  x
  160.       synchronized (SmsMessageSegmentContainer.class)5 K  X. g; L3 z3 u8 t; `" G
  161.       {. {: I8 E( a  D
  162.         int numSegmentsAlreadyStoredWithThatSegNumber = ActiveRecord.count(this.segments.sqlAll().where("segmentNumber=?", new Object[] { # J  |3 Q, f/ q- t
  163.           Integer.valueOf(msgSegment.getSegmentNumber()) }));
    ) L* g% D) U; c' A( |: B
  164. 4 c2 n3 G8 i; b& S# p
  165.         if (numSegmentsAlreadyStoredWithThatSegNumber == 0)" R1 M: h4 N" |2 R6 w& _$ |% G
  166.         {( N3 g* S, A9 [
  167.           logger.finer("New SMS Segmeted Accepted.  Adding it to SMS Container");
    ( ~- D# P/ [  |3 Y( C
  168.           logger.finer("saving segment to message holder");
    1 R6 M4 p" D: S
  169.           Batch batch = new Batch();# O; y( \9 Z& z/ `4 D( O3 a* Z
  170.           this.segments.push(batch, msgSegment);8 }; q7 G7 p( Q; K1 B
  171.           msgSegment.save(batch);- L, x5 j" C( H6 \& a# \3 \4 C
  172.           if (0L != msgSegment.getTimeStamp())% C+ u0 c0 [* m$ T
  173.             setTimeStampLastReceivedSegment(msgSegment.getTimeStamp());" z; i6 D, w2 v( j# m+ J! v9 I
  174.           save(batch);
    6 h  m2 u9 o( c1 _# _" D! j. y
  175.           batch.execute();
      T- u$ n6 Q; e3 t/ R
  176.         }1 \/ i. s, S, z. b
  177.         else {
    ! T* _6 j) E' E$ ^" y! v$ v
  178.           logger.warning("Found duplicate SMS Message segment already saved");
    7 C1 ~' J: E4 X0 ~+ y  G" B; Q9 B: v4 U
  179.         }- b" t5 m9 {+ k. i' X/ \
  180.       }( }5 O+ n0 O* h+ O$ Y
  181.     }8 v6 r6 i. [6 q! W9 f$ T  M
  182.     catch (ActiveRecordException e)% c2 |: {+ m9 F& W- L2 s) I- E% F
  183.     {) Z1 _: G( p0 S2 m2 p) f
  184.       logger.severe("Error saving SMS Message Segment.  Data will probably be lost.");' C* O4 U1 }, n  L
  185.     }
    # H% ~- Q, I* A: n, U) c
  186.   }
    , r" Z3 H# @9 ]

  187. + K7 D8 g2 a" X: I# T1 A
  188.   private String convertToJson(boolean doHidePrivateData)# f5 [& l# u# w! o+ K: J7 R
  189.   {
    . R% e* d; z  l2 h0 l" ~
  190.     JSONObject smsJson = new JSONObject();
    ! h; E. t$ X' Z2 F8 z' R& I& A2 L
  191.     SmsMessageFromTil msgSeg = null;! O% K+ u) U7 y: [' x
  192.     try
    ( R+ F" `) G; c7 u( U
  193.     {+ ?0 d* [- ~% I2 b$ I8 ~* P
  194.       msgSeg = (SmsMessageFromTil)this.segments.findFirst();
    ' q* d7 B+ H" Q* t" D  E
  195.       if (msgSeg != null)
    8 Z5 l, D/ n+ T# j" @
  196.       {
    # m5 |& w, n4 S$ A) r$ G
  197.         if (doHidePrivateData)
    + @6 M0 Q1 x, t  o' j0 v9 J1 w/ T
  198.         {
    4 I5 l& M. y0 ^5 [. U! Y$ d8 B
  199.           smsJson.put("body", "This has been hidden for logging");
    5 n9 s$ p2 o% p6 |
  200.           smsJson.put("address", "555-333-4444");
    5 ]/ y/ r! X# I, @5 ?% O2 C7 \/ A
  201.           smsJson.put("callbackNumber", "555-333-4444");
    ! b! U+ @8 G# \/ f  k/ H
  202.         }7 g( m; ]7 R$ R0 G3 J% R  \
  203.         else {! p2 e3 z0 e, n, c* i# r
  204.           smsJson.put("body", getCompletedBody());
    - i5 R- [4 V6 |& ~" B# {
  205.           smsJson.put("address", msgSeg.getWhoIsItFrom());& q# p2 T! {/ T  z/ n5 [& p% Z# H& P( P
  206.           smsJson.put("callbackNumber", msgSeg.getCallbackNumber());
    1 |4 ]6 K) i& _
  207.         }: P$ K6 m& y& Q. d! m# ~
  208.         smsJson.put("networkMsgId", msgSeg.getMessageId());
    ) T- H2 H, q4 I1 m8 \
  209.         smsJson.put("deliveryReportOptions", msgSeg.getDeliveryReportOptions());
    % M# u2 m) @- f$ Q/ j  b* P# X
  210.         smsJson.put("timeStamp", msgSeg.getTimeStamp());0 ?/ i8 J5 A0 J7 T2 e2 E/ v
  211.         if (msgSeg.isThisMessageFromAGsmNetwork())# W4 W$ |: z7 n7 t/ o* n* J$ M6 O) ]
  212.         {  T/ H5 A4 P5 T0 _0 Z
  213.           smsJson.put("priority", msgSeg.getSmsClassInfo());
    0 R3 X! S2 [% d4 j# e# H: g
  214.           if (msgSeg.isFromSim())
    6 C- Z6 |! f2 L- S3 Q- B
  215.             smsJson.put("isFromSim", true);# H7 {6 o1 |8 X
  216.         }2 I( E5 O1 w' ^1 i( `% i
  217.         else {
    , A) v* J- X! A9 P
  218.           smsJson.put("priority", msgSeg.getPriority());
    - w' m# N( K) ]5 Y) r4 z
  219.         }
    7 n5 Z& J7 g/ ?4 k' X- Q* I
  220.         smsJson.put("displayMode", msgSeg.getDisplayMode());
    $ @$ a. x% e/ N
  221.         smsJson.put("privacyMode", msgSeg.getPrivacyMode()); break label257:0 g5 p9 k) x- B" X1 G! Z3 s: ]
  222.       }7 i: Y$ |4 K7 e; B& O9 _2 Z

  223. 2 g# B! Z" q2 E
  224.       logger.severe("Did not find Message Segment to generate JSON string");
    1 W2 q4 s. N  E; v
  225.     }
    + h4 f) [! J% g
  226.     catch (ActiveRecordException e), Z$ G4 ~3 W9 }( P' S( ?1 W
  227.     {
    + [4 ~* n+ U; M4 A* }
  228.       logger.severe("Caught Exception", e);& @* c- X8 C3 T9 P! F) ?0 j
  229.     }
      C2 A( U7 I0 R* a- q( N. K
  230.     catch (JSONException e)
    $ Q7 X( e0 ~& C' r3 S/ v# ?$ a4 K" Q
  231.     {
    , ]) P0 S4 X! Y* q5 y6 W5 H
  232.       logger.severe("Caught Exception", e);
    4 b% c; m" j" C8 Z2 B
  233.     }; [) J; A) s* P, W* g
  234.     label257: String jsonString = smsJson.toString();
    ( L1 J: a2 P* k, V2 C: K! L% N% u1 j
  235.     logger.finer("toJSONString SMS Message: " + jsonString);
    ( A  I( ~- T4 {& e# x* a
  236.     return jsonString;
    / c+ g1 ^2 T8 e9 E( \
  237.   }, w- f; ^' @! D

  238. 6 d9 F$ A9 i; h: ]
  239.   public String toJSONString()5 N$ L+ c# d! H3 S9 K1 o& k! G' I# n
  240.   {
    2 w3 j8 _' v# d( P$ ~
  241.     return convertToJson(false);# Y7 n$ [  }/ u" t3 i
  242.   }1 L4 _6 o: U3 T8 \7 s" t

  243.   Y) y. ~" e* F: M
  244.   public String toDebugJSONString()0 P% L$ H( }: y$ d: m
  245.   {
    - a( J, ?7 N9 v3 D3 U
  246.     return convertToJson(true);  a1 P, ^1 {8 c
  247.   }
    4 k5 e6 C, K/ b, k; N( n
  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-2-23 17:35 , Processed in 0.351087 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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