| 1 |
/* |
| 2 |
* Copyright 2005-2008 The Portal Application Laboratory Team. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
package jp.sf.pal.blog.util; |
| 17 |
|
| 18 |
import java.util.StringTokenizer; |
| 19 |
|
| 20 |
import jp.sf.pal.blog.BlogConstants; |
| 21 |
|
| 22 |
import org.apache.commons.logging.Log; |
| 23 |
import org.apache.commons.logging.LogFactory; |
| 24 |
|
| 25 |
public class BlogMessagingKeyToken { |
| 26 |
/** |
| 27 |
* Logger for this class |
| 28 |
*/ |
| 29 |
private static final Log log = LogFactory |
| 30 |
.getLog(BlogMessagingKeyToken.class); |
| 31 |
|
| 32 |
private String prefix; |
| 33 |
|
| 34 |
private String owner; |
| 35 |
|
| 36 |
public BlogMessagingKeyToken() { |
| 37 |
this.prefix = null; |
| 38 |
this.owner = null; |
| 39 |
} |
| 40 |
|
| 41 |
public BlogMessagingKeyToken(String key) { |
| 42 |
this(); |
| 43 |
set(key); |
| 44 |
} |
| 45 |
|
| 46 |
protected String get() { |
| 47 |
if(log.isDebugEnabled()) { |
| 48 |
log.debug("get() - start"); |
| 49 |
} |
| 50 |
String keyToken = null; |
| 51 |
StringBuffer sb = new StringBuffer(); |
| 52 |
if (this.prefix != null) { |
| 53 |
sb.append(this.prefix); |
| 54 |
} |
| 55 |
if (this.owner != null) { |
| 56 |
sb.append(BlogConstants.BLOG_MESSAGING_TOKEN_SEPARATOR); |
| 57 |
sb.append(this.owner); |
| 58 |
} |
| 59 |
if (sb.length() > 0) { |
| 60 |
keyToken = sb.toString(); |
| 61 |
} |
| 62 |
if(log.isDebugEnabled()) { |
| 63 |
log.debug("get() - : value=" + keyToken); |
| 64 |
} |
| 65 |
if(log.isDebugEnabled()) { |
| 66 |
log.debug("get() - end"); |
| 67 |
} |
| 68 |
return keyToken; |
| 69 |
} |
| 70 |
|
| 71 |
public String getPrefix() { |
| 72 |
return this.prefix; |
| 73 |
} |
| 74 |
|
| 75 |
public String getOwner() { |
| 76 |
return this.owner; |
| 77 |
} |
| 78 |
|
| 79 |
protected void set(String key) { |
| 80 |
if(log.isDebugEnabled()) { |
| 81 |
log.debug("set(String) - start"); |
| 82 |
} |
| 83 |
if(log.isDebugEnabled()) { |
| 84 |
log.debug("set(String) - : key=" + key); |
| 85 |
} |
| 86 |
StringTokenizer st = new StringTokenizer(key, |
| 87 |
BlogConstants.BLOG_MESSAGING_TOKEN_SEPARATOR); |
| 88 |
if (st.hasMoreTokens()) { |
| 89 |
this.prefix = st.nextToken(); |
| 90 |
} |
| 91 |
if (st.hasMoreTokens()) { |
| 92 |
this.owner = st.nextToken(); |
| 93 |
} |
| 94 |
if(log.isDebugEnabled()) { |
| 95 |
log.debug("set(String) - end"); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
public void setPrefix(String prefix) { |
| 100 |
this.prefix = prefix; |
| 101 |
} |
| 102 |
|
| 103 |
public void setOwner(String owner) { |
| 104 |
this.owner = owner; |
| 105 |
} |
| 106 |
|
| 107 |
public String toString() { |
| 108 |
if(log.isDebugEnabled()) { |
| 109 |
log.debug("toString() - start"); |
| 110 |
} |
| 111 |
String key = get(); |
| 112 |
if(log.isDebugEnabled()) { |
| 113 |
log.debug("toString() - end"); |
| 114 |
} |
| 115 |
return key; |
| 116 |
} |
| 117 |
} |