Example usage for java.lang StringBuffer insert

List of usage examples for java.lang StringBuffer insert

Introduction

In this page you can find the example usage for java.lang StringBuffer insert.

Prototype

@Override
public StringBuffer insert(int offset, double d) 

Source Link

Usage

From source file:nl.b3p.catalog.xml.mdeXml2Html.java

public static String buildXPath(Element e) {
    Element e2 = e;//from   w  w  w . j  a v  a  2  s  . com
    String fullName = e.getName();
    if (e.getNamespacePrefix() != null && !e.getNamespacePrefix().isEmpty()) {
        fullName = e.getNamespacePrefix() + ":" + fullName;
    }
    StringBuffer sb = new StringBuffer(fullName);
    Parent p = e.getParent();
    while (p != null && p instanceof Element) {
        int i = p.indexOf(e2);
        if (i > 0) {
            sb.append("[" + (i + 1) + "]");
        }
        sb.insert(0, "/");
        e2 = (Element) p;
        fullName = e2.getName();
        if (e2.getNamespacePrefix() != null && !e2.getNamespacePrefix().isEmpty()) {
            fullName = e2.getNamespacePrefix() + ":" + fullName;
        }
        p = p.getParent();
        sb.insert(0, fullName);
    }
    sb.insert(0, "/");
    return sb.toString();
}

From source file:org.mycore.common.xml.MCRXMLFunctions.java

/**
 * Strippes HTML tags from string./*from   w  w w  .  j  a v  a  2  s .  com*/
 * 
 * @param s string to strip HTML tags of
 * @return the plain text without tags
 */
public static String stripHtml(final String s) {
    StringBuffer res = new StringBuffer(s);

    Matcher m;
    while ((m = TAG_PATTERN.matcher(res.toString())).find()) {
        res.delete(m.start(), m.end());
        res.insert(m.start(), stripHtml(m.group(m.groupCount() - 1)));
    }

    return StringEscapeUtils.unescapeHtml(res.toString()).replaceAll(TAG_SELF_CLOSING, "");
}

From source file:net.lightbody.bmp.proxy.jetty.util.URI.java

/** Add two URI path segments.
 * Handles null and empty paths, path and query params (eg ?a=b or
 * ;JSESSIONID=xxx) and avoids duplicate '/'
 * @param p1 URI path segment //from  w w w . java 2s  . co  m
 * @param p2 URI path segment
 * @return Legally combined path segments.
 */
public static String addPaths(String p1, String p2) {
    if (p1 == null || p1.length() == 0) {
        if (p2 == null || p2.length() == 0)
            return p1;
        return p2;
    }
    if (p2 == null || p2.length() == 0)
        return p1;

    int split = p1.indexOf(';');
    if (split < 0)
        split = p1.indexOf('?');
    if (split == 0)
        return p2 + p1;
    if (split < 0)
        split = p1.length();

    StringBuffer buf = new StringBuffer(p1.length() + p2.length() + 2);
    buf.append(p1);

    if (buf.charAt(split - 1) == '/') {
        if (p2.startsWith("/")) {
            buf.deleteCharAt(split - 1);
            buf.insert(split - 1, p2);
        } else
            buf.insert(split, p2);
    } else {
        if (p2.startsWith("/"))
            buf.insert(split, p2);
        else {
            buf.insert(split, '/');
            buf.insert(split + 1, p2);
        }
    }

    return buf.toString();
}

From source file:MainClass.java

public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr)
        throws BadLocationException {

    if (string == null) {
        return;/*w  ww. j  av a2 s.  c  o m*/
    } else {
        String newValue;
        Document doc = fb.getDocument();
        int length = doc.getLength();
        if (length == 0) {
            newValue = string;
        } else {
            String currentContent = doc.getText(0, length);
            StringBuffer currentBuffer = new StringBuffer(currentContent);
            currentBuffer.insert(offset, string);
            newValue = currentBuffer.toString();
        }
        currentValue = checkInput(newValue, offset);
        fb.insertString(offset, string, attr);
    }
}

From source file:com.eviware.soapui.support.xml.actions.InsertBase64FileTextAreaAction.java

public void actionPerformed(ActionEvent e) {
    File file = UISupport.getFileDialogs().open(this, dialogTitle, null, null, null);
    if (file == null)
        return;//from w ww .jav a  2 s  . c  o m

    try {
        // read file
        byte[] ba = FileUtils.readFileToByteArray(file);

        // convert to base 64
        Base64 b64 = new Base64();
        String hex = new String(b64.encode(ba));
        // insert into text at cursor position
        int pos = textArea.getCaretPosition();
        StringBuffer text = new StringBuffer(textArea.getText());
        text.insert(pos, hex);
        textArea.setText(text.toString());

    } catch (IOException e1) {
        UISupport.showErrorMessage("Error reading from file: " + e1.getMessage());
    }
}

From source file:org.apache.myfaces.shared_impl.renderkit.RendererUtils.java

