Example usage for org.apache.wicket.util.string PrependingStringBuffer length

List of usage examples for org.apache.wicket.util.string PrependingStringBuffer length

Introduction

In this page you can find the example usage for org.apache.wicket.util.string PrependingStringBuffer length.

Prototype

public int length() 

Source Link

Document

Returns the size of this PrependingStringBuffer

Usage

From source file:org.brixcms.web.util.PathLabel.java

License:Apache License

@Override
public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
    PrependingStringBuffer b = new PrependingStringBuffer();
    BrixNode current = getModelObject();

    while (true) {
        StringBuilder builder = new StringBuilder();
        writePath(current, builder, current.equals(getModelObject()));
        if (b.length() > 0) {
            b.prepend(" / ");
        }/*ww  w  .j a va 2 s. c  om*/
        b.prepend(builder.toString());
        if (current.getDepth() == 0 || current.getPath().equals(rootPath)) {
            break;
        }
        current = (BrixNode) current.getParent();
    }

    final Response r = getResponse();
    r.write(b.toString());
}

From source file:org.hippoecm.frontend.model.JcrItemModel.java

License:Apache License

private void doSave() {
    if (!isValidSession()) {
        return;/*ww w . j  av  a  2s  .  co m*/
    }
    try {
        relPath = null;
        Node node = null;
        PrependingStringBuffer spb = new PrependingStringBuffer();

        // if we have an item, use it to update the path
        Item item = getObject();
        if (item != null) {
            try {
                absPath = item.getPath();
                if (item.isNode()) {
                    node = (Node) item;
                } else {
                    node = item.getParent();
                    spb.prepend(item.getName());
                    spb.prepend('/');
                }
            } catch (InvalidItemStateException ex) {
                // ignore; item doesn't exist anymore
                super.detach();
            }
        }

        // no node was found, use path to resolve an ancestor
        if (node == null) {
            if (absPath != null) {
                Session session = UserSession.get().getJcrSession();
                String path = absPath;
                while (path.lastIndexOf('/') > 0) {
                    spb.prepend(path.substring(path.lastIndexOf('/')));
                    path = path.substring(0, path.lastIndexOf('/'));
                    try {
                        node = (Node) session.getItem(path);
                        break;
                    } catch (PathNotFoundException ignored) {
                    }
                }
            } else {
                log.debug("Neither path nor uuid present");
                return;
            }
        }

        while (node != null && JcrHelper.isVirtualNode(node)) {
            if (node.getIndex() > 1) {
                spb.prepend(']');
                spb.prepend(Integer.toString(node.getIndex()));
                spb.prepend('[');
            }
            spb.prepend(node.getName());
            spb.prepend('/');
            node = node.getParent();
        }

        if (node != null) {
            uuid = node.getIdentifier();
            if (spb.length() > 1) {
                relPath = spb.toString().substring(1);
            }
        }
    } catch (RepositoryException ex) {
        log.error(ex.toString());
    }
}

From source file:org.wicketstuff.security.components.SecureComponentHelper.java

License:Apache License

/**
 * Builds an alias string for {@link MarkupContainer}s.
 * /*from   w w w . ja  v a  2 s  .com*/
 * @param container
 * @return an alias
 */
public static String containerAlias(MarkupContainer container) {
    if (container == null)
        throw new SecurityException("specified markupcontainer is null");
    MarkupContainer parent = container;
    PrependingStringBuffer buffer = new PrependingStringBuffer(150);
    while (parent != null) {
        if (buffer.length() > 0)
            buffer.prepend(PATH_SEPARATOR);
        buffer.prepend(parent.getClass().getName());
        parent = parent.getParent();
    }
    return buffer.toString();
}