Example usage for org.apache.commons.lang ObjectUtils toString

List of usage examples for org.apache.commons.lang ObjectUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ObjectUtils toString.

Prototype

public static String toString(Object obj) 

Source Link

Document

Gets the toString of an Object returning an empty string ("") if null input.

 ObjectUtils.toString(null)         = "" ObjectUtils.toString("")           = "" ObjectUtils.toString("bat")        = "bat" ObjectUtils.toString(Boolean.TRUE) = "true" 

Usage

From source file:org.andromda.cartridges.gui.metafacades.GuiViewLogicImpl.java

/**
 * @return populator//  w  w w.j  a  v a 2s.  c  om
 * @see org.andromda.cartridges.gui.metafacades.GuiViewLogic#getPopulator()
 */
@Override
protected String handleGetPopulator() {

    return ObjectUtils.toString(this.getConfiguredProperty(GuiGlobals.VIEW_POPULATOR_PATTERN))
            .replaceAll("\\{0\\}", StringUtilsHelper.upperCamelCaseName(this.getName()));

}

From source file:org.andromda.cartridges.gui.metafacades.GuiViewLogicImpl.java

/**
 * @return isPopup//from www .  jav a 2s .c  om
 * @see org.andromda.cartridges.gui.metafacades.GuiView#isPopup()
 */
@Override
protected boolean handleIsPopup() {

    return ObjectUtils.toString(this.findTaggedValue(GuiProfile.TAGGEDVALUE_VIEW_TYPE))
            .equalsIgnoreCase(GuiGlobals.VIEW_TYPE_POPUP);

}

From source file:org.andromda.presentation.gui.FileDownloadServlet.java

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*w  w w .j a  va  2s.  c  o m*/
@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    try {
        final String action = request.getParameter(ACTION);
        final FacesContext context = FacesContextUtils.getFacesContext(request, response);
        if (action != null && action.trim().length() > 0) {
            final MethodBinding methodBinding = context.getApplication()
                    .createMethodBinding("#{" + action + "}", null);
            methodBinding.invoke(context, null);
        }

        final Object form = context.getApplication().getVariableResolver().resolveVariable(context, "form");
        final Boolean prompt = Boolean.valueOf(request.getParameter(PROMPT));
        final String fileNameProperty = request.getParameter(FILE_NAME);
        final String outputProperty = request.getParameter(OUTPUT);
        if (form != null && outputProperty != null && fileNameProperty.trim().length() > 0) {
            final OutputStream stream = response.getOutputStream();

            // - reset the response to clear out any any headers (i.e. so
            //   the user doesn't get "unable to open..." when using IE.)
            response.reset();

            Object output = PropertyUtils.getProperty(form, outputProperty);
            final String fileName = ObjectUtils.toString(PropertyUtils.getProperty(form, fileNameProperty));
            final String contentType = this.getContentType(context, request.getParameter(CONTENT_TYPE),
                    fileName);

            if (prompt.booleanValue() && fileName != null && fileName.trim().length() > 0) {
                response.addHeader("Content-disposition", "attachment; filename=\"" + fileName + '"');
            }

            // - for IE we need to set the content type, content length and buffer size and
            //   then the flush the response right away because it seems as if there is any lag time
            //   IE just displays a blank page. With mozilla based clients reports display correctly regardless.
            if (contentType != null && contentType.length() > 0) {
                response.setContentType(contentType);
            }
            if (output instanceof String) {
                output = ((String) output).getBytes();
            }
            if (output instanceof byte[]) {
                byte[] file = (byte[]) output;
                response.setBufferSize(file.length);
                response.setContentLength(file.length);
                response.flushBuffer();
                stream.write(file);
            } else if (output instanceof InputStream) {
                final InputStream report = (InputStream) output;
                final byte[] buffer = new byte[BUFFER_SIZE];
                response.setBufferSize(BUFFER_SIZE);
                response.flushBuffer();
                for (int ctr = 0; (ctr = report.read(buffer)) > 0;) {
                    stream.write(buffer, 0, ctr);
                }
            }
            stream.flush();
        }
        if (form != null) {
            // - remove the output now that we're done with it (in case its large)
            PropertyUtils.setProperty(form, outputProperty, null);
        }
    } catch (Throwable throwable) {
        throw new ServletException(throwable);
    }
}

