2009年9月28日月曜日

Google Chrome OS Betaがダウンロード可能になったので試してみる。

参考ページ

手順は大まかに
 1.isoイメージのダウンロード
 2.LiveCDの作成
 3.HDDを抜いておく
 4.LiveCDの起動
 5.USB(4GB)にインストール
で順調に進んでくれればいいなと思っている。特に工程の5が。

2009年9月25日金曜日

boost c++のインストール(UNRでの場合)

boost c++のダウンロード

解凍してディレクトリに入る

$ ./bootstrap.sh --prefix=/usr/ --with-libraries=all
$ sudo ./bjam install

/usr/includeにboostというディレクトリが作成され、/usr/libにlibboost_regex.aのようなboost関係の静的ライブラリが作られる。

環境変数に
 CPLUS_INCLUDE_PATH=/usr/include
 LD_LIBRARY_PATH=/usr/lib
を追加

2009年9月10日木曜日

Chromiumの拡張機能について

参考ページ

9月10日。どうやら拡張機能のAPIの準備が整ったようだ。ただし、冒頭にこんな文がある。

原文:This tutorial requires Windows. You can try it on Linux and OS X, and it might work, but the extensions support is less stable on those platforms. We're working hard to bring them up to speed.

訳:このチュートリアルはWindows向けです。Linux,Macでは、もしかしたら何とかできるかもしれませんが、基本まだ無理です。できるようになるように頑張ってます。

頑張ってください。期待して待ってます。

2009年9月9日水曜日

GAE/Jでのformについて

  <form action="/write" method="post" enctype="multipart/form-data">
<input type="text" name="userid" />
<input type="submit" value="push" />
</form>

enctypeでスラッシュを使うとなぜかrequest.getParameter("○○○");でデータの取得が出来ない。
  <form action="/write" method="post" enctype="multipart-form-data">
<input type="text" name="userid" />
<input type="submit" value="push" />
</form>

enctypeでハイフンを使うとrequest.getParameter("○○○");でデータの取得ができる。

何でなんだろうか?

2009年8月23日日曜日

GAE/Jでアップロードした画像をデータストアに保存し、imgタグに出力する

upload.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>TEMPLATE</title>
</head>
<body>
<form action="/upload" method="post" enctype="multipart/form-data">
アップロードするファイル : <input type="file" name="imgfile" /><br>
<input type="submit" value="upload" />
</form>
<img src="/indication" alt="imgfile" />
</body>
</html>
UploadTest.javaにアップロードしたファイルをPostリクエストで送信
package org.test;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import org.test.DataStImg;
import org.test.PMF;

public class UploadTest extends HttpServlet {
private static final Logger log =
Logger.getLogger(UploadTest.class.getName());

public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

PersistenceManager pm = PMF.get().getPersistenceManager();
final int size = 50000;
try{
ServletFileUpload upload = new ServletFileUpload();
upload.setSizeMax(size);//50KBの制限

FileItemIterator iterator = upload.getItemIterator(req);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream stream = item.openStream();

if(item.isFormField()){
log.warning("Got a form field: " + item.getFieldName());
} else {
log.warning("Got an uploaded file: " + item.getFieldName() +
", name = " + item.getName());
//ここからが大変だった。
ByteArrayOutputStream out = new ByteArrayOutputStream();
int len;
int i = 0;
byte[] buffer = new byte[1024];
while( (len = stream.read(buffer, 0, buffer.length)) != -1){
out.write(buffer, 0, len);

}
byte[] b = out.toByteArray();

//直す気力ないけどファイル名を取得して
//contentに入れればファイル名をキーに画像を呼び出せる。
String content = "content";
DataStImg ds = new DataStImg(content, b);
pm.makePersistent(ds);
pm.close();

resp.sendRedirect("/html/upload.html");
}
}
}
catch(Exception ex){
throw new ServletException(ex);
}
}
}
package org.test;

