Example usage for org.apache.commons.lang3 StringUtils repeat

List of usage examples for org.apache.commons.lang3 StringUtils repeat

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils repeat.

Prototype

public static String repeat(final char ch, final int repeat) 

Source Link

Document

<p>Returns padding using the specified delimiter repeated to a given length.</p> <pre> StringUtils.repeat('e', 0) = "" StringUtils.repeat('e', 3) = "eee" StringUtils.repeat('e', -2) = "" </pre> <p>Note: this method doesn't not support padding with <a href="http://www.unicode.org/glossary/#supplementary_character">Unicode Supplementary Characters</a> as they require a pair of char s to be represented.

Usage

From source file:org.openestate.io.examples.Is24CsvWritingExample.java

/**
 * Write some {@link Is24CsvRecord} objects into a {@link String} and print the
 * results to the console./* ww w  .  ja v a  2s. co  m*/
 *
 * @param records
 * the CSV records to write
 */
protected static void writeToConsole(List<Is24CsvRecord> records) {
    LOGGER.info("writing document");
    Is24CsvPrinter printer = null;
    try {
        StringBuilder csv = new StringBuilder();
        printer = Is24CsvPrinter.create(csv);
        printer.printRecords(records);
        LOGGER.info(StringUtils.repeat("-", 50) + SystemUtils.LINE_SEPARATOR + csv.toString());
    } catch (Exception ex) {
        LOGGER.error("Can't write document into a string!");
        LOGGER.error("> " + ex.getLocalizedMessage(), ex);
        System.exit(1);
    } finally {
        IOUtils.closeQuietly(printer);
    }
}

From source file:org.openestate.io.examples.Is24XmlWritingExample.java

/**
 * Write an {@link Is24XmlDocument} into a {@link String} and print the
 * results to the console.//from   w  w w .ja  va 2s  .c o m
 *
 * @param doc
 * the document to write
 */
protected static void writeToConsole(Is24XmlDocument doc) {
    LOGGER.info("writing document");
    try {
        String xml = doc.toXmlString(PRETTY_PRINT);
        LOGGER.info(StringUtils.repeat("-", 50) + SystemUtils.LINE_SEPARATOR + xml);
    } catch (Exception ex) {
        LOGGER.error("Can't write document into a string!");
        LOGGER.error("> " + ex.getLocalizedMessage(), ex);
        System.exit(1);
    }
}

From source file:org.openestate.io.examples.KyeroWritingExample.java

/**
 * Write a {@link KyeroDocument} into a {@link String} and print the
 * results to the console./*from   w  w w . j  ava2 s.co  m*/
 *
 * @param doc
 * the document to write
 */
protected static void writeToConsole(KyeroDocument doc) {
    LOGGER.info("writing document with version " + doc.getDocumentVersion());
    try {
        String xml = doc.toXmlString(PRETTY_PRINT);
        LOGGER.info(StringUtils.repeat("-", 50) + SystemUtils.LINE_SEPARATOR + xml);
    } catch (Exception ex) {
        LOGGER.error("Can't write document into a string!");
        LOGGER.error("> " + ex.getLocalizedMessage(), ex);
        System.exit(1);
    }
}

From source file:org.openestate.io.examples.OpenImmoWritingExample.java

/**
 * Write an {@link OpenImmoTransferDocument} into a {@link String} and print the
 * results to the console./*from   w ww. j  a  v a 2s  . co m*/
 *
 * @param doc
 * the document to write
 */
protected static void writeToConsole(OpenImmoTransferDocument doc) {
    LOGGER.info("writing document with version " + doc.getDocumentVersion());
    try {
        String xml = doc.toXmlString(PRETTY_PRINT);
        LOGGER.info(StringUtils.repeat("-", 50) + SystemUtils.LINE_SEPARATOR + xml);
    } catch (Exception ex) {
        LOGGER.error("Can't write document into a string!");
        LOGGER.error("> " + ex.getLocalizedMessage(), ex);
        System.exit(1);
    }
}

From source file:org.openestate.io.examples.TrovitWritingExample.java