From source file:org.andromda.timetracker.domain.crud.TaskController.java

/**
 * Helper method to fill the select component list.
 *
 * @return a collection with the filtered list.
 *///from  ww w .j a va  2  s.com
public Collection<SelectItem> getAsSelectItems() {
    final Collection<TaskValueObject> vos;
    try {
        vos = ManageableServiceLocator.instance().getTaskManageableService().readAll();
    } catch (final Throwable throwable) {
        logger.error(throwable.getMessage(), throwable);
        this.addExceptionMessage(throwable);
        return null;
    }
    final Collection<SelectItem> result = new ArrayList<SelectItem>(vos.size());
    for (TaskValueObject vo : vos) {
        result.add(new SelectItem(vo.getId(), ObjectUtils.toString(vo.getName())));
    }
    return result;
}

From source file:org.andromda.timetracker.domain.crud.UserController.java

/**
 * Helper method to fill the select component list.
 *
 * @return a collection with the filtered list.
 *///from w  ww.j  a  va2 s  .c  o  m
public Collection<SelectItem> getAsSelectItems() {
    final Collection<UserValueObject> vos;
    try {
        vos = ManageableServiceLocator.instance().getUserManageableService().readAll();
    } catch (final Throwable throwable) {
        logger.error(throwable.getMessage(), throwable);
        this.addExceptionMessage(throwable);
        return null;
    }
    final Collection<SelectItem> result = new ArrayList<SelectItem>(vos.size());
    for (UserValueObject vo : vos) {
        result.add(new SelectItem(vo.getId(), ObjectUtils.toString(vo.getUsername())));
    }
    return result;
}

From source file:org.apache.ambari.server.controller.internal.RepositoryVersionResourceProvider.java

@Override
public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException,
        UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
    final Set<Map<String, Object>> propertyMaps = request.getProperties();

    modifyResources(new Command<Void>() {
        @Override//from w ww  . jav  a 2  s. c o m
        public Void invoke() throws AmbariException {
            for (Map<String, Object> propertyMap : propertyMaps) {
                final Long id;
                try {
                    id = Long.parseLong(propertyMap.get(REPOSITORY_VERSION_ID_PROPERTY_ID).toString());
                } catch (Exception ex) {
                    throw new AmbariException("Repository version should have numerical id");
                }

                final RepositoryVersionEntity entity = repositoryVersionDAO.findByPK(id);
                if (entity == null) {
                    throw new ObjectNotFoundException("There is no repository version with id " + id);
                }

                if (StringUtils.isNotBlank(
                        ObjectUtils.toString(propertyMap.get(REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID)))) {
                    final List<ClusterVersionEntity> clusterVersionEntities = clusterVersionDAO
                            .findByStackAndVersion(entity.getStack(), entity.getVersion());

                    if (!clusterVersionEntities.isEmpty()) {
                        final ClusterVersionEntity firstClusterVersion = clusterVersionEntities.get(0);
                        throw new AmbariException(
                                "Upgrade pack can't be changed for repository version which is "
                                        + firstClusterVersion.getState().name() + " on cluster "
                                        + firstClusterVersion.getClusterEntity().getClusterName());
                    }

                    final String upgradePackage = propertyMap.get(REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID)
                            .toString();
                    entity.setUpgradePackage(upgradePackage);
                }

                if (StringUtils.isNotBlank(
                        ObjectUtils.toString(propertyMap.get(SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID)))) {
                    final Object operatingSystems = propertyMap.get(SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID);
                    final String operatingSystemsJson = gson.toJson(operatingSystems);
                    try {
                        repositoryVersionHelper.parseOperatingSystems(operatingSystemsJson);
                    } catch (Exception ex) {
                        throw new AmbariException("Json structure for operating systems is incorrect", ex);
                    }
                    entity.setOperatingSystems(operatingSystemsJson);
                }

                if (StringUtils.isNotBlank(
                        ObjectUtils.toString(propertyMap.get(REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID)))) {
                    entity.setDisplayName(
                            propertyMap.get(REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID).toString());
                }

                validateRepositoryVersion(entity);
                repositoryVersionDAO.merge(entity);
            }
            return null;
        }
    });

    return getRequestStatus(null);
}

