diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/utils/RealNetUtils.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/utils/RealNetUtils.java new file mode 100644 index 0000000..d645800 --- /dev/null +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/utils/RealNetUtils.java @@ -0,0 +1,180 @@ +package com.realnet.utils; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public class RealNetUtils { + + public static String stringReplace(String str, String start, String end, String replaceWith, String file_type) { + int i = str.indexOf(start); + while (i != -1) { + int j = str.indexOf(end, i + 1); + if (j != -1) { + /* + * @Include starting and ending string String data = str.substring(0, i + + * start.length()) + "\n" + replaceWith + "\n"; String temp = str.substring(j); + * + * @Not Include starting and ending string String data = str.substring(0, i) + + * "\n" + replaceWith + "\n"; String temp = str.substring(j + end.length()); + */ + String data = str.substring(0, i) + "\n" + replaceWith + "\n"; + String temp = str.substring(j + end.length()); + data += temp; + str = data; + i = str.indexOf(start, i + replaceWith.length() + end.length() + 1); + } else { + break; + } + } + +// if (replaced) { +// String newStart = ""; +// String newEnd = ""; +// if(file_type.equals("html") || file_type.equals("jsp")) { +// newStart = ""; +// newEnd = ""; +// str = str.replace(start, newStart); +// str = str.replace(end, newEnd); +// } +// if(file_type.equals("java") || file_type.equals("ts") || file_type.equals("js")) { +// newStart = "/* bcf-fieldloop-startshere-processed */"; +// newEnd = "/* bcf-fieldloop-endshere-processed */"; +// str = str.replace(start, newStart); +// str = str.replace(end, newEnd); +// } +// } + return str; + } + + public static String stringReplace(String str, String start, String end, String replaceWith) { + int i = str.indexOf(start); + while (i != -1) { + int j = str.indexOf(end, i + 1); + if (j != -1) { + /* + * @Include starting and ending string String data = str.substring(0, i + + * start.length()) + "\n" + replaceWith + "\n"; String temp = str.substring(j); + * + * @Not Include starting and ending string String data = str.substring(0, i) + + * "\n" + replaceWith + "\n"; String temp = str.substring(j + end.length()); + */ + String data = str.substring(0, i) + "\n" + replaceWith + "\n"; + String temp = str.substring(j + end.length()); + data += temp; + str = data; + i = str.indexOf(start, i + replaceWith.length() + end.length() + 1); + } else { + break; + } + } + return str; + } + + // file and folder present in a zip file + public static void printFileList(String filePath) { + FileInputStream fis = null; + ZipInputStream zipIs = null; + ZipEntry zEntry = null; + try { + fis = new FileInputStream(filePath); + zipIs = new ZipInputStream(new BufferedInputStream(fis)); + while ((zEntry = zipIs.getNextEntry()) != null) { + System.out.println(zEntry.getName()); + } + zipIs.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /* + * SPRING_MVC_HIBERNATE_MYSQL (sphmy), ANGULAR_SPRING_BOOT_MYSQL (aspmy), + * REACT_REACT_NATIVE_MYSQL (rrnmy), REACT_REACT_NATIVE_MONGODB (rrnmo), + * ANGULAR_SPRING_BOOT_MONGODB (aspmo), PHP_LARAVEL_MYSQL (plvmy), MEAN (mean) + */ + + public static String toFirstUpperCase(String input) { + String output = input.substring(0, 1).toUpperCase() + input.substring(1); + return output; + } + + public static String formatStringtoSql(String input) { + if (input == null || input.isEmpty()) { + return input; + } + + // Convert input to lowercase and replace spaces with underscores + String result = input.trim().replace(" ", "_"); + + // Use StringBuilder to modify the result string + StringBuilder formattedString = new StringBuilder(result); + + // Iterate through each character in the string + for (int i = 0; i < formattedString.length(); i++) { + char currentChar = formattedString.charAt(i); + + // Check if the current character is an underscore or space + if (currentChar == '_') { + continue; + } + + // Check if the previous character was an underscore + if (i > 0 && formattedString.charAt(i - 1) == '_') { + formattedString.setCharAt(i, Character.toLowerCase(currentChar)); + } else if (Character.isUpperCase(currentChar)) { + // Insert an underscore before capital letters (except the first character) + if (i > 0) { + formattedString.insert(i, '_'); + formattedString.setCharAt(i + 1, Character.toLowerCase(currentChar)); + i++; // Skip the next character which is already processed + } + } + } + +// Example Gaurav Kumar gaurav_kumar GauravKumar gaurav_kumar gaurav_Kumar + + return formattedString.toString(); + } + + public String formatString(String input) { + if (input == null || input.isEmpty()) { + return input; + } + + // Convert input to lowercase and replace spaces with underscores + String result = input.trim().replace(" ", "_"); + + // Use StringBuilder to modify the result string + StringBuilder formattedString = new StringBuilder(result); + + // Iterate through each character in the string + for (int i = 0; i < formattedString.length(); i++) { + char currentChar = formattedString.charAt(i); + + // Check if the current character is an underscore or space + if (currentChar == '_') { + continue; + } + + // Check if the previous character was an underscore + if (i > 0 && formattedString.charAt(i - 1) == '_') { + formattedString.setCharAt(i, Character.toLowerCase(currentChar)); + } else if (Character.isUpperCase(currentChar)) { + // Insert an underscore before capital letters (except the first character) + if (i > 0) { + formattedString.insert(i, '_'); + formattedString.setCharAt(i + 1, Character.toLowerCase(currentChar)); + i++; // Skip the next character which is already processed + } + } + } + + return formattedString.toString(); + } +} diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/vpspack/Services/SiteBuilderService.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/vpspack/Services/SiteBuilderService.java index de2b167..2a66e90 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/vpspack/Services/SiteBuilderService.java +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/vpspack/Services/SiteBuilderService.java @@ -21,6 +21,7 @@ import com.realnet.realm.Entity.Realm; import com.realnet.realm.Services.RealmService; import com.realnet.users.entity1.AppUser; import com.realnet.users.service1.AppUserServiceImpl; +import com.realnet.utils.RealNetUtils; import com.realnet.vpspack.Entity.SiteBuilder; import com.realnet.vpspack.Repository.SiteBuilderRepository; @@ -98,8 +99,10 @@ public class SiteBuilderService { return test; } - public ResponseEntity createHtmlFile(String siteBuilderName, Map pageHtmlMap) throws IOException { + public ResponseEntity createHtmlFile(String siteBuilderName, Map pageHtmlMap) + throws IOException { + siteBuilderName = RealNetUtils.formatStringtoSql(siteBuilderName).toLowerCase(); String folderPath = projectPath + File.separator + "Files" + File.separator + siteBuilderName; int i = 0; @@ -125,8 +128,8 @@ public class SiteBuilderService { i++; System.out.println(i + " file created "); } - - return new ResponseEntity<>(new EntityResponse(i+ " files created "), HttpStatus.CREATED); + + return new ResponseEntity<>(new EntityResponse(i + " files created "), HttpStatus.CREATED); } public AppUser getUser() {