private synchronized void save() { myDir.mkdirs(); Properties props = new Properties(); props.setProperty(KIND_KEY, myKind.toString()); props.setProperty(ID_KEY, myRepositoryId); props.setProperty(PATH_OR_URL_KEY, myRepositoryPathOrUrl); props.setProperty(INDEX_VERSION_KEY, CURRENT_VERSION); if (myUpdateTimestamp != null) props.setProperty(TIMESTAMP_KEY, String.valueOf(myUpdateTimestamp)); if (myDataDirName != null) props.setProperty(DATA_DIR_NAME_KEY, myDataDirName); if (myFailureMessage != null) props.setProperty(FAILURE_MESSAGE_KEY, myFailureMessage); try { FileOutputStream s = new FileOutputStream(new File(myDir, INDEX_INFO_FILE)); try { props.store(s, null); } finally { s.close(); } } catch (IOException e) { MavenLog.LOG.warn(e); } }
public synchronized void saveProperties() { if (ownLock()) { try { FileOutputStream out = new FileOutputStream(propertyFile); try { fontProps.store(out, "-- ICEpf Font properties --"); } finally { out.close(); } recordMofifTime(); } catch (IOException ex) { // check to make sure the storage relate dialogs can be shown if (getBoolean("application.showLocalStorageDialogs", true)) { Resources.showMessageDialog( null, JOptionPane.ERROR_MESSAGE, messageBundle, "fontManager.properties.title", "manager.properties.saveError", ex); } // log the error if (logger.isLoggable(Level.WARNING)) { logger.log(Level.WARNING, "Error saving font properties cache", ex); } } } }
public SaikuDatasource addDatasource(SaikuDatasource datasource) { try { String uri = repoURL.toURI().toString(); if (uri != null && datasource != null) { uri += datasource.getName().replace(" ", "_"); File dsFile = new File(new URI(uri)); if (dsFile.exists()) { dsFile.delete(); } else { dsFile.createNewFile(); } FileWriter fw = new FileWriter(dsFile); Properties props = datasource.getProperties(); props.store(fw, null); fw.close(); datasources.put(datasource.getName(), datasource); return datasource; } else { throw new SaikuServiceException( "Cannot save datasource because uri or datasource is null uri(" + (uri == null) + ")"); } } catch (Exception e) { throw new SaikuServiceException("Error saving datasource", e); } }
@Test public void testState() throws IOException { final File fcontent = File.createTempFile("foo", "bar"); final Properties properties = new Properties(); final Date dt = new Date(); properties.put("int", 10453); properties.put("long", 1000000L); properties.put("date", dt); final OutputStream out = new FileOutputStream(fcontent); properties.store(out); final Properties loadProperties = new Properties(); final InputStream in = new FileInputStream(fcontent); loadProperties.load(in); assertNotNull(properties.get("int")); assertNotNull(properties.get("long")); assertNotNull(properties.get("date")); assertEquals(10453, properties.get("int")); assertEquals(1000000L, properties.get("long")); assertEquals(dt, properties.get("date")); }
public static void save(Properties properties, File file) throws IOException { Assert.notNull(properties, "存储的属性为空!"); OutputStream outputStream = new FileOutputStream(file); properties.store(outputStream, "saved on " + DateHelper.getStringDate()); outputStream.flush(); outputStream.close(); }
void propSave(Properties props) throws Exception { OutputStream output = new FileOutputStream(propFile()); try { props.store(output, null); } finally { output.close(); } }
/** * Method used to save the configuration in a specific file * * @param propertiesFile configuration file */ public static void store(String propertiesFile) { try { FileOutputStream cfgOutStream = new FileOutputStream(propertiesFile); prop.store(cfgOutStream, "jim configuration file"); } catch (Exception e) { logger.error("error opening propertiesFile: " + propertiesFile, e); } }
private void shellWidgetDisposed(DisposeEvent evt) { try { // Save app settings to file appSettings.store(new FileOutputStream("appsettings.ini"), ""); } catch (FileNotFoundException e) { } catch (IOException e) { } }
private void exitMenuItemWidgetSelected(SelectionEvent evt) { try { // Save app settings to file appSettings.store(new FileOutputStream("appsettings.ini"), ""); } catch (FileNotFoundException e) { } catch (IOException e) { } getShell().dispose(); System.exit(1); }
private void saveUserSettingsMap(String username, Map userMap) { File userFile = new File(users, username + "_settings.properties"); Properties props = (Properties) userMap; try { props.store(new FileOutputStream(userFile), null); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public void save() { final Properties properties = new Properties(); Optional.ofNullable(username).ifPresent(s -> properties.setProperty("username", s)); Optional.ofNullable(password).ifPresent(s -> properties.setProperty("password", s)); Optional.ofNullable(from) .ifPresent(d -> properties.setProperty("from", d.format(DateTimeFormatter.ISO_DATE))); try { properties.store(getConfigurationWriter(), null); } catch (IOException e) { e.printStackTrace(); // TODO logging } }
public void save(ActionEvent e) { if (file == null) { saveAs(e); } try { OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); wordList.store(out, "Generated by JWordPlay"); out.flush(); out.close(); } catch (IOException ex) { handleException(ex); } }
/** * Generate an ant script that can be run to generate final p2 metadata for a product. Returns * null if p2 bundles aren't available. * * <p>If no product file is given, the generated p2 call generates final metadata for a * ${p2.root.name}_${p2.root.version} IU. * * <p>versionAdvice is a properties file with bsn=3.2.1.xyz entries * * @param workingDir - the directory in which to generate the script * @param productFileLocation - the location of a .product file (can be null) * @param versionAdvice - version advice (can be null) * @return The location of the generated script, or null * @throws CoreException */ public static String generateP2ProductScript( String workingDir, String productFileLocation, Properties versionAdvice) throws CoreException { if (!loadP2Class()) return null; File working = new File(workingDir); working.mkdirs(); File adviceFile = null; if (versionAdvice != null) { adviceFile = new File(working, "versionAdvice.properties"); // $NON-NLS-1$ try { OutputStream os = new BufferedOutputStream(new FileOutputStream(adviceFile)); try { versionAdvice.store(os, null); } finally { os.close(); } } catch (IOException e) { String message = NLS.bind(Messages.exception_writingFile, adviceFile.toString()); throw new CoreException( new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); } } AntScript p2Script = null; try { p2Script = newAntScript(workingDir, "p2product.xml"); // $NON-NLS-1$ p2Script.printProjectDeclaration( "P2 Product IU Generation", "main", "."); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ p2Script.println(); p2Script.printProperty(PROPERTY_P2_APPEND, "true"); // $NON-NLS-1$ p2Script.printProperty(PROPERTY_P2_COMPRESS, "false"); // $NON-NLS-1$ p2Script.printProperty(PROPERTY_P2_METADATA_REPO_NAME, ""); // $NON-NLS-1$ p2Script.printProperty(PROPERTY_P2_ARTIFACT_REPO_NAME, ""); // $NON-NLS-1$ p2Script.printTargetDeclaration( "main", null, TARGET_P2_METADATA, null, "Generate the final Product IU"); //$NON-NLS-1$//$NON-NLS-2$ generateP2FinalCall( p2Script, productFileLocation, adviceFile != null ? adviceFile.getAbsolutePath() : null); p2Script.printTargetEnd(); p2Script.printProjectEnd(); } finally { if (p2Script != null) p2Script.close(); } return workingDir + "/p2product.xml"; // $NON-NLS-1$ }
public void writeProperties(Map<?, ?> properties) { Properties props = new Properties(); props.putAll(properties); try { FileOutputStream stream = new FileOutputStream(this); try { props.store(stream, "comment"); } finally { stream.close(); } } catch (IOException e) { throw new RuntimeException(e); } }
public static void main(String[] args) throws Exception { Properties props = new Properties(); // 向Properties中增加属性 props.setProperty("username", "yeeku"); props.setProperty("password", "123456"); // 将Properties中的属性保存到a.ini文件中 props.store(new FileOutputStream("a.ini"), "comment line"); // 新建一个Properties对象 Properties props2 = new Properties(); // 向Properties中增加属性 props2.setProperty("gender", "male"); // 将a.ini文件中的属性名-属性值追加到props2中 props2.load(new FileInputStream("a.ini")); System.out.println(props2); }
private static File dumpModulesPaths(@NotNull Project project) throws IOException { ApplicationManager.getApplication().assertReadAccessAllowed(); Properties res = new Properties(); MavenProjectsManager manager = MavenProjectsManager.getInstance(project); for (Module module : ModuleManager.getInstance(project).getModules()) { if (manager.isMavenizedModule(module)) { MavenProject mavenProject = manager.findProject(module); if (mavenProject != null && !manager.isIgnored(mavenProject)) { res.setProperty( mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ":pom" + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getFile().getPath()); res.setProperty( mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ':' + mavenProject.getPackaging() + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getOutputDirectory()); } } } File file = new File( PathManager.getSystemPath(), "Maven/idea-projects-state-" + project.getLocationHash() + ".properties"); file.getParentFile().mkdirs(); OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { res.store(out, null); } finally { out.close(); } return file; }
/** * saves the parameters to a file so that they can be used again next time the application starts. */ private void saveParametersToFile() { try { synchronized (savedOptionsFile) { if (savedOptionsFile.exists()) { savedOptionsFile.delete(); } savedOptionsFile.createNewFile(); FileOutputStream fos = new FileOutputStream(savedOptionsFile); parameters.store(fos, "Denny's DVDs configuration"); fos.close(); } } catch (IOException e) { ApplicationRunner.handleException( "Unable to save user parameters to file. " + "They wont be remembered next time you start."); } }
public void saveUpdateProperties(Properties updateProperties) { File propertiesDirectory; propertiesDirectory = new File(System.getProperty("user.home"), PROPERTIES_DIRECTORY_NAME); if (!propertiesDirectory.exists()) { propertiesDirectory.mkdir(); } BufferedOutputStream outStream = null; try { outStream = new BufferedOutputStream( new FileOutputStream( new File(propertiesDirectory, getProperty("checkUpdate.fileName")))); updateProperties.store(outStream, "Tangara update properties"); } catch (Exception ex) { LOG.error("Failed to write lastlaunch property", ex); } finally { IOUtils.closeQuietly(outStream); } }
/* * Create a link file in the links folder. Point it to the given extension location. */ public void createLinkFile(String message, String filename, String extensionLocation) { File file = new File(output, getRootFolder() + "links/" + filename + ".link"); file.getParentFile().mkdirs(); Properties properties = new Properties(); properties.put("path", extensionLocation); OutputStream stream = null; try { stream = new BufferedOutputStream(new FileOutputStream(file)); properties.store(stream, null); } catch (IOException e) { fail(message, e); } finally { try { if (stream != null) stream.close(); } catch (IOException e) { // ignore } } }
/** * Write out the update blojsom configuration file. This is done after adding or deleting a new * user. */ private void writeBlojsomConfiguration() { File blojsomConfigurationFile = new File( _blojsomConfiguration.getInstallationDirectory() + _blojsomConfiguration.getBaseConfigurationDirectory() + "blojsom.properties"); Iterator usersIterator = _blojsomConfiguration.getBlogUsers().keySet().iterator(); ArrayList users = new ArrayList(); while (usersIterator.hasNext()) { users.add(usersIterator.next()); } Properties configurationProperties = new BlojsomProperties(true); configurationProperties.put(BLOJSOM_USERS_IP, users); configurationProperties.put(BLOJSOM_FETCHER_IP, _blojsomConfiguration.getFetcherClass()); configurationProperties.put(BLOJSOM_DEFAULT_USER_IP, _blojsomConfiguration.getDefaultUser()); configurationProperties.put( BLOJSOM_INSTALLATION_DIRECTORY_IP, _blojsomConfiguration.getInstallationDirectory()); configurationProperties.put( BLOJSOM_CONFIGURATION_BASE_DIRECTORY_IP, _blojsomConfiguration.getBaseConfigurationDirectory()); configurationProperties.put(BLOJSOM_BLOG_HOME_IP, _blojsomConfiguration.getGlobalBlogHome()); configurationProperties.put( BLOJSOM_TEMPLATES_DIRECTORY_IP, _blojsomConfiguration.getTemplatesDirectory()); configurationProperties.put( BLOJSOM_RESOURCE_DIRECTORY_IP, _blojsomConfiguration.getResourceDirectory()); configurationProperties.put( BLOJSOM_RESOURCE_MANAGER_IP, _blojsomConfiguration.getResourceManager()); configurationProperties.put( BLOJSOM_RESOURCE_MANAGER_BUNDLES_IP, "org.blojsom.plugin.admin.resources.messages"); configurationProperties.put( BLOJSOM_BROADCASTER_IP, _blojsomConfiguration.getEventBroadcaster().getClass().getName()); try { FileOutputStream fos = new FileOutputStream(blojsomConfigurationFile); configurationProperties.store(fos, null); fos.close(); } catch (IOException e) { _logger.error(e); } }
static void saveAuIdProperties(String location, Properties props) { // XXX these AU_ID_FILE entries need to be backed up elsewhere to avoid // single-point corruption File propDir = new File(location); if (!propDir.exists()) { logger.debug("Creating directory '" + propDir.getAbsolutePath() + "'"); propDir.mkdirs(); } File propFile = new File(propDir, AU_ID_FILE); try { logger.debug3("Saving au id properties at '" + location + "'."); OutputStream os = new BufferedOutputStream(new FileOutputStream(propFile)); props.store(os, "ArchivalUnit id info"); os.close(); propFile.setReadOnly(); } catch (IOException ioe) { logger.error("Couldn't write properties for " + propFile.getPath() + ".", ioe); throw new LockssRepository.RepositoryStateException("Couldn't write au id properties file."); } }
private void speichern(Path saveName) { Properties prop = new Properties(); if (!quellListModel.isEmpty()) for (int i = 0; i < quellListModel.getSize(); i++) prop.setProperty( String.format("quellMenu%d", i), quellListModel.getElementAt(i).getValueMember().toString()); if (!zielListModel.isEmpty()) for (int i = 0; i < zielListModel.getSize(); i++) prop.setProperty( String.format("zielMenu%d", i), zielListModel.getElementAt(i).getValueMember().toString()); try { FileOutputStream out = new FileOutputStream(saveName.toString()); prop.store(out, null); out.close(); } catch (Exception e) { e.printStackTrace(); } }
public void save(File f) { Properties save = new Properties(); OutputStream output = null; try { save.setProperty("provider", selectProviderCb.getValue()); save.setProperty("grain", selectGrainCb.getValue()); save.setProperty("weight", weightTf.getText()); save.setProperty("info", infoTa.getText()); for (Entry<String, TextField> entry : propertiesTf.entrySet()) { TextField tf = entry.getValue(); String propertyName = entry.getKey(); save.setProperty(propertyName, tf.getText()); if (tf.isDisable()) { save.setProperty(propertyName + "_ENABLED", "OFF"); } else { save.setProperty(propertyName + "_ENABLED", "ON"); } } output = new FileOutputStream(f); save.store(output, null); mainStage.setTitle(f.getName()); } catch (Exception ex) { infoTa.setText("Не могу сохранить в файл"); } finally { if (output != null) { try { output.close(); } catch (IOException e) { e.printStackTrace(); } } } }
public static void saveSetting(String key, String val) throws IOException { Properties p; File f; if ((f = Environment.getPropertiesFile(FManager.class)).exists()) { try (InputStream is = new FileInputStream(f)) { p = new Properties(); p.load(is); p.setProperty(key, val); is.close(); FileOutputStream fos = new FileOutputStream(f); p.store( fos, "Updated " + DateFormatUtils.format( System.currentTimeMillis(), ISO_EXTENDED_FORMAT_PATTERN, Locale.ENGLISH)); try { fos.close(); } catch (Exception ex) { } } } else { throw new IOException("Cannot store properties."); } }
public void saveSettings(Map<String, String> keyValMap, boolean autoLoad) throws IOException { Properties p; File f; if ((f = Environment.getPropertiesFile(FManager.class)).exists()) { this.activeFingerprintFileMap.clear(); try (InputStream is = new FileInputStream(f)) { p = new Properties(); // p.load(is); keyValMap .entrySet() .stream() .forEach( pair -> { p.setProperty(pair.getKey(), pair.getValue()); this.activeFingerprintFileMap.put( new File(pair.getKey()), Boolean.valueOf(pair.getValue())); }); p.setProperty(AUTOLOAD, autoLoad + ""); // is.close(); FileOutputStream fos = new FileOutputStream(f); p.store( fos, "Updated " + DateFormatUtils.format( System.currentTimeMillis(), ISO_EXTENDED_FORMAT_PATTERN, Locale.ENGLISH)); try { fos.close(); } catch (Exception ex) { } } } else { throw new IOException("Cannot store properties."); } }
private void rememberSharedBundlesInfoTimestamp(URI installArea, File outputFolder) { if (installArea == null) return; File sharedBundlesInfo = new File(URIUtil.append(installArea, SHARED_BUNDLES_INFO)); if (!sharedBundlesInfo.exists()) return; Properties timestampToPersist = new Properties(); timestampToPersist.put( SimpleConfiguratorImpl.KEY_BUNDLESINFO_TIMESTAMP, Long.toString(sharedBundlesInfo.lastModified())); OutputStream os = null; try { try { File outputFile = new File(outputFolder, SimpleConfiguratorImpl.BASE_TIMESTAMP_FILE_BUNDLESINFO); os = new BufferedOutputStream(new FileOutputStream(outputFile)); timestampToPersist.store(os, "Written by " + this.getClass()); // $NON-NLS-1$ } finally { if (os != null) os.close(); } } catch (IOException e) { return; } }
public void generateResourceBundle(String baseName, Path bundleDir) throws GenerationException, IOException { HashMap<String, Properties> bundles = generateResourceBundle(baseName); for (String bKey : bundles.keySet()) { final Properties bundle = bundles.get(bKey); final Path file = bundleDir.resolve(bKey + ".properties"); try (Writer w = Files.newBufferedWriter(file, Charset.forName("utf8"))) { bundle.store( w, String.format( "ResourceBundle (%s) for %s, generated by %s v%s", bKey, baseName, "com.github.tkurz.sesame:vocab-builder", MavenUtil.loadVersion( "com.github.tkurz.sesame", "vocab-builder", "0.0.0-DEVELOP"))); } catch (IOException e) { log.error("Could not write Bundle {} to {}: {}", bKey, file, e); throw e; } } }
void save() throws IOException { File dir = getStorageDirectory(); dir.mkdirs(); File index = new File(dir, FILE_INDEX); props.store(new FileOutputStream(index), null); }
/** * implemented. <br> * this method replaces save. It behaves the same, but it will throw a <br> * java.io.IOException if an IO error occurs, while save did nothing <br> * <br> * to test this we should create an OutputStream wich will be guaranteed to fail ! <br> * ???? must be added !!!! (how) <br> * Add a test to determine of store generates a comment line with the current time <br> */ public void test_store() { th.checkPoint("store(java.io.OutputStream,java.lang.String)void"); Properties p = new Properties(defProps); try { p.store((ByteArrayOutputStream) null, "no comment"); th.fail("should throw NullPointerException"); } catch (NullPointerException ne) { th.check(true); } catch (Exception e) { th.fail("should throw an NullPointerEception instead of: " + e); } try { p.store(bout, null); th.check(true); } catch (NullPointerException ne) { th.fail("should not throw NullPointerException"); } catch (Exception e) { th.fail("shouldn't throw any Exception, but got: " + e); } resetStreams(); try { p.store(bout, null); } catch (Exception e) { th.fail("shouldn't throw any Exception, but got: " + e); } byte ba[] = bout.toByteArray(); th.check((ba[0] == (byte) '#') && (ba[1] != (byte) '#'), "only the date should be written"); th.check(ba.length < 50, "default properties are never printed out"); resetStreams(); try { p.load(bin); } catch (Exception e) { } try { p.store(bout, "no comments"); } catch (Exception e) { th.fail("shouldn't throw any Exception, but got: " + e); } ba = bout.toByteArray(); String s = new String(ba, 0, 12); th.check(s.equals("#no comments"), "got: " + s); int i = 0, count = 0; while (i < 2 && count < ba.length) { if (ba[count++] == (byte) '\n') i++; } // we will construct a vector containing all the lines with should be written Vector v = new Vector(); Enumeration ek = p.keys(); while (ek.hasMoreElements()) { s = (String) ek.nextElement(); v.add(s + "=" + p.getProperty(s)); } while (count < ba.length) { int start = count; while (count < ba.length) { if (ba[count] != '\n') count++; else break; } s = new String(ba, start, count - start); th.check(v.contains(s), "v does not contain: " + s); v.removeElement(s); count++; } }
/** * Process the blog entries * * @param httpServletRequest Request * @param httpServletResponse Response * @param user {@link org.blojsom.blog.BlogUser} instance * @param context Context * @param entries Blog entries retrieved for the particular request * @return Modified set of blog entries * @throws org.blojsom.plugin.BlojsomPluginException If there is an error processing the blog * entries */ public BlogEntry[] process( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlogUser user, Map context, BlogEntry[] entries) throws BlojsomPluginException { if (!authenticateUser(httpServletRequest, httpServletResponse, context, user)) { httpServletRequest.setAttribute(PAGE_PARAM, ADMIN_LOGIN_PAGE); return entries; } // Check to see the requesting user is an administrator if (!_administrators.containsKey(user.getId())) { _logger.debug("User: "******" is not a valid administrator"); httpServletRequest.setAttribute(PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); return entries; } context.put( BLOJSOM_PLUGIN_EDIT_BLOG_USERS_MAP, Collections.unmodifiableMap(_blojsomConfiguration.getBlogUsers())); String action = BlojsomUtils.getRequestValue(ACTION_PARAM, httpServletRequest); if (BlojsomUtils.checkNullOrBlank(action)) { _logger.debug("User did not request edit action"); httpServletRequest.setAttribute(PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); } else if (PAGE_ACTION.equals(action)) { _logger.debug("User requested edit blog users page"); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_USERS_PAGE); } else if (DELETE_BLOG_USER_ACTION.equals(action)) { _logger.debug("User requested delete blog user action"); String blogUserID = BlojsomUtils.getRequestValue(BLOG_USER_ID, httpServletRequest); if (BlojsomUtils.checkNullOrBlank(blogUserID)) { httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_USERS_PAGE); return entries; } else { _logger.debug("Deleting user: "******"/"); if (!BlojsomUtils.deleteDirectory(blogConfigurationDirectory)) { _logger.error( "Unable to remove blog configuration directory: " + blogConfigurationDirectory.toString()); addOperationResultMessage( context, "Unable to remove blog configuration for user: "******"Removed blog configuration directory: " + blogConfigurationDirectory.toString()); } File blogDirectory = new File(_blogHomeBaseDirectory + blogUserID + "/"); if (!BlojsomUtils.deleteDirectory(blogDirectory)) { _logger.error("Unable to remove blog directory for user: "******"Unable to remove blog directory for user: "******"Removed blog directory: " + blogDirectory.toString()); } File blogResourcesDirectory = new File( _blojsomConfiguration.getInstallationDirectory() + _blojsomConfiguration.getResourceDirectory() + blogUserID + "/"); if (!BlojsomUtils.deleteDirectory(blogResourcesDirectory)) { _logger.error( "Unable to remove blog resource directory: " + blogResourcesDirectory.toString()); addOperationResultMessage( context, "Unable to remove resources directory for user: "******"Removed blog resource directory: " + blogResourcesDirectory.toString()); } writeBlojsomConfiguration(); _logger.debug("Wrote new blojsom configuration after deleting user: "******"Deleted user: "******"User requested add blog user action"); Map blogUsers = _blojsomConfiguration.getBlogUsers(); String blogUserID = BlojsomUtils.getRequestValue(BLOG_USER_ID, httpServletRequest); if (BlojsomUtils.checkNullOrBlank(blogUserID)) { // Check that we got a blog user ID addOperationResultMessage(context, "No blog ID specified for adding a blog"); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_USERS_PAGE); return entries; } else if (blogUsers.containsKey(blogUserID)) { // Check that the user does not already exist _logger.debug("User: "******" already exists"); addOperationResultMessage(context, "Blog ID: " + blogUserID + " already exists"); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_USERS_PAGE); return entries; } else { // Begin the process of adding a new user _logger.debug("Adding new user id: " + blogUserID); BlogUser blogUser = new BlogUser(); blogUser.setId(blogUserID); File blogUserDirectory = new File( _blojsomConfiguration.getInstallationDirectory() + _blojsomConfiguration.getBaseConfigurationDirectory() + blogUserID); if (blogUserDirectory .exists()) { // Make sure that the blog user ID does not conflict with a directory // underneath the installation directory _logger.debug("User directory already exists for blog user: "******"User directory already exists for blog ID: " + blogUserID); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_USERS_PAGE); return entries; } else { // Otherwise, check the authorization passwords match String blogUserPassword = BlojsomUtils.getRequestValue(BLOG_USER_PASSWORD, httpServletRequest); String blogUserPasswordCheck = BlojsomUtils.getRequestValue(BLOG_USER_PASSWORD_CHECK, httpServletRequest); String blogBaseURL = BlojsomUtils.getRequestValue(BLOG_BASE_URL_IP, httpServletRequest); String blogURL = BlojsomUtils.getRequestValue(BLOG_URL_IP, httpServletRequest); // Check for the blog and blog base URLs if (BlojsomUtils.checkNullOrBlank(blogURL) || BlojsomUtils.checkNullOrBlank(blogBaseURL)) { _logger.debug("No blog URL or base URL supplied"); addOperationResultMessage(context, "No blog URL or base URL supplied"); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_USERS_PAGE); return entries; } else { if (!blogURL.endsWith("/")) { blogURL += "/"; } if (!blogBaseURL.endsWith("/")) { blogBaseURL += "/"; } } // Check to see that the password and password check are equal if (!blogUserPassword.equals(blogUserPasswordCheck)) { _logger.debug("User password does not equal password check"); addOperationResultMessage(context, "User password does not equal user password check"); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_USERS_PAGE); return entries; } else { // And if they do, copy the bootstrap directory and initialize the user String bootstrap = _blojsomConfiguration.getInstallationDirectory() + _blojsomConfiguration.getBaseConfigurationDirectory() + _bootstrapDirectory + "/"; _logger.debug("Bootstrap directory: " + bootstrap); File bootstrapDirectory = new File(bootstrap); String userDirectory = _blojsomConfiguration.getInstallationDirectory() + _blojsomConfiguration.getBaseConfigurationDirectory() + blogUserID + "/"; _logger.debug("User directory: " + userDirectory); File newUserDirectory = new File(userDirectory); _logger.debug( "Copying bootstrap directory: " + bootstrapDirectory.toString() + " to target user directory: " + newUserDirectory.toString()); try { BlojsomUtils.copyDirectory(bootstrapDirectory, newUserDirectory); } catch (IOException e) { addOperationResultMessage( context, "Unable to copy bootstrap directory. Check log files for error"); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_USERS_PAGE); _logger.error(e); return entries; } try { // Configure blog Properties blogProperties = BlojsomUtils.loadProperties( _servletConfig, _blojsomConfiguration.getBaseConfigurationDirectory() + blogUserID + '/' + BLOG_DEFAULT_PROPERTIES); blogProperties.put(BLOG_HOME_IP, _blogHomeBaseDirectory + blogUserID); File blogHomeDirectory = new File(_blogHomeBaseDirectory + blogUserID); if (!blogHomeDirectory.mkdirs()) { _logger.error( "Unable to create blog home directory: " + blogHomeDirectory.toString()); addOperationResultMessage( context, "Unable to create blog home directory for blog ID: " + blogUserID); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_USERS_PAGE); return entries; } blogProperties.put(BLOG_BASE_URL_IP, blogBaseURL); blogProperties.put(BLOG_URL_IP, blogURL); // Write out the blog configuration File blogConfigurationFile = new File( _blojsomConfiguration.getInstallationDirectory() + _blojsomConfiguration.getBaseConfigurationDirectory() + blogUserID + '/' + BLOG_DEFAULT_PROPERTIES); FileOutputStream fos = new FileOutputStream(blogConfigurationFile); blogProperties.store(fos, null); fos.close(); _logger.debug( "Wrote blog configuration information for new user: "******"Set authorization information for new user: "******"Wrote blog authorization information for new user: "******"Loaded flavor information for new user: "******"Added plugin chain: " + plugin + '=' + pluginProperties.getProperty(plugin) + " for user: "******"Loaded plugin chain map for new user: "******"/"); File bootstrapResourcesDirectory = new File(bootstrapDirectory, _blojsomConfiguration.getResourceDirectory()); if (!blogResourcesDirectory.mkdirs()) { _logger.error( "Unable to create blog resource directory: " + blogResourcesDirectory.toString()); } else { _logger.debug("Added blog resource directory: " + blogResourcesDirectory.toString()); } try { if (bootstrapResourcesDirectory.exists()) { BlojsomUtils.copyDirectory(bootstrapResourcesDirectory, blogResourcesDirectory); } // Cleanup the bootstrap resources directory File resourcesDirectoryToDelete = new File( _blojsomConfiguration.getInstallationDirectory() + _blojsomConfiguration.getBaseConfigurationDirectory() + blogUserID + _blojsomConfiguration.getResourceDirectory()); if (resourcesDirectoryToDelete.exists()) { BlojsomUtils.deleteDirectory(resourcesDirectoryToDelete); } } catch (IOException e) { _logger.error(e); } // Add the user to the global list of users _blojsomConfiguration.getBlogUsers().put(blogUserID, blogUser); writeBlojsomConfiguration(); _logger.debug("Wrote new blojsom configuration after adding new user: "******"Added new blog: " + blogUserID); } } } } return entries; }