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

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

Introduction

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

Prototype

public static String uncapitalize(String str) 

Source Link

Document

Uncapitalizes a String changing the first letter to title case as per Character#toLowerCase(char) .

Usage

From source file:org.openlegacy.terminal.mvc.web.DefaultGenericController.java

private String prepareView(ScreenEntity screenEntity, Model uiModel, boolean partial,
        HttpServletRequest request) throws MalformedURLException {
    String screenEntityName = ProxyUtil.getOriginalClass(screenEntity.getClass()).getSimpleName();
    uiModel.addAttribute(StringUtils.uncapitalize(screenEntityName), screenEntity);
    ScreenEntityDefinition entityDefinition = screenEntitiesRegistry.get(screenEntityName);
    uiModel.addAttribute(PAGE, pageBuilder.build(entityDefinition));

    SitePreference sitePreference = SitePreferenceUtils.getCurrentSitePreference(request);

    boolean isComposite = entityDefinition.getChildEntitiesDefinitions().size() > 0 && !partial;
    String suffix = isComposite ? MvcConstants.COMPOSITE_SUFFIX : "";
    String viewName = entityDefinition.getEntityName() + suffix;

    String viewsPath = sitePreference == SitePreference.MOBILE ? mobileViewsPath : webViewsPath;

    // check if custom view exists, if not load generic view by characteristics
    if (servletContext
            .getResource(MessageFormat.format("{0}/{1}{2}", viewsPath, viewName, viewsSuffix)) == null) {
        if (isComposite) {
            // generic composite view (multi tabbed page)
            viewName = MvcConstants.COMPOSITE;
        } else if (entityDefinition.getType() == MenuEntity.class) {
            // generic menu view
            viewName = MvcConstants.ROOTMENU_VIEW;
        } else if (partial) {
            // generic inner page view (inner tab)
            viewName = MvcConstants.GENERIC_VIEW;
        } else if (entityDefinition.isWindow()) {
            // generic window pop-pup view
            viewName = MvcConstants.GENERIC_WINDOW;
        } else {//from w  ww . ja  v  a  2  s  .c  o  m
            // generic view
            viewName = MvcConstants.GENERIC;
        }
    }

    return viewName;
}

From source file:org.openlegacy.terminal.mvc.web.ScreenBindUtils.java

/**
 * Collects multiple screens table, and sets it to the view
 * /* ww w. java2 s.c  o m*/
 * @param entity
 * @param uiModel
 * @param session
 * @param definition
 */
public void bindCollectTable(TerminalSession session, Object entity, Model uiModel) {
    Object collectedEntity = multyScreenTableBindUtil.bindCollectTable(session, entity);
    if (collectedEntity != null) {
        String screenEntityName = ProxyUtil.getOriginalClass(entity.getClass()).getSimpleName();
        uiModel.addAttribute(StringUtils.uncapitalize(screenEntityName), collectedEntity);
    }
}

From source file:org.openlegacy.utils.StringUtil.java

public static String toVariableName(String text, boolean capFirst) {

    String variableName = null;//from   w  ww.  ja v  a  2  s . co  m

    if (!text.contains(" ") && !text.contains("_") && !text.contains("-")) {
        text = text.replaceAll("\\W", "");
        if (!capFirst) {
            variableName = StringUtils.uncapitalize(text);
        } else {
            variableName = StringUtils.capitalize(text);
        }
    } else {
        char[] chars = text.toCharArray();
        StringBuilder sb = new StringBuilder(text.length());
        for (char d : chars) {

            char c = d;

            if (capFirst) {
                c = Character.toUpperCase(c);
                capFirst = false;
            } else {
                c = Character.toLowerCase(c);
            }

            if (Character.isLetter(c) || Character.isDigit(c)) {
                sb.append(c);
            }
            if (c == ' ' || c == '_' || c == '-') {
                capFirst = true;
            }

        }
        variableName = sb.toString();
    }

    if (RESERVERD_WORDS_DICTIONARY.containsKey(variableName)) {
        variableName = variableName + "_";
    }

    if (!StringUtils.isEmpty(variableName) && variableName.charAt(0) >= '0' && variableName.charAt(0) <= '9') {
        variableName = "_" + variableName;
    }

    return variableName;

}

From source file:org.openlegacy.web.tags.TagUtils.java

public static String uncapFirst(String text) {
    return StringUtils.uncapitalize(text);
}

From source file:org.overlord.sramp.repository.jcr.JCRArtifactPersister.java

/**
 * Phase one of persisting an artifact consists of creating the JCR node for the artifact and
 * persisting all of its meta-data to it.
 * @param session//w w  w.java 2  s.co m
 * @param metaData
 * @param content
 * @param referenceFactory
 * @param classificationHelper
 * @throws Exception
 */
public static Phase1Result persistArtifactPhase1(Session session, BaseArtifactType metaData,
        InputStream content, ClassificationHelper classificationHelper) throws Exception {
    JCRUtils tools = new JCRUtils();
    if (metaData.getUuid() == null) {
        metaData.setUuid(UUID.randomUUID().toString());
    }
    String uuid = metaData.getUuid();
    ArtifactType artifactType = ArtifactType.valueOf(metaData);
    String name = metaData.getName();
    String artifactPath = MapToJCRPath.getArtifactPath(uuid);
    if (session.nodeExists(artifactPath)) {
        throw new ArtifactAlreadyExistsException(uuid);
    }
    log.debug(Messages.i18n.format("UPLOADING_TO_JCR", name)); //$NON-NLS-1$

    Node artifactNode = null;
    boolean isDocumentArtifact = SrampModelUtils.isDocumentArtifact(metaData);
    if (content == null && !isDocumentArtifact) {
        artifactNode = tools.findOrCreateNode(session, artifactPath, "nt:folder", //$NON-NLS-1$
                JCRConstants.SRAMP_NON_DOCUMENT_TYPE);
    } else {
        artifactNode = tools.uploadFile(session, artifactPath, content);
        JCRUtils.setArtifactContentMimeType(artifactNode, artifactType.getMimeType());
    }

    String jcrMixinName = artifactType.getArtifactType().getApiType().value();
    jcrMixinName = JCRConstants.SRAMP_ + StringUtils.uncapitalize(jcrMixinName);
    artifactNode.addMixin(jcrMixinName);
    // BaseArtifactType
    artifactNode.setProperty(JCRConstants.SRAMP_UUID, uuid);
    artifactNode.setProperty(JCRConstants.SRAMP_ARTIFACT_MODEL, artifactType.getArtifactType().getModel());
    artifactNode.setProperty(JCRConstants.SRAMP_ARTIFACT_TYPE, artifactType.getArtifactType().getType());
    // Extended
    if (ExtendedArtifactType.class.isAssignableFrom(artifactType.getArtifactType().getTypeClass())) {
        artifactNode.setProperty(JCRConstants.SRAMP_EXTENDED_TYPE, artifactType.getExtendedType());
    }
    // Extended Document
    if (ExtendedDocument.class.isAssignableFrom(artifactType.getArtifactType().getTypeClass())) {
        artifactNode.setProperty(JCRConstants.SRAMP_EXTENDED_TYPE, artifactType.getExtendedType());
    }
    // Document
    if (DocumentArtifactType.class.isAssignableFrom(artifactType.getArtifactType().getTypeClass())) {
        artifactNode.setProperty(JCRConstants.SRAMP_CONTENT_TYPE, artifactType.getMimeType());
        artifactNode.setProperty(JCRConstants.SRAMP_CONTENT_SIZE,
                artifactNode.getProperty("jcr:content/jcr:data").getLength()); //$NON-NLS-1$
        String shaHex = DigestUtils
                .shaHex(artifactNode.getProperty("jcr:content/jcr:data").getBinary().getStream()); //$NON-NLS-1$
        artifactNode.setProperty(JCRConstants.SRAMP_CONTENT_HASH, shaHex);
    }
    // XMLDocument
    if (XmlDocument.class.isAssignableFrom(artifactType.getArtifactType().getTypeClass())) {
        // read the encoding from the header
        artifactNode.setProperty(JCRConstants.SRAMP_CONTENT_ENCODING, "UTF-8"); //$NON-NLS-1$
    }

    // Update the JCR node with any properties included in the meta-data
    ArtifactToJCRNodeVisitor visitor = new ArtifactToJCRNodeVisitor(artifactType, artifactNode,
            new JCRReferenceFactoryImpl(session), classificationHelper);
    ArtifactVisitorHelper.visitArtifact(visitor, metaData);
    if (visitor.hasError())
        throw visitor.getError();

    log.debug(Messages.i18n.format("SAVED_JCR_NODE", name, uuid)); //$NON-NLS-1$
    if (sramp.isAuditingEnabled()) {
        auditCreateArtifact(artifactNode);
        session.save();
    }
    session.save();

    Phase1Result result = new Phase1Result();
    result.artifactNode = artifactNode;
    result.artifactType = artifactType;
    result.isDocumentArtifact = isDocumentArtifact;
    return result;
}

