Example usage for org.apache.commons.lang StringUtils replaceOnce

List of usage examples for org.apache.commons.lang StringUtils replaceOnce

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils replaceOnce.

Prototype

public static String replaceOnce(String text, String searchString, String replacement) 

Source Link

Document

Replaces a String with another String inside a larger String, once.

Usage

From source file:com.taobao.itest.util.XlsUtil.java

/**
 * Eventually converted into a unified type path: classpath :***, to the
 * Spring to solve/*  w ww . j  ava 2 s .c  o m*/
 * 
 * @param execlDir
 * @return
 */
private static String getExcelRealPath(String execlDir) {
    if (StringUtils.isBlank(execlDir)) {
        throw new IllegalArgumentException("Excel file path must be clearly specified!");
    } else if (execlDir.startsWith("classpath:")) {
        return execlDir;
    } else if (execlDir.startsWith("/")) {
        return StringUtils.replaceOnce(execlDir, "/", "classpath:");
    } else {
        String testClass = getTestClassPackage();
        if (null == testClass) {
            // Call the test class not found
            throw new IllegalArgumentException(
                    "There are some errors in method invode.Please check StackTrace.");
        }

        return StringUtils
                .join(new String[] { "classpath:", StringUtils.replace(testClass, ".", "/"), "/", execlDir });
    }
}

From source file:com.liferay.sync.engine.service.SyncAccountService.java

public static SyncAccount setFilePathName(long syncAccountId, String targetFilePathName) {

    // Sync account

    SyncAccount syncAccount = fetchSyncAccount(syncAccountId);

    String sourceFilePathName = syncAccount.getFilePathName();

    syncAccount.setFilePathName(targetFilePathName);

    update(syncAccount);//from   w  w w.j  a  va 2 s.  com

    // Sync file

    SyncFile syncFile = SyncFileService.fetchSyncFile(sourceFilePathName);

    syncFile.setFilePathName(targetFilePathName);

    SyncFileService.update(syncFile);

    // Sync files

    if (syncFile.isFolder()) {
        SyncFileService.renameSyncFiles(sourceFilePathName, targetFilePathName);
    }

    // Sync sites

    FileSystem fileSystem = FileSystems.getDefault();

    List<SyncSite> syncSites = SyncSiteService.findSyncSites(syncAccountId);

    for (SyncSite syncSite : syncSites) {
        String syncSiteFilePathName = syncSite.getFilePathName();

        syncSiteFilePathName = StringUtils.replaceOnce(syncSiteFilePathName,
                sourceFilePathName + fileSystem.getSeparator(), targetFilePathName + fileSystem.getSeparator());

        syncSite.setFilePathName(syncSiteFilePathName);

        SyncSiteService.update(syncSite);
    }

    return syncAccount;
}

From source file:com.hangum.tadpole.rdb.core.dialog.export.sqltoapplication.composites.axisj.AxisjComposite.java

private void refreshBrowser() {
    try {//from   w  w w .  jav a 2s.  c o m
        String STR_PREVIEW_TEMPLATE = IOUtils.toString(AxisjConsts.class.getResource("AXISJ.PREVIEW.html"));

        STR_PREVIEW_TEMPLATE = StringUtils.replaceOnce(STR_PREVIEW_TEMPLATE, "_TDB_TEMPLATE_TITLE_",
                textVariable.getText());
        STR_PREVIEW_TEMPLATE = StringUtils.replaceOnce(STR_PREVIEW_TEMPLATE, "_AXISJ_JS_BLOCK_",
                textConvert.getText());

        browserPreview.setText(STR_PREVIEW_TEMPLATE);
    } catch (IOException e1) {
        logger.error("AXISJ preview exception", e1);
    }
}

From source file:eionet.cr.web.util.JstlFunctions.java

/**
 *
 * @param stackTrace/*  w  ww  . ja  v  a2s  .com*/
 * @return
 */
