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

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

Introduction

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

Prototype

public static String abbreviate(String str, int maxWidth) 

Source Link

Document

Abbreviates a String using ellipses.

Usage

From source file:org.pentaho.di.core.util.Assert.java

/**
 * @param input//ww  w .  jav  a 2 s.c  o  m
 *          input to test.
 * @param predicate
 *          predicate to apply.
 * @throws IllegalArgumentException
 *           if predicate didn't rejected input.
 */
public static void assertFalse(final Object input, final Predicate predicate) throws IllegalArgumentException {
    if (!predicate.evaluate(input)) {
        return;
    }
    final StringBuilder builder = new StringBuilder();
    builder.append("Predicate didn't rejected input [predicate=");
    builder.append(predicate);
    builder.append(", input=");
    builder.append(StringUtils.abbreviate(String.valueOf(input), INPUT_MAX_WIDTH));
    builder.append("]");
    throw new IllegalArgumentException(builder.toString());
}

From source file:org.polymap.core.AuthenticationDialog.java

protected Control createDialogArea(Composite parent) {
    message = i18n.get("prompt", StringUtils.abbreviate(serviceUrl, 65));

    Composite composite = (Composite) super.createDialogArea(parent);
    ((GridLayout) composite.getLayout()).numColumns = 2;
    ((GridLayout) composite.getLayout()).makeColumnsEqualWidth = false;

    createMessageArea(composite);/* w w w.jav  a  2  s.co m*/

    Label usernameLabel = new Label(composite, SWT.NONE);
    usernameLabel.setText(i18n.get("username"));
    usernameText = new Text(composite, SWT.BORDER);
    usernameText.setText(username);
    usernameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    Label passwordLabel = new Label(composite, SWT.NONE);
    passwordLabel.setText(i18n.get("password"));
    passwordText = new Text(composite, SWT.BORDER | SWT.PASSWORD);
    passwordText.setText(password);
    passwordText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    GridData gridData = new GridData(SWT.LEFT, SWT.FILL, true, false);
    gridData.horizontalSpan = 2;

    return composite;
}

From source file:org.polymap.core.data.imex.shape.ShapeExportFeaturesOperation.java

