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

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

Introduction

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

Prototype

public static String capitalize(String str) 

Source Link

Document

Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .

Usage

From source file:com.doculibre.constellio.services.SolrServicesImpl.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private static Method findGetter(Class clazz, String propertyName)
        throws SecurityException, NoSuchMethodException {
    try {/*from  w w w .  jav a 2  s.  c  om*/
        String getterName = "get" + StringUtils.capitalize(propertyName);
        return clazz.getMethod(getterName, (Class[]) null);
    } catch (NoSuchMethodException e) {
        String getterName = "is" + StringUtils.capitalize(propertyName);
        return clazz.getMethod(getterName, (Class[]) null);
    }
}

From source file:au.org.emii.portal.composer.MapComposer.java

/**
 * Maps environmental and contextual layers from a "&layers" param. Uses the
 * short name of the layer. e.g. "aspect" or ""
 *//*from  w  ww  .j  a va 2 s  .co m*/
public void mapLayerFromParams() {
    Map<String, String> userParams = getQueryParameterMap(
            Executions.getCurrent().getDesktop().getQueryString());
    if (userParams != null) {
        String layersCSV = userParams.get("layers");
        if (StringUtils.trimToNull(layersCSV) == null) {
            return;
        }
        String[] layers = layersCSV.split(",");
        for (String s : layers) {
            JSONArray layerlist = CommonData.getLayerListJSONArray();
            for (int j = 0; j < layerlist.size(); j++) {
                JSONObject field = (JSONObject) layerlist.get(j);
                JSONObject layer = (JSONObject) field.get("layer");
                String name = field.get(StringConstants.ID).toString();
                if (name.equalsIgnoreCase(s) || s.equalsIgnoreCase(layer.get("name").toString())) {
                    String fieldId = field.get(StringConstants.ID).toString();
                    String uid = layer.get(StringConstants.ID).toString();
                    String type = layer.get(StringConstants.TYPE).toString();
                    String treeName = StringUtils.capitalize(field.get(StringConstants.NAME).toString());
                    String treePath = layer.get("displaypath").toString();
                    String legendurl = CommonData.getGeoServer()
                            + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=9&LAYER="
                            + s + (fieldId.length() < 10 ? "&styles=" + fieldId + "_style" : "");
                    String metadata = CommonData.getLayersServer() + "/layers/view/more/" + uid;
                    getMapComposer().addWMSLayer(s, treeName, treePath, (float) 0.75, metadata, legendurl,
                            StringConstants.ENVIRONMENTAL.equalsIgnoreCase(type) ? LayerUtilitiesImpl.GRID
                                    : LayerUtilitiesImpl.CONTEXTUAL,
                            null, null, null);
                }
            }
        }
    }
}

From source file:ch.entwine.weblounge.common.impl.site.SiteImpl.java

/**
 * Initializes this site from an XML node that was generated using
 * {@link #toXml()}.//from  w w  w .ja  v a 2  s.c o  m
 * 
 * @param config
 *          the site node
 * @param xpathProcessor
 *          xpath processor to use
 * @throws IllegalStateException
 *           if the site cannot be parsed
 * @see #toXml()
 */
public static Site fromXml(Node config, XPath xpathProcessor) throws IllegalStateException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

    // identifier
    String identifier = XPathHelper.valueOf(config, "@id", xpathProcessor);
    if (identifier == null)
        throw new IllegalStateException("Unable to create sites without identifier");

    // class
    Site site = null;
    String className = XPathHelper.valueOf(config, "ns:class", xpathProcessor);
    if (className != null) {
        try {
            Class<? extends Site> c = (Class<? extends Site>) classLoader.loadClass(className);
            site = c.newInstance();
            site.setIdentifier(identifier);
        } catch (ClassNotFoundException e) {
            throw new IllegalStateException(
                    "Implementation " + className + " for site '" + identifier + "' not found", e);
        } catch (InstantiationException e) {
            throw new IllegalStateException(
                    "Error instantiating impelementation " + className + " for site '" + identifier + "'", e);
        } catch (IllegalAccessException e) {
            throw new IllegalStateException("Access violation instantiating implementation " + className
                    + " for site '" + identifier + "'", e);
        } catch (Throwable t) {
            throw new IllegalStateException(
                    "Error loading implementation " + className + " for site '" + identifier + "'", t);
        }

    } else {
        site = new SiteImpl();
        site.setIdentifier(identifier);
    }

    // name
    String name = XPathHelper.valueOf(config, "ns:name", xpathProcessor);
    if (name == null)
        throw new IllegalStateException("Site '" + identifier + " has no name");
    site.setName(name);

    // domains
    NodeList urlNodes = XPathHelper.selectList(config, "ns:domains/ns:url", xpathProcessor);
    if (urlNodes.getLength() == 0)
        throw new IllegalStateException("Site '" + identifier + " has no hostname");
    String url = null;
    try {
        for (int i = 0; i < urlNodes.getLength(); i++) {
            Node urlNode = urlNodes.item(i);
            url = urlNode.getFirstChild().getNodeValue();
            boolean defaultUrl = ConfigurationUtils.isDefault(urlNode);
            Environment environment = Environment.Production;
            Node environmentAttribute = urlNode.getAttributes().getNamedItem("environment");
            if (environmentAttribute != null && environmentAttribute.getNodeValue() != null)
                environment = Environment.valueOf(StringUtils.capitalize(environmentAttribute.getNodeValue()));

            SiteURLImpl siteURL = new SiteURLImpl(new URL(url));
            siteURL.setDefault(defaultUrl);
            siteURL.setEnvironment(environment);

            site.addHostname(siteURL);
        }
    } catch (MalformedURLException e) {
        throw new IllegalStateException("Site '" + identifier + "' defines malformed url: " + url);
    }

    // languages
    NodeList languageNodes = XPathHelper.selectList(config, "ns:languages/ns:language", xpathProcessor);
    if (languageNodes.getLength() == 0)
        throw new IllegalStateException("Site '" + identifier + " has no languages");
    for (int i = 0; i < languageNodes.getLength(); i++) {
        Node languageNode = languageNodes.item(i);
        Node defaultAttribute = languageNode.getAttributes().getNamedItem("default");
        String languageId = languageNode.getFirstChild().getNodeValue();
        try {
            Language language = LanguageUtils.getLanguage(languageId);
            if (ConfigurationUtils.isTrue(defaultAttribute))
                site.setDefaultLanguage(language);
            else
                site.addLanguage(language);
        } catch (UnknownLanguageException e) {
            throw new IllegalStateException(
                    "Site '" + identifier + "' defines unknown language: " + languageId);
        }
    }

    // templates
    NodeList templateNodes = XPathHelper.selectList(config, "ns:templates/ns:template", xpathProcessor);
    PageTemplate firstTemplate = null;
    for (int i = 0; i < templateNodes.getLength(); i++) {
        PageTemplate template = PageTemplateImpl.fromXml(templateNodes.item(i), xpathProcessor);
        boolean isDefault = ConfigurationUtils.isDefault(templateNodes.item(i));
        if (isDefault && site.getDefaultTemplate() != null) {
            logger.warn("Site '{}' defines more than one default templates", site.getIdentifier());
        } else if (isDefault) {
            site.setDefaultTemplate(template);
            logger.debug("Site '{}' uses default template '{}'", site.getIdentifier(),
                    template.getIdentifier());
        } else {
            site.addTemplate(template);
            logger.debug("Added template '{}' to site '{}'", template.getIdentifier(), site.getIdentifier());
        }
        if (firstTemplate == null)
            firstTemplate = template;
    }

    // Make sure we have a default template
    if (site.getDefaultTemplate() == null) {
        if (firstTemplate == null)
            throw new IllegalStateException(
                    "Site '" + site.getIdentifier() + "' does not specify any page templates");
        logger.warn("Site '{}' does not specify a default template. Using '{}'", site.getIdentifier(),
                firstTemplate.getIdentifier());
        site.setDefaultTemplate(firstTemplate);
    }

    // security
    String securityConfiguration = XPathHelper.valueOf(config, "ns:security/ns:configuration", xpathProcessor);
    if (securityConfiguration != null) {
        URL securityConfig = null;

        // If converting the path into a URL fails, we are assuming that the
        // configuration is part of the bundle
        try {
            securityConfig = new URL(securityConfiguration);
        } catch (MalformedURLException e) {
            logger.debug("Security configuration {} is pointing to the bundle", securityConfiguration);
            securityConfig = SiteImpl.class.getResource(securityConfiguration);
            if (securityConfig == null) {
                throw new IllegalStateException("Security configuration " + securityConfig + " of site '"
                        + site.getIdentifier() + "' cannot be located inside of bundle", e);
            }
        }
        site.setSecurity(securityConfig);
    }

    // administrator
    Node adminNode = XPathHelper.select(config, "ns:security/ns:administrator", xpathProcessor);
    if (adminNode != null) {
        site.setAdministrator(SiteAdminImpl.fromXml(adminNode, site, xpathProcessor));
    }

    // digest policy
    Node digestNode = XPathHelper.select(config, "ns:security/ns:digest", xpathProcessor);
    if (digestNode != null) {
        site.setDigestType(DigestType.valueOf(digestNode.getFirstChild().getNodeValue()));
    }

    // role definitions
    NodeList roleNodes = XPathHelper.selectList(config, "ns:security/ns:roles/ns:*", xpathProcessor);
    for (int i = 0; i < roleNodes.getLength(); i++) {
        Node roleNode = roleNodes.item(i);
        String roleName = roleNode.getLocalName();
        String localRoleName = roleNode.getFirstChild().getNodeValue();
        if (Security.SITE_ADMIN_ROLE.equals(roleName))
            site.addLocalRole(Security.SITE_ADMIN_ROLE, localRoleName);
        if (Security.PUBLISHER_ROLE.equals(roleName))
            site.addLocalRole(Security.PUBLISHER_ROLE, localRoleName);
        if (Security.EDITOR_ROLE.equals(roleName))
            site.addLocalRole(Security.EDITOR_ROLE, localRoleName);
        if (Security.GUEST_ROLE.equals(roleName))
            site.addLocalRole(Security.GUEST_ROLE, localRoleName);
    }

    // options
    Node optionsNode = XPathHelper.select(config, "ns:options", xpathProcessor);
    OptionsHelper.fromXml(optionsNode, site, xpathProcessor);

    return site;
}

