Hi -- my attachments did not appear. Let me try that again with just code inserted.

Here's the servlet code that registers or re-registers node types:

===========================================

public class NodeTypeConfigServlet extends HttpServlet{

/**
 * default logger
 */
private static final Logger log = LoggerFactory.getLogger(NodeTypeConfigServlet.class);

static final String NODETYPE_CND_FILE_NAME="edgeNodeTypes.cnd";
static final String EDGE_NAMESPACE_URI="http://www.edgenuity.com/edge";;
static final String EDGE_PREFIX="edge";
static final String SUPERUSER_USER="admin";
static final String SUPERUSER_PW ="admin";

private Repository repository = null;

public void init() throws ServletException {
 super.init();
 CompactNodeTypeDefReader cndReader;

 try {
  //repository = rf.getRepository();
  repository = new ServletRepository(this);

  char[] pwarr = SUPERUSER_PW.toCharArray();
  SimpleCredentials sc = new SimpleCredentials(SUPERUSER_USER,pwarr);
  Session session = repository.login(sc, null);
  Workspace ws = session.getWorkspace();
  NamespaceRegistry nsReg = ws.getNamespaceRegistry();
  try {
   String uri = nsReg.getURI(EDGE_PREFIX);
log.info("Prefix "+EDGE_PREFIX+" has already been registered under URI of "+uri);

  } catch(NamespaceException nex) {
   // prefix is not mapped, so register it
   nsReg.registerNamespace(EDGE_PREFIX, EDGE_NAMESPACE_URI);
  }

  // Read in the CND file
InputStreamReader rd = new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(NODETYPE_CND_FILE_NAME));
  //
  // Create a CompactNodeTypeDefReader
  cndReader = new CompactNodeTypeDefReader(rd, NODETYPE_CND_FILE_NAME);

  // Get the List of NodeTypeDef objects
  List ntdList = cndReader.getNodeTypeDefs();

  // Get the NodeTypeManager from the Workspace.
  // Note that it must be cast from the generic JCR NodeTypeManager to the
  // Jackrabbit-specific implementation.
  NodeTypeManagerImpl ntmgr =(NodeTypeManagerImpl)ws.getNodeTypeManager();

  // Acquire the NodeTypeRegistry
  NodeTypeRegistry ntreg = ntmgr.getNodeTypeRegistry();


  // Loop through the prepared NodeTypeDefs
  for (Iterator i = ntdList.iterator(); i.hasNext();) {

   // Get the NodeTypeDef...
   NodeTypeDef ntd = (NodeTypeDef)i.next();

   log.info("----NODE TYPE DEF node name="+ntd.getName());
   // register it if it is not already registered
   if (ntreg.isRegistered(ntd.getName())) {
log.info("Node type "+ntd.getName()+ " is already registered -- it will be re-registered in case properties have been changed");
   }

   else {
    log.info("Node type "+ntd.getName()+" wil be registered ");
    ntreg.registerNodeType(ntd);
   }
  }

 }
 catch (NamespaceException nex) {
  throw new ServletException(nex);
 }
 catch (RepositoryException ex) {
  throw new ServletException(ex);
 }
 catch (org.apache.jackrabbit.core.nodetype.compact.ParseException pex) {
  throw new ServletException(pex);
 }
catch (org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException iex) {
  throw new ServletException(iex);
 }
}
}

======================================================
and here's the snippet that dumps out nodes on the client side via the spi webdav interface:

private void dump(Node node, boolean expandBin) throws RepositoryException
 {
   System.out.println("NODE = "+node.getPath());
   PropertyIterator properties = node.getProperties();
   Property property = null;
   while (properties.hasNext()) {
property = properties.nextProperty();
System.out.print("----Property "+property.getPath() + "=");
if (property.getDefinition().isMultiple()) {
    Value[] values = property.getValues();
    for (int i = 0; i < values.length; i++) {
 if (i > 0)
     System.out.println(",");
 System.out.println(values[i].getString());
    }
} else {
    if (property.getType() != PropertyType.BINARY)
 System.out.print(property.getString());
    else if (expandBin)
 System.out.print(property.getString());
    else
 System.out.print("["+property.getLength()+"] Data Not Printed!");
}
System.out.println();
   }
   NodeIterator nodes = node.getNodes();
   while (nodes.hasNext()) {
Node child = nodes.nextNode();
dump(child, expandBin);
   }
 }






----- Original Message ----- From: "Betty Chang" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, July 31, 2008 2:12 PM
Subject: Re: what does NodeTypeRegistry.reregisterNodeType() do?


Hi -- I've attached a couple of pieces of code.  The servlet is the code
that registers or re-registers the node types.  I run it
in the same webapp as jackrabbit, and have it load on startup after
everything else.
The dumpsnippet.java is from a test program that just dumps the nodes.   I
call it at the "/jcr.system/jcr.nodeTypes" level
 to see all the node types and their properties.   This is run via the spi
webdav interface.

I can add node types to the CND file and restart tomcat and all is well, but
adding non-mandatory properties to an
exisiting node type does not seem to do anything.

Thanks

Betty

----- Original Message ----- From: "Betty Chang" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, July 30, 2008 12:13 PM
Subject: Re: what does NodeTypeRegistry.reregisterNodeType() do?


Hi -- I'm doing the nodetype registration on the server side as a servlet.
Originally,
I did it in a separate webapp in the same tomcat server
as the jackrabbit server, then I changed it to a servlet within the
jackrabbit webapp.
I configured the servlet to load on startup after all other startup
servlets.  It reads in the .CND file, checks if a nodetype
already exists, and if so, it re-registers it.  If not, it just registers
it.

My client programs are able to add to the repository using these custom
node types and they show up under
jcr:system/jcr:nodeTypes in the tree.

I can add a new node type to the CND file, restart the tomcat, and the new
node type shows up in the dump on
the client side.
However, if I add a new property to an existing node type, the new
property does not show up.

I'm not sure why it would be a caching issue, because my client program is
just a little test program that can dump out all
the nodes and I run it fresh everytime.

Betty

----- Original Message ----- From: "Angela Schreiber" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, July 30, 2008 2:10 AM
Subject: Re: what does NodeTypeRegistry.reregisterNodeType() do?



In answer to the protocol question,  the remote client uses the spi
webdav
interface

ah, i see. that explains it. this is probably a caching issue of the spi
layer.

the SPI layer does not support nodetype registration
anyway, since this a jackrabbit specific extension
and not part of the JCR API.
how did you register the nodetype?

please feel free to create a jira issue.

before you create an issue, i'd like to understand
how you registered the nodetype.

angela





Reply via email to