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

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

Introduction

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

Prototype

public static short[] add(short[] array, short element) 

Source Link

Document

Copies the given array and adds the given element at the end of the new array.

Usage

From source file:org.sipfoundry.sipxconfig.phone.polycom.PolycomPhone.java

@Override
public Profile[] getProfileTypes() {
    Profile[] profileTypes;//from   ww  w.  j a  va 2  s  .c  om
    if (getDeviceVersion() == PolycomModel.VER_4_0_X || getDeviceVersion() == PolycomModel.VER_4_1_X) {
        profileTypes = new Profile[] { new ApplicationProfile(getAppFilename()),
                new ApplicationsProfile(getAppsFilename()), new FeaturesProfile(getFeaturesFilename()),
                new RegAdvancedProfile(getRegAdvancedFilename()), new RegionProfile(getRegionFilename()),
                new SipBasicProfile(getSipBasicFilename()), new SipInteropProfile(getSipInteropFilename()),
                new SiteProfile(getSiteFilename()), new VideoProfile(getVideoFilename()) };
    } else {
        profileTypes = new Profile[] { new ApplicationProfile(getAppFilename()),
                new SipProfile(getSipFilename()), new PhoneProfile(getPhoneFilename()),
                new DeviceProfile(getDeviceFilename()) };
    }

    if (getPhonebookManager().getPhonebookManagementEnabled()) {
        profileTypes = (Profile[]) ArrayUtils.add(profileTypes, new DirectoryProfile(getDirectoryFilename()));
    }

    return profileTypes;
}

From source file:org.sipfoundry.sipxconfig.phone.yealink.YealinkPhone.java

@Override
public Profile[] getProfileTypes() {
    Profile[] profileTypes = new Profile[] { new DeviceProfile(getDeviceFilename()) };

    if (getPhonebookManager().getPhonebookManagementEnabled()) {
        if (getModel().isSupported(YealinkConstants.FEATURE_PHONEBOOK)) {
            PhonebookManager pbm = getPhonebookManager();
            if (null != pbm) {
                User user = getPrimaryUser();
                if (null != user) {
                    Collection<Phonebook> phoneBooks = pbm.getAllPhonebooksByUser(user);
                    if (null != phoneBooks) {
                        Integer i = 0;
                        for (Phonebook pb : phoneBooks) {
                            if (null != pb) {
                                if (pb.getShowOnPhone()) {
                                    profileTypes = (Profile[]) ArrayUtils.add(profileTypes,
                                            new DirectoryProfile(getDirectoryFilename(i++), pb));
                                }/*from   ww w . j  ava  2  s.  c om*/
                            }
                        }
                    }
                }
            }
        }
    }
    return profileTypes;
}

From source file:org.sipfoundry.sipxconfig.site.vm.MailboxPreferencesForm.java

public IPropertySelectionModel getVoicemailPropertiesModel() {
    // FIXME: why not just check user properties directly...
    boolean unifiedMessagingParamsGroup = false;
    String host = getPreferences().getUser().getSettingValue(HOST_SETTING);
    Integer port = (Integer) getPreferences().getUser().getSettingTypedValue(PORT_SETTING);
    if (StringUtils.isNotEmpty(host) && port != null) {
        unifiedMessagingParamsGroup = true;
    }/*from  ww  w. java 2 s. c  om*/
    String[] options = new String[] { MailboxPreferences.ATTACH_VOICEMAIL,
            MailboxPreferences.DO_NOT_ATTACH_VOICEMAIL };
    if (unifiedMessagingParamsGroup) {
        options = (String[]) ArrayUtils.add(options, MailboxPreferences.SYNCHRONIZE_WITH_EMAIL_SERVER);
    }
    StringPropertySelectionModel model = new StringPropertySelectionModel(options);
    return new LocalizedOptionModelDecorator(model, getMessages(), "voicemailProperties.");
}

From source file:org.sparkcommerce.core.web.processor.ToggleFacetLinkProcessor.java

