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.LexGrid.LexBIG.example.BuildTreeForMetaCodeBySource.java

/**
 * Prints formatted text with the CUIs and AUIs of
 * neighboring concepts for the requested SAB.
 * @throws LBException/*from  w  w w.  jav  a2  s. c om*/
 */
protected void printNeighborhood(String scheme, CodingSchemeVersionOrTag csvt, ResolvedConceptReference rcr,
        String sab) throws LBException {

    // Resolve neighboring concepts with associations
    // qualified by the SAB.
    CodedNodeGraph neighborsBySource = getLexBIGService().getNodeGraph(scheme, csvt, null);
    neighborsBySource.restrictToAssociations(null, Constructors.createNameAndValueList(sab, "Source"));
    ResolvedConceptReferenceList nodes = neighborsBySource.resolveAsList(rcr, true, true, Integer.MAX_VALUE, 1,
            null, new PropertyType[] { PropertyType.PRESENTATION }, sortByCode_, null, -1);

    List<AssociatedConcept> neighbors = new ArrayList<AssociatedConcept>();
    for (ResolvedConceptReference node : nodes.getResolvedConceptReference()) {
        // Process sources and targets ...
        if (node.getSourceOf() != null) {
            for (Association assoc : node.getSourceOf().getAssociation())
                for (AssociatedConcept ac : assoc.getAssociatedConcepts().getAssociatedConcept())
                    if (isValidForSAB(ac, sab))
                        neighbors.add(ac);
            if (node.getTargetOf() != null) {
                if (node.getTargetOf() != null)
                    for (Association assoc : node.getTargetOf().getAssociation())
                        for (AssociatedConcept ac : assoc.getAssociatedConcepts().getAssociatedConcept())
                            if (isValidForSAB(ac, sab))
                                neighbors.add(ac);
            }
            // Add to printed output
            for (ResolvedConceptReference neighbor : neighbors) {
                Util.displayMessage(neighbor.getCode() + ':'
                        + StringUtils.abbreviate(neighbor.getEntityDescription().getContent(), 60));
                for (String line : getAtomText(neighbor, sab).split("\\|"))
                    Util.displayMessage("    {" + StringUtils.abbreviate(line, 60) + '}');
            }
        }
    }
}

From source file:org.LexGrid.LexBIG.example.FindUMLSContextsForCUI.java

/**
 * Prints the given item, recursing to print all children.
 *///from  ww w . j a v  a  2  s .  c  o m
protected void printPath(TreeItem ti, String focusCode, int depth, Map<TreeItem, Integer> item2Depth) {

    // Increase indent based on depth.
    StringBuffer indent = new StringBuffer();
    indent.append("  ");
    for (int i = 2; i < depth * 2; i++)
        indent.append(" | ");

    // Determine if the item was already printed at a
    // previous depth.  If not, remember the node for
    // future reference.
    Integer priorDepth = item2Depth.get(ti);
    if (priorDepth == null)
        item2Depth.put(ti, depth);

    // Construct and display text for the item.
    StringBuffer codeAndText = new StringBuffer(indent)
            .append(focusCode.equals(ti.code) ? ">" : (priorDepth != null ? "*" : " ")).append(ti.code)
            .append(':').append(StringUtils.abbreviate(ti.text, 60));
    Util.displayMessage(codeAndText.toString());

    // Print all children, if the item is not a
    // recursive entry.
    if (priorDepth == null) {
        indent.append(" | ");
        for (String association : ti.assocToChildMap.keySet()) {
            Util.displayMessage(indent.toString() + ' ' + association);
            List<TreeItem> children = ti.assocToChildMap.get(association);
            Collections.sort(children);
            for (TreeItem childItem : children)
                printPath(childItem, focusCode, depth + 1, item2Depth);
        }
    }
}

From source file:org.LexGrid.LexBIG.gui.displayResults.DisplayCodedNodeSet.java