From source file:org.apache.ambari.server.controller.internal.WidgetLayoutResourceProvider.java

@Override
public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException,
        UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {

    final Set<Map<String, Object>> propertyMaps = request.getProperties();

    modifyResources(new Command<Void>() {
        @Override/*from   w w w  . j a  v  a 2  s .  c  o  m*/
        public Void invoke() throws AmbariException {
            for (Map<String, Object> propertyMap : propertyMaps) {
                final Long layoutId;
                try {
                    layoutId = Long.parseLong(propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID).toString());
                } catch (Exception ex) {
                    throw new AmbariException("WidgetLayout should have numerical id");
                }
                lock.writeLock().lock();
                try {
                    final WidgetLayoutEntity entity = widgetLayoutDAO.findById(layoutId);
                    if (entity == null) {
                        throw new ObjectNotFoundException("There is no widget layout with id " + layoutId);
                    }
                    if (StringUtils.isNotBlank(
                            ObjectUtils.toString(propertyMap.get(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID)))) {
                        entity.setLayoutName(propertyMap.get(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID).toString());
                    }
                    if (StringUtils.isNotBlank(
                            ObjectUtils.toString(propertyMap.get(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID)))) {
                        entity.setSectionName(
                                propertyMap.get(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID).toString());
                    }
                    if (StringUtils.isNotBlank(
                            ObjectUtils.toString(propertyMap.get(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID)))) {
                        entity.setDisplayName(
                                propertyMap.get(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID).toString());
                    }
                    if (StringUtils.isNotBlank(
                            ObjectUtils.toString(propertyMap.get(WIDGETLAYOUT_SCOPE_PROPERTY_ID)))) {
                        entity.setScope(propertyMap.get(WIDGETLAYOUT_SCOPE_PROPERTY_ID).toString());
                    }

                    Set widgetsSet = (LinkedHashSet) propertyMap.get(WIDGETLAYOUT_WIDGETS_PROPERTY_ID);

                    //Remove old relations from widget entities
                    for (WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity : entity
                            .getListWidgetLayoutUserWidgetEntity()) {
                        widgetLayoutUserWidgetEntity.getWidget().getListWidgetLayoutUserWidgetEntity()
                                .remove(widgetLayoutUserWidgetEntity);
                    }
                    entity.setListWidgetLayoutUserWidgetEntity(new LinkedList<WidgetLayoutUserWidgetEntity>());

                    List<WidgetLayoutUserWidgetEntity> widgetLayoutUserWidgetEntityList = new LinkedList<WidgetLayoutUserWidgetEntity>();
                    int order = 0;
                    for (Object widgetObject : widgetsSet) {
                        HashMap<String, Object> widget = (HashMap) widgetObject;
                        long id = Integer.parseInt(widget.get("id").toString());
                        WidgetEntity widgetEntity = widgetDAO.findById(id);
                        if (widgetEntity == null) {
                            throw new AmbariException(
                                    "Widget with id " + widget.get("id").toString() + " does not exists");
                        }
                        WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity = new WidgetLayoutUserWidgetEntity();

                        widgetLayoutUserWidgetEntity.setWidget(widgetEntity);
                        widgetLayoutUserWidgetEntity.setWidgetOrder(order++);
                        widgetLayoutUserWidgetEntity.setWidgetLayout(entity);
                        widgetLayoutUserWidgetEntityList.add(widgetLayoutUserWidgetEntity);
                        widgetEntity.getListWidgetLayoutUserWidgetEntity().add(widgetLayoutUserWidgetEntity);
                        entity.getListWidgetLayoutUserWidgetEntity().add(widgetLayoutUserWidgetEntity);
                    }

                    widgetLayoutDAO.mergeWithFlush(entity);
                } finally {
                    lock.writeLock().unlock();
                }
            }
            return null;
        }
    });

    return getRequestStatus(null);
}

