📄 memotransformmanager.java
字号:
/* * Copyright 2006-2007 Queplix Corp. * * Licensed under the Queplix Public License, Version 1.1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.queplix.core.modules.eqlext.utils.images;import com.queplix.core.error.GenericSystemException;import com.queplix.core.utils.StringHelper;import com.queplix.core.utils.log.AbstractLogger;import com.queplix.core.utils.log.Log;import org.apache.regexp.RE;import org.apache.regexp.RESyntaxException;import java.util.ArrayList;import java.util.List;/** * Memo attachment links transformer manager. * <br>Supported memo types: * <li>XML * <li>HTML * <li>Text * @author [ALB] Baranov Andrey * @version $Revision: 1.1.1.1 $ $Date: 2005/09/12 15:30:44 $ */public class MemoTransformManager { // =============================================================== Constants /** Logger. */ protected static AbstractLogger logger = Log.getLog( MemoTransformManager.class ); /** XML format type. */ public static final int XML_FORMAT = 0; /** HTML format type. */ public static final int HTML_FORMAT = 1; /** Text format type. */ public static final int TEXT_FORMAT = 2; /** @todo add support other MIME types */ /** Name position. */ public static final int NAME_POS = 1; /** Subfolder position. */ public static final int SUBFOLDER_POS = 2; /** Content (attachment description) position. */ public static final int CONTENT_POS = 3; // // System regular expression to find attachment in the memo. // public static final String SYSTEM_REG_EXP = "<attachment\\s+href='([^']+)/([^']+)'>(.*?)</attachment>"; public static final String SYSTEM_FORMAT = "<attachment href='{" + SUBFOLDER_POS + "}/{" + NAME_POS + "}'>{" + CONTENT_POS + "}</attachment>"; public static final ReStruct SYSTEM_RE_STRUCT = new ReStruct( SYSTEM_REG_EXP, SUBFOLDER_POS, NAME_POS, CONTENT_POS ); // ===================================================== Variables // Memo field. private final String memo; // Flag indicates collect attachments in // <code>attachments</code> or not. private boolean collectAttachments; // Memo format. private final int memoFormat; // Formats. private String xmlFormat = null; private String htmlFormat = SYSTEM_FORMAT; private String textFormat = null; // RE structure lists. private final List xmlReStructs; private final List htmlReStructs; private final List textReStructs; // Attachments. private List attachments; // ===================================================== Constructors /** * Constructor * @param memo value */ public MemoTransformManager( String memo ) { this( memo, false ); } /** * Constructor * @param memo value * @param collectAttachments collect atatchments or no */ public MemoTransformManager( String memo, boolean collectAttachments ) { this.memo = memo; this.collectAttachments = collectAttachments; this.xmlReStructs = new ArrayList(); this.htmlReStructs = new ArrayList(); this.textReStructs = new ArrayList(); // Init HTML RE list htmlReStructs.add( SYSTEM_RE_STRUCT ); if( collectAttachments ) { this.attachments = new ArrayList(); } if( StringHelper.isXML( memo ) ) { memoFormat = XML_FORMAT; } else if( StringHelper.isHTML( memo ) ) { memoFormat = HTML_FORMAT; } else { memoFormat = TEXT_FORMAT; } if( logger.getLogger().isDebugEnabled() ) { logger.DEBUG( "Memo format: " + memoFormat ); logger.DEBUG( "Collect Attachments?: " + collectAttachments ); } } // ===================================================== Public methods // // Setters. // public void setXMLFormat( String xmlFormat ) { this.xmlFormat = xmlFormat; } public void setHTMLFormat( String htmlFormat ) { this.htmlFormat = htmlFormat; } public void setTextFormat( String textFormat ) { this.textFormat = textFormat; } public void setXMLReStruct( ReStruct xmlReStruct ) { xmlReStructs.clear(); xmlReStructs.add( xmlReStruct ); } public void setXMLReStruct( List reStructs ) { xmlReStructs.clear(); xmlReStructs.addAll( reStructs ); } public void setHTMLReStruct( ReStruct htmlReStruct ) { htmlReStructs.clear(); htmlReStructs.add( htmlReStruct ); } public void setHTMLReStruct( List reStructs ) { htmlReStructs.clear(); htmlReStructs.addAll( reStructs ); } public void setTextReStruct( ReStruct textReStruct ) { textReStructs.clear(); textReStructs.add( textReStruct ); } public void setTextReStruct( List reStructs ) { textReStructs.clear(); textReStructs.addAll( reStructs ); } public void addXMLReStruct( ReStruct xmlReStruct ) { xmlReStructs.add( xmlReStruct ); } public void addHTMLReStruct( ReStruct htmlReStruct ) { htmlReStructs.add( htmlReStruct ); } public void addTextReStruct( ReStruct textReStruct ) { textReStructs.add( textReStruct ); } // // Getters. // public int getMemoFormat() { return memoFormat; } public Attachment[] getAttachments() { if( !collectAttachments ) { throw new IllegalStateException(); } if( attachments.size() == 0 ) { return null; } else { return( Attachment[] ) attachments.toArray( new Attachment[0] ); } } /** * Get the array of attachments encountered in memo. * @return array or NULL */ public Attachment[] findAttachments() { List l; switch( memoFormat ) { case XML_FORMAT: l = findAttachments( memo, xmlReStructs ); break; case HTML_FORMAT: l = findAttachments( memo, htmlReStructs ); break; default: l = findAttachments( memo, textReStructs ); } if( l == null || l.size() == 0 ) { return null; } else { return( Attachment[] ) l.toArray( new Attachment[0] ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -