Search in sources :

Example 6 with StringUtils.replace

use of org.apache.commons.lang3.StringUtils.replace in project Gargoyle by callakrsos.

the class CommonsSqllPan method menuExportInsertScriptOnAction.

@Override
public void menuExportInsertScriptOnAction(ActionEvent e) {
    Optional<Pair<String, String[]>> showTableInputDialog = showTableInputDialog(f -> f.getName());
    //		Optional<Pair<String, String>> showInputDialog = DialogUtil.showInputDialog("table Name", "테이블명을 입력하세요.");
    if (showTableInputDialog == null)
        return;
    showTableInputDialog.ifPresent(op -> {
        if (op == null || op.getValue() == null)
            return;
        String schemaName = op.getValue()[0];
        String _tableName = op.getValue()[1];
        String tableName = "";
        if (ValueUtil.isNotEmpty(schemaName)) {
            tableName = String.format("%s.%s", schemaName, _tableName);
        } else {
            tableName = _tableName;
        }
        List<Map<String, Object>> items = getSelectedTabResultItems();
        Map<String, Object> map = items.get(0);
        final Set<String> keySet = map.keySet();
        StringBuilder clip = new StringBuilder();
        String insertPreffix = "insert into " + tableName;
        String collect = keySet.stream().collect(Collectors.joining(",", "(", ")"));
        String insertMiddle = " values ";
        List<String> valueList = items.stream().map(v -> {
            return ValueUtil.toJSONObject(v);
        }).map(v -> {
            Iterator<String> iterator = keySet.iterator();
            List<Object> values = new ArrayList<>();
            while (iterator.hasNext()) {
                String columnName = iterator.next();
                Object value = v.get(columnName);
                values.add(value);
            }
            return values;
        }).map(list -> {
            return list.stream().map(str -> {
                if (str == null)
                    return null;
                else {
                    String convert = str.toString();
                    convert = convert.substring(1, convert.length() - 1);
                    if (convert.indexOf("'") >= 0) {
                        try {
                            convert = StringUtils.replace(convert, "'", "''");
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                    return "'".concat(convert).concat("'");
                }
            }).collect(Collectors.joining(",", "(", ")"));
        }).map(str -> {
            return new StringBuilder().append(insertPreffix).append(collect).append(insertMiddle).append(str).append(";\n").toString();
        }).collect(Collectors.toList());
        valueList.forEach(str -> {
            clip.append(str);
        });
        SimpleTextView parent = new SimpleTextView(clip.toString());
        parent.setWrapText(false);
        FxUtil.createStageAndShow(String.format("[InsertScript] Table : %s", tableName), parent, stage -> {
        });
    });
}
Also used : Connection(java.sql.Connection) DbUtil(com.kyj.fx.voeditor.visual.util.DbUtil) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) SchemaItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.SchemaItemTree) Map(java.util.Map) ColumnItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.ColumnItemTree) TableInformationUserMetadataVO(com.kyj.fx.voeditor.visual.component.sql.table.TableInformationUserMetadataVO) Pair(javafx.util.Pair) DatabaseTreeNode(com.kyj.fx.voeditor.visual.component.sql.dbtree.DatabaseTreeNode) Set(java.util.Set) KeyEvent(javafx.scene.input.KeyEvent) SimpleTextView(com.kyj.fx.voeditor.visual.component.text.SimpleTextView) ConfigResourceLoader(com.kyj.fx.voeditor.visual.momory.ConfigResourceLoader) Collectors(java.util.stream.Collectors) TreeView(javafx.scene.control.TreeView) TableInformationFrameView(com.kyj.fx.voeditor.visual.component.sql.table.TableInformationFrameView) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) ResourceLoader(com.kyj.fx.voeditor.visual.momory.ResourceLoader) DatabaseItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.DatabaseItemTree) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) Scene(javafx.scene.Scene) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException) ResultSetToMapConverter(com.kyj.fx.voeditor.visual.functions.ResultSetToMapConverter) TreeItem(javafx.scene.control.TreeItem) MouseEvent(javafx.scene.input.MouseEvent) HashMap(java.util.HashMap) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) Constructor(java.lang.reflect.Constructor) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) TableItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.TableItemTree) BiConsumer(java.util.function.BiConsumer) KeyCode(javafx.scene.input.KeyCode) Properties(java.util.Properties) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FxClipboardUtil(com.kyj.fx.voeditor.visual.util.FxClipboardUtil) IOException(java.io.IOException) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) GagoyleParamEmptyException(com.kyj.fx.voeditor.visual.exceptions.GagoyleParamEmptyException) Consumer(java.util.function.Consumer) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) NotYetSupportException(com.kyj.fx.voeditor.visual.exceptions.NotYetSupportException) DatabaseTreeCallback(com.kyj.fx.voeditor.visual.component.sql.dbtree.DatabaseTreeCallback) Collections(java.util.Collections) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException) SQLException(java.sql.SQLException) IOException(java.io.IOException) GagoyleParamEmptyException(com.kyj.fx.voeditor.visual.exceptions.GagoyleParamEmptyException) NotYetSupportException(com.kyj.fx.voeditor.visual.exceptions.NotYetSupportException) Iterator(java.util.Iterator) SimpleTextView(com.kyj.fx.voeditor.visual.component.text.SimpleTextView) List(java.util.List) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Pair(javafx.util.Pair)

