Example usage for java.lang System setProperty

List of usage examples for java.lang System setProperty

Introduction

In this page you can find the example usage for java.lang System setProperty.

Prototype

public static String setProperty(String key, String value) 

Source Link

Document

Sets the system property indicated by the specified key.

Usage

From source file:Main.java

public static String deleteUrl(String url, Bundle params) throws MalformedURLException, IOException {
    System.setProperty("http.keepAlive", "false");
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " agent");
    conn.setRequestMethod("DELETE");
    conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    conn.setDoOutput(false);/*from   w w w  .j a  v  a  2s .c  o  m*/
    conn.setDoInput(true);
    //conn.setRequestProperty("Connection", "Keep-Alive");
    conn.connect();

    String response = "";
    try {
        response = read(conn.getInputStream());
    } catch (FileNotFoundException e) {
        // Error Stream contains JSON that we can parse to a FB error
        response = read(conn.getErrorStream());
    }
    return response;
}

From source file:Main.java

public static synchronized DocumentBuilderFactory getDocumentBuilderFactory() {
    String oldDbfImpl = System.getProperty(DBF_SYSTEM_PROPERTY);
    System.setProperty(DBF_SYSTEM_PROPERTY, JAVA_INTERNAL_DBF_CLASS);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    if (oldDbfImpl != null) {
        System.setProperty(DBF_SYSTEM_PROPERTY, oldDbfImpl);
    } else {//ww w.  j av  a 2 s . c o  m
        System.getProperties().remove(DBF_SYSTEM_PROPERTY);
    }
    return dbf;
}

From source file:Main.java

/**
 * Set smart revalidate to true to incur less overhead when the method
 * {@link Component#revalidate()} is called.
 * <br>Revalidate calls {@link Container#isValidateRoot()} which 
 * normally results in calling {@link Component#validate()} for the top Windows/Frame/Dialog container.
 * With smart revalidate the "validate root" can be a scroll-pane for example
 * (see also {@link JComponent#isValidateRoot()}.
 *///from   w  w w . j  av  a  2s  .co m
public static void smartRevalidate(boolean beSmart) {
    System.setProperty("java.awt.smartInvalidate", Boolean.toString(beSmart));
}

From source file:Main.java

public static String format(String xml) throws Exception {
    InputSource src = new InputSource(new StringReader(xml));
    Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
    Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml"));

    System.setProperty(DOMImplementationRegistry.PROPERTY,
            "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");

    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
    LSSerializer writer = impl.createLSSerializer();

    writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
    writer.getDomConfig().setParameter("xml-declaration", keepDeclaration);
    return writer.writeToString(document);
}

From source file:Main.java

private static XPathFactory getXPathFactory() throws XPathFactoryConfigurationException {
    if (_xPathFactory == null) {
        String magicValue = System
                .getProperty("javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom");
        System.setProperty("javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom",
                "net.sf.saxon.xpath.XPathFactoryImpl");
        //          System.setProperty("javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom","org.apache.xpath.jaxp.XPathFactoryImpl");
        //          System.setProperty("jaxp.debug","yes");
        _xPathFactory = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);
        if (magicValue == null)
            System.clearProperty("javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom");
        else// w ww.ja  va 2 s.  c om
            System.setProperty("javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom", magicValue);
    }
    return _xPathFactory;
}

From source file:Main.java

private static String connect(String uri, String charsetName) {
    String result = "";
    try {/*from   w  w  w  .  j a  va2s  . co m*/
        URL url = new URL(uri);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setConnectTimeout(5 * 1000);
        if (Integer.parseInt(Build.VERSION.SDK) < 8) {
            System.setProperty("http.keepAlive", "false");
        }
        if (conn.getResponseCode() == 200) {
            InputStream is = conn.getInputStream();
            result = readData(is, charsetName);
        }
        conn.disconnect();
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    } catch (Exception e) {
    }
    return result;
}

From source file:com.lucidworks.client.SecurityUtils.java

public static void setSecurityConfig() {
    final String jassFile = System.getProperty(LWWW_JAAS_FILE);
    if (jassFile != null) {
        log.info("Using kerberized Solr.");
        System.setProperty("java.security.auth.login.config", jassFile);
        final String appname = System.getProperty(LWWW_JAAS_APPNAME, "Client");
        System.setProperty("solr.kerberos.jaas.appname", appname);
        HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer());
    }//  w w w .ja  va2  s  .  c om
}

From source file:Main.java

public static Object getNodesListXpath(String XpathS, Node node, String nsuri, String pre, QName returnType)
        throws Exception {
    Object matches = null;/*from   w  ww  .j a  v  a  2 s.  co  m*/
    // TODO move this to a generic start up method
    System.setProperty("javax.xml.xpath.XPathFactory:" + XPathConstants.DOM_OBJECT_MODEL, XpathFactory);

    XPathFactory xpathFactory = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);
    XPath xpath = xpathFactory.newXPath();
    XPathExpression xpe = xpath.compile(XpathS);
    matches = xpe.evaluate(node, returnType);

    return matches;
}

From source file:com.ngdata.hbaseindexer.indexer.SecurityUtils.java

public static void setSecurityConfig() {
    final String jaasFile = System.getProperty(LWW_JAAS_FILE);
    if (jaasFile != null) {
        log.info("Using kerberized Solr.");
        System.setProperty("java.security.auth.login.config", jaasFile);
        final String appname = System.getProperty(LWW_JAAS_APPNAME, "Client");
        System.setProperty("solr.kerberos.jaas.appname", appname);
        HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer());
    }//from   ww  w  . j  av  a2s  .c om
}

From source file:Main.java

public static String simplePost(String url, Bundle params, String method)
        throws MalformedURLException, IOException {
    OutputStream os;/*from  w  ww .ja va2 s .c o  m*/

    System.setProperty("http.keepAlive", "false");
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " agent");

    conn.setRequestMethod(method);
    conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    conn.setDoOutput(true);
    conn.setDoInput(true);
    //conn.setRequestProperty("Connection", "Keep-Alive");

    conn.connect();

    os = new BufferedOutputStream(conn.getOutputStream());
    os.write(encodePostParams(params).getBytes());
    os.flush();

    String response = "";
    try {
        response = read(conn.getInputStream());
    } catch (FileNotFoundException e) {
        // Error Stream contains JSON that we can parse to a FB error
        response = read(conn.getErrorStream());
    }
    return response;
}