Example usage for java.util Properties put

List of usage examples for java.util Properties put

Introduction

In this page you can find the example usage for java.util Properties put.

Prototype

@Override
    public synchronized Object put(Object key, Object value) 

Source Link

Usage

From source file:Examples.java

/**
 * A fuller example showing how the TrAX interface can be used 
 * to serialize a DOM tree.//from  ww  w.ja  v  a  2  s . c  o m
 */
public static void exampleAsSerializer(String sourceID, String xslID) throws TransformerException,
        TransformerConfigurationException, SAXException, IOException, ParserConfigurationException {
    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
    org.w3c.dom.Document outNode = docBuilder.newDocument();
    Node doc = docBuilder.parse(new InputSource(sourceID));

    TransformerFactory tfactory = TransformerFactory.newInstance();

    // This creates a transformer that does a simple identity transform, 
    // and thus can be used for all intents and purposes as a serializer.
    Transformer serializer = tfactory.newTransformer();

    Properties oprops = new Properties();
    oprops.put("method", "html");
    serializer.setOutputProperties(oprops);
    serializer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(System.out)));
}

From source file:com.topsec.tsm.common.message.CommandHandlerUtil.java

public static Serializable handleQueryServerInfo(Serializable obj, NodeMgrFacade nodeMgrFacade) {
    long currentTime = System.currentTimeMillis();
    try {/*from   ww w. j  a  v a  2 s .  com*/
        //server??License?
        //?server???
        //change code
        Node smpNode = nodeMgrFacade.getNodeByNodeId(NodeDefinition.NODE_TYPE_SMP);
        while (smpNode == null) {
            nodeMgrFacade.registerSMP();
            Thread.sleep(2000);
            System.out.println("Server Starting...");
            smpNode = nodeMgrFacade.getNodeByNodeId(NodeDefinition.NODE_TYPE_SMP);
        }
        Properties props = new Properties();
        props.put("LicenseType", TalVersionUtil.getInstance().getVersion());
        props.put("NODEID", smpNode.getNodeId());
        long endTimer = System.currentTimeMillis();
        logger.info("Get server info used:" + (endTimer - currentTime));
        return props;
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    }
}

From source file:org.eclipse.gemini.blueprint.test.internal.util.PropertiesUtil.java

/**
 * Filter/Eliminate keys that have a value that starts with the given prefix.
 * /*  w w w . ja  va2 s.  c o  m*/
 * @param properties
 * @param prefix
 * @return
 */
public static Properties filterValuesStartingWith(Properties properties, String prefix) {
    if (!StringUtils.hasText(prefix))
        return EMPTY_PROPERTIES;

    Assert.notNull(properties);
    Properties excluded = (properties instanceof OrderedProperties ? new OrderedProperties()
            : new Properties());

    for (Enumeration enm = properties.keys(); enm.hasMoreElements();) {
        String key = (String) enm.nextElement();
        String value = properties.getProperty(key);
        if (value.startsWith(prefix)) {
            excluded.put(key, value);
        }
    }

    for (Enumeration enm = excluded.keys(); enm.hasMoreElements();) {
        properties.remove(enm.nextElement());
    }
    return excluded;
}

From source file:com.granule.json.utils.XML.java

/**
 * Method to do the transform from an JSON input stream to a XML stream.
 * Neither input nor output streams are closed.  Closure is left up to the caller.
 *
 * @param JSONStream The XML stream to convert to JSON
 * @param XMLStream The stream to write out JSON to.  The contents written to this stream are always in UTF-8 format.
 * @param verbose Flag to denote whether or not to render the XML text in verbose (indented easy to read), or compact (not so easy to read, but smaller), format.
 *
 * @throws IOException Thrown if an IO error occurs.
 *//* www .  j a  va  2s.co  m*/
public static void toXml(InputStream JSONStream, OutputStream XMLStream, boolean verbose) throws IOException {
    if (logger.isLoggable(Level.FINER)) {
        logger.entering(className, "toXml(InputStream, OutputStream)");
    }

    if (XMLStream == null) {
        throw new NullPointerException("XMLStream cannot be null");
    } else if (JSONStream == null) {
        throw new NullPointerException("JSONStream cannot be null");
    } else {

        if (logger.isLoggable(Level.FINEST)) {
            logger.logp(Level.FINEST, className, "transform", "Parsing the JSON and a DOM builder.");
        }

        try {
            //Get the JSON from the stream.
            JSONObject jObject = new JSONObject(JSONStream);

            //Create a new document

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbf.newDocumentBuilder();
            Document doc = dBuilder.newDocument();

            if (logger.isLoggable(Level.FINEST)) {
                logger.logp(Level.FINEST, className, "transform", "Parsing the JSON content to XML");
            }

            convertJSONObject(doc, doc.getDocumentElement(), jObject, "jsonObject");

            //Serialize it.
            TransformerFactory tfactory = TransformerFactory.newInstance();
            Transformer serializer = null;
            if (verbose) {
                serializer = tfactory.newTransformer(new StreamSource(new StringReader(styleSheet)));
                ;
            } else {
                serializer = tfactory.newTransformer();
            }
            Properties oprops = new Properties();
            oprops.put(OutputKeys.METHOD, "xml");
            oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
            oprops.put(OutputKeys.VERSION, "1.0");
            oprops.put(OutputKeys.INDENT, "true");
            serializer.setOutputProperties(oprops);
            serializer.transform(new DOMSource(doc), new StreamResult(XMLStream));

        } catch (Exception ex) {
            IOException iox = new IOException("Problem during conversion");
            iox.initCause(ex);
            throw iox;
        }
    }

    if (logger.isLoggable(Level.FINER)) {
        logger.exiting(className, "toXml(InputStream, OutputStream)");
    }
}