public static String getConcatenatedId(FacesContext context, UIComponent component) {
    if (context == null)
        throw new NullPointerException("context");

    StringBuffer idBuf = new StringBuffer();

    idBuf.append(component.getId());//w  w w . j ava2  s  .c  o  m

    UIComponent parent;

    while ((parent = component.getParent()) != null) {
        if (parent instanceof NamingContainer) {
            idBuf.insert(0, NamingContainer.SEPARATOR_CHAR);
            idBuf.insert(0, parent.getId());
        }
    }

    return idBuf.toString();
}

From source file:com.icesoft.faces.component.util.CustomComponentUtils.java

private static void getPathToComponent(UIComponent component, StringBuffer buf) {
    if (component == null) {
        return;/*from   w  ww .ja v  a2 s  .  c o m*/
    }

    StringBuffer intBuf = new StringBuffer();

    intBuf.append("[Class: ");
    intBuf.append(component.getClass().getName());
    if (component instanceof UIViewRoot) {
        intBuf.append(",ViewId: ");
        intBuf.append(((UIViewRoot) component).getViewId());
    } else {
        intBuf.append(",Id: ");
        intBuf.append(component.getId());
    }
    intBuf.append("]");

    //intBuf.toString for non-1.4 JDK 1.5 compiler output
    buf.insert(0, intBuf.toString());

    if (component != null) {
        getPathToComponent(component.getParent(), buf);
    }
}

From source file:org.broadleafcommerce.profile.web.core.util.PhoneFormatterImpl.java

private String formatTelephoneNumber(String pNumber) {
    if (pNumber == null) {
        return null;
    }/*from ww w  .j av  a2  s .c  o m*/

    String number = pNumber.replaceAll("\\D", "");

    if (number.length() == 0) {
        return null;
    }

    if (number.length() > 10) {
        number = number.substring(0, 10);
    }

    StringBuffer newNumber = new StringBuffer(number);

    if (newNumber.length() == 10) {
        newNumber.insert(6, "-");
        newNumber.insert(3, "-");
    }

    return newNumber.toString();
}

From source file:com.qpark.eip.core.failure.BaseFailureHandler.java

public static FailureDescription getFailure(final String code, final Throwable t, final Object... data) {
    FailureDescription fd = new FailureDescription();
    StringBuffer supportInfo = new StringBuffer(128);
    FailureMessageType fm = null;//w  w w .  j  av a 2s  .  c  om
    if (code != null) {
        fm = getFailureMessage(code);
        if (fm == null) {
            fm = getFailureMessage(DEFAULT);
            supportInfo.append("No definition found for code ").append(code)
                    .append(" in failure-messages.xml.\n");
        }
    } else {
        fm = getFailureMessage(DEFAULT);
    }
    Object[] datax = data;
    if (datax == null) {
        datax = new Object[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                "" };
    }

    supportInfo.insert(0, format(fm.getSupportInformation(), datax));

    fd.setWhatHappened(format(fm.getWhatHappened(), datax));
    fd.setWhyHappened(format(fm.getWhyHappened(), datax));
    fd.setWhatToDo(format(fm.getWhatToDo(), datax));
    if (fm.getSeverity() != null && fm.getSeverity().equals(FailureMessageSeverity.WARNING)) {
        fd.setSeverity(FailureMessageSeverity.WARNING);
    } else {
        fd.setSeverity(FailureMessageSeverity.ERROR);
    }

    fd.setErrorCode(code);

    fd.setSupportInformation(supportInfo.toString());

    if (fd.getSeverity().equals(FailureMessageSeverity.ERROR)) {
        if (t != null) {
            showFailureDescription(t.getClass().getSimpleName(), t.getMessage(), fd.getErrorCode(),
                    fd.getSeverity().name(), fd.getWhatHappened(), fd.getWhyHappened(), fd.getWhatToDo());
        } else {
            showFailureDescription("", "", fd.getErrorCode(), fd.getSeverity().name(), fd.getWhatHappened(),
                    fd.getWhyHappened(), fd.getWhatToDo());
        }
    }

    StringBuffer sb = new StringBuffer(256);
    sb.append("Occurred at: ").append(new Date());
    if (t != null) {
        sb.append("\n").append(t.getMessage()).append("\n");
        sb.append(getStackTrace(t));
    }
    fd.setErrorDetails(sb.toString());
    return fd;
}

From source file:control.UploadFile.java

private File checkExist(String fileName) {
    fileName = "new" + fileName.substring(fileName.lastIndexOf('.'));
    File f = new File(saveFile + "/" + fileName);
    if (f.exists()) {
        StringBuffer sb = new StringBuffer(fileName);
        sb.insert(sb.lastIndexOf("."), "-" + new Date().getTime());
        f = new File(saveFile + "/" + sb.toString());
    }//from w  ww  .  jav  a  2  s. c  o m
    return f;
}