From source file:org.overlord.sramp.repository.jcr.JCRArtifactPersister.java

/**
 * Persist any derived artifacts to JCR.
 * @param session//from   ww  w  .  ja v a  2s. com
 * @param sourceArtifactNode
 * @param derivedArtifacts
 * @param classificationHelper
 * @throws SrampException
 */
private static void persistDerivedArtifacts(Session session, Node sourceArtifactNode,
        Collection<BaseArtifactType> derivedArtifacts, ClassificationHelper classificationHelper)
        throws SrampException {
    try {
        // Persist each of the derived nodes
        for (BaseArtifactType derivedArtifact : derivedArtifacts) {
            if (derivedArtifact.getUuid() == null) {
                throw new SrampServerException(
                        Messages.i18n.format("MISSING_DERIVED_UUID", derivedArtifact.getName())); //$NON-NLS-1$
            }
            ArtifactType derivedArtifactType = ArtifactType.valueOf(derivedArtifact);
            String jcrMixinName = derivedArtifactType.getArtifactType().getApiType().value();
            if (derivedArtifactType.isExtendedType()) {
                jcrMixinName = "extendedDerivedArtifactType"; //$NON-NLS-1$
                derivedArtifactType.setExtendedDerivedType(true);
            }
            jcrMixinName = JCRConstants.SRAMP_ + StringUtils.uncapitalize(jcrMixinName);

            // Create the JCR node and set some basic properties first.
            String nodeName = derivedArtifact.getUuid();
            Node derivedArtifactNode = sourceArtifactNode.addNode(nodeName,
                    JCRConstants.SRAMP_DERIVED_PRIMARY_TYPE);
            derivedArtifactNode.addMixin(jcrMixinName);
            derivedArtifactNode.setProperty(JCRConstants.SRAMP_UUID, derivedArtifact.getUuid());
            derivedArtifactNode.setProperty(JCRConstants.SRAMP_ARTIFACT_MODEL,
                    derivedArtifactType.getArtifactType().getModel());
            derivedArtifactNode.setProperty(JCRConstants.SRAMP_ARTIFACT_TYPE,
                    derivedArtifactType.getArtifactType().getType());
            // Extended
            if (ExtendedArtifactType.class
                    .isAssignableFrom(derivedArtifactType.getArtifactType().getTypeClass())) {
                // read the encoding from the header
                derivedArtifactNode.setProperty(JCRConstants.SRAMP_EXTENDED_TYPE,
                        derivedArtifactType.getExtendedType());
            }

            // It's definitely derived.
            derivedArtifactNode.setProperty("sramp:derived", true); //$NON-NLS-1$

            // Create the visitor that will be used to write the artifact information to the JCR node
            ArtifactToJCRNodeVisitor visitor = new ArtifactToJCRNodeVisitor(derivedArtifactType,
                    derivedArtifactNode, null, classificationHelper);
            visitor.setProcessRelationships(false);
            ArtifactVisitorHelper.visitArtifact(visitor, derivedArtifact);
            if (visitor.hasError())
                throw visitor.getError();

            // Audit the create event for the derived node
            if (sramp.isAuditingEnabled() && sramp.isDerivedArtifactAuditingEnabled()) {
                auditCreateArtifact(derivedArtifactNode);
            }

            log.debug(Messages.i18n.format("SAVED_DERIVED_ARTY_TO_JCR", derivedArtifact.getName(), //$NON-NLS-1$
                    derivedArtifact.getUuid()));
        }

        // Save current changes so that references to nodes can be found.  Note that if
        // transactions are enabled, this will not actually persist to final storage.
        session.save();

        log.debug(Messages.i18n.format("SAVED_ARTIFACTS", derivedArtifacts.size())); //$NON-NLS-1$
    } catch (SrampException e) {
        throw e;
    } catch (Throwable t) {
        throw new SrampServerException(t);
    }
}

