Update of /var/cvs/src/org/mmbase/framework
In directory james.mmbase.org:/tmp/cvs-serv8861
Modified Files:
BasicComponent.java Block.java ComponentRepository.java
Log Message:
MMB-1581
See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/framework
See also: http://www.mmbase.org/jira/browse/MMB-1581
Index: BasicComponent.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/framework/BasicComponent.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- BasicComponent.java 23 Feb 2008 12:15:54 -0000 1.44
+++ BasicComponent.java 11 Apr 2008 09:57:24 -0000 1.45
@@ -23,7 +23,7 @@
* components, and may be requested several blocks.
*
* @author Michiel Meeuwissen
- * @version $Id: BasicComponent.java,v 1.44 2008/02/23 12:15:54 michiel Exp $
+ * @version $Id: BasicComponent.java,v 1.45 2008/04/11 09:57:24 michiel Exp $
* @since MMBase-1.9
*/
public class BasicComponent implements Component {
@@ -141,7 +141,9 @@
Element element = (Element) blockElements.item(i);
String blockName = element.getAttribute("name");
String mimetype = element.getAttribute("mimetype");
- Block.Type[] classification =
Block.Type.getClassification(element.getAttribute("classification"), true);
+ String classification = element.getAttribute("classification");
+ // create types if missing
+ Block.Type.getClassification(classification, true);
Block b = new Block(blockName, mimetype, this, classification);
b.getDescription().fillFromXml("description", element);
b.getTitle().fillFromXml("title", element);
Index: Block.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/framework/Block.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- Block.java 21 Mar 2008 16:08:16 -0000 1.36
+++ Block.java 11 Apr 2008 09:57:24 -0000 1.37
@@ -21,7 +21,7 @@
*
* @author Johannes Verelst
* @author Michiel Meeuwissen
- * @version $Id: Block.java,v 1.36 2008/03/21 16:08:16 michiel Exp $
+ * @version $Id: Block.java,v 1.37 2008/04/11 09:57:24 michiel Exp $
* @since MMBase-1.9
*/
public class Block {
@@ -40,16 +40,17 @@
private final LocalizedString title;
private final Type[] classification;
- public Block(String name, String mimetype, Component parent, Type[] cla) {
+ public Block(String name, String mimetype, Component parent, String cla) {
if (name == null) throw new IllegalArgumentException();
if (parent == null) throw new IllegalArgumentException();
if (cla == null) throw new IllegalArgumentException();
this.name = name;
this.parent = parent;
this.mimetype = mimetype; // can this be null?
- this.classification = cla;
- for (Type t : classification) {
- t.blocks.add(this);
+ this.classification = Block.Type.getClassification(cla, false);
+ for (BlockContainer bc : Block.Type.getWeightedClassification(this,
cla)) {
+ bc.getType().blocks.add(bc);
+ Collections.sort(bc.getType().blocks);
}
this.description = new LocalizedString(name);
this.title = new LocalizedString(name);
@@ -187,8 +188,7 @@
for (String part : p.split("\\s*?[,\\s]\\s*")) {
Type type = ROOT;
for (String subpart : part.split("\\.")) {
- int weight =
subpart.contains(":")?Integer.parseInt(subpart.substring(subpart.indexOf(":")+1)):0;
- subpart =
subpart.contains(":")?subpart.substring(0,subpart.indexOf(":")):subpart;
+
Type proposal = new Type(subpart, type);
int index = type.subs.indexOf(proposal);
if (index == -1) {
@@ -207,12 +207,45 @@
}
return result.toArray(new Type[] {});
}
+
+ static Collection<BlockContainer> getWeightedClassification(final
Block b, final String p) {
+ List<BlockContainer> result = new ArrayList<BlockContainer>();
+ PARTS:
+ for (String part : p.split("\\s*?[,\\s]\\s*")) {
+
+ int weight;
+ int colon = part.indexOf(":");
+ if (colon > 0) {
+ weight = Integer.parseInt(part.substring(colon + 1));
+ part = part.substring(0, colon);
+ } else {
+ weight = 100;
+ }
+
+ Type type = ROOT;
+ for (String subpart : part.split("\\.")) {
+
+ Type proposal = new Type(subpart, type);
+ int index = type.subs.indexOf(proposal);
+ if (index == -1) {
+ continue PARTS;
+ } else {
+ proposal = type.subs.get(index);
+ }
+ type = proposal;
+ }
+ BlockContainer bc = new BlockContainer(b, type, weight);
+
+ result.add(bc);
+ }
+ return result;
+ }
private final LocalizedString title;
private final String name;
private final Type parent;
private int weight = 100;
final List<Type> subs = new ArrayList<Type>();
- final List<Block> blocks = new ArrayList<Block>();
+ final List<BlockContainer> blocks = new ArrayList<BlockContainer>();
private Type(String n) {
name = n;
parent = null;
@@ -225,12 +258,20 @@
parent = p;
title = new LocalizedString(name);
}
+
public List<Type> getSubTypes() {
return Collections.unmodifiableList(subs);
}
public List<Block> getBlocks() {
- return Collections.unmodifiableList(blocks);
+ return new AbstractList<Block>() {
+ public int size() {
+ return blocks.size();
+ }
+ public Block get(int i) {
+ return blocks.get(i).get();
+ }
+ };
}
public String getName() {
return name;
@@ -281,5 +322,31 @@
}
}
+ static class BlockContainer implements Comparable<BlockContainer> {
+ final int weight;
+ final Block block;
+ final Block.Type type;
+ BlockContainer(Block block, Block.Type type, int weight) {
+ this.block = block;
+ this.weight = weight;
+ this.type = type;
+ }
+
+ Block get() {
+ return block;
+ }
+ Block.Type getType() {
+ return type;
+ }
+ public int compareTo(BlockContainer o) {
+ int c = weight - o.weight;
+ if (c != 0) {
+ return c;
+ } else {
+ return block.getName().compareTo(o.get().getName());
+ }
+ }
+ }
+
}
Index: ComponentRepository.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/framework/ComponentRepository.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- ComponentRepository.java 25 Mar 2008 09:20:24 -0000 1.33
+++ ComponentRepository.java 11 Apr 2008 09:57:24 -0000 1.34
@@ -24,7 +24,7 @@
* This (singleton) class maintains all compoments which are registered in the
current MMBase.
*
* @author Michiel Meeuwissen
- * @version $Id: ComponentRepository.java,v 1.33 2008/03/25 09:20:24 michiel
Exp $
+ * @version $Id: ComponentRepository.java,v 1.34 2008/04/11 09:57:24 michiel
Exp $
* @since MMBase-1.9
*/
public class ComponentRepository {
@@ -65,7 +65,8 @@
private ComponentRepository() { }
/**
- * @javadoc
+ * Converts a comma seperated list of blocks to an array of [EMAIL
PROTECTED] Block.Type}.s. Possible
+ * 'weights' per block are ignored.
*/
public Block.Type[] getBlockClassification(String id) {
if (id == null) {
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs