Mercurial > hg > Members > shoshi > TreeCMSv1
changeset 52:1b78f1f3add3
changed API in classs Node
author | shoshi |
---|---|
date | Fri, 11 Feb 2011 18:17:15 +0900 |
parents | d4709911e0ed |
children | 7a558c7d4f41 |
files | src/treecms/demo/ContentsTreeBuilder.java src/treecms/proto/api/Node.java src/treecms/proto/cassandra/v1/CassBrowser.java src/treecms/proto/cassandra/v1/CassLink.java src/treecms/proto/cassandra/v1/CassNode.java src/treecms/proto/cassandra/v1/CassTreeImporter.java src/treecms/proto/simple/SimpleLink.java src/treecms/proto/simple/SimpleNode.java src/treecms/proto/test/NodeTest.java |
diffstat | 9 files changed, 50 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/src/treecms/demo/ContentsTreeBuilder.java Fri Feb 11 15:07:57 2011 +0900 +++ b/src/treecms/demo/ContentsTreeBuilder.java Fri Feb 11 18:17:15 2011 +0900 @@ -2,9 +2,6 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileReader; -import java.nio.ByteBuffer; -import java.util.Calendar; import org.apache.commons.codec.binary.Base64; @@ -32,14 +29,14 @@ Node lecture = root.createNode(); y09m12.addChild(lecture); lecture.setTitle("今日はレクチャの日です"); - lecture.setAttribute("layout","Blog/Main/BlogPage"); - lecture.setAttribute("publish_date","2009-12-22-00-00-00"); + lecture.setAttribute("layout","Blog/Main/BlogPage".getBytes()); + lecture.setAttribute("publish_date","2009-12-22-00-00-00".getBytes()); //contents - 2009年12月 - 今日はレクチャの日です - 本文 Node body = root.createNode(); lecture.addChild(body); body.setTitle("本文"); - body.setAttribute("data","今日は二子玉川のオフィスでレイアウトの練習をしています。\n難しそうです。\nたいへんです。\n困ったです。"); + body.setAttribute("data","今日は二子玉川のオフィスでレイアウトの練習をしています。\n難しそうです。\nたいへんです。\n困ったです。".getBytes()); //contents - 2009年12月 - 今日はレクチャの日です - 画像 File picFile = new File("contents/cat.jpeg"); @@ -48,12 +45,10 @@ in.read(buf); in.close(); - String base64 = new String(Base64.encodeBase64(buf)); - Node pic = root.createNode(); lecture.addChild(pic); pic.setTitle("画像"); - pic.setAttribute("data",base64); + pic.setAttribute("data",buf); //contents - 2010年01月 Node y10m01 = root.createNode(); @@ -64,27 +59,27 @@ Node seitai = root.createNode(); y10m01.addChild(seitai); seitai.setTitle("整体"); - seitai.setAttribute("layout","Blog/Main/BlogPage"); - seitai.setAttribute("publish_date","2009-01-05-00-00-00"); + seitai.setAttribute("layout","Blog/Main/BlogPage".getBytes()); + seitai.setAttribute("publish_date","2009-01-05-00-00-00".getBytes()); //contents - 2010年01月 - 整体 - 本文 Node bSeitai = root.createNode(); seitai.addChild(bSeitai); bSeitai.setTitle("本文"); - bSeitai.setAttribute("data","今日は整体の先生のところへ行きました。昨年 11 月に腰を痛めてから、ずっと通っています。歩けなくなったのが 3 日で一応歩けるようになりました。でも朝とか痛いし、重い物もてないし、台所にずっと立ってるのがつらいんです。"); + bSeitai.setAttribute("data","今日は整体の先生のところへ行きました。昨年 11 月に腰を痛めてから、ずっと通っています。歩けなくなったのが 3 日で一応歩けるようになりました。でも朝とか痛いし、重い物もてないし、台所にずっと立ってるのがつらいんです。".getBytes()); //contents - 2010年01月 - 仕事始め Node hajime = root.createNode(); y10m01.addChild(hajime); hajime.setTitle("仕事始め"); - hajime.setAttribute("layout","Blog/Main/BlogPage"); - lecture.setAttribute("publish_date","2009-01-07-00-00-00"); + hajime.setAttribute("layout","Blog/Main/BlogPage".getBytes()); + lecture.setAttribute("publish_date","2009-01-07-00-00-00".getBytes()); //contents - 2010年01月 - 仕事始め - 本文 Node bHajime = root.createNode(); hajime.addChild(bHajime); bHajime.setTitle("本文"); - bHajime.setAttribute("data","なんかひどい一日でした。\n佐野厄除け大師の電車広告によると、今年はなんとか厄みたいなんで、ちょっといやだなぁ。"); + bHajime.setAttribute("data","なんかひどい一日でした。\n佐野厄除け大師の電車広告によると、今年はなんとか厄みたいなんで、ちょっといやだなぁ。".getBytes()); //comments @@ -101,7 +96,7 @@ Node css = root.createNode(); application.addChild(css); css.setTitle("css"); - css.setAttribute("data","#header {background-image: url(/cgi-bin/WebObjects/Atropos_TRAIN.woa/wa/imageP/12606f53c0b);}"); + css.setAttribute("data","#header {background-image: url(/cgi-bin/WebObjects/Atropos_TRAIN.woa/wa/imageP/12606f53c0b);}".getBytes()); return root; }
--- a/src/treecms/proto/api/Node.java Fri Feb 11 15:07:57 2011 +0900 +++ b/src/treecms/proto/api/Node.java Fri Feb 11 18:17:15 2011 +0900 @@ -21,8 +21,8 @@ public String getClassName(); public void setClassName(String _class); - public String getAttribute(String _attr); - public void setAttribute(String _attr,String _value); + public byte[] getAttribute(String _attr); + public void setAttribute(String _attr,byte[] _value); public Set<String> getAttributeKeys(); public void up(Node _child);
--- a/src/treecms/proto/cassandra/v1/CassBrowser.java Fri Feb 11 15:07:57 2011 +0900 +++ b/src/treecms/proto/cassandra/v1/CassBrowser.java Fri Feb 11 18:17:15 2011 +0900 @@ -51,8 +51,8 @@ node.setTitle("fugafuga"); node.setClassName("hogehoge"); - node.setAttribute("fuga","higa"); - node.setAttribute("Title","higa"); + node.setAttribute("fuga","higa".getBytes()); + node.setAttribute("Title","higa".getBytes()); System.out.println(node.getTitle()); @@ -200,12 +200,12 @@ prefix = CHILDREN_DELIM; } - setColumn(_id.toString(),CHILDREN,buf.toString()); + setColumn(_id.toString(),CHILDREN,buf.toString().getBytes()); } public void clearChildren(NodeID _id) { - setColumn(_id.toString(),CHILDREN,""); + setColumn(_id.toString(),CHILDREN,"".getBytes()); } public boolean removeChild(NodeID _id,Node _child) @@ -240,7 +240,7 @@ } if(changed){ - setColumn(_id.toString(),CHILDREN,buf.toString()); + setColumn(_id.toString(),CHILDREN,buf.toString().getBytes()); } return changed; @@ -268,7 +268,7 @@ if(flag){ // setColumn(_id.toString(),CHILDREN,new String(buf.array())); - setColumn(_id.toString(),CHILDREN,buf.toString()); + setColumn(_id.toString(),CHILDREN,buf.toString().getBytes()); } } @@ -297,7 +297,7 @@ } //setColumn(_id.toString(),CHILDREN,new String(buf.array())); - setColumn(_id.toString(),CHILDREN,buf.toString()); + setColumn(_id.toString(),CHILDREN,buf.toString().getBytes()); } public void up(NodeID _id,Node _child) @@ -322,12 +322,12 @@ } String result = buf.toString().substring(1); - setColumn(_id.toString(),CHILDREN,result); + setColumn(_id.toString(),CHILDREN,result.getBytes()); } public void setClassName(NodeID _id,String _className) { - setColumn(_id.toString(),CLASSNAME,_className); + setColumn(_id.toString(),CLASSNAME,_className.getBytes()); } public Node createNode() @@ -409,12 +409,12 @@ public String getClassName(NodeID _id) { - return getColumn(_id.toString(),CLASSNAME); + return new String(getColumn(_id.toString(),CLASSNAME)); } public String getChildrenRaw(NodeID _id) { - String res = getColumn(_id.toString(),CHILDREN); + String res = new String(getColumn(_id.toString(),CHILDREN)); if(res == null){ return ""; } @@ -423,20 +423,20 @@ public String getTitle(NodeID _id) { - return getColumn(_id.toString(),TITLE); + return new String(getColumn(_id.toString(),TITLE)); } public void setTitle(NodeID _id,String _title) { - setColumn(_id.toString(),TITLE,_title); + setColumn(_id.toString(),TITLE,_title.getBytes()); } - public String getAttribute(NodeID _id,String _attr) + public byte[] getAttribute(NodeID _id,String _attr) { return getColumn(_id.toString(),ATTR_PREFIX+_attr); } - public void setAttribute(NodeID _id,String _attr,String _value) + public void setAttribute(NodeID _id,String _attr,byte[] _value) { setColumn(_id.toString(),ATTR_PREFIX+_attr,_value); } @@ -489,17 +489,17 @@ return null; } - private String getColumn(String _row,String _colName) + private byte[] getColumn(String _row,String _colName) { ColumnPath path = new ColumnPath(); path.column_family = m_colFamily; path.column = _colName.getBytes(); - String value = ""; + byte[] value = {0}; try{ ColumnOrSuperColumn column; column = m_cassandra.get(m_keySpace,_row,path,ConsistencyLevel.ALL); - value = new String(column.column.value); + value = column.column.value; }catch(NotFoundException _e){ System.out.println("column not found ["+_row+"]["+_colName+"]"); }catch(Exception _e){ @@ -509,14 +509,14 @@ return value; } - private boolean setColumn(String _row,String _colName,String _value) + private boolean setColumn(String _row,String _colName,byte[] _value) { ColumnPath path = new ColumnPath(); path.column_family = m_colFamily; path.column = _colName.getBytes(); try{ - m_cassandra.insert(m_keySpace,_row,path,_value.getBytes(),System.currentTimeMillis()/1000,ConsistencyLevel.ALL); + m_cassandra.insert(m_keySpace,_row,path,_value,System.currentTimeMillis()/1000,ConsistencyLevel.ALL); return true; }catch(Exception _e){ _e.printStackTrace(); @@ -533,20 +533,20 @@ @Override public Node useContents() { - String uuid = getColumn(TREEINFO,ROOTNODE); + String uuid = new String(getColumn(TREEINFO,ROOTNODE)); NodeID rootID = getTipIDFromUUID(uuid); return new CassNode(this,rootID); } public Node getNode(NodeID m_id) { - String uuid = getColumn(m_id.toString(),LINKUUID); + String uuid = new String(getColumn(m_id.toString(),LINKUUID)); NodeID id = getTipIDFromUUID(uuid); return new CassNode(this,id); } public void setNode(NodeID m_id,NodeID _link) { - setColumn(m_id.toString(),LINKUUID,_link.getUUID()); + setColumn(m_id.toString(),LINKUUID,_link.getUUID().getBytes()); } }
--- a/src/treecms/proto/cassandra/v1/CassLink.java Fri Feb 11 15:07:57 2011 +0900 +++ b/src/treecms/proto/cassandra/v1/CassLink.java Fri Feb 11 18:17:15 2011 +0900 @@ -76,7 +76,7 @@ } @Override - public String getAttribute(String _attr) + public byte[] getAttribute(String _attr) { return getNode().getAttribute(_attr); } @@ -136,7 +136,7 @@ } @Override - public void setAttribute(String _attr,String _value) + public void setAttribute(String _attr,byte[] _value) { getNode().setAttribute(_attr,_value); }
--- a/src/treecms/proto/cassandra/v1/CassNode.java Fri Feb 11 15:07:57 2011 +0900 +++ b/src/treecms/proto/cassandra/v1/CassNode.java Fri Feb 11 18:17:15 2011 +0900 @@ -76,7 +76,7 @@ } @Override - public String getAttribute(String _attr) + public byte[] getAttribute(String _attr) { return getBrowser().getAttribute(m_id,_attr); } @@ -136,7 +136,7 @@ } @Override - public void setAttribute(String _attr, String _value) + public void setAttribute(String _attr,byte[] _value) { getBrowser().setAttribute(m_id,_attr,_value); }
--- a/src/treecms/proto/cassandra/v1/CassTreeImporter.java Fri Feb 11 15:07:57 2011 +0900 +++ b/src/treecms/proto/cassandra/v1/CassTreeImporter.java Fri Feb 11 18:17:15 2011 +0900 @@ -46,7 +46,7 @@ for(String key : node.getAttributeKeys()){ Column attr = new Column(); attr.name = key.getBytes(); - attr.value = node.getAttribute(key).getBytes(); + attr.value = node.getAttribute(key); columns.add(packColumn(attr)); }
--- a/src/treecms/proto/simple/SimpleLink.java Fri Feb 11 15:07:57 2011 +0900 +++ b/src/treecms/proto/simple/SimpleLink.java Fri Feb 11 18:17:15 2011 +0900 @@ -152,13 +152,13 @@ } @Override - public String getAttribute(String _attr) + public byte[] getAttribute(String _attr) { return getTip().getAttribute(_attr); } @Override - public void setAttribute(String _attr,String _value) + public void setAttribute(String _attr,byte[] _value) { getTip().setAttribute(_attr,_value); }
--- a/src/treecms/proto/simple/SimpleNode.java Fri Feb 11 15:07:57 2011 +0900 +++ b/src/treecms/proto/simple/SimpleNode.java Fri Feb 11 18:17:15 2011 +0900 @@ -1,16 +1,16 @@ package treecms.proto.simple; import java.util.Iterator; + import java.util.Collections; import java.util.List; import java.util.LinkedList; import java.util.Map; import java.util.Set; - import treecms.proto.api.Link; import treecms.proto.api.Node; import treecms.proto.api.NodeID; -import java.util.Hashtable; +import java.util.HashMap; class SimpleNode implements Node { @@ -18,7 +18,7 @@ private NodeID m_id; private String m_title,m_class; - private Map<String,String> m_attrs; + private Map<String,byte[]> m_attrs; SimpleNode(NodeID _id) { @@ -28,7 +28,7 @@ m_title = ""; m_class = ""; - m_attrs = new Hashtable<String,String>(); + m_attrs = new HashMap<String,byte[]>(); } @Override @@ -157,13 +157,13 @@ } @Override - public String getAttribute(String _attr) + public byte[] getAttribute(String _attr) { return m_attrs.get(_attr); } @Override - public void setAttribute(String _attr, String _value) + public void setAttribute(String _attr,byte[] _value) { m_attrs.put(_attr,_value); }
--- a/src/treecms/proto/test/NodeTest.java Fri Feb 11 15:07:57 2011 +0900 +++ b/src/treecms/proto/test/NodeTest.java Fri Feb 11 18:17:15 2011 +0900 @@ -158,7 +158,7 @@ { String key = "test"; String value = "value"; - m_node.setAttribute(key,value); + m_node.setAttribute(key,value.getBytes()); Assert.assertEquals(true,value.equals(m_node.getAttribute(key))); }