/**
 * Write a {@link TrovitDocument} into a {@link String} and print the
 * results to the console.// w  w  w. j av a2 s . c  om
 *
 * @param doc
 * the document to write
 */
protected static void writeToConsole(TrovitDocument doc) {
    LOGGER.info("writing document");
    try {
        String xml = doc.toXmlString(PRETTY_PRINT);
        LOGGER.info(StringUtils.repeat("-", 50) + SystemUtils.LINE_SEPARATOR + xml);
    } catch (Exception ex) {
        LOGGER.error("Can't write document into a string!");
        LOGGER.error("> " + ex.getLocalizedMessage(), ex);
        System.exit(1);
    }
}

From source file:org.openestate.io.examples.WisItWritingExample.java

/**
 * Write a {@link WisItDocument} into a {@link String} and print the
 * results to the console./* ww w  .  j av  a2  s .c  om*/
 *
 * @param doc
 * the document to write
 */
protected static void writeToConsole(WisItDocument doc) {
    LOGGER.info("writing document");
    try {
        String xml = doc.toXmlString(PRETTY_PRINT);
        LOGGER.info(StringUtils.repeat("-", 50) + SystemUtils.LINE_SEPARATOR + xml);
    } catch (Exception ex) {
        LOGGER.error("Can't write document into a string!");
        LOGGER.error("> " + ex.getLocalizedMessage(), ex);
        System.exit(1);
    }
}

From source file:org.openestate.io.immoxml.ImmoXmlJavadocBindings.java

public static void main(String[] args) {
    TreeSet<String> elementNames = new TreeSet<String>();
    TreeMap<String, String> typeNames = new TreeMap<String, String>();
    for (Class clazz : ClassFinder.find(ImmoXmlUtils.PACKAGE)) {
        XmlRootElement element = (XmlRootElement) clazz.getAnnotation(XmlRootElement.class);
        if (element != null) {
            elementNames.add(element.name());
            continue;
        }//  w w w . ja v  a2  s  .  co m

        XmlType type = (XmlType) clazz.getAnnotation(XmlType.class);
        if (type != null) {
            typeNames.put(type.name(), clazz.getSimpleName());
            continue;
        }
    }

    System.out.println(StringUtils.repeat("-", 50));
    System.out.println("XML elements");
    System.out.println(StringUtils.repeat("-", 50));
    for (String name : elementNames) {
        System.out.println("\n" + "<jaxb:bindings node=\"/xsd:schema/xsd:element[@name='" + name + "']\">\n"
                + "  <jaxb:class>\n" + "    <jaxb:javadoc><![CDATA[Java class for &lt;" + name
                + "&gt; element.]]></jaxb:javadoc>\n" + "  </jaxb:class>\n" + "</jaxb:bindings>");
    }
    System.out.println("");

    System.out.println(StringUtils.repeat("-", 50));
    System.out.println("XML types");
    System.out.println(StringUtils.repeat("-", 50));
    for (String name : typeNames.keySet()) {
        System.out.println("\n" + "<jaxb:bindings node=\"/xsd:schema/xsd:complexType[@name='" + name + "']\">\n"
                + "  <jaxb:class name=\"" + typeNames.get(name) + "\">\n"
                + "    <jaxb:javadoc><![CDATA[Java class for \"" + name + "\" complex type.]]></jaxb:javadoc>\n"
                + "  </jaxb:class>\n" + "</jaxb:bindings>");
    }
    System.out.println("");
}

From source file:org.openestate.io.openimmo.OpenImmoJavadocBindings.java