import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Blob;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class DataStImg {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;

@Persistent
private Blob blob;

@Persistent
private String content;

public DataStImg(String content, byte[] buffer) {
blob = new Blob(buffer);
this.content = content;
System.out.println("In DataStImg");
}

public Long getId() {
return id;
}

public byte[] getImg() {
return blob.getBytes();
}

public String getContent() {
return content;
}

public void setImg(byte[] buffer) {

this.blob = blob;
}

public void setContent(String content) {
this.content = content;
}

}
Google app engineのFAQのところにあったコードを参考に作成。DataStImg.javaに画像データを保存し、再びupload.htmlにリダイレクト。imgタグsrc属性にservletを呼び出すためのURLを指定しておく。IndicationImg.javaにGETリクエストが送信される。
package org.test;

import java.util.List;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
import javax.jdo.PersistenceManager;
import org.test.DataStImg;
import org.test.PMF;

public class IndicationImg extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
resp.setContentType("image/png");
PersistenceManager pm = PMF.get().getPersistenceManager();

try {
String query = "select from " + DataStImg.class.getName();
List dss = (List) pm.newQuery(query).execute();
if (dss.isEmpty()) {
resp.sendRedirect("/html/upload.html");
} else {
for (DataStImg ds : dss) {
byte[] b = ds.getImg();
BufferedInputStream in = new BufferedInputStream(
new ByteArrayInputStream(b));

ServletOutputStream out = resp.getOutputStream();
int len;
while( (len = in.read(b, 0, b.length)) != -1) {
out.write(b, 0, len);
}

out.close();
in.close();
//まずは何番目の画像とか細かいこと考えず、
//とにかく最初に入れた画像を表示する
break;
}
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
pm.close();
}
}
}
これで画像が表示される。

2009年8月22日土曜日

GAE/Jでのファイルアップロードについて

参考ページ(参考にしたソースコード)
参考ページ(使用できるフレームワークについての情報)
参考ページ(Apache Commons FileUploadについて)から1.2.1.tar.gzをダウンロードし、解凍。
できたフォルダから/commons-fileupload-1.2.1/lib/commons-fileupload-1.2.1.jarを/google/appengine/mydirectory/war/WEB-INF/lib/にコピー。
UploadTest.java
package org.test;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import java.util.logging.Logger;


public class UploadTest extends HttpServlet {
private static final Logger log =
Logger.getLogger(UploadTest.class.getName());

public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try{
ServletFileUpload upload = new ServletFileUpload();
resp.setContentType("image/png");

FileItemIterator iterator = upload.getItemIterator(req);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream stream = item.openStream();

if(item.isFormField()){
log.warning("Got a form field: " + item.getFieldName());
} else {
log.warning("Got an uploaded file: " + item.getFieldName() +
", name = " + item.getName());
int len;
byte[] buffer = new byte[8192];
while((len = stream.read(buffer, 0, buffer.length)) != -1){
resp.getOutputStream().write(buffer, 0, len);
}
}
}
}
catch(Exception ex){
throw new ServletException(ex);
}
}
}
upload.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Upload</title>
</head>
<body>
<form action="/upload" method="post" enctype="multipart/form-data">
アップロードするファイル : <input type="file" name="imgfile" /><br>
<input type="submit" value="upload" />
</form>
</body>
</html>

2009年8月11日火曜日

chromiumをUSBブートのlxubuntuで使用してみて

Firefoxと比較して圧倒的に起動・動作共に早い。ただし、かなり不安定ではある。特にGoogleのサービスを使用しようとログインを試みると高頻度で落ちる。異常な終了をした場合、前のセッションを復元する機能があるため大きな問題になることはなかった。

少なくとも、USBブートをしている限りはFirefoxより圧倒的にパフォーマンスは良い。セキュリティに関する部分は間情報が少なく未知数で、情報が出揃ってくるまでは危ないサイトにはいかないようにすべき。

拡張機能は現段階では使用不能?