|
From: Andreas V. <a_...@us...> - 2004-04-24 13:35:20
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5797/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.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- Item.java 22 Apr 2004 09:38:01 -0000 1.24 +++ Item.java 24 Apr 2004 13:35:10 -0000 1.25 @@ -101,9 +101,18 @@ * instantiating this item */ private Map alreadyInstantiated; - // item attributes cache - Map annotations; - Map attachments; + + /** + * This map contains the objects of type ItemAnnotation that are assigned to + * this item + */ + protected Map annotations = new HashMap(); + + /** + * This map contains the objects of type ItemAttachment that are assigned to + * this item + */ + protected Map attachments = new HashMap(); /** * This set contains all languages that have been used in this item. Needed @@ -339,14 +348,14 @@ 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 + * + * @return A title in any language or null if no title was specified for * this item */ public String getAnyTitle() { @@ -356,9 +365,9 @@ return title; } else { // Try to get a title in any language - Set keys = attrs.keySet(); + Set keys = attrs.keySet(); Iterator keyIterator = keys.iterator(); - + while (keyIterator.hasNext()) { String key = (String) keyIterator.next(); if (key.startsWith("title")) { @@ -369,8 +378,8 @@ } } // No title was specified for this item - return null; - } + return null; + } } /** @@ -559,14 +568,14 @@ /** * This method returns a String that contains a XML representation of this - * item. + * item. * To do this the method calls getItemAttributeAsXML(String, boolean, Object) * 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 attachments of this * 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 @@ -577,14 +586,14 @@ logger.debug("getItemAsXML"); StringBuffer xml = new StringBuffer(); - + xml.append( "<?xml version=\"1.0\" encoding=\"" + this.xmlEncoding + "\"?>\n<item>\n" + " <itemid>" + new Integer(this.itemid).toString() + "</itemid>\n" + " <globalid>" + this.globalid + "</globalid>\n " + "<itemclass>" + this.getItemClass() + "</itemclass>\n"); - + Iterator i = attrs.keySet().iterator(); while (i.hasNext()) { @@ -617,18 +626,18 @@ } /** - * This method is an auxiliary method for getItemAsXML(boolean, boolean). - * It returns a String that contains a XML representation of the item - * attribute specified by the parameter <code>attribute</code> or the + * This method is an auxiliary method for getItemAsXML(boolean, boolean). + * 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 + * specified by the parameter <code>attribute</code> or the parameters * <code>attribute</code> and <code>value</code> */ protected String getItemAttributeAsXML(String attribute, @@ -644,7 +653,7 @@ if (value == null) { // Object value wasn't specified value = this.getAttribute(attribute); } - + // Handling multilanguage attributes if (attribute.matches(".+_[a-z]{2}")) { // Attribute is multilanguage @@ -658,16 +667,16 @@ } if (value instanceof String) { - // A String can contain any text; therefore it is possible that + // A String can contain any text; therefore it is possible that // the String is not wellformed. So we have to wrap text that is // not wellformed in a CDATA statement if (!((String) value).matches("(?s)<![CDATA[.*]]>") && (ItemAttrs.checkWellFormedXML("<test>" + (String) value + "</test>").length()) > 0) { - + value = ((String) value).replaceAll("\\]\\]>", "]]>"); value = "<![CDATA[" + value + "]]>"; - } + } xml.append(">" + value + "</" + attribute + ">\n"); if (ItemAttrs.checkWellFormedXML(xml.toString()).length() > 0) { @@ -748,10 +757,10 @@ xml.append(" </" + attribute + ">\n"); } else if (value instanceof Boolean) { xml.append(">" + ((Boolean) value).toString() + "</" - + attribute + ">\n"); + + attribute + ">\n"); } else if (value instanceof User) { xml.append(" id=\"" + new Integer(( - (User) value).getId()).toString() + "\"/>\n"); + (User) value).getId()).toString() + "\"/>\n"); } else if (value instanceof Category) { xml.append(" id=\"" + new Integer(( (Category) value).getCategoryId()).toString() + "\"/>\n"); @@ -759,9 +768,6 @@ xml.append(" id=\"" + new Integer(( (Item) value).getLocalId()).toString() + "\"/>\n"); } else if (value instanceof Timestamp) { - //TBD: Check clearly internal and external representation of - // date and date time - //DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); DateFormat format = new SimpleDateFormat(INTERNAL_DATE_FORMAT + " " + INTERNAL_TIME_FORMAT); xml.append(">" + format.format(value) + "</" + attribute @@ -792,7 +798,7 @@ protected String getItemAttributeAsXML(String aname, boolean withXMLDeclaration) { - return this.getItemAttributeAsXML(aname, withXMLDeclaration, + return this.getItemAttributeAsXML(aname, withXMLDeclaration, //this.getAttribute(aname)); null); } |