// Copyright 2012 Georg-August-Universität Göttingen, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package de.ugoe.cs.autoquest.plugin.html; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.xml.sax.SAXException; import de.ugoe.cs.autoquest.eventcore.Event; import de.ugoe.cs.autoquest.eventcore.IEventType; import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModelException; import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; import de.ugoe.cs.autoquest.plugin.html.eventcore.HTMLEventTypeFactory; import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLDocument; import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLDocumentSpec; import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement; import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElementSpec; import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElement; import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElementSpec; import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLServerSpec; /** *
* This class provides the functionality to parse XML log files generated by the HTMLMonitor of * AutoQUEST. The result of parsing a file is a collection of event sequences and a GUI model. *
** The parser can be configured with parsing parameters to adapt, e.g., ids or or ignore indexes of * parsed GUI elements. Details can be found in the manual pages of the respective parsing commands. *
* * @author Fabian Glaser, Patrick Harms * @version 1.0 * */ public class HTMLLogParser extends AbstractDefaultLogParser { /** ** the pattern used for parsing HTML GUI element paths *
*/ private Pattern htmlElementPattern = Pattern.compile("(\\w+)(\\[(\\d+)\\]|\\(htmlId=([\\w-]+)\\))"); /** ** file containing parameters to influence parsing *
*/ private String parseParamFile; /** ** a map containing replacement specifications for ids of GUI elements *
*/ private Map* initializes the parser with the file containing parsing parameters to be considered *
* * @param parseParamFile the parsing parameters to be considered */ public HTMLLogParser(String parseParamFile) { this.parseParamFile = parseParamFile; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleGUIElement(String, Map) */ @Override protected boolean handleGUIElement(String id, Map* returns the replacement mapping for the tag specified by the parameters, if a mapping exists. *
* * @param tagName the tag of the considered GUI element * @param index the index of the GUI element * @param id the id of the GUI element * @param parent the parent GUI element of the considered GUI element * * @return the replacement mapping, if any is configured; null else */ private String getReplacementMapping(String tagName, int index, String htmlId, HTMLGUIElement parent) { List* reads parsing parameters from the config file and makes them available for the parsing * process *
*/ private void ensureParsingParameters() throws SAXException { if (replacementSpecifications == null) { replacementSpecifications = new HashMap