private void graphAssociations(Graph graph, Node parentNode, AssociationList al, boolean down,
        boolean addToResults) {
    if (al != null && al.getAssociationCount() > 0) {
        Association[] aList = al.getAssociation();
        for (int i = 0; i < aList.length; i++) {

            int maxPageSize = LB_GUI.MAX_PAGE_SIZE;

            Association a = aList[i];//from   w  ww. j  a v a 2 s . com

            Iterator<? extends AssociatedConcept> itr = a.getAssociatedConcepts().iterateAssociatedConcept();

            List<AssociatedConcept> list = new ArrayList<AssociatedConcept>();

            for (int z = 0; z < maxPageSize && itr.hasNext(); z++) {
                list.add(itr.next());
            }

            if (itr.hasNext()) {
                list.add(new MoreResultsToPageAssociatedConcept());
            }

            AssociatedConcept[] acList = list.toArray(new AssociatedConcept[list.size()]);

            for (int j = 0; j < acList.length; j++) {
                AssociatedConcept ac = acList[j];
                if (addToResults)
                    addCodeToDisplayedResults(ac);
                Node child = graph.addNode(ac, getShowCodesInGraph());

                // Resolve the core association name ...
                StringBuffer edgeText = new StringBuffer();
                if (StringUtils.isNotBlank(a.getDirectionalName())) {
                    edgeText.append(a.getDirectionalName());
                } else {
                    if (!down)
                        edgeText.append("[R]");
                    edgeText.append(a.getAssociationName());
                }

                // Add qualifiers, if available. Format 'assoc:qual(val),
                // ...'
                NameAndValueList aqList = ac.getAssociationQualifiers();
                if (aqList != null && aqList.getNameAndValueCount() > 0) {
                    edgeText.append(':');
                    for (int k = 0; k < aqList.getNameAndValueCount(); k++) {
                        NameAndValue nv = aqList.getNameAndValue(k);
                        if (k > 0)
                            edgeText.append(", ");
                        edgeText.append(nv.getName());
                        if (StringUtils.isNotBlank(nv.getContent()))
                            edgeText.append('(').append(nv.getContent()).append(')');
                    }
                }

                // Limit the text length to protect use of horizontal space
                graph.addEdge(parentNode, child, StringUtils.abbreviate(edgeText.toString(), 64));

                if (down) {
                    graphAssociations(graph, child, ac.getSourceOf(), down, addToResults);
                } else {
                    graphAssociations(graph, child, ac.getTargetOf(), down, addToResults);
                }
            }
        }
    }
}

From source file:org.LexGrid.LexBIG.gui.displayResults.Graph.java

/**
 * Utility method to return the graph based node name for the given concept
 * reference.//from   w  ww  .  j  a  va  2s . c  o  m
 * 
 * @param code
 *            The concept code to visualize. If null, the code is not
 *            included in the returned name.
 * @param desc
 *            The concept description; can be null.
 * @param abbreviate
 *            If true, the text will be abbreviated if it exceeds a
 *            pre-defined limit (with '...' appended). This can be used to
 *            accomodate more nodes in horizontal space.
 * @param separator
 *            the String to use to separate the code from the description
 * @return The corresponding node name.
 */
public static String getNodeName(String code, String desc, boolean abbreviate, String separator) {
    StringBuffer nameBuf = new StringBuffer(128);
    if (code != null)
        nameBuf.append('[').append(code.trim()).append("]").append(separator);
    if (StringUtils.isNotBlank(desc))
        nameBuf.append(desc);
    return (abbreviate) ? StringUtils.abbreviate(nameBuf.toString(), 64) : nameBuf.toString();
}

From source file:org.LexGrid.LexBIG.gui.displayResults.VDDisplayCodedNodeSet.java

