use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class ImageHandler method hasImage.
public boolean hasImage(ICaller caller) {
IImageProvider provider = null;
IAttribute cm_att = caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
if (cm_att != null && cm_att.getValue().length() > 0) {
provider = (IImageProvider) this.m_providers.get(cm_att.getValue());
if (provider != null) {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Using IImageProvider <" + provider.getID() + "> for existance check.");
boolean isForceImage = Boolean.parseBoolean(System.getProperty(IJAMConst.SYSTEM_UI_FORCEIMAGE, "false"));
if (isForceImage) {
if (provider.hasImage(caller))
return true;
} else {
return provider.hasImage(caller);
}
}
}
return this.hasImageDefault(caller);
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class Serializer method toString.
private static String toString(ICaller caller, boolean includeImage) throws SerializerException {
if (caller instanceof IMultiPhoneCaller) {
return toString((IMultiPhoneCaller) caller, includeImage);
}
StringBuffer serialized = new StringBuffer(128);
try {
// add int area code
serialized.append(encode((caller.getPhoneNumber().getIntAreaCode().length() == 0 ? BLANK : caller.getPhoneNumber().getIntAreaCode())));
serialized.append(m_token);
// add area code
serialized.append(encode((caller.getPhoneNumber().getAreaCode().length() == 0 ? BLANK : caller.getPhoneNumber().getAreaCode())));
serialized.append(m_token);
// add call number
serialized.append(encode((caller.getPhoneNumber().getCallNumber().length() == 0 ? BLANK : caller.getPhoneNumber().getCallNumber())));
serialized.append(m_token);
// add firstname
serialized.append(encode((caller.getName().getFirstname().length() == 0 ? BLANK : caller.getName().getFirstname())));
serialized.append(m_token);
// add lastname
serialized.append(encode((caller.getName().getLastname().length() == 0 ? BLANK : caller.getName().getLastname())));
serialized.append(m_token);
// add additional
serialized.append(encode((caller.getName().getAdditional().length() == 0 ? BLANK : caller.getName().getAdditional())));
serialized.append(m_token);
// add caller UUID
serialized.append(encode((caller.getUUID().length() == 0 ? BLANK : caller.getUUID())));
serialized.append(m_token);
// add attributes
IAttributeMap al = caller.getAttributes();
if (al.size() == 0)
serialized.append(BLANK);
Iterator i = al.iterator();
IAttribute att = null;
while (i.hasNext()) {
att = (IAttribute) i.next();
serialized.append(encode(att.getName()));
serialized.append(EQUAL);
serialized.append(encodeAttributeValue(att.getValue()));
serialized.append(m_atoken);
}
} catch (Throwable t) {
throw new SerializerException(t.getMessage());
}
return serialized.toString();
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class Serializer method toCall.
/**
* Deserializes a byte array stream into an call object.
*
* @param call call as a byte array representation.
* @param runtime runtime to used
* @return call object
* @throws SerializerException
*/
public static ICall toCall(byte[] call, IRuntime runtime) throws SerializerException {
if (runtime == null)
throw new SerializerException("Runtime object is not set but required.");
String callString = new String(call);
if (callString.indexOf(m_ctoken) < 0)
throw new SerializerException("Call format is invalid. Call is set <" + callString + ">");
// tokenize the whole input
StringTokenizer st = new StringTokenizer(callString, m_ctoken);
if (st.countTokens() != 2)
throw new SerializerException("Call format is invalid. Found " + st.countTokens() + " tokens, but required are exactly 2.");
ICaller caller = toCaller(st.nextToken().getBytes(), runtime);
if (!st.hasMoreTokens())
throw new SerializerException("Call format is invalid. Second token is empty.");
// tokenize to call data
callString = st.nextToken();
st = new StringTokenizer(callString, m_token);
if (st.countTokens() < 7)
throw new SerializerException("Call format is invalid. Token count < 7.");
// build MSN
IMsn msn = runtime.getCallFactory().createMsn(// token 1
decode(st.nextToken().trim()), // token 2
decode(st.nextToken().trim()));
if (msn.getMSN().equalsIgnoreCase("*")) {
msn.setMSN("0");
}
// build CIP
ICip cip = runtime.getCallFactory().createCip(// token 3
decode(st.nextToken().trim()), // token 4
decode(st.nextToken().trim()));
// token 5
String uuid = decode(st.nextToken().trim());
// token 6
Date date = new Date(Long.parseLong(decode(st.nextToken().trim())));
// build attributes
String attString = decode(st.nextToken().trim());
IAttributeMap attList = runtime.getCallFactory().createAttributeMap();
if (attString.length() > 0) {
StringTokenizer ast = new StringTokenizer(attString, m_atoken);
String attrib = null;
while (ast.hasMoreTokens()) {
attrib = ast.nextToken().trim();
if (attrib.indexOf(EQUAL) > -1) {
IAttribute att = runtime.getCallFactory().createAttribute(decode(attrib.substring(0, attrib.indexOf(EQUAL))), decodeAttributeValue(attrib.substring(attrib.indexOf(EQUAL) + EQUAL.length())));
attList.add(att);
}
}
}
return runtime.getCallFactory().createCall(uuid, caller, msn, cip, date, attList);
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class Formatter method getParsedAttributes.
private String getParsedAttributes(String text, IAttributeMap attMap, boolean cleanup, boolean resolveCond) {
if (attMap == null || attMap.size() == 0)
return text;
// added 2010/09/26: render conditions
if (resolveCond)
text = this.resolveConditions(text, attMap);
IAttribute a = null;
String value = null;
Iterator i = attMap.iterator();
while (i.hasNext()) {
a = (IAttribute) i.next();
if (this.containString(text, IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_PREFIX + a.getName() + IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_POSTFIX)) {
value = a.getValue();
text = StringUtils.replaceString(text, IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_PREFIX + a.getName() + IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_POSTFIX, value);
text = this.cleanString(text.trim());
text = text.trim();
}
}
if (cleanup) {
// find unparsed tokens and remove them
String unparsedAttribute = null;
while (text.indexOf(IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_PREFIX) > -1) {
unparsedAttribute = text.substring(text.indexOf(IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_PREFIX), text.indexOf(IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_POSTFIX, text.indexOf(IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_PREFIX) + 1) + IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_POSTFIX.length());
text = StringUtils.replaceString(text, unparsedAttribute, "");
text = this.cleanString(text.trim());
text = text.trim();
}
// CRLF replacement
text = StringUtils.replaceString(text, IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_CRLF, IJAMConst.CRLF);
text = cleanString(text);
}
return text;
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class CommentCallerHandler method createComment.
private IComment createComment(File commentFile) {
IComment comment = new Comment();
String commentID = commentFile.getName();
commentID = commentID.substring(0, commentID.indexOf(this.getCommentFilenameExtension()));
comment.setID(commentID);
comment.setDate(new Date(commentFile.lastModified()));
try {
FileReader commentReader = new FileReader(commentFile);
BufferedReader bufReader = new BufferedReader(commentReader);
StringBuffer text = new StringBuffer();
while (bufReader.ready()) {
text.append(bufReader.readLine());
text.append(IJAMConst.CRLF);
}
bufReader.close();
commentReader.close();
comment.setText(text.substring(0));
} catch (FileNotFoundException ex) {
this.m_logger.warning("Cannot find comment file " + commentFile);
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + commentFile);
}
File commentAttributesFile = new File(commentFile.getAbsolutePath() + ".attributes");
if (commentAttributesFile.exists() && commentAttributesFile.isFile()) {
Properties commentAttributes = new Properties();
try {
FileInputStream in = new FileInputStream(commentAttributesFile);
commentAttributes.load(in);
in.close();
Iterator it = commentAttributes.keySet().iterator();
IAttribute a = null;
String key = null;
while (it.hasNext()) {
key = (String) it.next();
a = PIMRuntime.getInstance().getCallerFactory().createAttribute(key, commentAttributes.getProperty(key));
comment.addAttribute(a);
}
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + commentAttributesFile.getAbsolutePath());
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + commentAttributesFile.getAbsolutePath());
}
}
return comment;
}
Aggregations