/** * Returns the plugin settings list for the profile whose name is input * * @param profileName the name of the profile whose settings you want to retrieve * @return the ArrayList of PluginSettings of the profile * @throws NoSuchElementException if the profile name is not found */ public ArrayList<PluginSetting> getProfile(String profileString) throws NoSuchElementException { if (profileString == null) { throw new NoSuchElementException(); } String profileName = null; String pageName = ""; String[] profileStrings = profileString.split("[.]"); if (profileStrings.length == 1) { profileName = profileStrings[0]; } else if (profileStrings.length == 2) { pageName = profileStrings[0]; profileName = profileStrings[1]; } else { throw new NoSuchElementException("Incorrect Syntax in EMML Tag: " + profileString); } for (EMMLProfile profile : profileList) { if (profileName.equalsIgnoreCase(profile.getProfileName()) && pageName.equalsIgnoreCase(profile.getPageName())) { return profile.getSettings(); } } throw new NoSuchElementException( "Profile Not Found: " + profileString); // If we don't have the profile with the name of the input variable }
/** * Opens, reads and parses profile information from an input File. Creates profiles from the * profile page and stores them for later use. * * @param inputFile the file to be parsed * @param name the name to give the profile. If empty, this Profile Page will replace the current * temporary Profile Page * @throws FileNotFoundException if the inputFile doesn't exist * @throws IOException if an IO problem happens when using the file */ public void importProfilePage(FileInputStream inputFile, String name) throws IOException { /*if(!Oem.testmode)*/ Common.logger.add(new LogEntry(LogEntry.PB_LOG_INFO, "start")); if (inputFile == null) { return; } FileChannel fileChannel = inputFile.getChannel(); Charset charset = Charset.forName("US-ASCII"); CharsetDecoder decoder = charset.newDecoder(); CharBuffer charBuffer = decoder.decode(fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size())); if (name == null) name = ""; try { deleteProfilePage(name); } catch (NoSuchElementException e) { // No worries, may not exist. Just carry on } // Remove all comments, including multiline comments commentMatcher.reset(charBuffer); charBuffer = CharBuffer.wrap(commentMatcher.replaceAll("")); // Remove all urls StringBuffer sb = new StringBuffer(charBuffer); ArrayList<String> urls = new ArrayList<String>(); urlMatcher.reset(sb); while (urlMatcher.find()) // When its found a "url('...'); { // String url = urlMatcher.group(2); String url = urlMatcher.group(3); int endPosition = urlMatcher.end(); // While theres an open bracket for (String string = sb.substring(endPosition); sb.length() > (endPosition + 1) && ((url.replaceAll("[^(]", "").length() - url.replaceAll("[^)]", "").length()) > 0); string = sb.substring(endPosition)) { // Find a the next closing bracket bracketMatcher.reset(string); if (bracketMatcher.find()) { url += bracketMatcher.group(2) + ")" + sb.substring( endPosition, endPosition + bracketMatcher.end(1)); // Add it to the URL endPosition += bracketMatcher.end(3); } else // Badly formed EMML { sb.setLength(0); /*if(!Oem.testmode)*/ Common.logger.add( new LogEntry(LogEntry.PB_LOG_WARNING, "Bad Syntax in Profile")); break; } } // Checks if it exited with an error (i.e. open bracket remains) if (sb.length() <= (endPosition + 1) && ((url.replaceAll("[^(]", "").length() - url.replaceAll("[^)]", "").length()) > 0)) { // incorrect input sb.setLength(0); /*if(!Oem.testmode)*/ Common.logger.add( new LogEntry(LogEntry.PB_LOG_WARNING, "Bad Syntax in Profile")); } else { // Adds the extracted url to the url List for injecting later // and replaces the extracted string with the ESCAPE character which is defined above urls.add(url); sb.delete(urlMatcher.start(), endPosition); sb.insert(urlMatcher.start(), ESCAPE_CHAR); } urlMatcher.reset(sb); } // Remove all whitespace profileSplitter.reset(sb); while (profileSplitter.find()) { EMMLProfile profile = new EMMLProfile(name.toLowerCase(), profileSplitter.group(1).trim()); String profileContents = profileSplitter.group(2); String[] settingStrings = profileContents.split(";"); for (String setting : settingStrings) { String[] settingComponents = setting.split(":"); String setting1 = ""; String setting2 = ""; if (settingComponents.length >= 1) { setting1 = settingComponents[0]; if (settingComponents.length >= 2) { for (int i = 1; i < settingComponents.length; i++) { setting2 += settingComponents[i]; } // DO REPLACE while (setting2.matches(".*" + ESCAPE_CHAR + ".*")) { setting2 = setting2.replaceFirst(ESCAPE_CHAR, urls.remove(0)); } } } profile.addSettings(parseEMMLTag(setting1, setting2)); } profileList.add(profile); Common.logger.add( new LogEntry( LogEntry.PB_LOG_INFO, "Added profile: " + profile.getPageName() + "." + profile.getProfileName())); } /*if(!Oem.testmode)*/ Common.logger.add(new LogEntry(LogEntry.PB_LOG_INFO, "end")); }