List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:org.nuxeo.theme.themes.ThemeSerializer.java
private void serializeFormat(final Format format, final org.w3c.dom.Element domParent) { final String typeName = format.getFormatType().getTypeName(); final org.w3c.dom.Element domElement = doc.createElement(typeName); final String description = format.getDescription(); if (description != null) { domParent.appendChild(doc.createComment(String.format(" %s ", description))); }/*www . j a v a 2 s . c o m*/ StringBuilder s = new StringBuilder(); Iterator<Element> iter = ElementFormatter.getElementsFor(format).iterator(); boolean hasElement = iter.hasNext(); while (iter.hasNext()) { Element element = iter.next(); s.append(element.computeXPath()); if (iter.hasNext()) { s.append("|"); } } if (hasElement) { domElement.setAttribute("element", s.toString()); } // widgets if ("widget".equals(typeName)) { // view name String viewName = format.getName(); org.w3c.dom.Element domView = doc.createElement("view"); domView.appendChild(doc.createTextNode(viewName)); domElement.appendChild(domView); // properties Properties properties = format.getProperties(); Enumeration<?> names = properties.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if ("view".equals(name)) { continue; } String value = properties.getProperty(name); org.w3c.dom.Element domAttr = doc.createElement(name); domAttr.appendChild(doc.createTextNode(Utils.cleanUp(value))); domElement.appendChild(domAttr); } } // layout else if ("layout".equals(typeName)) { Properties properties = format.getProperties(); Enumeration<?> names = properties.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String value = properties.getProperty(name); org.w3c.dom.Element domView = doc.createElement(name); domView.appendChild(doc.createTextNode(Utils.cleanUp(value))); domElement.appendChild(domView); } } // style else if ("style".equals(typeName)) { Style style = (Style) format; if (style.isExternal()) { return; } String styleName = style.getName(); Style ancestor = (Style) ThemeManager.getAncestorFormatOf(style); if (styleName != null) { domElement.setAttribute("name", styleName); } if (ancestor != null) { domElement.setAttribute("inherit", ancestor.getName()); } if (style.isRemote()) { domElement.setAttribute("remote", "true"); } if ((!style.isRemote() || style.isCustomized())) { for (String viewName : style.getSelectorViewNames()) { for (String path : style.getPathsForView(viewName)) { Properties styleProperties = style.getPropertiesFor(viewName, path); if (styleProperties.isEmpty()) { continue; } org.w3c.dom.Element domSelector = doc.createElement("selector"); path = Utils.cleanUp(path); domSelector.setAttribute("path", path); if (!"*".equals(viewName)) { domSelector.setAttribute("view", viewName); } for (Map.Entry<Object, Object> entry : styleProperties.entrySet()) { org.w3c.dom.Element domProperty = doc.createElement((String) entry.getKey()); String value = (String) entry.getValue(); String presetName = PresetManager.extractPresetName(null, value); if (presetName != null) { domProperty.setAttribute("preset", presetName); } else { domProperty.appendChild(doc.createTextNode(Utils.cleanUp(value))); } domSelector.appendChild(domProperty); } // Set selector description String selectorDescription = style.getSelectorDescription(path, viewName); if (selectorDescription != null) { domElement.appendChild(doc.createComment(String.format(" %s ", selectorDescription))); } domElement.appendChild(domSelector); } } } } domParent.appendChild(domElement); }
From source file:org.wso2.carbon.identity.notification.mgt.NotificationMgtConfigBuilder.java
/** * Build a list of subscription by a particular module * * @param moduleName Name of the module * @param moduleProperties Set of properties which * @return A list of subscriptions by the module */// www . jav a 2 s .c om private List<Subscription> buildSubscriptionList(String moduleName, Properties moduleProperties) { // Get subscribed events Properties subscriptions = NotificationManagementUtils.getSubProperties( moduleName + "." + NotificationMgtConstants.Configs.SUBSCRIPTION, moduleProperties); List<Subscription> subscriptionList = new ArrayList<Subscription>(); Enumeration propertyNames = subscriptions.propertyNames(); // Iterate through events and build event objects while (propertyNames.hasMoreElements()) { String key = (String) propertyNames.nextElement(); String subscriptionName = (String) subscriptions.remove(key); // Read all the event properties starting from the event prefix Properties subscriptionProperties = NotificationManagementUtils.getPropertiesWithPrefix( moduleName + "." + NotificationMgtConstants.Configs.SUBSCRIPTION + "." + subscriptionName, moduleProperties); Subscription subscription = new Subscription(subscriptionName, subscriptionProperties); subscriptionList.add(subscription); } return subscriptionList; }
From source file:org.apache.jcs.engine.control.CompositeCacheConfigurator.java
/** * Create caches used internally. System status gives them creation * priority./*from w w w .j av a 2s . com*/ * * @param props */ protected void parseSystemRegions(Properties props) { Enumeration en = props.propertyNames(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); if (key.startsWith(SYSTEM_REGION_PREFIX) && (key.indexOf("attributes") == -1)) { String regionName = key.substring(SYSTEM_REGION_PREFIX.length()); String value = OptionConverter.findAndSubst(key, props); ICache cache; synchronized (regionName) { cache = parseRegion(props, regionName, value, null, SYSTEM_REGION_PREFIX); } compositeCacheManager.systemCaches.put(regionName, cache); // to be availiable for remote reference they need to be here as // well compositeCacheManager.caches.put(regionName, cache); } } }
From source file:PropertiesHelper.java
/** * Adds new properties to an existing set of properties while * substituting variables. This function will allow value * substitutions based on other property values. Value substitutions * may not be nested. A value substitution will be ${property.key}, * where the dollar-brace and close-brace are being stripped before * looking up the value to replace it with. Note that the ${..} * combination must be escaped from the shell. * * @param b is the set of properties to add to existing properties. * @return the combined set of properties. *//* w ww . j a v a2s.com*/ protected Properties addProperties(Properties b) { // initial // Properties result = new Properties(this); Properties sys = System.getProperties(); Pattern pattern = Pattern.compile("\\$\\{[-a-zA-Z0-9._]+\\}"); for (Enumeration e = b.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String value = b.getProperty(key); // unparse value ${prop.key} inside braces Matcher matcher = pattern.matcher(value); StringBuffer sb = new StringBuffer(); while (matcher.find()) { // extract name of properties from braces String newKey = value.substring(matcher.start() + 2, matcher.end() - 1); // try to find a matching value in result properties String newVal = getProperty(newKey); // if still not found, try system properties if (newVal == null) { newVal = sys.getProperty(newKey); } // replace braced string with the actual value or empty string matcher.appendReplacement(sb, newVal == null ? "" : newVal); } matcher.appendTail(sb); setProperty(key, sb.toString()); } return this; }
From source file:com.ifunshow.antelopeframe.core.web.exception.SimpleMappingExceptionResolver.java
/** * Find a matching view name in the given exception mappings. * @param exceptionMappings mappings between exception class names and error view names * @param ex the exception that got thrown during handler execution * @return the view name, or <code>null</code> if none found * @see #setExceptionMappings/*from w ww .ja v a 2s. c om*/ */ protected String findMatchingViewName(Properties exceptionMappings, Exception ex) { String viewName = null; String dominantMapping = null; int deepest = Integer.MAX_VALUE; for (Enumeration<?> names = exceptionMappings.propertyNames(); names.hasMoreElements();) { String exceptionMapping = (String) names.nextElement(); int depth = getDepth(exceptionMapping, ex); if (depth >= 0 && depth < deepest) { deepest = depth; dominantMapping = exceptionMapping; viewName = exceptionMappings.getProperty(exceptionMapping); } } if (viewName != null && logger.isDebugEnabled()) { logger.debug("Resolving to view '" + viewName + "' for exception of type [" + ex.getClass().getName() + "], based on exception mapping [" + dominantMapping + "]"); } return viewName; }
From source file:org.accada.reader.hal.ControllerProperties.java
/** * Gets the names of the configurable parameters. * /*from w w w . j av a 2s. c o m*/ * @return The parameter names. * * @throws Exception */ public String[] getParameterNames() throws Exception { String[] names = null; InputStream in; Properties props = new Properties(); log.debug("Trying to get Parameters"); //possible Errors are propageted and further processed as HardwareExceptions in = this.getClass().getResourceAsStream("/props/" + propsFile); //possible Errors are propageted and further processed as HardwareExceptions props.load(in); in.close(); Enumeration propNames = props.propertyNames(); names = new String[props.size()]; int i = 0; while (propNames.hasMoreElements()) { names[i] = (String) propNames.nextElement(); i++; } return names; }
From source file:org.jsecurity.realm.text.PropertiesRealm.java
@SuppressWarnings("unchecked") private void createRealmEntitiesFromProperties(Properties properties) { StringBuffer userDefs = new StringBuffer(); StringBuffer roleDefs = new StringBuffer(); Enumeration<String> propNames = (Enumeration<String>) properties.propertyNames(); while (propNames.hasMoreElements()) { String key = propNames.nextElement().trim(); String value = properties.getProperty(key).trim(); if (log.isTraceEnabled()) { log.trace("Processing properties line - key: [" + key + "], value: [" + value + "]."); }/*from w w w. j a v a2s .c o m*/ if (isUsername(key)) { String username = getUsername(key); userDefs.append(username).append(" = ").append(value).append("\n"); } else if (isRolename(key)) { String rolename = getRolename(key); roleDefs.append(rolename).append(" = ").append(value).append("\n"); } else { String msg = "Encountered unexpected key/value pair. All keys must be prefixed with either '" + USERNAME_PREFIX + "' or '" + ROLENAME_PREFIX + "'."; throw new IllegalStateException(msg); } } setUserDefinitions(userDefs.toString()); setRoleDefinitions(roleDefs.toString()); processDefinitions(); }
From source file:org.ow2.chameleon.core.ChameleonConfiguration.java
/** * Loads system properties./*from w w w . ja v a2 s . co m*/ * * @throws java.io.IOException if the system.properties file cannot be read. */ public void loadSystemProperties() throws IOException { InputStream stream = null; try { File file = new File(baseDirectory.getAbsolutePath(), Constants.SYSTEM_PROPERTIES_FILE); Properties ps = new Properties(); if (file.isFile()) { stream = new FileInputStream(file); ps.load(stream); Enumeration e = ps.propertyNames(); while (e.hasMoreElements()) { String k = (String) e.nextElement(); String v = StringUtils.substVars((String) ps.get(k), k, null, System.getProperties()); System.setProperty(k, v); } } } finally { IOUtils.closeQuietly(stream); } }
From source file:org.springframework.web.portlet.handler.SimpleMappingExceptionResolver.java
/** * Find a matching view name in the given exception mappings * @param exceptionMappings mappings between exception class names and error view names * @param ex the exception that got thrown during handler execution * @return the view name, or <code>null</code> if none found * @see #setExceptionMappings/* w ww .java 2s . c o m*/ */ protected String findMatchingViewName(Properties exceptionMappings, Exception ex) { String viewName = null; String dominantMapping = null; int deepest = Integer.MAX_VALUE; for (Enumeration names = exceptionMappings.propertyNames(); names.hasMoreElements();) { String exceptionMapping = (String) names.nextElement(); int depth = getDepth(exceptionMapping, ex); if (depth >= 0 && depth < deepest) { deepest = depth; dominantMapping = exceptionMapping; viewName = exceptionMappings.getProperty(exceptionMapping); } } if (viewName != null && logger.isDebugEnabled()) { logger.debug("Resolving to view '" + viewName + "' for exception of type [" + ex.getClass().getName() + "], based on exception mapping [" + dominantMapping + "]"); } return viewName; }
From source file:org.intermine.web.struts.BagBuildController.java
/** * Set up environment for the buildBag page. * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * @return an ActionForward object defining where control goes next * * @exception Exception if an error occurs *///from ww w. j a v a 2 s. co m @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); final InterMineAPI im = SessionMethods.getInterMineAPI(session); Model model = im.getModel(); ObjectStore os = im.getObjectStore(); ObjectStoreSummary oss = im.getObjectStoreSummary(); Collection<String> qualifiedTypes = model.getClassNames(); ArrayList<String> typeList = new ArrayList(); ArrayList<String> preferedTypeList = new ArrayList(); TagManager tagManager = im.getTagManager(); List<Tag> preferredBagTypeTags = tagManager.getTags("im:preferredBagType", null, "class", im.getProfileManager().getSuperuser()); for (Tag tag : preferredBagTypeTags) { preferedTypeList.add(TypeUtil.unqualifiedName(tag.getObjectIdentifier())); } Map<String, List<FieldDescriptor>> classKeys = im.getClassKeys(); for (Iterator<String> iter = qualifiedTypes.iterator(); iter.hasNext();) { String className = iter.next(); String unqualifiedName = TypeUtil.unqualifiedName(className); if (ClassKeyHelper.hasKeyFields(classKeys, unqualifiedName) && oss.getClassCount(className) > 0) { typeList.add(unqualifiedName); } } Collections.sort(preferedTypeList); Collections.sort(typeList); request.setAttribute("typeList", typeList); request.setAttribute("preferredTypeList", preferedTypeList); BagQueryConfig bagQueryConfig = im.getBagQueryConfig(); String extraClassName = bagQueryConfig.getExtraConstraintClassName(); if (extraClassName != null) { request.setAttribute("extraBagQueryClass", TypeUtil.unqualifiedName(extraClassName)); List extraClassFieldValues = getFieldValues(os, oss, extraClassName, bagQueryConfig.getConstrainField()); request.setAttribute("extraClassFieldValues", extraClassFieldValues); // find the types in typeList that contain a field with the name given by // bagQueryConfig.getConnectField() List<String> typesWithConnectingField = new ArrayList<String>(); Iterator<String> allTypesIterator = new IteratorChain(typeList.iterator(), preferedTypeList.iterator()); while (allTypesIterator.hasNext()) { String connectFieldName = bagQueryConfig.getConnectField(); String typeName = allTypesIterator.next(); String qualifiedTypeName = model.getPackageName() + "." + typeName; ClassDescriptor cd = model.getClassDescriptorByName(qualifiedTypeName); FieldDescriptor fd = cd.getFieldDescriptorByName(connectFieldName); if (fd != null && fd instanceof ReferenceDescriptor) { typesWithConnectingField.add(typeName); } } request.setAttribute("typesWithConnectingField", typesWithConnectingField); final String defaultValue = getDefaultValue(request, im); if (StringUtils.isNotEmpty(defaultValue)) { BuildBagForm bbf = (BuildBagForm) form; bbf.setExtraFieldValue(defaultValue); } } // get example bag values String bagExampleIdentifiersPropertiesKey = "bag.example.identifiers"; ServletContext servletContext = session.getServletContext(); Properties properties = SessionMethods.getWebProperties(servletContext); Properties bagExampleIdentifiers = PropertiesUtil .getPropertiesStartingWith(bagExampleIdentifiersPropertiesKey, properties); if (bagExampleIdentifiers.size() != 0) { Map<String, String> bagExampleIdentifiersMap = new HashMap<String, String>(); Enumeration<?> e = bagExampleIdentifiers.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = bagExampleIdentifiers.getProperty(key); if (key.equals(bagExampleIdentifiersPropertiesKey)) { bagExampleIdentifiersMap.put("default", value); } else { bagExampleIdentifiersMap.put(key.replace(bagExampleIdentifiersPropertiesKey + ".", ""), value); } bagExampleIdentifiers.getProperty(key); } request.setAttribute("bagExampleIdentifiers", bagExampleIdentifiersMap); } return null; }