Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2740

Re: Chinese Character problem for PO with attachment filename in chinese

$
0
0

public static String readAttachmentContentURL (String url,

                                                   String fileName,

                                                   Container container,

                                                   Random randomGenerator) throws StreamTransformationException

    {

 

 

        nullOrEmptyCheck(url,URL);

 

 

        OutputAttachments outputAttachments = getOutputAttachments(container);

 

 

        String cid = System.currentTimeMillis() + "_"

            + generateRandomNum(randomGenerator);

       

        try {

            HttpClient httpClient = new HttpClient();

            GetMethod getMethod = new GetMethod(url);

            httpClient.executeMethod(getMethod);

            int status = getMethod.getStatusCode();

            if (status != HttpStatus.SC_OK) {

                throw new StreamTransformationException(

                    "OutboundAttachmentHandler Exception - Attachment Download Status Code"

                        + status);

            }

            byte[] content = getMethod.getResponseBody();

 

 

            nullOrEmptyCheck(new String(content),CONTENT);

 

 

            Header attachmentContentTypeHeader = getMethod.getResponseHeader(CONTENT_TYPE);

 

 

            String respContentType;

            if (attachmentContentTypeHeader == null) {

                respContentType = DEFAULT_OB_CONTENT_TYPE;

            }

            else {

                respContentType = attachmentContentTypeHeader.getValue();

                if (respContentType == null || respContentType == "") {

                    respContentType = DEFAULT_OB_CONTENT_TYPE;

                }

            }

           

            Header contentDispositionHeader = getMethod.getResponseHeader(CONTENT_DISPOSITION);

 

 

            cid = attachFileNameToCID(fileName, respContentType, cid, contentDispositionHeader);

 

 

            Attachment attachment = outputAttachments.create(

                cid,

                respContentType,

                content);

            outputAttachments.setAttachment(attachment);

        }

        catch (IOException e) {

            throw new StreamTransformationException("OutboundAttachmentHandler Exception"

                + e.getMessage(), e);

 

 

        }

 

 

        return cid;

    }

 

 

 

 

private static String attachFileNameToCID (String fileName,

                                               String respContentType,

                                               String cid,

                                               Header contentDispositionHeader) throws StreamTransformationException

    {

        String extention = ".";

 

 

        if (!Util.nullOrEmptyOrBlankString(fileName)) {

            cid = cid + fileName;

        }

        else {

            String[] contentTypeWithEncode = respContentType.split(";");

            String contentType = null;

            if (contentTypeWithEncode[0] != null) {

                contentType = contentTypeWithEncode[0];

            }

           

            if (contentDispositionHeader != null) {

                String dispositionContent = contentDispositionHeader.getValue();

                fileName = AttachmentUtil.getFileName(dispositionContent);

                if (!Util.nullOrEmptyOrBlankString(fileName)) {

                    cid = cid + fileName;

                }

                else {

                    extention = extention + getExtention(contentType);

                    cid = cid + extention;

                }

            }

            else {

                extention = extention + getExtention(contentType);

                cid = cid + extention;

            }

 

 

        }

        return cid;

    }

 

 

cid is the value coming in the xml for URL tag.

<Comments>

               <Attachment>

                  <URL>1452237793341_1969839383Copy of 诺å?Ž Lin Teng 15082403(ä¸?å?«ç¨Žï¼‰.docx</URL>             

</Comments>


Viewing all articles
Browse latest Browse all 2740

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>