info.magnolia.cms.core.Path.getValidatedLabel()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(93)

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

Path.getValidatedLabel介绍

暂无

代码示例

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlutils

/**
 * retrieve validate label for input string
 * @param value the string to validate
 * @return the validated label, or null if value was null
 * @see {@link Path#getValidatedLabel(String)}
 */
public static String getValidatedLabel(String value)
{
  if (value == null)
  {
    return null;
  }
  return Path.getValidatedLabel(value);
}

代码示例来源:origin: info.magnolia/magnolia-module-forum

/**
 * Cleans up a String, making it appropriate for usage as a node name.
 */
protected String cleanup(String s) {
  if (StringUtils.isEmpty(s)) {
    return "_";
  }
  // TODO : getValidatedLabel() should be copied/moved to a more appropriate(ly named) class?
  return Path.getValidatedLabel(s).toLowerCase();
}

代码示例来源:origin: info.magnolia.contacts/magnolia-contacts

/**
   * Define the Node Name. Node Name = First Char of the lastName + the full
   * firstName. lastName = eric firstName = tabli The node name is etabli
   */
  private String defineNodeName(final Node node) throws RepositoryException {
    String intitialFirstName = node.getProperty("firstName").getString();
    String firstName = StringUtils.isNotBlank(intitialFirstName) ? intitialFirstName.trim() : intitialFirstName;
    String lastName = node.getProperty("lastName").getString().trim();
    return Path.getValidatedLabel((firstName.charAt(0) + lastName.replaceAll("\\s+", "")).toLowerCase());
  }
}

代码示例来源:origin: info.magnolia.dam/magnolia-dam-app

/**
 * Create a new Node Unique NodeName.
 */
public static String generateUniqueNodeNameForAsset(final Node node, String newNodeName) throws RepositoryException {
  return Path.getUniqueLabel(node.getSession(), node.getParent().getPath(), Path.getValidatedLabel(newNodeName));
}

代码示例来源:origin: info.magnolia/magnolia-module-rssaggregator

@SuppressWarnings("unchecked")
  @Override
  public void writeToItem(T newValue) {
    String value = Path.getValidatedLabel((String) newValue);
    Property<T> p = getOrCreateProperty(type);
    p.setValue((T) value);
  }
}

代码示例来源:origin: info.magnolia/magnolia-module-inplace-templating

@Override
protected void setNodeName(Node node, JcrNodeAdapter item) throws RepositoryException {
  if (item.isNew()) {
    NodeUtil.renameNode(node, Path.getUniqueLabel(node.getSession(), node.getParent().getPath(), Path.getValidatedLabel(UNTITLED_TEMPLATE)));
  }
}

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlmedia

/**
 * Loads a media linking to an external video.
 * @param videourl absolute video url
 * @param parent media folder
 * @param filename video filename
 * @param overwrite overwrite an exxisting media
 * @return loaded media
 * @throws RepositoryException exception working on media repository
 * @throws IOException exception working with file stream
 */
public static Node loadExternalVideo(String videourl, String parent, String filename, boolean overwrite)
  throws RepositoryException, IOException
{
  log.debug("loading external video {}/{} with url {}", new Object[]{parent, filename, videourl });
  MediaTypeConfiguration mtc = Components.getComponent(MediaConfigurationManager.class).getTypes().get("youtube");
  String cleanFilename = Path.getValidatedLabel(videourl);
  Node media = createMediaNode(mtc, parent, cleanFilename, overwrite);
  media.setProperty("videoUrl", videourl);
  mtc.getHandler().onPostSave(media);
  return media;
}

代码示例来源:origin: info.magnolia.dam/magnolia-dam-app

