Example usage for java.util TimeZone LONG

List of usage examples for java.util TimeZone LONG

Introduction

In this page you can find the example usage for java.util TimeZone LONG.

Prototype

int LONG

To view the source code for java.util TimeZone LONG.

Click Source Link

Document

A style specifier for getDisplayName() indicating a long name, such as "Pacific Standard Time."

Usage

From source file:com.landenlabs.all_devtool.SystemFragment.java

public void updateList() {
    // Time today = new Time(Time.getCurrentTimezone());
    // today.setToNow();
    // today.format(" %H:%M:%S")
    Date dt = new Date();
    m_titleTime.setText(m_timeFormat.format(dt));

    boolean expandAll = m_list.isEmpty();
    m_list.clear();//from ww w .j a  v a2 s.co  m

    // Swap colors
    int color = m_rowColor1;
    m_rowColor1 = m_rowColor2;
    m_rowColor2 = color;

    ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);

    try {
        String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(),
                Settings.Secure.ANDROID_ID);
        addBuild("Android ID", androidIDStr);

        try {
            AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext());
            final String adIdStr = adInfo.getId();
            final boolean isLAT = adInfo.isLimitAdTrackingEnabled();
            addBuild("Ad ID", adIdStr);
        } catch (IOException e) {
            // Unrecoverable error connecting to Google Play services (e.g.,
            // the old version of the service doesn't support getting AdvertisingId).
        } catch (GooglePlayServicesNotAvailableException e) {
            // Google Play services is not available entirely.
        }

        /*
        try {
        InstanceID instanceID = InstanceID.getInstance(getContext());
        if (instanceID != null) {
            // Requires a Google Developer project ID.
            String authorizedEntity = "<need to make this on google developer site>";
            instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
            addBuild("Instance ID", instanceID.getId());
        }
        } catch (Exception ex) {
        }
        */

        ConfigurationInfo info = actMgr.getDeviceConfigurationInfo();
        addBuild("OpenGL", info.getGlEsVersion());
    } catch (Exception ex) {
        m_log.e(ex.getMessage());
    }

    try {
        long heapSize = Debug.getNativeHeapSize();
        // long maxHeap = Runtime.getRuntime().maxMemory();

        // ConfigurationInfo cfgInfo = actMgr.getDeviceConfigurationInfo();
        int largHeapMb = actMgr.getLargeMemoryClass();
        int heapMb = actMgr.getMemoryClass();

        MemoryInfo memInfo = new MemoryInfo();
        actMgr.getMemoryInfo(memInfo);

        final String sFmtMB = "%.2f MB";
        Map<String, String> listStr = new TreeMap<String, String>();
        listStr.put("Mem Available (now)", String.format(sFmtMB, (double) memInfo.availMem / MB));
        listStr.put("Mem LowWhenOnlyAvail", String.format(sFmtMB, (double) memInfo.threshold / MB));
        if (Build.VERSION.SDK_INT >= 16) {
            listStr.put("Mem Installed", String.format(sFmtMB, (double) memInfo.totalMem / MB));
        }
        listStr.put("Heap (this app)", String.format(sFmtMB, (double) heapSize / MB));
        listStr.put("HeapMax (default)", String.format(sFmtMB, (double) heapMb));
        listStr.put("HeapMax (large)", String.format(sFmtMB, (double) largHeapMb));
        addBuild("Memory...", listStr);
    } catch (Exception ex) {
        m_log.e(ex.getMessage());
    }

    try {
        List<ProcessErrorStateInfo> procErrList = actMgr.getProcessesInErrorState();
        int errCnt = (procErrList == null ? 0 : procErrList.size());
        procErrList = null;

        // List<RunningAppProcessInfo> procList = actMgr.getRunningAppProcesses();
        int procCnt = actMgr.getRunningAppProcesses().size();
        int srvCnt = actMgr.getRunningServices(100).size();

        Map<String, String> listStr = new TreeMap<String, String>();
        listStr.put("#Processes", String.valueOf(procCnt));
        listStr.put("#Proc With Err", String.valueOf(errCnt));
        listStr.put("#Services", String.valueOf(srvCnt));
        // Requires special permission
        //   int taskCnt = actMgr.getRunningTasks(100).size();
        //   listStr.put("#Tasks",  String.valueOf(taskCnt));
        addBuild("Processes...", listStr);
    } catch (Exception ex) {
        m_log.e("System-Processes %s", ex.getMessage());
    }

    try {
        Map<String, String> listStr = new LinkedHashMap<String, String>();
        listStr.put("LargeIconDensity", String.valueOf(actMgr.getLauncherLargeIconDensity()));
        listStr.put("LargeIconSize", String.valueOf(actMgr.getLauncherLargeIconSize()));
        putIf(listStr, "isRunningInTestHarness", "Yes", ActivityManager.isRunningInTestHarness());
        putIf(listStr, "isUserAMonkey", "Yes", ActivityManager.isUserAMonkey());
        addBuild("Misc...", listStr);
    } catch (Exception ex) {
        m_log.e("System-Misc %s", ex.getMessage());
    }

    // --------------- Locale / Timezone -------------
    try {
        Locale ourLocale = Locale.getDefault();
        Date m_date = new Date();
        TimeZone tz = TimeZone.getDefault();

        Map<String, String> localeListStr = new LinkedHashMap<String, String>();

        localeListStr.put("Locale Name", ourLocale.getDisplayName());
        localeListStr.put(" Variant", ourLocale.getVariant());
        localeListStr.put(" Country", ourLocale.getCountry());
        localeListStr.put(" Country ISO", ourLocale.getISO3Country());
        localeListStr.put(" Language", ourLocale.getLanguage());
        localeListStr.put(" Language ISO", ourLocale.getISO3Language());
        localeListStr.put(" Language Dsp", ourLocale.getDisplayLanguage());

        localeListStr.put("TimeZoneID", tz.getID());
        localeListStr.put(" DayLightSavings", tz.useDaylightTime() ? "Yes" : "No");
        localeListStr.put(" In DLS", tz.inDaylightTime(m_date) ? "Yes" : "No");
        localeListStr.put(" Short Name", tz.getDisplayName(false, TimeZone.SHORT, ourLocale));
        localeListStr.put(" Long Name", tz.getDisplayName(false, TimeZone.LONG, ourLocale));

        addBuild("Locale TZ...", localeListStr);
    } catch (Exception ex) {
        m_log.e("Locale/TZ %s", ex.getMessage());
    }

    // --------------- Location Services -------------
    try {
        Map<String, String> listStr = new LinkedHashMap<String, String>();

        final LocationManager locMgr = (LocationManager) getActivity()
                .getSystemService(Context.LOCATION_SERVICE);

        GpsStatus gpsStatus = locMgr.getGpsStatus(null);
        if (gpsStatus != null) {
            listStr.put("Sec ToGetGPS", String.valueOf(gpsStatus.getTimeToFirstFix()));

            Iterable<GpsSatellite> satellites = gpsStatus.getSatellites();
            Iterator<GpsSatellite> sat = satellites.iterator();
            while (sat.hasNext()) {
                GpsSatellite satellite = sat.next();

                putIf(listStr,
                        String.format("Azm:%.0f, Elev:%.0f", satellite.getAzimuth(), satellite.getElevation()),
                        String.format("%.2f Snr", satellite.getSnr()), satellite.usedInFix());
            }
        }

        Location location = null;
        if (ActivityCompat.checkSelfPermission(getContext(),
                Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(getContext(),
                        Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {

            location = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (null == location)
                location = locMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            if (null == location)
                location = locMgr.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
        }

        if (null != location) {
            listStr.put(location.getProvider() + " lat,lng",
                    String.format("%.3f, %.3f", location.getLatitude(), location.getLongitude()));
        }
        if (listStr.size() != 0) {
            List<String> gpsProviders = locMgr.getAllProviders();
            int idx = 1;
            for (String providerName : gpsProviders) {
                LocationProvider provider = locMgr.getProvider(providerName);
                if (null != provider) {
                    listStr.put(providerName,
                            (locMgr.isProviderEnabled(providerName) ? "On " : "Off ")
                                    + String.format("Accuracy:%d Pwr:%d", provider.getAccuracy(),
                                            provider.getPowerRequirement()));
                }
            }
            addBuild("GPS...", listStr);
        } else
            addBuild("GPS", "Off");
    } catch (Exception ex) {
        m_log.e(ex.getMessage());
    }

    // --------------- Application Info -------------
    ApplicationInfo appInfo = getActivity().getApplicationInfo();
    if (null != appInfo) {
        Map<String, String> appList = new LinkedHashMap<String, String>();
        try {
            appList.put("ProcName", appInfo.processName);
            appList.put("PkgName", appInfo.packageName);
            appList.put("DataDir", appInfo.dataDir);
            appList.put("SrcDir", appInfo.sourceDir);
            //    appList.put("PkgResDir", getActivity().getPackageResourcePath());
            //     appList.put("PkgCodeDir", getActivity().getPackageCodePath());
            String[] dbList = getActivity().databaseList();
            if (dbList != null && dbList.length != 0)
                appList.put("DataBase", dbList[0]);
            // getActivity().getComponentName().

        } catch (Exception ex) {
        }
        addBuild("AppInfo...", appList);
    }

    // --------------- Account Services -------------
    final AccountManager accMgr = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE);
    if (null != accMgr) {
        Map<String, String> strList = new LinkedHashMap<String, String>();
        try {
            for (Account account : accMgr.getAccounts()) {
                strList.put(account.name, account.type);
            }
        } catch (Exception ex) {
            m_log.e(ex.getMessage());
        }
        addBuild("Accounts...", strList);
    }

    // --------------- Package Features -------------
    PackageManager pm = getActivity().getPackageManager();
    FeatureInfo[] features = pm.getSystemAvailableFeatures();
    if (features != null) {
        Map<String, String> strList = new LinkedHashMap<String, String>();
        for (FeatureInfo featureInfo : features) {
            strList.put(featureInfo.name, "");
        }
        addBuild("Features...", strList);
    }

    // --------------- Sensor Services -------------
    final SensorManager senMgr = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    if (null != senMgr) {
        Map<String, String> strList = new LinkedHashMap<String, String>();
        // Sensor accelerometer = senMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        // senMgr.registerListener(foo, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
        List<Sensor> listSensor = senMgr.getSensorList(Sensor.TYPE_ALL);
        try {
            for (Sensor sensor : listSensor) {
                strList.put(sensor.getName(), sensor.getVendor());
            }
        } catch (Exception ex) {
            m_log.e(ex.getMessage());
        }
        addBuild("Sensors...", strList);
    }

    try {
        if (Build.VERSION.SDK_INT >= 17) {
            final UserManager userMgr = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
            if (null != userMgr) {
                try {
                    addBuild("UserName", userMgr.getUserName());
                } catch (Exception ex) {
                    m_log.e(ex.getMessage());
                }
            }
        }
    } catch (Exception ex) {
    }

    try {
        Map<String, String> strList = new LinkedHashMap<String, String>();
        int screenTimeout = Settings.System.getInt(getActivity().getContentResolver(),
                Settings.System.SCREEN_OFF_TIMEOUT);
        strList.put("ScreenTimeOut", String.valueOf(screenTimeout / 1000));
        int rotate = Settings.System.getInt(getActivity().getContentResolver(),
                Settings.System.ACCELEROMETER_ROTATION);
        strList.put("RotateEnabled", String.valueOf(rotate));
        if (Build.VERSION.SDK_INT >= 17) {
            // Global added in API 17
            int adb = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.ADB_ENABLED);
            strList.put("AdbEnabled", String.valueOf(adb));
        }
        addBuild("Settings...", strList);
    } catch (Exception ex) {
    }

    if (expandAll) {
        // updateList();
        int count = m_list.size();
        for (int position = 0; position < count; position++)
            m_listView.expandGroup(position);
    }

    m_adapter.notifyDataSetChanged();
}

From source file:com.ecyrd.jspwiki.WikiEngine.java

/**
 *  Does all the real initialization./*from w ww.j  a  v  a  2s.c om*/
 */
private void initialize(Properties props) throws WikiException {
    m_startTime = new Date();
    m_properties = props;

    //
    //  Initialized log4j.  However, make sure that
    //  we don't initialize it multiple times.  Also, if
    //  all of the log4j statements have been removed from
    //  the property file, we do not do any property setting
    //  either.q
    //
    if (!c_configured) {
        if (props.getProperty("log4j.rootCategory") != null) {
            PropertyConfigurator.configure(props);
        }
        c_configured = true;
    }

    log.info("*******************************************");
    log.info(Release.APPNAME + " " + Release.getVersionString() + " starting. Whee!");

    fireEvent(WikiEngineEvent.INITIALIZING); // begin initialization

    log.debug("Java version: " + System.getProperty("java.runtime.version"));
    log.debug("Java vendor: " + System.getProperty("java.vm.vendor"));
    log.debug("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " "
            + System.getProperty("os.arch"));
    log.debug("Default server locale: " + Locale.getDefault());
    log.debug("Default server timezone: " + TimeZone.getDefault().getDisplayName(true, TimeZone.LONG));

    if (m_servletContext != null) {
        log.info("Servlet container: " + m_servletContext.getServerInfo());
        if (m_servletContext.getMajorVersion() < 2
                || (m_servletContext.getMajorVersion() == 2 && m_servletContext.getMinorVersion() < 4)) {
            throw new InternalWikiException(
                    "I require a container which supports at least version 2.4 of Servlet specification");
        }
    }

    log.debug("Configuring WikiEngine...");

    //  Initializes the CommandResolver
    m_commandResolver = new CommandResolver(this, props);

    //
    //  Create and find the default working directory.
    //
    m_workDir = TextUtil.getStringProperty(props, PROP_WORKDIR, null);

    if (m_workDir == null) {
        m_workDir = System.getProperty("java.io.tmpdir", ".");
        m_workDir += File.separator + Release.APPNAME + "-" + m_appid;
    }

    try {
        File f = new File(m_workDir);
        f.mkdirs();

        //
        //  A bunch of sanity checks
        //
        if (!f.exists())
            throw new WikiException("Work directory does not exist: " + m_workDir);
        if (!f.canRead())
            throw new WikiException("No permission to read work directory: " + m_workDir);
        if (!f.canWrite())
            throw new WikiException("No permission to write to work directory: " + m_workDir);
        if (!f.isDirectory())
            throw new WikiException("jspwiki.workDir does not point to a directory: " + m_workDir);
    } catch (SecurityException e) {
        log.fatal("Unable to find or create the working directory: " + m_workDir, e);
        throw new IllegalArgumentException("Unable to find or create the working dir: " + m_workDir);
    }

    log.info("JSPWiki working directory is '" + m_workDir + "'");

    m_saveUserInfo = TextUtil.getBooleanProperty(props, PROP_STOREUSERNAME, m_saveUserInfo);

    m_useUTF8 = "UTF-8".equals(TextUtil.getStringProperty(props, PROP_ENCODING, "ISO-8859-1"));
    m_baseURL = TextUtil.getStringProperty(props, PROP_BASEURL, "");
    if (!m_baseURL.endsWith("/")) {
        m_baseURL = m_baseURL + "/";
    }

    m_beautifyTitle = TextUtil.getBooleanProperty(props, PROP_BEAUTIFYTITLE, m_beautifyTitle);

    m_templateDir = TextUtil.getStringProperty(props, PROP_TEMPLATEDIR, "default");
    m_frontPage = TextUtil.getStringProperty(props, PROP_FRONTPAGE, "Main");

    // Initialize the page name comparator now as it may be used while
    // initializing other modules
    initPageSorter(props);

    //
    //  Initialize the important modules.  Any exception thrown by the
    //  managers means that we will not start up.
    //

    // FIXME: This part of the code is getting unwieldy.  We must think
    //        of a better way to do the startup-sequence.
    try {
        Class urlclass = ClassUtil.findClass("com.ecyrd.jspwiki.url",
                TextUtil.getStringProperty(props, PROP_URLCONSTRUCTOR, "DefaultURLConstructor"));
        m_urlConstructor = (URLConstructor) urlclass.newInstance();
        m_urlConstructor.initialize(this, props);

        m_pageManager = (PageManager) ClassUtil.getMappedObject(PageManager.class.getName(), this, props);
        m_pluginManager = (PluginManager) ClassUtil.getMappedObject(PluginManager.class.getName(), this, props);
        m_differenceManager = (DifferenceManager) ClassUtil.getMappedObject(DifferenceManager.class.getName(),
                this, props);
        m_attachmentManager = (AttachmentManager) ClassUtil.getMappedObject(AttachmentManager.class.getName(),
                this, props);
        m_variableManager = (VariableManager) ClassUtil.getMappedObject(VariableManager.class.getName(), props);
        // m_filterManager     = (FilterManager)ClassUtil.getMappedObject(FilterManager.class.getName(), this, props );
        m_renderingManager = (RenderingManager) ClassUtil.getMappedObject(RenderingManager.class.getName());

        m_searchManager = (SearchManager) ClassUtil.getMappedObject(SearchManager.class.getName(), this, props);

        m_authenticationManager = (AuthenticationManager) ClassUtil
                .getMappedObject(AuthenticationManager.class.getName());
        m_authorizationManager = (AuthorizationManager) ClassUtil
                .getMappedObject(AuthorizationManager.class.getName());
        m_userManager = (UserManager) ClassUtil.getMappedObject(UserManager.class.getName());
        m_groupManager = (GroupManager) ClassUtil.getMappedObject(GroupManager.class.getName());

        m_editorManager = (EditorManager) ClassUtil.getMappedObject(EditorManager.class.getName(), this);
        m_editorManager.initialize(props);

        m_progressManager = new ProgressManager();

        // Initialize the authentication, authorization, user and acl managers

        m_authenticationManager.initialize(this, props);
        m_authorizationManager.initialize(this, props);
        m_userManager.initialize(this, props);
        m_groupManager.initialize(this, props);
        m_aclManager = getAclManager();

        // Start the Workflow manager
        m_workflowMgr = (WorkflowManager) ClassUtil.getMappedObject(WorkflowManager.class.getName());
        m_workflowMgr.initialize(this, props);

        m_internationalizationManager = (InternationalizationManager) ClassUtil
                .getMappedObject(InternationalizationManager.class.getName(), this);

        m_templateManager = (TemplateManager) ClassUtil.getMappedObject(TemplateManager.class.getName(), this,
                props);

        m_adminBeanManager = (AdminBeanManager) ClassUtil.getMappedObject(AdminBeanManager.class.getName(),
                this);

        // Since we want to use a page filters initilize() method
        // as a engine startup listener where we can initialize global event listeners,
        // it must be called lastly, so that all object references in the engine
        // are availabe to the initialize() method
        m_filterManager = (FilterManager) ClassUtil.getMappedObject(FilterManager.class.getName(), this, props);

        // RenderingManager depends on FilterManager events.

        m_renderingManager.initialize(this, props);

        //
        //  ReferenceManager has the side effect of loading all
        //  pages.  Therefore after this point, all page attributes
        //  are available.
        //
        //  initReferenceManager is indirectly using m_filterManager, therefore
        //  it has to be called after it was initialized.
        //
        initReferenceManager();

        //
        //  Hook the different manager routines into the system.
        //
        getFilterManager().addPageFilter(m_referenceManager, -1001);
        getFilterManager().addPageFilter(m_searchManager, -1002);
    }

    catch (RuntimeException e) {
        // RuntimeExceptions may occur here, even if they shouldn't.
        log.fatal("Failed to start managers.", e);
        e.printStackTrace();
        throw new WikiException("Failed to start managers: " + e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        log.fatal("JSPWiki could not start, URLConstructor was not found: ", e);
        e.printStackTrace();
        throw new WikiException(e.getMessage(), e);
    } catch (InstantiationException e) {
        log.fatal("JSPWiki could not start, URLConstructor could not be instantiated: ", e);
        e.printStackTrace();
        throw new WikiException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        log.fatal("JSPWiki could not start, URLConstructor cannot be accessed: ", e);
        e.printStackTrace();
        throw new WikiException(e.getMessage(), e);
    } catch (Exception e) {
        // Final catch-all for everything
        log.fatal("JSPWiki could not start, due to an unknown exception when starting.", e);
        e.printStackTrace();
        throw new WikiException("Failed to start; please check log files for better information.", e);
    }

    //
    //  Initialize the good-to-have-but-not-fatal modules.
    //
    try {
        if (TextUtil.getBooleanProperty(props, RSSGenerator.PROP_GENERATE_RSS, false)) {
            m_rssGenerator = (RSSGenerator) ClassUtil.getMappedObject(RSSGenerator.class.getName(), this,
                    props);
        }

        m_pageRenamer = (PageRenamer) ClassUtil.getMappedObject(PageRenamer.class.getName(), this, props);
    } catch (Exception e) {
        log.error(
                "Unable to start RSS generator - JSPWiki will still work, " + "but there will be no RSS feed.",
                e);
    }

    // Start the RSS generator & generator thread
    if (m_rssGenerator != null) {
        m_rssFile = TextUtil.getStringProperty(props, RSSGenerator.PROP_RSSFILE, "rss.rdf");
        File rssFile = null;
        if (m_rssFile.startsWith(File.separator)) {
            // honor absolute pathnames:
            rssFile = new File(m_rssFile);
        } else {
            // relative path names are anchored from the webapp root path:
            rssFile = new File(getRootPath(), m_rssFile);
        }
        int rssInterval = TextUtil.getIntegerProperty(props, RSSGenerator.PROP_INTERVAL, 3600);
        RSSThread rssThread = new RSSThread(this, rssFile, rssInterval);
        rssThread.start();
    }

    fireEvent(WikiEngineEvent.INITIALIZED); // initialization complete

    log.info("WikiEngine configured.");
    m_isConfigured = true;
}

From source file:org.apache.wiki.WikiEngine.java

/**
 *  Does all the real initialization.//  ww w .java  2 s.c om
 */
private void initialize(Properties props) throws WikiException {
    m_startTime = new Date();
    m_properties = props;

    //
    //  Initialized log4j.  However, make sure that
    //  we don't initialize it multiple times.  Also, if
    //  all of the log4j statements have been removed from
    //  the property file, we do not do any property setting
    //  either.q
    //
    if (!c_configured) {
        if (props.getProperty("log4j.rootCategory") != null) {
            PropertyConfigurator.configure(props);
        }
        c_configured = true;
    }

    log.info("*******************************************");
    log.info(Release.APPNAME + " " + Release.getVersionString() + " starting. Whee!");

    fireEvent(WikiEngineEvent.INITIALIZING); // begin initialization

    log.debug("Java version: " + System.getProperty("java.runtime.version"));
    log.debug("Java vendor: " + System.getProperty("java.vm.vendor"));
    log.debug("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " "
            + System.getProperty("os.arch"));
    log.debug("Default server locale: " + Locale.getDefault());
    log.debug("Default server timezone: " + TimeZone.getDefault().getDisplayName(true, TimeZone.LONG));

    if (m_servletContext != null) {
        log.info("Servlet container: " + m_servletContext.getServerInfo());
        if (m_servletContext.getMajorVersion() < 2
                || (m_servletContext.getMajorVersion() == 2 && m_servletContext.getMinorVersion() < 4)) {
            throw new InternalWikiException(
                    "I require a container which supports at least version 2.4 of Servlet specification");
        }
    }

    log.debug("Configuring WikiEngine...");

    //  Initializes the CommandResolver
    m_commandResolver = new CommandResolver(this, props);

    //
    //  Create and find the default working directory.
    //
    m_workDir = TextUtil.getStringProperty(props, PROP_WORKDIR, null);

    if (m_workDir == null) {
        m_workDir = System.getProperty("java.io.tmpdir", ".");
        m_workDir += File.separator + Release.APPNAME + "-" + m_appid;
    }

    try {
        File f = new File(m_workDir);
        f.mkdirs();

        //
        //  A bunch of sanity checks
        //
        if (!f.exists())
            throw new WikiException("Work directory does not exist: " + m_workDir);
        if (!f.canRead())
            throw new WikiException("No permission to read work directory: " + m_workDir);
        if (!f.canWrite())
            throw new WikiException("No permission to write to work directory: " + m_workDir);
        if (!f.isDirectory())
            throw new WikiException("jspwiki.workDir does not point to a directory: " + m_workDir);
    } catch (SecurityException e) {
        log.fatal("Unable to find or create the working directory: " + m_workDir, e);
        throw new IllegalArgumentException("Unable to find or create the working dir: " + m_workDir);
    }

    log.info("JSPWiki working directory is '" + m_workDir + "'");

    m_saveUserInfo = TextUtil.getBooleanProperty(props, PROP_STOREUSERNAME, m_saveUserInfo);

    m_useUTF8 = "UTF-8".equals(TextUtil.getStringProperty(props, PROP_ENCODING, "ISO-8859-1"));
    m_baseURL = TextUtil.getStringProperty(props, PROP_BASEURL, "");
    if (!m_baseURL.endsWith("/")) {
        m_baseURL = m_baseURL + "/";
    }

    m_beautifyTitle = TextUtil.getBooleanProperty(props, PROP_BEAUTIFYTITLE, m_beautifyTitle);

    m_templateDir = TextUtil.getStringProperty(props, PROP_TEMPLATEDIR, "default");
    m_frontPage = TextUtil.getStringProperty(props, PROP_FRONTPAGE, "Main");

    // Initialize the page name comparator now as it may be used while
    // initializing other modules
    initPageSorter(props);

    //
    //  Initialize the important modules.  Any exception thrown by the
    //  managers means that we will not start up.
    //

    // FIXME: This part of the code is getting unwieldy.  We must think
    //        of a better way to do the startup-sequence.
    try {
        Class urlclass = ClassUtil.findClass("org.apache.wiki.url",
                TextUtil.getStringProperty(props, PROP_URLCONSTRUCTOR, "DefaultURLConstructor"));
        m_urlConstructor = (URLConstructor) urlclass.newInstance();
        m_urlConstructor.initialize(this, props);

        m_pageManager = (PageManager) ClassUtil.getMappedObject(PageManager.class.getName(), this, props);
        m_pluginManager = (PluginManager) ClassUtil.getMappedObject(PluginManager.class.getName(), this, props);
        m_differenceManager = (DifferenceManager) ClassUtil.getMappedObject(DifferenceManager.class.getName(),
                this, props);
        m_attachmentManager = (AttachmentManager) ClassUtil.getMappedObject(AttachmentManager.class.getName(),
                this, props);
        m_variableManager = (VariableManager) ClassUtil.getMappedObject(VariableManager.class.getName(), props);
        // m_filterManager     = (FilterManager)ClassUtil.getMappedObject(FilterManager.class.getName(), this, props );
        m_renderingManager = (RenderingManager) ClassUtil.getMappedObject(RenderingManager.class.getName());

        m_searchManager = (SearchManager) ClassUtil.getMappedObject(SearchManager.class.getName(), this, props);

        m_authenticationManager = (AuthenticationManager) ClassUtil
                .getMappedObject(AuthenticationManager.class.getName());
        m_authorizationManager = (AuthorizationManager) ClassUtil
                .getMappedObject(AuthorizationManager.class.getName());
        m_userManager = (UserManager) ClassUtil.getMappedObject(UserManager.class.getName());
        m_groupManager = (GroupManager) ClassUtil.getMappedObject(GroupManager.class.getName());

        m_editorManager = (EditorManager) ClassUtil.getMappedObject(EditorManager.class.getName(), this);
        m_editorManager.initialize(props);

        m_progressManager = new ProgressManager();

        // Initialize the authentication, authorization, user and acl managers

        m_authenticationManager.initialize(this, props);
        m_authorizationManager.initialize(this, props);
        m_userManager.initialize(this, props);
        m_groupManager.initialize(this, props);
        m_aclManager = getAclManager();

        // Start the Workflow manager
        m_workflowMgr = (WorkflowManager) ClassUtil.getMappedObject(WorkflowManager.class.getName());
        m_workflowMgr.initialize(this, props);

        m_internationalizationManager = (InternationalizationManager) ClassUtil
                .getMappedObject(InternationalizationManager.class.getName(), this);

        m_templateManager = (TemplateManager) ClassUtil.getMappedObject(TemplateManager.class.getName(), this,
                props);

        m_adminBeanManager = (AdminBeanManager) ClassUtil.getMappedObject(AdminBeanManager.class.getName(),
                this);

        // Since we want to use a page filters initilize() method
        // as a engine startup listener where we can initialize global event listeners,
        // it must be called lastly, so that all object references in the engine
        // are availabe to the initialize() method
        m_filterManager = (FilterManager) ClassUtil.getMappedObject(FilterManager.class.getName(), this, props);

        // RenderingManager depends on FilterManager events.

        m_renderingManager.initialize(this, props);

        //
        //  ReferenceManager has the side effect of loading all
        //  pages.  Therefore after this point, all page attributes
        //  are available.
        //
        //  initReferenceManager is indirectly using m_filterManager, therefore
        //  it has to be called after it was initialized.
        //
        initReferenceManager();

        //
        //  Hook the different manager routines into the system.
        //
        m_filterManager.addPageFilter(m_referenceManager, -1001);
        m_filterManager.addPageFilter(m_searchManager, -1002);
    }

    catch (RuntimeException e) {
        // RuntimeExceptions may occur here, even if they shouldn't.
        log.fatal("Failed to start managers.", e);
        e.printStackTrace();
        throw new WikiException("Failed to start managers: " + e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        log.fatal("JSPWiki could not start, URLConstructor was not found: ", e);
        e.printStackTrace();
        throw new WikiException(e.getMessage(), e);
    } catch (InstantiationException e) {
        log.fatal("JSPWiki could not start, URLConstructor could not be instantiated: ", e);
        e.printStackTrace();
        throw new WikiException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        log.fatal("JSPWiki could not start, URLConstructor cannot be accessed: ", e);
        e.printStackTrace();
        throw new WikiException(e.getMessage(), e);
    } catch (Exception e) {
        // Final catch-all for everything
        log.fatal("JSPWiki could not start, due to an unknown exception when starting.", e);
        e.printStackTrace();
        throw new WikiException("Failed to start; please check log files for better information.", e);
    }

    //
    //  Initialize the good-to-have-but-not-fatal modules.
    //
    try {
        if (TextUtil.getBooleanProperty(props, RSSGenerator.PROP_GENERATE_RSS, false)) {
            m_rssGenerator = (RSSGenerator) ClassUtil.getMappedObject(RSSGenerator.class.getName(), this,
                    props);
        }

        m_pageRenamer = (PageRenamer) ClassUtil.getMappedObject(PageRenamer.class.getName(), this, props);
    } catch (Exception e) {
        log.error(
                "Unable to start RSS generator - JSPWiki will still work, " + "but there will be no RSS feed.",
                e);
    }

    // Start the RSS generator & generator thread
    if (m_rssGenerator != null) {
        m_rssFile = TextUtil.getStringProperty(props, RSSGenerator.PROP_RSSFILE, "rss.rdf");
        File rssFile = null;
        if (m_rssFile.startsWith(File.separator)) {
            // honor absolute pathnames:
            rssFile = new File(m_rssFile);
        } else {
            // relative path names are anchored from the webapp root path:
            rssFile = new File(getRootPath(), m_rssFile);
        }
        int rssInterval = TextUtil.getIntegerProperty(props, RSSGenerator.PROP_INTERVAL, 3600);
        RSSThread rssThread = new RSSThread(this, rssFile, rssInterval);
        rssThread.start();
    }

    fireEvent(WikiEngineEvent.INITIALIZED); // initialization complete

    log.info("WikiEngine configured.");
    m_isConfigured = true;
}

From source file:DateFormatUtils.java

/**
 * <p>Returns a list of Rules given a pattern.</p>
 * /*w w  w . j  av  a  2 s  . c o m*/
 * @return a <code>List</code> of Rule objects
 * @throws IllegalArgumentException if pattern is invalid
 */
protected List parsePattern() {
    DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
    List rules = new ArrayList();

    String[] ERAs = symbols.getEras();
    String[] months = symbols.getMonths();
    String[] shortMonths = symbols.getShortMonths();
    String[] weekdays = symbols.getWeekdays();
    String[] shortWeekdays = symbols.getShortWeekdays();
    String[] AmPmStrings = symbols.getAmPmStrings();

    int length = mPattern.length();
    int[] indexRef = new int[1];

    for (int i = 0; i < length; i++) {
        indexRef[0] = i;
        String token = parseToken(mPattern, indexRef);
        i = indexRef[0];

        int tokenLen = token.length();
        if (tokenLen == 0) {
            break;
        }

        Rule rule;
        char c = token.charAt(0);

        switch (c) {
        case 'G': // era designator (text)
            rule = new TextField(Calendar.ERA, ERAs);
            break;
        case 'y': // year (number)
            if (tokenLen >= 4) {
                rule = selectNumberRule(Calendar.YEAR, tokenLen);
            } else {
                rule = TwoDigitYearField.INSTANCE;
            }
            break;
        case 'M': // month in year (text and number)
            if (tokenLen >= 4) {
                rule = new TextField(Calendar.MONTH, months);
            } else if (tokenLen == 3) {
                rule = new TextField(Calendar.MONTH, shortMonths);
            } else if (tokenLen == 2) {
                rule = TwoDigitMonthField.INSTANCE;
            } else {
                rule = UnpaddedMonthField.INSTANCE;
            }
            break;
        case 'd': // day in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
            break;
        case 'h': // hour in am/pm (number, 1..12)
            rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
            break;
        case 'H': // hour in day (number, 0..23)
            rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
            break;
        case 'm': // minute in hour (number)
            rule = selectNumberRule(Calendar.MINUTE, tokenLen);
            break;
        case 's': // second in minute (number)
            rule = selectNumberRule(Calendar.SECOND, tokenLen);
            break;
        case 'S': // millisecond (number)
            rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
            break;
        case 'E': // day in week (text)
            rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
            break;
        case 'D': // day in year (number)
            rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
            break;
        case 'F': // day of week in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
            break;
        case 'w': // week in year (number)
            rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
            break;
        case 'W': // week in month (number)
            rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
            break;
        case 'a': // am/pm marker (text)
            rule = new TextField(Calendar.AM_PM, AmPmStrings);
            break;
        case 'k': // hour in day (1..24)
            rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
            break;
        case 'K': // hour in am/pm (0..11)
            rule = selectNumberRule(Calendar.HOUR, tokenLen);
            break;
        case 'z': // time zone (text)
            if (tokenLen >= 4) {
                rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.SHORT);
            }
            break;
        case 'Z': // time zone (value)
            if (tokenLen == 1) {
                rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
            } else {
                rule = TimeZoneNumberRule.INSTANCE_COLON;
            }
            break;
        case '\'': // literal text
            String sub = token.substring(1);
            if (sub.length() == 1) {
                rule = new CharacterLiteral(sub.charAt(0));
            } else {
                rule = new StringLiteral(sub);
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal pattern component: " + token);
        }

        rules.add(rule);
    }

    return rules;
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String GetTimeZone() {
    String sRet = "";
    TimeZone tz;//  w w w . ja v  a 2  s . com

    tz = TimeZone.getDefault();
    Date now = new Date();
    sRet = tz.getDisplayName(tz.inDaylightTime(now), TimeZone.LONG);

    return (sRet);
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String SetTimeZone(String sTimeZone) {
    String sRet = "Unable to set timezone to " + sTimeZone;
    TimeZone tz = null;//w  ww.  j a  v  a  2  s.c  o m
    AlarmManager amgr = null;

    if ((sTimeZone.length() > 0) && (sTimeZone.startsWith("GMT"))) {
        amgr = (AlarmManager) contextWrapper.getSystemService(Context.ALARM_SERVICE);
        if (amgr != null)
            amgr.setTimeZone(sTimeZone);
    } else {
        String[] zoneNames = TimeZone.getAvailableIDs();
        int nNumMatches = zoneNames.length;
        int lcv = 0;

        for (lcv = 0; lcv < nNumMatches; lcv++) {
            if (zoneNames[lcv].equalsIgnoreCase(sTimeZone))
                break;
        }

        if (lcv < nNumMatches) {
            amgr = (AlarmManager) contextWrapper.getSystemService(Context.ALARM_SERVICE);
            if (amgr != null)
                amgr.setTimeZone(zoneNames[lcv]);
        }
    }

    if (amgr != null) {
        tz = TimeZone.getDefault();
        Date now = new Date();
        sRet = tz.getDisplayName(tz.inDaylightTime(now), TimeZone.LONG);
    }

    return (sRet);
}