List of usage examples for org.apache.commons.lang3 StringUtils abbreviate
public static String abbreviate(final String str, final int maxWidth)
Abbreviates a String using ellipses.
From source file:org.kalypso.kalypsomodel1d2d.ui.map.temsys.ElevationListDescriptionProvider.java
@Override public String getText(final Object element) { if (element instanceof ITerrainElevationModel) { final String description = ((ITerrainElevationModel) element).getDescription(); if (StringUtils.isEmpty(description)) return StringUtils.EMPTY; // REMARK: column should not get too big... return StringUtils.abbreviate(description, 50); }//from w ww.j a va 2s. c o m throw new RuntimeException(Messages .getString("org.kalypso.kalypsomodel1d2d.ui.map.temsys.ElevationModelSystemEditorComponent.0") //$NON-NLS-1$ + Messages.getString( "org.kalypso.kalypsomodel1d2d.ui.map.temsys.ElevationModelSystemEditorComponent.1") //$NON-NLS-1$ + (element == null ? null : element.getClass()) + "\n\t value=" + element); //$NON-NLS-1$ }
From source file:org.kalypso.model.wspm.pdb.internal.waterlevel2d.AggregatedWaterlevel.java
/** build description from all waterlevels */ String getDescription() throws MismatchedDimensionException, FactoryException, TransformException { final ProjectedWaterlevel[] waterlevels = getWaterlevels(); final Set<String> descriptions = new LinkedHashSet<>(); for (final ProjectedWaterlevel waterlevel : waterlevels) { /* collect description, ignore blanks/empty */ final String description = waterlevel.getDescription(); descriptions.add(StringUtils.trimToNull(description)); }/*from w w w . j av a 2 s . co m*/ /* Build combined description without null elements */ descriptions.remove(null); final String joined = StringUtils.join(descriptions, ", "); //$NON-NLS-1$ final int maxLength = PdbMappingUtils.findLength(CrossSectionPart.class, CrossSectionPart.PROPERTY_DESCRIPTION); return StringUtils.abbreviate(joined, maxLength); }
From source file:org.kalypso.model.wspm.tuhh.ui.export.bankline.BanklineExportShapeWorker.java
private void addData(final Feature element, final IProgressMonitor monitor) throws ShapeDataException, GM_Exception { monitor.beginTask(Messages.getString("BanklineExportShapeWorker_11"), 1); //$NON-NLS-1$ // The built geometries are in Kalypso-SRS, because the geometries are derived from the wspm-workspace final String kalypsoSrs = KalypsoDeegreePlugin.getDefault().getCoordinateSystem(); final BanklineBuilder exporter = new BanklineBuilder(element, m_markerProvider, m_densifyDistance); final IStatus status = exporter.execute(monitor); if (!status.isOK()) m_log.add(status);/*from w w w . ja va 2 s . c o m*/ final Geometry banklineGeometry = exporter.getBanklineGeometry(); if (banklineGeometry != null) { final Object[] data = new Object[5]; final WspmWaterBody water = exporter.getWaterBody(); final TuhhReach reach = exporter.getReach(); final String waterName = water == null ? StringUtils.EMPTY : water.getName(); final String refId = water == null ? StringUtils.EMPTY : water.getRefNr(); final String reachName = reach == null ? StringUtils.EMPTY : reach.getName(); data[0] = StringUtils.abbreviate(waterName, FIELD_LENGTH_NAME); data[1] = StringUtils.abbreviate(refId, FIELD_LENGTH_NAME); data[2] = StringUtils.abbreviate(reachName, FIELD_LENGTH_NAME); data[3] = StringUtils.abbreviate(element.getFeatureType().getQName().getLocalPart(), FIELD_LENGTH_TYPE); data[4] = StringUtils.abbreviate(status.getMessage(), FIELD_LENGTH_STATUS); final List<?> geometries = GeometryExtracter.extract(banklineGeometry, Polygon.class); for (final Object geom : geometries) addShapeElement((Geometry) geom, kalypsoSrs, data); } monitor.done(); }
From source file:org.kalypso.model.wspm.tuhh.ui.internal.gml.WspmReachNamesDecorator.java
private void decorateProfile(final IProfileFeature profile, final IDecoration decoration) { final WspmWaterBody water = profile.getWater(); if (water == null) return;//from w w w .jav a2 s. c o m final String[] reachNames = collectReachNames(water, profile); if (ArrayUtils.isEmpty(reachNames)) return; final String names = StringUtils.join(reachNames, ", "); //$NON-NLS-1$ final String suffix = String.format(Messages.getString("WspmReachNamesDecorator_0"), names); //$NON-NLS-1$ final String shortenedSuffix = StringUtils.abbreviate(suffix, 255); decoration.addSuffix(shortenedSuffix); }
From source file:org.kalypso.module.project.local.ProjectHandlesComposite.java
private void renderProject(final Composite body, final IAction mainAction, final IAction[] actions, final String name, final String description) { final Control mainControl = renderAction(body, mainAction, name); mainControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); for (final IAction action : actions) { final Control control = renderAction(body, action, name); control.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); }//from w ww . j a v a 2 s. co m // renderAction( project.getOpenAction() ); // /* first row - project actions */ // handler.getEditAction().render( body, m_toolkit ); // handler.getDeleteAction().render( body, m_toolkit ); // handler.getDatabaseAction().render( body, m_toolkit ); // handler.getExportAction().render( body, m_toolkit ); /* second row - enshorted project description */ if (description != null) { // TODO: ugly: the label should wrap if too big; 50 chars is just arbitrary... final String shortDescription = StringUtils.abbreviate(description, 50); final String msg = String.format(" %s", shortDescription); //$NON-NLS-1$ final Label descriptionLabel = m_toolkit.createLabel(body, msg); descriptionLabel.setToolTipText(description); final int numColumns = ((GridLayout) body.getLayout()).numColumns; descriptionLabel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, numColumns, 0)); //$NON-NLS-1$ } }
From source file:org.kalypso.ogc.gml.featureview.control.FeatureTabItem.java
public void updateControl() { final Feature feature = getFeature(); final String text = FeatureHelper.getAnnotationValue(feature, IAnnotation.ANNO_LABEL); /* Ensure minimum length */ final int MIN_TITLE_LENGTH = 8; final int MAX_TITLE_LENGTH = 30; final String paddedText = StringUtils.rightPad(text, MIN_TITLE_LENGTH); /* Ensure maximum length */ final String abreviatedText = StringUtils.abbreviate(paddedText, MAX_TITLE_LENGTH); m_item.setText(abreviatedText);/*from w ww . j av a2s.com*/ m_item.setToolTipText(text); m_fc.updateControl(); }
From source file:org.kuali.kra.coi.notesandattachments.attachments.CoiDisclosureAttachment.java
public String getShortDescription() { String result = StringUtils.abbreviate(getDescription(), 20) + ": " + StringUtils.abbreviate(getFile().getName(), 20); if (!StringUtils.isEmpty(getUpdateUser())) { result += ": " + getUpdatedByString() + " " + getUpdateUser(); }/*from ww w . j a va2s. c o m*/ return result; }
From source file:org.languagetool.dev.dumpcheck.DatabaseHandler.java
@Override protected void handleResult(Sentence sentence, List<RuleMatch> ruleMatches, Language language) { try {//w w w . j a v a2 s . co m java.sql.Date nowDate = new java.sql.Date(new Date().getTime()); for (RuleMatch match : ruleMatches) { String smallContext = smallContextTools.getContext(match.getFromPos(), match.getToPos(), sentence.getText()); insertSt.setString(1, language.getShortCode()); Rule rule = match.getRule(); insertSt.setString(2, rule.getId()); insertSt.setString(3, rule.getCategory().getName()); if (rule instanceof AbstractPatternRule) { AbstractPatternRule patternRule = (AbstractPatternRule) rule; insertSt.setString(4, patternRule.getSubId()); } else { insertSt.setNull(4, Types.VARCHAR); } insertSt.setString(5, rule.getDescription()); insertSt.setString(6, StringUtils.abbreviate(match.getMessage(), 255)); String context = contextTools.getContext(match.getFromPos(), match.getToPos(), sentence.getText()); if (context.length() > MAX_CONTEXT_LENGTH) { // let's skip these strange cases, as shortening the text might leave us behind with invalid markup etc continue; } insertSt.setString(7, context); insertSt.setString(8, StringUtils.abbreviate(smallContext, 255)); insertSt.setDate(9, nowDate); // should actually be the dump's date, but isn't really used anyway... insertSt.setDate(10, nowDate); insertSt.setString(11, sentence.getUrl()); insertSt.setString(12, sentence.getSource()); insertSt.addBatch(); if (++batchCount >= batchSize) { executeBatch(); batchCount = 0; } checkMaxErrors(++errorCount); if (errorCount % 100 == 0) { System.out.println("Storing error #" + errorCount + " for text:"); System.out.println(" " + sentence.getText()); } } checkMaxSentences(++sentenceCount); } catch (DocumentLimitReachedException | ErrorLimitReachedException e) { throw e; } catch (Exception e) { throw new RuntimeException("Error storing matches for '" + sentence.getTitle() + "'", e); } }
From source file:org.languagetool.dev.dumpcheck.SentenceSourceChecker.java
private void run(File propFile, Set<String> disabledRules, String langCode, List<String> fileNames, String[] ruleIds, String[] additionalCategoryIds, int maxSentences, int maxErrors, File languageModelDir, File word2vecModelDir, File neuralNetworkModelDir, Pattern filter) throws IOException { Language lang = Languages.getLanguageForShortCode(langCode); MultiThreadedJLanguageTool languageTool = new MultiThreadedJLanguageTool(lang); languageTool.setCleanOverlappingMatches(false); if (languageModelDir != null) { languageTool.activateLanguageModelRules(languageModelDir); }//from w w w .ja v a 2 s. c om if (word2vecModelDir != null) { languageTool.activateWord2VecModelRules(word2vecModelDir); } if (neuralNetworkModelDir != null) { languageTool.activateNeuralNetworkRules(neuralNetworkModelDir); } if (ruleIds != null) { enableOnlySpecifiedRules(ruleIds, languageTool); } else { applyRuleDeactivation(languageTool, disabledRules); } if (filter != null) { System.out.println( "*** NOTE: only sentences that match regular expression '" + filter + "' will be checked"); } activateAdditionalCategories(additionalCategoryIds, languageTool); disableSpellingRules(languageTool); System.out.println("Working on: " + StringUtils.join(fileNames, ", ")); System.out.println("Sentence limit: " + (maxSentences > 0 ? maxSentences : "no limit")); System.out.println("Error limit: " + (maxErrors > 0 ? maxErrors : "no limit")); //System.out.println("Version: " + JLanguageTool.VERSION + " (" + JLanguageTool.BUILD_DATE + ")"); ResultHandler resultHandler = null; int ruleMatchCount = 0; int sentenceCount = 0; try { if (propFile != null) { resultHandler = new DatabaseHandler(propFile, maxSentences, maxErrors); } else { //resultHandler = new CompactStdoutHandler(maxSentences, maxErrors); resultHandler = new StdoutHandler(maxSentences, maxErrors); } MixingSentenceSource mixingSource = MixingSentenceSource.create(fileNames, lang, filter); while (mixingSource.hasNext()) { Sentence sentence = mixingSource.next(); try { List<RuleMatch> matches = languageTool.check(sentence.getText()); resultHandler.handleResult(sentence, matches, lang); sentenceCount++; if (sentenceCount % 5000 == 0) { System.err.printf("%s sentences checked...\n", NumberFormat.getNumberInstance(Locale.US).format(sentenceCount)); } ruleMatchCount += matches.size(); } catch (DocumentLimitReachedException | ErrorLimitReachedException e) { throw e; } catch (Exception e) { throw new RuntimeException( "Check failed on sentence: " + StringUtils.abbreviate(sentence.getText(), 250), e); } } } catch (DocumentLimitReachedException | ErrorLimitReachedException e) { System.out.println(getClass().getSimpleName() + ": " + e); } finally { languageTool.shutdown(); if (resultHandler != null) { float matchesPerSentence = (float) ruleMatchCount / sentenceCount; System.out.printf(lang + ": %d total matches\n", ruleMatchCount); System.out.printf(lang + ": %.2f rule matches per sentence\n", matchesPerSentence); try { resultHandler.close(); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:org.languagetool.dev.wikipedia.atom.MatchDatabase.java
void add(WikipediaRuleMatch ruleMatch) { String sql = "INSERT INTO feed_matches " + "(title, language_code, rule_id, rule_sub_id, rule_description, rule_message, rule_category, error_context, edit_date, diff_id) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; try (PreparedStatement prepSt = conn.prepareStatement(sql)) { prepSt.setString(1, StringUtils.abbreviate(ruleMatch.getTitle(), 255)); prepSt.setString(2, ruleMatch.getLanguage().getShortCode()); prepSt.setString(3, ruleMatch.getRule().getId()); if (ruleMatch.getRule() instanceof AbstractPatternRule) { prepSt.setString(4, ((AbstractPatternRule) ruleMatch.getRule()).getSubId()); } else {//from w ww .j a v a 2s. co m prepSt.setString(4, null); } prepSt.setString(5, StringUtils.abbreviate(ruleMatch.getRule().getDescription(), 255)); prepSt.setString(6, StringUtils.abbreviate(ruleMatch.getMessage(), 255)); if (ruleMatch.getRule().getCategory() != null) { prepSt.setString(7, StringUtils.abbreviate(ruleMatch.getRule().getCategory().getName(), 255)); } else { prepSt.setString(7, "<no category>"); } prepSt.setString(8, StringUtils.abbreviate(ruleMatch.getErrorContext(), 500)); prepSt.setTimestamp(9, new Timestamp(ruleMatch.getEditDate().getTime())); prepSt.setLong(10, ruleMatch.getDiffId()); prepSt.execute(); } catch (SQLException e) { if (e.toString().contains("Incorrect string value")) { // Let's accept this - i.e. not crash - for now: // See http://stackoverflow.com/questions/1168036/ and http://stackoverflow.com/questions/10957238/ System.err.println("Could not add rule match " + ruleMatch + " to database - stacktrace follows:"); e.printStackTrace(); } else { throw new RuntimeException("Could not add rule match " + ruleMatch + " to database", e); } } }