public static void main(String[] args) {
    String[] feedbackNames = new String[] { "fehlerliste", "interessent", "objekt", "openimmo_feedback",
            "sender", "status", };

    TreeSet<String> elementNames = new TreeSet<String>();
    TreeMap<String, String> typeNames = new TreeMap<String, String>();
    for (Class clazz : ClassFinder.find(OpenImmoUtils.PACKAGE)) {
        XmlRootElement element = (XmlRootElement) clazz.getAnnotation(XmlRootElement.class);
        if (element != null) {
            elementNames.add(element.name());
            continue;
        }//from  w  ww.  j av a  2 s  . c o m

        XmlType type = (XmlType) clazz.getAnnotation(XmlType.class);
        if (type != null) {
            typeNames.put(type.name(), clazz.getSimpleName());
            continue;
        }
    }

    System.out.println(StringUtils.repeat("-", 50));
    System.out.println("XML elements in openimmo.xsd");
    System.out.println(StringUtils.repeat("-", 50));
    for (String name : elementNames) {
        if (ArrayUtils.contains(feedbackNames, name))
            continue;
        System.out.println("\n" + "<jaxb:bindings node=\"/xsd:schema/xsd:element[@name='" + name + "']\">\n"
                + "  <jaxb:class>\n" + "    <jaxb:javadoc><![CDATA[Java class for &lt;" + name
                + "&gt; element.]]></jaxb:javadoc>\n" + "  </jaxb:class>\n" + "</jaxb:bindings>");
    }
    System.out.println("");

    System.out.println(StringUtils.repeat("-", 50));
    System.out.println("XML elements in openimmo_feedback.xsd");
    System.out.println(StringUtils.repeat("-", 50));
    for (String name : elementNames) {
        if (!ArrayUtils.contains(feedbackNames, name))
            continue;
        System.out.println("\n" + "<jaxb:bindings node=\"/xsd:schema/xsd:element[@name='" + name + "']\">\n"
                + "  <jaxb:class>\n" + "    <jaxb:javadoc><![CDATA[Java class for &lt;" + name
                + "&gt; element.]]></jaxb:javadoc>\n" + "  </jaxb:class>\n" + "</jaxb:bindings>");
    }
    System.out.println("");

    System.out.println(StringUtils.repeat("-", 50));
    System.out.println("XML types");
    System.out.println(StringUtils.repeat("-", 50));
    for (String name : typeNames.keySet()) {
        System.out.println("\n" + "<jaxb:bindings node=\"/xsd:schema/xsd:complexType[@name='" + name + "']\">\n"
                + "  <jaxb:class name=\"" + typeNames.get(name) + "\">\n"
                + "    <jaxb:javadoc><![CDATA[Java class for \"" + name + "\" complex type.]]></jaxb:javadoc>\n"
                + "  </jaxb:class>\n" + "</jaxb:bindings>");
    }
    System.out.println("");
}

From source file:org.openestate.is24.restapi.utils.RequestFailedException.java

public RequestFailedException(Response response, String message) {
    super(message);
    this.statusCode = response.statusCode;
    this.statusMessage = StringUtils.trimToNull(response.statusMessage);
    this.requestRefNumber = StringUtils.trimToNull(response.requestRefNumber);

    Messages messages = null;// www  . j a va  2s.  com
    String body = StringUtils.trimToNull(response.body);

    // parse messages from XML response
    if (body != null && body.startsWith("<?xml")) {
        try {
            messages = (Messages) XmlUtils.unmarshal(body);
        } catch (Exception ex) {
            LOGGER.error("WARNING: Can't read error messages from response body!");
            LOGGER.error(StringUtils.repeat("-", 40));
            LOGGER.error(body);
            LOGGER.error(StringUtils.repeat("-", 40));
            LOGGER.error(ex.getLocalizedMessage(), ex);
        }
    }

    // create messages from plain text response
    if (messages == null) {
        final org.openestate.is24.restapi.xml.common.ObjectFactory factory = new org.openestate.is24.restapi.xml.common.ObjectFactory();

        Message msg = factory.createMessage();
        msg.setMessage((body != null) ? body : this.statusMessage);
        msg.setMessageCode(null);
        messages = factory.createMessages();
        messages.getMessage().add(msg);
    }

    this.responseMessages = messages;
}

From source file:org.openmrs.module.radiology.dicom.DicomUidValidatorTest.java

/**
 * @see DicomUidValidator#isValid(String)
 * @verifies return false for uid longer than 64 characters
 *//*from w  w w  .  ja v  a  2s. c o m*/
@Test
public void isValid_shouldReturnFalseForUidLongerThan64Characters() throws Exception {

    String uid = StringUtils.repeat("1.2", 22);
    assertThat(uid.length(), is(greaterThan(64)));

    assertFalse(DicomUidValidator.isValid(uid));
}