List of usage examples for java.util Properties storeToXML
public void storeToXML(OutputStream os, String comment) throws IOException
From source file:org.pentaho.metadata.registry.SimpleFileRegistry.java
/** * @see org.pentaho.metadata.registry.IMetadataRegistry#commit() *///from w w w. ja v a 2 s. co m @Override public void commit() throws Exception { // save the links List<Link> links = getLinks(); Properties props = new Properties(); int idx = 0; for (Link link : links) { props.put("link-" + idx + "-subId", link.getSubjectId()); props.put("link-" + idx + "-subType", link.getSubjectTypeId()); props.put("link-" + idx + "-verb", link.getVerbId()); props.put("link-" + idx + "-objId", link.getObjectId()); props.put("link-" + idx + "-objType", link.getObjectTypeId()); idx++; } idx = 0; Map<String, Map<String, Entity>> entities = getEntities(); for (Entry<String, Map<String, Entity>> entry : entities.entrySet()) { Map<String, Entity> typeMap = entry.getValue(); Set<Entry<String, Entity>> typeSet = typeMap.entrySet(); for (Entry<String, Entity> typeEntry : typeSet) { Entity entity = typeEntry.getValue(); props.put("entity-" + idx + "-id", entity.getId()); props.put("entity-" + idx + "-type", entity.getTypeId()); if (entity.getTitle() != null) { props.put("entity-" + idx + "-title", entity.getTitle()); } else { props.put("entity-" + idx + "-title", entity.getId()); } Map<String, String> attrMap = entity.getAttributes(); int idx2 = 0; for (Entry<String, String> attrEntry : attrMap.entrySet()) { String key = attrEntry.getKey(); String value = attrEntry.getValue(); props.put("entity-" + idx + "-attrkey-" + idx2, key); props.put("entity-" + idx + "-attrvalue-" + idx2, StringEscapeUtils.escapeJava(value)); idx2++; } idx++; } } File file = new File(filePath); OutputStream out = new FileOutputStream(file); try { props.storeToXML(out, null); } finally { out.close(); } }
From source file:org.olat.admin.registration.SystemRegistrationManager.java
String getRegistrationPropertiesMessage(Properties tempConfiguration) { Properties msgProperties = new Properties(); if (tempConfiguration == null) { // Create temp properties from persisted properties tempConfiguration = persitedProperties.createPropertiesFromPersistedProperties(); }/*from w w w .j a v a2 s. c o m*/ final boolean website = Boolean.parseBoolean(tempConfiguration.getProperty(CONF_KEY_PUBLISH_WEBSITE)); final boolean notify = Boolean.parseBoolean(tempConfiguration.getProperty(CONF_KEY_NOTIFY_RELEASES)); if (website || notify) { msgProperties = tempConfiguration; msgProperties.setProperty("RegistrationVersion", "1.0"); // OLAT version msgProperties.setProperty("olatAppName", Settings.getApplicationName()); msgProperties.setProperty("olatVersion", Settings.getFullVersionInfo()); // System config msgProperties.setProperty("configInstantMessagingEnabled", String.valueOf(InstantMessagingModule.isEnabled())); msgProperties.setProperty("configLanguages", I18nModule.getEnabledLanguageKeys().toString()); msgProperties.setProperty("configClusterEnabled", clusterMode); msgProperties.setProperty("configDebugginEnabled", String.valueOf(Settings.isDebuging())); // Course counts final RepositoryManager repoMgr = RepositoryManager.getInstance(); final int allCourses = repoMgr.countByTypeLimitAccess(CourseModule.ORES_TYPE_COURSE, RepositoryEntry.ACC_OWNERS); final int publishedCourses = repoMgr.countByTypeLimitAccess(CourseModule.ORES_TYPE_COURSE, RepositoryEntry.ACC_USERS); msgProperties.setProperty("courseCountAll", String.valueOf(allCourses)); msgProperties.setProperty("courseCountPublished", String.valueOf(publishedCourses)); // User counts final BaseSecurity secMgr = BaseSecurityManager.getInstance(); final SecurityGroup olatuserGroup = secMgr.findSecurityGroupByName(Constants.GROUP_OLATUSERS); final int users = secMgr.countIdentitiesOfSecurityGroup(olatuserGroup); final int disabled = secMgr.getIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_LOGIN_DENIED).size(); msgProperties.setProperty("usersEnabled", String.valueOf(users - disabled)); final PermissionOnResourceable[] permissions = { new PermissionOnResourceable(Constants.PERMISSION_HASROLE, Constants.ORESOURCE_AUTHOR) }; final List<Identity> authorsList = secMgr.getIdentitiesByPowerSearch(null, null, true, null, permissions, null, null, null, null, null, null); final int authors = authorsList.size(); msgProperties.setProperty("usersAuthors", String.valueOf(authors)); // Activity final Calendar lastLoginLimit = Calendar.getInstance(); lastLoginLimit.add(Calendar.DAY_OF_YEAR, -6); // -1 - 6 = -7 for last // week msgProperties.setProperty("activeUsersLastWeek", String.valueOf(secMgr.countUniqueUserLoginsSince(lastLoginLimit.getTime()))); lastLoginLimit.add(Calendar.MONTH, -1); msgProperties.setProperty("activeUsersLastMonth", String.valueOf(secMgr.countUniqueUserLoginsSince(lastLoginLimit.getTime()))); // Groups final BGContextManager groupMgr = BGContextManagerImpl.getInstance(); final int buddyGroups = groupMgr.countGroupsOfType(BusinessGroup.TYPE_BUDDYGROUP); msgProperties.setProperty("groupCountBuddyGroups", String.valueOf(buddyGroups)); final int learningGroups = groupMgr.countGroupsOfType(BusinessGroup.TYPE_LEARNINGROUP); msgProperties.setProperty("groupCountLearningGroups", String.valueOf(learningGroups)); final int rightGroups = groupMgr.countGroupsOfType(BusinessGroup.TYPE_RIGHTGROUP); msgProperties.setProperty("groupCountRightGroups", String.valueOf(rightGroups)); if (website) { // URL msgProperties.setProperty("websiteURL", Settings.getServerContextPathURI()); // Description final String desc = tempConfiguration.getProperty(CONF_KEY_WEBSITE_DESCRIPTION); msgProperties.setProperty("websiteDescription", desc); } if (notify) { // Email final String email = tempConfiguration.getProperty(CONF_KEY_EMAIL); msgProperties.setProperty("email", email); } } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { msgProperties.storeToXML(baos, "OLAT Registration Data, since 6.1.1 Release"); } catch (final IOException e) { throw new OLATRuntimeException("OLAT Registration failed", e); } String retVal = null; try { retVal = baos.toString("UTF8"); } catch (final UnsupportedEncodingException e) { throw new OLATRuntimeException("OLAT Registration failed", e); } return retVal; }