Example usage for org.apache.commons.lang ArrayUtils remove

List of usage examples for org.apache.commons.lang ArrayUtils remove

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils remove.

Prototype

private static Object remove(Object array, int index) 

Source Link

Document

Removes the element at the specified position from the specified array.

Usage

From source file:org.talend.hadoop.distribution.AbstractDistribution.java

/**
 * //ww  w  .  j  av  a  2 s.  co m
 * load default
 */
public String getDefaultConfig(String... keys) {
    if (keys != null && keys.length > 0) {
        // check distribution
        final String keyDistr = keys[0];
        final String distribution = getDistribution();
        if (distribution.equals(keyDistr)) {
            final String version = getVersion();
            Object object = defaultConfigsMap.get(distribution, version);
            if (object == null) { // init
                JSONObject defaultConfig = loadDefaultConfigurations();
                if (defaultConfig != null) {
                    object = defaultConfig;
                    defaultConfigsMap.put(distribution, version, defaultConfig);
                }
            }
            if (object instanceof JSONObject) {
                JSONObject json = (JSONObject) object;
                String[] keysWithoutDistribution = (String[]) ArrayUtils.remove(keys, 0);
                if (keysWithoutDistribution.length == 0) {// no key yet,
                    return DefaultConfigurationManager.getValue(json, "");
                }
                return DefaultConfigurationManager.getValue(json, keysWithoutDistribution);
            }

        }
    }
    return null;
}

From source file:org.talend.hadoop.distribution.utils.DefaultConfigurationManager.java

/**
 * if the keys is empty(String[0]), return null.
 * /* www .  j a  v a2s . c o  m*/
 * If the keys only contain empty string (String[1]{""}), will return the whole JSON string directly.
 * 
 * if the subKeys is not leaf keys, means, contain some children values, will return the sub JSON string directly.
 * for example, existed "HBASE/PORT", but the subKeys is only "HBASE", means will return the string of JSON which
 * contained the "PORT" or others.
 * 
 */
public static String getValue(JSONObject jsonObject, String... keys) {
    if (keys == null || jsonObject == null) {
        return null;
    }
    if (keys.length > 0) {
        String arg = keys[0];
        if (arg != null) {
            if (arg.trim().length() == 0) { // empty key, means get all
                return jsonObject.toString();
            }
            if (jsonObject.has(arg)) {
                try {
                    Object obj = jsonObject.get(arg);
                    if (obj != null) {
                        String[] subKeys = (String[]) ArrayUtils.remove(keys, 0);
                        if (subKeys.length == 0) { // no key yet.
                            return obj.toString();
                        } else if (obj instanceof JSONObject) {
                            return getValue((JSONObject) obj, subKeys);
                        } else if (obj instanceof JSONArray) {
                            return String.valueOf(obj); // return all array directly
                        } else {
                            return String.valueOf(obj);
                        }
                    }
                } catch (JSONException e) {
                    //
                }
            }
        }
    }
    return null;
}

From source file:org.tariel.dependrpc.pos.JMystem.java

/**
 * Converts temp words list into ISentence
 * @param sent List<JsonWord> list of parsed words from mystem
 * @return ISentence ready sentence/*  w ww  .j a  va2  s.c o  m*/
 */
