⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memotransformmanager.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Cut all client attachment tags from the memo text.     * Insert system tags instead.     * @param reStructs client regular expression structure list to find neccessary links     * @return converted memo     */    public String convertToSystem( List reStructs ) {        switch( memoFormat ) {        case XML_FORMAT:            return convert( reStructs, xmlFormat );        case HTML_FORMAT:            return convert( reStructs, htmlFormat );        default:            return convert( reStructs, textFormat );        }    }    /**     * Cut all client attachment tags from the memo text.     * Insert system tags instead.     * @param reStruct client regular expression structure to find neccessary links     * @return converted memo     */    public String convertToSystem( ReStruct reStruct ) {        switch( memoFormat ) {        case XML_FORMAT:            return convert( reStruct, xmlFormat );        case HTML_FORMAT:            return convert( reStruct, htmlFormat );        default:            return convert( reStruct, textFormat );        }    }    /**     * Cut all system attachment tags from the memo text.     * Insert client tags instead.     * @param format client format string for MessageFormat object     * @return converted memo     * @see java.text.MessageFormat     */    public String convertToClient( String format ) {        switch( memoFormat ) {        case XML_FORMAT:            return convert( xmlReStructs, format );        case HTML_FORMAT:            return convert( htmlReStructs, format );        default:            return convert( textReStructs, format );        }    }    // ===================================================== Protected methods    //    // Convert methods.    // Return converted string.    //    protected String convert( List reStructs, String format ) {        int size = ( reStructs == null ) ? 0 : reStructs.size();        String s = memo;        for( int i = 0; i < size; i++ ) {            s = __convert( s, ( ReStruct ) reStructs.get( i ), format );        }        return s;    }    protected String convert( ReStruct reStruct, String format ) {        return __convert( memo, reStruct, format );    }    protected String __convert( String memo, ReStruct reStruct, String format ) {        if( logger.getLogger().isDebugEnabled() ) {            logger.DEBUG( "Start convertion. ReStruct: " + reStruct + ". Format: " + format );        }        // If memo is empty or no ReStruct or no format - do nothing.        if( StringHelper.isEmpty( memo ) ) {            return memo;        }        if( reStruct == null ) {            logger.WARN( "No suitable regexp structure..." );            return memo;        }        if( format == null ) {            logger.WARN( "No suitable format..." );            return memo;        }        try {            RE re = new RE( reStruct.getRegexp(), RE.MATCH_CASEINDEPENDENT | RE.MATCH_MULTILINE );            int i = 0;            int curPos = 0;            while( re.match( memo, curPos ) ) {                Attachment attachment = nextAttachment( re, memo, reStruct );                if( logger.getLogger().isDebugEnabled() ) {                    logger.DEBUG( "Found attachment: " + attachment );                }                // add attachment in map                if( attachments != null ) {                    attachments.add( attachment );                }                // replace tags                String link = constructLink( attachment, format, reStruct );                int start = re.getParenStart( 0 );                int end = re.getParenEnd( 0 );                String head = memo.substring( 0, start );                String tail = memo.substring( end );                memo = head + link + tail;                curPos = start + link.length();                // counter                i++;            }            if( logger.getLogger().isDebugEnabled() ) {                logger.DEBUG( "Finish convertion. Memo matched " + i + " times..." );            }        } catch( RESyntaxException ex ) {            logger.ERROR( ex );            throw new GenericSystemException( "Regexp exception: " +                                              ex.getMessage(), ex );        }        return memo;    }    //    // Find attachments methods.    // Return the list with Attachment objects.    //    protected List findAttachments( String memo, List reStructs ) {        List attachments = new ArrayList();        int size = ( reStructs == null ) ? 0 : reStructs.size();        for( int i = 0; i < size; i++ ) {            __findAttachments( memo, ( ReStruct ) reStructs.get( i ), attachments );        }        return attachments;    }    protected List findAttachments( String memo, ReStruct reStruct ) {        List attachments = new ArrayList();        __findAttachments( memo, reStruct, attachments );        return attachments;    }    protected List __findAttachments( String memo, ReStruct reStruct, List attachments ) {        // If empty - do nothing.        if( StringHelper.isEmpty( memo ) ) {            return attachments;        }        try {            RE re = new RE( reStruct.getRegexp(), RE.MATCH_CASEINDEPENDENT | RE.MATCH_MULTILINE );            int curPos = 0;            while( re.match( memo, curPos ) ) {                Attachment attachment = nextAttachment( re, memo, reStruct );                if( logger.getLogger().isDebugEnabled() ) {                    logger.DEBUG( "Found attachment: " + attachment );                }                attachments.add( attachment );                curPos = re.getParenEnd( 0 );            }        } catch( RESyntaxException ex ) {            logger.ERROR( ex );            throw new GenericSystemException( "Regexp exception: " + ex.getMessage(), ex );        }        return attachments;    }    // Build link on attachment    protected String constructLink( Attachment attachment,                                    String format,                                    ReStruct reStruct ) {        try {            RE re = new RE( "\\{1\\}" );            format = re.subst( format, getLinkPos1( attachment, reStruct ), RE.REPLACE_ALL );            re = new RE( "\\{2\\}" );            format = re.subst( format, getLinkPos2( attachment, reStruct ), RE.REPLACE_ALL );            re = new RE( "\\{3\\}" );            format = re.subst( format, getLinkPos3( attachment, reStruct ), RE.REPLACE_ALL );        } catch( RESyntaxException ex ) {            logger.ERROR( ex );            throw new GenericSystemException( "Regexp exception: " + ex.getMessage(),                                              ex );        }        return format;    }    // Get value for link position #1    protected String getLinkPos1( Attachment attachment, ReStruct reStruct ) {        return attachment.getName();    }    // Get value for link position #2    protected String getLinkPos2( Attachment attachment, ReStruct reStruct ) {        return attachment.getSubfolder();    }    // Get value for link position #3    protected String getLinkPos3( Attachment attachment, ReStruct reStruct ) {        String content = attachment.getContent();        if( content == null ) {            content = StringHelper.EMPTY_VALUE;        }        return content;    }    // Read next attachment.    protected Attachment nextAttachment( RE re,                                         String memo,                                         ReStruct reStruct ) {        // read name (mandatory)        String name = memo.substring( re.getParenStart( reStruct.getNamePos() ),                                      re.getParenEnd( reStruct.getNamePos() ) );        // read subfolder (mandatory)        String subfolder = memo.substring( re.getParenStart( reStruct.getSubfolderPos() ),                                           re.getParenEnd( reStruct.getSubfolderPos() ) );        // read content (optional)        String content = null;        int contentStart = re.getParenStart( reStruct.getContentPos() );        int contentEnd = re.getParenEnd( reStruct.getContentPos() );        if( contentStart >= 0 && contentEnd >= 0 ) {            content = memo.substring( contentStart, contentEnd );        }        // construct Attachment        return new Attachment( name, subfolder, content );    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -