public BundleInfo[] save(Manipulator manipulator, boolean backup) throws IOException { List setToInitialConfig = new LinkedList(); List setToSimpleConfig = new LinkedList(); ConfigData configData = manipulator.getConfigData(); if (!divideBundleInfos( manipulator, setToInitialConfig, setToSimpleConfig, configData.getInitialBundleStartLevel())) return configData.getBundles(); File outputFile = getConfigFile(manipulator); URI installArea = ParserUtils.getOSGiInstallArea( Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getConfigData().getProperties(), manipulator.getLauncherData()) .toURI(); saveConfiguration( (BundleInfo[]) setToSimpleConfig.toArray(new BundleInfo[setToSimpleConfig.size()]), outputFile, installArea, backup); configData.setProperty( SimpleConfiguratorManipulatorImpl.PROP_KEY_CONFIGURL, outputFile.toURL().toExternalForm()); return orderingInitialConfig(setToInitialConfig); }
private void getImgLinks(HTML dequeuedHtml) { // TODO Auto-generated method stub String[] allValidExtension = m_ConfigData.getImageExtensions(); StringBuilder extenstionAddToRegex = new StringBuilder(); extenstionAddToRegex.append("("); for (int i = 0; i < allValidExtension.length; i++) { if (i == allValidExtension.length - 1) { extenstionAddToRegex.append(allValidExtension[i].toLowerCase() + "|"); extenstionAddToRegex.append(allValidExtension[i].toUpperCase() + ")"); } else { extenstionAddToRegex.append(allValidExtension[i].toLowerCase() + "|"); extenstionAddToRegex.append(allValidExtension[i].toUpperCase() + "|"); } } String regex = "<(img|IMG)\\s+(src|SRC)=\"(.*?\\." + extenstionAddToRegex.toString() + ")\""; System.out.println("Regex for image is " + regex); Pattern pattern = Pattern.compile(regex); Matcher m = pattern.matcher(dequeuedHtml.GetBody()); System.out.println("fetching image links"); while (m.find()) { String link = m.group(3); System.out.println("enqueue to Downloader: " + link); if (!m_AllTraversedLinks.Exists(link)) { // m_DownloadQueue.enqueue(link); m_DownloadQueue.enqueue(link); // m_AllTraversedLinks.enqueue(link); System.out.println("Analyzer: adding image link: " + link); } } System.out.println("Done with fetching image links"); }
public void onEnable() { plugin = this; saveDefaultConfig(); getServer().getLogger().info("Loading corpses creator..."); loadCorpsesCreator(); ConfigData.load(); if (!cont) { return; } PluginManager pm = getServer().getPluginManager(); pm.registerEvents(new PlayerJoin(), this); pm.registerEvents(new PlayerRespawn(), this); pm.registerEvents(new PlayerChangedWorld(), this); pm.registerEvents(new PlayerDeath(), this); getCommand("spawncorpse").setExecutor(new SpawnCorpse()); }
protected URL writeConfig(ConfigData configuration, String fileName) throws Exception { File configFile = new File(configDirectory, fileName); File backupFile = new File(configDirectory, fileName + ".bak"); ConfigLogImplementation.logMethods.info("Writing configuration file at " + configFile); checkConfigDirectoryWritable(); checkConfigFileWritableIfExists(configFile); checkConfigFileWritableIfExists(backupFile); File tempConfigFile = null; FileOutputStream fos = null; try { ConfigLogImplementation.logMethods.debug("About to create temp file"); tempConfigFile = File.createTempFile("tempConfig", "." + extension, configDirectory); tempConfigFile.deleteOnExit(); ConfigLogImplementation.logMethods.debug("About to write: " + tempConfigFile); try { fos = new FileOutputStream(tempConfigFile); writeConfigToStream(fos, configuration.getSerializedConfig(), configuration.getVersion()); } finally { if (fos != null) { try { fos.close(); } catch (Exception e) { ConfigLogImplementation.logMethods.error( "Failed to close out file stream to temp file " + tempConfigFile.getPath(), e); } } } ConfigLogImplementation.logMethods.debug("Written: " + tempConfigFile); if (backupFile.exists()) { ConfigLogImplementation.logMethods.debug("About to delete " + backupFile); boolean deleted = backupFile.delete(); if (deleted) { ConfigLogImplementation.logMethods.debug("Deleted " + backupFile); } else { ConfigLogImplementation.logMethods.warn("Failed to delete " + backupFile); } } if (configFile.exists()) { ConfigLogImplementation.logMethods.debug( "About to rename old config: " + configFile + " to " + backupFile); if (!configFile.renameTo(backupFile)) { throw new IOException( "Unable to rename old config: " + configFile + " to " + backupFile); } } ConfigLogImplementation.logMethods.debug( "About to rename temp config: " + tempConfigFile + " to " + configFile); if (!tempConfigFile.renameTo(configFile)) { throw new IOException( "Unable to rename temp config: " + tempConfigFile + " to new config: " + configFile); } } catch (IOException e) { ConfigLogImplementation.logMethods.error("Unable to save config: " + configFile, e); throw new ConfigManagerException("Unable to save config", e); } return configFile.toURI().toURL(); }
/** * 解析配置XML文件 * * @param cfd 从配置文件中解析的数据 * @return */ public ConfigData parseConfigXml() { if (null == path || "".equals(path)) return null; ConfigData cfd = new ConfigData(); File f = new File(path); try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(f); // 时间点 cfd.setTimePoint( Integer.parseInt( doc.getElementsByTagName("timePoint").item(0).getFirstChild().getNodeValue())); // 抓包基础路径 cfd.setCaptureBasePath( doc.getElementsByTagName("captureBasePath").item(0).getFirstChild().getNodeValue()); // 客户端服务器交互 时间间隔 cfd.setTimeInterval( Integer.parseInt( doc.getElementsByTagName("timeInterval").item(0).getFirstChild().getNodeValue())); // 服务器IP cfd.setServerIP(doc.getElementsByTagName("ipAddress").item(0).getFirstChild().getNodeValue()); // 服务器端口 cfd.setServerPort( Integer.parseInt( doc.getElementsByTagName("port").item(0).getFirstChild().getNodeValue())); // 任务信息 NodeList nl = doc.getElementsByTagName("task"); for (int i = 0; i < nl.getLength(); i++) { TaskInfo ti = new TaskInfo(); ti.setTaskNum( Integer.parseInt( doc.getElementsByTagName("taskNum").item(i).getFirstChild().getNodeValue())); ti.setTaskName(doc.getElementsByTagName("taskName").item(i).getFirstChild().getNodeValue()); ti.setTaskClass( doc.getElementsByTagName("taskClass").item(i).getFirstChild().getNodeValue()); cfd.addTaskInfo(ti); } } catch (ParserConfigurationException e) { Logger log = Logger.getLogger("ConfigParse"); log.error(e.getMessage()); log.error(e.getStackTrace()); return null; } catch (SAXException e) { Logger log = Logger.getLogger("ConfigParse"); log.error(e.getMessage()); log.error(e.getStackTrace()); return null; } catch (IOException e) { Logger log = Logger.getLogger("ConfigParse"); log.error(e.getMessage()); log.error(e.getStackTrace()); return null; } catch (Exception e) { Logger log = Logger.getLogger("ConfigParse"); log.error(e.getMessage()); log.error(e.getStackTrace()); return null; } return cfd; }