private ISentence createSentence(List<JsonWord> sent) {
    ISentence sentence = SentenceFabrique.getSentence();
    for (JsonWord entry : sent) {
        Class cls = IWord.class;
        Class[] paramString = new Class[1];
        paramString[0] = String.class;

        IWord tmpWord = SentenceFabrique.getWord(entry.text);
        tmpWord.setLex(entry.analysis.lex);
        String[] gr = entry.analysis.gr.split(",");
        //Clear array from "=" symbols
        int index = 0;
        for (String grstr : gr) {
            if (grstr.contains("=")) {
                String[] eqSymParts = grstr.split("=");
                grstr = eqSymParts[0];
                gr = (String[]) ArrayUtils.remove(gr, index);
                gr = (String[]) ArrayUtils.addAll(gr, eqSymParts);
            }
            index++;
        }
        //Parse array into IWord instance
        for (String grstr : gr) {
            try {
                //Recogise current mystem propertie and set such one in IWord
                for (Field field : IWord.class.getDeclaredFields()) {
                    List<String> values = Arrays.asList((String[]) field.get(tmpWord));
                    if (values.contains(grstr)) {
                        Method method = cls.getDeclaredMethod("set" + field.getName(), paramString);
                        method.invoke(tmpWord, grstr);
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        }
        sentence.appendWord(tmpWord);
    }
    return sentence;
}

From source file:org.wso2.carbon.event.processor.common.storm.component.EventPublisherBolt.java

@Override
public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
    if (log.isDebugEnabled()) {
        log.debug(logPrefix + "Received Event: " + tuple.getSourceStreamId() + ":"
                + Arrays.deepToString(tuple.getValues().toArray()));
    }/* w  ww  .ja  va  2  s  .  c o  m*/

    this.collector = basicOutputCollector;
    if (!initialized) {
        init();
    }

    Object[] dataArray = tuple.getValues().toArray();
    long timestamp = (Long) dataArray[dataArray.length - 1];
    dataArray = ArrayUtils.remove(dataArray, dataArray.length - 1);

    StreamDefinition streamDefinition = streamIdToDefinitionMap.get(tuple.getSourceStreamId());
    if (streamDefinition != null) {
        asyncEventPublisher.sendEvent(dataArray, timestamp, tuple.getSourceStreamId());
    } else {
        log.warn(logPrefix + "Tuple received for unknown stream " + tuple.getSourceStreamId() + ". Discarding "
                + "Event: " + tuple.getSourceStreamId() + ":" + Arrays.deepToString(dataArray) + "@"
                + timestamp);
    }
    if (log.isDebugEnabled()) {
        log.debug(logPrefix + "Emitted Event: " + tuple.getSourceStreamId() + ":"
                + Arrays.deepToString(dataArray) + "@" + timestamp);
    }
}

From source file:org.wso2.carbon.event.processor.common.storm.component.SiddhiBolt.java

@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    if (siddhiManager == null) {
        init();/*w w w.  j a v  a 2  s  .  com*/
    }
    inputThroughputProbe.update();

    try {
        this.collector = collector;
        InputHandler inputHandler = executionPlanRuntime.getInputHandler(tuple.getSourceStreamId());
        Object[] dataArray = tuple.getValues().toArray();
        long timestamp = (Long) dataArray[dataArray.length - 1];
        dataArray = ArrayUtils.remove(dataArray, dataArray.length - 1);

        if (log.isDebugEnabled()) {
            log.debug(logPrefix + "Received Event: " + tuple.getSourceStreamId() + ":"
                    + Arrays.deepToString(dataArray) + "@" + timestamp);
        }

        if (inputHandler != null) {
            inputHandler.send(timestamp, dataArray);
        } else {
            log.warn(logPrefix + "Event received for unknown stream " + tuple.getSourceStreamId()
                    + ". Discarding" + " the Event: " + tuple.getSourceStreamId() + ":"
                    + Arrays.deepToString(dataArray) + "@" + timestamp);
        }
    } catch (InterruptedException e) {
        log.error(e);
    }
}

From source file:paulscode.android.mupen64plusae.persistent.GlobalPrefs.java

/**
 * Instantiates a new user preferences wrapper.
 *
 * @param context//ww w .ja va  2  s  .  c  o m
 *            The application context.
 */
public GlobalPrefs(Context context, AppData appData) {
    mPreferences = PreferenceManager.getDefaultSharedPreferences(context);

    // Locale
    mLocaleCode = mPreferences.getString(KEY_LOCALE_OVERRIDE, DEFAULT_LOCALE_OVERRIDE);
    mLocale = TextUtils.isEmpty(mLocaleCode) ? Locale.getDefault() : createLocale(mLocaleCode);
    final Locale[] availableLocales = Locale.getAvailableLocales();
    String[] values = context.getResources().getStringArray(R.array.localeOverride_values);
    String[] entries = new String[values.length];
    for (int i = values.length - 1; i > 0; i--) {
        final Locale locale = createLocale(values[i]);

        // Get intersection of languages (available on device) and (translated for Mupen)
        if (ArrayUtils.contains(availableLocales, locale)) {
            // Get the name of the language, as written natively
            entries[i] = WordUtils.capitalize(locale.getDisplayName(locale));
        } else {
            // Remove the item from the list
            entries = (String[]) ArrayUtils.remove(entries, i);
            values = (String[]) ArrayUtils.remove(values, i);
        }
    }
    entries[0] = context.getString(R.string.localeOverride_entrySystemDefault);
    mLocaleNames = entries;
    mLocaleCodes = values;

    // Files
    userDataDir = mPreferences.getString("pathGameSaves", "");
    galleryCacheDir = userDataDir + "/GalleryCache";
    coverArtDir = galleryCacheDir + "/CoverArt";
    unzippedRomsDir = galleryCacheDir + "/UnzippedRoms";
    profilesDir = userDataDir + "/Profiles";
    crashLogDir = userDataDir + "/CrashLogs";
    coreUserDataDir = userDataDir + "/CoreConfig/UserData";
    coreUserCacheDir = userDataDir + "/CoreConfig/UserCache";
    hiResTextureDir = coreUserDataDir + "/mupen64plus/hires_texture/"; // MUST match what rice assumes natively
    textureCacheDir = coreUserCacheDir + "/mupen64plus/cache";
    romInfoCache_cfg = galleryCacheDir + "/romInfoCache.cfg";
    controllerProfiles_cfg = profilesDir + "/controller.cfg";
    touchscreenProfiles_cfg = profilesDir + "/touchscreen.cfg";
    emulationProfiles_cfg = profilesDir + "/emulation.cfg";
    customCheats_txt = profilesDir + "/customCheats.txt";
    touchscreenCustomSkinsDir = userDataDir + "/CustomSkins";
    legacyAutoSaves = userDataDir + "/AutoSaves";
    legacySlotSaves = userDataDir + "/SlotSaves";

    // Plug-ins
    audioPlugin = new Plugin(mPreferences, appData.libsDir, "audioPlugin");

    // Library prefs
    isRecentShown = mPreferences.getBoolean("showRecentlyPlayed", true);
    isFullNameShown = mPreferences.getBoolean("showFullNames", true);

    // Touchscreen prefs
    isTouchscreenFeedbackEnabled = mPreferences.getBoolean("touchscreenFeedback", false);
    touchscreenScale = (mPreferences.getInt("touchscreenScale", 100)) / 100.0f;
    touchscreenTransparency = (255 * mPreferences.getInt("touchscreenTransparency", 100)) / 100;
    touchscreenAutoHold = getSafeInt(mPreferences, "touchscreenAutoHold", 0);

    // Video prefs
    displayOrientation = getSafeInt(mPreferences, "displayOrientation", 0);
    displayPosition = getSafeInt(mPreferences, "displayPosition", Gravity.CENTER_VERTICAL);
    final int transparencyPercent = mPreferences.getInt("displayActionBarTransparency", 50);
    displayActionBarTransparency = (255 * transparencyPercent) / 100;
    isFpsEnabled = mPreferences.getBoolean("displayFps", false);
    final int selectedHardwareType = getSafeInt(mPreferences, "videoHardwareType", -1);
    isPolygonOffsetHackEnabled = selectedHardwareType > -2;
    videoHardwareType = selectedHardwareType < 0 ? appData.hardwareInfo.hardwareType : selectedHardwareType;
    switch (videoHardwareType) {
    case HardwareInfo.HARDWARE_TYPE_OMAP:
        videoPolygonOffset = 0.2f;
        break;
    case HardwareInfo.HARDWARE_TYPE_OMAP_2:
        videoPolygonOffset = -1.5f;
        break;
    case HardwareInfo.HARDWARE_TYPE_QUALCOMM:
        videoPolygonOffset = -0.2f;
        break;
    case HardwareInfo.HARDWARE_TYPE_IMAP:
        videoPolygonOffset = -0.001f;
        break;
    case HardwareInfo.HARDWARE_TYPE_TEGRA:
        videoPolygonOffset = -2.0f;
        break;
    case HardwareInfo.HARDWARE_TYPE_UNKNOWN:
        videoPolygonOffset = -1.5f;
        break;
    default:
        videoPolygonOffset = SafeMethods.toFloat(mPreferences.getString("videoPolygonOffset", "-1.5"), -1.5f);
        break;
    }
    isImmersiveModeEnabled = mPreferences.getBoolean("displayImmersiveMode", false);

    // Audio prefs
    audioSwapChannels = mPreferences.getBoolean("audioSwapChannels", false);
    audioSDLSecondaryBufferSize = getSafeInt(mPreferences, "audioSDLBufferSize", 2048);
    audioSLESSecondaryBufferSize = getSafeInt(mPreferences, "audioSLESBufferSize2", 256);
    audioSLESSecondaryBufferNbr = getSafeInt(mPreferences, "audioSLESBufferNbr2", 20);
    audioSLESSamplingRate = getSafeInt(mPreferences, "audioSLESSamplingRate", 0);

    if (audioPlugin.enabled)
        isFramelimiterEnabled = !mPreferences.getBoolean("audioSynchronize", true);
    else
        isFramelimiterEnabled = !mPreferences.getString("audioPlugin", "").equals("nospeedlimit");

    // User interface modes
    final String navMode = mPreferences.getString("navigationMode", "auto");
    if (navMode.equals("bigscreen"))
        isBigScreenMode = true;
    else if (navMode.equals("standard"))
        isBigScreenMode = false;
    else
        isBigScreenMode = AppData.IS_OUYA_HARDWARE || appData.isAndroidTv; // TODO: Add other systems as they enter market

    // Peripheral share mode
    isControllerShared = mPreferences.getBoolean("inputShareController", false);

    maxAutoSaves = mPreferences.getInt("gameAutoSaves", 5);

    // Determine the key codes that should not be mapped to controls
    final boolean volKeysMappable = mPreferences.getBoolean("inputVolumeMappable", false);
    final List<Integer> unmappables = new ArrayList<>();
    unmappables.add(KeyEvent.KEYCODE_MENU);

    // Back key is needed to show/hide the action bar in HC+
    unmappables.add(KeyEvent.KEYCODE_BACK);

    if (!volKeysMappable) {
        unmappables.add(KeyEvent.KEYCODE_VOLUME_UP);
        unmappables.add(KeyEvent.KEYCODE_VOLUME_DOWN);
        unmappables.add(KeyEvent.KEYCODE_VOLUME_MUTE);
    }
    unmappableKeyCodes = Collections.unmodifiableList(unmappables);

    // Controller profiles
    controllerProfile1 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE1,
            getControllerProfileDefault(1), GetControllerProfilesConfig(),
            appData.GetControllerProfilesConfig());
    controllerProfile2 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE2,
            getControllerProfileDefault(2), GetControllerProfilesConfig(),
            appData.GetControllerProfilesConfig());
    controllerProfile3 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE3,
            getControllerProfileDefault(3), GetControllerProfilesConfig(),
            appData.GetControllerProfilesConfig());
    controllerProfile4 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE4,
            getControllerProfileDefault(4), GetControllerProfilesConfig(),
            appData.GetControllerProfilesConfig());

    // Player map
    playerMap = new PlayerMap(mPreferences.getString(GamePrefs.PLAYER_MAP, ""));

    // Determine whether controller deconfliction is needed
    int numControllers = 0;
    numControllers += controllerProfile1 != null ? 1 : 0;
    numControllers += controllerProfile2 != null ? 1 : 0;
    numControllers += controllerProfile3 != null ? 1 : 0;
    numControllers += controllerProfile4 != null ? 1 : 0;

    playerMap.setEnabled(numControllers > 1 && !isControllerShared);
}