Example 7 with StringUtils.replace

use of org.apache.commons.lang3.StringUtils.replace in project eol-globi-data by jhpoelen.

the class CitationUtil method getDOI.

public static String getDOI(Dataset dataset) {
    String doi = dataset.getOrDefault("doi", "");
    URI archiveURI = dataset.getArchiveURI();
    if (StringUtils.isBlank(doi)) {
        String recordZenodo = StringUtils.replace(archiveURI.toString(), ZENODO_URL_PREFIX, "");
        String[] split = recordZenodo.split("/");
        if (split.length > 0) {
            doi = "https://doi.org/10.5281/zenodo." + split[0];
        }
    }
    return doi;
}
Also used : StringUtils.defaultString(org.apache.commons.lang3.StringUtils.defaultString) URI(java.net.URI)

Example 8 with StringUtils.replace

use of org.apache.commons.lang3.StringUtils.replace in project symja_android_library by axkr.

the class F method showGraphic.

public static String showGraphic(IExpr expr) {
    try {
        if (expr.isSameHeadSizeGE(Graphics, 2)) {
            return openSVGOnDesktop((IAST) expr);
        } else if (expr.isSameHeadSizeGE(Graphics3D, 2)) {
            StringBuilder buf = new StringBuilder();
            if (GraphicsFunctions.renderGraphics3D(buf, (IAST) expr, EvalEngine.get())) {
                try {
                    String manipulateStr = buf.toString();
                    String html = JSBuilder.buildGraphics3D(JSBuilder.GRAPHICS3D_TEMPLATE, manipulateStr);
                    return openHTMLOnDesktop(html);
                } catch (Exception ex) {
                    LOGGER.debug("JSBuilder.buildGraphics3D() failed", ex);
                }
            }
        } else if (expr instanceof GraphExpr) {
            String javaScriptStr = GraphFunctions.graphToJSForm((GraphExpr) expr);
            if (javaScriptStr != null) {
                String html = Config.VISJS_PAGE;
                html = StringUtils.replace(html, "`1`", javaScriptStr);
                html = StringUtils.replace(html, "`2`", "var options = {};");
                return openHTMLOnDesktop(html);
            }
        } else if (expr.isAST(JSFormData, 3)) {
            return printJSFormData(expr);
        } else if (expr.isString()) {
            IStringX str = (IStringX) expr;
            if (str.getMimeType() == IStringX.TEXT_HTML) {
                String htmlSnippet = str.toString();
                String htmlPage = Config.HTML_PAGE;
                htmlPage = StringUtils.replace(htmlPage, "`1`", htmlSnippet);
                EvalEngine.get().getOutPrintStream().println(htmlPage);
                return openHTMLOnDesktop(htmlPage);
            }
        } else if (expr.isList(x -> x.isAST(JSFormData, 3))) {
            StringBuilder buf = new StringBuilder();
            ((IAST) expr).forEach(x -> buf.append(printJSFormData(x)));
            return buf.toString();
        }
    } catch (Exception ex) {
        LOGGER.debug("F.showGraphic() failed", ex);
    }
    return null;
}
Also used : ExprParserFactory(org.matheclipse.core.parser.ExprParserFactory) ManipulateFunction(org.matheclipse.core.builtin.ManipulateFunction) Apcomplex(org.apfloat.Apcomplex) IAssumptions(org.matheclipse.core.eval.util.IAssumptions) GraphDataFunctions(org.matheclipse.core.builtin.GraphDataFunctions) IOFunctions(org.matheclipse.core.builtin.IOFunctions) StringUtils(org.apache.commons.lang3.StringUtils) IComplex(org.matheclipse.core.interfaces.IComplex) BoxesFunctions(org.matheclipse.core.builtin.BoxesFunctions) ComputationalGeometryFunctions(org.matheclipse.core.builtin.ComputationalGeometryFunctions) EllipticIntegrals(org.matheclipse.core.builtin.EllipticIntegrals) MinMaxFunctions(org.matheclipse.core.builtin.MinMaxFunctions) Lambda(org.matheclipse.core.eval.util.Lambda) Map(java.util.Map) BigInteger(java.math.BigInteger) ISparseArray(org.matheclipse.core.interfaces.ISparseArray) ListFunctions(org.matheclipse.core.builtin.ListFunctions) IComplexNum(org.matheclipse.core.interfaces.IComplexNum) EvalEngine(org.matheclipse.core.eval.EvalEngine) BiIntFunction(org.matheclipse.core.eval.util.BiIntFunction) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IntervalFunctions(org.matheclipse.core.builtin.IntervalFunctions) GeodesyFunctions(org.matheclipse.core.builtin.GeodesyFunctions) ISymbol(org.matheclipse.core.interfaces.ISymbol) FinancialFunctions(org.matheclipse.core.builtin.FinancialFunctions) ComputerThreads(edu.jas.kern.ComputerThreads) VisitorLevelSpecification(org.matheclipse.core.visit.VisitorLevelSpecification) CountDownLatch(java.util.concurrent.CountDownLatch) IASTMutable(org.matheclipse.core.interfaces.IASTMutable) Logger(org.apache.logging.log4j.Logger) NumericArrayFunctions(org.matheclipse.core.builtin.NumericArrayFunctions) RootsFunctions(org.matheclipse.core.builtin.RootsFunctions) EvalAttributes(org.matheclipse.core.eval.EvalAttributes) IntegerFunctions(org.matheclipse.core.builtin.IntegerFunctions) IAssociation(org.matheclipse.core.interfaces.IAssociation) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) SourceCodeFunctions(org.matheclipse.core.builtin.SourceCodeFunctions) ApfloatContext(org.apfloat.ApfloatContext) OutputFunctions(org.matheclipse.core.builtin.OutputFunctions) RandomFunctions(org.matheclipse.core.builtin.RandomFunctions) GraphicsFunctions(org.matheclipse.core.builtin.GraphicsFunctions) TrieMatch(org.matheclipse.parser.trie.TrieMatch) Algebra(org.matheclipse.core.builtin.Algebra) SyntaxError(org.matheclipse.parser.client.SyntaxError) IntFunction(java.util.function.IntFunction) AssociationFunctions(org.matheclipse.core.builtin.AssociationFunctions) ConstantDefinitions(org.matheclipse.core.builtin.ConstantDefinitions) IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) BufferedWriter(java.io.BufferedWriter) Combinatoric(org.matheclipse.core.builtin.Combinatoric) FunctionDefinitions(org.matheclipse.core.builtin.FunctionDefinitions) Config(org.matheclipse.core.basic.Config) IOException(java.io.IOException) AbstractCoreFunctionEvaluator(org.matheclipse.core.eval.interfaces.AbstractCoreFunctionEvaluator) QuantityParser(org.matheclipse.core.tensor.QuantityParser) File(java.io.File) Programming(org.matheclipse.core.builtin.Programming) HypergeometricFunctions(org.matheclipse.core.builtin.HypergeometricFunctions) ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) SimplifyFunctions(org.matheclipse.core.builtin.SimplifyFunctions) IExpr(org.matheclipse.core.interfaces.IExpr) AssumptionFunctions(org.matheclipse.core.builtin.AssumptionFunctions) ICoreFunctionEvaluator(org.matheclipse.core.eval.interfaces.ICoreFunctionEvaluator) SeriesFunctions(org.matheclipse.core.builtin.SeriesFunctions) IStringX(org.matheclipse.core.interfaces.IStringX) BiFunction(java.util.function.BiFunction) Functors(org.matheclipse.core.generic.Functors) TensorFunctions(org.matheclipse.core.builtin.TensorFunctions) IInteger(org.matheclipse.core.interfaces.IInteger) QuantityFunctions(org.matheclipse.core.builtin.QuantityFunctions) PreemptStatus(edu.jas.kern.PreemptStatus) Apfloat(org.apfloat.Apfloat) INumber(org.matheclipse.core.interfaces.INumber) Arithmetic(org.matheclipse.core.builtin.Arithmetic) BooleanFunctions(org.matheclipse.core.builtin.BooleanFunctions) ClusteringFunctions(org.matheclipse.core.builtin.ClusteringFunctions) Locale(java.util.Locale) StatisticsFunctions(org.matheclipse.core.builtin.StatisticsFunctions) FileFunctions(org.matheclipse.core.builtin.FileFunctions) IPatternSequence(org.matheclipse.core.interfaces.IPatternSequence) IdentityHashMap(java.util.IdentityHashMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) JSBuilder(org.matheclipse.core.form.output.JSBuilder) PredicateQ(org.matheclipse.core.builtin.PredicateQ) StringFunctions(org.matheclipse.core.builtin.StringFunctions) ExprParser(org.matheclipse.core.parser.ExprParser) ExpTrigsFunctions(org.matheclipse.core.builtin.ExpTrigsFunctions) PolynomialFunctions(org.matheclipse.core.builtin.PolynomialFunctions) WXFFunctions(org.matheclipse.core.builtin.WXFFunctions) SidesFunctions(org.matheclipse.core.builtin.SidesFunctions) SparseArrayFunctions(org.matheclipse.core.builtin.SparseArrayFunctions) CacheBuilder(com.google.common.cache.CacheBuilder) AST2Expr(org.matheclipse.core.convert.AST2Expr) ParserConfig(org.matheclipse.parser.client.ParserConfig) AttributeFunctions(org.matheclipse.core.builtin.AttributeFunctions) GraphExpr(org.matheclipse.core.expression.data.GraphExpr) LinearAlgebra(org.matheclipse.core.builtin.LinearAlgebra) CurveFitterFunctions(org.matheclipse.core.builtin.CurveFitterFunctions) ASTElementLimitExceeded(org.matheclipse.core.eval.exception.ASTElementLimitExceeded) VectorAnalysisFunctions(org.matheclipse.core.builtin.VectorAnalysisFunctions) IFraction(org.matheclipse.core.interfaces.IFraction) Function(java.util.function.Function) ImageFunctions(org.matheclipse.core.builtin.ImageFunctions) BiPredicate(java.util.function.BiPredicate) WindowFunctions(org.matheclipse.core.builtin.WindowFunctions) SpecialFunctions(org.matheclipse.core.builtin.SpecialFunctions) Documentation(org.matheclipse.core.form.Documentation) IPattern(org.matheclipse.core.interfaces.IPattern) CompilerFunctions(org.matheclipse.core.builtin.CompilerFunctions) EntityFunctions(org.matheclipse.core.builtin.EntityFunctions) SparseArrayExpr(org.matheclipse.core.expression.data.SparseArrayExpr) Desktop(java.awt.Desktop) StructureFunctions(org.matheclipse.core.builtin.StructureFunctions) IPatternMatcher(org.matheclipse.core.patternmatching.IPatternMatcher) IAST(org.matheclipse.core.interfaces.IAST) IPatternMap(org.matheclipse.core.patternmatching.IPatternMap) Complex(org.hipparchus.complex.Complex) FileWriter(java.io.FileWriter) INum(org.matheclipse.core.interfaces.INum) GraphFunctions(org.matheclipse.core.builtin.GraphFunctions) NumberTheory(org.matheclipse.core.builtin.NumberTheory) ContainsFunctions(org.matheclipse.core.builtin.ContainsFunctions) Field(org.hipparchus.Field) Object2Expr(org.matheclipse.core.convert.Object2Expr) PatternMatching(org.matheclipse.core.builtin.PatternMatching) IRational(org.matheclipse.core.interfaces.IRational) BesselFunctions(org.matheclipse.core.builtin.BesselFunctions) JavaFunctions(org.matheclipse.core.builtin.JavaFunctions) BigFraction(org.hipparchus.fraction.BigFraction) UnitTestingFunctions(org.matheclipse.core.builtin.UnitTestingFunctions) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) GraphExpr(org.matheclipse.core.expression.data.GraphExpr) IAST(org.matheclipse.core.interfaces.IAST) IStringX(org.matheclipse.core.interfaces.IStringX) IOException(java.io.IOException)