@Override
@SuppressWarnings("unchecked")
protected Map<String, String> getModifiedAttributeValues(Arguments arguments, Element element,
        String attributeName) {/*w ww .  ja va  2  s .c  o  m*/
    Map<String, String> attrs = new HashMap<String, String>();

    SparkRequestContext blcContext = SparkRequestContext.getSparkRequestContext();
    HttpServletRequest request = blcContext.getRequest();

    String baseUrl = request.getRequestURL().toString();
    Map<String, String[]> params = new HashMap<String, String[]>(request.getParameterMap());

    Expression expression = (Expression) StandardExpressions.getExpressionParser(arguments.getConfiguration())
            .parseExpression(arguments.getConfiguration(), arguments, element.getAttributeValue(attributeName));
    SearchFacetResultDTO result = (SearchFacetResultDTO) expression.execute(arguments.getConfiguration(),
            arguments);

    String key = facetService.getUrlKey(result);
    String value = facetService.getValue(result);
    String[] paramValues = params.get(key);

    if (ArrayUtils.contains(paramValues, facetService.getValue(result))) {
        paramValues = (String[]) ArrayUtils.removeElement(paramValues, facetService.getValue(result));
    } else {
        paramValues = (String[]) ArrayUtils.add(paramValues, value);
    }

    params.remove(ProductSearchCriteria.PAGE_NUMBER);
    params.put(key, paramValues);

    String url = ProcessorUtils.getUrl(baseUrl, params);

    attrs.put("href", url);
    return attrs;
}

From source file:org.sparkcommerce.openadmin.server.service.persistence.module.provider.MediaFieldPersistenceProvider.java

