Mercurial > hg > Members > tatsuki > JungleXMLReader
comparison src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java @ 23:a9dc4ffd1f52
add stringPathToIdTest and Method
author | one |
---|---|
date | Mon, 27 Oct 2014 10:40:29 +0900 |
parents | b6b5e3f48988 |
children | 96b9017b0e44 |
comparison
equal
deleted
inserted
replaced
22:b6b5e3f48988 | 23:a9dc4ffd1f52 |
---|---|
19 public class JuGrix { | 19 public class JuGrix { |
20 | 20 |
21 JungleTree personTree; | 21 JungleTree personTree; |
22 JungleTree organizationTree; | 22 JungleTree organizationTree; |
23 JungleTree roleTree; | 23 JungleTree roleTree; |
24 JungleTree rdeTree; | |
24 public JuGrix(){ | 25 public JuGrix(){ |
25 try{ | 26 try{ |
26 loadXml reader = new loadXml(); | 27 loadXml reader = new loadXml(); |
27 personTree = reader.loadTestData("Person.xml"); | 28 personTree = reader.loadTestData("Person.xml"); |
28 organizationTree = reader.loadTestData("Organization.xml"); | 29 organizationTree = reader.loadTestData("Organization.xml"); |
29 roleTree = reader.loadTestData("Role.xml"); | 30 roleTree = reader.loadTestData("Role.xml"); |
31 rdeTree = reader.loadTestData("RoleDescriptionElement.xml"); | |
30 } catch (Exception e) { | 32 } catch (Exception e) { |
31 e.printStackTrace(); | 33 e.printStackTrace(); |
32 } | 34 } |
33 } | 35 } |
34 | 36 |
720 parentIds.add(id); | 722 parentIds.add(id); |
721 parentIds.addAll(_deepParentOrganizationIds(id,filterIds)); | 723 parentIds.addAll(_deepParentOrganizationIds(id,filterIds)); |
722 return parentIds.iterator(); | 724 return parentIds.iterator(); |
723 } | 725 } |
724 | 726 |
727 public String stringPathToId(String args) { | |
728 String[] splitPath = args.split(":"); | |
729 | |
730 String str = splitPath[2]; | |
731 for (int count = 3; count < splitPath.length;count++) { | |
732 str = str + ":" + splitPath[count]; | |
733 } | |
734 | |
735 final String StrPath = str; | |
736 | |
737 InterfaceTraverser traverser = null; | |
738 TreeNode root = null ; | |
739 if (splitPath[0].equals("r")) { | |
740 traverser = roleTree.getTraverser(); | |
741 root = roleTree.getRootNode(); | |
742 } | |
743 if (splitPath[0].equals("rde")) { | |
744 traverser = rdeTree.getTraverser(); | |
745 root = rdeTree.getRootNode(); | |
746 } | |
747 | |
748 Iterator<Pair<TreeNode,NodePath>> idIterator = traverser.find( | |
749 (TreeNode node) -> { | |
750 String element = node.getAttributes().getString("element"); | |
751 if (element == null) | |
752 return false; | |
753 if (!element.equals("path")) | |
754 return false; | |
755 String pathString = node.getAttributes().getString("text"); | |
756 if (pathString == null) | |
757 return false; | |
758 if (pathString.equals(StrPath)) | |
759 return true; | |
760 return false; | |
761 }); | |
762 | |
763 if (!idIterator.hasNext()) | |
764 return ""; | |
765 | |
766 Pair<TreeNode, NodePath> nodePair = idIterator.next(); | |
767 NodePath path = nodePair.right(); | |
768 NodePath targetPath = path.last().right(); | |
769 | |
770 TreeNode targetNode = getTarget(root, targetPath); | |
771 String targetId = targetNode.getAttributes().getString("id"); | |
772 return targetId; | |
773 } | |
774 | |
725 | 775 |
726 | 776 |
727 | 777 |
728 | 778 |
729 | 779 |