[jboss-cvs] jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/links ...
Christian Bauer
christian.bauer at jboss.com
Wed Feb 21 11:24:11 EST 2007
User: cbauer
Date: 07/02/21 11:24:11
Modified: examples/wiki/src/org/jboss/seam/wiki/core/links
WikiLinkResolver.java
Log:
User registration/login and some security
JBSEAM-870
JBSEAM-871
JBSEAM-874
Revision Changes Path
1.3 +8 -122 jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/links/WikiLinkResolver.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: WikiLinkResolver.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/links/WikiLinkResolver.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- WikiLinkResolver.java 16 Feb 2007 16:26:44 -0000 1.2
+++ WikiLinkResolver.java 21 Feb 2007 16:24:11 -0000 1.3
@@ -7,11 +7,9 @@
import org.jboss.seam.wiki.core.node.Directory;
import org.jboss.seam.wiki.core.node.Node;
import org.jboss.seam.wiki.core.prefs.GlobalPreferences;
+import org.jboss.seam.wiki.core.dao.NodeDAO;
import org.jboss.seam.Component;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityNotFoundException;
-import javax.persistence.NoResultException;
import javax.faces.context.FacesContext;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
@@ -48,7 +46,7 @@
"=>" + WIKI_PROTOCOL + Pattern.quote("]");
@In(create = true)
- protected EntityManager entityManager;
+ private NodeDAO nodeDAO;
@In(required = false)
private Document currentDocument;
@@ -89,7 +87,7 @@
while (matcher.find()) {
// Find the node by PK
- Node node = findNode(Long.valueOf(matcher.group(2)));
+ Node node = nodeDAO.findNode(Long.valueOf(matcher.group(2)));
// Node is in current area, just use its name
if (node != null && node.getAreaNumber().equals(area.getAreaNumber())) {
@@ -117,7 +115,7 @@
Matcher wikiUrlMatcher = Pattern.compile(WIKI_PROTOCOL).matcher(linkText);
Matcher knownProtocolMatcher = Pattern.compile(KNOWN_PROTOCOLS).matcher(linkText);
- WikiLink wikiLink = null;
+ WikiLink wikiLink;
// Check if its a common protocol
if (knownProtocolMatcher.find()) {
@@ -127,7 +125,7 @@
} else if (wikiUrlMatcher.find()) {
// Find the node by PK
- Node node = findNode(Long.valueOf(wikiUrlMatcher.group(1)));
+ Node node = nodeDAO.findNode(Long.valueOf(wikiUrlMatcher.group(1)));
if (node != null) {
wikiLink = new WikiLink(node.getId(), false, renderURL(node), node.getName());
} else {
@@ -170,12 +168,12 @@
// Try to find the node in the referenced area
String areaName = crossLinkMatcher.group(1);
String nodeName = crossLinkMatcher.group(2);
- Node crossLinkArea = findArea(convertToWikiName(areaName));
+ Node crossLinkArea = nodeDAO.findArea(convertToWikiName(areaName));
if (crossLinkArea != null)
- return findNodeInArea(crossLinkArea.getAreaNumber(), convertToWikiName(nodeName));
+ return nodeDAO.findNodeInArea(crossLinkArea.getAreaNumber(), convertToWikiName(nodeName));
} else {
// Try the current area
- return findNodeInArea(currentArea.getAreaNumber(), convertToWikiName(linkText));
+ return nodeDAO.findNodeInArea(currentArea.getAreaNumber(), convertToWikiName(linkText));
}
return null;
}
@@ -212,116 +210,4 @@
}
}
- // #########################################################################################
-
- // Convenience DAO methods
-
- @Transactional
- public Node findNode(Long nodeId) {
- entityManager.joinTransaction();
- try {
- return entityManager.find(Node.class, nodeId);
- } catch (EntityNotFoundException ex) {
- }
- return null;
- }
-
- @Transactional
- public Node findNodeInArea(Long areaNumber, String wikiname) {
- entityManager.joinTransaction();
-
- try {
- return (Node) entityManager
- .createQuery("select n from Node n where n.areaNumber = :areaNumber and n.wikiname = :wikiname")
- .setParameter("areaNumber", areaNumber)
- .setParameter("wikiname", wikiname)
- .getSingleResult();
- } catch (EntityNotFoundException ex) {
- } catch (NoResultException ex) {
- }
- return null;
- }
-
- @Transactional
- public Document findDocumentInArea(Long areaNumber, String wikiname) {
- entityManager.joinTransaction();
-
- try {
- return (Document) entityManager
- .createQuery("select d from Document d where d.areaNumber = :areaNumber and d.wikiname = :wikiname")
- .setParameter("areaNumber", areaNumber)
- .setParameter("wikiname", wikiname)
- .getSingleResult();
- } catch (EntityNotFoundException ex) {
- } catch (NoResultException ex) {
- }
- return null;
- }
-
- @Transactional
- public Directory findDirectoryInArea(Long areaNumber, String wikiname) {
- entityManager.joinTransaction();
-
- try {
- return (Directory) entityManager
- .createQuery("select d from Directory d where d.areaNumber = :areaNumber and d.wikiname = :wikiname")
- .setParameter("areaNumber", areaNumber)
- .setParameter("wikiname", wikiname)
- .getSingleResult();
- } catch (EntityNotFoundException ex) {
- } catch (NoResultException ex) {
- }
- return null;
- }
-
- @Transactional
- public Directory findArea(String wikiname) {
- entityManager.joinTransaction();
-
- try {
- return (Directory) entityManager
- .createQuery("select d from Directory d where d.parent = :root and d.wikiname = :wikiname")
- .setParameter("root", wikiRoot)
- .setParameter("wikiname", wikiname)
- .getSingleResult();
- } catch (EntityNotFoundException ex) {
- } catch (NoResultException ex) {
- }
- return null;
- }
-
- // I need these methods because find() is broken, e.g. find(Document,1) would return a Directory if the
- // persistence context contains a directory with id 1... even more annoying, I need to catch NoResultException,
- // so there really is no easy and correct way to look for the existence of a row.
-
- @Transactional
- public Document findDocument(Long documentId) {
- entityManager.joinTransaction();
-
- try {
- return (Document) entityManager
- .createQuery("select d from Document d where d.id = :id")
- .setParameter("id", documentId)
- .getSingleResult();
- } catch (EntityNotFoundException ex) {
- } catch (NoResultException ex) {
- }
- return null;
- }
-
- @Transactional
- public Directory findDirectory(Long directoryId) {
- entityManager.joinTransaction();
-
- try {
- return (Directory) entityManager
- .createQuery("select d from Directory d where d.id = :id")
- .setParameter("id", directoryId)
- .getSingleResult();
- } catch (EntityNotFoundException ex) {
- } catch (NoResultException ex) {
- }
- return null;
- }
-
}
More information about the jboss-cvs-commits
mailing list