Example 9 with StringUtils.replace

use of org.apache.commons.lang3.StringUtils.replace in project cas by apereo.

the class Log4jInitialization method setMainArguments.

@Override
public void setMainArguments(final String[] mainArguments) {
    val args = Arrays.stream(mainArguments).filter(arg -> arg.startsWith("--logging.level")).map(arg -> StringUtils.replace(arg, "=", " ")).toArray(String[]::new);
    MainMapLookup.setMainArguments(args);
}
Also used : lombok.val(lombok.val) LoggingInitialization(org.apereo.cas.util.logging.LoggingInitialization) Arrays(java.util.Arrays) lombok.val(lombok.val) MainMapLookup(org.apache.logging.log4j.core.lookup.MainMapLookup) StringUtils(org.apache.commons.lang3.StringUtils) NoArgsConstructor(lombok.NoArgsConstructor)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)7 Map (java.util.Map)6 IOException (java.io.IOException)4 Set (java.util.Set)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 DatabaseTreeNode (com.kyj.fx.voeditor.visual.component.sql.dbtree.DatabaseTreeNode)2 DatabaseItemTree (com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.DatabaseItemTree)2 TableItemTree (com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.TableItemTree)2 SimpleTextView (com.kyj.fx.voeditor.visual.component.text.SimpleTextView)2 ConfigResourceLoader (com.kyj.fx.voeditor.visual.momory.ConfigResourceLoader)2 ResourceLoader (com.kyj.fx.voeditor.visual.momory.ResourceLoader)2 DialogUtil (com.kyj.fx.voeditor.visual.util.DialogUtil)2 FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)2 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)2 Collections (java.util.Collections)2 Date (java.util.Date)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2