|
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() */ |
|
From: Andreas V. <a_...@us...> - 2004-04-12 10:49:19
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23392/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.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- Item.java 11 Apr 2004 17:41:03 -0000 1.15 +++ Item.java 12 Apr 2004 10:35:28 -0000 1.16 @@ -569,8 +569,12 @@ } if (value instanceof String) { + // 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((String) value)).length() > 0) { + && (ItemAttrs.checkWellFormedXML("<test>" + (String) value + + "</test>").length()) > 0) { value = "<![CDATA[" + value + "]]>"; } xml.append(">" + value + "</" + attribute + ">\n"); @@ -653,19 +657,16 @@ 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() + "\">" - + value.toString() + "</" + attribute + ">\n"); + xml.append(" id=\"" + new Integer(( + (User) value).getId()).toString() + "\"/>\n"); } else if (value instanceof Category) { - xml.append(" id=\"" - + new Integer(((Category) value).getCategoryId()).toString() - + "\">" + value.toString() + "</" + attribute + ">\n"); + xml.append(" id=\"" + new Integer(( + (Category) value).getCategoryId()).toString() + "\"/>\n"); } else if (value instanceof Item) { - xml.append(" id=\"" - + new Integer(((Item) value).getLocalId()).toString() - + "\">" + value.toString() + "</" + attribute + ">\n"); + 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 |
|
From: Andreas V. <a_...@us...> - 2004-04-14 18:47:33
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5921/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.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- Item.java 14 Apr 2004 11:54:30 -0000 1.17 +++ Item.java 14 Apr 2004 18:47:24 -0000 1.18 @@ -590,9 +590,11 @@ // 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[.+]]>") + 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"); |
|
From: Andreas V. <a_...@us...> - 2004-04-14 20:18:50
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25819/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.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- Item.java 14 Apr 2004 18:47:24 -0000 1.18 +++ Item.java 14 Apr 2004 20:18:42 -0000 1.19 @@ -212,7 +212,8 @@ private void initFromXML(String xml, ItemManager itemManager) throws CobricksException { - Map attrs = itemManager.extractFromXML(xml, alreadyInstantiated, this); + Map attrs = ItemAttrs.extractFromXML(xml, alreadyInstantiated, this, + itemManager); if (attrs == null) { logger.warn("Item(String, ItemManager): Couldn't instantiate Item"); } else { @@ -234,8 +235,8 @@ this.setFromMap(checkedAttrs); this.usedLanguages.add(this.defaultLanguage); } else { - logger.warn("The item out of the XML didn't pass the ontology" + - "check. Possible reason: Inconsistency."); + logger.warn("The item out of the XML didn't pass the ontology " + + "check. Possible reason: Inconsistency."); throw new CobricksException(itemManager.getComponentId(), Item.XML_INSTANTIATION_EXCEPTION_CODE, "Ontology check failed"); } |
|
From: Andreas V. <a_...@us...> - 2004-04-15 15:57:55
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15458/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.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- Item.java 14 Apr 2004 20:18:42 -0000 1.19 +++ Item.java 15 Apr 2004 15:57:33 -0000 1.20 @@ -83,11 +83,6 @@ */ private String xmlEncoding = "UTF-8"; - /** - * This map contains all items which are already instantiated before - * instantiating this item - */ - private Map alreadyInstantiated; // item attributes cache Map annotations; Map attachments; @@ -118,20 +113,7 @@ throws CobricksException { super(); this.defaultLanguage = itemManager.getDefaultLanguage(); - this.xmlEncoding = itemManager.getXMLEncoding(); - this.alreadyInstantiated = new HashMap(); - this.initFromXML(xml, itemManager); - - } - - protected Item (String xml, - ItemManager itemManager, - Map alreadyInstantiatedItems) - throws CobricksException { - super(); - this.defaultLanguage = itemManager.getDefaultLanguage(); - this.xmlEncoding = itemManager.getXMLEncoding(); - this.alreadyInstantiated = alreadyInstantiatedItems; + this.xmlEncoding = itemManager.getXMLEncoding(); this.initFromXML(xml, itemManager); } @@ -212,8 +194,7 @@ private void initFromXML(String xml, ItemManager itemManager) throws CobricksException { - Map attrs = ItemAttrs.extractFromXML(xml, alreadyInstantiated, this, - itemManager); + Map attrs = ItemAttrs.extractFromXML(xml, itemManager); if (attrs == null) { logger.warn("Item(String, ItemManager): Couldn't instantiate Item"); } else { |
|
From: Andreas V. <a_...@us...> - 2004-04-15 17:33:16
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6615/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.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- Item.java 15 Apr 2004 15:57:33 -0000 1.20 +++ Item.java 15 Apr 2004 17:33:02 -0000 1.21 @@ -772,6 +772,11 @@ return Item.OBJECT_TYPE; } + /** + * This method returns the ItemAnnotation with the annotationId + * @param aid - the annotationId to be looked for + * @return - ItemAnnotation + */ public ItemAnnotation getAnnotation(int aid) { ItemAnnotation ia; @@ -791,11 +796,18 @@ return null; } - + /** + * this method returns a list containing all annotations of this item + * @return - ArrayList with ItemAnnotations + */ public List getAnnotations() { return new ArrayList(this.annotations.values()); } - + /** + * returns the ItemAttachment to the given itemAttachmentId + * @param aid - the ItemAttachmentId + * @return - the corresponding ItemAttachment + */ public ItemAttachment getAttachment(int aid) { ItemAttachment ia; @@ -815,7 +827,10 @@ return null; } - + /** + * returns a list containing all ItemAttachments of this Item + * @return - list of ItemAttachments + */ public List getAttachments() { return new ArrayList(this.attachments.values()); } @@ -848,13 +863,34 @@ public final void setItemClass(String itemClass) { this.itemclass = itemClass; } - protected void addItemAttachment(ItemAttachment ia){ - attachments.put(""+ia.getId(), ia); - } - protected void addItemAnnotation(ItemAnnotation ia){ - annotations.put(""+ia.getId(), ia); + /** + * Adds an ItemAttachment to the Item + * @param ia - an ItemAttachment + */ + protected void addItemAttachment(ItemAttachment ia) { + attachments.put("" + ia.getId(), ia); } - protected void deleteAllAttachments(){ + /** + * Adds an ItemAnnotation to the Item + * @param ia - an ItemAnnotation + */ + protected void addItemAnnotation(ItemAnnotation ia) { + annotations.put("" + ia.getId(), ia); + } + /** + * deletes all Attachments of this Item + * + */ + protected void deleteAllAttachments() { attachments.clear(); } + + /** + * deletes the given ItemAttachment + * @param ia - ItemAttachment to be deleted + */ + public void removeItemAttachment(ItemAttachment ia) { + attachments.remove("" + ia.getId()); + } + } \ No newline at end of file |
|
From: Andreas V. <a_...@us...> - 2004-04-15 20:01:37
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7446/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.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- Item.java 15 Apr 2004 17:33:02 -0000 1.21 +++ Item.java 15 Apr 2004 20:01:27 -0000 1.22 @@ -468,21 +468,21 @@ } /** - * This method returns a String that contains a XML representation of this - * 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 - * 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 - * attachments of this item should be added - * @return String that represents this item - */ + * This method returns a String that contains a XML representation of this + * 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. + * + * @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 + * attachments of this item should be added + * @return String that represents this item + */ public String getItemAsXML(boolean withAnnotations, boolean withAttachments) { logger.debug("getItemAsXML"); @@ -527,7 +527,7 @@ } /** - * This method is an auxiliary method for getItemAsXML. + * 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>. |
|
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 { |
|
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); } |
|
From: Andreas V. <a_...@us...> - 2004-04-26 14:09:28
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20183/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.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- Item.java 24 Apr 2004 13:35:10 -0000 1.25 +++ Item.java 26 Apr 2004 14:09:20 -0000 1.26 @@ -122,7 +122,8 @@ private Set usedLanguages = new HashSet(); /** - * This map contains all attributes except local id, global id and item class. + * This map contains all attributes except local id, global id and item + * class. */ protected Map attrs = new HashMap(); @@ -365,16 +366,13 @@ return title; } else { // Try to get a title in any language - Set keys = attrs.keySet(); - Iterator keyIterator = keys.iterator(); + Iterator it = this.usedLanguages.iterator(); - while (keyIterator.hasNext()) { - String key = (String) keyIterator.next(); - if (key.startsWith("title")) { - title = getStringAttribute(key); - if ((title != null) && (title.length() > 0)) { - return title; - } + while (it.hasNext()) { + String next = (String) it.next(); + + if (attrs.containsKey("title_" + next)) { + return this.getStringAttribute("title_" + next); } } // No title was specified for this item @@ -420,10 +418,6 @@ this.usedLanguages.add(lang); setAttribute("description_" + lang, description); } - - public String getDefaultLanguage() { - return defaultLanguage; - } public String getUrl() { return getStringAttribute("url"); @@ -569,8 +563,8 @@ /** * This method returns a String that contains a XML representation of this * item. - * To do this the method calls getItemAttributeAsXML(String, boolean, Object) - * for each attribute of this 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 @@ -582,7 +576,8 @@ * attachments of this item should be added * @return String that represents this item */ - public String getItemAsXML(boolean withAnnotations, boolean withAttachments) { + public String getItemAsXML(boolean withAnnotations, + boolean withAttachments) { logger.debug("getItemAsXML"); StringBuffer xml = new StringBuffer(); @@ -624,12 +619,12 @@ return xml.toString(); } - + /** * 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>. + * 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 @@ -637,8 +632,8 @@ * @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> + * specified by the parameter "attribute" or the parameters "attribute" and + * "value" */ protected String getItemAttributeAsXML(String attribute, boolean withXMLDeclaration, Object value) { @@ -680,11 +675,9 @@ xml.append(">" + value + "</" + attribute + ">\n"); if (ItemAttrs.checkWellFormedXML(xml.toString()).length() > 0) { - logger.warn( - "getItemAttributeAsXML: Value of XML Attribute " - + attribute - + " isn't well formed.\n I will ignore this " - + "attribute. Check syntax of:\n" + xml); + logger.warn("getItemAttributeAsXML: Value of XML Attribute " + + attribute + " isn't well formed.\n I will ignore this" + + " attribute. Check syntax of:\n" + xml); return null; } @@ -698,9 +691,7 @@ return null; } - xml.append(">\n"); - Object temp = getItemAttributeAsXML("string", false, obj); if (temp != null) { @@ -737,9 +728,7 @@ return null; } - xml.append(">\n"); - Object temp = getItemAttributeAsXML(name, false, obj); if (temp != null) { @@ -773,7 +762,8 @@ xml.append(">" + format.format(value) + "</" + attribute + ">\n"); } else if (value instanceof java.sql.Date) { - DateFormat dateFormat = new SimpleDateFormat(INTERNAL_DATE_FORMAT); + DateFormat dateFormat = + new SimpleDateFormat(INTERNAL_DATE_FORMAT); xml.append(">" + dateFormat.format(value) + "</" + attribute + ">\n"); } else if (value instanceof Integer) { @@ -988,4 +978,5 @@ */ public void removeItemAttachment(ItemAttachment ia) { attachments.remove("" + ia.getId()); - }} \ No newline at end of file + } +} \ No newline at end of file |
|
From: Andreas V. <a_...@us...> - 2004-04-29 18:45:53
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23719/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.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- Item.java 26 Apr 2004 14:09:20 -0000 1.26 +++ Item.java 29 Apr 2004 18:45:41 -0000 1.27 @@ -35,27 +35,32 @@ public class Item extends org.cobricks.core.DataObject implements java.io.Serializable { private static final int OBJECT_TYPE = -1; + /** * This is the cobricks error code that is used if there is an exception * during instantiation. */ protected static final String XML_INSTANTIATION_EXCEPTION_CODE = "411"; + /** * Standard logger for logging events. */ private static Logger logger = Logger.getLogger(Item.class); + /** * This defines the format used in all internal string representations * of dates. */ public static final String INTERNAL_DATE_FORMAT = "yyyy.MM.dd"; + /** * This defines the format used in all internalt string representations * of time (mostly datetime = date + " " + time). */ public static final String INTERNAL_TIME_FORMAT = "HH:mm:ss.SSS"; - /** This constant defines the default maximum depth of recursive + /** + * This constant defines the default maximum depth of recursive * instantiations: -1 means infinite, 0 means no recursive instantion * (return id instead), >0 means the maximum number of instantiations before * only the id is returned. @@ -79,12 +84,14 @@ */ protected String itemclass; - /** This defines the default maximum depth of recursive + /** + * This defines the default maximum depth of recursive * instantiations: -1 means infinite, 0 means no recursive instantion * (return id instead), >0 means the maximum number of instantiations before * only the id is returned. */ private int recursiveLevel = Item.DEFAULT_RECURSIVE_LEVEL; + /** * The default language is used in all multi language attributes in case * no custom language is defined. @@ -235,6 +242,20 @@ throw new Exception("failed loading item"); */ } + + /** + * This method is an auxiliary method for some of the constructors. + * It extracts the attributes of an Item from a XML representation by + * calling the method extractFromXML(String, Map, Item, ItemManager) of the + * ItemAttrs class. + * Afterwards this method checks and sets the attributes. + * + * @param xml The XML representation of the Item to be initialized + * @param itemManager ItemManager, used to pass it to some auxiliary methods + * @throws CobricksException This can be thrown if the attributes that were + * extracted from the String "xml" didn't pass the check against the + * itemontology + */ private void initFromXML(String xml, ItemManager itemManager) throws CobricksException { @@ -253,22 +274,29 @@ } else { attrs.remove("itemclass"); } + this.annotations = (Map) attrs.get("annotations"); + attrs.remove("annotations"); + this.attachments = (Map) attrs.get("attachments"); + attrs.remove("attachments"); + + // Check the extracted attributes against the itemontology Map checkedAttrs = ItemAttrs.checkAttrsAgainstOntology(attrs, - itemManager,this.itemclass, false, this.getRecursiveLevel()); + itemManager, this.itemclass, false, this.getRecursiveLevel()); if (checkedAttrs != null) { logger.debug("item has the following attrs:" + attrs.keySet().toString()); this.setFromMap(checkedAttrs); this.usedLanguages.add(this.defaultLanguage); } else { - logger.warn("The item out of the XML didn't pass the ontology " - + "check. Possible reason: Inconsistency."); - throw new CobricksException(itemManager.getComponentId(), - Item.XML_INSTANTIATION_EXCEPTION_CODE, "Ontology check failed"); + logger.warn("The item out of the XML didn't pass the ontology " + + "check. Possible reason: Inconsistency."); + throw new CobricksException(itemManager.getComponentId(), + Item.XML_INSTANTIATION_EXCEPTION_CODE, + "Ontology check failed"); } - } } + /** * @see org.cobricks.core.DataObject#getObjectUri() */ @@ -298,7 +326,8 @@ return this.alreadyInstantiated; } - /** This defines the default maximum depth of recursive + /** + * This defines the default maximum depth of recursive * instantiations: -1 means infinite, 0 means no recursive instantion * (return id instead), >0 means the maximum number of instantiations before * only the id is returned. @@ -494,6 +523,7 @@ } public void removeAttribute(String aname, String userid) { + // TBD this.removeAttribute(aname); } @@ -608,11 +638,41 @@ } if (withAnnotations) { - //TBD: do something + List annotations = this.getAnnotations(); + + // Print out the id of every annotation + if ((annotations != null) && (!annotations.isEmpty())) { + xml.append("<annotations>\n"); + Iterator annIterator = annotations.iterator(); + + while (annIterator.hasNext()) { + ItemAnnotation annotation = + (ItemAnnotation) annIterator.next(); + xml.append(" <annotation id=\"" + annotation.getId() + + "\"/>\n"); + } + + xml.append("</annotations>\n"); + } } if (withAttachments) { - //TBD: do something + List attachments = this.getAttachments(); + + // Print out the id of every attachment + if ((attachments != null) && (!attachments.isEmpty())) { + xml.append("<attachments>\n"); + Iterator attIterator = attachments.iterator(); + + while (attIterator.hasNext()) { + ItemAttachment attachment = + (ItemAttachment) attIterator.next(); + xml.append(" <attachment id=\"" + attachment.getId() + + "\"/>\n"); + } + + xml.append("</attachments>\n"); + } } xml.append("</item>"); @@ -785,12 +845,19 @@ } } - + /** + * This method is a convenience method for calling the method + * getItemAttributeAsXML(String, boolean, Object). + * + * @param aname The name of the Object to be "transformed" + * @param withXMLDeclaration If set a XML declaration is added at the + * beginning of the returned String + * @return String that holds a XML representation of the item attribute + * specified by the parameter "aname" + */ protected String getItemAttributeAsXML(String aname, boolean withXMLDeclaration) { - return this.getItemAttributeAsXML(aname, withXMLDeclaration, - //this.getAttribute(aname)); - null); + return this.getItemAttributeAsXML(aname, withXMLDeclaration, null); } /** |
|
From: Andreas V. <a_...@us...> - 2004-05-07 07:33:43
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27645/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.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- Item.java 7 May 2004 07:22:40 -0000 1.28 +++ Item.java 7 May 2004 07:33:34 -0000 1.29 @@ -54,7 +54,7 @@ public static final String INTERNAL_DATE_FORMAT = "yyyy.MM.dd"; /** - * This defines the format used in all internalt string representations + * This defines the format used in all internal string representations * of time (mostly datetime = date + " " + time). */ public static final String INTERNAL_TIME_FORMAT = "HH:mm:ss.SSS"; @@ -1047,4 +1047,4 @@ public void removeItemAttachment(ItemAttachment ia) { attachments.remove("" + ia.getId()); } -} +} \ No newline at end of file |
|
From: Andreas V. <a_...@us...> - 2004-05-14 18:03:53
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26354/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.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- Item.java 7 May 2004 07:33:34 -0000 1.29 +++ Item.java 14 May 2004 18:03:42 -0000 1.30 @@ -10,6 +10,7 @@ import org.cobricks.user.User; +import java.io.IOException; import java.sql.Timestamp; import java.text.DateFormat; @@ -33,7 +34,7 @@ * Copyright (c) 2003 Michael Koch, mic...@ac... */ public class Item extends org.cobricks.core.DataObject - implements java.io.Serializable { + implements java.io.Externalizable { private static final int OBJECT_TYPE = -1; /** @@ -245,6 +246,55 @@ } /** + * This method is used to deserialize this Item. + * + * @param s The serialized Item + * @throws ClassNotFoundException + * @throws IOException + */ + public void readExternal(java.io.ObjectInput s) + throws ClassNotFoundException, IOException { + itemid = s.readInt(); + globalid = s.readUTF(); + itemclass = s.readUTF(); + recursiveLevel = s.readInt(); + defaultLanguage = s.readUTF(); + xmlEncoding = s.readUTF(); + Object temp = s.readObject(); + if (temp != null) { + alreadyInstantiated = (Map) temp; + } + annotations = (Map) s.readObject(); + attachments = (Map) s.readObject(); + usedLanguages = (Set) s.readObject(); + attrs = (Map) s.readObject(); + } + + /** + * This method is used to serialize this Item. + * + * @param s Specifies the location where the Item is written to. + * @throws IOException + */ + public void writeExternal(java.io.ObjectOutput s) throws IOException { + s.writeInt(itemid); + s.writeUTF(globalid); + if ((itemclass != null) && (itemclass.length() > 0)) { + s.writeUTF(itemclass); + } else { + s.writeUTF("item"); + } + s.writeInt(recursiveLevel); + s.writeUTF(defaultLanguage); + s.writeUTF(xmlEncoding); + s.writeObject(alreadyInstantiated); + s.writeObject(annotations); + s.writeObject(attachments); + s.writeObject(usedLanguages); + s.writeObject(attrs); + } + + /** * This method is an auxiliary method for some of the constructors. * It extracts the attributes of an Item from a XML representation by * calling the method extractFromXML(String, Map, Item, ItemManager) of the |
|
From: Stefan H. <ste...@us...> - 2004-05-15 10:24:36
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15848/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.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- Item.java 14 May 2004 18:03:42 -0000 1.30 +++ Item.java 15 May 2004 10:24:28 -0000 1.31 @@ -1097,4 +1097,18 @@ public void removeItemAttachment(ItemAttachment ia) { attachments.remove("" + ia.getId()); } + /** + * This method returns the amount of attachments this file has. + * @return An int value + */ + public int getAttachmentCount() { + return attachments.size(); + } + /** + * This method returns the amount of attachments this file has. + * @return An int value + */ + public int getAnnotationCount() { + return annotations.size(); + } } \ No newline at end of file |
|
From: Wolfgang L. <w_l...@us...> - 2004-11-08 19:39:54
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10426/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.42 retrieving revision 1.43 diff -u -d -r1.42 -r1.43 --- Item.java 23 Oct 2004 15:47:01 -0000 1.42 +++ Item.java 8 Nov 2004 19:39:45 -0000 1.43 @@ -310,6 +310,22 @@ tmps = this.replace(tmps, """, "\""); attrs.put(key, tmps); } + pos = tmps.indexOf(">"); + if (pos > -1) { + tmps = this.replace(tmps, ">", ">"); + attrs.put(key, tmps); + } + pos = tmps.indexOf("<"); + if (pos > -1) { + tmps = this.replace(tmps, "<", "<"); + attrs.put(key, tmps); + } + pos = tmps.indexOf("&"); + if (pos > -1) { + tmps = this.replace(tmps, "&", "&"); + attrs.put(key, tmps); + } + } } } catch (Exception e) { |
|
From: jiang <jia...@us...> - 2006-02-13 21:07:50
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25459/src/org/cobricks/item Modified Files: Item.java Log Message: update Item.java Index: Item.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/Item.java,v retrieving revision 1.49 retrieving revision 1.50 diff -u -d -r1.49 -r1.50 --- Item.java 16 Jan 2006 09:23:44 -0000 1.49 +++ Item.java 13 Feb 2006 21:07:42 -0000 1.50 @@ -828,7 +828,7 @@ * Adds an ItemAnnotation to the Item * @param ia - an ItemAnnotation */ - protected void addItemAnnotation(ItemAnnotation ia) + public void addItemAnnotation(ItemAnnotation ia) { annotations.put(Integer.toString(ia.getId()), ia); } |