Example usage for java.util Properties loadFromXML

List of usage examples for java.util Properties loadFromXML

Introduction

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

Prototype

public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException 

Source Link

Document

Loads all of the properties represented by the XML document on the specified input stream into this properties table.

Usage

From source file:de.blinkt.openvpn.ActivityDashboard.java

public String getProperty(String key) {
    Properties prop = new Properties();
    String value = null;/*w w w.  j av a2s .c  om*/
    try {
        FileInputStream fi = new FileInputStream(getFilesDir() + "/setting.xml");
        prop.loadFromXML(fi);

        value = prop.getProperty(key);
    } catch (Exception e) {
        System.out.println(e);
    }
    return value;
}

From source file:org.kchine.r.server.impl.RServantImpl.java

public RServantImpl(String name, String prefix, Registry registry) throws RemoteException {
    super(name, prefix, registry, _port);

    log.info("$$>rmi.port.start:" + _port);
    // --------------   
    init();/*from  ww w. j  a  v  a  2s.c  om*/

    log.info("Stub:" + PoolUtils.stubToHex(this));

    if (System.getProperty("preloadall") != null && System.getProperty("preloadall").equalsIgnoreCase("true")) {
        try {
            Properties props = new Properties();
            props.loadFromXML(this.getClass().getResourceAsStream("/classlist.xml"));
            for (Object c : props.keySet()) {
                this.getClass().getClassLoader().loadClass((String) c);
            }

        } catch (Exception e) {
            //e.printStackTrace();
        }

        try {
            Properties props = new Properties();
            props.loadFromXML(this.getClass().getResourceAsStream("/resourcelist.xml"));
            for (Object c : props.keySet()) {
                DirectJNI.getInstance().getResourceAsStream((String) c);
            }
        } catch (Exception e) {
            //e.printStackTrace();
        }
    }

    if (System.getProperty("http.port") != null && !System.getProperty("http.port").equals("")) {
        try {
            final int port = Integer.decode(System.getProperty("http.port"));
            new Thread(new Runnable() {
                public void run() {
                    try {
                        startHttpServer(port);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    new Thread(new Runnable() {
        public void run() {
            try {
                GroovyInterpreterSingleton.getInstance().exec("import org.kchine.r.server.R;");
                GroovyInterpreterSingleton.getInstance().exec("R=org.kchine.r.server.R.getInstance();");
                //GroovyInterpreterSingleton.getInstance().exec("SCI=(org.kchine.scilab.server.ScilabServices)org.kchine.r.server.R.getInstance();");
                //GroovyInterpreterSingleton.getInstance().exec("OO=(org.kchine.openoffice.server.OpenOfficeServices)org.kchine.r.server.R.getInstance();");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }).start();

}

From source file:de.huxhorn.lilith.swing.ApplicationPreferences.java

/**
 * @param file the properties xml file//from  w w  w .  j  a  v a2s.  co m
 * @return the resulting map
 * @noinspection MismatchedQueryAndUpdateOfCollection
 */
private Map<String, String> loadPropertiesXml(File file) {
    InputStream is = null;
    try {
        is = new BufferedInputStream(new FileInputStream(file));
        Properties props = new Properties();
        props.loadFromXML(is);
        Map<String, String> result = new HashMap<>();
        for (Object keyObj : props.keySet()) {
            String key = (String) keyObj;
            String value = (String) props.get(key);
            if (value != null) {
                result.put(key, value);
            }
        }
        return result;
    } catch (IOException e) {
        if (logger.isWarnEnabled())
            logger.warn("Couldn't load properties from '" + file.getAbsolutePath() + "'!", e);
    } finally {
        IOUtilities.closeQuietly(is);
    }
    return null;
}

From source file:uk.chromis.pos.inventory.ProductsEditor.java

private void jPropertyAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPropertyAddButtonActionPerformed
    Properties props = new Properties();

    try {/*from w  w w. j  av  a  2 s .  c om*/
        if (!txtProperties.getText().isEmpty()) {
            props.loadFromXML(
                    new ByteArrayInputStream(txtProperties.getText().getBytes(StandardCharsets.UTF_8)));
        }
    } catch (IOException ex) {
        Logger.getLogger(ProductsEditor.class.getName()).log(Level.SEVERE, null, ex);
    }

    String sel = (String) jComboProperties.getSelectedItem();
    String type = m_PropertyOptions.getProperty(sel, "");

    int nComma = type.indexOf(',');
    if (nComma > 0) {
        type = type.substring(0, nComma).trim();
    }

    switch (type) {
    case "boolean":
        String sYes = (String) jPropertyValueCombo.getSelectedItem();
        sYes = sYes.compareTo("Yes") == 0 ? "1" : "0";
        props.put(sel, sYes);
        break;
    case "number":
        Double dValue;
        try {
            dValue = (Double) Formats.DOUBLE.parseValue(jPropertyValueText.getText());
        } catch (BasicException ex) {
            dValue = 0.0;
        }
        props.put(sel, dValue.toString());
        break;
    case "option":
        props.put(sel, (String) jPropertyValueCombo.getSelectedItem());
        break;
    case "text":
        props.put(sel, (String) jPropertyValueText.getText());
        break;
    default:
        break;
    }

    try {
        ByteArrayOutputStream o = new ByteArrayOutputStream();
        props.storeToXML(o, AppLocal.APP_NAME, "UTF-8");
        txtProperties.setText(o.toString());
    } catch (IOException ex) {
        Logger.getLogger(ProductsEditor.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:uk.chromis.pos.inventory.ProductsEditor.java

private ProductInfoExt getProductInfo() {

    ProductInfoExt info = new ProductInfoExt();
    info.setReference(m_jRef.getText());
    info.setCode(m_jCode.getText());//  w  w  w . jav  a 2s  .c o m
    info.setName(m_jName.getText());
    info.setCom(m_jComment.isSelected());
    info.setScale(m_jScale.isSelected());
    info.setPriceBuy(readCurrency(m_jPriceBuy.getText()));
    info.setPriceSell(readCurrency(m_jPriceSell.getText()));

    info.setCategoryID((String) m_CategoryModel.getSelectedKey());
    info.setPromotionID((String) m_PromotionModel.getSelectedKey());
    info.setTaxCategoryID((String) taxcatmodel.getSelectedKey());
    info.setAttributeSetID((String) attmodel.getSelectedKey());
    info.setTaxRate(taxeslogic.getTaxRate((TaxCategoryInfo) taxcatmodel.getSelectedItem()));
    info.setImage(m_jImage.getImage());

    info.setStockCost(readCurrency(m_jstockcost.getText()));
    info.setStockVolume(readCurrency(m_jstockvolume.getText()));

    info.setInCatalog(m_jInCatalog.isSelected());
    info.setRetired(m_jRetired.isSelected());

    String val = m_jCatalogOrder.getText();
    if (!val.isEmpty())
        info.setCatOrder(Double.parseDouble(val));

    info.setKitchen(m_jKitchen.isSelected());
    info.setService(m_jService.isSelected());

    info.setReference(m_jRef.getText());

    info.setVprice(m_jVprice.isSelected());
    info.setVerpatrib(m_jVerpatrib.isSelected());

    info.setTextTip(m_jTextTip.getText());
    info.setWarranty(m_jCheckWarrantyReceipt.isSelected());

    val = m_jStockUnits.getText();
    if (!val.isEmpty())
        info.setStockUnits(Double.parseDouble(val));

    info.setAlias(m_jAlias.getText());
    info.setAlwaysAvailable(m_jAlwaysAvailable.isSelected());
    info.setCanDiscount(m_jDiscounted.isSelected());
    info.setManageStock(m_jManageStock.isSelected());
    info.setIsPack(m_jIsPack.isSelected());

    val = m_jPackQuantity.getText();
    if (!val.isEmpty())
        info.setPackQuantity(Double.parseDouble(val));

    info.setPackProduct((String) packproductmodel.getSelectedKey());

    info.setDisplay(m_jDisplay.getText());

    Properties props = new Properties();
    try {
        String xml = txtProperties.getText();
        if (!xml.isEmpty()) {
            props.loadFromXML(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
        }
        info.setProperties(props);
    } catch (IOException ex) {
        Logger.getLogger(ProductsEditor.class.getName()).log(Level.SEVERE, null, ex);
    }

    return info;
}

From source file:com.lfv.lanzius.server.LanziusServer.java

private void menuChoiceServerStart() {
    if (isSwapping)
        return;/* ww  w  . j  a  v  a 2 s .com*/
    log.info("Menu: Starting server");
    try {
        // Create a HTTP server for information exchange
        httpServer = new Server();

        // Setup velocity
        Velocity.init();

        // Read the property files
        Properties serverProperties = new Properties();
        serverProperties.loadFromXML(new FileInputStream("data/properties/serverproperties.xml"));
        logEvents = serverProperties.getProperty("LogEvents", "false").equalsIgnoreCase("true");
        if (logEvents)
            log.info("Enabling event logging");

        // Setup HTTP server
        int httpPort = Integer.parseInt(serverProperties.getProperty("HttpPort", "36600"));
        httpConnector = new SelectChannelConnector();
        httpConnector.setPort(httpPort);
        httpServer.setConnectors(new Connector[] { httpConnector });

        // Dynamic context handler for the xml data provider
        ContextHandler xmlContextHandler = new ContextHandler();
        xmlContextHandler.setContextPath("/xml");
        Handler xmlHandler = new InfoRequestHandler(this, log);
        xmlContextHandler.setHandler(xmlHandler);
        httpServer.setHandlers(new Handler[] { xmlContextHandler });

        // Create a bundle
        bundle = new ServerBundle(doc);

        // Create server logger map containing all available loggers
        loggerMap = Collections.synchronizedMap(new TreeMap<Integer, ServerLogger>());

        // Start the UDP server
        int port = Integer.parseInt(serverProperties.getProperty("UdpPort", "36604"));
        networkManager = new ServerNetworkManager(port, bundle, this);

        networkManager.setNetworkHandler(this);

        isaTracePainter = serverProperties.getProperty("ISATracePainter", "line");
        panel.resetIsaChart();

    } catch (Exception ex) {
        log.error("Unable to start server! ", ex);
        JOptionPane.showMessageDialog(frame,
                "Unable to start server! Check the validity of the configuration file, the serverproperties.xml and\nthe networkproperties.ini files!  Also make sure that no other server is already running!",
                "Error!", JOptionPane.ERROR_MESSAGE);
        return;
    }

    try {
        serverStartedDate = null;

        networkManager.start();
        serverStartedDate = new Date();

        // Start the HTTP server
        httpServer.start();

        // Tell it to the view to show an icon
        panel.setServerStartedDate(serverStartedDate);

    } catch (Exception ex) {
        log.error("Unable to start server!", ex);
        JOptionPane.showMessageDialog(frame,
                "Unable to start server! Check the validity of the configuration file, the serverproperties.xml and\nthe networkproperties.ini files!  Also make sure that no other server is already running!",
                "Error!", JOptionPane.ERROR_MESSAGE);
        // Network manager has been started, stop it again!
        if (serverStartedDate != null) {
            networkManager.stop();
            serverStartedDate = null;
        }
    }
}

From source file:org.kchine.r.server.DirectJNI.java

private static void init(ClassLoader cl) throws Exception {
    Properties props = new Properties();
    InputStream is = cl.getResourceAsStream("maps/rjbmaps.xml");
    System.out.println("####### is:" + is);
    props.loadFromXML(is);
    DirectJNI._packageNames = (Vector<String>) PoolUtils.hexToObject((String) props.get("PACKAGE_NAMES"), cl);
    DirectJNI._s4BeansMapping = (HashMap<String, String>) PoolUtils
            .hexToObject((String) props.get("S4BEANS_MAP"), cl);
    DirectJNI._s4BeansMappingRevert = (HashMap<String, String>) PoolUtils
            .hexToObject((String) props.get("S4BEANS_REVERT_MAP"), cl);
    DirectJNI._factoriesMapping = (HashMap<String, String>) PoolUtils
            .hexToObject((String) props.get("FACTORIES_MAPPING"), cl);
    DirectJNI._s4BeansHash = (HashMap<String, Class<?>>) PoolUtils
            .hexToObject((String) props.get("S4BEANS_HASH"), cl);
    DirectJNI._rPackageInterfacesHash = (HashMap<String, Vector<Class<?>>>) PoolUtils
            .hexToObject((String) props.get("R_PACKAGE_INTERFACES_HASH"), cl);
    DirectJNI._abstractFactories = (Vector<String>) PoolUtils
            .hexToObject((String) props.get("ABSTRACT_FACTORIES"), cl);
    log.info("<> rPackageInterfaces:" + DirectJNI._packageNames);
    log.info("<> s4Beans MAP :" + DirectJNI._s4BeansMapping);
    log.info("<> s4Beans Revert MAP :" + DirectJNI._s4BeansMappingRevert);
    log.info("<> factories :" + DirectJNI._factoriesMapping);
    _mappingClassLoader = cl;//from ww w .j  a v  a 2s. co m
    _resourcesClassLoader = cl;
    Thread.currentThread().setContextClassLoader(_resourcesClassLoader);
    DirectJNI.getInstance().getRServices().sourceFromResource("/bootstrap.R");
    DirectJNI.getInstance().initPackages();
    DirectJNI.getInstance().upgdateBootstrapObjects();
}