public static String formatStackTrace(String stackTrace) {

    if (stackTrace == null || stackTrace.trim().length() == 0) {
        return stackTrace;
    }

    StringBuilder buf = new StringBuilder();
    StringTokenizer lines = new StringTokenizer(stackTrace, "\r\n");
    while (lines != null && lines.hasMoreElements()) {
        String line = lines.nextToken();
        line = StringUtils.replaceOnce(line, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
        buf.append(line).append("<br/>");
    }

    return buf.length() == 0 ? stackTrace : buf.toString();
}

From source file:com.hangum.tadpole.rdb.core.actions.oracle.TableSapceManageEditor.java

@Override
public void createPartControl(Composite parent) {
    GridLayout gl_parent = new GridLayout(1, false);
    gl_parent.verticalSpacing = 1;/*from   w ww.  j  a  va  2s . com*/
    gl_parent.marginHeight = 1;
    gl_parent.horizontalSpacing = 1;
    gl_parent.marginWidth = 1;
    parent.setLayout(gl_parent);

    Composite compositeToolbar = new Composite(parent, SWT.NONE);
    compositeToolbar.setLayout(new GridLayout(2, false));
    compositeToolbar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    ToolBar toolBar = new ToolBar(compositeToolbar, SWT.FLAT | SWT.RIGHT);
    GridData gd_toolBar = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_toolBar.widthHint = 267;
    toolBar.setLayoutData(gd_toolBar);

    ToolItem tltmRefresh = new ToolItem(toolBar, SWT.NONE);
    tltmRefresh.setToolTipText(CommonMessages.get().Refresh);
    tltmRefresh.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/refresh.png")); //$NON-NLS-1$

    tltmRefresh.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            refreshTablespaceList();
        }
    });

    lblDbname = new Label(compositeToolbar, SWT.NONE);
    lblDbname.setText(""); //$NON-NLS-1$

    columnFilter = new DefaultTableColumnFilter();

    Composite compositeTablespaceList = new Composite(parent, SWT.NONE);
    GridData gd_compositeTablespaceList = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_compositeTablespaceList.minimumHeight = 200;
    compositeTablespaceList.setLayoutData(gd_compositeTablespaceList);
    compositeTablespaceList.setLayout(new GridLayout(1, false));

    tableViewer = new TableViewer(compositeTablespaceList, SWT.BORDER | SWT.FULL_SELECTION);
    Table tableTablespace = tableViewer.getTable();
    tableTablespace.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    tableTablespace.setHeaderVisible(true);
    tableTablespace.setLinesVisible(true);
    tableViewer.addFilter(columnFilter);

    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (tableViewer.getSelection().isEmpty()) {
                return;
            }

            StructuredSelection ss = (StructuredSelection) tableViewer.getSelection();
            tablespaceDao = (OracleTablespaceDAO) ss.getFirstElement();

            List<HashMap<String, String>> datafileList = new ArrayList<HashMap<String, String>>();
            try {

                SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
                datafileList = (List<HashMap<String, String>>) sqlClient
                        .queryForList("getTablespaceDataFileList", tablespaceDao.getTablespace_name()); //$NON-NLS-1$

            } catch (Exception e) {
                logger.error("Tablespace detail information loading...", e); //$NON-NLS-1$
            }

            textDropScript.setText(StringUtils.trimToEmpty(getDropScript()));
            makeCreateScript();

            tableViewer_datafiles.setInput(datafileList);
            tableViewer_datafiles.refresh();

            if (datafileList.size() > 0) {
                tableViewer_datafiles
                        .setSelection(new StructuredSelection(tableViewer_datafiles.getElementAt(0)), true);

                refreshDatafileInformation();
            } else {
                // ?? ??  ??  .
                tableViewer_property.setInput(new ArrayList<Map<String, String>>());
                tableViewer_property.refresh();
            }
        }
    });

    Group grpQuery = new Group(parent, SWT.NONE);
    grpQuery.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    grpQuery.setText("Detail Information");
    GridLayout gl_grpQuery = new GridLayout(1, false);
    gl_grpQuery.verticalSpacing = 1;
    gl_grpQuery.horizontalSpacing = 1;
    gl_grpQuery.marginHeight = 1;
    gl_grpQuery.marginWidth = 1;
    grpQuery.setLayout(gl_grpQuery);

    Composite composite = new Composite(grpQuery, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    composite.setLayout(new FillLayout(SWT.HORIZONTAL));

    SashForm sashForm = new SashForm(composite, SWT.NONE);

    SashForm sashForm_1 = new SashForm(sashForm, SWT.VERTICAL);

    Composite composite_2 = new Composite(sashForm_1, SWT.BORDER);
    GridLayout gl_composite_2 = new GridLayout(1, false);
    gl_composite_2.verticalSpacing = 0;
    gl_composite_2.horizontalSpacing = 0;
    gl_composite_2.marginHeight = 0;
    gl_composite_2.marginWidth = 0;
    composite_2.setLayout(gl_composite_2);

    tableViewer_datafiles = new TableViewer(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
    table_datafiles = tableViewer_datafiles.getTable();
    table_datafiles.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    table_datafiles.setLinesVisible(true);
    table_datafiles.setHeaderVisible(true);

    tableViewer_datafiles.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (tableViewer_datafiles.getSelection().isEmpty()) {
                return;
            }
            refreshDatafileInformation();
            makeCreateScript();
        }
    });

    Composite composite_6 = new Composite(composite_2, SWT.NONE);
    composite_6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout gl_composite_6 = new GridLayout(2, false);
    composite_6.setLayout(gl_composite_6);

    btnDatafileName = new Button(composite_6, SWT.CHECK);
    btnDatafileName.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            textDataFileName.setEnabled(btnDatafileName.getSelection());
            if (btnDatafileName.getSelection()) {
                StructuredSelection ss = (StructuredSelection) tableViewer_datafiles.getSelection();
                if (ss != null) {
                    HashMap<String, Object> datafileMap = (HashMap<String, Object>) ss.getFirstElement();
                    String fileName = (String) datafileMap.get("FILE_NAME");

                    int cnt = tableViewer_datafiles.getTable().getItemCount() + 1;

                    fileName = StringUtils.replaceOnce(fileName, ".", "_Copy" + cnt + ".");
                    textDataFileName.setText(fileName);
                } else {
                    textDataFileName.setFocus();
                }
            }
            makeAddDatafileScript();
        }
    });
    btnDatafileName.setText("Datafile Name");
    textDataFileName = new Text(composite_6, SWT.BORDER | SWT.V_SCROLL | SWT.SINGLE);
    textDataFileName.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent event) {
            makeAddDatafileScript();
        }
    });
    textDataFileName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textDataFileName.setText("Auto");
    textDataFileName.setEnabled(false);

    Label lblNewLabel_2 = new Label(composite_6, SWT.NONE);
    lblNewLabel_2.setText("Datafile Size(MB)");

    Composite composite_7 = new Composite(composite_6, SWT.NONE);
    GridLayout gl_composite_7 = new GridLayout(2, false);
    gl_composite_7.verticalSpacing = 0;
    gl_composite_7.horizontalSpacing = 0;
    gl_composite_7.marginWidth = 0;
    gl_composite_7.marginHeight = 0;
    composite_7.setLayout(gl_composite_7);

    textDatafileSize = new Text(composite_7, SWT.BORDER | SWT.RIGHT);
    textDatafileSize.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent event) {
            makeAddDatafileScript();
        }
    });
    GridData gd_textDatafileSize = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_textDatafileSize.widthHint = 60;
    textDatafileSize.setLayoutData(gd_textDatafileSize);
    textDatafileSize.setText("5");

    btnReuse = new Button(composite_7, SWT.CHECK);
    btnReuse.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            makeAddDatafileScript();
        }
    });
    btnReuse.setText("Reuse");

    Composite composite_5 = new Composite(composite_2, SWT.NONE);
    composite_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    composite_5.setLayout(new GridLayout(4, false));

    btnAutoExtend = new Button(composite_5, SWT.CHECK);
    btnAutoExtend.setSelection(true);
    btnAutoExtend.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            textAutoExtendSize.setEnabled(btnAutoExtend.getSelection());
            btnMaximumSize.setEnabled(btnAutoExtend.getSelection());
            textMaximumSize.setEnabled(btnAutoExtend.getSelection());

            makeAddDatafileScript();
        }
    });
    btnAutoExtend.setText("Auto Extend");

    Label lblExtendSize = new Label(composite_5, SWT.NONE);
    lblExtendSize.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblExtendSize.setText("Extend Size(MB)");

    textAutoExtendSize = new Text(composite_5, SWT.BORDER | SWT.RIGHT);
    textAutoExtendSize.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent event) {
            makeAddDatafileScript();
        }
    });
    textAutoExtendSize.setText("5");
    textAutoExtendSize.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(composite_5, SWT.NONE);

    btnMaximumSize = new Button(composite_5, SWT.CHECK);
    btnMaximumSize.setSelection(true);
    btnMaximumSize.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            textMaximumSize.setEnabled(!btnMaximumSize.getSelection());
            textMaximumSize.setText((1024 * 5) + ""); //5GB
            textMaximumSize.setFocus();
            textMaximumSize.setSelection(0, textMaximumSize.getText().length());
            makeAddDatafileScript();
        }
    });
    btnMaximumSize.setText("Maximum Unlimited");

    Label lblMaximumSizemb = new Label(composite_5, SWT.NONE);
    lblMaximumSizemb.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblMaximumSizemb.setText("Maximum Size(MB)");

    textMaximumSize = new Text(composite_5, SWT.BORDER | SWT.RIGHT);
    textMaximumSize.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent event) {
            makeAddDatafileScript();
        }
    });
    textMaximumSize.setEnabled(false);
    textMaximumSize.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Button btnAddDatafile = new Button(composite_5, SWT.NONE);
    btnAddDatafile.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            makeAddDatafileScript();
        }
    });
    btnAddDatafile.setText("Add Datafile");

    tableViewer_property = new TableViewer(sashForm_1, SWT.BORDER | SWT.FULL_SELECTION);
    table = tableViewer_property.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);

    TableViewerColumn tvPropertyName = new TableViewerColumn(tableViewer_property, SWT.NONE);
    TableColumn tcPropertyName = tvPropertyName.getColumn();
    tcPropertyName.setWidth(180);
    tcPropertyName.setText("Property");

    TableViewerColumn tvPropertyValue = new TableViewerColumn(tableViewer_property, SWT.NONE);
    TableColumn tcPropertyValue = tvPropertyValue.getColumn();
    tcPropertyValue.setWidth(300);
    tcPropertyValue.setText("Value");

    tableViewer_property.setContentProvider(new ArrayContentProvider());
    tableViewer_property.setLabelProvider(new TablespaceExtInfoLabelProvider());
    sashForm_1.setWeights(new int[] { 1, 1 });

    Composite composite_1 = new Composite(sashForm, SWT.BORDER);
    composite_1.setLayout(new GridLayout(1, false));

    Label lblNewLabel_1 = new Label(composite_1, SWT.NONE);
    lblNewLabel_1.setText("Drop Tablespace");

    textDropScript = new Text(composite_1, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
    textDropScript.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
    GridData gd_textDropScript = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_textDropScript.minimumHeight = 20;
    textDropScript.setLayoutData(gd_textDropScript);

    Composite composite_4 = new Composite(composite_1, SWT.NONE);
    composite_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    composite_4.setLayout(new GridLayout(3, false));

    btnIncludingContents = new Button(composite_4, SWT.CHECK);
    btnIncludingContents.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // ?? ??  .
            btnCascadeConstraints.setEnabled(btnIncludingContents.getSelection());
            textDropScript.setText(getDropScript());
        }
    });
    btnIncludingContents.setText("Including Contents?");

    btnCascadeConstraints = new Button(composite_4, SWT.CHECK);
    btnCascadeConstraints.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // ?  .
            textDropScript.setText(getDropScript());
        }
    });
    btnCascadeConstraints.setEnabled(false);
    btnCascadeConstraints.setText("Cascade Constraints?");

    Button btnDrop = new Button(composite_4, SWT.NONE);
    btnDrop.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            //Excute script
            RequestResultDAO reqReResultDAO = new RequestResultDAO();
            try {
                ExecuteDDLCommand.executSQL(userDB, reqReResultDAO, textDropScript.getText().trim());
            } catch (Exception ex) {
                logger.error(ex);
            } //$NON-NLS-1$
            if (PublicTadpoleDefine.SUCCESS_FAIL.F.name().equals(reqReResultDAO.getResult())) {
                MessageDialog.openError(getSite().getShell(), CommonMessages.get().Error,
                        Messages.get().RiseError + reqReResultDAO.getMesssage()
                                + reqReResultDAO.getException().getMessage());
            } else {
                MessageDialog.openInformation(getSite().getShell(), CommonMessages.get().Information,
                        Messages.get().WorkHasCompleted);
                refreshTablespaceList();
            }

        }
    });
    btnDrop.setSize(94, 28);
    btnDrop.setText("Drop Tablespace");

    Label lblNewLabel = new Label(composite_1, SWT.NONE);
    lblNewLabel.setText("Create Tablespace && Add Datafile");

    textScript = new Text(composite_1, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    textScript.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Composite composite_3 = new Composite(composite_1, SWT.NONE);
    composite_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

    Button btnExecute = new Button(composite_3, SWT.NONE);
    btnExecute.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            //Excute script
            RequestResultDAO reqReResultDAO = new RequestResultDAO();
            try {
                ExecuteDDLCommand.executSQL(userDB, reqReResultDAO, textScript.getText().trim());
            } catch (Exception ex) {
                logger.error(ex);
            } //$NON-NLS-1$
            if (PublicTadpoleDefine.SUCCESS_FAIL.F.name().equals(reqReResultDAO.getResult())) {
                MessageDialog.openError(getSite().getShell(), CommonMessages.get().Error,
                        Messages.get().RiseError + reqReResultDAO.getMesssage()
                                + reqReResultDAO.getException().getMessage());
            } else {
                MessageDialog.openInformation(getSite().getShell(), CommonMessages.get().Information,
                        Messages.get().WorkHasCompleted);
                refreshTablespaceList();
                refreshDatafileInformation();
            }
        }
    });
    btnExecute.setBounds(0, 0, 150, 28);
    btnExecute.setText("Execute Script");
    sashForm.setWeights(new int[] { 1, 1 });

    createTableColumn();
    createTableDataFileColumn();

    initUI();

}

