Mercurial > hg > Members > tatsuki > JungleXMLReader
changeset 43:1bdd50e26fac
Merge with 037731e99d6e876ecc1ef2d921d2ce5f71974376
author | one |
---|---|
date | Tue, 25 Nov 2014 12:12:17 +0900 |
parents | c036d36c33af (current diff) 037731e99d6e (diff) |
children | 5e8eac03fed3 |
files | src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JungleBulletinBoard.java src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/ChildOrganizationIdsTest.java src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/PersonIdsTest.java src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/RoleDescriptionElementIdsTest.java src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/xmlReadTest/SaxTest.java |
diffstat | 4 files changed, 96 insertions(+), 83 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/ac/jp/u_ryukyu/cr/ie/tatsuki/xmlReader/ReadXmlHandler.java Tue Nov 25 11:57:17 2014 +0900 +++ b/src/main/java/ac/jp/u_ryukyu/cr/ie/tatsuki/xmlReader/ReadXmlHandler.java Tue Nov 25 12:12:17 2014 +0900 @@ -15,118 +15,124 @@ import org.xml.sax.*; import org.xml.sax.helpers.*; - public class ReadXmlHandler extends DefaultHandler { - private JungleTree tree; - private JungleTreeEditor editor; - private NodePath path; + private JungleTree tree; + private JungleTreeEditor editor; + private NodePath path; private String elementName; - - public ReadXmlHandler(JungleTree tree){ - this.tree = tree; - this.editor = tree.getTreeEditor(); - this.path = new DefaultNodePath().add(-1); - } - - @Override - public void startElement(String uri, String localName,String qName, Attributes attributes) { - Pair<Integer, NodePath> nodePair = path.last(); - path = nodePair.right(); - int num = nodePair.left() + 1; - - Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, num); - if (either.isA()) { - //error - } - this.editor = either.b(); - - path = path.add(num); - //System.out.println(path.toString()); + + public ReadXmlHandler(JungleTree tree) { + this.tree = tree; + this.editor = tree.getTreeEditor(); + this.path = new DefaultNodePath().add(-1); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) { + Pair<Integer, NodePath> nodePair = path.last(); + path = nodePair.right(); + int num = nodePair.left() + 1; - - if (uri != "") { - // System.out.println("namespaceURI= " + uri); - } + Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, num); + if (either.isA()) { + // error + } + this.editor = either.b(); - if (localName != "") { - // System.out.println("localName= " + localName); - } + path = path.add(num); + // System.out.println(path.toString()); + + if (uri != "") { + // System.out.println("namespaceURI= " + uri); + } + + if (localName != "") { + // System.out.println("localName= " + localName); + } if (qName != "") { - // System.out.println("qName= " + qName); + // System.out.println("qName= " + qName); elementName = qName; - Either<Error, JungleTreeEditor> newEither = editor.putAttribute(path, "element", ByteBuffer.wrap(qName.getBytes())); + Either<Error, JungleTreeEditor> newEither = editor.putAttribute(path, "element", + ByteBuffer.wrap(qName.getBytes())); if (newEither.isA()) { - //error + // error } this.editor = newEither.b(); } if (attributes.getLength() != 0) { - for (int count = 0 ;attributes.getLength() > count; count++) { - // System.out.println(attributes.getLocalName(count) + " = " + attributes.getValue(count)); + for (int count = 0; attributes.getLength() > count; count++) { + // System.out.println(attributes.getLocalName(count) + " = " + + // attributes.getValue(count)); String key = elementName + "-" + attributes.getLocalName(count); String value = attributes.getValue(count); ByteBuffer bValue = ByteBuffer.wrap(value.getBytes()); - Either<Error, JungleTreeEditor> newEither = editor.putAttribute(path,key , bValue); + Either<Error, JungleTreeEditor> newEither = editor.putAttribute(path, key, bValue); if (newEither.isA()) { - //error + // error } this.editor = newEither.b(); } } - path = path.add(-1); - } + path = path.add(-1); + } - @Override - public void characters(char[] ch, int start, int length) { - String str = new String(ch, start, length); - Pattern pattern = Pattern.compile("\n"); - Matcher macher = pattern.matcher(str); - - if (!macher.find()) { + @Override + public void characters(char[] ch, int start, int length) { + String str = new String(ch, start, length); + Pattern pattern = Pattern.compile("\n"); + Matcher macher = pattern.matcher(str); + + if (!macher.find()) { + + String[] splitStrs = str.split(" "); + for (String splitStr : splitStrs) { + Pair<Integer, NodePath> nodePair = path.last(); NodePath onePath = nodePair.right(); - //System.out.println(str); - Either<Error, JungleTreeEditor> newEither = editor.putAttribute(onePath, "text-" + elementName, ByteBuffer.wrap(str.getBytes())); + Either<Error, JungleTreeEditor> newEither = editor.putAttribute(onePath, "text-" + elementName, + ByteBuffer.wrap(splitStr.getBytes())); if (newEither.isA()) { - //error + // error } this.editor = newEither.b(); + + } } - } + } - @Override - public void endElement(String namespaceURI, String localName, String qName) { - path = path.tail(); - if (namespaceURI != "") { - // System.out.println("namespaceURI= " + namespaceURI); - } - if (localName != "") { - // System.out.println("localName= " + localName); - } - - if (qName != "") { - // System.out.println("qName= " + qName); - } - } + @Override + public void endElement(String namespaceURI, String localName, String qName) { + path = path.tail(); + if (namespaceURI != "") { + // System.out.println("namespaceURI= " + namespaceURI); + } + if (localName != "") { + // System.out.println("localName= " + localName); + } - @Override - public void startDocument() { - // System.out.println("start"); - } + if (qName != "") { + // System.out.println("qName= " + qName); + } + } + + @Override + public void startDocument() { + // System.out.println("start"); + } - @Override - public void endDocument() { - Either<Error, JungleTreeEditor> either = editor.success(); - if (either.isA()) { - //error - } - // System.out.println("end"); - } + @Override + public void endDocument() { + Either<Error, JungleTreeEditor> either = editor.success(); + if (either.isA()) { + // error + } + // System.out.println("end"); + } - public JungleTree getTree(){ - return tree; - } + public JungleTree getTree() { + return tree; + } }
--- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/GetAttributeImp.java Tue Nov 25 11:57:17 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/GetAttributeImp.java Tue Nov 25 12:12:17 2014 +0900 @@ -1,5 +1,7 @@ package jp.ac.u_ryukyu.cr.ie.tatsuki.bbs; +import java.util.Iterator; + import fj.data.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; @@ -10,7 +12,7 @@ node = _node; } - public String getMessage(String key) { + public Iterator<String> getMessage(String key) { return node.getAttributes().getString(key); }
--- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/ShowBoardsServletMatrix.java Tue Nov 25 11:57:17 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/ShowBoardsServletMatrix.java Tue Nov 25 12:12:17 2014 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.cr.ie.tatsuki.bbs; import java.io.PrintWriter; +import java.util.Iterator; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest;
--- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/ShowMatrix.java Tue Nov 25 11:57:17 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/ShowMatrix.java Tue Nov 25 12:12:17 2014 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.cr.ie.tatsuki.bbs; import java.io.PrintWriter; +import java.util.Iterator; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -89,7 +90,10 @@ List<String> keys = attribute.getKeys(); for (String key : keys) { - _pw.write(key + " : " + bbs.sanitize(attribute.getMessage(key)) + "<br>"); + Iterator<String> attributeIterator = attribute.getMessage(key); + for (;attributeIterator.hasNext();) { + _pw.write(key + " : " + bbs.sanitize(attributeIterator.next()) + "<br>"); + } }