2016년 1월 29일 금요일

[Bootstrap] :: Bootstrap Modal Styling for header.

Bootstrap modal를 그대로 사용해도 나름 깔끔하지만 Header부분에 상황에 따라서 색상으로 표현을 해주고 싶어서 CSS로 적용한것을 남겨두려 한다.

CSS file

.modal-primary-header {
    color: #fff;
    background-color: #337ab7;
    border-color: #2e6da4;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;

}

HTML File
<!-- Modal -->
    <div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header modal-primary-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel"><span class="glyphicon glyphicon-info-sign"></span> Purchase Order</h4>
                       </div>
                    <div class="modal-body">
                        <label>Are you sure?</label>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-success">OK</button>
                        <button type="button" class="btn btn-danger" data-dismiss="modal" aria-hidden="true">Cancel</button>
                    </div>
                </div>
                    <!-- /.modal-content -->
            </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->

출력화면

[JAVA] :: JAVA에서 간단히 URL 파일 다운로드 방법

Java에서 정말 간단하게 URL파일을 다운 받을때 사용하면 좋은거 같아서 남겨두려 한다.

코드는 이게 끝이다.
try(InputStream in = new URL(fileURL).openStream()){
     Files.copy(in, Paths.get("저장할 파일 경로 및 파일명+".파일 확장자"),     StandardCopyOption.REPLACE_EXISTING);

}

이상이다.

[JAVA] :: Jsoup을 이용한 HTML페이지 Parsing

최근에 HTML페이지를 Parsing하여 페이지 이미지를 추출해 컴퓨터에 저장하는 일이 생겨

찾아보다가 알게된 Jsoup에 사용법에 대해 남겨 놓으려고 한다.

pom.xml
<dependency>
  <!-- jsoup HTML parser library @ http://jsoup.org/ -->
  <groupId>org.jsoup</groupId>
  <artifactId>jsoup</artifactId>
  <version>1.8.3</version>

</dependency>

최신버전으로 Maven pom에 등록후 사용이 가능하다.

Document doc = Jsoup.connect(url)
   .timeout(0)
   .ignoreContentType(true)
   .get();

을 호출하면 Document Object로 HTML코드들이 반환된다.

String imgUrl = doc.select("#IMG1").attr("src");

추출하고자하는 HTML field의 ID or Tag name or css등으로 원하는 부분을 Select할 수 있다.

그리고 해당 태그의 속성의 값만을 추출할 수도있다 .attr을 사용함으로써.

끝이다. 매우 간단하다..

몇몇 사이트는 페이지를 Jsoup로 호출하면 416 에러가 발생하면서 robot으로 인식하여 페이지 접근을 막아놓은 사이트들이 있다.

그럴땐 .userAgent("로봇이름") 으로 증명하면된다. 왠만하면 나는 google robot입니다 라고 보내면 거의다 통과된다.

Jsoup를 이용하여 로그인후 이용해야하는 페이지 역시 Parsing할 수있다.
.data("필드 이름","필드 값"); 을 사용하면 접근이 가능하다.

이상이다. 

2016년 1월 21일 목요일

[Apache Tomcat] :: Openssl 설정 방법.

http://whiteship.me/?p=13548

[Android] :: bluetooth keyboard 연결시 화면 갱신 문제.

bluetooth keyboard 연결시 Activity가 갱신되는 문제가 발생하게 되어 찾다 찾다 보니

매우 간단하게 해결 할 수 있는 방법이 나왔다.

AndroidManifest.xml 파일안에 <activity tag에 
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout"

를 추가해주면 해결.. 이거때문에.. 구글링을 엄청했었는데.. 너무 허무하다..


[Spring Framework] :: Spring 4 + JasperReports + JsonDataSource Step 1.

pom.xml

<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.5</version>
</dependency>

<dependency>
<groupId>net.sf.barcode4j</groupId>
<artifactId>barcode4j</artifactId>
<version>2.1</version>
</dependency>

<dependency>
    <groupId>batik</groupId>
    <artifactId>batik-bridge</artifactId>
    <version>1.6-1</version>

</dependency>

WebConfig.java

@Bean // Jasper preview bean Set.
public JasperReportsViewResolver getJasperReportsViewResolver() {
  final JasperReportsViewResolver resolver = new JasperReportsViewResolver();
  resolver.setPrefix("/resources/jasper/");
  resolver.setSuffix(".jrxml");
  resolver.setReportDataKey("datasource");
  resolver.setViewNames("report_*"); // .jrxml file name & call name
  resolver.setViewClass(JasperReportsMultiFormatView.class);
  resolver.setOrder(0);
  return resolver;
}

//preview sample code
@RequestMapping(value = "test-report", method = RequestMethod.GET)
public String companyList(final Model model) {
try {
Gson gson = new Gson();
testModel tt = new testModel();
tt.setTitle("Hello");
tt.setBarcode("HY12000");
tt.setUsers(sserService.findAllUsers());
InputStream is = new ByteArrayInputStream(gson.toJson(tt).getBytes());
JsonDataSource dataSource = new JsonDataSource(is, "");
model.addAttribute("datasource", dataSource);
model.addAttribute("format", "pdf"); // preview type
return "report_testreoprt" // return .jrxml file name
} catch (JRException e) {
e.printStackTrace();
return "report_testreoprt"; // return .jrxml file name
}

}

//file Output code.
@Override
public void testPDFDownload(final String jsonData) throws JRException, IOException {
JasperDesign jasperDesign;
JasperPrint jasperPrint;
Resource resource = new ClassPathXmlApplicationContext().getResource("classpath:static/jasper/tesy.jrxml");
InputStream is = new ByteArrayInputStream(jsonData.getBytes());
jasperDesign = JRXmlLoader.load(resource.getInputStream());
JasperReport jasperReport  = JasperCompileManager.compileReport(jasperDesign);
JsonDataSource dataSource = new JsonDataSource(is, "");
jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(),
dataSource);
//exportType
JasperExportManager.exportReportToPdfFile(jasperPrint,
"src/main/resources/static/jasper/report.pdf");
}


[Spring Framework] :: Spring Boot file upload with Ajax | Netgloo Blog

Spring Boot file upload with Ajax | Netgloo Blog

2016년 1월 18일 월요일

[Spring Framework] :: Spring4 Boot Email Setting

Spring Boot을 사용하면서 많은 것들이 달라져서 잊어 먹지 않고자 여기에 정리를 해두려 한다.

Boot을 사용하기 이전에는 Mail Config File을 Xml파일로 셋팅 후 Spring Config에 설정해주어야 했지만

이제는 Boot에서 application.properties파일에 간단하게 설정이 가능해졌다.

방법은 아래와 같다.

우선 pom.xml에 dependency를 추가해준다.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>

</dependency>

그 후 application.properties에 아래와 같이 셋팅해준다.
spring.mail.host=smtp.gmail.com
spring.mail.port=465
spring.mail.username=xxxxx@gmail.com
spring.mail.password=xxxxx
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.ssl.enable = true

spring.mail.properties설정은 옵션이다 메일서버에 따라서 해줘야 할 경우도 있고 안해줘도 될 경우가 있다.

그 후 이제 바로 사용이 가능하다.

필자의 경우는 Service를 따로 만들어 사용하고 있다.

@Service("emailSendService")
public class EmailSendServiceImpl implements EmailSendService {

@Autowired
private JavaMailSender mailSender;

@Override
public void send(final String fromMail, final String toMail, final String mailTitle
                              , final String message) {
        SimpleMailMessage email = new SimpleMailMessage();
        email.setFrom(fromMail);
        email.setTo(toMail);
        email.setSubject(mailTitle);
       email.setText(message);
       mailSender.send(email);
    }
}

끝이다. 이전보다 매우 간단해졌다.

이상..

2016년 1월 17일 일요일

[Android Lib] Butter Knife(1) - Setting

안드로이드 개발할때 매우 필수적으로 이용하고 있는 Butter Knife 사용법을 정리 해놓고자 한다.

Butter Knife는 안드로이드 View 및 View Event들에 대한 Annotation을 제공해줌으로써

코드를 매우 간결하게 작성할수 있도록 도와준다.

우선 Butter Knife를 이용하기 위해서는 Gradle에 아래 내용을 추가해주어야 한다.



compile 'com.jakewharton:butterknife:7.0.1'
그리고 사용하고자 하는 Active 및 Fragment에 아래와 같이 작성한다.

class ExampleActivity extends Activity {
  @Bind(R.id.title) TextView title;
  @Bind(R.id.subtitle) TextView subtitle;
  @Bind(R.id.footer) TextView footer;

  @Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_activity);
    ButterKnife.bind(this);
    // TODO Use fields...
  }
}
public class FancyFragment extends Fragment {
  @Bind(R.id.button1) Button button1;
  @Bind(R.id.button2) Button button2;

  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fancy_fragment, container, false);
    ButterKnife.bind(this, view);
    // TODO Use fields...
    return view;
  } @Override public void onDestroyView() {
    super.onDestroyView();
    ButterKnife.unbind(this);
  }
}
사용 하고자 하는 View에 대해서는 @Bind로 ID를 명시해주면 바로 사용이 가능하다 이제는 예전처럼 findViewById를 사용하지 않아도 바로 한줄 만으로 View를 사용 할 수 있게 되었으니 세상이 얼마나 좋아 지지 않았는가.
다음 포스팅은 이벤트별 Annotation에 대해 남겨놓으려 한다.

