|
From: Andreas V. <a_...@us...> - 2004-04-22 09:38:15
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv956/src/org/cobricks/item Modified Files: Item.java Log Message: Index: Item.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/Item.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- Item.java 17 Apr 2004 17:33:00 -0000 1.23 +++ Item.java 22 Apr 2004 09:38:01 -0000 1.24 @@ -339,6 +339,39 @@ return getStringAttribute("title_" + lang); } + + /** + * This method tries to return a title of this item. + * At first it searches for a title in the default language. + * In case this title was found, it is returned. + * Otherwise the method searches for a title in any language and returns it. + * + * @return A title in any language or null if no title was specified for + * this item + */ + public String getAnyTitle() { + // Get the title in the default language and return it (if it was found) + String title = getTitle(defaultLanguage); + if ((title != null) && (title.length() > 0)) { + return title; + } else { + // Try to get a title in any language + Set keys = attrs.keySet(); + Iterator keyIterator = keys.iterator(); + + while (keyIterator.hasNext()) { + String key = (String) keyIterator.next(); + if (key.startsWith("title")) { + title = getStringAttribute(key); + if ((title != null) && (title.length() > 0)) { + return title; + } + } + } + // No title was specified for this item + return null; + } + } /** * Sets the special attribute title in the default language. @@ -378,6 +411,10 @@ this.usedLanguages.add(lang); setAttribute("description_" + lang, description); } + + public String getDefaultLanguage() { + return defaultLanguage; + } public String getUrl() { return getStringAttribute("url"); @@ -611,9 +648,8 @@ // Handling multilanguage attributes if (attribute.matches(".+_[a-z]{2}")) { // Attribute is multilanguage - int pos = attribute.lastIndexOf("_"); - String lang = attribute.substring(pos + 1); - attribute = attribute.substring(0, pos); + String lang = attribute.substring(attribute.length() - 2); + attribute = attribute.substring(0, attribute.length() - 3); xml.append("<" + attribute + " lang=\"" + lang + "\""); } else { |