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

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

本文整理了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

  1. /**
  2. * retrieve validate label for input string
  3. * @param value the string to validate
  4. * @return the validated label, or null if value was null
  5. * @see {@link Path#getValidatedLabel(String)}
  6. */
  7. public static String getValidatedLabel(String value)
  8. {
  9. if (value == null)
  10. {
  11. return null;
  12. }
  13. return Path.getValidatedLabel(value);
  14. }

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

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

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

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

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

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

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

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public void writeToItem(T newValue) {
  4. String value = Path.getValidatedLabel((String) newValue);
  5. Property<T> p = getOrCreateProperty(type);
  6. p.setValue((T) value);
  7. }
  8. }

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

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

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

  1. /**
  2. * Loads a media linking to an external video.
  3. * @param videourl absolute video url
  4. * @param parent media folder
  5. * @param filename video filename
  6. * @param overwrite overwrite an exxisting media
  7. * @return loaded media
  8. * @throws RepositoryException exception working on media repository
  9. * @throws IOException exception working with file stream
  10. */
  11. public static Node loadExternalVideo(String videourl, String parent, String filename, boolean overwrite)
  12. throws RepositoryException, IOException
  13. {
  14. log.debug("loading external video {}/{} with url {}", new Object[]{parent, filename, videourl });
  15. MediaTypeConfiguration mtc = Components.getComponent(MediaConfigurationManager.class).getTypes().get("youtube");
  16. String cleanFilename = Path.getValidatedLabel(videourl);
  17. Node media = createMediaNode(mtc, parent, cleanFilename, overwrite);
  18. media.setProperty("videoUrl", videourl);
  19. mtc.getHandler().onPostSave(media);
  20. return media;
  21. }

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

  1. /**
  2. * Insert unique increment before the extension in case of asset; primarily deduce reference name from the fileName property.
  3. */
  4. @Override
  5. protected String getUniqueNewItemName(Item referenceItem, Node destination) throws RepositoryException {
  6. if (referenceItem.isNode() && ((Node) referenceItem).isNodeType(Asset.NAME)) {
  7. Node resourceNode = AssetResource.getResourceNodeFromAsset(((Node) referenceItem));
  8. if (resourceNode != null) {
  9. String extension = PropertyUtil.getString(resourceNode, AssetResource.EXTENSION, EMPTY);
  10. String fileName = PropertyUtil.getString(resourceNode, AssetResource.FILENAME);
  11. String referenceName = (fileName != null && fileName.endsWith(extension)) ? fileName : fileName + "." + extension;
  12. return Path.getUniqueLabel(destination.getSession(), destination.getPath(), Path.getValidatedLabel(referenceName), extension);
  13. }
  14. }
  15. return super.getUniqueNewItemName(referenceItem, destination);
  16. }
  17. }

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

  1. @Override
  2. protected void operateOnNode(InstallContext installContext, Node node) {
  3. try {
  4. if (!node.hasNode(SUB_APP_MAPPING) || node.hasNode(SUB_APP_MAPPINGS)) {
  5. return;
  6. }
  7. Node subAppMapping = node.getNode(SUB_APP_MAPPING);
  8. Node subAppMappings = node.addNode(SUB_APP_MAPPINGS, NodeTypes.ContentNode.NAME);
  9. PropertyIterator propertyIterator = new FilteringPropertyIterator(subAppMapping.getProperties(), new JcrAndMgnlMetadataHidingPredicate());
  10. while (propertyIterator.hasNext()) {
  11. Property obsoleteMappingProperty = propertyIterator.nextProperty();
  12. Node newMappingNode = subAppMappings.addNode(Path.getValidatedLabel(obsoleteMappingProperty.getName()), NodeTypes.ContentNode.NAME);
  13. newMappingNode.setProperty(NODE_TYPE, obsoleteMappingProperty.getName());
  14. newMappingNode.setProperty(SUB_APP_ID, obsoleteMappingProperty.getValue());
  15. }
  16. subAppMapping.remove();
  17. } catch (RepositoryException e) {
  18. installContext.error(String.format("Cannot finish task '%s':", this.getDescription()), e);
  19. }
  20. }

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

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

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

  1. String mediaName = Path.getValidatedLabel(filename);

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

  1. assertEquals("f", Path.getValidatedLabel("f", null));
  2. assertEquals("fo", Path.getValidatedLabel("fo", null));
  3. assertEquals("foo", Path.getValidatedLabel("foo", null));
  4. assertEquals("foo.bar", Path.getValidatedLabel("foo.bar", null));
  5. assertEquals("foo..bar", Path.getValidatedLabel("foo..bar", null));
  6. assertEquals("-foo", Path.getValidatedLabel(".foo", null));
  7. assertEquals("-.foo", Path.getValidatedLabel("..foo", null));
  8. assertEquals("f-oo", Path.getValidatedLabel("f$oo", null));
  9. assertEquals("f-oo", Path.getValidatedLabel("f*oo", null));
  10. assertEquals("f-oo", Path.getValidatedLabel("f[oo", null));
  11. assertEquals("f-oo", Path.getValidatedLabel("f]oo", null));
  12. assertEquals("f-oo", Path.getValidatedLabel("f;oo", null));
  13. assertEquals("f-oo", Path.getValidatedLabel("f:oo", null));
  14. assertEquals("f-oo", Path.getValidatedLabel("f\"oo", null));
  15. assertEquals("f-oo", Path.getValidatedLabel("f'oo", null));
  16. assertEquals("f-oo", Path.getValidatedLabel("f#oo", null));
  17. assertEquals("f-oo", Path.getValidatedLabel("f!oo", null));
  18. assertEquals("f-oo", Path.getValidatedLabel("f+oo", null));
  19. assertEquals("f-oo", Path.getValidatedLabel("f?oo", null));
  20. assertEquals("f-oo", Path.getValidatedLabel("f/oo", null));
  21. assertEquals("f-oo", Path.getValidatedLabel("f%oo", null));
  22. assertEquals("f-oo", Path.getValidatedLabel("f oo", null)); // if you can't see it, that's a space (ascii code 32)
  23. assertEquals("f-oo", Path.getValidatedLabel("f-oo", null));
  24. assertEquals("f_oo", Path.getValidatedLabel("f_oo", null));
  25. assertEquals("f-oo", Path.getValidatedLabel("f~oo", null));

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

  1. @Override
  2. public String convertToModel(String label, Class<? extends String> targetType, Locale locale) throws ConversionException {
  3. // Null is required for the property to be removed if path is empty
  4. String res = null;
  5. if (StringUtils.isBlank(label)) {
  6. return res;
  7. }
  8. try {
  9. Session session = MgnlContext.getJCRSession(workspace);
  10. String path = PathUtil.createPath(basePath, label);
  11. if (session.nodeExists(path)) {
  12. res = session.getNode(path).getIdentifier();
  13. } else {
  14. // try to convert the label to a valid node name
  15. label = Path.getValidatedLabel(label);
  16. path = PathUtil.createPath(basePath, label);
  17. if (session.nodeExists(path)) {
  18. res = session.getNode(path).getIdentifier();
  19. } else {
  20. log.warn("{} is not a valid node path or is not existing in the following repository {} ", path, workspace);
  21. }
  22. }
  23. } catch (RepositoryException e) {
  24. log.error("Unable to convert Path to UUID", e);
  25. }
  26. return res;
  27. }

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

  1. Path.getValidatedLabel(Components
  2. .getComponent(MediaConfigurationManager.class)
  3. .getTypes()

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

  1. public static Node createAsset(Node parentFolder, UploadReceiver receiver) throws RepositoryException {
  2. // Get the Asset Node name
  3. String fileName = receiver.getFileName();
  4. String assetNodeName = Path.getValidatedLabel(fileName);
  5. JcrNodeAdapter resourceItem = null;
  6. JcrNodeAdapter assetItem = null;
  7. // Get the existing asset or create one new
  8. if (parentFolder.hasNode(assetNodeName)) {
  9. assetItem = new JcrNodeAdapter(parentFolder.getNode(assetNodeName));
  10. resourceItem = new JcrNodeAdapter(AssetNodeTypes.AssetResource.getResourceNodeFromAsset(parentFolder.getNode(assetNodeName)));
  11. } else {
  12. assetItem = new JcrNewNodeAdapter(parentFolder, AssetNodeTypes.Asset.NAME, assetNodeName);
  13. resourceItem = new JcrNewNodeAdapter(parentFolder, NodeTypes.Resource.NAME, JcrConstants.JCR_CONTENT);
  14. }
  15. // Link the resource to the Asset Item
  16. assetItem.addChild(resourceItem);
  17. // Populate the resourceItem based on the receiver
  18. new AssetTransformer().populateItem((AssetUploadReceiver) receiver, resourceItem);
  19. // Set the Asset name property
  20. Node assetNode = assetItem.applyChanges();
  21. SaveAssetFormAction.setAssetPropertyName(assetItem, assetNode, fileName);
  22. return assetNode;
  23. }
  24. }

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

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

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

  1. /**
  2. * Adds multi value type.
  3. * @param node Parent node.
  4. * @param name Name of the value node.
  5. * @param value Value.
  6. * @param itemType Item type of newly created node.
  7. * @return Newly created multi value node.
  8. * @throws RepositoryException When node can't be created or saved.
  9. * @see MULTI_VALUE_ITEM_TYPE
  10. */
  11. public static Content addMultiValue(Content node, String name, Value value, ItemType itemType)
  12. throws RepositoryException {
  13. Content multiNode = ContentUtil.getOrCreateContent(node, name, new ItemType(
  14. DataConsts.MODULE_DATA_CONTENT_NODE_TYPE));
  15. String valueNodeName = StringUtils.left(
  16. Path.getValidatedLabel(NodeDataUtil.getValueString(value, "YYYYmmDD")),
  17. 20);
  18. valueNodeName = Path.getUniqueLabel(node, valueNodeName);
  19. Content valueNode = multiNode.createContent(valueNodeName, itemType);
  20. NodeDataUtil.getOrCreate(valueNode, name).setValue(value);
  21. return valueNode;
  22. }

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

  1. @Test
  2. public void getNode_NewProperty() throws Exception {
  3. // GIVEN
  4. String id = ModelConstants.JCR_NAME;
  5. String value = "new Parent { % !";
  6. JcrNodeAdapter adapter = new JcrNodeAdapter(node);
  7. // Get the node name as property
  8. Property property = adapter.getItemProperty(id);
  9. assertEquals(nodeName, property.getValue().toString());
  10. // Change the property node name
  11. property.setValue(value);
  12. // WHEN
  13. Node res = adapter.applyChanges();
  14. // THEN
  15. // should have a new NodeName
  16. assertEquals(Path.getValidatedLabel(value), res.getName());
  17. assertEquals(true, res.hasProperty("propertyString"));
  18. assertEquals(true, res.hasNode("child"));
  19. }

相关文章