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

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

Introduction

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

Prototype

public static String substringAfter(final String str, final String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:com.willwinder.universalgcodesender.GrblUtils.java

public static Alarm parseAlarmResponse(String response) {
    String alarmCode = StringUtils.substringAfter(response.toLowerCase(), "alarm:");
    switch (alarmCode) {
    case "1":
        return Alarm.HARD_LIMIT;
    default:/*from  ww  w .  j  a  v  a 2 s  . c o  m*/
        return Alarm.UNKONWN;
    }
}

From source file:de.crowdcode.kissmda.core.uml.UmlHelper.java

/**
 * Check for parameterized type to get the template parameter substitution.
 * //from  w  ww  .j a v a 2s . c  o  m
 * @param type
 *            UML2 type
 * @return Map of umlTypeName and umlQualifiedTypeName
 */
public Map<String, String> checkParameterizedTypeForTemplateParameterSubstitution(Type type) {
    Map<String, String> results = new HashMap<String, String>();

    String umlTypeName = type.getName();
    String umlQualifiedTypeName = type.getQualifiedName();

    List<String> templateSubstitutions = getTemplateParameterSubstitution(type);
    if (templateSubstitutions.size() != 0) {
        int index = 0;

        String paramTypeNames = StringUtils.substringAfter(umlTypeName, "<");
        paramTypeNames = StringUtils.removeEnd(paramTypeNames, ">");
        EList<String> paramTypeNameList = convertStringToList(paramTypeNames, ",");

        for (String paramTypeName : paramTypeNameList) {
            umlTypeName = StringUtils.replace(umlTypeName, paramTypeName, templateSubstitutions.get(index));
            umlQualifiedTypeName = StringUtils.replace(umlQualifiedTypeName, paramTypeName,
                    templateSubstitutions.get(index));
            index = index + 1;
        }
    }

    results.put("umlTypeName", umlTypeName);
    results.put("umlQualifiedTypeName", umlQualifiedTypeName);

    return results;
}

From source file:de.blizzy.documentr.web.page.PageController.java

@RequestMapping(value = "/saveRange/{projectName:" + DocumentrConstants.PROJECT_NAME_PATTERN + "}/"
        + "{branchName:" + DocumentrConstants.BRANCH_NAME_PATTERN + "}/" + "{path:"
        + DocumentrConstants.PAGE_PATH_URL_PATTERN + "}/json", method = RequestMethod.POST)
@ResponseBody//  ww  w . j  av  a 2  s.co  m
@PreAuthorize("hasPagePermission(#projectName, #branchName, #path, EDIT_PAGE)")
public Map<String, Object> savePageRange(@PathVariable String projectName, @PathVariable String branchName,
        @PathVariable String path, @RequestParam String markdown, @RequestParam String range,
        @RequestParam String commit, Authentication authentication, HttpServletRequest request)
        throws IOException {

    path = Util.toRealPagePath(path);

    markdown = markdown.replaceAll("[\\r\\n]+$", StringUtils.EMPTY); //$NON-NLS-1$
    int rangeStart = Integer.parseInt(StringUtils.substringBefore(range, ",")); //$NON-NLS-1$
    int rangeEnd = Integer.parseInt(StringUtils.substringAfter(range, ",")); //$NON-NLS-1$

    Page page = pageStore.getPage(projectName, branchName, path, commit, true);
    String text = ((PageTextData) page.getData()).getText();
    rangeEnd = Math.min(rangeEnd, text.length());

    String oldMarkdown = text.substring(rangeStart, rangeEnd);
    String cleanedOldMarkdown = oldMarkdown.replaceAll("[\\r\\n]+$", StringUtils.EMPTY); //$NON-NLS-1$
    rangeEnd -= oldMarkdown.length() - cleanedOldMarkdown.length();

    String newText = text.substring(0, rangeStart) + markdown
            + text.substring(Math.min(rangeEnd, text.length()));

    page.setData(new PageTextData(newText));
    User user = userStore.getUser(authentication.getName());
    MergeConflict conflict = pageStore.savePage(projectName, branchName, path, page, commit, user);

    Map<String, Object> result = Maps.newHashMap();
    if (conflict != null) {
        result.put("conflict", Boolean.TRUE); //$NON-NLS-1$
        HttpSession session = request.getSession();
        session.setAttribute("conflict", conflict); //$NON-NLS-1$
        session.setAttribute("conflict.projectName", projectName); //$NON-NLS-1$
        session.setAttribute("conflict.branchName", branchName); //$NON-NLS-1$
        session.setAttribute("conflict.path", path); //$NON-NLS-1$
    } else {
        String newCommit = pageStore.getPageMetadata(projectName, branchName, path).getCommit();
        String contextPath = request.getContextPath();
        String html = pageRenderer.getHtml(projectName, branchName, path, authentication, contextPath);
        html = markdownProcessor.processNonCacheableMacros(html, projectName, branchName, path, authentication,
                contextPath);
        result.put("html", html); //$NON-NLS-1$
        result.put("commit", newCommit); //$NON-NLS-1$
    }
    return result;
}

From source file:com.evolveum.midpoint.web.component.wizard.resource.SynchronizationStep.java

private void initObjectSyncEditor(WebMarkupContainer editor) {
    Label editorLabel = new Label(ID_EDITOR_LABEL, new AbstractReadOnlyModel<String>() {
        @Override/* ww  w. j  a  va2  s .co  m*/
        public String getObject() {
            if (!isAnySelected()) {
                return null; // shouldn't occur
            }
            String name = syncDtoModel.getObject().getSelected().getName() != null
                    ? syncDtoModel.getObject().getSelected().getName()
                    : "";
            return getString("SynchronizationStep.label.editSyncObject", name);
        }
    });
    editorLabel.setOutputMarkupId(true);
    editor.add(editorLabel);

    TextField editorName = new TextField<>(ID_EDITOR_NAME,
            new PropertyModel<String>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".name"));
    editorName.add(new UpdateNamesBehaviour());
    parentPage.addEditingEnabledBehavior(editorName);
    editor.add(editorName);

    TextArea editorDescription = new TextArea<>(ID_EDITOR_DESCRIPTION,
            new PropertyModel<String>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".description"));
    parentPage.addEditingEnabledBehavior(editorDescription);
    editor.add(editorDescription);

    DropDownChoice editorKind = new DropDownChoice<>(ID_EDITOR_KIND,
            new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".kind"),
            WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), new EnumChoiceRenderer<>());
    editorKind.setNullValid(true);
    editorKind.add(new UpdateNamesBehaviour());
    parentPage.addEditingEnabledBehavior(editorKind);
    editor.add(editorKind);

    TextField editorIntent = new TextField<>(ID_EDITOR_INTENT,
            new PropertyModel<String>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".intent"));
    editorIntent.add(new UpdateNamesBehaviour());
    parentPage.addEditingEnabledBehavior(editorIntent);
    editor.add(editorIntent);

    MultiValueAutoCompleteTextPanel<QName> editorObjectClass = new MultiValueAutoCompleteTextPanel<QName>(
            ID_EDITOR_OBJECT_CLASS,
            new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".objectClass"), true,
            parentPage.getReadOnlyModel()) {

        @Override
        protected IModel<String> createTextModel(final IModel<QName> model) {
            return new PropertyModel<>(model, "localPart");
        }

        @Override
        protected QName createNewEmptyItem() {
            return new QName("");
        }

        @Override
        protected boolean buttonsDisabled() {
            return !isAnySelected();
        }

        @Override
        protected List<QName> createObjectList() {
            return syncDtoModel.getObject().getObjectClassList();
        }

        @Override
        protected String createAutoCompleteObjectLabel(QName object) {
            return object.getLocalPart();
        }

        @Override
        protected IValidator<String> createAutoCompleteValidator() {
            return createObjectClassValidator(new AbstractReadOnlyModel<List<QName>>() {
                @Override
                public List<QName> getObject() {
                    return syncDtoModel.getObject().getObjectClassList();
                }
            });
        }
    };
    parentPage.addEditingEnabledBehavior(editorObjectClass);
    editor.add(editorObjectClass);

    // TODO: switch to ObjectTypeSelectPanel
    DropDownChoice editorFocus = new DropDownChoice<>(ID_EDITOR_FOCUS,
            new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".focusType"),
            new AbstractReadOnlyModel<List<QName>>() {

                @Override
                public List<QName> getObject() {
                    return WebComponentUtil.createFocusTypeList();
                }
            }, new QNameChoiceRenderer());
    editorFocus.setNullValid(true);
    editorFocus.add(new UpdateNamesBehaviour());
    parentPage.addEditingEnabledBehavior(editorFocus);
    editor.add(editorFocus);

    CheckBox editorEnabled = new CheckBox(ID_EDITOR_ENABLED,
            new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".enabled"));
    parentPage.addEditingEnabledBehavior(editorEnabled);
    editor.add(editorEnabled);

    AjaxSubmitLink editorCondition = new AjaxSubmitLink(ID_EDITOR_BUTTON_CONDITION) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            conditionEditPerformed(target);
        }
    };
    addDisableClassModifier(editorCondition);
    editor.add(editorCondition);

    AjaxSubmitLink editorConfirmation = new AjaxSubmitLink(ID_EDITOR_BUTTON_CONFIRMATION) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            confirmationEditPerformed(target);
        }
    };
    addDisableClassModifier(editorConfirmation);
    editor.add(editorConfirmation);

    DropDownChoice editorObjectTemplate = new DropDownChoice<>(ID_EDITOR_OBJECT_TEMPLATE,
            new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".objectTemplateRef"),
            new AbstractReadOnlyModel<List<ObjectReferenceType>>() {

                @Override
                public List<ObjectReferenceType> getObject() {
                    return WebModelServiceUtils.createObjectReferenceList(ObjectTemplateType.class,
                            getPageBase(), syncDtoModel.getObject().getObjectTemplateMap());
                }
            }, new ObjectReferenceChoiceRenderer(syncDtoModel.getObject().getObjectTemplateMap()));
    editorObjectTemplate.setNullValid(true);
    parentPage.addEditingEnabledBehavior(editorObjectTemplate);
    editor.add(editorObjectTemplate);

    CheckBox editorReconcile = new CheckBox(ID_EDITOR_RECONCILE,
            new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".reconcile"));
    parentPage.addEditingEnabledBehavior(editorReconcile);
    editor.add(editorReconcile);

    TriStateComboPanel opportunistic = new TriStateComboPanel(ID_EDITOR_OPPORTUNISTIC,
            new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".opportunistic"));
    parentPage.addEditingEnabledBehavior(opportunistic);
    editor.add(opportunistic);

    MultiValueTextEditPanel editorCorrelation = new MultiValueTextEditPanel<ConditionalSearchFilterType>(
            ID_EDITOR_EDITOR_CORRELATION,
            new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".correlation"),
            new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED_CORRELATION), false, true,
            parentPage.getReadOnlyModel()) {

        @Override
        protected IModel<String> createTextModel(final IModel<ConditionalSearchFilterType> model) {
            return new Model<String>() {

                @Override
                public String getObject() {
                    StringBuilder sb = new StringBuilder();

                    ConditionalSearchFilterType searchFilter = model.getObject();
                    if (searchFilter != null && searchFilter.getDescription() != null) {
                        sb.append(searchFilter.getDescription());
                    }

                    if (sb.toString().isEmpty()) {
                        sb.append(getString("SynchronizationStep.label.notSpecified"));
                    }

                    return sb.toString();
                }
            };
        }

        @Override
        protected ConditionalSearchFilterType createNewEmptyItem() {
            return new ConditionalSearchFilterType();
        }

        @Override
        protected void editPerformed(AjaxRequestTarget target, ConditionalSearchFilterType object) {
            correlationEditPerformed(target, object);
        }

        @Override
        protected void performAddValueHook(AjaxRequestTarget target, ConditionalSearchFilterType added) {
            parentPage.refreshIssues(target);
        }

        @Override
        protected void performRemoveValueHook(AjaxRequestTarget target,
                ListItem<ConditionalSearchFilterType> item) {
            parentPage.refreshIssues(target);
        }

        @Override
        protected boolean buttonsDisabled() {
            return !isAnySelected();
        }
    };
    editor.add(editorCorrelation);

    MultiValueTextEditPanel editorReaction = new MultiValueTextEditPanel<SynchronizationReactionType>(
            ID_EDITOR_REACTION,
            new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".reaction"),
            new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED_REACTION), false, true,
            parentPage.getReadOnlyModel()) {

        @Override
        protected IModel<String> createTextModel(final IModel<SynchronizationReactionType> model) {
            return new Model<String>() {

                @Override
                public String getObject() {
                    SynchronizationReactionType reaction = model.getObject();
                    if (reaction == null) {
                        return "";
                    }
                    StringBuilder sb = new StringBuilder();
                    sb.append(reaction.getName() != null ? reaction.getName() + " " : "");
                    sb.append("(");
                    if (reaction.getSituation() != null) {
                        sb.append(reaction.getSituation());
                    }
                    if (Boolean.TRUE.equals(reaction.isSynchronize()) || !reaction.getAction().isEmpty()) {
                        sb.append(" -> ");
                        if (!reaction.getAction().isEmpty()) {
                            boolean first = true;
                            for (SynchronizationActionType action : reaction.getAction()) {
                                if (first) {
                                    first = false;
                                } else {
                                    sb.append(", ");
                                }
                                sb.append(StringUtils.substringAfter(action.getHandlerUri(), "#"));
                            }
                        } else {
                            sb.append("sync"); // TODO i18n
                        }
                    }
                    sb.append(")");
                    return sb.toString();
                }
            };
        }

        @Override
        protected SynchronizationReactionType createNewEmptyItem() {
            return new SynchronizationReactionType();
        }

        @Override
        protected void editPerformed(AjaxRequestTarget target, SynchronizationReactionType object) {
            reactionEditPerformed(target, object);
        }

        @Override
        protected void performAddValueHook(AjaxRequestTarget target, SynchronizationReactionType added) {
            parentPage.refreshIssues(target);
        }

        @Override
        protected void performRemoveValueHook(AjaxRequestTarget target,
                ListItem<SynchronizationReactionType> item) {
            parentPage.refreshIssues(target);
        }

        @Override
        protected boolean buttonsDisabled() {
            return !isAnySelected();
        }
    };
    editorReaction.setOutputMarkupId(true);
    editor.add(editorReaction);

    Label kindTooltip = new Label(ID_T_KIND);
    kindTooltip.add(new InfoTooltipBehavior());
    editor.add(kindTooltip);

    Label intentTooltip = new Label(ID_T_INTENT);
    intentTooltip.add(new InfoTooltipBehavior());
    editor.add(intentTooltip);

    Label objClassTooltip = new Label(ID_T_OBJ_CLASS);
    objClassTooltip.add(new InfoTooltipBehavior());
    editor.add(objClassTooltip);

    Label focusTooltip = new Label(ID_T_FOCUS);
    focusTooltip.add(new InfoTooltipBehavior());
    editor.add(focusTooltip);

    Label enabledTooltip = new Label(ID_T_ENABLED);
    enabledTooltip.add(new InfoTooltipBehavior());
    editor.add(enabledTooltip);

    Label conditionTooltip = new Label(ID_T_CONDITION);
    conditionTooltip.add(new InfoTooltipBehavior());
    editor.add(conditionTooltip);

    Label confirmationTooltip = new Label(ID_T_CONFIRMATION);
    confirmationTooltip.add(new InfoTooltipBehavior());
    editor.add(confirmationTooltip);

    Label objTemplateTooltip = new Label(ID_T_OBJ_TEMPLATE);
    objTemplateTooltip.add(new InfoTooltipBehavior());
    editor.add(objTemplateTooltip);

    Label reconcileTooltip = new Label(ID_T_RECONCILE);
    reconcileTooltip.add(new InfoTooltipBehavior());
    editor.add(reconcileTooltip);

    Label opportunisticTooltip = new Label(ID_T_OPPORTUNISTIC);
    opportunisticTooltip.add(new InfoTooltipBehavior());
    editor.add(opportunisticTooltip);

    Label correlationTooltip = new Label(ID_T_CORRELATION);
    correlationTooltip.add(new InfoTooltipBehavior());
    editor.add(correlationTooltip);

    Label reactionTooltip = new Label(ID_T_REACTION);
    reactionTooltip.add(new InfoTooltipBehavior());
    editor.add(reactionTooltip);
}