From source file:com.krawler.spring.crm.leadModule.crmLeadCommonController.java

private void sendMailToLeadOwner(User user, Map map) {
    try {/*w  w w . j  a  va 2  s.c o  m*/
        String subject = user.getCompany().getCompanyName() + " CRM - Failed to genrate Web lead";
        String mailbodyContent = "Hi %s,<p>Following web lead has not been generated in the system</p>"
                + "<table width='80%'><th><td>Property</td><td>Value</td></th>";
        for (Map.Entry e : (Set<Map.Entry>) map.entrySet()) {
            String key = (String) e.getKey();
            if (key != null && key.startsWith("wl_")) {
                key = key.substring(3);
            }
            mailbodyContent += "<tr>" + "<td>" + StringUtils.capitalize(key) + "</td>" + "<td>" + e.getValue()
                    + "</td>" + "</tr>";
        }
        mailbodyContent += "</table>"
                + "<p>Please Note that lead cannot be displayed in the list with out regenerating.</p>"
                + "<p></p><p>- Thanks,</p><p>Administrator</p>";
        String mailbody = String.format(mailbodyContent, StringUtil.getFullName(user));
        String htmlmsg = "<html><head><link rel='shortcut icon' href='../../images/deskera/deskera.png'/><title>New Web Lead</title></head><style type='text/css'>"
                + "a:link, a:visited, a:active {\n" + "    color: #03C;" + "}\n" + "body {\n"
                + "   font-family: Arial, Helvetica, sans-serif;" + "   color: #000;" + "   font-size: 13px;"
                + "}\n" + "</style><body>" + "   <div>" + mailbody + "   </div></body></html>";
        String pmsg = htmlmsg;
        String fromAddress = user.getCompany().getCreator().getEmailID();
        SendMailHandler.postMail(new String[] { supportEmailAddress }, subject, htmlmsg, pmsg, fromAddress, "");
    } catch (Exception ex) {
        logger.warn("Mail for web lead generation failure can not send :" + map, ex);
    }
}

From source file:net.sf.firemox.xml.magic.Oracle2Xml.java