From source file:edu.mayo.cts2.framework.webapp.rest.controller.ValueSetDefinitionController.java

@RequestMapping(value = { PATH_VALUESETBYID + "/" + VALUE_SET_RESOLUTION_SHORT + "/" + ALL_WILDCARD,
        PATH_VALUESETBYID + "/" + VALUE_SET_RESOLUTION_SHORT }, method = RequestMethod.GET)
public ModelAndView getValueSetDefinitionOfValueSetByTagRedirect(HttpServletRequest httpServletRequest,
        RestReadContext restReadContext, QueryControl queryControl,
        @PathVariable(VAR_VALUESETID) String valueSetName,
        @RequestParam(value = PARAM_TAG, defaultValue = DEFAULT_TAG) String tag,
        @RequestParam(value = "redirect", defaultValue = DEFAULT_REDIRECT) boolean redirect) {

    //TODO: Accept tag URIs here
    VersionTagReference tagReference = new VersionTagReference(tag);

    String valueSetDefinitionLocalId = this.tagResolver.getVersionNameFromTag(
            this.valueSetDefinitionReadService, ModelUtils.nameOrUriFromName(valueSetName), tagReference,
            this.resolveRestReadContext(restReadContext));

    String contextPath = this.getUrlPathHelper().getContextPath(httpServletRequest);

    String requestUri = StringUtils.removeStart(this.getUrlPathHelper().getRequestUri(httpServletRequest),
            contextPath);//from   w w w .j a va  2  s.com

    requestUri = StringUtils.removeStart(requestUri, "/");

    requestUri = StringUtils.replaceOnce(requestUri, VALUESET + "/" + valueSetName + "/", VALUESET + "/"
            + valueSetName + "/" + VALUESETDEFINITION_SHORT + "/" + valueSetDefinitionLocalId + "/");

    if (redirect) {
        @SuppressWarnings("unchecked")
        Map<String, Object> parameters = new HashMap<String, Object>(httpServletRequest.getParameterMap());

        parameters.remove(PARAM_REDIRECT);

        return new ModelAndView("redirect:" + "/" + requestUri + this.mapToQueryString(parameters));
    } else {
        return new ModelAndView("forward:" + "/" + requestUri);
    }
}

