Search Results for '개발노트'

181 POSTS

  1. 2009.07.25 tiny_mce 에서 한글 문제 1
  2. 2009.06.10 javaMail 다중유저에게 메일 보내기
  3. 2009.02.17 String을 Date로 변환시 포맷형태 정리.

tiny_mce 에서 한글 문제

Posted 2009. 7. 25. 14:12
tiny_mce WYSWYG editor를 사용하면서 발견하게 된 문제점.

아무생각없이 웹에서 tiny_mce를 다운받아 세팅하고

적용하면서 잘 쓰는데 알수 없는 이상한 버그가 발견되었다.

처음 로딩하고 한글로 설정되어 있는 상태에서 글자를 쓰려고 하면 한글자 써지고 또 지워지고...

엔터나 한영키 누른후에는 정상작동.

분명 한글문제와 관련있다고 생각되어 style="ime-mode:inactive" 를 추가도 해보고 뻘짓아닌 뻘짓도 해보고...

잘 안됬다.

그러다 여기저기 설치된 tiny_mce 에디터를 비교해 보면서 알게 된 차이점.

옵션사항이 다르다는것을 알게됬다.

바로 아래 옵션 추가후

forced_root_block : false

결국 해결.





기존엔 한명씩 보내던 것을 묶어서 보내게 된다. InetAddress를 이용해서...

package Part1;

import java.util.Date;
import java.util.Properties;
import java.io.*;
import java.util.Calendar;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Email {

    public static void main(String[] args) {
      
//        String to = "matiari@korea.com";  // hanmail.net으로  이메일 보냄.
        String from = "mati@matiphoto.com"; // epu에서...
        String host = "mail.epu.co.kr";

        Calendar now    = Calendar.getInstance();
        int year      = now.get(Calendar.YEAR);
        int month     = now.get(Calendar.MONTH) + 1;
        int nowdate   = now.get(Calendar.DATE);
        int dayofweek = now.get(Calendar.DAY_OF_WEEK);
        int hour      = now.get(Calendar.HOUR_OF_DAY);
        int min       = now.get(Calendar.MINUTE);
        String szToday = String.valueOf(year) + "." + String.valueOf(month) + "." + String.valueOf(nowdate) + "(" + IntToWeek(dayofweek)  + ") " + String.valueOf(hour) + ":" + String.valueOf(min);
        szToday += " 마티가 전하는 안부인사^^ ";
              
        // Create properties, get Session
        Properties props = new Properties();

        // need to specify which host to send it to
        props.put("mail.smtp.host", host);
       
        // To see what is going on behind the scene
        props.put("mail.debug", "true");
        Session session = Session.getInstance(props);

        try {
            // Instantiatee a message
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(from));
    
            InternetAddress[] toAddr = new InternetAddress[10];
            toAddr[0] = new InternetAddress ("jhk149@hanmail.net");  // 현경
            toAddr[1] = new InternetAddress ("jjangee71@nate.com");  // 짱이
            toAddr[2] = new InternetAddress ("mati@matiphoto.com");   // 마티
            toAddr[3] = new InternetAddress ("amante69@hanmail.net");  // 마티
            toAddr[4] = new InternetAddress ("matiari@korea.com");  // 마티
            toAddr[5] = new InternetAddress ("ryooimm@hanmail.net");  // 로사
            toAddr[6] = new InternetAddress ("aqulina@nate.com");  // 아리나
            toAddr[7] = new InternetAddress ("fairyi@nate.com");  // 호선
            toAddr[8] = new InternetAddress ("hwacci@lycos.co.kr"); // 종철
            toAddr[9] = new InternetAddress ("matiari@nate.com"); // 마티
       
            msg.setRecipients(Message.RecipientType.TO, toAddr);
            msg.setSubject(szToday);
            msg.setSentDate(new Date());
           
//            msg.setContent("마티의 첫번째 소식지 <br>아놔~ 졸린거... <br> ㅋㅋㅋ<br><br>싫음 말구... -.-;",  "text/html;charset=ksc5601");
            msg.setContent(readMsgFile().toString(),  "text/html;charset=ksc5601");

            Transport.send(msg);  //메일발송
        }
        catch (MessagingException mex) {
            mex.printStackTrace();
        }
        catch (Exception e) {}
       
    }
   
    // 파일을 읽어서 StringBuffer에 담는다.
 static StringBuffer readMsgFile() {
     FileReader fr = null;
     StringBuffer sBuf = new StringBuffer("Hi~<br>");
     
     try {
      fr = new FileReader("E:/MatiData/TodayMail.txt"); // 내 컴퓨터에 있는 파일을 읽어서 그대로 보냄.
      BufferedReader br = new BufferedReader(fr);
      String readData = br.readLine();
      while ( readData != null){
//      System.out.println(readData);
//      System.out.println("<br>");
       sBuf.append(readData);
       sBuf.append("<br>");
       readData = br.readLine();
      }
      br.close();
     } catch (IOException ex) {
      System.out.println("예외발생: " + ex.getMessage());
      sBuf = null;
     } finally {
      if (fr != null) try { fr.close(); } catch (IOException ex) {}
     }
  return sBuf;
   }
   
 // Integer로 된 요일을 String을 변경.
    static String IntToWeek(int nWeek) {
     String szWeek = new String();
     
     switch (nWeek) {
   case 1 : szWeek = "일"; break;
   case 2 : szWeek = "월"; break;
   case 3 : szWeek = "화"; break;
   case 4 : szWeek = "수"; break;
   case 5 : szWeek = "목"; break;
   case 6 : szWeek = "금"; break;
   case 7 : szWeek = "토"; break;
      default : szWeek = "공"; break;
     }
     return szWeek;
    }
    
 //
}//End of class

 