From source file:org.pentaho.mantle.rebind.EventBusUtilGenerator.java

String addHandlerParamJson(JClassType type) {
    StringBuilder json = new StringBuilder(128);
    json.append('"').append('{');
    JMethod[] methods = type.getMethods();
    for (JMethod eventMethod : methods) {

        if (eventMethod.isPublic() && !eventMethod.isStatic() && (eventMethod.isConstructor() == null)
                && !"void".equalsIgnoreCase(eventMethod.getReturnType().getSimpleSourceName())
                && !eventMethod.getName().equals("getAssociatedType")) {
            // let's add the property to JSON object
            String propertyName = StringUtils.uncapitalize(eventMethod.getName().substring(3));
            String simpleType = type.getField(propertyName).getType().getSimpleSourceName();
            if ("string".equalsIgnoreCase(simpleType)) {
                json.append(//from   www.  ja  v  a  2s  . c  o  m
                        "\\\"" + propertyName + "\\\":\\\"\" + event." + eventMethod.getName() + "() + \"\\\"");
            } else {
                json.append("\\\"" + propertyName + "\\\":\" + event." + eventMethod.getName() + "() + \"");
            }
            json.append(',');
        }
    }

    int lastIndex = json.lastIndexOf(",");
    if (lastIndex == -1) {
        json.append('}');
    } else {
        json.setCharAt(lastIndex, '}');
    }
    return json.append('"').toString();
}

From source file:org.projectforge.business.scripting.ScriptDao.java

/**
 * Adds all registered dao's and other variables, such as appId, appVersion and task-tree. These variables are
 * available in Groovy scripts/*from  w w w.j a va 2s . c  o  m*/
 * 
 * @param scriptVariables
 */
public void addScriptVariables(final Map<String, Object> scriptVariables) {
    scriptVariables.put("appId", AppVersion.APP_ID);
    scriptVariables.put("appVersion", AppVersion.NUMBER);
    scriptVariables.put("appRelease", AppVersion.RELEASE_DATE);
    scriptVariables.put("reportList", null);
    scriptVariables.put("taskTree", new ScriptingTaskTree(TaskTreeHelper.getTaskTree()));
    for (final RegistryEntry entry : Registry.getInstance().getOrderedList()) {
        final ScriptingDao<?> scriptingDao = entry.getScriptingDao();
        if (scriptingDao != null) {
            final String varName = StringUtils.uncapitalize(entry.getId());
            scriptVariables.put(varName + "Dao", scriptingDao);
        }
    }
}

From source file:org.projectforge.common.BeanHelper.java

public static String determinePropertyName(final Method method) {
    final String name = method.getName();
    if (name.startsWith("get") == true || name.startsWith("set") == true) {
        return StringUtils.uncapitalize(name.substring(3));
    } else if (name.startsWith("is") == true) {
        return StringUtils.uncapitalize(name.substring(2));
    }//  ww  w.j a va 2 s . co  m
    return method.getName();
}

From source file:org.projectforge.scripting.ScriptDao.java

/**
 * Adds all registered dao's and other variables, such as appId, appVersion and task-tree. These variables are available in Groovy scripts
 * @param scriptVariables/*from  ww  w. j  av a 2  s  . c o m*/
 */
public void addScriptVariables(final Map<String, Object> scriptVariables) {
    scriptVariables.put("appId", AppVersion.APP_ID);
    scriptVariables.put("appVersion", AppVersion.NUMBER);
    scriptVariables.put("appRelease", AppVersion.RELEASE_DATE);
    scriptVariables.put("reportList", null);
    scriptVariables.put("taskTree", new ScriptingTaskTree(taskTree));
    for (final RegistryEntry entry : Registry.instance().getOrderedList()) {
        final ScriptingDao<?> scriptingDao = entry.getScriptingDao();
        if (scriptingDao != null) {
            final String varName = StringUtils.uncapitalize(entry.getId());
            scriptVariables.put(varName + "Dao", scriptingDao);
        }
    }
}