private void writeActions(PrintWriter out, String pActions, boolean writeTarget, boolean ignoreCost) {
    String actions = pActions.replaceAll("--", "");
    boolean startWithSpc = actions.startsWith(" ");
    actions = actions.trim();/*ww w. j  a v a  2s .  c  o  m*/

    if (actions.matches("add [x]*[0-9]+[ubgrw]* .*") || actions.matches("add [x]*[0-9]*[ubgrw]+ .*")) {
        // Give mana
        actions = writeXmanaGive(out, actions, true);
    }

    // return to your hand
    if (actions.indexOf(lowerCard + " to your hand") != -1) {
        out.println("\t\t\t\t<target type='this' />");
        out.println("\t\t\t\t<action ref='return-to-hand'/>");
        actions = StringUtils.replaceOnce(actions, lowerCard + " to your hand", "");
    } else if (actions.indexOf("to your hand") != -1) {
        out.println("\t\t\t\t<action ref='return-to-hand'/>");
        actions = StringUtils.replaceOnce(actions, "to your hand", "");
    } else if (actions.indexOf(lowerCard + " to its owner's hand") != -1) {
        out.println("\t\t\t\t<target type='this' />");
        out.println("\t\t\t\t<action ref='return-to-hand'/>");
        actions = StringUtils.replaceOnce(actions, lowerCard + " to its owner's hand", "");
    } else if (actions.indexOf("to its owner's hand") != -1) {
        out.println("\t\t\t\t<action ref='return-to-hand'/>");
        actions = StringUtils.replaceOnce(actions, "to its owner's hand", "");
    }

    if (actions.indexOf("regenerate " + lowerCard) != -1)
        out.println("\t\t\t\t<action ref='regenerate'/>");

    if (actions.indexOf("regenerate target") != -1)
        out.println("\t\t\t\t<action ref='regenerate-target'/>");

    // First perform Target action
    writeTarget(out, actions, writeTarget);

    if (actions.indexOf("enchanted creature gets ") != -1) {
        out.println("\t\t\t\t<target type='attachedto'/>");
        actions = StringUtils.replaceOnce(actions, "enchanted creature", "");
    } else if (actions.indexOf(lowerCard + " gets") != -1) {
        out.println("\t\t\t\t<target type='this'/>");
        actions = StringUtils.replaceOnce(actions, lowerCard, "");
    } else if (actions.indexOf(lowerCard + " gains") != -1) {
        out.println("\t\t\t\t<target type='this'/>");
        actions = StringUtils.replaceOnce(actions, lowerCard, "");
    }

    if (actions.indexOf("put") != -1 && actions.indexOf("puts") == -1
            && actions.indexOf("creature token") != -1) {
        if (actions.lastIndexOf("put") < actions.indexOf("creature token")) {
            final int endIndex = actions.indexOf("creature token");
            String tokenAction = actions.substring(actions.lastIndexOf("put") + 4, endIndex - 1);
            String[] words = tokenAction.split(" ");

            if (words.length > 3) {
                out.print("\t\t\t\t<repeat value='");
                if (words[0].compareTo("a") == 0)
                    out.println("1'/>");
                else if (words[0].compareTo("two") == 0)
                    out.println("2'/>");
                else if (words[0].compareTo("x") == 0)
                    out.println("x'/> <!-- NEEDS CODE FOR X TOKENS -->");
                else if (words[0].compareTo("three") == 0)
                    out.println("3'/>");
                else if (words[0].compareTo("four") == 0)
                    out.println("4'/>");
                else if (words[0].compareTo("five") == 0)
                    out.println("5'/>");
                else if (words[0].compareTo("six") == 0)
                    out.println("6'/>");
                else if (words[0].compareTo("seven") == 0)
                    out.println("7'/>");
                out.println("\t\t\t\t<create-card>");
                if (words.length == 6)
                    out.println("\t\t\t\t\t<card name='" + StringUtils.capitalize(words[5]) + "'>");
                else
                    out.println("\t\t\t\t\t<card name='" + StringUtils.capitalize(words[3]) + "'>");
                out.println("\t\t\t\t\t\t<rules-author-comment></rules-author-comment>");
                out.println("\t\t\t\t\t\t<init>");
                out.println("\t\t\t\t\t\t\t<registers>");
                out.println("\t\t\t\t\t\t\t\t<register index='power' value='" + words[1].charAt(0) + "'/>");
                out.println("\t\t\t\t\t\t\t\t<register index='toughness' value='" + words[1].charAt(2) + "'/>");
                out.println("\t\t\t\t\t\t\t</registers>");
                out.print("\t\t\t\t\t\t\t<colors>" + words[2]);
                List<String> tokenProperties = new ArrayList<String>();
                tokenProperties.add("token");
                if (words.length == 6) {
                    out.print(" " + words[4]);
                    tokenProperties.add(words[5]);
                } else {
                    tokenProperties.add(words[3]);
                }
                out.println("</colors>");
                out.println("\t\t\t\t\t\t\t<idcards>creature</idcards>");
                if (actions.indexOf("with", endIndex) != -1
                        && actions.indexOf("into", endIndex) > actions.indexOf("with", endIndex)) {
                    updateProperties(actions.substring(actions.indexOf("with", endIndex) + "with".length() + 1,
                            actions.indexOf("into", endIndex)), tokenProperties);
                }
                out.print("\t\t\t\t\t\t\t<properties>");
                for (String property : tokenProperties) {
                    out.print(property);
                    out.print(' ');
                }
                out.println("</properties>");
                out.println("\t\t\t\t\t\t</init>");
                out.println("\t\t\t\t\t</card>");
                out.println("\t\t\t\t</create-card>");
                String zone = actions.substring(actions.lastIndexOf("put") + 4);
                zone = zone.substring(zone.indexOf("into") + "into".length()).trim();
                int zoneIndex = zone.indexOf('.');
                if (zoneIndex > zone.indexOf(' ') && zone.indexOf(' ') >= 0) {
                    zoneIndex = zone.indexOf(' ');
                }
                if (actions.indexOf("target opponent") != -1
                        && actions.indexOf("target opponent") < actions.indexOf('.')) {
                    out.print("\t\t\t\t<move-card controller='target-list.first' destination='");
                } else {
                    out.print("\t\t\t\t<move-card controller='you' destination='");
                }
                if (zoneIndex != -1) {
                    out.print(zone.substring(0, zoneIndex).replaceAll(",", "").trim());
                } else {
                    out.print("nowhere");
                }
                out.println("'/>");
            }
        }
    }
    if (startWithSpc) {
        actions = " " + actions;
    }

    while (actions.length() > 0) {
        if (actions.startsWith("add [x]*[0-9]+[ubgrw] ") || actions.startsWith("add [x]*[0-9]*[ubgrw]+ ")) {
            // Give mana
            actions = writeXmanaGive(out, actions, true);
        } else if (actions.startsWith("add one mana of any color")) {
            out.println("\t\t\t\t<give-mana black='1'/>");
            out.println(
                    "\t\t\t\t<!-- DUPLICATE THIS ABILITY WITH THE FOLLOWING ACTIONS OR USE <action ref='tap-add-B'/> REF-ABILITY");
            out.println("\t\t\t\t<give-mana blue='1'/>");
            out.println("\t\t\t\t<give-mana green='1'/>");
            out.println("\t\t\t\t<give-mana red='1'/>");
            out.println("\t\t\t\t<give-mana white='1'/>");
            out.println("\t\t\t\t  -->");
            actions = actions.substring("add one mana of any color".length());
        } else if (actions.startsWith("add two mana of any ")) {
            out.println("\t\t\t\t<give-mana black='2'/>");
            out.println("\t\t\t\t<!-- DUPLICATE THIS ABILITY WITH THE FOLLOWING ACTIONS");
            out.println("\t\t\t\t<give-mana blue='2'/>");
            out.println("\t\t\t\t<give-mana green='2'/>");
            out.println("\t\t\t\t<give-mana red='2'/>");
            out.println("\t\t\t\t<give-mana white='2'/>");
            out.println("\t\t\t\t  -->");
            actions = actions.substring("add two mana of any ".length());
        } else if (actions.startsWith("add three mana of any ")) {
            out.println("\t\t\t\t<give-mana black='3'/>");
            out.println("\t\t\t\t<!-- DUPLICATE THIS ABILITY WITH THE FOLLOWING ACTIONS");
            out.println("\t\t\t\t<give-mana blue='3'/>");
            out.println("\t\t\t\t<give-mana green='3'/>");
            out.println("\t\t\t\t<give-mana red='3'/>");
            out.println("\t\t\t\t<give-mana white='3'/>");
            out.println("\t\t\t\t  -->");
            actions = actions.substring("add three mana of any ".length());
        } else if (actions.startsWith("remove it from the game at end of turn")) {
            out.println("\t\t\t\t<action ref-'remove-from-game-target-eot'/>");
            actions = actions.substring("remove it from the game at end of turn".length());
        } else if (actions.startsWith("destroy it at end of turn")) {
            out.println("\t\t\t\t<action ref='destroy-target-eot'/>");
            actions = actions.substring("destroy it at end of turn".length());
        } else if (actions.startsWith("can attack this turn as though it didn't have defender")) {
            out.println("\t\t\t\t<action ref='wall-can-attack-until-eot'/>");
            actions = actions.substring("can attack this turn as though it didn't have defender".length());
        } else if (actions.startsWith("look at ") && actions.indexOf("hand") != -1) {
            // Look at target opponent's hand
            out.println("\t\t\t\t<show-zone zone='hand' for='you'/>");
            out.println("\t\t\t\t<!-- INSERT HERE ACTIONS PERFORMED WHILE HAND IS VISIBLE -->");
            out.println("\t\t\t\t<action ref='restore-hand-visibility'/>");
            actions = actions.substring(actions.indexOf("hand") + "hand".length());
            continue;
        } else if (actions.startsWith("choose a creature type")) {
            // Choose a creature type
            out.println(
                    "\t\t\t\t<input-property operation='set' index='free0' register='this' values='FIRST_SUB_TYPE..LAST_SUB_TYPE' />");
            actions = actions.substring("choose a creature type".length());
            continue;
        } else if (actions.startsWith("choose a color")) {
            // Choose a color
            out.println("\t\t\t\t<input-color operation='set' index='free0' register='this'/>");
            actions = actions.substring("choose a color".length());
            continue;
        } else if (actions.startsWith("search ")) {
            // Search in your library for...
            List<String> idCard = new ArrayList<String>();
            List<String> inIdCard = new ArrayList<String>();
            List<String> color = new ArrayList<String>();
            List<String> property = new ArrayList<String>();
            boolean upTo = actions.indexOf("up to ") != -1;
            if (actions.indexOf("any number of ") != -1) {
                out.println("\t\t\t\t<target-list operation='clear' name='%'/>");
                out.println("\t\t\t\t<target type='you' name='%'/> ");
                out.println("\t\t\t\t<show-zone zone='library' for='you' name='%'/>");
                out.println(
                        "\t\t\t\t<target mode='choose' type='card' raise-event='false' restriction-zone='library' hop='2' cancel='false' name='search-any'>");
                out.println("\t\t\t\t\t<test>");
                out.println("\t\t\t\t\t\t<controller player='target-list.first'/>");
                out.println("\t\t\t\t\t</test>");
                out.println("\t\t\t\t</target>");
                out.println("\t\t\t\t<hop value='-1' name='%'/>");
                out.println("\t\t\t\t<action ref='restore-library-visibility'/>");
                out.println("\t\t\t\t<shuffle zone='library'/>");
                out.println("\t\t\t\t<target-list operation='remove-first' name='%'/> ");
                actions = actions.substring("search ".length());
            }
            boolean isYou = actions.startsWith("search your ");
            if (actions.indexOf("white") != -1) {
                color.add("white");
            }
            if (actions.indexOf("black") != -1) {
                color.add("black");
            }
            if (actions.indexOf("blue") != -1) {
                color.add("blue");
            }
            if (actions.indexOf("green") != -1) {
                color.add("green");
            }
            if (actions.indexOf("red") != -1) {
                color.add("red");
            }
            if (actions.indexOf("artifact") != -1) {
                idCard.add("artifact");
            } else if (actions.indexOf("creature") != -1) {
                idCard.add("creature");
            }
            if (actions.indexOf("enchantment") != -1) {
                idCard.add("enchantment");
            }
            if (actions.indexOf("sorcery") != -1) {
                idCard.add("sorcery");
            }
            if (actions.indexOf("instant") != -1) {
                idCard.add("instant");
            }
            if (actions.indexOf("island") != -1) {
                idCard.add("island");
            }
            if (actions.indexOf("swamp") != -1) {
                idCard.add("swamp");
            }
            if (actions.indexOf("forest") != -1) {
                idCard.add("forest");
            }
            if (actions.indexOf("mountain") != -1) {
                idCard.add("mountain");
            }
            if (actions.indexOf("plains") != -1) {
                idCard.add("plains");
            }
            if (actions.indexOf("mercenary") != -1) {
                property.add("mercenary");
            }
            if (actions.indexOf("nonbasic land") != -1) {
                inIdCard.add("nonbasic-land");
            }
            if (actions.indexOf("basic land") != -1) {
                inIdCard.add("basic-land");
            } else if (actions.indexOf("land") != -1) {
                inIdCard.add("land");
            }
            if (actions.indexOf("legend") != -1) {
                property.add("legend");
            }
            if (actions.indexOf("zombie") != -1) {
                property.add("zombie");
            }
            if (actions.indexOf("rebel") != -1) {
                property.add("rebel");
            }
            if (actions.indexOf("dragon") != -1) {
                property.add("dragon");
            }
            if (actions.indexOf("goblin") != -1) {
                property.add("goblin");
            }
            if (actions.indexOf("dwarf") != -1) {
                property.add("dwarf");
            }
            if (isYou && upTo) {
                out.println("\t\t\t\t<action ref='search-lib-up-to' value='3'>");
            } else if (isYou) {
                out.println("\t\t\t\t<action ref='search-lib'>");
            } else {
                out.println("\t\t\t\t<action ref='target-player'/>");
                if (upTo) {
                    out.println("\t\t\t\t<action ref='search-lib-up-to-player' value='3'>");
                } else {
                    out.println("\t\t\t\t<action ref='search-lib-player' value='3'>");
                }
            }
            out.println("\t\t\t\t\t<test>");
            out.println("\t\t\t\t\t\t<and>");
            out.println("\t\t\t\t\t\t\t<controller player='target-list.first'/>");
            if (idCard.size() + inIdCard.size() > 1) {
                out.println("\t\t\t\t\t\t\t<or>");
            }
            for (String id : idCard) {
                out.println("\t\t\t\t\t\t\t\t<has-idcard idcard='" + id + "'/>");
            }
            for (String id : inIdCard) {
                out.println("\t\t\t\t\t\t\t\t<in-idcard idcard='" + id + "'/>");
            }
            if (idCard.size() + inIdCard.size() > 1) {
                out.println("\t\t\t\t\t\t\t</or>");
            }
            if (property.size() > 1) {
                out.println("\t\t\t\t\t\t\t<or>");
            }
            for (String id : property) {
                out.println("\t\t\t\t\t\t\t<has-property property='" + id + "'/>");
            }
            if (property.size() > 1) {
                out.println("\t\t\t\t\t\t\t</or>");
            }
            if (color.size() > 1) {
                out.println("\t\t\t\t\t\t\t<or>");
            }
            for (String id : color) {
                out.println("\t\t\t\t\t\t\t<has-color color='" + id + "'/>");
            }
            if (color.size() > 1) {
                out.println("\t\t\t\t\t\t\t</or>");
            }
            out.println("\t\t\t\t\t\t</and>");
            out.println("\t\t\t\t\t</test>");
            out.println("\t\t\t\t</action>");
            out.println("\t\t\t\t\t<!-- INSERT HERE ACTIONS PERFORMED WHEN CARDS HAVE BEEN CHOSEN -->");
            actions = actions.substring("search ".length());
        } else if (actions.startsWith("sacrifice ")) {
            // Sacrifice
            if (!ignoreCost)
                writeSacrifice(out, actions);
            actions = actions.substring("sacrifice ".length());
        } else

        if (actions.startsWith("untap ")) {
            // Tap
            actions = writeActionOnTarget(out, "untap ", actions);
            out.println("\t\t\t\t<untap/>");
        } else if (actions.startsWith("tap ")) {
            actions = writeActionOnTarget(out, "tap ", actions);
            out.println("\t\t\t\t<tap/>");
        } else

        if (actions.startsWith("discards")) {
            // Discard a card from your hand
            out.println(
                    "\t\t\t\t<!-- UPDATE THE NUMBER OF CARD PLAYER HAVE TO DISCARD, OR REMOVE REPEAT ACTION IF IS ONE -->");
            if (actions.contains("at random")) {
                out.println("\t\t\t\t<action ref='discard-random' value='1'/>");
            } else {
                out.print("\t\t\t\t<action ref='player-discard' ");
                if (actions.startsWith("discards two"))
                    out.println("value='2'/>");
                else
                    out.println("value='1'/>");
            }
            actions = actions.substring("discards ".length());
        } else if (actions.startsWith("discard ")) {
            // Discard a card from your hand
            out.println(
                    "\t\t\t\t<!-- UPDATE THE NUMBER OF CARD PLAYER HAVE TO DISCARD, OR REMOVE REPEAT ACTION IF IS ONE -->");
            if (actions.contains("at random")) {
                out.println("\t\t\t\t<action ref='discard-random' value='1'/>");
            } else {
                out.print("\t\t\t\t<action ref='discard' ");
                if (actions.startsWith("discard two"))
                    out.println("value='2'/>");
                else
                    out.println("value='1'/>");
            }
            actions = actions.substring("discard ".length());
        } else if (actions.startsWith("draw a card at the beginning of the next turn's upkeep.")) {

            out.println("\t\t\t\t<action ref='draw-a-card-next-upkeep'/>");
            actions = actions.replace("draw a card at the beginning of the next turn's upkeep.", "");
        } else if (actions.startsWith(" draws")) {
            // Draw cards
            if (!actions.startsWith(" draws a card")) {
                if (actions.startsWith(" draws two cards")) {
                    out.println("\t\t\t\t<repeat value='2'/>");
                } else if (actions.startsWith(" draws three card")) {
                    out.println("\t\t\t\t<repeat value='3'/>");
                } else if (actions.startsWith(" draws ") && actions.indexOf("cards") != -1) {
                    out.println("\t\t\t\t<!-- UPDATE THE NUMBER OF CARD PLAYER HAVE TO DRAW -->");
                    out.println("\t\t\t\t<repeat value='1'/>");
                }
            }
            out.println("\t\t\t\t<action ref='draw-a-card'/>");
            actions = actions.substring(" draws".length());
        } else if (actions.startsWith("draw ")) {
            out.println("\t\t\t\t<target type='you'/>");
            if (!actions.startsWith("draw a card")) {
                if (actions.startsWith("draw two cards")) {
                    out.println("\t\t\t\t<repeat value='2'/>");
                } else if (actions.startsWith("draw three card")) {
                    out.println("\t\t\t\t<repeat value='3'/>");
                } else if (actions.startsWith("draw ") && actions.indexOf("cards") != -1) {
                    out.println("\t\t\t\t<!-- UPDATE THE NUMBER OF CARD YOU HAVE TO DRAW -->");
                    out.println("\t\t\t\t<repeat value='1'/>");
                }
            }
            out.println("\t\t\t\t<action ref='draw-a-card'/>");
            actions = actions.substring("draw ".length());
        } else if (actions.startsWith("destroy ")) {
            // Destroy
            actions = writeActionOnTarget(out, "destroy ", actions);
            if (actions.contains("can't be regenerated"))
                out.println("\t\t\t\t<action ref='bury'/>");
            else
                out.println("\t\t\t\t<action ref='destroy'/>");
        } else if (actions.startsWith("deals ") && actions.indexOf("damage") != -1) {
            // Damage
            String toReplace = actions.substring(0, actions.indexOf("damage") + "damage".length()) + " to ";
            String type = toReplace.indexOf("combat") != -1 ? "damage-combat" : "damage-normal";
            String amount = actions
                    .substring(actions.indexOf("deals ") + "deals ".length(), actions.indexOf("damage")).trim();
            actions = writeActionOnTarget(out, toReplace, actions);
            try {
                out.println("\t\t\t\t<assign-damage value='" + Integer.parseInt(amount) + "' type='" + type
                        + "'/>");
            } catch (NumberFormatException e) {
                out.println("\t\t\t\t<assign-damage type='" + type + "'>");
                out.println("\t\t\t\t\t<value register='this' index='power'/>");
                out.println("\t\t\t\t</assign-damage>");
            }
        } else if (actions.startsWith("put ") && actions.matches("put [^ ]+ [^ ]+ counter.*")) {
            // Add objects
            int counterIndex = actions.indexOf("counter");
            String[] counters = actions.substring(0, counterIndex).split(" ");
            String objectCount = counters[1].trim();
            String objectName = counters[2].trim();
            if (actions.matches("put [^ ]+ [^ ]+ counter? on " + lowerCard + ".*")) {
                out.println("\t\t\t\t<target-list operation='clear'/>");
                out.println("\t\t\t\t<target type='this'/>");
            }
            try {
                final int objectCountInt;
                if ("a".equals(objectCount)) {
                    objectCountInt = 1;
                } else if ("two".equals(objectCount)) {
                    objectCountInt = 2;
                } else if ("tree".equals(objectCount)) {
                    objectCountInt = 3;
                } else if ("four".equals(objectCount)) {
                    objectCountInt = 4;
                } else if ("five".equals(objectCount)) {
                    objectCountInt = 5;
                } else {
                    objectCountInt = Integer.parseInt(objectCount);
                }
                if (objectCountInt > 1) {
                    out.print("\t\t\t\t<repeat value='");
                    out.print(objectCountInt);
                    out.println("/>");
                }
            } catch (NumberFormatException e) {
                out.println("\t\t\t\t<repeat>");
                out.println("\t\t\t\t\t<value register='stack' index='0'/>");
                out.println("\t\t\t\t</repeat>");
            }
            out.print("\t\t\t\t<add-object object-name='");
            out.print(objectName);
            out.println("'/>");
            actions = actions.substring(counterIndex + "counter".length() + 1);
        } else if (actions.startsWith("counter ")) {
            // counter a spell
            out.println("\t\t\t\t<action ref='counter'/>");
            actions = actions.substring("counter ".length());
        } else if (actions.startsWith("prevent the next ")) {
            int amount = 1;
            try {
                amount = Integer.valueOf(
                        actions.substring("prevent the next ".length(), "prevent the next ".length() + 1));
            } catch (NumberFormatException e) {
                out.println("\t\t\t\t<!-- UPDATE THE DAMAGE PREVENTION NUMBER -->");
            }
            out.println("\t\t\t\t<!-- UPDATE THE DAMAGE PREVENTION OBJECTS -->");
            out.println("\t\t\t\t<action ref='prevent-" + amount + "'/>");
            actions = actions.substring("prevent the next ".length() + 1);
        } else if (actions.startsWith("prevent all")) {
            // Prevent all damage that would be dealt to ...
            out.println("\t\t\t\t<action ref='prevent-all'/>");
            actions = actions.substring("prevent all".length());
        } else if (actions.startsWith("redirect the next ")) {
            int amount = 1;
            try {
                amount = Integer.valueOf(
                        actions.substring("redirect the next ".length(), "redirect the next ".length() + 1));
            } catch (NumberFormatException e) {
                out.println("\t\t\t\t<!-- UPDATE THE DAMAGE REDIRECTION NUMBER -->");
            }
            out.println("\t\t\t\t<!-- UPDATE THE DAMAGE REDIRECTION OBJECTS -->");
            out.println("\t\t\t\t<action ref='redirect-" + amount + "'/>");
            actions = actions.substring("redirect the next ".length() + 1);
        } else if (actions.startsWith("redirect all")) {
            // Redirect all damage that would be dealt to ...
            out.println("\t\t\t\t<action ref='redirect-all'/>");
            actions = actions.substring("redirect all".length());
        } else if (actions.startsWith("pay ") && actions.indexOf(" life") != -1) {
            // Pay 2 life
            try {
                int value = Integer.parseInt(actions.substring("pay ".length(), "pay ".length() + 2).trim());
                out.println("\t\t\t\t<action ref='pay-life' value='" + value + "'/>");
            } catch (NumberFormatException e) {
                out.println("\t\t\t\t<action ref='pay-life'>");
                out.println("\t\t\t\t\t<!-- UPDATE THE X VALUE OF LIFE TO PAY -->");
                out.println("\t\t\t\t\t<value register='stack' index='0'/>");
                out.println("\t\t\t\t</action>");
            }
            actions = actions.substring(actions.indexOf(" life") + " life".length());
        } else if (actions.startsWith(" gain ") && actions.indexOf(" life") != -1) {
            // You gain 2 life
            try {
                int value = Integer
                        .parseInt(actions.substring(" gain ".length(), " gain ".length() + 2).trim());
                out.println("\t\t\t\t<action ref='gain-life' value='" + value + "'/>");
            } catch (NumberFormatException e) {
                out.println("\t\t\t\t<action ref='gain-life'>");
                out.println("\t\t\t\t\t<!-- UPDATE THE X VALUE OF LIFE TO ADD -->");
                out.println("\t\t\t\t\t<value register='stack' index='0'/>");
                out.println("\t\t\t\t</action>");
            }
            actions = actions.substring(actions.indexOf(" life") + " life".length());
        } else if (actions.startsWith(" lose ") && actions.indexOf(" life") != -1) {
            // You lose 2 life
            try {
                int value = Integer
                        .parseInt(actions.substring(" lose ".length(), " lose ".length() + 2).trim());
                out.println("\t\t\t\t<action ref='lose-life' value='" + value + "'/>");
            } catch (NumberFormatException e) {
                out.println("\t\t\t\t<action ref='lose-life'>");
                out.println("\t\t\t\t\t<!-- UPDATE THE X VALUE OF LIFE TO LOSE -->");
                out.println("\t\t\t\t\t<value register='stack' index='0'/>");
                out.println("\t\t\t\t</action>");
            }
            actions = actions.substring(actions.indexOf(" life") + " life".length());
        } else if (actions.startsWith(" gains ") && actions.indexOf(" life") != -1) {
            // Player gains 2 life
            try {
                int value = Integer
                        .parseInt(actions.substring(" gains ".length(), " gains ".length() + 2).trim());
                out.println("\t\t\t\t<action ref='gain-life-target' value='" + value + "'/>");
            } catch (NumberFormatException e) {
                out.println("\t\t\t\t<action ref='gain-life-target'>");
                out.println("\t\t\t\t\t<!-- UPDATE THE X VALUE OF LIFE TO ADD -->");
                out.println("\t\t\t\t\t<value register='stack' index='0'/>");
                out.println("\t\t\t\t</action>");
            }
            actions = actions.substring(actions.indexOf(" life") + " life".length());
        } else if (actions.startsWith(" loses ") && actions.indexOf(" life") != -1) {
            // Player loses 2 life
            try {
                int value = Integer
                        .parseInt(actions.substring(" loses ".length(), " loses ".length() + 2).trim());
                out.println("\t\t\t\t<action ref='lose-life-target' value='" + value + "'/>");
            } catch (NumberFormatException e) {
                out.println("\t\t\t\t<action ref='lose-life-target'>");
                out.println("\t\t\t\t\t<!-- UPDATE THE X VALUE OF LIFE TO LOSE -->");
                out.println("\t\t\t\t\t<value register='stack' index='0'/>");
                out.println("\t\t\t\t</action>");
            }
            actions = actions.substring(actions.indexOf(" life") + " life".length());
        } else if (actions.startsWith(" gets ") || actions.startsWith(" gains ")) {
            // Gets ...
            if (actions.indexOf(" poison counter") != -1) {
                // poison counter
                out.println("\t\t\t\t<!-- UPDATE THE NB OF POISON TO ADD -->");
                out.println(
                        "\t\t\t\t<modify-register register='opponent' index='poison' operation='add' value=''/>");
                actions = actions
                        .substring(actions.indexOf(" poison counter") + " poison counter".length() + 1);
            } else {
                // Gets
                String power = null;
                boolean endOfTurn = actions.indexOf(" until end of turn") != -1;
                out.println("\t\t\t\t<add-modifier>");

                if (actions.indexOf("/") == -1) {
                    out.println("\t\t\t\t\t<!-- UPDATE THE MODIFIER TYPE AND THE LINKED ATTRIBUTE -->");
                    String property = "";
                    if (actions.indexOf("gains") != -1)
                        property = actions.substring(actions.indexOf("gains")).split(" ")[1];
                    else
                        property = "flying";
                    out.println("\t\t\t\t\t<property-modifier property='" + property + "' linked='false'>");
                    if (endOfTurn) {
                        out.println("\t\t\t\t\t\t<until>");
                        out.println("\t\t\t\t\t\t\t<end-of-phase phase='cleanup'/>");
                        out.println("\t\t\t\t\t\t</until>");
                    }
                    out.println("\t\t\t\t\t</property-modifier>");
                } else {
                    if (actions.startsWith(" gets ")) {
                        power = actions.substring(" gets ".length(), actions.indexOf("/")).trim();
                    } else {
                        power = actions.substring(" gains ".length(), actions.indexOf("/")).trim();
                    }
                    String tmpStr = actions.substring(actions.indexOf("/") + 1);
                    int dot = tmpStr.indexOf(".");
                    int space = tmpStr.indexOf(" ");
                    String toughness = tmpStr
                            .substring(0, (space < dot || dot == -1) && space != -1 ? space : dot)
                            .replaceAll(",", "").trim();
                    if (!power.startsWith("+0")) {
                        out.println("\t\t\t\t\t<!-- CHECK THE LINKED ATTRIBUTE -->");
                        if (power.indexOf("x") != -1) {
                            out.println("\t\t\t\t\t<register-modifier index='power' operation='"
                                    + (power.startsWith("-") ? "minus" : "add") + "' linked='false'>");
                            if (endOfTurn) {
                                out.println("\t\t\t\t\t\t<until>");
                                out.println("\t\t\t\t\t\t\t<end-of-phase phase='cleanup'/>");
                                out.println("\t\t\t\t\t\t</until>");
                            }
                            out.println("\t\t\t\t\t\t<!-- UPDATE THE POWER X VALUE -->");
                            out.println("\t\t\t\t\t\t<value register='stack' index='0'/>");
                        } else {
                            out.println("\t\t\t\t\t<register-modifier index='power' value='"
                                    + power.substring(1) + "' operation='"
                                    + (power.startsWith("-") ? "minus" : "add") + "' linked='false'>");
                            if (endOfTurn) {
                                out.println("\t\t\t\t\t\t<until>");
                                out.println("\t\t\t\t\t\t\t<end-of-phase phase='cleanup'/>");
                                out.println("\t\t\t\t\t\t</until>");
                            }
                        }
                        out.println("\t\t\t\t\t</register-modifier>");
                    }
                    if (!toughness.startsWith("+0")) {
                        out.println("\t\t\t\t\t<!-- CHECK THE LINKED ATTRIBUTE -->");
                        if (toughness.indexOf("x") != -1) {
                            out.println("\t\t\t\t\t<register-modifier index='toughness' operation='"
                                    + (power.startsWith("-") ? "minus" : "add") + "' linked='false'>");
                            if (endOfTurn) {
                                out.println("\t\t\t\t\t\t<until>");
                                out.println("\t\t\t\t\t\t\t<end-of-phase phase='cleanup'/>");
                                out.println("\t\t\t\t\t\t</until>");
                            }
                            out.println("\t\t\t\t\t\t<!-- UPDATE THE TOUGHNESS X VALUE -->");
                            out.println("\t\t\t\t\t\t<value register='stack' index='0'/>");

                        } else {
                            out.println("\t\t\t\t\t<register-modifier index='toughness' value='"
                                    + toughness.substring(1) + "' operation='"
                                    + (toughness.startsWith("-") ? "minus" : "add") + "' linked='false'>");
                            if (endOfTurn) {
                                out.println("\t\t\t\t\t\t<until>");
                                out.println("\t\t\t\t\t\t\t<end-of-phase phase='cleanup'/>");
                                out.println("\t\t\t\t\t\t</until>");
                            }
                        }
                        out.println("\t\t\t\t\t</register-modifier>");
                    }
                }
                out.println("\t\t\t\t</add-modifier>");

                if (isAura) {
                    out.println("\t\t\t\t<target type='this'/>");
                    out.println("\t\t\t\t<attachlist>");
                    out.println("\t\t\t\t\t\t<!-- UPDATE ATTACHMENT CONDITION -->");
                    out.println("\t\t\t\t<valid-attachment ref='valid-enchant-creature'/>");
                    out.println("\t\t\t\t</attachlist>");

                }
                actions = actions.substring(" gets ".length());
            }
        } else if (actions.matches("^remove .{1,5} cards? in your graveyard from the game")) {
            if (actions.startsWith("remove two"))
                out.println("\t\t\t\t<repeat value='2'/>");
            else if (actions.startsWith("remove three"))
                out.println("\t\t\t\t<repeat value='3'/>");
            else if (actions.startsWith("remove four"))
                out.println("\t\t\t\t<repeat value='4'/>");
            out.println("\t\t\t\t<action ref='remove-a-card-from-graveyard'/>");
        }
        if (actions.length() > 0) {
            actions = actions.substring(1);
        }
    }

    // TODO Enchanted creature has first strike and trample.
    // At the end of its controller's turn,

    // TODO Choose one -- You gain 5 life; or prevent the next 5 damage that
    // would be dealt to target creature this turn.

    // TODO Entwine {2} (Choose both if you pay the entwine cost.)

}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java