public Status execute(final IProgressMonitor monitor) throws Exception {
    monitor.beginTask(context.adapt(FeatureOperationExtension.class).getLabel(), context.features().size());

    // complex type?
    FeatureCollection features = context.features();
    if (!(features.getSchema() instanceof SimpleFeatureType)) {
        throw new UnsupportedOperationException("Complex features are not supported yet.");
    }//  www .  j a  v  a2 s .  c om

    SimpleFeatureType srcSchema = (SimpleFeatureType) features.getSchema();

    // shapeSchema
    ILayer layer = context.adapt(ILayer.class);
    final String basename = layer != null ? FilenameUtils.normalize(layer.getLabel())
            : FilenameUtils.normalize(srcSchema.getTypeName());

    SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
    ftb.setName(basename);
    ftb.setCRS(srcSchema.getCoordinateReferenceSystem());

    // attributes
    final Map<String, String> nameMap = new HashMap();
    for (AttributeDescriptor attr : srcSchema.getAttributeDescriptors()) {
        // attribute name (shapefile: 10 max)
        String targetName = StringUtils.left(attr.getLocalName(), 10);
        for (int i = 1; nameMap.containsValue(targetName); i++) {
            targetName = StringUtils.left(attr.getLocalName(), 10 - (i / 10 + 1)) + i;
            log.info("    Shapefile: " + attr.getLocalName() + " -> " + targetName);
        }
        nameMap.put(attr.getLocalName(), targetName);

        ftb.add(targetName, attr.getType().getBinding());
    }
    final SimpleFeatureType shapeSchema = ftb.buildFeatureType();

    // retyped collection
    final SimpleFeatureBuilder fb = new SimpleFeatureBuilder(shapeSchema);
    FeatureCollection<SimpleFeatureType, SimpleFeature> retyped = new RetypingFeatureCollection<SimpleFeatureType, SimpleFeature>(
            features, shapeSchema) {
        private int count = 0;

        protected SimpleFeature retype(SimpleFeature feature) {
            if (monitor.isCanceled()) {
                throw new RuntimeException("Operation canceled.");
            }
            for (Property prop : feature.getProperties()) {
                Object value = prop.getValue();
                // Shapefile has length limit 254
                if (value instanceof String) {
                    value = StringUtils.abbreviate((String) value, 254);
                }
                fb.set(nameMap.get(prop.getName().getLocalPart()), value);
            }
            if (++count % 100 == 0) {
                monitor.worked(100);
                monitor.subTask("Objekte: " + count);
            }
            return fb.buildFeature(feature.getID());
        }
    };

    ShapefileDataStoreFactory shapeFactory = new ShapefileDataStoreFactory();

    Map<String, Serializable> params = new HashMap<String, Serializable>();
    final File shapefile = File.createTempFile(basename + "-", ".shp");
    shapefile.deleteOnExit();
    params.put(ShapefileDataStoreFactory.URLP.key, shapefile.toURI().toURL());
    params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.FALSE);

    ShapefileDataStore shapeDs = (ShapefileDataStore) shapeFactory.createNewDataStore(params);
    shapeDs.createSchema(shapeSchema);

    //shapeDs.forceSchemaCRS(DefaultGeographicCRS.WGS84);
    //shapeDs.setStringCharset( )

    String typeName = shapeDs.getTypeNames()[0];
    FeatureStore<SimpleFeatureType, SimpleFeature> shapeFs = (FeatureStore<SimpleFeatureType, SimpleFeature>) shapeDs
            .getFeatureSource(typeName);

    // no tx needed; without tx saves alot of memory

    shapeFs.addFeatures(retyped);

    // test code; slow but reads just one feature at a time
    //        FeatureIterator<SimpleFeature> it = retyped.features();
    //        try {
    //            while (it.hasNext()) {
    //                try {
    //                    SimpleFeature feature = it.next();
    //                    DefaultFeatureCollection coll = new DefaultFeatureCollection( null, null );
    //                    coll.add( feature );
    //                    //shapeFs.addFeatures( coll );
    //                    log.info( "Added: " +  feature );
    //                }
    //                catch (Exception e ) {
    //                    log.warn( "", e );
    //                }
    //            }
    //        }
    //        finally {
    //            it.close();
    //        }

    // open download        
    Polymap.getSessionDisplay().asyncExec(new Runnable() {
        public void run() {
            String url = DownloadServiceHandler.registerContent(new ContentProvider() {

                public String getContentType() {
                    return "application/zip";
                }

                public String getFilename() {
                    return basename + ".shp.zip";
                }

                public InputStream getInputStream() throws Exception {
                    ByteArrayOutputStream bout = new ByteArrayOutputStream(1024 * 1024);
                    ZipOutputStream zipOut = new ZipOutputStream(bout);

                    for (String fileSuffix : FILE_SUFFIXES) {
                        zipOut.putNextEntry(new ZipEntry(basename + "." + fileSuffix));
                        File f = new File(shapefile.getParent(),
                                StringUtils.substringBefore(shapefile.getName(), ".") + "." + fileSuffix);
                        InputStream in = new BufferedInputStream(new FileInputStream(f));
                        IOUtils.copy(in, zipOut);
                        in.close();
                        f.delete();
                    }
                    zipOut.close();
                    return new ByteArrayInputStream(bout.toByteArray());
                }

                public boolean done(boolean success) {
                    // all files deleted in #getInputStream()
                    return true;
                }
            });

            log.info("Shapefile: download URL: " + url);
            ExternalBrowser.open("download_window", url,
                    ExternalBrowser.NAVIGATION_BAR | ExternalBrowser.STATUS);
        }
    });
    monitor.done();
    return Status.OK;
}

From source file:org.polymap.core.mapeditor.contextmenu.WmsFeatureInfoContribution.java

@Override
public IContextMenuContribution init(ContextMenuSite _site) {
    this.site = _site;

    setVisible(false);/*from  w  ww .ja va2s  .com*/

    for (final ILayer layer : site.getMap().getLayers()) {
        if (layer.isVisible() && layer.getGeoResource().canResolve(WebMapServer.class)) {

            setVisible(true);

            UIJob job = new UIJob("GetFeatureInfo: " + layer.getLabel()) {
                protected void runWithException(IProgressMonitor monitor) throws Exception {
                    try {
                        IGeoResource geores = layer.getGeoResource();
                        WebMapServer wms = geores.resolve(WebMapServer.class, null);

                        WMSCapabilities caps = wms.getCapabilities();

                        // GetFeatureInfo supported?
                        if (caps.getRequest().getGetFeatureInfo() != null) {
                            List<String> formats = caps.getRequest().getGetFeatureInfo().getFormats();
                            log.info("Possible formats: " + layer.getLabel());
                            log.info("    " + Iterables.toString(formats));

                            String format = formats.contains("text/html") ? "text/html" : null;
                            format = format == null && formats.contains("text/plain") ? "text/plain" : format;
                            //                                format = format == null && formats.contains( "application/vnd.ogc.gml" ) ? "application/vnd.ogc.gml" : format;

                            // no format !?
                            if (format == null) {
                                log.warn(Messages.get("WmsFeatureInfoContribution_noFormat", layer.getLabel())
                                        + ", Formate: " + Iterables.toString(formats));
                                //                                    PolymapWorkbench.handleError( MapEditorPlugin.PLUGIN_ID, this, 
                                //                                            Messages.get( "WmsFeatureInfoContribution_noFormat", layer.getLabel() ), 
                                //                                            new Exception( "Formate: " + Iterables.toString( formats ) ) );
                            }
                            // rough check if any feature is covered
                            String plain = issueRequest(geores, format, false);
                            log.info("Plain: " + StringUtils.abbreviate(plain, 200));
                            if (plain.length() > 50) {
                                awaitAndFillMenuEntry(layer, geores, format);
                            }
                        }
                    } catch (Throwable e) {
                        log.warn("Unable to GetFeatureInfo of: " + layer.getLabel());
                        log.debug("", e);
                    }
                }
            };
            job.schedule();
        }
    }
    return this;
}

