Search in sources :

Example 16 with IAttribute

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);
}
Also used : IImageProvider(de.janrufmonitor.util.io.IImageProvider) IAttribute(de.janrufmonitor.framework.IAttribute)

Example 17 with IAttribute

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();
}
Also used : Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller)

Example 18 with IAttribute

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);
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) ICip(de.janrufmonitor.framework.ICip) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMsn(de.janrufmonitor.framework.IMsn) Date(java.util.Date)

Example 19 with IAttribute

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;
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute) Iterator(java.util.Iterator)

Example 20 with IAttribute

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;
}
Also used : IComment(de.janrufmonitor.service.comment.api.IComment) Comment(de.janrufmonitor.service.comment.impl.Comment) IComment(de.janrufmonitor.service.comment.api.IComment) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) Date(java.util.Date) FileInputStream(java.io.FileInputStream) BufferedReader(java.io.BufferedReader) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) FileReader(java.io.FileReader) File(java.io.File)

Aggregations

IAttribute (de.janrufmonitor.framework.IAttribute)111 ICaller (de.janrufmonitor.framework.ICaller)44 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)40 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)39 List (java.util.List)34 ICallerList (de.janrufmonitor.framework.ICallerList)31 ArrayList (java.util.ArrayList)29 Iterator (java.util.Iterator)25 ICall (de.janrufmonitor.framework.ICall)19 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)15 SQLException (java.sql.SQLException)15 File (java.io.File)14 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)12 IOException (java.io.IOException)12 Message (de.janrufmonitor.exception.Message)11 ComFailException (com.jacob.com.ComFailException)10 Date (java.util.Date)10 IMsn (de.janrufmonitor.framework.IMsn)9 Dispatch (com.jacob.com.Dispatch)8 UUID (de.janrufmonitor.util.uuid.UUID)8