/**
 * @param queryFieldItemsArg//from   w  ww .j ava  2  s  . co  m
 * @param fixLabels
 * @return ERTICaptionInfo for the visible columns returned by a query.
 */
public static List<ERTICaptionInfoQB> getColumnInfo(final Vector<QueryFieldPanel> queryFieldItemsArg,
        final boolean fixLabels, final DBTableInfo rootTbl, boolean forSchemaExport) {
    List<ERTICaptionInfoQB> result = new Vector<ERTICaptionInfoQB>();
    Vector<ERTICaptionInfoTreeLevelGrp> treeGrps = new Vector<ERTICaptionInfoTreeLevelGrp>(5);
    for (QueryFieldPanel qfp : queryFieldItemsArg) {
        if (qfp.getFieldQRI() == null) {
            continue;
        }

        //System.out.println(qfp.getFieldQRI().getFieldName());

        DBFieldInfo fi = qfp.getFieldInfo();
        DBTableInfo ti = null;
        if (fi != null) {
            ti = fi.getTableInfo();
        }
        String colName = qfp.getFieldName();
        if (ti != null && fi != null) {
            colName = ti.getAbbrev() + '.' + fi.getColumn();
        }
        if (qfp.isForDisplay()) {
            String lbl = qfp.getSchemaItem() == null
                    ? (qfp.getItemMapping() == null ? qfp.getLabel() : qfp.getExportedFieldName())
                    : qfp.getSchemaItem().getFieldName();
            if (fixLabels) {
                lbl = fixFldNameForJR(lbl);
            }
            ERTICaptionInfoQB erti = null;

            //Test to see if it is actually necessary to use a ERTICaptionInfoRel for the field.
            boolean buildRelERTI = false;
            if (qfp.getFieldQRI() instanceof RelQRI) {
                //Test to see if it is actually necessary to use a ERTICaptionInfoRel for the field.
                RelationshipType relType = ((RelQRI) qfp.getFieldQRI()).getRelationshipInfo().getType();
                //XXX Formatter.getSingleField() checks for ZeroOrOne and OneToOne rels.
                if (relType != RelationshipType.ManyToOne /*&& relType != RelationshipType.ZeroOrOne && relType != RelationshipType.OneToOne*/) {
                    buildRelERTI = true;
                } else {
                    DataObjDataFieldFormatIFace formatter = ((RelQRI) qfp.getFieldQRI())
                            .getDataObjFormatter(qfp.getFormatName());
                    if (formatter != null) {
                        buildRelERTI = formatter.getSingleField() == null || (formatter.getSingleField() != null
                                && formatter.getFields()[0].getSep() != null);
                    } else {
                        buildRelERTI = true;
                    }
                }
            }

            if (buildRelERTI) {
                RelQRI rqri = (RelQRI) qfp.getFieldQRI();
                RelationshipType relType = rqri.getRelationshipInfo().getType();
                boolean useCache;
                if (relType == RelationshipType.ManyToOne || relType == RelationshipType.ManyToMany) {
                    useCache = true;
                } else {
                    //XXX actually need to be sure that this rel's table has a many-to-one relationship (direct or indirect) to the root.
                    useCache = rootTbl != null && rootTbl.getTableId() != rqri.getTableInfo().getTableId();
                }
                erti = new ERTICaptionInfoRel(colName, lbl, true, qfp.getFieldQRI().getFormatter(), 0,
                        qfp.getStringId(), ((RelQRI) qfp.getFieldQRI()).getRelationshipInfo(), useCache, null,
                        qfp.getFormatName());
            } else if (qfp.getFieldQRI() instanceof TreeLevelQRI) {
                TreeLevelQRI tqri = (TreeLevelQRI) qfp.getFieldQRI();
                for (ERTICaptionInfoTreeLevelGrp tg : treeGrps) {
                    erti = tg.addRank((TreeLevelQRI) qfp.getFieldQRI(), colName, lbl, qfp.getStringId(),
                            tqri.getRealFieldName());
                    if (erti != null) {
                        break;
                    }
                }
                if (erti == null) {
                    ERTICaptionInfoTreeLevelGrp newTg = new ERTICaptionInfoTreeLevelGrp(tqri.getTreeDataClass(),
                            tqri.getTreeDefId(), tqri.getTableAlias(), true, null);
                    erti = newTg.addRank(tqri, colName, lbl, qfp.getStringId(), tqri.getRealFieldName());
                    treeGrps.add(newTg);
                }
            } else {
                erti = new ERTICaptionInfoQB(colName, lbl, true, getColumnFormatter(qfp, forSchemaExport), 0,
                        qfp.getStringId(), qfp.getPickList(), fi);
            }
            erti.setColClass(qfp.getFieldQRI().getDataClass());
            if (qfp.getFieldInfo() != null && !(qfp.getFieldQRI() instanceof DateAccessorQRI)
                    && qfp.getFieldQRI().getFieldInfo().isPartialDate()) {
                String precName = qfp.getFieldQRI().getFieldInfo().getDatePrecisionName();

                Vector<ColInfo> colInfoList = new Vector<ColInfo>();
                ColInfo columnInfo = erti.new ColInfo(StringUtils.capitalize(precName), precName);
                columnInfo.setPosition(0);
                colInfoList.add(columnInfo);

                columnInfo = erti.new ColInfo(qfp.getFieldQRI().getFieldInfo().getColumn(),
                        qfp.getFieldQRI().getFieldInfo().getName());
                columnInfo.setPosition(1);
                colInfoList.add(columnInfo);
                erti.setColInfoList(colInfoList);
                erti.setColName(null);
                // XXX We need to get this from the SchemaConfig
                //erti.setUiFieldFormatter(UIFieldFormatterMgr.getInstance().getFormatter("PartialDate"));
            }
            if (forSchemaExport) {
                erti.setVisible(qfp.getQueryField().getIsDisplay());
            }
            result.add(erti);
        }
    }
    for (ERTICaptionInfoTreeLevelGrp tg : treeGrps) {
        try {
            tg.setUp();
        } catch (SQLException ex) {
            UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(QueryBldrPane.class, ex);
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }
    return result;
}

From source file:com.nortal.jroad.typegen.xmlbeans.XteeSchemaCodePrinter.java

private String findXteeTitle(SchemaProperty prop) throws IOException {
    String xteeTitle = null;/*from   w  w w  .j av a 2s.c  o  m*/
    try {
        String localPart = prop.getName().getLocalPart();
        Node propNode = ((SchemaTypeImpl) prop.getContainerType()).getParseObject().getDomNode();
        Node node = propNode;

        if (StringUtils.equals(localPart, "item") || StringUtils.equals(localPart, "all")) {
            while (true) {
                if (StringUtils.equals(node.getLocalName(), "element")) {
                    localPart = node.getAttributes().getNamedItem("name").getNodeValue();
                    break;
                }
                node = node.getParentNode();
                if (node == null) {
                    node = findFirstNode(propNode.getChildNodes(), "element", localPart);
                    break;
                }
            }
        } else {
            node = findFirstNode(node.getChildNodes(), "element", localPart);
        }
        if (node != null) {
            xteeTitle = clearString(
                    getXmlObjectValue(findFirstNode(node.getChildNodes(), "title", null, false)));
            if (xteeTitle == null) {
                xteeTitle = StringUtils.capitalize(node.getAttributes().getNamedItem("name").getNodeValue());
            }
        }
    } catch (Exception e) {
        throw new IOException(e);
    }

    return xteeTitle;
}

From source file:net.sourceforge.subsonic.service.SearchServiceTestCase.java

private void doTestLine(final String artist, final String album, final String title, final String year,
        final String path, final String genre, final long lastModified, final long length) {

    MusicFile file = new MusicFile() {
        public synchronized MetaData getMetaData() {
            MetaData metaData = new MetaData();
            metaData.setArtist(artist);/*from w w  w  .  ja  v  a2  s .c  o m*/
            metaData.setAlbum(album);
            metaData.setTitle(title);
            metaData.setYear(year);
            metaData.setGenre(genre);
            return metaData;
        }

        public File getFile() {
            return new File(path);
        }

        public boolean isFile() {
            return true;
        }

        public boolean isDirectory() {
            return false;
        }

        public long lastModified() {
            return lastModified;
        }

        public long length() {
            return length;
        }
    };

    SearchService.Line line = SearchService.Line.forFile(file, Collections.<File, SearchService.Line>emptyMap(),
            Collections.<File>emptySet());
    String yearString = year == null ? "" : year;
    String expected = 'F' + SearchService.Line.SEPARATOR + lastModified + SearchService.Line.SEPARATOR
            + lastModified + SearchService.Line.SEPARATOR + path + SearchService.Line.SEPARATOR + length
            + SearchService.Line.SEPARATOR + StringUtils.upperCase(artist) + SearchService.Line.SEPARATOR
            + StringUtils.upperCase(album) + SearchService.Line.SEPARATOR + StringUtils.upperCase(title)
            + SearchService.Line.SEPARATOR + yearString + SearchService.Line.SEPARATOR
            + StringUtils.capitalize(genre);

    assertEquals("Error in toString().", expected, line.toString());
    assertEquals("Error in forFile().", expected, SearchService.Line
            .forFile(file, Collections.<File, SearchService.Line>emptyMap(), Collections.<File>emptySet())
            .toString());
    assertEquals("Error in parse().", expected, SearchService.Line.parse(expected).toString());
}

From source file:net.voxton.mafiacraft.core.help.menu.DivisionMenu.java

License:asdf

public DivisionMenu(GovType type) {
    super(StringUtils.capitalize("asdf"));
    this.type = type;
}

From source file:net.ymate.platform.core.beans.support.PropertyStateSupport.java

public PropertyStateSupport(T source) throws Exception {
    __source = source;//from   w  w w.  jav  a  2s  .c  o  m
    __targetClass = source.getClass();
    __stateMetas = new ArrayList<PropertyStateMeta>();
    __propertyStates = new HashMap<String, PropertyStateMeta>();
    //
    ClassUtils.BeanWrapper<T> _wrapper = ClassUtils.wrapper(source);
    for (String _fieldName : _wrapper.getFieldNames()) {
        PropertyState _state = _wrapper.getField(_fieldName).getAnnotation(PropertyState.class);
        if (_state != null) {
            PropertyStateMeta _stateMeta = new PropertyStateMeta(
                    StringUtils.defaultIfBlank(_state.propertyName(), _fieldName), _state.aliasName(),
                    _wrapper.getValue(_fieldName));
            __stateMetas.add(_stateMeta);
            __propertyStates.put("set" + StringUtils.capitalize(_fieldName), _stateMeta);
            if (StringUtils.isNotBlank(_state.setterName())) {
                __propertyStates.put(_state.setterName(), _stateMeta);
            }
        }
    }
}