Example usage for org.apache.commons.lang3 StringUtils removeStartIgnoreCase

List of usage examples for org.apache.commons.lang3 StringUtils removeStartIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils removeStartIgnoreCase.

Prototype

public static String removeStartIgnoreCase(final String str, final String remove) 

Source Link

Document

Case insensitive removal of a substring if it is at the beginning of a source string, otherwise returns the source string.

A null source string will return null .

Usage

From source file:com.github.achatain.nopasswordauthentication.utils.AuthorizedServlet.java

protected String extractApiToken(HttpServletRequest req) {
    String authorization = req.getHeader(HttpHeaders.AUTHORIZATION);
    Preconditions.checkArgument(authorization != null, "Missing authorization header");

    String apiToken = StringUtils.removeStartIgnoreCase(authorization, BEARER_PREFIX);
    Preconditions.checkArgument(StringUtils.isNotBlank(apiToken), "Missing api token");

    return StringUtils.trim(apiToken);
}

From source file:eu.usrv.amdiforge.server.GraveAdminCommand.java

private static String stripFilename(String name) {
    return StringUtils.removeEndIgnoreCase(StringUtils.removeStartIgnoreCase(name, PREFIX), ".dat");
}

From source file:com.mirth.connect.plugins.directoryresource.DirectoryResourceServlet.java

@Override
public List<String> getLibraries(String resourceId) {
    try {/*from  w  w  w  .  ja v  a 2  s  .c o  m*/
        DirectoryResourceProperties props = null;
        ResourcePropertiesList resources = serializer.deserialize(configurationController.getResources(),
                ResourcePropertiesList.class);
        for (ResourceProperties resource : resources.getList()) {
            if (resource instanceof DirectoryResourceProperties && resource.getId().equals(resourceId)) {
                props = (DirectoryResourceProperties) resource;
                break;
            }
        }

        List<String> libraries = new ArrayList<String>();

        if (props != null) {
            List<URL> urls = contextFactoryController.getLibraries(props.getId());

            if (StringUtils.isNotBlank(props.getDirectory())) {
                File directory = new File(props.getDirectory());
                for (URL url : urls) {
                    libraries.add(StringUtils.removeStartIgnoreCase(url.toString(),
                            directory.toURI().toURL().toString()));
                }
            } else {
                for (URL url : urls) {
                    libraries.add(url.toString());
                }
            }

            Collections.sort(libraries);
        }

        return libraries;
    } catch (MirthApiException e) {
        throw e;
    } catch (Exception e) {
        throw new MirthApiException(e);
    }
}

From source file:com.netflix.genie.security.oauth2.pingfederate.PingFederateUserAuthenticationConverter.java

/**
 * {@inheritDoc}//from   ww  w.j  av  a  2 s  .  com
 */
//TODO: might be too much unnecessary validation in here
@Override
public Authentication extractAuthentication(final Map<String, ?> map) {
    // Make sure we have a client id to use as the Principle
    if (!map.containsKey(CLIENT_ID_KEY)) {
        throw new InvalidTokenException("No client id key found in map");
    }

    final Object clientIdObject = map.get(CLIENT_ID_KEY);
    if (!(clientIdObject instanceof String)) {
        throw new InvalidTokenException("Client id wasn't string");
    }

    final String userName = (String) clientIdObject;
    if (StringUtils.isBlank(userName)) {
        throw new InvalidTokenException("Client id was blank. Unable to use as user name");
    }

    // Scopes were already validated in PingFederateRemoteTokenServices
    final Object scopeObject = map.get(SCOPE_KEY);
    if (!(scopeObject instanceof Collection)) {
        throw new InvalidTokenException("Scopes were not a collection");
    }

    @SuppressWarnings("unchecked")
    final Collection<String> scopes = (Collection<String>) scopeObject;
    if (scopes.isEmpty()) {
        throw new InvalidTokenException("No scopes available. Unable to authenticate");
    }

    // Default to user role
    final Set<GrantedAuthority> authorities = Sets.newHashSet(USER_AUTHORITY);

    scopes.stream().filter(scope -> scope.contains(GENIE_PREFIX)).distinct()
            .forEach(scope -> authorities.add(new SimpleGrantedAuthority(
                    ROLE_PREFIX + StringUtils.removeStartIgnoreCase(scope, GENIE_PREFIX).toUpperCase())));

    return new UsernamePasswordAuthenticationToken(userName, "N/A", authorities);
}

