KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > content > transform > BinaryPassThroughContentTransformer


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.content.transform;
18
19 import java.util.Map JavaDoc;
20
21 import org.alfresco.service.cmr.repository.ContentReader;
22 import org.alfresco.service.cmr.repository.ContentWriter;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 /**
27  * Allows direct streaming from source to target when the respective mimetypes
28  * are identical, except where the mimetype is text.
29  * <p>
30  * Text has to be transformed based on the encoding even if the mimetypes don't
31  * reflect it.
32  *
33  * @see org.alfresco.repo.content.transform.StringExtractingContentTransformer
34  *
35  * @author Derek Hulley
36  */

37 public class BinaryPassThroughContentTransformer extends AbstractContentTransformer
38 {
39     private static final Log logger = LogFactory.getLog(BinaryPassThroughContentTransformer.class);
40     
41     /**
42      * @return Returns 1.0 if the formats are identical and not text
43      */

44     public double getReliability(String JavaDoc sourceMimetype, String JavaDoc targetMimetype)
45     {
46         if (sourceMimetype.startsWith(StringExtractingContentTransformer.PREFIX_TEXT))
47         {
48             // we can only stream binary content through
49
return 0.0;
50         }
51         else if (!sourceMimetype.equals(targetMimetype))
52         {
53             // no transformation is possible so formats must be exact
54
return 0.0;
55         }
56         else
57         {
58             // formats are the same and are not text
59
return 1.0;
60         }
61     }
62
63     /**
64      * Performs a direct stream provided the preconditions are met
65      */

66     public void transformInternal(
67             ContentReader reader,
68             ContentWriter writer,
69             Map JavaDoc<String JavaDoc, Object JavaDoc> options) throws Exception JavaDoc
70     {
71         // just stream it
72
writer.putContent(reader.getContentInputStream());
73     }
74 }
75
Popular Tags