From source file:Examples.java

/**
 * Show how to override output properties.
 *///from ww  w. j  av  a2s.  c om
public static void exampleOutputProperties(String sourceID, String xslID)
        throws TransformerException, TransformerConfigurationException {

    TransformerFactory tfactory = TransformerFactory.newInstance();
    Templates templates = tfactory.newTemplates(new StreamSource(xslID));
    Properties oprops = templates.getOutputProperties();

    oprops.put(OutputKeys.INDENT, "yes");

    Transformer transformer = templates.newTransformer();

    transformer.setOutputProperties(oprops);
    transformer.transform(new StreamSource(sourceID), new StreamResult(new OutputStreamWriter(System.out)));
}

From source file:info.magnolia.importexport.PropertiesImportExport.java

private static void appendNodeTypeAndUUID(Content node, Properties out, final boolean dumpMetaData)
        throws RepositoryException {
    String path = getExportPath(node);
    // we don't need to export the JCR root node.
    if (path.equals("/jcr:root")) {
        return;/*from w  ww .ja v a 2 s .  c o  m*/
    }

    String nodeTypeName = node.getNodeTypeName();
    if (nodeTypeName != null && StringUtils.isNotEmpty(nodeTypeName)) {
        out.put(path + "@type", nodeTypeName);
    }
    String nodeUUID = node.getUUID();
    if (nodeUUID != null && StringUtils.isNotEmpty(nodeUUID)) {
        out.put(path + "@uuid", node.getUUID());
    }
}

From source file:it.infn.ct.security.utilities.LDAPUtils.java

private static DirContext getContext() throws NamingException {
    ResourceBundle rb = ResourceBundle.getBundle("ldap");
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, rb.getString("url"));
    env.put(Context.SECURITY_PRINCIPAL, rb.getString("rootDN"));
    env.put(Context.SECURITY_AUTHENTICATION, "none");
    return new InitialDirContext(env);
}

From source file:eu.eidas.node.utils.PropertiesUtil.java

private static void initProps(Properties props) {
    LOG.info(LoggingMarkerMDC.SYSTEM_EVENT, "Loading properties");
    propertiesMap = new HashMap<String, String>();
    for (Object key : props.keySet()) {
        String keyStr = key.toString();
        propertiesMap.put(keyStr, props.getProperty(keyStr));
    }//  w w  w .  j  a va 2 s.  c  o  m
    if (eidasXmlLocation != null && !props.containsKey(MASTER_CONF_FILE_PARAM)) {
        String fileRepositoryDir = eidasXmlLocation.substring(0,
                eidasXmlLocation.length() - MASTER_CONF_FILE.length());
        propertiesMap.put(MASTER_CONF_FILE_PARAM, fileRepositoryDir);
        props.put(MASTER_CONF_FILE_PARAM, fileRepositoryDir);
    }

}

From source file:it.infn.ct.security.utilities.LDAPUtils.java

private static DirContext getAuthContext(String userCN, String password, boolean dedicatedAdminUser)
        throws NamingException {
    ResourceBundle rb = ResourceBundle.getBundle("ldap");
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, rb.getString("url"));
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    if (dedicatedAdminUser) {
        env.put(Context.SECURITY_PRINCIPAL, rb.getString("bindDN"));
        env.put(Context.SECURITY_CREDENTIALS, rb.getString("bindPass"));
    } else {/*from  ww w  . j  ava2 s  .co  m*/
        env.put(Context.SECURITY_PRINCIPAL, "cn=" + userCN + "," + rb.getString("peopleRoot"));
        env.put(Context.SECURITY_CREDENTIALS, password);
    }

    return new InitialDirContext(env);

}

From source file:net.roboconf.agent.internal.misc.UserDataUtils.java

/**
 * Reconfigures the messaging.//ww  w .  ja v  a  2  s.  co  m
 * @param etcDir the KARAF_ETC directory
 * @param msgData the messaging configuration parameters
 */
public static void reconfigureMessaging(String etcDir, Map<String, String> msgData) throws IOException {

    String messagingType = msgData.get(MessagingConstants.MESSAGING_TYPE_PROPERTY);
    Logger.getLogger(UserDataUtils.class.getName())
            .fine("Messaging type for reconfiguration: " + messagingType);
    if (!Utils.isEmptyOrWhitespaces(etcDir)) {

        // Write the messaging configuration
        Properties props = new Properties();
        props.putAll(msgData);
        props.remove(Constants.MESSAGING_TYPE);

        File f = new File(etcDir, "net.roboconf.messaging." + messagingType + ".cfg");
        Utils.writePropertiesFile(props, f);

        // Set the messaging type
        f = new File(etcDir, CONF_FILE_AGENT);

        props = Utils.readPropertiesFileQuietly(f, Logger.getLogger(UserDataUtils.class.getName()));
        props.put(Constants.MESSAGING_TYPE, messagingType);
        Utils.writePropertiesFile(props, f);
    }
}