source: trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/JFCReplayIDValidator.java @ 806

Last change on this file since 806 was 806, checked in by fglaser, 12 years ago
  • new helper class JFCReplayIDValidator added, that is able to extract all IDs from

GUITAR Gui file and to check if a given (generated) replayID is contained in this GUI file.

  • JFCReplayIDCalculator modified for test purposes (can be initialized with a Validator

to check if IDs that are generated "on the way" are valid)

  • Test Case extended for JFCReplayIDCalculator extended
  • extended guimapping for freemind
  • added new JFCReplayIDCalculator test ressources
  • Property svn:mime-type set to text/plain
File size: 2.0 KB
Line 
1package de.ugoe.cs.quest.plugin.jfc;
2
3import java.io.File;
4import java.io.IOException;
5import java.util.HashSet;
6import java.util.Set;
7
8import javax.xml.parsers.DocumentBuilder;
9import javax.xml.parsers.DocumentBuilderFactory;
10import javax.xml.parsers.ParserConfigurationException;
11
12import org.w3c.dom.Document;
13import org.w3c.dom.Node;
14import org.w3c.dom.NodeList;
15import org.xml.sax.SAXException;
16
17public class JFCReplayIDValidator {
18        private Set<String> validIds = null;
19       
20        public JFCReplayIDValidator(File guitarEfgFile) throws ParserConfigurationException, SAXException, IOException{
21                this.initialize(guitarEfgFile);
22        }
23       
24        public void initialize(File guitarGUIFile) throws ParserConfigurationException, SAXException, IOException{
25                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
26                DocumentBuilder builder = factory.newDocumentBuilder();
27                Document freemindGUI = builder.parse(guitarGUIFile);
28       
29                validIds = new HashSet<String>();
30               
31                NodeList guis = freemindGUI.getFirstChild().getChildNodes();
32                for (int i = 0; i < guis.getLength(); i++)
33                        extractIDs(guis.item(i));
34        }
35       
36        private void extractIDs(Node node){
37                NodeList children = node.getChildNodes();
38                if (children != null){
39                        for (int j = 0; j < children.getLength(); j++){
40                                if (children.item(j).getNodeName().equals("Attributes")){
41                                        NodeList properties = children.item(j).getChildNodes();
42                                        for (int i = 0; i < properties.getLength(); i++){
43                                                NodeList property = properties.item(i).getChildNodes();
44                                                for (int k = 0; k < property.getLength(); k++){
45                                                        if (property.item(k).getTextContent().equals("ID")){
46                                                                validIds.add(property.item(k+2).getTextContent());
47                                                        }
48                                                }
49                                        }
50                                }
51                                else{
52                                        extractIDs(children.item(j));
53                                }
54                        }
55                }
56        }
57       
58
59        public boolean validateReplayID(String replayID){
60                if (validIds == null || validIds.size() == 0)
61                        throw new IllegalStateException("There are no valid IDs known, call initialize first.");
62               
63                if (validIds.contains(replayID))
64                        return true;
65               
66                return false;
67               
68        }
69}
Note: See TracBrowser for help on using the repository browser.