org.apache.jackrabbit.util.Text类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中org.apache.jackrabbit.util.Text类的一些代码示例,展示了Text类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Text类的具体详情如下:
包路径:org.apache.jackrabbit.util.Text
类名称:Text

Text介绍

[英]This Class provides some text related utilities
[中]此类提供了一些与文本相关的实用程序

代码示例

代码示例来源:origin: net.adamcin.commons/net.adamcin.commons.jcr

public void move(String fromPath, String toPath) throws RepositoryException {
  final String fromParentPath = Text.getRelativeParent(fromPath, 1);
  final boolean appendName = getSession().nodeExists(toPath);
  final String toParentPath = appendName ? toPath : Text.getRelativeParent(toPath, 1);
  final String finalPath = appendName ? toPath + "/" + Text.getName(fromPath) : toPath;
  getSession().move(fromPath, toPath);
  processChanges(fromParentPath, fromPath, toParentPath, finalPath);
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

@Override
  @Nonnull
  public String generateNodeName(@Nonnull String authorizableId) {
    return Text.escapeIllegalJcrChars(authorizableId);
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

/**
 * returns an array of strings decomposed of the original string, split at
 * every occurrence of 'ch'. if 2 'ch' follow each other with no intermediate
 * characters, empty "" entries are avoided.
 *
 * @param str the string to decompose
 * @param ch  the character to use a split pattern
 * @return an array of strings
 */
public static String[] explode(String str, int ch) {
  return explode(str, ch, false);
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-core

void setSearchRoots(String userSearchRoot, String groupSearchRoot) {
  this.userSearchRoot = userSearchRoot;
  this.groupSearchRoot = groupSearchRoot;
  authorizableSearchRoot = userSearchRoot;
  while (!Text.isDescendant(authorizableSearchRoot, groupSearchRoot)) {
    authorizableSearchRoot = Text.getRelativeParent(authorizableSearchRoot, 1);
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

/**
 * @see org.apache.jackrabbit.api.security.user.Authorizable#setProperty(String, javax.jcr.Value[])
 */
@Override
public void setProperty(@Nonnull String relPath, @Nullable Value[] values) throws RepositoryException {
  if (values == null) {
    removeProperty(relPath);
  } else {
    String oakPath = getOakPath(relPath);
    String name = Text.getName(oakPath);
    PropertyState propertyState =
        PropertyStates.createProperty(name, Arrays.asList(values));
    String intermediate = (oakPath.equals(name)) ? null : Text.getRelativeParent(oakPath, 1);
    Tree parent = getOrCreateTargetTree(intermediate);
    checkProtectedProperty(parent, propertyState);
    parent.setProperty(propertyState);
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

@Nonnull
@Override
public AccessControlPolicy[] getEffectivePolicies(@Nullable String absPath) throws RepositoryException {
  String oakPath = getOakPath(absPath);
  Tree tree = getTree(oakPath, Permissions.READ_ACCESS_CONTROL, true);
  Root r = getRoot().getContentSession().getLatestRoot();
  tree = r.getTree(tree.getPath());
  List<AccessControlPolicy> effective = new ArrayList<AccessControlPolicy>();
  AccessControlPolicy policy = createACL(oakPath, tree, true);
  if (policy != null) {
    effective.add(policy);
  }
  if (oakPath != null) {
    String parentPath = Text.getRelativeParent(oakPath, 1);
    while (!parentPath.isEmpty()) {
      Tree t = r.getTree(parentPath);
      AccessControlPolicy plc = createACL(parentPath, t, true);
      if (plc != null) {
        effective.add(plc);
      }
      parentPath = (PathUtils.denotesRoot(parentPath)) ? "" : Text.getRelativeParent(parentPath, 1);
    }
  }
  if (readPaths.contains(oakPath)) {
    effective.add(ReadPolicy.INSTANCE);
  }
  return effective.toArray(new AccessControlPolicy[effective.size()]);
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

@Nonnull
private String getFolderPath(@Nonnull String nodeName,
               @Nullable String intermediatePath,
               @Nonnull String authRoot) throws ConstraintViolationException {
  boolean emptyOrNull = (intermediatePath == null || intermediatePath.isEmpty() || authRoot.equals(intermediatePath));
  StringBuilder sb = new StringBuilder();
    String hint = Text.unescapeIllegalJcrChars(nodeName);
    int idLength = hint.length();
    StringBuilder segment = new StringBuilder();
      sb.append(DELIMITER).append(Text.escapeIllegalJcrChars(segment.toString()));

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

@CheckForNull
public static String getAuthorizableRootPath(@Nonnull ConfigurationParameters parameters,
                       @Nullable AuthorizableType type) {
  String path = null;
  if (type != null) {
    switch (type) {
      case USER:
        path = parameters.getConfigValue(UserConstants.PARAM_USER_PATH, UserConstants.DEFAULT_USER_PATH);
        break;
      case GROUP:
        path = parameters.getConfigValue(UserConstants.PARAM_GROUP_PATH, UserConstants.DEFAULT_GROUP_PATH);
        break;
      default:
        path = parameters.getConfigValue(UserConstants.PARAM_USER_PATH, UserConstants.DEFAULT_USER_PATH);
        String groupRoot = parameters.getConfigValue(UserConstants.PARAM_GROUP_PATH, UserConstants.DEFAULT_GROUP_PATH);
        while (!Text.isDescendantOrEqual(path, groupRoot)) {
          path = Text.getRelativeParent(path, 1);
        }
    }
  }
  return path;
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

@Nonnull
private String buildXPathStatement(@Nonnull String relPath,
                  @Nullable String value,
                  @Nonnull AuthorizableType type, boolean exact) {
  StringBuilder stmt = new StringBuilder();
  String searchRoot = namePathMapper.getJcrPath(QueryUtil.getSearchRoot(type, config));
  String propName = Text.getName(relPath);
  String path;
  String ntName;

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

private MoveEntry(@Nonnull String sourcePath,
           @Nonnull String destPath) {
    this.sourcePath = sourcePath;
    this.destPath = destPath;
    parentSourcePaths.add(Text.getRelativeParent(sourcePath, 1));
    parentDestPaths.add(Text.getRelativeParent(destPath, 1));
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

@Override
  boolean matches(@Nonnull String toMatch) {
    if (patternStr.isEmpty()) {
      return path.equals(toMatch);
    } else {
      // no wildcard contained in restriction: use path defined
      // by path + restriction to calculate the match
      return Text.isDescendantOrEqual(patternStr, toMatch);
    }
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

private void verifyHierarchy(@Nonnull String path) throws CommitFailedException {
  if (!Text.isDescendant(userRootPath, path)) {
    String msg = "Attempt to create a token (or it's parent) outside of configured scope " + path;
    throw constraintViolation(64, msg);
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

private static void checkScope(@Nonnull String userPath, @Nonnull String targetPath, @Nonnull String relPath) throws RepositoryException {
    if (!Text.isDescendantOrEqual(userPath, targetPath)) {
      throw new RepositoryException("Relative path " + relPath + " outside of scope of " + userPath);
    }
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

@Nonnull
private static TreeLocation getLocation(@Nonnull Tree tree, @Nonnull String relativePath) {
  TreeLocation loc = TreeLocation.create(tree);
  for (String element : Text.explode(relativePath, '/', false)) {
    if (PathUtils.denotesParent(element)) {
      loc = loc.getParent();
    } else if (!PathUtils.denotesCurrent(element)) {
      loc = loc.getChild(element);
    }  // else . -> skip to next element
  }
  return loc;
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testCopyInvisibleSubTree() throws Exception {
  deny(childNPath, privilegesFromName(Privilege.JCR_READ));
  allow(targetPath, privilegesFromName(Privilege.JCR_ALL));
  assertFalse(testSession.nodeExists(childNPath));
  testSession.getWorkspace().copy(path, destPath);
  Node copiedNode = testSession.getNode(destPath);
  String childName = Text.getName(childNPath);
  assertFalse(copiedNode.hasNode(childName));
  assertTrue(copiedNode.hasNode(Text.getName(childNPath2)));
  superuser.refresh(false);
  assertFalse(superuser.nodeExists(destPath + '/' + childName));
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-core

/**
 * 
 * @param relPath A relative path.
 * @return The corresponding node.
 * @throws RepositoryException If an error occurs.
 */
private Node getOrCreateTargetNode(String relPath) throws RepositoryException {
  Node n;
  if (relPath != null) {
    if (node.hasNode(relPath)) {
      n = node.getNode(relPath);
    } else {
      n = node;
      for (String segment : Text.explode(relPath, '/')) {
        if (n.hasNode(segment)) {
          n = n.getNode(segment);
        } else {
          n = n.addNode(segment);
        }
      }
    }
    if (!Text.isDescendantOrEqual(node.getPath(), n.getPath())) {
      node.refresh(false);
      throw new RepositoryException("Relative path " + relPath + " outside of scope of " + this);
    }
  } else {
    n = node;
  }
  return n;
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
public void afterSuite() throws Exception {
  Session s = loginAdministrative();
  try {
    Authorizable authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(GROUP);
    if (authorizable != null) {
      Node n = s.getNode(Text.getRelativeParent(authorizable.getPath(), 1));
      n.remove();
    }
    s.save();
  } finally {
    s.logout();
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testReorder3() throws Exception {
  Node n = testSession.getNode(path);
  // give 'add_child_nodes', 'nt-management' and 'remove_child_nodes' at
  // 'path' -> reorder must succeed
  allow(path, privilegesFromNames(new String[] {Privilege.JCR_ADD_CHILD_NODES,
      Privilege.JCR_REMOVE_CHILD_NODES, Privilege.JCR_NODE_TYPE_MANAGEMENT}));
  n.orderBefore(Text.getName(childNPath2), Text.getName(childNPath));
  testSession.save();
}

代码示例来源:origin: apache/jackrabbit

try {
  Item item = context.getExportRoot();
  Repository rep = item.getSession().getRepository();
  String repName = rep.getDescriptor(Repository.REP_NAME_DESC);
  String repURL = rep.getDescriptor(Repository.REP_VENDOR_URL_DESC);
  String repVersion = rep.getDescriptor(Repository.REP_VERSION_DESC);
  writer.print("<html><head><title>");
  writer.print(Text.encodeIllegalHTMLCharacters(repName));
  writer.print(" ");
  writer.print(Text.encodeIllegalHTMLCharacters(repVersion));
  writer.print(" ");
  writer.print(Text.encodeIllegalHTMLCharacters(item.getPath()));
  writer.print("</title></head>");
  writer.print("<body><h2>");
  writer.print(Text.encodeIllegalHTMLCharacters(item.getPath()));
  writer.print("</h2><ul>");
  writer.print("<li><a href=\"..\">..</a></li>");
  if (item.isNode()) {
    NodeIterator iter = ((Node)item).getNodes();
    while (iter.hasNext()) {
      Node child = iter.nextNode();
      String label = Text.getName(child.getPath());
      writer.print("<li><a href=\"");
      writer.print(Text.encodeIllegalHTMLCharacters(Text.escape(label)));
      if (child.isNode()) {
        writer.print("/");
      writer.print(Text.encodeIllegalHTMLCharacters(label));
      writer.print("</a></li>");

代码示例来源:origin: apache/jackrabbit

String evPath = ev.getPath();
String repMembers = session.getJCRName(UserConstants.P_MEMBERS);
if (repMembers.equals(Text.getName(evPath))) {
  if (UserConstants.NT_REP_MEMBERS.equals(((NodeTypeImpl) parent.getPrimaryNodeType()).getQName())) {
    clearCache();
log.warn("Internal error: {}", e.getMessage());
clearCache();

相关文章