From source file:paulscode.android.mupen64plusae.persistent.UserPrefs.java

/**
 * Instantiates a new user preferences wrapper.
 * /*from ww  w. ja v  a  2  s .  com*/
 * @param context The application context.
 */
@SuppressWarnings("deprecation")
@SuppressLint("InlinedApi")
@TargetApi(17)
public UserPrefs(Context context) {
    AppData appData = new AppData(context);
    mPreferences = PreferenceManager.getDefaultSharedPreferences(context);

    // Locale
    mLocaleCode = mPreferences.getString(KEY_LOCALE_OVERRIDE, DEFAULT_LOCALE_OVERRIDE);
    mLocale = TextUtils.isEmpty(mLocaleCode) ? Locale.getDefault() : createLocale(mLocaleCode);
    Locale[] availableLocales = Locale.getAvailableLocales();
    String[] values = context.getResources().getStringArray(R.array.localeOverride_values);
    String[] entries = new String[values.length];
    for (int i = values.length - 1; i > 0; i--) {
        Locale locale = createLocale(values[i]);

        // Get intersection of languages (available on device) and (translated for Mupen)
        if (ArrayUtils.contains(availableLocales, locale)) {
            // Get the name of the language, as written natively
            entries[i] = WordUtils.capitalize(locale.getDisplayName(locale));
        } else {
            // Remove the item from the list
            entries = (String[]) ArrayUtils.remove(entries, i);
            values = (String[]) ArrayUtils.remove(values, i);
        }
    }
    entries[0] = context.getString(R.string.localeOverride_entrySystemDefault);
    mLocaleNames = entries;
    mLocaleCodes = values;

    // Files
    userDataDir = mPreferences.getString("pathGameSaves", "");
    galleryDataDir = userDataDir + "/GalleryData";
    profilesDir = userDataDir + "/Profiles";
    crashLogDir = userDataDir + "/CrashLogs";
    coreUserDataDir = userDataDir + "/CoreConfig/UserData";
    coreUserCacheDir = userDataDir + "/CoreConfig/UserCache";
    hiResTextureDir = coreUserDataDir + "/mupen64plus/hires_texture/"; // MUST match what rice assumes natively
    romInfoCache_cfg = galleryDataDir + "/romInfoCache.cfg";
    controllerProfiles_cfg = profilesDir + "/controller.cfg";
    touchscreenProfiles_cfg = profilesDir + "/touchscreen.cfg";
    emulationProfiles_cfg = profilesDir + "/emulation.cfg";
    customCheats_txt = profilesDir + "/customCheats.txt";

    // Plug-ins
    audioPlugin = new Plugin(mPreferences, appData.libsDir, "audioPlugin");

    // Touchscreen prefs
    isTouchscreenFeedbackEnabled = mPreferences.getBoolean("touchscreenFeedback", false);
    touchscreenRefresh = getSafeInt(mPreferences, "touchscreenRefresh", 0);
    touchscreenScale = ((float) mPreferences.getInt("touchscreenScale", 100)) / 100.0f;
    touchscreenTransparency = (255 * mPreferences.getInt("touchscreenTransparency", 100)) / 100;
    touchscreenSkin = appData.touchscreenSkinsDir + "/" + mPreferences.getString("touchscreenStyle", "Outline");
    touchscreenAutoHold = getSafeInt(mPreferences, "touchscreenAutoHold", 0);

    // Xperia PLAY touchpad prefs
    isTouchpadEnabled = appData.hardwareInfo.isXperiaPlay && mPreferences.getBoolean("touchpadEnabled", true);
    isTouchpadFeedbackEnabled = mPreferences.getBoolean("touchpadFeedback", false);
    touchpadSkin = appData.touchpadSkinsDir + "/Xperia-Play";
    ConfigFile touchpad_cfg = new ConfigFile(appData.touchpadProfiles_cfg);
    ConfigSection section = touchpad_cfg.get(mPreferences.getString("touchpadLayout", ""));
    if (section != null)
        touchpadProfile = new Profile(true, section);
    else
        touchpadProfile = null;

    // Video prefs
    displayOrientation = getSafeInt(mPreferences, "displayOrientation", 0);
    displayPosition = getSafeInt(mPreferences, "displayPosition", Gravity.CENTER_VERTICAL);
    int transparencyPercent = mPreferences.getInt("displayActionBarTransparency", 50);
    displayActionBarTransparency = (255 * transparencyPercent) / 100;
    displayFpsRefresh = getSafeInt(mPreferences, "displayFpsRefresh", 0);
    isFpsEnabled = displayFpsRefresh > 0;
    videoHardwareType = getSafeInt(mPreferences, "videoHardwareType", -1);
    videoPolygonOffset = SafeMethods.toFloat(mPreferences.getString("videoPolygonOffset", "-0.2"), -0.2f);
    isImmersiveModeEnabled = mPreferences.getBoolean("displayImmersiveMode", false);

    // Audio prefs
    audioSwapChannels = mPreferences.getBoolean("audioSwapChannels", false);
    audioSecondaryBufferSize = getSafeInt(mPreferences, "audioBufferSize", 2048);
    if (audioPlugin.enabled)
        isFramelimiterEnabled = mPreferences.getBoolean("audioSynchronize", true);
    else
        isFramelimiterEnabled = !mPreferences.getString("audioPlugin", "").equals("nospeedlimit");

    // User interface modes
    String navMode = mPreferences.getString("navigationMode", "auto");
    if (navMode.equals("bigscreen"))
        isBigScreenMode = true;
    else if (navMode.equals("standard"))
        isBigScreenMode = false;
    else
        isBigScreenMode = AppData.IS_OUYA_HARDWARE; // TODO: Add other systems as they enter market
    isActionBarAvailable = AppData.IS_HONEYCOMB && !isBigScreenMode;

    // Peripheral share mode
    isControllerShared = mPreferences.getBoolean("inputShareController", false);

    // Determine the key codes that should not be mapped to controls
    boolean volKeysMappable = mPreferences.getBoolean("inputVolumeMappable", false);
    List<Integer> unmappables = new ArrayList<Integer>();
    unmappables.add(KeyEvent.KEYCODE_MENU);
    if (AppData.IS_HONEYCOMB) {
        // Back key is needed to show/hide the action bar in HC+
        unmappables.add(KeyEvent.KEYCODE_BACK);
    }
    if (!volKeysMappable) {
        unmappables.add(KeyEvent.KEYCODE_VOLUME_UP);
        unmappables.add(KeyEvent.KEYCODE_VOLUME_DOWN);
        unmappables.add(KeyEvent.KEYCODE_VOLUME_MUTE);
    }
    unmappableKeyCodes = Collections.unmodifiableList(unmappables);

    // Determine the pixel dimensions of the rendering context and view surface
    {
        // Screen size
        final WindowManager windowManager = (WindowManager) context
                .getSystemService(android.content.Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        int stretchWidth;
        int stretchHeight;
        if (display == null) {
            stretchWidth = stretchHeight = 0;
        } else if (AppData.IS_KITKAT && isImmersiveModeEnabled) {
            DisplayMetrics metrics = new DisplayMetrics();
            display.getRealMetrics(metrics);
            stretchWidth = metrics.widthPixels;
            stretchHeight = metrics.heightPixels;
        } else {
            stretchWidth = display.getWidth();
            stretchHeight = display.getHeight();
        }

        float aspect = 0.75f; // TODO: Handle PAL
        boolean isLetterboxed = ((float) stretchHeight / (float) stretchWidth) > aspect;
        int zoomWidth = isLetterboxed ? stretchWidth : Math.round((float) stretchHeight / aspect);
        int zoomHeight = isLetterboxed ? Math.round((float) stretchWidth * aspect) : stretchHeight;
        int cropWidth = isLetterboxed ? Math.round((float) stretchHeight / aspect) : stretchWidth;
        int cropHeight = isLetterboxed ? stretchHeight : Math.round((float) stretchWidth * aspect);

        int hResolution = getSafeInt(mPreferences, "displayResolution", 0);
        String scaling = mPreferences.getString("displayScaling", "zoom");
        if (hResolution == 0) {
            // Native resolution
            if (scaling.equals("stretch")) {
                videoRenderWidth = videoSurfaceWidth = stretchWidth;
                videoRenderHeight = videoSurfaceHeight = stretchHeight;
            } else if (scaling.equals("crop")) {
                videoRenderWidth = videoSurfaceWidth = cropWidth;
                videoRenderHeight = videoSurfaceHeight = cropHeight;
            } else // scaling.equals( "zoom") || scaling.equals( "none" )
            {
                videoRenderWidth = videoSurfaceWidth = zoomWidth;
                videoRenderHeight = videoSurfaceHeight = zoomHeight;
            }
        } else {
            // Non-native resolution
            switch (hResolution) {
            case 720:
                videoRenderWidth = 960;
                videoRenderHeight = 720;
                break;
            case 600:
                videoRenderWidth = 800;
                videoRenderHeight = 600;
                break;
            case 480:
                videoRenderWidth = 640;
                videoRenderHeight = 480;
                break;
            case 360:
                videoRenderWidth = 480;
                videoRenderHeight = 360;
                break;
            case 240:
                videoRenderWidth = 320;
                videoRenderHeight = 240;
                break;
            case 120:
                videoRenderWidth = 160;
                videoRenderHeight = 120;
                break;
            default:
                videoRenderWidth = Math.round((float) hResolution / aspect);
                videoRenderHeight = hResolution;
                break;
            }
            if (scaling.equals("zoom")) {
                videoSurfaceWidth = zoomWidth;
                videoSurfaceHeight = zoomHeight;
            } else if (scaling.equals("crop")) {
                videoSurfaceWidth = cropWidth;
                videoSurfaceHeight = cropHeight;
            } else if (scaling.equals("stretch")) {
                videoSurfaceWidth = stretchWidth;
                videoSurfaceHeight = stretchHeight;
            } else // scaling.equals( "none" )
            {
                videoSurfaceWidth = videoRenderWidth;
                videoSurfaceHeight = videoRenderHeight;
            }
        }
    }
}

From source file:pt.webdetails.cgg.scripts.SystemFolderScriptResourceLoader.java

@Override
public InputStream getContextResource(String s) throws IOException, ScriptResourceNotFoundException {
    if ((basePath != null && basePath.startsWith("/system")) || s.startsWith("/system")) {
        SystemPluginResourceAccess resourceAccess = new SystemPluginResourceAccess("cgg", "");

        String fullPath = s;/*from ww  w .ja v a  2 s  .com*/
        if (basePath != null && !s.startsWith("/system")) {
            fullPath = basePath + "/" + s;
        }
        return resourceAccess.getFileInputStream(fullPath);
    } else if (basePath != null && basePath.startsWith("/plugin") || s.startsWith("/plugin")) {
        // get the plugin id first
        String[] sections = s.split("/");

        SystemPluginResourceAccess resourceAccess = new SystemPluginResourceAccess(sections[2], "");

        //remove the name of the plugin
        sections = (String[]) ArrayUtils.remove(sections, 1);
        sections = (String[]) ArrayUtils.remove(sections, 1);

        return resourceAccess.getFileInputStream(StringUtils.join(sections, "/"));
    } else {
        throw new ScriptResourceNotFoundException(s);
    }
}

From source file:rems.Global.java

public static boolean sendEmail(String toEml, String ccEml, String bccEml, String attchmnt, String sbjct,
        String bdyTxt, String[] errMsgs) {
    try {/*from  ww  w  .  j  a v a 2 s.c  om*/
        String selSql = "SELECT smtp_client, mail_user_name, mail_password, smtp_port FROM sec.sec_email_servers WHERE (is_default = 't')";
        ResultSet selDtSt = Global.selectDataNoParams(selSql);
        selDtSt.last();
        int m = selDtSt.getRow();
        String smtpClnt = "";
        String fromEmlNm = "";
        String fromPswd = "";
        errMsgs[0] = "";
        int portNo = 0;
        if (m > 0) {
            selDtSt.beforeFirst();
            selDtSt.next();
            smtpClnt = selDtSt.getString(1);
            fromEmlNm = selDtSt.getString(2);
            fromPswd = selDtSt.getString(3);
            portNo = selDtSt.getInt(4);
        }
        selDtSt.close();
        String fromPassword = Global.decrypt(fromPswd, Global.AppKey);
        // load your HTML email template
        if (bdyTxt.contains("<body") == false || bdyTxt.contains("</body>") == false) {
            bdyTxt = "<body>" + bdyTxt + "</body>";
        }
        if (bdyTxt.contains("<html") == false || bdyTxt.contains("</html>") == false) {
            bdyTxt = "<!DOCTYPE html><html lang=\"en\">" + bdyTxt + "</html>";
        }
        String htmlEmailTemplate = bdyTxt;
        // define you base URL to resolve relative resource locations
        URL url = new URL(Global.AppUrl);
        // create the email message
        ImageHtmlEmail email = new ImageHtmlEmail();
        email.setDataSourceResolver(new DataSourceUrlResolver(url));
        email.setHostName(smtpClnt);
        email.setSmtpPort(portNo);
        email.setAuthentication(fromEmlNm, fromPassword);
        email.setDebug(true);
        email.setStartTLSEnabled(true);
        email.setStartTLSRequired(true);

        String spltChars = "\\s*;\\s*";
        String[] toEmails = removeDplctChars(toEml).trim().split(spltChars);
        String[] ccEmails = removeDplctChars(ccEml).trim().split(spltChars);
        String[] bccEmails = removeDplctChars(bccEml).trim().split(spltChars);
        String[] attchMnts = removeDplctChars(attchmnt).trim().split(spltChars);
        for (int i = 0; i < attchMnts.length; i++) {
            if (attchMnts[i].equals("")) {
                continue;
            }
            EmailAttachment attachment = new EmailAttachment();
            if (attchMnts[i].startsWith("http://") || attchMnts[i].startsWith("https://")) {
                attachment.setURL(new URL(attchMnts[i].replaceAll(" ", "%20")));
                //"http://www.apache.org/images/asf_logo_wide.gif"
            } else {
                attachment.setPath(attchMnts[i].replaceAll(" ", "%20"));
            }
            attachment.setDisposition(EmailAttachment.ATTACHMENT);
            //attachment.setDescription("Picture of John");
            //attachment.setName("John");
            // add the attachment
            email.attach(attachment);
        }
        int lovID = Global.getLovID("Email Addresses to Ignore");
        int toMailsAdded = 0;
        for (int i = 0; i < toEmails.length; i++) {
            if (Global.isEmailValid(toEmails[i], lovID)) {
                if (Global.getEnbldPssblValID(toEmails[i], lovID) <= 0) {
                    //DO Nothing
                    toMailsAdded++;
                } else {
                    toEmails[i] = "ToBeRemoved";
                    errMsgs[0] += "Address:" + toEmails[i] + " blacklisted by you!\r\n";
                }
            } else {
                errMsgs[0] += "Address:" + toEmails[i] + " is Invalid!\r\n";
            }
        }
        if (toMailsAdded <= 0) {
            return false;
        }
        for (int i = 0; i < toEmails.length; i++) {
            if (toEmails[i].equals("ToBeRemoved")) {
                toEmails = (String[]) ArrayUtils.remove(toEmails, i);
            }
        }
        if (toEmails.length > 0) {
            if (toEmails[0].equals("") == false) {
                email.addTo(toEmails);
            }
        }
        for (int i = 0; i < ccEmails.length; i++) {
            if (Global.isEmailValid(ccEmails[i], lovID)) {
                if (Global.getEnbldPssblValID(ccEmails[i], lovID) <= 0) {
                    //DO Nothing
                } else {
                    ccEmails[i] = "ToBeRemoved";
                    errMsgs[0] += "Address:" + ccEmails[i] + " blacklisted by you!\r\n";
                }
            } else {
                errMsgs[0] += "Address:" + ccEmails[i] + " is Invalid!\r\n";
            }
        }
        for (int i = 0; i < ccEmails.length; i++) {
            if (ccEmails[i].equals("ToBeRemoved")) {
                ccEmails = (String[]) ArrayUtils.remove(ccEmails, i);
            }
        }
        if (ccEmails.length > 0) {
            if (ccEmails[0].equals("") == false) {
                email.addCc(ccEmails);
            }
        }
        for (int i = 0; i < bccEmails.length; i++) {
            if (Global.isEmailValid(bccEmails[i], lovID)) {
                if (Global.getEnbldPssblValID(bccEmails[i], lovID) <= 0) {
                    //DO Nothing
                } else {
                    bccEmails[i] = "ToBeRemoved";
                    errMsgs[0] += "Address:" + bccEmails[i] + " blacklisted by you!\r\n";
                }
            } else {
                errMsgs[0] += "Address:" + bccEmails[i] + " is Invalid!\r\n";
            }
        }
        for (int i = 0; i < bccEmails.length; i++) {
            if (bccEmails[i].equals("ToBeRemoved")) {
                bccEmails = (String[]) ArrayUtils.remove(bccEmails, i);
            }
        }
        if (bccEmails.length > 0) {
            if (bccEmails[0].equals("") == false) {
                email.addBcc(bccEmails);
            }
        }
        email.setFrom(fromEmlNm.trim());
        email.setSubject(sbjct);
        // set the html message
        email.setHtmlMsg(htmlEmailTemplate);
        // set the alternative message
        email.setTextMsg("Your email client does not support HTML messages");
        // send the email
        if (Global.CheckForInternetConnection()) {
            email.send();
            return true;
        }
        errMsgs[0] += "No Internet Connection";
        return false;
    } catch (SQLException ex) {
        Global.errorLog = "\r\nFailed to send Email!\r\n" + ex.getMessage();
        Global.writeToLog();
        errMsgs[0] += "Failed to send Email!\r\n" + ex.getMessage();
        return false;
    } catch (MalformedURLException ex) {
        Global.errorLog = "\r\nFailed to send Email!\r\n" + ex.getMessage();
        Global.writeToLog();
        errMsgs[0] += "Failed to send Email!\r\n" + ex.getMessage();
        return false;
    } catch (EmailException ex) {
        Global.errorLog = "\r\nFailed to send Email!\r\n" + ex.getMessage();
        Global.writeToLog();
        errMsgs[0] += "Failed to send Email!\r\n" + ex.getMessage();
        return false;
    } catch (Exception ex) {
        Global.errorLog = "\r\nFailed to send Email!\r\n" + ex.getMessage();
        Global.writeToLog();
        errMsgs[0] += "Failed to send Email!\r\n" + ex.getMessage();
        return false;
    }
}

From source file:sernet.verinice.rcp.accountgroup.GroupView.java

private void updateAccountList() {
    if (accountGroupDataService != null && accountGroupDataService.getAllAccounts() != null) {
        accounts = accountGroupDataService.getAllAccounts();
        // remove accounts that are enlisted in tableToGroupAccounts
        for (String account : accountsInGroup) {
            if (ArrayUtils.contains(accounts, account)) {
                accounts = (String[]) ArrayUtils.remove(accounts, ArrayUtils.indexOf(accounts, account));
            }//from  w  w w  .  j  a va2 s .  co m
        }
        Arrays.sort(accounts, COLLATOR);
        tableAccounts.setInput(accounts);
    }
}