/**
   * Insert unique increment before the extension in case of asset; primarily deduce reference name from the fileName property.
   */
  @Override
  protected String getUniqueNewItemName(Item referenceItem, Node destination) throws RepositoryException {
    if (referenceItem.isNode() && ((Node) referenceItem).isNodeType(Asset.NAME)) {
      Node resourceNode = AssetResource.getResourceNodeFromAsset(((Node) referenceItem));
      if (resourceNode != null) {
        String extension = PropertyUtil.getString(resourceNode, AssetResource.EXTENSION, EMPTY);
        String fileName = PropertyUtil.getString(resourceNode, AssetResource.FILENAME);
        String referenceName = (fileName != null && fileName.endsWith(extension)) ? fileName : fileName + "." + extension;
        return Path.getUniqueLabel(destination.getSession(), destination.getPath(), Path.getValidatedLabel(referenceName), extension);
      }
    }
    return super.getUniqueNewItemName(referenceItem, destination);
  }
}

代码示例来源:origin: info.magnolia/magnolia-module-data

@Override
protected void operateOnNode(InstallContext installContext, Node node) {
  try {
    if (!node.hasNode(SUB_APP_MAPPING) || node.hasNode(SUB_APP_MAPPINGS)) {
      return;
    }
    Node subAppMapping = node.getNode(SUB_APP_MAPPING);
    Node subAppMappings = node.addNode(SUB_APP_MAPPINGS, NodeTypes.ContentNode.NAME);
    PropertyIterator propertyIterator = new FilteringPropertyIterator(subAppMapping.getProperties(), new JcrAndMgnlMetadataHidingPredicate());
    while (propertyIterator.hasNext()) {
      Property obsoleteMappingProperty = propertyIterator.nextProperty();
      Node newMappingNode = subAppMappings.addNode(Path.getValidatedLabel(obsoleteMappingProperty.getName()), NodeTypes.ContentNode.NAME);
      newMappingNode.setProperty(NODE_TYPE, obsoleteMappingProperty.getName());
      newMappingNode.setProperty(SUB_APP_ID, obsoleteMappingProperty.getValue());
    }
    subAppMapping.remove();
  } catch (RepositoryException e) {
    installContext.error(String.format("Cannot finish task '%s':", this.getDescription()), e);
  }
}

代码示例来源:origin: info.magnolia.resources/magnolia-resources

node = NodeUtil.createPath(parent, Path.getValidatedLabel(name), NodeTypes.Content.NAME);

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlmedia

String mediaName = Path.getValidatedLabel(filename);

代码示例来源:origin: info.magnolia/magnolia-core

assertEquals("f", Path.getValidatedLabel("f", null));
assertEquals("fo", Path.getValidatedLabel("fo", null));
assertEquals("foo", Path.getValidatedLabel("foo", null));
assertEquals("foo.bar", Path.getValidatedLabel("foo.bar", null));
assertEquals("foo..bar", Path.getValidatedLabel("foo..bar", null));
assertEquals("-foo", Path.getValidatedLabel(".foo", null));
assertEquals("-.foo", Path.getValidatedLabel("..foo", null));
assertEquals("f-oo", Path.getValidatedLabel("f$oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f*oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f[oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f]oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f;oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f:oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f\"oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f'oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f#oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f!oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f+oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f?oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f/oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f%oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f oo", null)); // if you can't see it, that's a space (ascii code 32)
assertEquals("f-oo", Path.getValidatedLabel("f-oo", null));
assertEquals("f_oo", Path.getValidatedLabel("f_oo", null));
assertEquals("f-oo", Path.getValidatedLabel("f~oo", null));

代码示例来源:origin: info.magnolia/magnolia-module-data

@Override
public String convertToModel(String label, Class<? extends String> targetType, Locale locale) throws ConversionException {
  // Null is required for the property to be removed if path is empty
  String res = null;
  if (StringUtils.isBlank(label)) {
    return res;
  }
  try {
    Session session = MgnlContext.getJCRSession(workspace);
    String path = PathUtil.createPath(basePath, label);
    if (session.nodeExists(path)) {
      res = session.getNode(path).getIdentifier();
    } else {
      // try to convert the label to a valid node name
      label = Path.getValidatedLabel(label);
      path = PathUtil.createPath(basePath, label);
      if (session.nodeExists(path)) {
        res = session.getNode(path).getIdentifier();
      } else {
        log.warn("{} is not a valid node path or is not existing in the following repository {} ", path, workspace);
      }
    }
  } catch (RepositoryException e) {
    log.error("Unable to convert Path to UUID", e);
  }
  return res;
}

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlmedia

Path.getValidatedLabel(Components
  .getComponent(MediaConfigurationManager.class)
  .getTypes()

代码示例来源:origin: info.magnolia.dam/magnolia-dam-app

public static Node createAsset(Node parentFolder, UploadReceiver receiver) throws RepositoryException {
    // Get the Asset Node name
    String fileName = receiver.getFileName();
    String assetNodeName = Path.getValidatedLabel(fileName);

    JcrNodeAdapter resourceItem = null;
    JcrNodeAdapter assetItem = null;
    // Get the existing asset or create one new
    if (parentFolder.hasNode(assetNodeName)) {
      assetItem = new JcrNodeAdapter(parentFolder.getNode(assetNodeName));
      resourceItem = new JcrNodeAdapter(AssetNodeTypes.AssetResource.getResourceNodeFromAsset(parentFolder.getNode(assetNodeName)));
    } else {
      assetItem = new JcrNewNodeAdapter(parentFolder, AssetNodeTypes.Asset.NAME, assetNodeName);
      resourceItem = new JcrNewNodeAdapter(parentFolder, NodeTypes.Resource.NAME, JcrConstants.JCR_CONTENT);
    }
    // Link the resource to the Asset Item
    assetItem.addChild(resourceItem);
    // Populate the resourceItem based on the receiver
    new AssetTransformer().populateItem((AssetUploadReceiver) receiver, resourceItem);

    // Set the Asset name property
    Node assetNode = assetItem.applyChanges();
    SaveAssetFormAction.setAssetPropertyName(assetItem, assetNode, fileName);

    return assetNode;
  }
}

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlmedia

c = previousnode.getParent();
String validatedlabel = Path.getValidatedLabel(newnodename);

代码示例来源:origin: info.magnolia/magnolia-module-data

/**
 * Adds multi value type.
 * @param node Parent node.
 * @param name Name of the value node.
 * @param value Value.
 * @param itemType Item type of newly created node.
 * @return Newly created multi value node.
 * @throws RepositoryException When node can't be created or saved.
 * @see MULTI_VALUE_ITEM_TYPE
 */
public static Content addMultiValue(Content node, String name, Value value, ItemType itemType)
  throws RepositoryException {
  Content multiNode = ContentUtil.getOrCreateContent(node, name, new ItemType(
    DataConsts.MODULE_DATA_CONTENT_NODE_TYPE));
  String valueNodeName = StringUtils.left(
    Path.getValidatedLabel(NodeDataUtil.getValueString(value, "YYYYmmDD")),
    20);
  valueNodeName = Path.getUniqueLabel(node, valueNodeName);
  Content valueNode = multiNode.createContent(valueNodeName, itemType);
  NodeDataUtil.getOrCreate(valueNode, name).setValue(value);
  return valueNode;
}

代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility

@Test
public void getNode_NewProperty() throws Exception {
  // GIVEN
  String id = ModelConstants.JCR_NAME;
  String value = "new Parent { % !";
  JcrNodeAdapter adapter = new JcrNodeAdapter(node);
  // Get the node name as property
  Property property = adapter.getItemProperty(id);
  assertEquals(nodeName, property.getValue().toString());
  // Change the property node name
  property.setValue(value);
  // WHEN
  Node res = adapter.applyChanges();
  // THEN
  // should have a new NodeName
  assertEquals(Path.getValidatedLabel(value), res.getName());
  assertEquals(true, res.hasProperty("propertyString"));
  assertEquals(true, res.hasNode("child"));
}

相关文章

微信公众号

最新文章

更多