@Ignore // @Test(timeout=5000) public void benchmark() throws RepositoryException { /* once to warm up, second one for real */ String uuid = documents.get(random.nextInt(documents.size())); Node document = session.getNodeByUUID(uuid); document = document.getNode(document.getName()); long t1 = System.currentTimeMillis(); Set<Node> referrers = getReferrers(document); if (log.isDebugEnabled()) { System.err.println("result " + referrers.size() + " out of " + documents.size()); } long t2 = System.currentTimeMillis(); if (log.isDebugEnabled()) { System.err.println("timing references " + (t2 - t1) / 1000.0); } uuid = documents.get(random.nextInt(documents.size())); document = session.getNodeByUUID(uuid); document = document.getNode(document.getName()); t1 = System.currentTimeMillis(); referrers = getReferrers(document); t2 = System.currentTimeMillis(); if (log.isDebugEnabled()) { System.err.println("timing references " + (t2 - t1) / 1000.0); } }
public void testGenerateFeed2() throws Exception { Map<String, String> contextPodcast = new HashMap<String, String>(); contextPodcast.put("exo:feedType", "podcast"); contextPodcast.put("repository", "repository"); contextPodcast.put("srcWorkspace", COLLABORATION_WS); contextPodcast.put("actionName", "actionName"); contextPodcast.put("exo:rssVersion", "rss_1.0"); contextPodcast.put("exo:feedTitle", "Hello Feed"); contextPodcast.put("exo:link", "Testing"); contextPodcast.put("exo:summary", "Hello Summary"); contextPodcast.put("exo:description", "Hello Description"); contextPodcast.put("exo:storePath", "/Feeds"); contextPodcast.put("exo:feedName", "podcastName"); contextPodcast.put( "exo:queryPath", "SELECT * FROM exo:article where jcr:path LIKE '/Documents/%'"); contextPodcast.put("exo:title", "Hello Title"); contextPodcast.put("exo:url", "http://twitter.com"); rssService.generateFeed(contextPodcast); session.getRootNode().addNode("Feeds"); Node myFeeds = (Node) session.getItem("/Feeds"); myFeeds.addNode("podcast"); Node myPodcast = (Node) session.getItem("/Feeds/podcast"); myPodcast.addNode("podcastName"); Node myPodcastName = (Node) session.getItem("/Feeds/podcast/podcastName"); assertEquals("Feeds", myFeeds.getName()); assertEquals("podcast", myPodcast.getName()); assertEquals("podcastName", myPodcastName.getName()); }
@Test public void shouldAllowDataPersistedInOneSessionBeAccessibleInOtherSessions() throws Exception { startRepository(); Session session = getRepository().login(getTestCredentials()); assertThat(session, is(notNullValue())); assertThat(session.getRootNode(), is(notNullValue())); // Create a child node ... Node node = session.getRootNode().addNode("testnode", "nt:unstructured"); assertThat(node, is(notNullValue())); assertThat(node.getName(), is("testnode")); assertThat(node.getPath(), is("/testnode")); // Save and close the session ... session.save(); session.logout(); for (int i = 0; i != 3; ++i) { // Create another session ... session = getRepository().login(getTestCredentials()); assertThat(session, is(notNullValue())); assertThat(session.getRootNode(), is(notNullValue())); // Look for the child node ... node = session.getRootNode().getNode("testnode"); assertThat(node, is(notNullValue())); assertThat(node.getName(), is("testnode")); assertThat(node.getPath(), is("/testnode")); // Close the session ... session.logout(); } }
public void tearDown() throws Exception { List<Node> lstNode = taxonomyService.getAllTaxonomyTrees(true); for (Node tree : lstNode) { if (!tree.getName().equals("System")) taxonomyService.removeTaxonomyTree(tree.getName()); } for (String s : new String[] {"/Article", "/MyDocuments"}) if (session.itemExists(s)) { session.getItem(s).remove(); session.save(); } super.tearDown(); }
@Test public void shouldFindTreeBranchAsPrimaryItemUnderGitRoot() throws Exception { Node git = gitNode(); Node tree = git.getNode("tree"); assertThat(tree, is(notNullValue())); Item primaryItem = git.getPrimaryItem(); assertThat(primaryItem, is(notNullValue())); assertThat(primaryItem, is(instanceOf(Node.class))); Node primaryNode = (Node) primaryItem; assertThat(primaryNode.getName(), is(tree.getName())); assertThat(primaryNode.getParent(), is(sameInstance(git))); assertThat(primaryNode, is(sameInstance(tree))); }
/** Test if the removeExisting-flag removes an existing node in case of uuid conflict. */ public void testWorkspaceRestoreWithRemoveExistingJcr2() throws NotExecutableException, RepositoryException { // create version for parentNode of childNode superuser .getWorkspace() .clone( workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false); Version parentV = versionableNode .getSession() .getWorkspace() .getVersionManager() .checkin(versionableNode.getPath()); // move child node in order to produce the uuid conflict String newChildPath = wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName(); wSuperuser.move(wVersionableChildNode.getPath(), newChildPath); wSuperuser.save(); // restore the parent with removeExisting == true >> moved child node // must be removed. wSuperuser.getWorkspace().getVersionManager().restore(new Version[] {parentV}, true); if (wSuperuser.itemExists(newChildPath)) { fail( "Workspace.restore(Version[], boolean) with the boolean flag set to true, must remove the existing node in case of Uuid conflict."); } }
/** * Get content of document node. Content is got by exo:content or exo:text or exo:summary * * @param node * @return * @throws Exception */ private DocumentContent getArticleContent(Node node, List<Node> taxonomyTrees) throws Exception { DocumentContent documentContent = new DocumentContent(node.getName(), getIcon(node), "", getType(node)); // If node is added mix rss-enabled then get exo:content property if (node.hasProperty("exo:content")) { documentContent.setContent(node.getProperty("exo:content").getString()); } // Some node have exo:text so we override value of exo:content if (node.hasProperty("exo:text")) { documentContent.setContent(node.getProperty("exo:text").getString()); } // Some node have exo:summary so we override value of exo:content if (node.hasProperty("exo:summary")) { documentContent.setContent(node.getProperty("exo:summary").getString()); } List<Node> categories = taxonomyService_.getAllCategories(node); CategoryNode categoryNode; for (Node category : categories) { categoryNode = getCategoryNode(category, ""); for (Node taxonomyTree : taxonomyTrees) { if (category.getPath().contains(taxonomyTree.getPath())) { categoryNode.setParentPath( (category.getParent().getPath().replace(taxonomyTree.getParent().getPath(), ""))); break; } } if (categoryNode != null) documentContent.getCategories().add(categoryNode); } return documentContent; }
private Node createFileNode() throws ValueFormatException, RepositoryException { Calendar cal = Calendar.getInstance(); Node contentNode = mock(Node.class); Property dateProp = mock(Property.class); when(dateProp.getDate()).thenReturn(cal); Property lengthProp = mock(Property.class); when(lengthProp.getLength()).thenReturn(12345L); Property mimetypeProp = mock(Property.class); when(mimetypeProp.getString()).thenReturn("text/plain"); when(contentNode.getProperty(JcrConstants.JCR_LASTMODIFIED)).thenReturn(dateProp); when(contentNode.getProperty(JcrConstants.JCR_MIMETYPE)).thenReturn(mimetypeProp); when(contentNode.getProperty(JcrConstants.JCR_DATA)).thenReturn(lengthProp); when(contentNode.hasProperty(JcrConstants.JCR_DATA)).thenReturn(true); Node node = mock(Node.class); Property fooProp = new MockProperty("foo"); fooProp.setValue("bar"); List<Property> propertyList = new ArrayList<Property>(); propertyList.add(fooProp); MockPropertyIterator propertyIterator = new MockPropertyIterator(propertyList.iterator()); when(node.getProperties()).thenReturn(propertyIterator); when(node.hasNode("jcr:content")).thenReturn(true); when(node.getNode("jcr:content")).thenReturn(contentNode); when(node.getPath()).thenReturn("/path/to/file.doc"); when(node.getName()).thenReturn("file.doc"); return node; }
/** * Gets the title. * * @param node the node * @return the title * @throws Exception the exception */ public static String getTitle(Node node) throws Exception { String title = null; try { title = node.getProperty("exo:title").getValue().getString(); } catch (PathNotFoundException pnf1) { try { Value[] values = node.getNode("jcr:content").getProperty("dc:title").getValues(); if (values.length != 0) { title = values[0].getString(); } } catch (PathNotFoundException pnf2) { title = null; } } catch (ValueFormatException e) { title = null; } catch (IllegalStateException e) { title = null; } catch (RepositoryException e) { title = null; } if (StringUtils.isBlank(title)) { title = node.getName(); } return ContentReader.getXSSCompatibilityContent(title); }
public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException { WorkflowData workflowData = item.getWorkflowData(); log.info("==================== <> ======================"); Iterator props = args.entrySet().iterator(); String pathToArchive = args.get("PROCESS_ARGS", String.class); if (pathToArchive != null) if (workflowData.getPayloadType().equals(TYPE_JCR_PATH)) { String path = workflowData.getPayload().toString(); try { Node node = (Node) session.getSession().getItem(path + "/jcr:content"); String orderBy = node.getProperty("orderby").getString(); log.info("----------orderby: " + orderBy); Node nodeToOrder = (Node) session.getSession().getItem(pathToArchive); Iterator<Node> iterator = nodeToOrder.getNodes(); List<Node> nodes = copyIterator(iterator); Collections.sort(nodes, new NodeComparator(orderBy)); for (Node orderNode : nodes) { session .getSession() .getWorkspace() .move( pathToArchive + "/" + orderNode.getName(), pathToArchive + "/" + orderNode.getName()); } } catch (RepositoryException e) { throw new WorkflowException(e.getMessage(), e); } } }
@Override public List<JcrNode> childNodes(String path) throws RemoteException { List<JcrNode> children = null; if (path == null || path.trim().length() == 0) { return Collections.emptyList(); } try { Node node = (Node) session().getItem(path); NodeIterator it = node.getNodes(); children = new ArrayList<JcrNode>((int) it.getSize()); while (it.hasNext()) { Node n = it.nextNode(); JcrNode childNode = new JcrNode(n.getName(), n.getPath(), n.getPrimaryNodeType().getName()); childNode.setProperties(getProperties(n)); childNode.setAcessControlList(getAccessList(session().getAccessControlManager(), node)); childNode.setMixins(mixins(n)); childNode.setPropertyDefs(propertyDefs(n)); children.add(childNode); } } catch (PathNotFoundException e) { log.log(Level.FINER, e.getLocalizedMessage()); } catch (RepositoryException e) { log.log(Level.SEVERE, "Unexpected error", e); throw new RemoteException(e.getMessage()); } return children; }
public Post getPost(Node postNode) throws Exception { Post postNew = new Post(); PropertyReader reader = new PropertyReader(postNode); postNew.setId(postNode.getName()); postNew.setPath(postNode.getPath()); postNew.setOwner(reader.string(ForumNodeTypes.EXO_OWNER)); postNew.setCreatedDate(reader.date(ForumNodeTypes.EXO_CREATED_DATE)); postNew.setModifiedBy(reader.string(ForumNodeTypes.EXO_MODIFIED_BY)); postNew.setModifiedDate(reader.date(ForumNodeTypes.EXO_MODIFIED_DATE)); postNew.setEditReason(reader.string(ForumNodeTypes.EXO_EDIT_REASON)); postNew.setName(reader.string(ForumNodeTypes.EXO_NAME)); postNew.setMessage(reader.string(ForumNodeTypes.EXO_MESSAGE)); postNew.setRemoteAddr(reader.string(ForumNodeTypes.EXO_REMOTE_ADDR)); postNew.setIcon(reader.string(ForumNodeTypes.EXO_ICON)); postNew.setLink(reader.string(ForumNodeTypes.EXO_LINK)); postNew.setIsApproved(reader.bool(ForumNodeTypes.EXO_IS_APPROVED)); postNew.setIsHidden(reader.bool(ForumNodeTypes.EXO_IS_HIDDEN)); postNew.setIsActiveByTopic(reader.bool(ForumNodeTypes.EXO_IS_ACTIVE_BY_TOPIC)); postNew.setUserPrivate(reader.strings(ForumNodeTypes.EXO_USER_PRIVATE)); postNew.setNumberAttach(reader.l(ForumNodeTypes.EXO_NUMBER_ATTACH)); if (postNew.getNumberAttach() > 0) { postNew.setAttachments(getAttachmentsByNode(postNode)); } return postNew; }
/** {@inheritDoc} */ public void undeleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException { Node fileToUndeleteNode = session.getNodeByIdentifier(fileId.toString()); String trashFileIdNodePath = fileToUndeleteNode.getParent().getPath(); String origParentFolderPath = getOriginalParentFolderPath(session, pentahoJcrConstants, fileToUndeleteNode, false); String absDestPath = origParentFolderPath + RepositoryFile.SEPARATOR + fileToUndeleteNode.getName(); if (session.itemExists(absDestPath)) { RepositoryFile file = JcrRepositoryFileUtils.nodeToFile( session, pentahoJcrConstants, pathConversionHelper, lockHelper, (Node) session.getItem(absDestPath)); throw new RepositoryFileDaoFileExistsException(file); } session.move(fileToUndeleteNode.getPath(), absDestPath); session.getItem(trashFileIdNodePath).remove(); }
public Location move(Node original, Node newParent, Name newName, Node beforeSibling) throws RepositoryException { // Determine whether the node needs to move ... if (newParent == null && beforeSibling != null) { newParent = beforeSibling.getParent(); } if (newName != null || (newParent != null && !original.getParent().equals(newParent))) { // This is not just a reorder, so we definitely have to move first ... String destAbsPath = newParent != null ? newParent.getPath() : original.getParent().getPath(); assert !destAbsPath.endsWith("/"); String newNameStr = newName != null ? stringFor(newName) : original.getName(); destAbsPath += '/' + newNameStr; session.move(original.getPath(), destAbsPath); } if (beforeSibling != null) { // Even if moved, the 'orginal' node should still point to the node we just moved ... String siblingName = nameFor(beforeSibling); String originalName = nameFor(original); original.getParent().orderBefore(originalName, siblingName); } return locationFor(original); }
@Test @FixFor("MODE-1489") public void shouldAllowMultipleOrderBeforeWithoutSave() throws Exception { int childCount = 2; Node parent = session.getRootNode().addNode("parent", "nt:unstructured"); for (int i = 0; i < childCount; i++) { parent.addNode("Child " + i, "nt:unstructured"); } session.save(); long childIdx = 0; NodeIterator nodeIterator = parent.getNodes(); while (nodeIterator.hasNext()) { parent.orderBefore("Child " + childIdx, "Child 0"); childIdx++; nodeIterator.nextNode(); } session.save(); nodeIterator = parent.getNodes(); childIdx = nodeIterator.getSize() - 1; while (nodeIterator.hasNext()) { Node child = nodeIterator.nextNode(); assertEquals("Child " + childIdx, child.getName()); childIdx--; } }
/** Recursively outputs the contents of the given node. */ private static void dump(Node node) throws RepositoryException { // First output the node path System.out.println(node.getPath()); // Skip the virtual (and large!) jcr:system subtree if (node.getName().equals("jcr:system")) { return; } // Then output the properties PropertyIterator properties = node.getProperties(); while (properties.hasNext()) { Property property = properties.nextProperty(); if (property.getDefinition().isMultiple()) { // A multi-valued property, print all values Value[] values = property.getValues(); for (int i = 0; i < values.length; i++) { System.out.println(property.getPath() + " = " + values[i].getString()); } } else { // A single-valued property System.out.println(property.getPath() + " = " + property.getString()); } } // Finally output all the child nodes recursively NodeIterator nodes = node.getNodes(); while (nodes.hasNext()) { dump(nodes.nextNode()); } }
@Before public void setUp() throws RepositoryException { initMocks(this); final String relPath = "/" + testPid; final NodeType[] types = new NodeType[0]; try { when(mockObjNode.getName()).thenReturn(testPid); when(mockObjNode.getSession()).thenReturn(mockSession); when(mockObjNode.getMixinNodeTypes()).thenReturn(types); NodeType mockNodeType = mock(NodeType.class); when(mockNodeType.getName()).thenReturn("nt:folder"); when(mockObjNode.getPrimaryNodeType()).thenReturn(mockNodeType); when(mockSession.getRootNode()).thenReturn(mockRootNode); when(mockRootNode.getNode(relPath)).thenReturn(mockObjNode); when(mockSession.getUserID()).thenReturn(mockUser); testFedoraObject = new FedoraObject(mockObjNode); mockNodetypes = new NodeType[2]; mockNodetypes[0] = mock(NodeType.class); mockNodetypes[1] = mock(NodeType.class); when(mockObjNode.getMixinNodeTypes()).thenReturn(mockNodetypes); when(mockPredicate.apply(mockObjNode)).thenReturn(true); } catch (final RepositoryException e) { e.printStackTrace(); fail(e.getMessage()); } }
/** * Tests if restoring the <code>Version</code> of an existing node throws an <code> * ItemExistsException</code> if removeExisting is set to FALSE. */ public void testWorkspaceRestoreWithUUIDConflictJcr2() throws RepositoryException, NotExecutableException { try { // Verify that nodes used for the test are indeed versionable NodeDefinition nd = wVersionableNode.getDefinition(); if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { throw new NotExecutableException("Nodes must be versionable in order to run this test."); } VersionManager versionManager = wVersionableNode.getSession().getWorkspace().getVersionManager(); String path = wVersionableNode.getPath(); Version v = versionManager.checkin(path); versionManager.checkout(path); wSuperuser.move( wVersionableChildNode.getPath(), wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName()); wSuperuser.save(); wSuperuser.getWorkspace().getVersionManager().restore(new Version[] {v}, false); fail( "Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); } catch (ItemExistsException e) { // success } }
public String[] getFileNames(long companyId, long repositoryId) throws SystemException { List<String> fileNames = new ArrayList<String>(); Session session = null; try { session = JCRFactoryUtil.createSession(); Node rootNode = getRootNode(session, companyId); Node repositoryNode = getFolderNode(rootNode, repositoryId); NodeIterator itr = repositoryNode.getNodes(); while (itr.hasNext()) { Node node = (Node) itr.next(); NodeType primaryNodeType = node.getPrimaryNodeType(); String primaryNodeTypeName = primaryNodeType.getName(); if (primaryNodeTypeName.equals(JCRConstants.NT_FILE)) { fileNames.add(node.getName()); } } } catch (Exception e) { throw new SystemException(e); } finally { JCRFactoryUtil.closeSession(session); } return fileNames.toArray(new String[0]); }
private UserProfile getUserProfile(Node profileNode) throws Exception { UserProfile userProfile = new UserProfile(); userProfile.setUserId(profileNode.getName()); PropertyReader reader = new PropertyReader(profileNode); userProfile.setScreenName( reader.string( ForumNodeTypes.EXO_SCREEN_NAME, reader.string(ForumNodeTypes.EXO_FULL_NAME, profileNode.getName()))); userProfile.setFullName(reader.string(ForumNodeTypes.EXO_FULL_NAME)); userProfile.setFirstName(reader.string(ForumNodeTypes.EXO_FIRST_NAME)); userProfile.setLastName(reader.string(ForumNodeTypes.EXO_LAST_NAME)); userProfile.setEmail(reader.string(ForumNodeTypes.EXO_EMAIL)); userProfile.setUserRole(reader.l(ForumNodeTypes.EXO_USER_ROLE)); userProfile.setUserTitle(reader.string(ForumNodeTypes.EXO_USER_TITLE, "")); userProfile.setSignature(reader.string(ForumNodeTypes.EXO_SIGNATURE)); userProfile.setTotalPost(reader.l(ForumNodeTypes.EXO_TOTAL_POST)); userProfile.setTotalTopic(reader.l(ForumNodeTypes.EXO_TOTAL_TOPIC)); userProfile.setBookmark(reader.strings(ForumNodeTypes.EXO_BOOKMARK)); userProfile.setLastLoginDate(reader.date(ForumNodeTypes.EXO_LAST_LOGIN_DATE)); userProfile.setJoinedDate(reader.date(ForumNodeTypes.EXO_JOINED_DATE)); userProfile.setLastPostDate(reader.date(ForumNodeTypes.EXO_LAST_POST_DATE)); userProfile.setIsDisplaySignature(reader.bool(ForumNodeTypes.EXO_IS_DISPLAY_SIGNATURE)); userProfile.setIsDisplayAvatar(reader.bool(ForumNodeTypes.EXO_IS_DISPLAY_AVATAR)); userProfile.setShortDateFormat( reader.string(ForumNodeTypes.EXO_SHORT_DATEFORMAT, userProfile.getShortDateFormat())); userProfile.setLongDateFormat( reader.string(ForumNodeTypes.EXO_LONG_DATEFORMAT, userProfile.getLongDateFormat())); userProfile.setTimeFormat( reader.string(ForumNodeTypes.EXO_TIME_FORMAT, userProfile.getTimeFormat())); userProfile.setMaxPostInPage(reader.l(ForumNodeTypes.EXO_MAX_POST, 10)); userProfile.setMaxTopicInPage(reader.l(ForumNodeTypes.EXO_MAX_TOPIC, 10)); userProfile.setIsShowForumJump(reader.bool(ForumNodeTypes.EXO_IS_SHOW_FORUM_JUMP, true)); userProfile.setModerateForums( reader.strings(ForumNodeTypes.EXO_MODERATE_FORUMS, new String[] {})); userProfile.setModerateCategory( reader.strings(ForumNodeTypes.EXO_MODERATE_CATEGORY, new String[] {})); userProfile.setNewMessage(reader.l(ForumNodeTypes.EXO_NEW_MESSAGE)); userProfile.setTimeZone(reader.d(ForumNodeTypes.EXO_TIME_ZONE)); userProfile.setIsBanned(reader.bool(ForumNodeTypes.EXO_IS_BANNED)); userProfile.setBanUntil(reader.l(ForumNodeTypes.EXO_BAN_UNTIL)); userProfile.setBanReason(reader.string(ForumNodeTypes.EXO_BAN_REASON, "")); userProfile.setBanCounter(Integer.parseInt(reader.string(ForumNodeTypes.EXO_BAN_COUNTER, "0"))); userProfile.setBanReasonSummary( reader.strings(ForumNodeTypes.EXO_BAN_REASON_SUMMARY, new String[] {})); userProfile.setCreatedDateBan(reader.date(ForumNodeTypes.EXO_CREATED_DATE_BAN)); return userProfile; }
/** Dump a single node */ protected void dumpSingleNode( Node n, JSONWriter w, int currentRecursionLevel, int maxRecursionLevels) throws RepositoryException, JSONException { if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) { w.key(n.getName()); dump(n, w, currentRecursionLevel + 1, maxRecursionLevels); } }
private void listChildren(String indent, Node node, PrintStream out) throws RepositoryException { out.println(indent + node.getName() + ""); out.println(node.getPath()); NodeIterator ni = node.getNodes(); while (ni.hasNext()) { listChildren(indent + " ", ni.nextNode(), out); } }
@Test public void shouldReadFederatedNodeInProjection() throws Exception { Node git = gitNode(); assertThat(git, is(notNullValue())); assertThat(git.getParent(), is(sameInstance(testRoot))); assertThat(git.getPath(), is(testRoot.getPath() + "/git-modeshape")); assertThat(git.getName(), is("git-modeshape")); }
/** * Returns a list of datastreams for the object * * @param pid persistent identifier of the digital object * @return the list of datastreams * @throws RepositoryException * @throws IOException * @throws TemplateException */ @GET @Path("/") @Produces({TEXT_XML, APPLICATION_JSON}) public ObjectDatastreams getDatastreams(@PathParam("pid") final String pid) throws RepositoryException, IOException { final ObjectDatastreams objectDatastreams = new ObjectDatastreams(); final Builder<DatastreamElement> datastreams = builder(); NodeIterator i = getObjectNode(pid).getNodes(); while (i.hasNext()) { final Node ds = i.nextNode(); datastreams.add(new DatastreamElement(ds.getName(), ds.getName(), getDSMimeType(ds))); } objectDatastreams.datastreams = datastreams.build(); return objectDatastreams; }
private EcmDocument readDocumentByNode(Node node, int readType) throws EcmException { EcmDocument doc = null; try { if (node == null) { return doc; } doc = new EcmDocument(); Node resNode = node.getNode(Property.JCR_CONTENT); if (resNode == null) { return doc; } /** Load the document meta data */ DocumentMetadata meta = this.loadDocumentMetadata(resNode); meta.setFileName(node.getName()); meta.setIdentifier(node.getIdentifier()); String createdBy = node.getProperty(Property.JCR_CREATED_BY).getString(); Calendar createdDate = node.getProperty(Property.JCR_CREATED).getDate(); meta.setCreated(createdDate.getTime()); meta.setCreatedBy(createdBy); meta.setCheckedOut(node.isCheckedOut()); meta.setFullPath(node.getPath()); doc.setMetadata(meta); doc.setFileName(meta.getFileName()); doc.setParentFolder(node.getParent().getName()); /** Load the file content */ Property dataProperty = resNode.getProperty(Property.JCR_DATA); if (dataProperty != null && readType == 0) { doc.setInputStream(dataProperty.getBinary().getStream()); doc.getMetadata().setSize(dataProperty.getBinary().getSize()); } else if (dataProperty != null && readType == 1) { byte[] contents = convertToByteArray(dataProperty.getBinary()); doc.setContent(contents); doc.getMetadata().setSize(dataProperty.getBinary().getSize()); } } catch (PathNotFoundException e) { throw new EcmException( "Fail to read document from repository.", e, ErrorCodes.REPOSITROY_ERR_INVALID_PATH); } catch (RepositoryException e) { throw new EcmException( "Fail to read document from repository.", e, ErrorCodes.REPOSITROY_ERR_GENERIC); } catch (IOException e) { throw new EcmException( "Fail to read document from repository.", e, ErrorCodes.REPOSITROY_ERR_FAIL_TO_READ_CONTENT); } return doc; }
/** * initializes fields * * @throws Exception */ public void initParams() throws Exception { // get current node // name field if (currentNode.hasProperty("exo:title")) { nameValue_ = currentNode.getProperty("exo:title").getValue().getString(); } if (currentNode.hasNode("jcr:content")) { Node content = currentNode.getNode("jcr:content"); if (content.hasProperty("dc:title")) { try { nameValue_ = content.getProperty("dc:title").getValues()[0].getString(); } catch (Exception e) { nameValue_ = null; } } } if (nameValue_ == null) nameValue_ = currentNode.getName(); boolean hasNavigableMixinType = currentNode.isNodeType("exo:navigable"); if (hasNavigableMixinType) { isVisible = true; if (currentNode.getParent().isNodeType("exo:navigable")) { if (currentNode.hasProperty("exo:index")) { index_ = currentNode.getProperty("exo:index").getLong(); } renderIndexField = true; } if (currentNode.hasProperty("exo:navigationNode")) { navigationNode_ = currentNode.getProperty("exo:navigationNode").getString(); } if (currentNode.hasProperty("exo:clickable")) { if (currentNode.getProperty("exo:clickable").getBoolean()) { isClickable = true; } else isClickable = false; } if (currentNode.hasProperty("exo:page")) { listTargetPage_ = currentNode.getProperty("exo:page").getString(); } if (currentNode.hasProperty("exo:pageParamId")) { listShowClvBy_ = currentNode.getProperty("exo:pageParamId").getString(); } if (currentNode.hasProperty("exo:childrenPage")) { detailTargetPage_ = currentNode.getProperty("exo:childrenPage").getString(); } if (currentNode.hasProperty("exo:childrenPageParamId")) { detailShowClvBy_ = currentNode.getProperty("exo:childrenPageParamId").getString(); } } }
private static Node nextDirNode(NodeIterator iterator) throws RepositoryException { while (iterator.hasNext()) { Node node = iterator.nextNode(); if (node.getName().length() == 2) { return node; } } return null; }
public String getName() { String name = null; try { name = node.getName(); } catch (RepositoryException re) { LOGGER.error(re.getMessage(), re); } return name; }
public List<Node> getCategories(Node node) throws Exception { if (taxonomyService == null) taxonomyService = WCMCoreUtils.getService(TaxonomyService.class); List<Node> listCategories = new ArrayList<Node>(); List<Node> listNode = getAllTaxonomyTrees(); for (Node itemNode : listNode) { listCategories.addAll(taxonomyService.getCategories(node, itemNode.getName())); } return listCategories; }
/** * Get user navigation URI from equivalent mop node in portal-system workspace * * @param node the mop node in portal-system workspace * @return * @throws RepositoryException */ public static StringBuilder getUserNavigationURI(Node node) throws RepositoryException { if (!node.isNodeType("mop:portalsites")) { StringBuilder builder = getUserNavigationURI(node.getParent()); String name = node.getName(); if ("mop:children".equals(name) || "mop:default".equals(name) || "mop:rootnavigation".equals(name)) { return builder.append(""); } else { if (builder.length() > 0) { builder.append("/"); } return builder.append(node.getName().replaceFirst("mop:", "")); } } else { return new StringBuilder(); } }