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

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

Introduction

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

Prototype

public static String substringAfterLast(String str, String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:org.eclipse.smarthome.binding.digitalstrom.internal.lib.serverconnection.impl.HttpTransportImpl.java

private boolean checkNeededSessionToken(String request) {
    String functionName = StringUtils.substringAfterLast(StringUtils.substringBefore(request, "?"), "/");
    return !DsAPIImpl.METHODS_MUST_NOT_BE_LOGGED_IN.contains(functionName);
}

From source file:org.eclipse.smarthome.binding.homematic.internal.type.HomematicTypeGeneratorImpl.java

/**
 * Creates the ThingType for the given device.
 *///from w  w  w .  ja v  a 2s  . c om
private ThingType createThingType(HmDevice device, List<ChannelGroupType> groupTypes) {
    String label = MetadataUtils.getDeviceName(device);
    String description = String.format("%s (%s)", label, device.getType());

    List<String> supportedBridgeTypeUids = new ArrayList<String>();
    supportedBridgeTypeUids.add(THING_TYPE_BRIDGE.toString());
    ThingTypeUID thingTypeUID = UidUtils.generateThingTypeUID(device);

    Map<String, String> properties = new HashMap<String, String>();
    properties.put(Thing.PROPERTY_VENDOR, PROPERTY_VENDOR_NAME);
    properties.put(Thing.PROPERTY_MODEL_ID, device.getType());

    URI configDescriptionURI = getConfigDescriptionURI(device);
    if (configDescriptionProvider.getInternalConfigDescription(configDescriptionURI) == null) {
        generateConfigDescription(device, configDescriptionURI);
    }

    List<ChannelGroupDefinition> groupDefinitions = new ArrayList<ChannelGroupDefinition>();
    for (ChannelGroupType groupType : groupTypes) {
        String id = StringUtils.substringAfterLast(groupType.getUID().getId(), "_");
        groupDefinitions.add(new ChannelGroupDefinition(id, groupType.getUID()));
    }

    return ThingTypeBuilder.instance(thingTypeUID, label).withSupportedBridgeTypeUIDs(supportedBridgeTypeUids)
            .withDescription(description).withChannelGroupDefinitions(groupDefinitions)
            .withProperties(properties).withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER)
            .withConfigDescriptionURI(configDescriptionURI).build();
}

From source file:org.eclipse.smarthome.binding.ntp.test.NtpOSGiTest.java

private String getStringChannelTimeZoneFromItemRegistry() {
    String itemState = getItemState(ACCEPTED_ITEM_TYPE_STRING).toString();
    /*//from  ww  w. j  a v  a 2  s  .  c  o m
     * This method is used only in tests for the string channel,
     * where we have set the format for the date in advance.
     * Because of that format, we know that the time zone will be the
     * last word of the string from the item registry.
     */
    // FIXME: This can happen a lot easier with Java 8 date time API, so tests can be adapted, if there is an
    // upgrade to Java 8
    String timeZoneFromItemRegistry = StringUtils.substringAfterLast(itemState, " ");
    return timeZoneFromItemRegistry;
}

From source file:org.eclipse.smarthome.core.audio.internal.AudioServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    removeTimedOutStreams();/*from w ww  .  j  a va  2s . c  o  m*/

    final String streamId = StringUtils
            .substringBefore(StringUtils.substringAfterLast(req.getRequestURI(), "/"), ".");

    try (final InputStream stream = prepareInputStream(streamId, resp)) {
        if (stream == null) {
            logger.debug("Received request for invalid stream id at {}", req.getRequestURI());
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        } else {
            IOUtils.copy(stream, resp.getOutputStream());
            resp.flushBuffer();
        }
    } catch (final AudioException ex) {
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}

From source file:org.eclipse.smarthome.ui.icon.internal.AbstractResourceIconProviderTest.java

@Before
public void setUp() {

    provider = new AbstractResourceIconProvider() {
        @Override//  w w  w  . ja v a  2 s. co m
        protected InputStream getResource(String iconset, String resourceName) {
            switch (resourceName) {
            case "x-30.png":
                return new ByteArrayInputStream("x-30.png".getBytes());
            case "x-y z.png":
                return new ByteArrayInputStream("x-y z.png".getBytes());
            default:
                return null;
            }
        }

        @Override
        protected boolean hasResource(String iconset, String resourceName) {
            String state = StringUtils.substringAfterLast(resourceName, "-");
            state = StringUtils.substringBeforeLast(state, ".");
            return state.equals("30") || state.equals("y z");
        };

        @Override
        public Set<IconSet> getIconSets(Locale locale) {
            return Collections.emptySet();
        };

        @Override
        public Integer getPriority() {
            return 0;
        };
    };
}

From source file:org.eclipse.smarthome.ui.icon.internal.IconServlet.java

private String getCategory(HttpServletRequest req) {
    String category = StringUtils.substringAfterLast(req.getRequestURI(), "/");
    category = StringUtils.substringBeforeLast(category, ".");
    return StringUtils.substringBeforeLast(category, "-");
}

From source file:org.eclipse.smarthome.ui.icon.internal.IconServlet.java