From source file:cgeo.geocaching.connector.oc.OkapiClient.java

private static Geopoint parseCoords(final String location) {
    final String latitude = StringUtils.substringBefore(location, SEPARATOR_STRING);
    final String longitude = StringUtils.substringAfter(location, SEPARATOR_STRING);
    if (StringUtils.isNotBlank(latitude) && StringUtils.isNotBlank(longitude)) {
        return new Geopoint(latitude, longitude);
    }/*from ww  w  .j  a v  a2 s.  c  o  m*/

    return null;
}

From source file:cgeo.geocaching.connector.oc.OkapiClient.java

private static void setLocation(final Geocache cache, final String location) {
    final String latitude = StringUtils.substringBefore(location, SEPARATOR_STRING);
    final String longitude = StringUtils.substringAfter(location, SEPARATOR_STRING);
    cache.setCoords(new Geopoint(latitude, longitude));
}

From source file:com.google.dart.java2dart.SyntaxTranslator.java

@Override
public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) {
    IMethodBinding binding = node.resolveConstructorBinding();
    String signature = JavaUtils.getJdtSignature(binding);
    TypeName typeNameNode = (TypeName) translate(node.getType());
    final List<Expression> arguments = translateArguments(binding, node.arguments());
    final ClassDeclaration innerClass;
    {//w w  w .  j  a  v a 2 s . c om
        AnonymousClassDeclaration anoDeclaration = node.getAnonymousClassDeclaration();
        if (anoDeclaration != null) {
            ITypeBinding superclass = anoDeclaration.resolveBinding().getSuperclass();
            signature = superclass.getKey() + StringUtils.substringAfter(signature, ";");
            String name = typeNameNode.getName().getName().replace('.', '_');
            name = name + "_" + context.generateTechnicalAnonymousClassIndex();
            innerClass = declareInnerClass(binding, anoDeclaration, name, ArrayUtils.EMPTY_STRING_ARRAY);
            typeNameNode = typeName(name);
            // prepare enclosing type
            final ITypeBinding enclosingTypeBinding = getEnclosingTypeBinding(node);
            final SimpleIdentifier enclosingTypeRef;
            final AtomicBoolean addEnclosingTypeRef = new AtomicBoolean();
            {
                if (enclosingTypeBinding != null) {
                    enclosingTypeRef = identifier(enclosingTypeBinding.getName() + "_this");
                    // add enclosing class references
                    innerClass.accept(new RecursiveASTVisitor<Void>() {
                        @Override
                        public Void visitMethodInvocation(MethodInvocation node) {
                            if (node.getTarget() == null) {
                                IMethodBinding methodBinding = (IMethodBinding) context.getNodeBinding(node);
                                if (methodBinding != null
                                        && methodBinding.getDeclaringClass() == enclosingTypeBinding) {
                                    addEnclosingTypeRef.set(true);
                                    node.setTarget(enclosingTypeRef);
                                }
                            }
                            return super.visitMethodInvocation(node);
                        }

                        @Override
                        public Void visitSimpleIdentifier(SimpleIdentifier node) {
                            if (!(node.getParent() instanceof PropertyAccess)
                                    && !(node.getParent() instanceof PrefixedIdentifier)) {
                                Object binding = context.getNodeBinding(node);
                                if (binding instanceof IVariableBinding) {
                                    IVariableBinding variableBinding = (IVariableBinding) binding;
                                    if (variableBinding.isField()
                                            && variableBinding.getDeclaringClass() == enclosingTypeBinding) {
                                        addEnclosingTypeRef.set(true);
                                        replaceNode(node.getParent(), node,
                                                propertyAccess(enclosingTypeRef, node));
                                    }
                                }
                            }
                            return super.visitSimpleIdentifier(node);
                        }
                    });
                } else {
                    enclosingTypeRef = null;
                }
            }
            // declare referenced final variables XXX
            final String finalName = name;
            anoDeclaration.accept(new ASTVisitor() {
                final Set<org.eclipse.jdt.core.dom.IVariableBinding> addedParameters = Sets.newHashSet();
                final List<FormalParameter> constructorParameters = Lists.newArrayList();
                int index;

                @Override
                public void endVisit(AnonymousClassDeclaration node) {
                    if (!constructorParameters.isEmpty()) {
                        // add parameters to the existing "inner" constructor XXX
                        for (ClassMember classMember : innerClass.getMembers()) {
                            if (classMember instanceof ConstructorDeclaration) {
                                ConstructorDeclaration innerConstructor = (ConstructorDeclaration) classMember;
                                innerConstructor.getParameters().getParameters().addAll(constructorParameters);
                                return;
                            }
                        }
                        // create new "inner" constructor
                        innerClass.getMembers().add(index, constructorDeclaration(identifier(finalName), null,
                                formalParameterList(constructorParameters), null));
                    }
                    super.endVisit(node);
                }

                @Override
                public void endVisit(SimpleName node) {
                    IBinding nameBinding = node.resolveBinding();
                    if (nameBinding instanceof org.eclipse.jdt.core.dom.IVariableBinding) {
                        org.eclipse.jdt.core.dom.IVariableBinding variableBinding = (org.eclipse.jdt.core.dom.IVariableBinding) nameBinding;
                        org.eclipse.jdt.core.dom.MethodDeclaration enclosingMethod = getEnclosingMethod(node);
                        if (!variableBinding.isField() && enclosingMethod != null
                                && variableBinding.getDeclaringMethod() != enclosingMethod.resolveBinding()
                                && addedParameters.add(variableBinding)) {
                            TypeName parameterTypeName = translateTypeName(variableBinding.getType());
                            String parameterName = variableBinding.getName();
                            SimpleIdentifier parameterNameNode = identifier(parameterName);
                            innerClass.getMembers().add(index++, fieldDeclaration(parameterTypeName,
                                    variableDeclaration(parameterNameNode)));
                            constructorParameters.add(fieldFormalParameter(null, null, parameterNameNode));
                            arguments.add(parameterNameNode);
                            context.putReference(parameterNameNode, variableBinding, null);
                        }
                    }
                    super.endVisit(node);
                }

                @Override
                public boolean visit(AnonymousClassDeclaration node) {
                    if (addEnclosingTypeRef.get()) {
                        TypeName parameterTypeName = translateTypeName(enclosingTypeBinding);
                        innerClass.getMembers().add(index++, fieldDeclaration(false, Keyword.FINAL,
                                parameterTypeName, variableDeclaration(enclosingTypeRef)));
                        constructorParameters.add(fieldFormalParameter(null, null, enclosingTypeRef));
                        arguments.add(thisExpression());
                    }
                    return super.visit(node);
                }
            });
        } else {
            innerClass = null;
        }
    }
    InstanceCreationExpression creation = instanceCreationExpression(Keyword.NEW, typeNameNode, null,
            arguments);
    context.putNodeBinding(creation, binding);
    context.putAnonymousDeclaration(creation, innerClass);
    context.getConstructorDescription(binding).instanceCreations.add(creation);
    return done(creation);
}

