04.IT Knowledge/Java2010. 8. 13. 18:09

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;


public class JHttpURLConnection {
    public static String getHttpResults(String targetUrl, String parameter, String contentType) {
        String result = "";
        URL url;
        BufferedReader in = null;
        InputStreamReader isr = null;
        OutputStream out = null;
        try {
            url = new URL(targetUrl);
            URLConnection connection = url.openConnection();
            HttpURLConnection httpConn = (HttpURLConnection) connection;
            byte[] b = null;
            if(!"".equals(parameter)) {
                b = parameter.getBytes("UTF-8");
                httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
            }
            String cType = "text/xml; charset=utf-8";
            if(contentType != null && !"".equals(contentType)) {
                cType = contentType;
            }
            httpConn.setRequestProperty("Content-Type", cType);
            httpConn.setRequestMethod("POST");
            httpConn.setDoOutput(true);
            httpConn.setDoInput(true);

            if(!"".equals(parameter)) {
                out = httpConn.getOutputStream();
                out.write(b);
            }
            isr = new InputStreamReader(httpConn.getInputStream(), "utf-8");
            in = new BufferedReader(isr);

            String inputLine = "AA";
            StringBuffer message = new StringBuffer();
            while ((inputLine = in.readLine()) != null) {
                message.append(inputLine);
            }
            httpConn.disconnect();
            result = message.toString();
        } catch (MalformedURLException e) {
            result = ""
                + e.getMessage()
                + "
";
        } catch (IOException e) {
            result = ""
                + e.getMessage()
                + "
";
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException e) {
                result = ""
                    + e.getMessage()
                    + "
";
            }
            try {
                if (isr != null) {
                    isr.close();
                }
            } catch (IOException e) {
                result = ""
                    + e.getMessage()
                    + "
";
            }
            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                result = ""
                    + e.getMessage()
                    + "
";
            }
        }
        return result;
    }
    
    public static void main(String[] args) {
        System.out.println(getHttpResults("http://www.naver.com", "", "text/html; charset=utf-8"));
    }
}
Posted by 아주 오래된 미래
04.IT Knowledge/단상들2009. 7. 7. 21:36
http://twitter.com/projecty
위의 링크를 보면 발표 현장에서 사람들의 감정이 어땠는지를 아주 잘 느낄 수 있다.

반신반의 하기는 했지만, 역시 라니....ㅡ.ㅡ;;;
티맥스의 설레발은 참...

아직도 리눅스에 wine이라는 생각을 접을 수 없다.
차라리 공개적이고 대대적으로 참여를 호소했더라면 더 좋았을 것 같다..
Posted by 아주 오래된 미래
04.IT Knowledge/Java2009. 7. 2. 22:38
 Java Swing Framework에서 제공하는 Component를 JavaFX에서 가져다 쓰기 위해서는 SwingComponent 클래스를 이용하여 Wrapping을 하는 것이 필요하다.
 이 글에서는 단순한 Swing Component가 아닌 JFreeChart의 Chart를 JavaFX위에 올려보겠다.

 1. NetBeans download
  - http://www.netbeans.org에서 NetBeans IDE를 다운로드 받아 설치한다. 여기에서 설치 방법은 설명하지 않겠다.
   개인적인 경험으로 JavaFX를 프로그래밍 한다면 Eclipse보다 NetBeans를 사용할 것을 권한다. (조금 더 편한듯..)

 2. JFreeChart download
  - 우선 JFreeChart를 http://www.jfree.org/jfreechart/download.html에서 다운로드 받는다.
  다운로드 받은 압축파일을 해제한 후 디렉토리 아래의 lib 폴더의 jar들을 이후에 프로젝트의 값을 설정할 때 클래스 패스로 잡아준다.

 3. Write Sample Swing Class
  - 여기서는 JFreeChart에서 demo로 제공하는 BarChartDemo1 클래스를 변형하여 사용할 것이다. 원래의 소스에서는 ApplicationFrame 클래스를 상속하여 예제가 구성되어 있으나 여기서는 JPanel을 상속하여 JavaFX에서 호출 가능하도록 할 것이다.

다음은 아래의 소스를 구현한 스크린 샷이다.




////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// BarChart.java
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package a.wrapper;

import java.awt.Color;
import java.awt.GradientPaint;

import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

public class BarChart extends JPanel {

    private static String series1 = "First";
    private static String series2 = "Second";
    private static String series3 = "Third";

    private static String category1 = "Category 1";
    private static String category2 = "Category 2";
    private static String category3 = "Category 3";
    private static String category4 = "Category 4";
    private static String category5 = "Category 5";

    private static DefaultCategoryDataset dataset;

    public BarChart() {
        CategoryDataset datasetResult = createDataset();
        JFreeChart chart = createChart(datasetResult);
        ChartPanel panel = new ChartPanel(chart);
        this.add(panel);
    }

    public void changeDataset(double val) {
        dataset.setValue(1.0 + 2 * val, series1, category1);
        dataset.setValue(2.0 + 2 * val, series1, category2);
        dataset.setValue(3.0 + 2 * val, series1, category3);
        dataset.setValue(4.0 + 2 * val, series1, category4);
        dataset.setValue(5.0 + 2 * val, series1, category5);

        dataset.setValue(1.0 + 3 * val, series2, category1);
        dataset.setValue(2.0 + 3 * val, series2, category2);
        dataset.setValue(3.0 + 3 * val, series2, category3);
        dataset.setValue(4.0 + 3 * val, series2, category4);
        dataset.setValue(5.0 + 3 * val, series2, category5);

        dataset.setValue(1.0 + 4 * val, series3, category1);
        dataset.setValue(2.0 + 4 * val, series3, category2);
        dataset.setValue(3.0 + 4 * val, series3, category3);
        dataset.setValue(4.0 + 4 * val, series3, category4);
        dataset.setValue(5.0 + 4 * val, series3, category5);
    }

    private static CategoryDataset createDataset() {
        dataset = new DefaultCategoryDataset();
        dataset.addValue(1.0, series1, category1);
        dataset.addValue(4.0, series1, category2);
        dataset.addValue(3.0, series1, category3);
        dataset.addValue(5.0, series1, category4);
        dataset.addValue(5.0, series1, category5);

        dataset.addValue(5.0, series2, category1);
        dataset.addValue(7.0, series2, category2);
        dataset.addValue(6.0, series2, category3);
        dataset.addValue(8.0, series2, category4);
        dataset.addValue(4.0, series2, category5);

        dataset.addValue(4.0, series3, category1);
        dataset.addValue(3.0, series3, category2);
        dataset.addValue(2.0, series3, category3);
        dataset.addValue(3.0, series3, category4);
        dataset.addValue(6.0, series3, category5);
        return dataset;
    }

    private static JFreeChart createChart(CategoryDataset dataset) {

        JFreeChart chart = ChartFactory.createBarChart(
                "Bar Chart Demo",         // chart title
                "Category",               // domain axis label
                "Value",                  // range axis label
                dataset,                  // data
                PlotOrientation.VERTICAL, // orientation
                true,                     // include legend
                true,                     // tooltips?
                false                     // URLs?
                );

        chart.setBackgroundPaint(Color.white);
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setDrawBarOutline(false);

        GradientPaint gp0 = new GradientPaint(0.0f,0.0f,Color.blue,0.0f,0.0f,new Color(0, 0, 64));
        GradientPaint gp1 = new GradientPaint(0.0f,0.0f,Color.green,0.0f,0.0f,new Color(0, 64, 0));
        GradientPaint gp2 = new GradientPaint(0.0f,0.0f,Color.red,0.0f,0.0f,new Color(64, 0, 0));

        renderer.setSeriesPaint(0, gp0);
        renderer.setSeriesPaint(1, gp1);
        renderer.setSeriesPaint(2, gp2);

        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setCategoryLabelPositions(
                         CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
                                             );

        return chart;
    }
}

 4. Write Wrapper Class
  - JavaFX 실행파일에서 호출할 Wrapper 클래스를 정의한다.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// BarChartWrapper.fx
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package a.wrapper;

import javafx.ext.swing.SwingComponent;
import javax.swing.JPanel;
import java.awt.BorderLayout;

import org.jfree.data.category.CategoryDataset;

public class BarChartWrapper extends SwingComponent{

    var panel: JPanel;
    var centerPanel: JPanel;
    var northPanel: JPanel;

    var dataset: CategoryDataset;
    var chart: BarChart;

    public var top: SwingComponent on replace{
        northPanel.add( top.getJComponent(), BorderLayout.CENTER);
        panel.add(northPanel, BorderLayout.NORTH);
    }

    public var initValue: Double on replace{
        chart.changeDataset(initValue);
    }

    public override function createJComponent(){
        panel = new JPanel(new BorderLayout());
        centerPanel = new JPanel(new BorderLayout());
        northPanel = new JPanel(new BorderLayout());
        chart = new BarChart();
        centerPanel.add(chart, BorderLayout.CENTER);
        panel.add(centerPanel, BorderLayout.CENTER);
        return panel;
    }
}

 5. Write Main Class
  - JavaFX 실행파일을 작성한다.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Main.fx
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package a.main;

import javafx.stage.Stage;
import javafx.scene.Scene;

import a.wrapper.BarChartWrapper;
import javafx.ext.swing.SwingButton;

var initVal = 1.0;

Stage {
    title: "JavaFX에서 JFreeChart를 사용해 보자.."
    scene: Scene {
        content: BarChartWrapper {
            width: 600
            height: 450
            initValue: bind {initVal}
            top: SwingButton{
                text: "차트 데이터 변경하기"
                action: function() {
                    initVal *= 2
                }
            }
        }
    }
}

// 누구든 언제든 궁금한 사항이 있으면 질문하시라..
// 당장 답글이 달리지는 않겠지만, 일주일 이내에 반드시 답글을 달아드리겠삼~~

Posted by 아주 오래된 미래
04.IT Knowledge2009. 5. 26. 16:57
1. 주석
  -> 주석에 각종 로직을 Sudo-code 형태로 먼저 구현하는 습관을 들인다.
2. data type, 연산자
  -> Data type을 선언하는 방법을 익힌다.
       :: 이 때 중점적으로 볼 것은 String, integer, double, date 형을 보며, Array를 선언하는 방법이다.
  -> 연산자에 대해 익힌다.
3. loop, if, else
  -> Loop 제어(for, while, do) 및 if/else if/else 처리는 로직을 구현하는데 거의 대부분을 차지한다.
4. function (나아가 class, module)
  -> function을 선언하고 호출하는 방법을 익힌다.
  -> 외부에 작성된 소스를 include하는 방법을 익힌다.
5. file(Read and Write)
  -> 외부 파일에 저장 및 읽는 방법을 익힌다.
  -> 가능하다면 OS 명령어를 호출하는 방법도 익힌다.
6. DB처리
  -> DB에 접속하여 INSERT/UPDATE/DELETE/SELECT하는 방법을 익힌다.
7. Network
  -> TCP/IP, Telnet, FTP 처리 방법을 익힌다.
8.Thread
  -> 병렬/분산처리를 위한 방법을 익힌다.
9. Event
  -> 특정 event를 발생시키는 방법과 event 발생을 인지하는 방법을 익힌다.

Posted by 아주 오래된 미래
04.IT Knowledge2009. 5. 17. 15:22

apt는 최신 패키지를 다운로드 하여 설치하게 되는데 upgrade 하기전에 update 해서 source.list 를 갱신 하는것이 좋다.

1. 패키지 캐쉬 갱신 및 자동 업그레이드
# apt-get update
# apt-get upgrade

2. 개별 패키지 설치
# apt-get install <패키지명>

3. 원하는 패키지 찾기
# apt-cache  serach <패키지명>

4. 원하는 패키지 찾은 다음 정보 출력
# apt-cache show <패키지명>

5. 의존성 검사 수행하면서 업그레이드
# apt-get -s dist-upgrade

6. 설치한 패키지에 이상이 있어 다시 설치시
# apt-get --reinstall install <패키지명>

7. CD-ROM 목록 추가
# apt-cdrom add

8. 패키지 삭제
# apt-get remove <패키지명>
또는 # dpkg -P <패키지명>

9. 삭제하는 패키지의 설정화일들가지 모두 삭제시
# apt-get --purge remove <패키지명>

10. dselect에서 선택한 패키지의 설치 및 삭제
# apt-get dselect-upgrade

11. 설치된 패키지를 볼때
# dpkg -l

참고)   apt-get install 명령어로 받은 deb 파일의 저장 위치
          /var/cache/apt/archive/
        위 폴더에 .deb 패키지파일로 저장됨

출처 : http://www.fduser.org/blog/65

Posted by 아주 오래된 미래
04.IT Knowledge/Java2009. 3. 22. 09:34
server.xml

<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    +
    + javarang.net
    +
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
        <Host name="javarang.test" autoDeploy="true" deployOnStartup="true"
            configClass="org.jboss.web.tomcat.security.config.JBossContextConfig"
            deployXML="false">
            <Context path="" docBase="D:\\workspaces\\javarang.test" reloadable="true"/>
            <Alias>www.javarang.test</Alias>
            <Alias>javarang.test</Alias>
            <Valve className="org.jboss.web.tomcat.service.jca.CachedConnectionValve"
                cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager"
                transactionManagerObjectName="jboss:service=TransactionManager" />
            <Valve className="org.apache.catalina.valves.AccessLogValve" prefix="access" suffix=".log"
                fileDateFormat="yyyy-MM-dd"
                pattern="%t [%a] [%l] [%m] [%U] [%H] [%q] [%s] [%b] [%{User-Agent}i] [%{Referer}i]"
                directory="D:\\workspaces\\javarang.test\\logs"/>
        </Host>

jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
  <security-domain flushOnSessionInvalidation="false"/>
  <context-root>/</context-root>
  <virtual-host>javarang.test</virtual-host>
</jboss-web>
Posted by 아주 오래된 미래
<?xml version="1.0" encoding="utf-8"?>
<project name="Flex3 SDK Sample" default="all" basedir="../">
<taskdef resource="flexTasks.tasks" classpath="${basedir}/ant/flexTasks.jar" />

<property name="src"            value="${basedir}/src"/>
<property name="build"          value="${basedir}/deploy"/>
<property name="config"         value="${basedir}/ant/config"/>
<property name="FLEX_HOME"      value="D:/flex_sdk_3"/>
<property name="targetbuild"    value="C:/Tomcat/webapps/JavarangFlex/resources/flex3"/>

<target name="all">
    <antcall target="JavarangFlex"/>
</target>
<target name='JavarangFlex'>
    <property name='targetsrc' value='${src}' />
    <property name='targetbuild' value='${targetbuild}' />
    <property name='targetconfig' value='${config}' />

    <mxmlc file='${targetsrc}/Sample.mxml'
        output='${targetbuild}/Sample.swf'
        actionscript-file-encoding='UTF-8'
        optimize="true" debug="false"
        services='${config}/services-config.xml'>

        <load-config filename='${FLEX_HOME}/frameworks/flex-config.xml'/>
        <context-root>JavarangFlex</context-root>
        <source-path path-element='${FLEX_HOME}/frameworks'/>

        <compiler.library-path dir='${FLEX_HOME}/frameworks' append='true'>
            <include name='libs'/>
            <!--include name="${localePath}"/-->
        </compiler.library-path>
    </mxmlc>
</target>
</project>

Posted by 아주 오래된 미래
04.IT Knowledge/Java2009. 1. 1. 18:56
Posted by 아주 오래된 미래
04.IT Knowledge/SAS2008. 12. 31. 16:06
filename ff pipe 'dir /p' ;

data _null ;
  infile ff;
  input ;
  put _infile_ ;
  a = _infile_ ;
run;
Posted by 아주 오래된 미래
04.IT Knowledge/SAS2008. 12. 31. 16:02
%macro tttt;
data _null_;
aa=pathname("work");
put aa=;
run;
%mend tttt;
%tttt;
Posted by 아주 오래된 미래