private void graphAssociations(Graph graph, Node parentNode, AssociationList al, boolean down,
        boolean addToResults) {
    if (al != null && al.getAssociationCount() > 0) {
        Association[] aList = al.getAssociation();
        for (int i = 0; i < aList.length; i++) {
            Association a = aList[i];//w  w  w .  ja v a  2s .c o  m
            AssociatedConcept[] acList = a.getAssociatedConcepts().getAssociatedConcept();

            for (int j = 0; j < acList.length; j++) {
                AssociatedConcept ac = acList[j];
                if (addToResults)
                    addCodeToDisplayedResults(ac);
                Node child = graph.addNode(ac, getShowCodesInGraph());

                // Resolve the core association name ...
                StringBuffer edgeText = new StringBuffer();
                if (StringUtils.isNotBlank(a.getDirectionalName())) {
                    edgeText.append(a.getDirectionalName());
                } else {
                    if (!down)
                        edgeText.append("[R]");
                    edgeText.append(a.getAssociationName());
                }

                // Add qualifiers, if available. Format 'assoc:qual(val),
                // ...'
                NameAndValueList aqList = ac.getAssociationQualifiers();
                if (aqList != null && aqList.getNameAndValueCount() > 0) {
                    edgeText.append(':');
                    for (int k = 0; k < aqList.getNameAndValueCount(); k++) {
                        NameAndValue nv = aqList.getNameAndValue(k);
                        if (k > 0)
                            edgeText.append(", ");
                        edgeText.append(nv.getName());
                        if (StringUtils.isNotBlank(nv.getContent()))
                            edgeText.append('(').append(nv.getContent()).append(')');
                    }
                }

                // Limit the text length to protect use of horizontal space
                graph.addEdge(parentNode, child, StringUtils.abbreviate(edgeText.toString(), 64));

                if (down) {
                    graphAssociations(graph, child, ac.getSourceOf(), down, addToResults);
                } else {
                    graphAssociations(graph, child, ac.getTargetOf(), down, addToResults);
                }
            }
        }
    }
}

From source file:org.LexGrid.LexBIG.gui.restrictions.Association.java

@Override
public String toString() {
    // Begin quoted value ...
    StringBuffer temp = new StringBuffer("Matching Associations '");

    // Start with association names ...
    for (int i = 0; i < associations.length; i++) {
        temp.append(associations[i]);//ww w  .j  a  va  2  s.c o  m
        if (associations.length != i + 1)
            temp.append(", ");
    }
    // Add association names ...
    for (int i = 0; i < associationQualifiers.length; i++) {
        if (i == 0)
            temp.append(": ");
        temp.append(associationQualifiers[i]);
        if (associationQualifiers.length != i + 1)
            temp.append(", ");
    }
    // Finally, append the qualifier value (if present)
    if (StringUtils.isNotBlank(associationQualifierValue))
        temp.append("(").append(associationQualifierValue).append(")");

    // End quoted value and return
    temp.append('\'');
    return StringUtils.abbreviate(temp.toString(), 64);
}

From source file:org.LexGrid.LexBIG.gui.restrictions.DirectionalName.java

@Override
public String toString() {
    // Begin quoted value ...
    StringBuffer temp = new StringBuffer("Matching directionalNames '");

    // Start with directional names ...
    for (int i = 0; i < directionalNames.length; i++) {
        temp.append(directionalNames[i]);
        if (directionalNames.length != i + 1)
            temp.append(", ");
    }//from   w  w  w . j  a va 2s . c  om
    // Add association qualifiers ...
    for (int i = 0; i < associationQualifiers.length; i++) {
        if (i == 0)
            temp.append(": ");
        temp.append(associationQualifiers[i]);
        if (associationQualifiers.length != i + 1)
            temp.append(", ");
    }
    // Finally, append the qualifier value (if present)
    if (StringUtils.isNotBlank(associationQualifierValue))
        temp.append("(").append(associationQualifierValue).append(")");

    // End quoted value and return
    temp.append('\'');
    return StringUtils.abbreviate(temp.toString(), 64);
}

From source file:org.linagora.linshare.view.tapestry.components.ListSharedDocument.java

public String getTruncatedFileName() {
    String result = StringUtils.abbreviate(shareDocument.getFileName(), truncatedValue);
    return result;
}

From source file:org.linagora.linshare.view.tapestry.pages.history.Index.java

public String getTruncatedFileName() {
    String result = StringUtils.abbreviate(logEntry.getFileName(), truncatedValue);
    return result;
}

From source file:org.linagora.linshare.view.tapestry.pages.lists.DisplayMailingList.java

public String getTruncatedMailingListIdentifier() {
    String result = StringUtils.abbreviate(mailingListVo.getIdentifier(), truncatedValue);
    return result;
}