From source file:edu.mayo.cts2.framework.webapp.rest.controller.CodeSystemVersionController.java

@RequestMapping(value = { PATH_CODESYSTEMBYID + "/" + ENTITY + "/" + ALL_WILDCARD,
        PATH_CODESYSTEMBYID + "/" + ENTITIES }, method = RequestMethod.GET)
public ModelAndView getCodeSystemVersionOfCodeSystemByTagRedirect(HttpServletRequest httpServletRequest,
        RestReadContext restReadContext, QueryControl queryControl,
        @PathVariable(VAR_CODESYSTEMID) String codeSystemName,
        @RequestParam(value = PARAM_TAG, defaultValue = DEFAULT_TAG) String tag,
        @RequestParam(value = "redirect", defaultValue = DEFAULT_REDIRECT) boolean redirect) {

    //TODO: Accept tag URIs here
    VersionTagReference tagReference = new VersionTagReference(tag);

    String codeSystemVersionName = this.codeSystemVersionNameResolver.getVersionNameFromTag(
            codeSystemVersionReadService, ModelUtils.nameOrUriFromName(codeSystemName), tagReference,
            this.resolveRestReadContext(restReadContext));

    String contextPath = this.getUrlPathHelper().getContextPath(httpServletRequest);

    String requestUri = StringUtils.removeStart(this.getUrlPathHelper().getRequestUri(httpServletRequest),
            contextPath);//w  w  w  .  ja  v a 2s .co m

    requestUri = StringUtils.removeStart(requestUri, "/");

    requestUri = StringUtils.replaceOnce(requestUri, CODESYSTEM + "/" + codeSystemName + "/",
            CODESYSTEM + "/" + codeSystemName + "/" + VERSION + "/" + codeSystemVersionName + "/");

    if (redirect) {
        @SuppressWarnings("unchecked")
        Map<String, Object> parameters = new HashMap<String, Object>(httpServletRequest.getParameterMap());

        parameters.remove(PARAM_REDIRECT);

        return new ModelAndView("redirect:" + "/" + requestUri + this.mapToQueryString(parameters));
    } else {
        return new ModelAndView("forward:" + "/" + requestUri);
    }
}

