* Licensed 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
- *
+ * <p>
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
* 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.
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
import com.google.common.collect.Multimap;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.Vector;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.lang3.StringUtils;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.edges.EdgeRule;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.*;
-
public class NodesYAMLfromOXM extends OxmFileProcessor {
private static final Logger logger = LoggerFactory.getLogger("GenerateXsd.class");
- private static final String root = "../aai-schema/src/main/resources";
- private static final String autoGenRoot = "aai-schema/src/main/resources";
- private static final String generateTypeYAML = "yaml";
- private static final String normalStartDir = "aai-schema-gen";
- private static final String yaml_dir = (((System.getProperty("user.dir") != null)
- && (!System.getProperty("user.dir").contains(normalStartDir))) ? autoGenRoot : root)
+ private static final String ROOT = "../aai-schema/src/main/resources";
+ private static final String AUTO_GEN_ROOT = "aai-schema/src/main/resources";
+ private static final String GENERATE_TYPE_YAML = "yaml";
+ private static final String NORMAL_START_DIR = "aai-schema-gen";
+ private static final String YAML_DIR = (((System.getProperty("user.dir") != null)
+ && (!System.getProperty("user.dir").contains(NORMAL_START_DIR))) ? AUTO_GEN_ROOT : ROOT)
+ "/aai_swagger_yaml";
private StringBuilder inventoryDefSb = null;
private Map<String, String> operationDefinitions = new HashMap<>();
- private String basePath;
+ private final String basePath;
public NodesYAMLfromOXM(String basePath, SchemaVersions schemaVersions, NodeIngestor ni,
- EdgeIngestor ei) {
+ EdgeIngestor ei) {
super(schemaVersions, ni, ei);
this.basePath = basePath;
}
@Override
public String getDocumentHeader() {
- StringBuffer sb = new StringBuffer();
- sb.append("swagger: \"2.0\"\ninfo:" + LINE_SEPARATOR + " ");
+ StringBuilder sb = new StringBuilder();
+ sb.append("swagger: \"2.0\"\ninfo:").append(LINE_SEPARATOR).append(" ");
sb.append("description: |");
if (versionSupportsSwaggerDiff(v.toString())) {
- sb.append("\n\n [Differences versus the previous schema version]("
- +"apidocs" + basePath + "/aai_swagger_" + v.toString() + ".diff)");
- }
- sb.append(
- DOUBLE_LINE_SEPARATOR + " Copyright © 2017-18 AT&T Intellectual Property. All rights reserved." + OxmFileProcessor.DOUBLE_LINE_SEPARATOR + " Licensed under the Creative Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except in compliance with the License." + DOUBLE_LINE_SEPARATOR + " You may obtain a copy of the License at\n\n (https://creativecommons.org/licenses/by/4.0/)" + DOUBLE_LINE_SEPARATOR + " 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." + OxmFileProcessor.DOUBLE_LINE_SEPARATOR + " This document is best viewed with Firefox or Chrome. ");
- sb.append(
- "Nodes can be found by opening the models link below and finding the node-type. ");
+ sb.append("\n\n [Differences versus the previous schema version](" + "apidocs")
+ .append(basePath).append("/aai_swagger_").append(v.toString()).append(".diff)");
+ }
+ sb.append(DOUBLE_LINE_SEPARATOR).append(
+ " Copyright © 2017-18 AT&T Intellectual Property. All rights reserved.")
+ .append(OxmFileProcessor.DOUBLE_LINE_SEPARATOR).append(
+ " Licensed under the Creative Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except in compliance with the License.")
+ .append(DOUBLE_LINE_SEPARATOR).append(
+ " You may obtain a copy of the License at\n\n (https://creativecommons.org/licenses/by/4.0/)")
+ .append(DOUBLE_LINE_SEPARATOR).append(
+ " 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.")
+ .append(OxmFileProcessor.DOUBLE_LINE_SEPARATOR)
+ .append(" This document is best viewed with Firefox or Chrome. ");
sb.append(
- "Edge definitions can be found with the node definitions." + LINE_SEPARATOR + " version: \""
- + v.toString() + "\"" + LINE_SEPARATOR );
- sb.append(" title: Active and Available Inventory REST API" + LINE_SEPARATOR);
- sb.append(
- " license:" + LINE_SEPARATOR + " name: Apache 2.0" + LINE_SEPARATOR + " url: http://www.apache.org/licenses/LICENSE-2.0.html" + LINE_SEPARATOR);
- sb.append(" contact:" + LINE_SEPARATOR + " name: n/a" + LINE_SEPARATOR + " url: n/a" + LINE_SEPARATOR + " email: n/a" + LINE_SEPARATOR);
- sb.append("host: n/a" + LINE_SEPARATOR + "basePath: " + basePath + "/" + v.toString() + LINE_SEPARATOR);
- sb.append("schemes:" + LINE_SEPARATOR + " - https\npaths:" + LINE_SEPARATOR);
+ "Nodes can be found by opening the models link below and finding the node-type. ");
+ sb.append("Edge definitions can be found with the node definitions.").append(LINE_SEPARATOR)
+ .append(" version: \"").append(v.toString()).append("\"").append(LINE_SEPARATOR);
+ sb.append(" title: Active and Available Inventory REST API").append(LINE_SEPARATOR);
+ sb.append(" license:").append(LINE_SEPARATOR).append(" name: Apache 2.0")
+ .append(LINE_SEPARATOR)
+ .append(" url: http://www.apache.org/licenses/LICENSE-2.0.html")
+ .append(LINE_SEPARATOR);
+ sb.append(" contact:").append(LINE_SEPARATOR).append(" name: n/a")
+ .append(LINE_SEPARATOR).append(" url: n/a").append(LINE_SEPARATOR)
+ .append(" email: n/a").append(LINE_SEPARATOR);
+ sb.append("host: n/a").append(LINE_SEPARATOR).append("basePath: ").append(basePath)
+ .append("/").append(v.toString()).append(LINE_SEPARATOR);
+ sb.append("schemes:").append(LINE_SEPARATOR).append(" - https\npaths:")
+ .append(LINE_SEPARATOR);
return sb.toString();
}
@Override
public String process() throws ParserConfigurationException, SAXException, IOException,
FileNotFoundException, EdgeRuleNotFoundException {
- StringBuffer sb = new StringBuffer();
- StringBuffer pathSb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
+ StringBuilder pathSb = new StringBuilder();
NodeGetOperation.resetContainers();
try {
init();
throw e;
}
pathSb.append(getDocumentHeader());
- StringBuffer definitionsSb = new StringBuffer();
+ StringBuilder definitionsSb = new StringBuilder();
Element elem;
String javaTypeName;
for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
if (inventoryDefSb != null) {
javaTypeDefinitions.put("inventory", inventoryDefSb.toString());
}
- StringBuffer sb = new StringBuffer("definitions:\n");
+ StringBuilder sb = new StringBuilder("definitions:\n");
Map<String, String> sortedJavaTypeDefinitions = new TreeMap<>(javaTypeDefinitions);
for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) {
continue;
}
logger.debug(
- "Key: " + entry.getKey() + "Test: " + (entry.getKey() == "relationship-dict"));
+ "Key: " + entry.getKey() + "Test: " +
+ ("relationship-dict".equals(entry.getKey()) ? "true" : "false"));
if (entry.getKey().matches("relationship-dict")) {
String jb = entry.getValue();
logger.debug("Value: " + jb);
int ndx = jb.indexOf("related-to-property:");
if (ndx > 0) {
jb = jb.substring(0, ndx);
- jb = jb.replaceAll(" +$", "");
+ jb = StringUtils.stripEnd(jb, " ");
}
logger.debug("Value-after: " + jb);
sb.append(jb);
}
return sb.toString();
}
-
+
private String getDictionary(String resource) {
- StringBuffer dictSb = new StringBuffer();
- dictSb.append(" " + resource + ":\n");
+ StringBuilder dictSb = new StringBuilder();
+ dictSb.append(" ").append(resource).append(":\n");
dictSb.append(" description: |\n");
- dictSb.append(" dictionary of " + resource + "\n");
+ dictSb.append(" dictionary of ").append(resource).append("\n");
dictSb.append(" type: object\n");
dictSb.append(" properties:\n");
- dictSb.append(" " + resource + ":\n");
+ dictSb.append(" ").append(resource).append(":\n");
dictSb.append(" type: array\n");
dictSb.append(" items:\n");
- dictSb.append(" $ref: \"#/definitions/" + resource + "-dict\"\n");
+ dictSb.append(" $ref: \"#/definitions/").append(resource).append("-dict\"\n");
return dictSb.toString();
}
- private String processJavaTypeElementSwagger(String javaTypeName, Element javaTypeElement,
- StringBuffer pathSb, StringBuffer definitionsSb, String path, String tag, String opId,
- String getItemName, StringBuffer pathParams, String validEdges) {
+ private String processJavaTypeElementSwagger(
+ String javaTypeName, Element javaTypeElement,
+ StringBuilder pathSb, StringBuilder definitionsSb, String path, String tag, String opId,
+ String getItemName, StringBuilder pathParams, String validEdges) {
String xmlRootElementName = getXMLRootElementName(javaTypeElement);
StringBuilder definitionsLocalSb = new StringBuilder(256);
logger.debug("tag=" + tag + "; javaTypeName=" + javaTypeName);
return null;
}
- if (!javaTypeName.equals("Inventory")) {
- if (javaTypeName.equals("AaiInternal")) {
+ if (!"Inventory".equals(javaTypeName)) {
+ if ("AaiInternal".equals(javaTypeName)) {
return null;
}
if (opId == null) {
}
}
- path = xmlRootElementName.equals("inventory") ? ""
+ path = "inventory".equals(xmlRootElementName) ? ""
: (path == null) ? "/" + xmlRootElementName : path + "/" + xmlRootElementName;
XSDJavaType javaType = new XSDJavaType(javaTypeElement);
if (getItemName != null) {
- if (getItemName.equals("array")) {
+ if ("array".equals(getItemName)) {
return javaType.getArrayType();
} else {
return javaType.getItemName();
Element parentElement = (Element) parentNodes.item(0);
NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element");
- StringBuffer sbParameters = new StringBuffer();
- StringBuffer sbRequired = new StringBuffer();
+ StringBuilder sbParameters = new StringBuilder();
+ StringBuilder sbRequired = new StringBuilder();
int requiredCnt = 0;
int propertyCnt = 0;
- StringBuffer sbProperties = new StringBuffer();
+ StringBuilder sbProperties = new StringBuilder();
if (appliedPaths.containsKey(path)) {
return null;
}
StringTokenizer st = new StringTokenizer(path, "/");
- logger.debug("path: " + path + " st? " + st.toString());
+ logger.debug("path: " + path + " st? " + st);
if (st.countTokens() > 1 && getItemName == null) {
logger.debug("appliedPaths: " + appliedPaths + " containsKey? "
+ appliedPaths.containsKey(path));
logger.debug("xmlElementElement.getAttribute(required):"
+ xmlElementElement.getAttribute("required"));
- if (("true").equals(xmlElementElement.getAttribute("required"))) {
+ if ("true".equals(xmlElementElement.getAttribute("required"))) {
if (requiredCnt == 0) {
sbRequired.append(" required:\n");
}
++requiredCnt;
if (addTypeV == null || addTypeV.isEmpty()) {
- sbRequired.append(" - " + xmlElementElement.getAttribute("name") + "\n");
+ sbRequired.append(" - ").append(xmlElementElement.getAttribute("name"))
+ .append("\n");
} else {
for (int k = 0; k < addTypeV.size(); ++k) {
- sbRequired.append(
- " - " + getXmlRootElementName(addTypeV.elementAt(k)) + ":\n");
+ sbRequired.append(" - ")
+ .append(getXmlRootElementName(addTypeV.elementAt(k))).append(":\n");
}
}
}
NodeGetOperation.addContainerProps(container, containerProps);
}
if (xmlElementElement.isStandardType()) {
- boolean isDslStartNode = dslStartNodeProps.contains(xmlElementElement.getAttribute("name"));
+ boolean isDslStartNode =
+ dslStartNodeProps.contains(xmlElementElement.getAttribute("name"));
sbProperties.append(xmlElementElement.getTypePropertyYAML(isDslStartNode));
++propertyCnt;
}
// StringBuffer newPathParams = new StringBuffer((pathParams == null ? "" :
// pathParams.toString())+sbParameters.toString()); //cp8128 don't append the pathParams
// to sbParameters so that child nodes don't contain the parameters from parent
- StringBuffer newPathParams = new StringBuffer(sbParameters.toString());
+ StringBuilder newPathParams = new StringBuilder(sbParameters.toString());
String useName;
for (int k = 0; addTypeV != null && k < addTypeV.size(); ++k) {
String addType = addTypeV.elementAt(k);
tag == null ? useTag : tag, useOpId, "array", null, null);
if (itemName != null) {
- if (addType.equals("AaiInternal")) {
+ if ("AaiInternal".equals(addType)) {
logger.debug("addType AaiInternal, skip properties");
} else if (getItemName == null) {
++propertyCnt;
- sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
- if ( "RelationshipList".equals(addType)) {
+ sbProperties.append(" ").append(getXmlRootElementName(addType))
+ .append(":\n");
+ if ("RelationshipList".equals(addType)) {
sbProperties.append(" type: object\n");
- sbProperties.append(" $ref: \"#/definitions/"
- + itemName + "\"\n");
+ sbProperties.append(" $ref: \"#/definitions/").append(itemName)
+ .append("\"\n");
} else {
- sbProperties.append(" type: array\n items:\n");
- sbProperties.append(" $ref: \"#/definitions/"
- + (itemName == "" ? "aai-internal" : itemName) + "\"\n");
+ sbProperties.append(" type: array\n items:\n");
+ sbProperties.append(" $ref: \"#/definitions/")
+ .append("".equals(itemName) ? "aai-internal" : itemName)
+ .append("\"\n");
}
if (StringUtils.isNotEmpty(elementDescription)) {
- sbProperties
- .append(" description: " + elementDescription + "\n");
+ sbProperties.append(" description: ").append(elementDescription)
+ .append("\n");
}
}
} else {
// newPathParams = new StringBuffer((pathParams == null ? "" :
// pathParams.toString())+sbParameters.toString()); //cp8128 - change this
// to not append pathParameters. Just use sbParameters
- newPathParams = new StringBuffer(sbParameters.toString());
+ newPathParams = new StringBuilder(sbParameters.toString());
processJavaTypeElementSwagger(addType, getJavaTypeElementSwagger(addType),
pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, null,
newPathParams, validEdges);
useName = getXmlRootElementName(addType);
- sbProperties.append(" " + useName + ":\n");
- if ( "relationship".equals(useName)) {
+ sbProperties.append(" ").append(useName).append(":\n");
+ if ("relationship".equals(useName)) {
sbProperties.append(" type: object\n");
sbProperties.append(" $ref: \"#/definitions/relationship\"\n");
} else {
- sbProperties.append(" type: array\n items: \n");
- sbProperties.append(" $ref: \"#/definitions/"
- + getXmlRootElementName(addType) + "\"\n");
+ sbProperties.append(" type: array\n items: \n");
+ sbProperties.append(" $ref: \"#/definitions/")
+ .append(getXmlRootElementName(addType)).append("\"\n");
}
if (StringUtils.isNotEmpty(elementDescription)) {
- sbProperties
- .append(" description: " + elementDescription + "\n");
+ sbProperties.append(" description: ").append(elementDescription)
+ .append("\n");
}
} else {
// Make sure certain types added to the filter don't appear
- if (nodeFilter.contains(getXmlRootElementName(addType))) {
- ;
- } else {
- sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
+ if (!nodeFilter.contains(getXmlRootElementName(addType))) {
+ sbProperties.append(" ").append(getXmlRootElementName(addType))
+ .append(":\n");
sbProperties.append(" type: object\n");
- sbProperties.append(" $ref: \"#/definitions/"
- + getXmlRootElementName(addType) + "\"\n");
+ sbProperties.append(" $ref: \"#/definitions/")
+ .append(getXmlRootElementName(addType)).append("\"\n");
}
}
if (StringUtils.isNotEmpty(elementDescription)) {
- sbProperties.append(" description: " + elementDescription + "\n");
+ sbProperties.append(" description: ").append(elementDescription)
+ .append("\n");
}
++propertyCnt;
}
if (sbParameters.toString().length() > 0) {
if (pathParams == null) {
- pathParams = new StringBuffer();
+ pathParams = new StringBuilder();
}
pathParams.append(sbParameters);
}
processingInventoryDef = true;
if (inventoryDefSb == null) {
inventoryDefSb = new StringBuilder();
- definitionsSb.append(" " + xmlRootElementName + ":\n");
- definitionsLocalSb.append(" " + xmlRootElementName + ":\n");
+ definitionsSb.append(" ").append(xmlRootElementName).append(":\n");
+ definitionsLocalSb.append(" ").append(xmlRootElementName).append(":\n");
definitionsLocalSb.append(" properties:\n");
}
} else if (xmlRootElementName.equals("relationship")) {
definitionsLocalSb.append(" " + "relationship-dict" + ":\n");
dict = getDictionary(xmlRootElementName);
} else {
- definitionsSb.append(" " + xmlRootElementName + ":\n");
- definitionsLocalSb.append(" " + xmlRootElementName + ":\n");
+ definitionsSb.append(" ").append(xmlRootElementName).append(":\n");
+ definitionsLocalSb.append(" ").append(xmlRootElementName).append(":\n");
}
DeleteFootnoteSet footnotes = new DeleteFootnoteSet(xmlRootElementName);
- StringBuffer sbEdge = new StringBuffer();
+ StringBuilder sbEdge = new StringBuilder();
LinkedHashSet<String> preventDelete = new LinkedHashSet<String>();
String prevent = null;
- String nodeCaption = new String(" ###### Related Nodes\n");
+ String nodeCaption = " ###### Related Nodes\n";
try {
EdgeRuleQuery q =
new EdgeRuleQuery.Builder(xmlRootElementName).version(v).fromOnly().build();
results.get(key).stream()
.filter((i) -> (i.getFrom().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- logger.info(new String(new StringBuffer(" - TO ").append(i.getTo())
+ logger.info(new String(new StringBuilder(" - TO ").append(i.getTo())
.append(i.getDirection().toString()).append(i.getContains())));
});
results.get(key).stream()
.filter((i) -> (i.getFrom().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- sbEdge.append(" - TO " + i.getTo());
+ sbEdge.append(" - TO ").append(i.getTo());
EdgeDescription ed = new EdgeDescription(i);
String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName);
- sbEdge.append(ed.getRelationshipDescription("TO", xmlRootElementName)
- + footnote + "\n");
+ sbEdge.append(ed.getRelationshipDescription("TO", xmlRootElementName))
+ .append(footnote).append("\n");
if (StringUtils.isNotEmpty(footnote)) {
footnotes.add(footnote);
}
results.get(key).stream()
.filter((i) -> (i.getTo().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- sbEdge.append(" - FROM " + i.getFrom());
+ sbEdge.append(" - FROM ").append(i.getFrom());
EdgeDescription ed = new EdgeDescription(i);
String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName);
- sbEdge.append(ed.getRelationshipDescription("FROM", xmlRootElementName)
- + footnote + "\n");
+ sbEdge.append(ed.getRelationshipDescription("FROM", xmlRootElementName))
+ .append(footnote).append("\n");
if (StringUtils.isNotEmpty(footnote)) {
footnotes.add(footnote);
}
results.get(key).stream()
.filter((i) -> (i.getTo().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- logger.info(new String(new StringBuffer(" - FROM ").append(i.getFrom())
- .append(i.getDirection().toString()).append(i.getContains())));
+ logger
+ .info(new String(new StringBuilder(" - FROM ").append(i.getFrom())
+ .append(i.getDirection().toString()).append(i.getContains())));
});
results.get(key).stream()
.filter((i) -> (i.getTo().equals(xmlRootElementName)
definitionsLocalSb.append(" description: |\n");
if (pathDescriptionProperty != null) {
- definitionsSb.append(" " + pathDescriptionProperty + "\n");
- definitionsLocalSb.append(" " + pathDescriptionProperty + "\n");
+ definitionsSb.append(" ").append(pathDescriptionProperty).append("\n");
+ definitionsLocalSb.append(" ").append(pathDescriptionProperty).append("\n");
}
definitionsSb.append(validEdges);
definitionsLocalSb.append(validEdges);
namespaceFilter.add(xmlRootElementName);
if (xmlRootElementName.equals("inventory")) {
// will add to javaTypeDefinitions at end
- inventoryDefSb.append(definitionsLocalSb.toString());
+ inventoryDefSb.append(definitionsLocalSb);
} else if (xmlRootElementName.equals("relationship")) {
javaTypeDefinitions.put(xmlRootElementName, dict);
javaTypeDefinitions.put(xmlRootElementName + "-dict",
- definitionsLocalSb.toString());
+ definitionsLocalSb.toString());
} else {
javaTypeDefinitions.put(xmlRootElementName, definitionsLocalSb.toString());
}
} catch (Exception e) {
- e.printStackTrace();
+ logger.trace("Exception during javaTypeDefinitions :", e);
}
if (xmlRootElementName.equals("inventory")) {
logger.trace("skip xmlRootElementName(2)=" + xmlRootElementName);
private void writeYAMLfile(String outfileName, String fileContent) {
outfileName = (StringUtils.isEmpty(outfileName)) ? "aai_swagger" : outfileName;
outfileName = (outfileName.lastIndexOf(File.separator) == -1)
- ? yaml_dir + File.separator + outfileName + "_" + v.toString() + "." + generateTypeYAML
+ ? YAML_DIR + File.separator + outfileName + "_" + v.toString() + "." +
+ GENERATE_TYPE_YAML
: outfileName;
File outfile = new File(outfileName);
File parentDir = outfile.getParentFile();
parentDir.mkdirs();
}
try {
- outfile.createNewFile();
+ if(!outfile.createNewFile()) {
+ logger.error( "File {} already exist", outfileName);
+ }
} catch (IOException e) {
- logger.error("Exception creating output file " + outfileName);
- e.printStackTrace();
+ logger.error("Exception creating output file " + outfileName, e);
}
Path path = Paths.get(outfileName);
- Charset charset = Charset.forName("UTF-8");
- try (BufferedWriter bw = Files.newBufferedWriter(path, charset);) {
+ Charset charset = StandardCharsets.UTF_8;
+ try (BufferedWriter bw = Files.newBufferedWriter(path, charset)) {
bw.write(fileContent);
- if (bw != null) {
- bw.close();
- }
} catch (IOException e) {
- logger.error("Exception writing output file " + outfileName);
- e.printStackTrace();
+ logger.error("Exception writing output file " + outfileName, e);
}
}
public boolean validTag(String tag) {
if (tag != null) {
- // refactored to support top level paths from the schema file, set the ignore
- // parameter to false allows the logic to match all top level paths, including
- // Search and Actions, as hard-coded prior to refactoring
- if (checkTopLevel(tag, false)) {
- return true;
- }
+ // refactored to support top level paths from the schema file, set the ignore
+ // parameter to false allows the logic to match all top level paths, including
+ // Search and Actions, as hard-coded prior to refactoring
+ return checkTopLevel(tag, false);
}
return false;
}
public String appendOperations() {
// append definitions
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
Map<String, String> sortedOperationDefinitions =
new TreeMap<String, String>(operationDefinitions);
for (Map.Entry<String, String> entry : sortedOperationDefinitions.entrySet()) {