|
From: Andreas V. <a_...@us...> - 2004-04-11 17:54:46
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23501/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.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- Item.java 3 Apr 2004 10:44:45 -0000 1.14 +++ Item.java 11 Apr 2004 17:41:03 -0000 1.15 @@ -469,11 +469,14 @@ /** * This method returns a String that contains a XML representation of this - * item. To do this the method calls getItemAttributeAsXML for each attribute + * item. + * To do this the method calls getItemAttributeAsXML for each attribute * of this item. * If withAnnotations is set, a representation of the annotations of this - * item is added. If withAttachments is set, a representation of the + * item is added. + * If withAttachments is set, a representation of the * attachments of this item is added. + * * @param withAnnotations boolean to indicate if a representation of the * annotations of this item should be added * @param withAttachments boolean to indicate if a representation of the @@ -491,8 +494,7 @@ + new Integer(this.itemid).toString() + "</itemid>\n" + " <globalid>" + this.globalid + "</globalid>\n " + "<itemclass>" + this.getItemClass() + "</itemclass>\n"); - - // TBD: + defaultLanguage? + Iterator i = attrs.keySet().iterator(); while (i.hasNext()) { @@ -523,70 +525,22 @@ return xml.toString(); } - - protected String getItemAttributeAsXML(String aname, - boolean withXMLDeclaration) { - return this.getItemAttributeAsXML(aname, withXMLDeclaration, - //this.getAttribute(aname)); - null); - } - - /** - * This is an internal utility method to print an Object (here: used for - * printing attributes). TBD: Should this be deleted? - * In case the object to print is a cobricks type, the id will be returned. - * If it is a Collection, the elements will be printed, separated by ";". - * In all other cases, the Object.toString() method is used. - * @param obj The object to print out. - * @return A String representation of the Object - */ - private String printObject(Object obj) { - if (obj != null) { - if (obj instanceof DataObject) { - return String.valueOf(((DataObject) obj).getId()); - } else if (obj instanceof Collection) { - Iterator it = ((Collection) obj).iterator(); - String tmp = ""; - - while (it.hasNext()) { - tmp += (printObject(it.next()) + ";"); - } - - return tmp; - } else { - return obj.toString(); - } - } else { - return (""); - } - } - + /** - * This method adds the language of the submitted attribute name, in case - * it is a multi language attribute. (This is the case if the attribute name - * is ANAME_XX, where XX is the language code). - * If it is not a multi language attribute, this method will do nothing. - * @param aname The attribute name of the new attribute. + * This method is an auxiliary method for getItemAsXML. + * It returns a String that contains a XML representation of the item + * attribute specified by the parameter <code>attribute</code> or the + * parameters <code>attribute</code> and <code>value</code>. + * + * @param attribute The name of the Object to be "transformed" + * @param withXMLDeclaration If set a XML declaration is added at the + * beginning of the returned String + * @param value Object that should be "transformed" into XML; value is not + * required if the Object can be fetched via the parameter attribute + * @return String that holds a XML representation of the item attribute + * specified by the parameter <code>attribute</code> or the parameters + * <code>attribute</code> and <code>value</code> */ - private void addUsedLanguage(String aname) { - if (aname.matches(".+_..")) { - this.usedLanguages.add(aname.substring(aname.length() - 2)); - } - } - - /** - * This method is a helper method for getItemAsXML. It returns a String that - * contains a XML representation of the item attribute specified by the - * parameter "attribute" or the parameters "attribute" and "value". - * @param attribute The name of the Object to be "transformed" - * @param withXMLDeclaration If set a XML declaration is added at the - * beginning of the returned String - * @param value Object that should be "transformed" into XML; value is not - * required if the Object can be fetched via the parameter attribute - * @return String that holds a XML representation of the item attribute - * specified by the parameter "attribute" or the parameters "attribute" and - * "value" - */ protected String getItemAttributeAsXML(String attribute, boolean withXMLDeclaration, Object value) { StringBuffer xml = new StringBuffer(); @@ -601,16 +555,16 @@ value = this.getAttribute(attribute); } - // handling multi language attributes + // Handling multilanguage attributes if (attribute.matches(".+_[a-z]{2}")) { - // multi language attribute + // Attribute is multilanguage int pos = attribute.lastIndexOf("_"); String lang = attribute.substring(pos + 1); attribute = attribute.substring(0, pos); xml.append("<" + attribute + " lang=\"" + lang + "\""); } else { - // no multi language attribute + // Attribute is not multilanguage xml.append("<" + attribute); } @@ -743,6 +697,58 @@ } } + + protected String getItemAttributeAsXML(String aname, + boolean withXMLDeclaration) { + return this.getItemAttributeAsXML(aname, withXMLDeclaration, + //this.getAttribute(aname)); + null); + } + + /** + * This is an internal utility method to print an Object (here: used for + * printing attributes). TBD: Should this be deleted? + * In case the object to print is a cobricks type, the id will be returned. + * If it is a Collection, the elements will be printed, separated by ";". + * In all other cases, the Object.toString() method is used. + * @param obj The object to print out. + * @return A String representation of the Object + */ + private String printObject(Object obj) { + if (obj != null) { + if (obj instanceof DataObject) { + return String.valueOf(((DataObject) obj).getId()); + } else if (obj instanceof Collection) { + Iterator it = ((Collection) obj).iterator(); + String tmp = ""; + + while (it.hasNext()) { + tmp += (printObject(it.next()) + ";"); + } + + return tmp; + } else { + return obj.toString(); + } + } else { + return (""); + } + } + + /** + * This method adds the language of the submitted attribute name, in case + * it is a multi language attribute. (This is the case if the attribute name + * is ANAME_XX, where XX is the language code). + * If it is not a multi language attribute, this method will do nothing. + * @param aname The attribute name of the new attribute. + */ + private void addUsedLanguage(String aname) { + if (aname.matches(".+_..")) { + this.usedLanguages.add(aname.substring(aname.length() - 2)); + } + } + + /** * @see java.lang.Object#clone() */ |