From source file:com.impetus.ankush.common.dao.impl.GenericDaoJpa.java

/**
 * Convert to count query./*ww w  .j av a 2 s  .co m*/
 * 
 * @param query
 *            the query
 * @return the string
 */
private String convertToCountQuery(String query) {
    Pattern pattern = Pattern.compile("select(.+)from");
    Matcher matcher = pattern.matcher(query);
    if (matcher.find()) {
        String s = matcher.group(1).trim();
        query = StringUtils.replaceOnce(query, s, "count(" + s + ")");
    }
    return query;
}

From source file:com.google.gdt.eclipse.designer.wizards.model.mvp.ViewComposite.java

private void validateNames() {
    String newViewName = viewField.getText();
    // extract template
    {//from  w  w w  .  j  a  v a2  s.co  m
        if (StringUtils.endsWith(newViewName, "View")) {
            newViewName = StringUtils.replace(newViewName, "View", "");
        } else if (StringUtils.endsWith(newViewName, "Composite")) {
            newViewName = StringUtils.replace(newViewName, "Composite", "");
        } else if (StringUtils.endsWith(newViewName, "Frame")) {
            newViewName = StringUtils.replace(newViewName, "Frame", "");
        }
    }
    if (StringUtils.isEmpty(oldViewName)) {
        placeNameField.setTextWithoutUpdate(newViewName + placeNameField.getText());
        activityNameField.setTextWithoutUpdate(newViewName + activityNameField.getText());
    } else {
        placeNameField.setTextWithoutUpdate(
                StringUtils.replaceOnce(placeNameField.getText(), oldViewName, newViewName));
        activityNameField.setTextWithoutUpdate(
                StringUtils.replaceOnce(activityNameField.getText(), oldViewName, newViewName));
    }
    oldViewName = newViewName;
    // enabled fields
    placeNameField.setEnabled(placeField.getSelection());
    activityNameField.setEnabled(activityField.getSelection());
    factoryField.setEnabled(activityField.getSelection());
    factoryNameField.setEnabled(factoryField.isEnabled() && factoryField.getSelection());
}