From source file:org.projectforge.business.fibu.datev.BuchungssatzImportRow.java

/**
 * Achtung: Diese Klasse ruft ggf. korrigierend und ndernd check() auf.
 * @see java.lang.Object#toString()/*from  www  .ja v  a  2s .  c o  m*/
 * @see #check()
 */
public String toString() {
    check(); // Leider muss dieser modifizierende check() ausgefhrt werden, da auf die aufrufende Klasse ExcelImport kein Einfluss
    // genommen werden kann.
    String txt = StringUtils.abbreviate(text, 30);
    DayHolder day = new DayHolder(datum);
    return StringUtils.leftPad(NumberHelper.getAsString(satzNr), 4) + " "
            + StringUtils.leftPad(day.isoFormat(), 10)
            + StringUtils.leftPad(
                    NumberHelper.getAsString(betrag, NumberHelper.getCurrencyFormat(Locale.GERMAN)), 12)
            + " " + kost1 != null ? StringUtils.leftPad(kost1.toString(), 12)
                    : "-           " + " " + kost2 != null ? StringUtils.leftPad(kost2.toString(), 12)
                            : "-           " + " " + StringUtils.rightPad(txt, 30);
}

From source file:org.projectforge.business.fibu.datev.KontenplanExcelRow.java

public String toString() {
    String txt = StringUtils.abbreviate(bezeichnung, 30);
    return StringUtils.leftPad(NumberHelper.getAsString(konto), 5) + " " + StringUtils.rightPad(txt, 30);
}

From source file:org.projectforge.business.fibu.KostFormatter.java

/**
 * Gibt vollstndige Projektnummer inkl. Kundennummer aus ("5.xxx.xxx") und hngt den Kundennamen (max. 30 Zeichen)
 * und die Projektbezeichnung (max. 30 Zeichen) an, z. B. "5.123.566 - ABC : ABC e-datagate"
 * /*from   w w  w. j  av  a 2 s.c o m*/
 * @param projekt
 */
public static String formatProjekt(final ProjektDO projekt) {
    if (projekt == null) {
        return "";
    }
    final StringBuffer buf = new StringBuffer();
    buf.append(format(projekt));
    if (projekt.getKunde() != null) {
        buf.append(" - ").append(StringUtils.abbreviate(projekt.getKunde().getName(), 30)).append(": ");
    } else {
        buf.append(" - ");
    }
    buf.append(StringUtils.abbreviate(projekt.getName(), 30));
    return buf.toString();
}

From source file:org.projectforge.business.fibu.KostFormatter.java

/**
 * Gibt vollstndige Kundennummer aus ("5.xxx") und hngt den Kundennamen (max. 30 stellig) an, z. B.
 * "5.120 - ABC Verwaltungs GmbH"// w  w w  .j  a v  a  2 s  . c o  m
 * 
 * @param kunde
 */
public static String formatKunde(final KundeDO kunde) {
    if (kunde == null) {
        return "";
    }
    return format(kunde) + " - " + StringUtils.abbreviate(kunde.getName(), 30);
}

From source file:org.projectforge.business.humanresources.HRPlanningEntryDO.java

@Transient
public String getShortDescription() {
    return StringUtils.abbreviate(getDescription(), 50);
}

From source file:org.projectforge.business.timesheet.TimesheetDO.java

/**
 * @return The abbreviated description (maximum length is 50 characters).
 *//*  w  ww  . j a v a 2  s .c  o  m*/
@Transient
public String getShortDescription() {
    if (this.description == null) {
        return "";
    }
    return StringUtils.abbreviate(getDescription(), 50);
}