날짜를 나타낼때 변수로 받은 타입이 스트링일 경우가 많다. 이경우 DateFormat을 이용하여 Date 타입으로 컨버팅 하는데 자주 사용하다 보니 유틸리티로 만들어서 사용하곤 한다. 
그러다 보니 그 포맷 형태를 까먹을 때가 많다. 굳이 다 기억하고 싶지는 않지만 그래도 정리하고자 한다.

가장 일반적으로 사용하는 클래스는 java.text.SimpleDateFormat 클래스를 사용하는데, 성능면에서 많이 떨어진다고 한다.(얼마나 떨어지는지는 비교수치를 찾을 수가 없다. 시간 되면 테스트 한번 해보자). 그래서 사용하는 것이 apache.commons 에 있는 FastDateFormat 클래스이다.
SimpleDateFormat이든 FastDateFormat이든 변수로 사용되는 format 형식은 동일하다.

Letter Date / Time Component Examples
G Era designator AD
y Year 1996; 96
M Month in year July; Jul; 07
w Week in year 27
W Week in month 2
D Day in year 189
d Day in month 10
F Day of week in month 2
E Day in week Tuesday; Tue
a Am/pm marker PM
H Hour in day (0-23) 0
k Hour in day (1-24) 24
K Hour in am/pm (0-11) 0
h Hour in am/pm (1-12) 12
m Minute in hour 30
s Second in minute 55
S Millisecond 978
z Time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone -0800

1. String을 Date 타입으로 변환시 예제
String stringDate = "2009/02/19";
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date newDate = dateFormat.parse(stringDate);

apache.commons의 FastDateFormat 클래스는 다음처럼 사용한다.
FastDateFormat fastdateformat = FastDateFormat.getInstance(format, locale);
locale은 request로 부터 받아도 되고 또는 Default로 new Locale("ko_KR")처럼 지정할수도 있다.

2. 역으로 Date타입을 String타입으로 변환시 예제
String newStringDate = dateFormat.format(newDate)

상황에 따라서 newDate.toString()을 쓰기도 하지만 엉뚱한 값이 나올수도 있으니 유의.

다음엔 Locale에 들어가는 값에 대해 알아보고 정리해 보기로 해야겠다.


« PREV : 1 : ··· : 45 : 46 : 47 : 48 : 49 : 50 : 51 : ··· : 61 : NEXT »