try { ins = source.openStream(); return registerNodeType(session, ins); } catch (IOException ioe) { log.error("Cannot register node types from " + source, ioe); } catch (RepositoryException re) { if(isReRegisterBuiltinNodeType(re)) { log.debug("Attempt to re-register built-in node type from " + source, re); } else {
/** * Registers node types from the CND file read from the <code>source</code> * with the node type manager available from the given <code>session</code>. * <p> * The <code>NodeTypeManager</code> returned by the <code>session</code>'s * workspace is expected to be of type * <code>org.apache.jackrabbit.api.JackrabbitNodeTypeManager</code> for * the node type registration to succeed. * <p> * This method is not synchronized. It is up to the calling method to * prevent paralell execution. * * @param session The <code>Session</code> providing the node type manager * through which the node type is to be registered. * @param source The <code>InputStream</code> from which the CND file is * read. * @return <code>true</code> if registration of all node types succeeded. * @throws IOException if there is an error parsing the input stream * @throws RepositoryException if another error occurs */ public static boolean registerNodeType(Session session, InputStream source) throws IOException, RepositoryException { return registerNodeType(session, "cnd input stream", new InputStreamReader(source), false); }
public static boolean registerNodeType(Session session, String systemId, Reader reader, boolean reregisterExisting) throws IOException, RepositoryException { try { Workspace wsp = session.getWorkspace(); CndImporter.registerNodeTypes(reader, systemId, wsp.getNodeTypeManager(), wsp.getNamespaceRegistry(), session.getValueFactory(), reregisterExisting); } catch(RepositoryException re) { if(isReRegisterBuiltinNodeType(re)) { log.debug("Attempt to re-register built-in node type, RepositoryException ignored", re); } else { throw re; } } catch (ParseException e) { throw new IOException("Unable to parse CND Input: " + e.getMessage()); } return true; }
@Override public Boolean addNodeTypes(String cnd) throws SerializedException { //Convert cnd String to InputStream InputStream is = null; try { is = new ByteArrayInputStream(cnd.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { log.error("Failed to register node types", e); throw new SerializedException(e.getMessage()); } try { Session session = getJcrSession(); NodeTypeLoader.registerNodeType(session, is); session.save(); } catch (IOException e) { log.error("Failed to register node types", e); throw new SerializedException(e.getMessage()); } catch (RepositoryException e) { log.error("Failed to register node types", e); throw new SerializedException(e.getMessage()); } catch (Exception e) { log.error("Failed to register node types", e); throw new SerializedException(e.getMessage()); } return true; }
String reregister = nodeTypeFileParams.get("reregister"); boolean reregisterBool = Boolean.valueOf(reregister); NodeTypeLoader.registerNodeType(session, mappingURL.toString(), new InputStreamReader(ins), reregisterBool);