2016년 1월 16일 토요일

[Android Code] Gson TypeToken example.


ArrayList Type
1
2
3
Gson gson = new Gson();
Type type = new TypeToken<List<YourClass>>(){}.getType();
List<YourClass> arryList = gson.fromJson(JsonDataString, type);
cs

Map Type
1
2
3
Gson gson = new Gson();
Type type = new TypeToken<Map<Object, Object>>(){}.getType();
Map<Object, Object> mapObject = gson.fromJson(JsonDataString, type);

[Android Lib] Gson

Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of.
There are a few open-source projects that can convert Java objects to JSON. However, most of them require that you place Java annotations in your classes; something that you can not do if you do not have access to the source-code. Most also do not fully support the use of Java Generics. Gson considers both of these as very important design goals.
Gson Goals
  • Provide simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa
  • Allow pre-existing unmodifiable objects to be converted to and from JSON
  • Extensive support of Java Generics
  • Allow custom representations for objects
  • Support arbitrarily complex objects (with deep inheritance hierarchies and extensive use of generic types)
Gson Downloads
Gson Documentation
  • Gson API: Javadocs for the current Gson release
  • Gson user guide: This guide contains examples on how to use Gson in your code.
  • Gson Roadmap: Details of changes in the recent versions
  • Gson design document: This document discusses issues we faced while designing Gson. It also include a comparison of Gson with other Java libraries that can be used for Json conversion
Please use the google-gson Google group to discuss Gson, or to post questions.
Gson-related Content Created by Third Parties
License
Gson is released under the Apache 2.0 license.

[ Android Lib] FButton

[ Android Lib] FButton
FButton is a custom Button of Android with "Flat UI" concept. FButton's design get inspiration from designmono. This library is very small and highly customizable.

Screenshot


Link
https://github.com/hoang8f/android-flat-button


[Android App] :: PowerBall Maker v1.0

PowerBall Maker v1.0

Good Luck !!

powerball number generator.

Download link

 


[XBMC] Kodi Ondemandkorea addon 0.5.7

안녕하세요. 개발자 분께서 XBMC OnDemandkorea Addon 0.5.7 버전을 업데이트 해주셨네요 :) 모든분들 여기 가셔서 받으시면 될꺼같습니다. 그럼 모두 즐거운 KODI되세요 :)) LINK