@Override
public FieldProviderResponse populateValue(PopulateValueRequest populateValueRequest, Serializable instance)
        throws PersistenceException {
    if (!canHandlePersistence(populateValueRequest, instance)) {
        return FieldProviderResponse.NOT_HANDLED;
    }/*from  ww w . j  a  v a2 s . c  o m*/
    FieldProviderResponse response = FieldProviderResponse.HANDLED;
    boolean dirty = false;
    try {
        setNonDisplayableValues(populateValueRequest);
        Class<?> valueType = null;
        if (!populateValueRequest.getProperty().getName().contains(FieldManager.MAPFIELDSEPARATOR)) {
            valueType = populateValueRequest.getReturnType();
        } else {
            String valueClassName = populateValueRequest.getMetadata().getMapFieldValueClass();
            if (valueClassName != null) {
                valueType = Class.forName(valueClassName);
            }
            if (valueType == null) {
                valueType = populateValueRequest.getReturnType();
            }
        }

        if (valueType == null) {
            throw new IllegalAccessException("Unable to determine the valueType for the rule field ("
                    + populateValueRequest.getProperty().getName() + ")");
        }

        if (Media.class.isAssignableFrom(valueType)) {
            Media newMedia = convertJsonToMedia(populateValueRequest.getProperty().getUnHtmlEncodedValue());
            Media media;
            try {
                media = (Media) populateValueRequest.getFieldManager().getFieldValue(instance,
                        populateValueRequest.getProperty().getName());
            } catch (FieldNotAvailableException e) {
                throw new IllegalArgumentException(e);
            }
            populateValueRequest.getProperty().setOriginalValue(convertMediaToJson(media));

            boolean persist = false;
            if (media == null) {
                media = (Media) valueType.newInstance();
                persist = true;
            }

            Map description = BeanUtils.describe(media);
            for (Object temp : description.keySet()) {
                String property = (String) temp;
                //ignore id and SandBoxDiscriminator fields
                String[] ignoredProperties = sandBoxHelper.getSandBoxDiscriminatorFieldList();
                ignoredProperties = (String[]) ArrayUtils.add(ignoredProperties, "id");
                Arrays.sort(ignoredProperties);
                if (Arrays.binarySearch(ignoredProperties, property) < 0) {
                    String prop1 = String.valueOf(description.get(property));
                    String prop2 = String.valueOf(BeanUtils.getProperty(newMedia, property));
                    if (!prop1.equals(prop2)) {
                        dirty = true;
                        break;
                    }
                }
            }

            if (dirty) {
                updateMediaFields(media, newMedia);
                if (persist) {
                    populateValueRequest.getPersistenceManager().getDynamicEntityDao().persist(media);
                }
                populateValueRequest.getFieldManager().setFieldValue(instance,
                        populateValueRequest.getProperty().getName(), media);
                response = FieldProviderResponse.HANDLED_BREAK;
            }
        } else {
            throw new UnsupportedOperationException("MediaFields only work with Media types.");
        }
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
    populateValueRequest.getProperty().setIsDirty(dirty);

    return response;
}

From source file:org.structr.core.entity.AbstractRelationship.java

public void addPermission(final Permission permission) {

    String[] allowed = getPermissions();

    if (ArrayUtils.contains(allowed, permission.name())) {

        return;/*from  www . j  a v  a2s .  c  om*/
    }

    setAllowed((String[]) ArrayUtils.add(allowed, permission.name()));

}

From source file:org.talend.designer.core.runprocess.Processor.java

/**
 * Get the executable commandLine.//  w  ww .j  ava2  s  .c o  m
 * 
 * @param contextName
 * @param statOption
 * @param traceOption
 * @param codeOptions
 * @return
 */
@Override
public String[] getCommandLine(boolean needContext, boolean externalUse, int statOption, int traceOption,
        String... codeOptions) {
    setExternalUse(externalUse);
    String[] cmd = null;
    try {
        cmd = getCommandLine();

    } catch (ProcessorException e) {
        ExceptionHandler.process(e);
    }
    cmd = addCommmandLineAttch(needContext, cmd, context != null ? context.getName() : IContext.DEFAULT,
            statOption, traceOption, codeOptions);

    // (feature 4258)
    if (Platform.OS_LINUX.equals(getTargetPlatform())) {
        // original is $*
        cmd = (String[]) ArrayUtils.add(cmd, JobScriptsManager.CMDFORUNIX);
    } else if (Platform.OS_WIN32.equals(getTargetPlatform())) {
        cmd = (String[]) ArrayUtils.add(cmd, JobScriptsManager.CMDFORWIN);
    }
    return cmd;
}

From source file:org.talend.designer.core.runprocess.Processor.java

/**
 * Add the attchment condition to commmandline .
 * //ww w. jav  a 2  s.c o  m
 * @param commandLine
 * @param contextName
 * @param statOption
 * @param traceOption
 * @param codeOptions
 * @return
 */
protected static String[] addCommmandLineAttch(boolean needContext, String[] commandLine, String contextName,
        int statOption, int traceOption, String... codeOptions) {
    String[] cmd = commandLine;
    if (codeOptions != null) {
        for (String string : codeOptions) {
            if (string != null) {
                cmd = (String[]) ArrayUtils.add(cmd, string);
            }
        }
    }
    if (needContext && contextName != null) {
        cmd = (String[]) ArrayUtils.add(cmd, CTX_ARG + contextName);
    }
    if (statOption != -1) {
        cmd = (String[]) ArrayUtils.add(cmd, STAT_PORT_ARG + statOption);
    }
    if (traceOption != -1) {
        cmd = (String[]) ArrayUtils.add(cmd, TRACE_PORT_ARG + traceOption);
    }
    return cmd;
}

From source file:org.talend.designer.runprocess.DeleteAllJobWhenStartUp.java

@Override
public void earlyStartup() {

    if (!startUnderPluginModel && !CorePlugin.getDefault().getRepositoryService().isRCPMode()) {
        return;//from   w w  w.java  2  s . com
    }

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot workspaceRoot = workspace.getRoot();

    IProject rootProject = null;
    try {
        rootProject = JavaProcessorUtilities.getProcessorProject();
    } catch (CoreException e1) {
        ExceptionHandler.process(e1);
    }
    IResource javaRecs = workspaceRoot.findMember(JavaUtils.JAVA_PROJECT_NAME);
    if (javaRecs != null && javaRecs.getType() == IResource.PROJECT) {
        rootProject = (IProject) javaRecs;
        try {
            if (!rootProject.isOpen()) {
                rootProject.open(null);
            }
            javaRecs = workspaceRoot
                    .findMember(JavaUtils.JAVA_PROJECT_NAME + File.separator + JavaUtils.JAVA_SRC_DIRECTORY);
            if (javaRecs != null && javaRecs.getType() == IResource.FOLDER) {
                IFolder javaSrcFolder = (IFolder) javaRecs;

                IResource[] javaProRecs = javaSrcFolder.members();
                if (javaProRecs.length > 0) {
                    for (IResource javaProRec : javaProRecs) {
                        javaProRec.delete(true, null);
                    }
                }

            }

            IResource libRecs = workspaceRoot.findMember(JavaUtils.JAVA_PROJECT_NAME + File.separator + "lib");
            if (libRecs != null && libRecs.getType() == IResource.FOLDER) {
                IFolder javaLibFolder = (IFolder) libRecs;

                IResource[] javaProRecs = javaLibFolder.members();
                if (javaProRecs.length > 0) {
                    for (IResource javaProRec : javaProRecs) {
                        javaProRec.delete(true, null);
                    }
                }

            }
            IExtensionRegistry registry = Platform.getExtensionRegistry();
            IExtension nature = registry.getExtension("org.eclipse.core.resources.natures", JavaCore.NATURE_ID); //$NON-NLS-1$

            if (rootProject.getNature(JavaCore.NATURE_ID) == null && nature != null) {
                IProjectDescription description = rootProject.getDescription();
                String[] natures = description.getNatureIds();
                String[] newNatures = new String[natures.length + 1];
                System.arraycopy(natures, 0, newNatures, 0, natures.length);
                newNatures[natures.length] = JavaCore.NATURE_ID;
                description.setNatureIds(newNatures);
                rootProject.open(IResource.BACKGROUND_REFRESH, null);
                rootProject.setDescription(description, null);
            }
            IJavaProject javaProject = JavaCore.create(rootProject);

            IClasspathEntry[] entries = new IClasspathEntry[] {};

            IClasspathEntry jreClasspathEntry = JavaCore
                    .newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")); //$NON-NLS-1$
            IClasspathEntry classpathEntry = JavaCore
                    .newSourceEntry(javaProject.getPath().append(JavaUtils.JAVA_SRC_DIRECTORY));

            entries = (IClasspathEntry[]) ArrayUtils.add(entries, jreClasspathEntry);
            entries = (IClasspathEntry[]) ArrayUtils.add(entries, classpathEntry);

            javaProject.setRawClasspath(entries, null);
            javaProject.setOutputLocation(javaProject.getPath().append(JavaUtils.JAVA_CLASSES_DIRECTORY), null);

        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
    }

    // no need to synchronize the routines here, as it will be done in the code generation.

    // // fix bug 1151, move the sync all routines here from JavaProcessor and PerlProcessor.
    // Display.getDefault().asyncExec(new Runnable() {
    //
    // public void run() {
    // try {
    // RunProcessPlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer().syncAllRoutines();
    // } catch (Exception e) {
    // ExceptionHandler.process(e);
    // }
    // }
    // });

    executed = true;

}

From source file:org.talend.designer.runprocess.java.JavaProcessorUtilities.java

private static void sortClasspath(Set<String> jobModuleList, IProcess process)
        throws CoreException, BusinessException {
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    IClasspathEntry jreClasspathEntry = JavaCore
            .newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")); //$NON-NLS-1$
    IClasspathEntry classpathEntry = JavaCore
            .newSourceEntry(javaProject.getPath().append(JavaUtils.JAVA_SRC_DIRECTORY));

    boolean changesDone = false;
    if (!ArrayUtils.contains(entries, jreClasspathEntry)) {
        entries = (IClasspathEntry[]) ArrayUtils.add(entries, jreClasspathEntry);
        changesDone = true;//from w  w w . j a v a 2 s  . c  o  m
    }
    if (!ArrayUtils.contains(entries, classpathEntry)) {
        IClasspathEntry source = null;
        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                source = entry;
                break;
            }
        }
        if (source != null) {
            entries = (IClasspathEntry[]) ArrayUtils.remove(entries, ArrayUtils.indexOf(entries, source));
        }
        entries = (IClasspathEntry[]) ArrayUtils.add(entries, classpathEntry);
        changesDone = true;
    }

    // Added by Marvin Wang on Nov. 8, 2012. Maybe some modules are in the list with a directory, so cut the
    // directory only file name remaining.
    Set<String> listModulesReallyNeeded = ModuleNameExtractor.extractFileName(jobModuleList);
    Set<String> listModulesNeededByProcess = new HashSet<String>();
    if (listModulesReallyNeeded != null && listModulesReallyNeeded.size() > 0) {
        for (String jobModule : listModulesReallyNeeded) {
            listModulesNeededByProcess.add(jobModule);
        }
    }

    Set<String> optionalJarsOnlyForRoutines = new HashSet<String>();

    if (listModulesReallyNeeded == null) {
        listModulesReallyNeeded = new HashSet<String>();
    }

    // only for wizards or additional jars only to make the java project compile without any error.
    for (ModuleNeeded moduleNeeded : ModulesNeededProvider
            .getModulesNeededForRoutines(ERepositoryObjectType.ROUTINES)) {
        optionalJarsOnlyForRoutines.add(moduleNeeded.getModuleName());
    }

    if (ERepositoryObjectType.getType("BEANS") != null) {
        for (ModuleNeeded moduleNeeded : ModulesNeededProvider
                .getModulesNeededForRoutines(ERepositoryObjectType.getType("BEANS"))) {
            optionalJarsOnlyForRoutines.add(moduleNeeded.getModuleName());
        }
    }

    for (ModuleNeeded moduleNeeded : ModulesNeededProvider
            .getModulesNeededForRoutines(ERepositoryObjectType.PIG_UDF)) {
        optionalJarsOnlyForRoutines.add(moduleNeeded.getModuleName());
    }
    // list contains all routines linked to job as well as routines not used in the job
    // rebuild the list to have only the libs linked to routines "not used".
    optionalJarsOnlyForRoutines.removeAll(listModulesReallyNeeded);

    // at this point, the Set for optional jars really only contains optional jars for routines
    // only to be able to compile java project without error.
    for (String jar : optionalJarsOnlyForRoutines) {
        listModulesReallyNeeded.add(jar);
    }

    addLog4jToJarList(listModulesReallyNeeded);

    File libDir = getJavaProjectLibFolder();
    if ((libDir != null) && (libDir.isDirectory())) {
        Set<String> jarsNeedRetrieve = new HashSet<String>(listModulesReallyNeeded);
        for (File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
            jarsNeedRetrieve.remove(externalLib.getName());
        }
        List<IClasspathEntry> entriesToRemove = new ArrayList<IClasspathEntry>();
        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                boolean found = false;
                for (File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
                    if (entry.getPath().toPortableString().endsWith(externalLib.getName())) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    // jar not anymore in the lib path, need to update the classpath
                    entriesToRemove.add(entry);
                }
            }
        }
        for (IClasspathEntry entry : entriesToRemove) {
            entries = (IClasspathEntry[]) ArrayUtils.remove(entries, ArrayUtils.indexOf(entries, entry));
            changesDone = true;
        }

        if (!jarsNeedRetrieve.isEmpty()) {
            // get original context value
            Set<String> originalConexts = new HashSet<String>();
            Iterator<String> iterator = jarsNeedRetrieve.iterator();
            while (iterator.hasNext()) {
                String jarNeedRetrieve = iterator.next();
                if (ContextParameterUtils.isContainContextParam(jarNeedRetrieve)
                        && process instanceof IProcess2) {
                    iterator.remove(); // remove the context one.
                    IContext lastRunContext = ((IProcess2) process).getLastRunContext();
                    if (lastRunContext != null) {
                        String contextValue = ContextParameterUtils.parseScriptContextCode(jarNeedRetrieve,
                                lastRunContext);
                        if (contextValue != null) {
                            originalConexts.add(new File(contextValue).getName());
                        }
                    } else {
                        IContextManager contextManager = process.getContextManager();
                        if (contextManager != null) {
                            String contextValue = ContextParameterUtils.parseScriptContextCode(jarNeedRetrieve,
                                    contextManager.getDefaultContext());
                            if (contextValue != null) {
                                originalConexts.add(new File(contextValue).getName());
                            }
                        }
                    }
                }
            }
            jarsNeedRetrieve.addAll(originalConexts);
            ILibraryManagerService repositoryBundleService = CorePlugin.getDefault()
                    .getRepositoryBundleService();
            repositoryBundleService.retrieve(jarsNeedRetrieve, libDir.getAbsolutePath());
            if (process instanceof IProcess2) {
                ((IProcess2) process).checkProcess();
            }
        }
        for (File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
            if (externalLib.isFile() && listModulesReallyNeeded.contains(externalLib.getName())) {
                IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path(externalLib.getAbsolutePath()),
                        null, null);
                if (!ArrayUtils.contains(entries, newEntry)) {
                    entries = (IClasspathEntry[]) ArrayUtils.add(entries, newEntry);
                    changesDone = true;
                }
            }
        }
    }

    String missingJars = null;
    // String missingJarsForRoutinesOnly = null;
    Set<String> missingJarsForRoutinesOnly = new HashSet<String>();
    Set<String> missingJarsForProcessOnly = new HashSet<String>();
    // sort
    int exchange = 2; // The first,second library is JVM and SRC.
    for (String jar : listModulesReallyNeeded) {
        int index = indexOfEntry(entries, jar);
        if (index < 0) {
            if (ContextParameterUtils.isContainContextParam(jar)) {
                continue;
            }
            if (listModulesNeededByProcess.contains(jar)) {
                missingJarsForProcessOnly.add(jar);
            } else {
                missingJarsForRoutinesOnly.add(jar);
            }
            if (missingJars == null) {
                missingJars = Messages.getString("JavaProcessorUtilities.msg.missingjar.forProcess") + jar; //$NON-NLS-1$
            } else {
                missingJars = missingJars + ", " + jar; //$NON-NLS-1$
            }
        } else {
            if (index != exchange) {
                // exchange
                IClasspathEntry entry = entries[index];
                IClasspathEntry first = entries[exchange];
                entries[index] = first;
                entries[exchange] = entry;
                changesDone = true;
            }
            exchange++;
        }
    }
    if (changesDone) {
        javaProject.setRawClasspath(entries, null);
        javaProject.setOutputLocation(javaProject.getPath().append(JavaUtils.JAVA_CLASSES_DIRECTORY), null);
    }
    if (missingJars != null) {
        handleMissingJarsForProcess(missingJarsForRoutinesOnly, missingJarsForProcessOnly, missingJars);
    }
}