You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2022/12/16 10:01:27 UTC
[GitHub] [sling-org-apache-sling-repoinit-parser] kwin commented on a diff in pull request #27: SLING-11736 Add "createNode" as replacement of "createPath" with
kwin commented on code in PR #27:
URL: https://github.com/apache/sling-org-apache-sling-repoinit-parser/pull/27#discussion_r1050566210
##########
src/main/java/org/apache/sling/repoinit/parser/operations/CreateNode.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sling.repoinit.parser.operations;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Formatter;
+import java.util.List;
+
+import org.jetbrains.annotations.NotNull;
+import org.osgi.annotation.versioning.ProviderType;
+
+@ProviderType
+public class CreateNode extends Operation {
+ private List<PathSegmentDefinition> pathDef;
+ private final String defaultPrimaryType;
+ private List<PropertyLine> lines = Collections.emptyList();
+
+ public CreateNode(String defaultPrimaryType) {
+ this.pathDef = new ArrayList<>();
+ this.defaultPrimaryType = defaultPrimaryType;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + " " + pathDef;
+ }
+
+ @Override
+ protected String getParametersDescription() {
+ return pathDef.toString();
+ }
+
+ @NotNull
+ @Override
+ public String asRepoInitString() {
+ String defaultTypeStr = (defaultPrimaryType == null) ? "" : "("+defaultPrimaryType+") ";
+ StringBuilder sb = new StringBuilder();
+ for (PathSegmentDefinition psd : getDefinitions()) {
+ sb.append("/").append(psd.getSegment());
+ List<String> mixins = psd.getMixins();
+ if (!psd.isDefaultPrimary() || !mixins.isEmpty()) {
+ sb.append("(");
+ if (!psd.isDefaultPrimary()) {
+ sb.append(psd.getPrimaryType());
+ }
+ if (!mixins.isEmpty()) {
+ sb.append(" mixin ").append(listToString(mixins));
+ }
+ sb.append(")");
+ }
+ }
+
+ // FIXME: see SLING-10238 for type and quoted values that cannot be generated
+ // exactly as they were originally defined in repo-init
+ try (Formatter formatter = new Formatter()) {
+ if (lines.isEmpty()) {
+ formatter.format("create path %s%s%n", defaultTypeStr, sb.toString());
Review Comment:
this is a copy & paste mistake
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org