Reads user permissions.
()
| 49 | * Reads user permissions. |
| 50 | */ |
| 51 | private synchronized void read() { |
| 52 | if(!file.exists()) return; |
| 53 | try { |
| 54 | final MainOptions options = new MainOptions(false); |
| 55 | options.set(MainOptions.INTPARSE, true); |
| 56 | options.set(MainOptions.STRIPWS, true); |
| 57 | final XNode doc = new DBNode(Parser.singleParser(file, options, "")); |
| 58 | if(children(doc, Q_USERS).next() instanceof final XNode root) { |
| 59 | for(final GNode gchild : children(root)) { |
| 60 | final XNode child = (XNode) gchild; |
| 61 | final QNm qname = child.qname(); |
| 62 | if(qname.eq(Q_USER)) { |
| 63 | try { |
| 64 | final User user = new User(child, file); |
| 65 | final String name = user.name(); |
| 66 | if(users.get(name) != null) { |
| 67 | Util.errln("%: User '%' supplied more than once.", file, name); |
| 68 | } else { |
| 69 | users.put(name, user); |
| 70 | } |
| 71 | } catch(final BaseXException ex) { |
| 72 | // reject users with faulty data |
| 73 | Util.errln("%: %", file, ex.getLocalizedMessage()); |
| 74 | } |
| 75 | } else if(qname.eq(Q_INFO)) { |
| 76 | if(info != null) Util.errln("%: <%/> occurs more than once.", file, qname); |
| 77 | else info = child; |
| 78 | } else { |
| 79 | Util.errln("%: invalid element <%/>.", file, qname); |
| 80 | } |
| 81 | } |
| 82 | } else { |
| 83 | Util.errln("%: No <%/> root element.", file, Q_USERS); |
| 84 | } |
| 85 | } catch(final IOException ex) { |
| 86 | Util.errln(ex); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Writes permissions to disk. |