From source file:de.blizzy.documentr.web.page.PageController.java

@RequestMapping(value = "/cherryPick/{projectName:" + DocumentrConstants.PROJECT_NAME_PATTERN + "}/"
        + "{branchName:" + DocumentrConstants.BRANCH_NAME_PATTERN + "}/" + "{path:"
        + DocumentrConstants.PAGE_PATH_URL_PATTERN + "}", method = RequestMethod.POST)
@PreAuthorize("hasPagePermission(#projectName, #branchName, #path, VIEW)")
public String cherryPick(@PathVariable String projectName, @PathVariable String branchName,
        @PathVariable String path, @RequestParam String version1, @RequestParam String version2,
        @RequestParam("branch") Set<String> targetBranches, @RequestParam boolean dryRun, WebRequest request,
        Model model, Authentication authentication, Locale locale) throws IOException {

    path = Util.toRealPagePath(path);

    for (String targetBranch : targetBranches) {
        if (!permissionEvaluator.hasPagePermission(authentication, projectName, targetBranch, path,
                Permission.EDIT_PAGE)) {

            return ErrorController.forbidden();
        }/* w ww  . j  a  v a  2s  .  c o m*/
    }

    List<String> commits = cherryPicker.getCommitsList(projectName, branchName, path, version1, version2);
    if (commits.isEmpty()) {
        throw new IllegalArgumentException("no commits to cherry-pick"); //$NON-NLS-1$
    }

    User user = userStore.getUser(authentication.getName());

    Map<String, String[]> params = request.getParameterMap();
    Set<CommitCherryPickConflictResolve> resolves = Sets.newHashSet();
    for (Map.Entry<String, String[]> entry : params.entrySet()) {
        String name = entry.getKey();
        if (name.startsWith("resolveText_")) { //$NON-NLS-1$
            String branchCommit = StringUtils.substringAfter(name, "_"); //$NON-NLS-1$
            String branch = StringUtils.substringBefore(branchCommit, "/"); //$NON-NLS-1$
            String commit = StringUtils.substringAfter(branchCommit, "/"); //$NON-NLS-1$
            String text = entry.getValue()[0];
            CommitCherryPickConflictResolve resolve = new CommitCherryPickConflictResolve(branch, commit, text);
            resolves.add(resolve);
        }
    }

    Map<String, List<CommitCherryPickResult>> results = cherryPicker.cherryPick(projectName, branchName, path,
            commits, targetBranches, resolves, dryRun, user, locale);
    if (results.keySet().size() != targetBranches.size()) {
        throw new IllegalStateException();
    }

    if (!dryRun) {
        boolean allOk = true;
        loop: for (List<CommitCherryPickResult> branchResults : results.values()) {
            for (CommitCherryPickResult result : branchResults) {
                if (result.getStatus() != CommitCherryPickResult.Status.OK) {
                    allOk = false;
                    break loop;
                }
            }
        }

        if (allOk) {
            return "redirect:/page/" + projectName + "/" + branchName + //$NON-NLS-1$ //$NON-NLS-2$
                    "/" + Util.toUrlPagePath(path); //$NON-NLS-1$
        }
    }

    model.addAttribute("cherryPickResults", results); //$NON-NLS-1$
    model.addAttribute("version1", version1); //$NON-NLS-1$
    model.addAttribute("version2", version2); //$NON-NLS-1$
    model.addAttribute("resolves", resolves); //$NON-NLS-1$
    return "/project/branch/page/cherryPick"; //$NON-NLS-1$
}

From source file:de.micromata.genome.util.types.Converter.java

/**
 * convert delimited string to map./* ww  w  . j a v  a 2  s.co m*/
 *
 * @param str String to Convert
 * @param d1 Delimiter zwischen den Eintrgen
 * @param d2 Delimiter zwischen den key=value Paaren
 * @return the map
 */
public static Map<String, String> delimitedStringToMap(String str, String d1, String d2) {
    String[] fields = StringUtils.split(str, d1);
    Map<String, String> map = new HashMap<String, String>();
    for (String fld : fields) {
        String key = StringUtils.substringBefore(fld, d2);
        String val = StringUtils.substringAfter(fld, d2);
        map.put(key, val);
    }
    return map;
}

From source file:com.zhumeng.dream.orm.hibernate.HibernateDao.java

private String prepareCountSql(String orgSql) {
    String fromHql = orgSql;/*from   w  w w.  jav a  2  s.  c  o m*/
    //select??order by???count,?.
    fromHql = "from " + StringUtils.substringAfter(fromHql, "from");
    //      fromHql = StringUtils.substringBefore(fromHql, "order by");

    String countHql = "select count(*) " + fromHql;
    return countHql;
}