From source file:org.apache.ambari.server.controller.internal.WidgetResourceProvider.java

@Override
public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException,
        UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {

    final Set<Map<String, Object>> propertyMaps = request.getProperties();

    modifyResources(new Command<Void>() {
        @Override/*from w  ww.  ja v a  2  s .  c  o  m*/
        public Void invoke() throws AmbariException {
            for (Map<String, Object> propertyMap : propertyMaps) {
                final Long id;
                try {
                    id = Long.parseLong(propertyMap.get(WIDGET_ID_PROPERTY_ID).toString());
                } catch (Exception ex) {
                    throw new AmbariException("Widget should have numerical id");
                }

                final WidgetEntity entity = widgetDAO.findById(id);
                if (entity == null) {
                    throw new ObjectNotFoundException("There is no widget with id " + id);
                }

                if (StringUtils
                        .isNotBlank(ObjectUtils.toString(propertyMap.get(WIDGET_WIDGET_NAME_PROPERTY_ID)))) {
                    entity.setWidgetName(propertyMap.get(WIDGET_WIDGET_NAME_PROPERTY_ID).toString());
                }

                if (StringUtils
                        .isNotBlank(ObjectUtils.toString(propertyMap.get(WIDGET_WIDGET_TYPE_PROPERTY_ID)))) {
                    entity.setWidgetType(propertyMap.get(WIDGET_WIDGET_TYPE_PROPERTY_ID).toString());
                }

                if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(WIDGET_METRICS_PROPERTY_ID)))) {
                    entity.setMetrics(gson.toJson(propertyMap.get(WIDGET_METRICS_PROPERTY_ID)));
                }

                entity.setAuthor(getAuthorName(propertyMap));

                if (StringUtils
                        .isNotBlank(ObjectUtils.toString(propertyMap.get(WIDGET_DESCRIPTION_PROPERTY_ID)))) {
                    entity.setDescription(propertyMap.get(WIDGET_DESCRIPTION_PROPERTY_ID).toString());
                }

                if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(WIDGET_SCOPE_PROPERTY_ID)))) {
                    String scope = propertyMap.get(WIDGET_SCOPE_PROPERTY_ID).toString();
                    if (!isScopeAllowedForUser(scope)) {
                        throw new AmbariException(
                                "Only cluster operator can create widgets with cluster scope");
                    }
                    entity.setScope(scope);
                }

                if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(WIDGET_VALUES_PROPERTY_ID)))) {
                    entity.setWidgetValues(gson.toJson(propertyMap.get(WIDGET_VALUES_PROPERTY_ID)));
                }

                Map<String, Object> widgetPropertiesMap = new HashMap<String, Object>();
                for (Map.Entry<String, Object> entry : propertyMap.entrySet()) {
                    if (PropertyHelper.getPropertyCategory(entry.getKey())
                            .equals(WIDGET_PROPERTIES_PROPERTY_ID)) {
                        widgetPropertiesMap.put(PropertyHelper.getPropertyName(entry.getKey()),
                                entry.getValue());
                    }
                }

                if (!widgetPropertiesMap.isEmpty()) {
                    entity.setProperties(gson.toJson(widgetPropertiesMap));
                }

                widgetDAO.merge(entity);
            }
            return null;
        }
    });

    return getRequestStatus(null);
}

From source file:org.apache.ambari.server.controller.internal.WidgetResourceProvider.java

private String getAuthorName(Map<String, Object> properties) {
    if (StringUtils.isNotBlank(ObjectUtils.toString(properties.get(WIDGET_AUTHOR_PROPERTY_ID)))) {
        return properties.get(WIDGET_AUTHOR_PROPERTY_ID).toString();
    }//from  w  w  w.j  a  v  a 2  s .c  om
    return getManagementController().getAuthName();
}

From source file:org.apache.cocoon.transformation.LDAPTransformer.java

protected static String getStringValue(Object object) {
    return ObjectUtils.toString(object);
}