From source file:com.mirth.connect.server.api.MirthServlet.java

protected void initLogin() {
    if (isUserLoggedIn()) {
        currentUserId = Integer.parseInt(request.getSession().getAttribute(SESSION_USER).toString());
        context = new ServerEventContext(currentUserId);

        try {//  w  w w . j  a v a 2s . c  om
            userHasChannelRestrictions = authorizationController.doesUserHaveChannelRestrictions(currentUserId);

            if (userHasChannelRestrictions) {
                authorizedChannelIds = authorizationController.getAuthorizedChannelIds(currentUserId);
            }
        } catch (ControllerException e) {
            throw new MirthApiException(e);
        }
    } else if (configurationController.isBypasswordEnabled() && isRequestLocal()) {
        /*
         * If user isn't logged in, then only allow the request if it originated locally and the
         * bypassword is given.
         */
        boolean authorized = false;

        try {
            String authHeader = request.getHeader("Authorization");
            if (StringUtils.isNotBlank(authHeader)) {
                authHeader = new String(
                        Base64.decodeBase64(StringUtils.removeStartIgnoreCase(authHeader, "Basic ").trim()),
                        "US-ASCII");
                String[] authParts = StringUtils.split(authHeader, ':');
                if (authParts.length >= 2) {
                    if (StringUtils.equals(authParts[0], BYPASS_USERNAME)
                            && configurationController.checkBypassword(authParts[1])) {
                        authorized = true;
                    }
                }
            }
        } catch (Exception e) {
        }

        if (authorized) {
            context = ServerEventContext.SYSTEM_USER_EVENT_CONTEXT;
            currentUserId = context.getUserId();
            bypassUser = true;
        } else {
            throw new MirthApiException(Status.UNAUTHORIZED);
        }
    } else {
        throw new MirthApiException(Status.UNAUTHORIZED);
    }
}

From source file:com.sonicle.webtop.core.sdk.ServiceManifest.java

private String oasFileToContext(String oasFile) {
    return StringUtils.removeStartIgnoreCase(FilenameUtils.getBaseName(oasFile), "openapi-").toLowerCase();
}

From source file:com.norconex.commons.lang.url.URLNormalizer.java

/**
 * <p>Removes "www." domain name prefix.</p>
 * <code>http://www.example.com/ &rarr; http://example.com/</code>
 * @return this instance//from   w  w  w.  j a va2  s  .c o  m
 */
public URLNormalizer removeWWW() {
    String host = toURI(url).getHost();
    String newHost = StringUtils.removeStartIgnoreCase(host, "www.");
    url = StringUtils.replaceOnce(url, host, newHost);
    return this;
}

From source file:com.mirth.connect.connectors.http.HttpListener.java