From source file:com.google.gdt.eclipse.designer.wizards.model.mvp.ViewComposite.java

/**
 * Generate possible variants package name templates.
 *///w  ww . j  a va 2 s  . co  m
private static List<String> generatePackageNameTemplates(String packageName, String rootSourcePackageName) {
    // initial names as sub-packages 
    List<String> templatePackageNames = Lists.newArrayList(packageName + ".%keyName%");
    // generate names as 'view'-template
    {
        final String[] searchingViewsTemplates = new String[] { ".view", ".views", ".ui", ".uis" };
        String subPath = StringUtils.replace(packageName, rootSourcePackageName, "");
        for (String searchingViewTemplate : searchingViewsTemplates) {
            if (StringUtils.indexOfIgnoreCase(subPath, searchingViewTemplate) != -1) {
                templatePackageNames.add(rootSourcePackageName
                        + StringUtils.replaceOnce(subPath, searchingViewTemplate, ".%keyName%"));
            }
        }
    }
    // generate names in parent 
    {
        String parentPackageName = CodeUtils.getPackage(packageName);
        while (parentPackageName.length() >= rootSourcePackageName.length()) {
            templatePackageNames.add(parentPackageName + ".%keyName%");
            parentPackageName = CodeUtils.getPackage(parentPackageName);
        }
    }
    return templatePackageNames;
}