private Format getFormat(HttpServletRequest req) {
    String format = req.getParameter(PARAM_FORMAT);
    if (format == null) {
        String filename = StringUtils.substringAfterLast(req.getRequestURI(), "/");
        format = StringUtils.substringAfterLast(filename, ".");
    }//from   w  w w.ja  va  2  s  . c  o  m
    try {
        Format f = Format.valueOf(format.toUpperCase());
        return f;
    } catch (IllegalArgumentException e) {
        logger.debug("unknown format '{}' in HTTP request - falling back to PNG", format);
        return Format.PNG;
    }
}

From source file:org.eclipse.smarthome.ui.icon.internal.IconServlet.java

private String getState(HttpServletRequest req) {
    String state = req.getParameter(PARAM_STATE);
    if (state != null) {
        return state;
    } else {/* ww w.ja  v  a2s. co  m*/
        String filename = StringUtils.substringAfterLast(req.getRequestURI(), "/");
        state = StringUtils.substringAfterLast(filename, "-");
        state = StringUtils.substringBeforeLast(state, ".");
        if (StringUtils.isNotEmpty(state)) {
            return state;
        } else {
            return null;
        }
    }
}

From source file:org.eclipse.wb.android.internal.support.resources.ui.ResourceDialog.java

private void createResourceTreeGroup(Composite container) {
    {//w w  w. jav  a2  s. co m
        Group grpResources = new Group(container, SWT.NONE);
        GridLayoutFactory.create(grpResources);
        GridDataFactory.create(grpResources).fill().spanV(2).grabH();
        grpResources.setText("Resources:");
        Composite composite = new Composite(grpResources, SWT.NONE);
        GridLayoutFactory.create(composite).noMargins().noSpacing().columns(2);
        GridDataFactory.create(composite).fill().grabH();
        //
        Label lblNewLabel = new Label(composite, SWT.NONE);
        GridDataFactory.create(lblNewLabel).alignHR().alignVM();
        lblNewLabel.setText("Filter:");
        // search text
        final Text filterText = new Text(composite, SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL);
        GridDataFactory.create(filterText).alignHC().grabH().fill();
        filterText.addListener(SWT.FocusIn, new Listener() {
            public void handleEvent(Event event) {
                filterText.selectAll();
            }
        });
        filterText.addModifyListener(new ModifyListener() {
            private Timer timer;

            public void modifyText(ModifyEvent e) {
                final String filterString = filterText.getText();
                m_filter.setResourcePrefix(filterString);
                // schedule update
                if (timer != null) {
                    timer.cancel();
                }
                timer = new Timer();
                timer.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        DesignerPlugin.getStandardDisplay().asyncExec(new Runnable() {
                            public void run() {
                                m_resourcesTreeViewer.refresh();
                                if (!StringUtils.isEmpty(filterString)) {
                                    m_resourcesTreeViewer.expandAll();
                                }
                            }
                        });
                    }
                }, 250);
            }
        });
        filterText.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                if (e.detail == SWT.ICON_CANCEL) {
                    filterText.setText("");
                }
            }
        });
        filterText.addKeyListener(new KeyListener() {
            public void keyReleased(KeyEvent e) {
                if (e.keyCode == SWT.ARROW_DOWN) {
                    m_resourcesTreeViewer.getTree().setFocus();
                }
            }

            public void keyPressed(KeyEvent e) {
            }
        });
        if (!StringUtils.isEmpty(m_referenceValue)) {
            String resourceName = StringUtils.substringAfterLast(m_referenceValue, "/");
            filterText.setText(resourceName);
        }
        // resource tree
        m_resourcesTreeViewer = new TreeViewer(grpResources, SWT.BORDER | SWT.SINGLE);
        Tree tree = m_resourcesTreeViewer.getTree();
        GridDataFactory.create(tree).fill().grab().hintHC(40).hintVC(20);
        // all listeners
        m_resourcesTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                m_referenceValue = getReferenceValue((TreeSelection) m_resourcesTreeViewer.getSelection());
                // update OK button
                getButton(IDialogConstants.OK_ID).setEnabled(m_referenceValue != null);
            }
        });
        m_resourcesTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                if (m_referenceValue != null) {
                    okPressed();
                }
            }
        });
        // setup
        m_resourcesTreeViewer.setContentProvider(new ResourceContentProvider());
        m_resourcesTreeViewer.setLabelProvider(new ResourceLabelProvider());
        m_resourcesTreeViewer.addFilter(m_filter);
        // set focus to filter
        filterText.setFocus();
    }
}

From source file:org.eclipse.wb.internal.core.gef.policy.layout.generic.SelectionEditPolicyInstaller.java

/**
 * Loads policy {@link Class} from given package and its parents.
 *///from  www  .j  ava 2s . c o  m
private Class<?> loadClass(String basePackageName) {
    // name, based on container Class name
    String containerName;
    {
        containerName = StringUtils.substringAfterLast(containerClassName, ".model.");
        containerName = StringUtils.removeEnd(containerName, "Info");
    }
    // containerName + childName
    {
        String childClassName = child.getClass().getName();
        String childName = StringUtils.substringAfterLast(childClassName, ".");
        childName = StringUtils.removeEnd(childName, "Info");
        //
        Class<?> clazz = loadClass2(basePackageName, containerName + childName);
        if (clazz != null) {
            return clazz;
        }
    }
    // only containerName
    {
        Class<?> clazz = loadClass2(basePackageName, containerName);
        if (clazz != null) {
            return clazz;
        }
    }
    // no class
    return null;
}