private void initComponentsManual() {
    staticResourcesTable.setModel(new RefreshTableModel(StaticResourcesColumn.getNames(), 0) {
        @Override// w  ww . jav  a2 s.  co  m
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
        }
    });

    staticResourcesTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    staticResourcesTable.setRowHeight(UIConstants.ROW_HEIGHT);
    staticResourcesTable.setFocusable(true);
    staticResourcesTable.setSortable(false);
    staticResourcesTable.setOpaque(true);
    staticResourcesTable.setDragEnabled(false);
    staticResourcesTable.getTableHeader().setReorderingAllowed(false);
    staticResourcesTable.setShowGrid(true, true);
    staticResourcesTable.setAutoCreateColumnsFromModel(false);
    staticResourcesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    staticResourcesTable.setRowSelectionAllowed(true);
    staticResourcesTable.setCustomEditorControls(true);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        staticResourcesTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    class ContextPathCellEditor extends TextFieldCellEditor {
        public ContextPathCellEditor() {
            getTextField().setDocument(new MirthFieldConstraints("^\\S*$"));
        }

        @Override
        protected boolean valueChanged(String value) {
            if (StringUtils.isEmpty(value) || value.equals("/")) {
                return false;
            }

            if (value.equals(getOriginalValue())) {
                return false;
            }

            for (int i = 0; i < staticResourcesTable.getRowCount(); i++) {
                if (value.equals(fixContentPath((String) staticResourcesTable.getValueAt(i,
                        StaticResourcesColumn.CONTEXT_PATH.getIndex())))) {
                    return false;
                }
            }

            parent.setSaveEnabled(true);
            return true;
        }

        @Override
        public Object getCellEditorValue() {
            String value = fixContentPath((String) super.getCellEditorValue());
            String baseContextPath = getBaseContextPath();
            if (value.equals(baseContextPath)) {
                return null;
            } else {
                return fixContentPath(StringUtils.removeStartIgnoreCase(value, baseContextPath + "/"));
            }
        }

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
                int column) {
            String resourceContextPath = fixContentPath((String) value);
            setOriginalValue(resourceContextPath);
            getTextField().setText(getBaseContextPath() + resourceContextPath);
            return getTextField();
        }
    }
    ;

    staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTEXT_PATH.getIndex())
            .setCellEditor(new ContextPathCellEditor());
    staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTEXT_PATH.getIndex())
            .setCellRenderer(new DefaultTableCellRenderer() {
                @Override
                protected void setValue(Object value) {
                    super.setValue(getBaseContextPath() + fixContentPath((String) value));
                }
            });

    class ResourceTypeCellEditor extends MirthComboBoxTableCellEditor implements ActionListener {
        private Object originalValue;

        public ResourceTypeCellEditor(JTable table, Object[] items, int clickCount, boolean focusable) {
            super(table, items, clickCount, focusable, null);
            for (ActionListener actionListener : comboBox.getActionListeners()) {
                comboBox.removeActionListener(actionListener);
            }
            comboBox.addActionListener(this);
        }

        @Override
        public boolean stopCellEditing() {
            if (ObjectUtils.equals(getCellEditorValue(), originalValue)) {
                cancelCellEditing();
            } else {
                parent.setSaveEnabled(true);
            }
            return super.stopCellEditing();
        }

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
                int column) {
            originalValue = value;
            return super.getTableCellEditorComponent(table, value, isSelected, row, column);
        }

        @Override
        public void actionPerformed(ActionEvent evt) {
            ((AbstractTableModel) staticResourcesTable.getModel()).fireTableCellUpdated(
                    staticResourcesTable.getSelectedRow(), StaticResourcesColumn.VALUE.getIndex());
            stopCellEditing();
            fireEditingStopped();
        }
    }

    String[] resourceTypes = ResourceType.stringValues();
    staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()).setMinWidth(100);
    staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()).setMaxWidth(100);
    staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex())
            .setCellEditor(new ResourceTypeCellEditor(staticResourcesTable, resourceTypes, 1, false));
    staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex())
            .setCellRenderer(new MirthComboBoxTableCellRenderer(resourceTypes));

    class ValueCellEditor extends AbstractCellEditor implements TableCellEditor {

        private JPanel panel;
        private JLabel label;
        private JTextField textField;
        private String text;
        private String originalValue;

        public ValueCellEditor() {
            panel = new JPanel(new MigLayout("insets 0 1 0 0, novisualpadding, hidemode 3"));
            panel.setBackground(UIConstants.BACKGROUND_COLOR);

            label = new JLabel();
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent evt) {
                    new ValueDialog();
                    stopCellEditing();
                }
            });
            panel.add(label, "grow, pushx, h 19!");

            textField = new JTextField();
            panel.add(textField, "grow, pushx, h 19!");
        }

        @Override
        public boolean isCellEditable(EventObject evt) {
            if (evt == null) {
                return false;
            }
            if (evt instanceof MouseEvent) {
                return ((MouseEvent) evt).getClickCount() >= 2;
            }
            return true;
        }

        @Override
        public Object getCellEditorValue() {
            if (label.isVisible()) {
                return text;
            } else {
                return textField.getText();
            }
        }

        @Override
        public boolean stopCellEditing() {
            if (ObjectUtils.equals(getCellEditorValue(), originalValue)) {
                cancelCellEditing();
            } else {
                parent.setSaveEnabled(true);
            }
            return super.stopCellEditing();
        }

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
                int column) {
            boolean custom = table.getValueAt(row, StaticResourcesColumn.RESOURCE_TYPE.getIndex())
                    .equals(ResourceType.CUSTOM.toString());
            label.setVisible(custom);
            textField.setVisible(!custom);

            panel.setBackground(table.getSelectionBackground());
            label.setBackground(panel.getBackground());
            label.setMaximumSize(new Dimension(table.getColumnModel().getColumn(column).getWidth(), 19));

            String text = (String) value;
            this.text = text;
            originalValue = text;
            label.setText(text);
            textField.setText(text);

            return panel;
        }

        class ValueDialog extends MirthDialog {

            public ValueDialog() {
                super(parent, true);
                setTitle("Custom Value");
                setPreferredSize(new Dimension(600, 500));
                setLayout(new MigLayout("insets 12, novisualpadding, hidemode 3, fill", "", "[grow]7[]"));
                setBackground(UIConstants.BACKGROUND_COLOR);
                getContentPane().setBackground(getBackground());

                final MirthSyntaxTextArea textArea = new MirthSyntaxTextArea();
                textArea.setSaveEnabled(false);
                textArea.setText(text);
                textArea.setBorder(BorderFactory.createEtchedBorder());
                add(textArea, "grow");

                add(new JSeparator(), "newline, grow");

                JPanel buttonPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3"));
                buttonPanel.setBackground(getBackground());

                JButton openFileButton = new JButton("Open File...");
                openFileButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        String content = parent.browseForFileString(null);
                        if (content != null) {
                            textArea.setText(content);
                        }
                    }
                });
                buttonPanel.add(openFileButton);

                JButton okButton = new JButton("OK");
                okButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        text = textArea.getText();
                        label.setText(text);
                        textField.setText(text);
                        staticResourcesTable.getModel().setValueAt(text, staticResourcesTable.getSelectedRow(),
                                StaticResourcesColumn.VALUE.getIndex());
                        parent.setSaveEnabled(true);
                        dispose();
                    }
                });
                buttonPanel.add(okButton);

                JButton cancelButton = new JButton("Cancel");
                cancelButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        dispose();
                    }
                });
                buttonPanel.add(cancelButton);

                add(buttonPanel, "newline, right");

                pack();
                setLocationRelativeTo(parent);
                setVisible(true);
            }
        }
    }
    ;

    staticResourcesTable.getColumnExt(StaticResourcesColumn.VALUE.getIndex())
            .setCellEditor(new ValueCellEditor());

    staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex()).setMinWidth(100);
    staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex()).setMaxWidth(150);
    staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex())
            .setCellEditor(new TextFieldCellEditor() {
                @Override
                protected boolean valueChanged(String value) {
                    if (value.equals(getOriginalValue())) {
                        return false;
                    }
                    parent.setSaveEnabled(true);
                    return true;
                }
            });

    staticResourcesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (getSelectedRow(staticResourcesTable) != -1) {
                staticResourcesLastIndex = getSelectedRow(staticResourcesTable);
                staticResourcesDeleteButton.setEnabled(true);
            } else {
                staticResourcesDeleteButton.setEnabled(false);
            }
        }
    });

    contextPathField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent evt) {
            changedUpdate(evt);
        }

        @Override
        public void removeUpdate(DocumentEvent evt) {
            changedUpdate(evt);
        }

        @Override
        public void changedUpdate(DocumentEvent evt) {
            ((AbstractTableModel) staticResourcesTable.getModel()).fireTableDataChanged();
        }
    });

    staticResourcesDeleteButton.setEnabled(false);
}

From source file:net.sourceforge.pmd.renderers.CodeClimateRenderer.java

private CodeClimateIssue.Location getLocation(RuleViolation rv) {
    CodeClimateIssue.Location result;

    String pathWithoutCcRoot = StringUtils.removeStartIgnoreCase(rv.getFilename(), "/code/");

    if (rule.hasDescriptor(CODECLIMATE_REMEDIATION_MULTIPLIER)
            && !rule.getProperty(CODECLIMATE_BLOCK_HIGHLIGHTING)) {
        result = new CodeClimateIssue.Location(pathWithoutCcRoot, rv.getBeginLine(), rv.getBeginLine());
    } else {/* w ww.  ja  v a  2s . c o  m*/
        result = new CodeClimateIssue.Location(pathWithoutCcRoot, rv.getBeginLine(), rv.getEndLine());
    }

    return result;
}

From source file:nz.net.orcon.kanban.tools.ComplexDateConverter.java

protected String removeToday(String stringIn) {
    return StringUtils.removeStartIgnoreCase(stringIn, TODAY);
}