package mentata.ldaphttp.gospel; import mentata.ldaphttp.LDAPHttpObject; import mentata.ldaphttp.LDAPHttpVirtualAttribute; import mentata.ldaphttp.LDAPHttpException; import mentata.gateway.GatewayObject; import mentata.gateway.GatewayCisAttribute; import mentata.gateway.GatewayDnAttribute; import mentata.gateway.GatewayReverseDnAttribute; import mentata.gateway.GatewayURLAttribute; import mentata.gateway.GatewayUTCAttribute; import mentata.gateway.GatewayHRAttribute; /** * A directory entry that represents a Jesus weblog passage. */ public class comment extends GatewayObject { // the highest current identifier in use private static int[] id_number = {0}; // the prefix used in identifiers for new entries private static final String id_prefix = "CJBA"; /** * Instantiates an empty template for a Jesus weblog passage or comment. */ public comment() throws LDAPHttpException { // add the object class unique to these objects addObjectclasses(new String[] {"notion", "expression"}); // set default values for this object useServlets( new String[] {"retrieve", "create"} ); useFormats( new String[] {"html"} ); setDirectoryLocation("ou=Comments, ou=Expressions, o=mentata.com", SUBTREE); setFilter("(businesscategory=jesus)"); setLabel("Jesus Blog Comment"); setSorting(new String[] {"dnqualifier"}, new boolean[] {false}); setStylesheet("/styles/gospel.css"); setFooter("http://localhost/includes/gospel_footer.htm"); // add the attributes for this object class addAttribute( new GatewayCisAttribute(), "uid", "UID", REQUIRED, SINGLEVALUE); addAttribute( new GatewayCisAttribute(), "cn", "Title", REQUIRED, SINGLEVALUE); addAttribute( new GatewayCisAttribute(), "description", "Taken", OPTIONAL, SINGLEVALUE); addAttribute( new GatewayCisAttribute(), "businesscategory", "", OPTIONAL, SINGLEVALUE); addAttribute( new GatewayCisAttribute(), "content", "", OPTIONAL, SINGLEVALUE); addAttribute( new GatewayUTCAttribute(), "dnqualifier", "Added", OPTIONAL, SINGLEVALUE); addAttribute( new GatewayURLAttribute(), "link", "See", OPTIONAL, SINGLEVALUE); addAttribute( new GatewayDnAttribute(getContextName(), "person"), "owner", "By", OPTIONAL, MULTIVALUE); addAttribute( new GatewayDnAttribute(getContextName(), "comment"), "parent", "In response to", OPTIONAL, SINGLEVALUE); addAttribute( new GatewayHRAttribute(), "commenthr", "Comments", OPTIONAL, SINGLEVALUE); addAttribute( new CommentSubtreeAttribute(), "child", "", OPTIONAL, MULTIVALUE); addAttribute( new CommentFormAttribute(), "commentform", "", OPTIONAL, SINGLEVALUE); // set basic attribute lists for this object class addAttributeList("identify", new String[] {"uid", "cn"} ); addAttributeList("hyperlink", getAttributeList("identify") ); // set attribute lists to support retrievability addAttributeList("retrieve_list", new String[] {"description"} ); addAttributeList("retrieve_tabtext", new String[] {"cn", "content"} ); addAttributeList("retrieve_html", new String[] {"dnqualifier", "owner", "description", "parent", "link", "content", "commenthr", "child", "commentform"} ); } /** * Infers and sets the attribute's identifier. */ public void preCreate() throws LDAPHttpException { resetAttribute(getIdentifierAttribute(), new String[] { getNextIdentifier() }); resetAttribute("dnqualifier", new String[] { getTimestamp() }); if (getAttribute("cn").getValues() == null) resetAttribute("cn", new String[] {"untitled"}); } // determines the next identifier for use private String getNextIdentifier() throws LDAPHttpException { // use the next id number if (id_number[0] != 0) { synchronized (id_number) { id_number[0]++; } String test_filter = "(" + getIdentifierAttribute() + "=" + id_prefix + id_number[0] + ")"; if ( hasMatch(test_filter) ) { synchronized (id_number) { id_number[0] = 0; } } } // infer and store the next id number when unknown if (id_number[0] == 0) { synchronized (id_number) { int base = 0; int power = 0; int testid = 1; for(;;) { int previd = testid; testid = base + (1 << power); String filter = "(" + getIdentifierAttribute() + "=" + id_prefix + testid + ")"; if ( hasMatch(filter) ) { power++; } else { if (power > 1 ) { base = previd; power = 0; } else { id_number[0] = testid; break; } } } } } // return a newly constructed identifier return id_prefix + id_number[0]; } /** * An attribute for displaying all responding comments and sub-comments. */ public class CommentSubtreeAttribute extends GatewayReverseDnAttribute { /** * Creates an empty comment subtree attribute for the given translation class. * * @param chapter_class the name of the target chapter translation class */ public CommentSubtreeAttribute() { super(getContextName(), "comment", "parent"); } /** * Returns a subtree of comments. * * @return an array of comment subtrees * @throws LDAPHttpException if the target object can't be instantiated */ public String[] getHTMLValues() throws LDAPHttpException { // initialize the return value String[] formatted_values = super.getHTMLValues(); String[] current_values = getValues(); String[] final_values = null; if (current_values != null) { final_values = new String[current_values.length]; // recursively call the comment subtree for each comment LDAPHttpObject current_object = getTargetObject(); for (int i = 0; i < formatted_values.length; i++) { StringBuffer results_buffer = new StringBuffer("