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

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

Introduction

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

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is empty or null, the value of defaultStr.

Usage

From source file:org.jahia.modules.visibility.rules.VisibilityActionPurgeJob.java

@Override
public void executeJahiaJob(JobExecutionContext ctx) throws Exception {
    long timer = System.currentTimeMillis();
    final JobDataMap data = ctx.getJobDetail().getJobDataMap();
    final String workspace = StringUtils.defaultIfEmpty(data.getString("workspace"), Constants.LIVE_WORKSPACE);

    Integer[] counts = JCRTemplate.getInstance().doExecuteWithSystemSession(null, workspace,
            new JCRCallback<Integer[]>() {
                @SuppressWarnings("unchecked")
                public Integer[] doInJCR(JCRSessionWrapper session) throws RepositoryException {
                    Set<String> jobGroupNames = Collections.emptySet();
                    Object val = data.get("visibilityJobGroupNames");
                    if (val != null && val instanceof Set<?>) {
                        jobGroupNames = (Set<String>) val;
                    }//from w  w  w  .  j  av  a  2s . co m
                    logger.info(
                            "Start looking for orphaned start and end date visibility actions in job groups {} and workspace {}",
                            jobGroupNames, workspace);

                    return processJobs(jobGroupNames, session);
                }
            });

    logger.info("Finished scanning {} visibility action jobs. Deleted {} orphaned jobs. Execution took {} ms",
            new Long[] { Long.valueOf(counts[0]), Long.valueOf(counts[1]),
                    (System.currentTimeMillis() - timer) });
}

From source file:org.jahia.osgi.BundleUtils.java

/**
 * Returns a version of the module read from the provided bundle.
 *
 * @param bundle the bundle to read the module version from
 * @return a version of the module read from the provided bundle
 *///from ww  w .  j av  a  2 s.  com
public static String getModuleVersion(Bundle bundle) {
    final String version = bundle.getVersion().toString();
    if (version == null) {
        throw new NullPointerException(
                "Check your bundle's MANIFEST: missing required Bundle-Version for bundle " + bundle);
    }
    return StringUtils.defaultIfEmpty(bundle.getHeaders().get("Implementation-Version"), version);
}

From source file:org.jahia.services.content.files.FileServlet.java

protected String generateETag(String uuid, long lastModified) {
    return "\"" + StringUtils.replace(StringUtils.defaultIfEmpty(uuid, "unknown"), "\"", "") + "-"
            + lastModified + "\"";
}

From source file:org.jahia.services.content.files.FileServlet.java

protected FileKey parseKey(HttpServletRequest req) throws UnsupportedEncodingException {
    String workspace = null;//from  w  w w .  j a v a 2s.c o m
    String path = null;
    String p = req.getPathInfo();
    if (p != null && p.length() > 2) {
        int pathStart = p.indexOf("/", 1);
        workspace = pathStart > 1 ? p.substring(1, pathStart) : null;
        if (workspace != null) {
            path = p.substring(pathStart);
            if (ContextPlaceholdersReplacer.WORKSPACE_PLACEHOLDER
                    .equals(URLDecoder.decode(workspace, characterEncoding))) {
                // Hack for CK Editor links
                workspace = Constants.EDIT_WORKSPACE;
            }
            if (!JCRContentUtils.isValidWorkspace(workspace)) {
                // unknown workspace
                workspace = null;
            }
        }
    }

    return path != null && workspace != null
            ? new FileKey(workspace, JCRContentUtils.escapeNodePath(path), req.getParameter("v"),
                    req.getParameter("l"), StringUtils.defaultIfEmpty(req.getParameter("t"), StringUtils.EMPTY))
            : null;
}

From source file:org.jahia.services.content.JCRContentUtils.java

/**
 * Detects the mime-type for the specified file name, based on its extension (uses mime types, configured in the web.xml deployment
 * descriptor). If the type cannot be detected, the provided fallback mime type is returned.
 *
 * @param fileName         the name of the file to detect mime type for
 * @param fallbackMimeType the fallback mime-type to use if the type cannot be detected
 * @return the mime-type for the specified file name, based on its extension (uses mime types, configured in the web.xml deployment
 *         descriptor). If the type cannot be detected, the provided fallback mime type is returned.
 *//*www  . j  a va2 s .  co m*/
public static String getMimeType(String fileName, String fallbackMimeType) {
    return StringUtils.defaultIfEmpty(getMimeType(fileName), fallbackMimeType);
}

From source file:org.jahia.services.content.JCRStoreProvider.java

protected void initObservers() throws RepositoryException {
    if (!registerObservers) {
        return;/*from  w w w  . j a  v  a 2  s.c  om*/
    }
    Set<String> workspaces = service.getListeners().keySet();
    observerSessions = new HashMap<String, JCRSessionWrapper>(workspaces.size());
    for (String ws : workspaces) {
        // This session must not be released
        final JCRSessionWrapper session = getSystemSession(ws);
        observerSessions.put(ws, session);
        final Workspace workspace = session.getProviderSession(this).getWorkspace();

        ObservationManager observationManager = workspace.getObservationManager();
        JCRObservationManagerDispatcher listener = new JCRObservationManagerDispatcher();
        listener.setWorkspace(workspace.getName());
        listener.setMountPoint(mountPoint);
        listener.setRelativeRoot(relativeRoot);
        observationManager.addEventListener(listener,
                Event.NODE_ADDED + Event.NODE_REMOVED + Event.PROPERTY_ADDED + Event.PROPERTY_CHANGED
                        + Event.PROPERTY_REMOVED + Event.NODE_MOVED,
                observersUseRelativeRoot ? StringUtils.defaultIfEmpty(relativeRoot, "/") : "/", true, null,
                null, false);
        observerSessions.put(ws, session);
    }
}

From source file:org.jahia.services.content.rules.OrphanedActionPurgeJob.java

@Override
public void executeJahiaJob(JobExecutionContext ctx) throws Exception {
    long timer = System.currentTimeMillis();
    final JobDataMap data = ctx.getJobDetail().getJobDataMap();
    final String workspace = StringUtils.defaultIfEmpty(data.getString("workspace"), Constants.LIVE_WORKSPACE);
    final Set<String> jobGroupNames = getJobGroupNames(data);
    if (jobGroupNames == null || jobGroupNames.isEmpty()) {
        logger.debug("No job group names to scan. Skipping.");
        return;/*w  w w  . j ava 2s  .c  o  m*/
    }

    Integer[] counts = JCRTemplate.getInstance().doExecuteWithSystemSessionAsUser(null, workspace, null,
            new JCRCallback<Integer[]>() {
                public Integer[] doInJCR(JCRSessionWrapper session) throws RepositoryException {
                    logger.info("Start looking for orphaned action jobs in job groups {} and workspace {}",
                            jobGroupNames, workspace);

                    return processJobs(jobGroupNames, session);
                }
            });

    logger.info("Finished scanning {} action jobs. Deleted {} orphaned jobs. Execution took {} ms", new Long[] {
            Long.valueOf(counts[0]), Long.valueOf(counts[1]), (System.currentTimeMillis() - timer) });
}

From source file:org.jahia.services.render.BaseView.java

/**
 * Initializes an instance of this class.
 * //from   ww w .ja va2 s .com
 * @param path
 *            the resource path
 * @param key
 *            the key of the view
 * @param module
 *            corresponding {@link JahiaTemplatesPackage} instance
 */
protected BaseView(String path, String key, JahiaTemplatesPackage module) {
    super();
    this.path = path;
    this.key = key;
    this.module = module;
    this.fileExtension = StringUtils.defaultIfEmpty(StringUtils.substringAfterLast(path, "."), null);
}

From source file:org.jahia.services.render.FileSystemView.java

public FileSystemView(String path, String key, JahiaTemplatesPackage ownerPackage, ModuleVersion version,
        String displayName) {/* w ww . j a v  a 2s. c o m*/
    this.path = path;
    this.key = key;
    this.ownerPackage = ownerPackage;
    this.moduleVersion = StringUtils.defaultIfEmpty(version.toString(), null);
    this.displayName = displayName;
    int lastDotPos = path.lastIndexOf(".");
    if (lastDotPos > 0) {
        this.fileExtension = path.substring(lastDotPos + 1);
    }

    String pathWithoutExtension = path.substring(0, lastDotPos);
    String propName = pathWithoutExtension + ".properties";
    String absolutePath = StringUtils.substringBeforeLast(path, File.separator);
    String fileName = StringUtils.substringAfterLast(path, File.separator);
    String pathBeforeDot = StringUtils.substringBefore(fileName, ".");
    String defaultPropName = pathBeforeDot + ".properties";
    String thumbnail = pathWithoutExtension + ".png";
    String defaultThumbnail = pathBeforeDot + ".png";
    getProperties(propName, thumbnail, false);
    getProperties(absolutePath + File.separator + defaultPropName, defaultThumbnail, true);
}

From source file:org.jahia.services.render.URLGenerator.java

public String getLogout() {
    if (logout == null) {
        logout = StringUtils.defaultIfEmpty(LogoutConfig.getInstance().getCustomLogoutUrl(context.getRequest()),
                Logout.getLogoutServletPath());
    }//from  w ww .  j  a  va2s. c  om

    return logout;
}