// 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.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.logging.Level; import java.util.regex.Matcher; import java.util.regex.Pattern; import de.ugoe.cs.autoquest.eventcore.Event; import de.ugoe.cs.autoquest.eventcore.gui.DialogClose; import de.ugoe.cs.autoquest.eventcore.gui.DialogOpen; import de.ugoe.cs.autoquest.eventcore.gui.IInteraction; import de.ugoe.cs.autoquest.eventcore.gui.KeyboardFocusChange; import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction; import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; import de.ugoe.cs.autoquest.eventcore.gui.Scroll; import de.ugoe.cs.autoquest.eventcore.gui.TextInput; import de.ugoe.cs.autoquest.eventcore.guimodel.GUIElementFactory; 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.eventcore.guimodel.IGUIElementSpec; import de.ugoe.cs.autoquest.eventcore.guimodel.ITextArea; import de.ugoe.cs.autoquest.eventcore.guimodel.ITextField; import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElementSpec; import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageSpec; import de.ugoe.cs.util.FileTools; import de.ugoe.cs.util.console.Console; /** *
* TODO comment *
* * @author Patrick Harms */ public class OldHTMLLogParser { /** ** Name and path of the robot filter. *
*/ private static final String ROBOTFILTERFILE = "data/robots/robotfilter.txt"; /** ** Field that contains a regular expression that matches all robots * contained in {@link #ROBOTFILTERFILE}. *
*/ private String robotRegex = null; /** * */ private Pattern htmlElementPattern = Pattern.compile("(\\w+)(\\[(\\d+)\\]|\\(id=([\\w-]+)\\))"); /** * */ private List* TODO: comment *
* * @param source */ public void parseFile(String source) throws IllegalArgumentException { if (source == null) { throw new IllegalArgumentException("source must not be null"); } parseFile(new File(source)); } /** ** TODO: comment *
* * @param source */ public void parseFile(File source) throws IllegalArgumentException { if (source == null) { throw new IllegalArgumentException("source must not be null"); } else if (!source.exists()) { throw new IllegalArgumentException("source file does not exist"); } else if (!source.isFile()) { throw new IllegalArgumentException("source is not a file"); } BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(source), "UTF-8")); loadRobotRegex(); List* TODO: comment *
* * @return */ public Collection* TODO: comment *
* * @return */ public GUIModel getGuiModel() { return guiModel; } /** ** Reads {@link #ROBOTFILTERFILE} and creates a regular expression that * matches all the robots defined in the file. The regular expression is * stored in the field {@link #robotRegex}. *
* * @throws IOException * thrown if there is a problem reading the robot filter * @throws FileNotFoundException * thrown if the robot filter is not found */ private void loadRobotRegex() throws IOException, FileNotFoundException { String[] lines = FileTools.getLinesFromFile(ROBOTFILTERFILE); StringBuilder regex = new StringBuilder(); for (int i = 0; i < lines.length; i++) { regex.append("(.*" + lines[i] + ".*)"); if (i != lines.length - 1) { regex.append('|'); } } robotRegex = regex.toString(); } /** ** TODO: comment *
* * @param htmlElementPath * @return * @throws GUIModelException * @throws */ private IGUIElement getGUIElement(URL url, String title, String htmlElementPath) throws GUIModelException { String[] pathElements = htmlElementPath.split("/"); List* TODO: comment *
* * @param eventName * @param guiElement * @param eventParameters * @return */ private IInteraction getInteraction(String eventName, IGUIElement guiElement, List* TODO: comment *
* * @param clientId * @param interaction * @param guiElement * @param timestamp * @param agent * @return */ private Event createEvent(String clientId, IInteraction interaction, IGUIElement guiElement, long timestamp, String agent) { Event event = new Event(interaction, guiElement); event.setParameter("clientId", clientId); event.setParameter("agent", agent); event.setTimestamp(timestamp); return event; } /** ** TODO: comment *
* * @param eventName * @param eventParameters * @param i * @param string * @return */ private String getStringParameter(String eventName, List* TODO: comment *
* * @param eventName * @param eventParameters * @return */ private int[] getCoordinateParameter(String eventName, List* Checks whether an agent is a robot. *
* * @param agent * agent that is checked * @return true, if the agent is a robot; false otherwise */ private boolean isRobot(String agent) { return agent.matches(robotRegex); } }