├── .gitignore
├── .idea
├── .gitignore
├── artifacts
│ └── Tagger_jar.xml
├── dataSources.xml
├── encodings.xml
├── misc.xml
├── runConfigurations
│ └── TagReplacementToolApp.xml
├── sqldialects.xml
├── vcs.xml
└── workspace.xml
├── .mvn
└── wrapper
│ └── maven-wrapper.properties
├── META-INF
└── MANIFEST.MF
├── README.md
├── Tagger.drawio
├── mvnw
├── mvnw.cmd
├── pom.xml
├── src
└── main
│ └── java
│ └── com
│ └── tagger
│ ├── Changelog
│ ├── DeveloperDoc
│ ├── Readme
│ ├── TagReplacementToolApp.java
│ ├── TagReplacementToolConfig.java
│ ├── TagReplacementToolController.java
│ ├── TagReplacementToolModel.java
│ ├── TagReplacementToolView.java
│ ├── console
│ ├── Driver.java
│ ├── Driverv2.java
│ ├── TagReplacementTool.java
│ ├── TagReplacementToolv2.java
│ ├── TagReplacementToolv3.java
│ ├── hasher.java
│ ├── tagger.sql
│ └── trtconfig.json
│ ├── old
│ ├── Tagrt.java
│ └── TagrtGUI.java
│ └── tagger.sql
├── tagger.sql
└── trtconfig.json
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 | !**/src/main/**/target/
4 | !**/src/test/**/target/
5 |
6 | ### IntelliJ IDEA ###
7 | .idea/modules.xml
8 | .idea/jarRepositories.xml
9 | .idea/compiler.xml
10 | .idea/libraries/
11 | *.iws
12 | *.iml
13 | *.ipr
14 |
15 | ### Eclipse ###
16 | .apt_generated
17 | .classpath
18 | .factorypath
19 | .project
20 | .settings
21 | .springBeans
22 | .sts4-cache
23 |
24 | ### NetBeans ###
25 | /nbproject/private/
26 | /nbbuild/
27 | /dist/
28 | /nbdist/
29 | /.nb-gradle/
30 | build/
31 | !**/src/main/**/build/
32 | !**/src/test/**/build/
33 |
34 | ### VS Code ###
35 | .vscode/
36 |
37 | ### Mac OS ###
38 | .DS_Store
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/.idea/artifacts/Tagger_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/Tagger_jar
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/dataSources.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | mariadb
6 | true
7 | org.mariadb.jdbc.Driver
8 | jdbc:mariadb://localhost:3306
9 | $ProjectFileDir$
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/runConfigurations/TagReplacementToolApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/sqldialects.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | {
33 | "associatedIndex": 1
34 | }
35 |
36 |
37 |
38 |
39 |
40 |
41 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | 1691310599944
89 |
90 |
91 | 1691310599944
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 | 1691869002453
116 |
117 |
118 |
119 | 1691869002453
120 |
121 |
122 |
123 | 1691869194065
124 |
125 |
126 |
127 | 1691869194065
128 |
129 |
130 |
131 | 1692126213119
132 |
133 |
134 |
135 | 1692126213119
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
178 |
179 |
180 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 | wrapperVersion=3.3.2
18 | distributionType=only-script
19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
20 |
--------------------------------------------------------------------------------
/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: com.tagger.TagReplacementToolApp
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Tagger: Tag Replacement Tool
2 | ============================
3 |
4 | Tagger is a versatile Java application designed to simplify the process of replacing tags within text content. It provides a user-friendly GUI that allows users to interactively replace tags in a structured manner. The application supports a wide range of features including tag extraction, tag comment retrieval, and advanced tag replacement options.
5 |
6 | Features
7 | --------
8 |
9 | - Interactive GUI: Tagger offers an intuitive graphical user interface that allows users to seamlessly navigate and perform tag replacement operations.
10 |
11 | - Tag Extraction: The application intelligently extracts tags from the provided content, making it easy for users to identify and manage tags.
12 |
13 | - Tag Comment Retrieval: Tagger fetches tag comments associated with each tag, providing context to the user during the replacement process.
14 |
15 | - Advanced Tag Replacement: Users can replace tags with customized text, including the ability to handle nested tags and optional tag content.
16 |
17 | - Configuration Support: Tagger reads configuration settings from a JSON file, allowing users to easily customize database connections, table names, and more.
18 |
19 | - Save and Load Data: Users can save and load data, enabling seamless work sessions across different instances of the application.
20 |
21 | - Data Persistence: The application stores tag replacement history, allowing users to review and track previous tag replacements.
22 |
23 | - Error Handling: Tagger provides informative error messages and visual alerts, including an error message for failed database connections.
24 |
25 | - Version Control: The project maintains a comprehensive version history, making it easy to track changes and updates.
26 |
27 | Usage
28 | -----
29 |
30 | 1. Launch the application.
31 | 2. Select the `mo_name` from the dropdown.
32 | 3. Click the "Process" button to begin the tag replacement process.
33 | 4. For each tag, the application presents a replacement dialog allowing the user to customize replacement text.
34 | 5. Optional: Users can save and load data using the provided buttons in the GUI.
35 |
36 | Getting Started
37 | ---------------
38 |
39 | 1. Clone this repository:
40 |
41 | ```sh
42 | git clone https://github.com/aamitn/Tagger.git
43 | ```
44 |
45 | 2. Navigate to the project directory:
46 |
47 | ```sh
48 | cd Tagger
49 | ```
50 |
51 | 3. Set Up the Database:
52 | - Configure the database connection credentials in the `trtconfig.json` file.
53 | - You may need to set up your preferred database system (e.g., MySQ/PostgreSQL etc any db having suppoorted JDBC drivers ) and create the necessary tables before running the application.
54 | - You can create the database schema by running the included `tagger.sql` file . (Schema is provided for MySQL DB)
55 |
56 | 4. Build and run the application using your preferred Java IDE or command-line tools. For example, using the command-line:
57 |
58 | ```sh
59 | javac TagReplacementToolApp.java
60 | java TagReplacementToolApp
61 | ```
62 |
63 |
64 | Database Schema (Generic , can be adopted for any relational DB)
65 | -------------
66 |
67 | ### Table: `table1`
68 |
69 | | Column Name | Data Type | Constraints | Description |
70 | |-------------|------------|--------------------------|----------------------------------|
71 | | `mo_name` | VARCHAR(15) | PRIMARY KEY, NOT NULL | Unique identifier for each record. |
72 | | `mo_content` | TEXT | NULLABLE | Content with embedded tags. |
73 | | `mo_tags` | TEXT | NULLABLE | Comma-separated list of associated tags. |
74 |
75 | ### Table: `table2`
76 |
77 | | Column Name | Data Type | Constraints | Description |
78 | |-------------|------------|--------------------------|----------------------------------|
79 | | `mo_tags` | VARCHAR(15) | PRIMARY KEY, NOT NULL | Unique identifier for each tag. |
80 | | `tag_comment` | TEXT | NULLABLE | Description or comment about the tag. |
81 |
82 |
83 |
84 |
85 |
86 |
87 | Configuration
88 | -------------
89 |
90 | Configuration settings are stored in the `trtconfig.json` file. Modify this file to adjust database connections, table names, and other parameters. This file should be located on the root of C: drive in Windows
91 |
92 | Contributing
93 | ------------
94 |
95 | Contributions to this project are welcome. Feel free to submit bug reports, feature requests, and pull requests.
96 |
97 | License
98 | -------
99 |
100 | This project is licensed under the [MIT License](https://mit-license.org).
101 |
--------------------------------------------------------------------------------
/Tagger.drawio:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Apache Maven Wrapper startup batch script, version 3.3.2
23 | #
24 | # Optional ENV vars
25 | # -----------------
26 | # JAVA_HOME - location of a JDK home dir, required when download maven via java source
27 | # MVNW_REPOURL - repo url base for downloading maven distribution
28 | # MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
29 | # MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
30 | # ----------------------------------------------------------------------------
31 |
32 | set -euf
33 | [ "${MVNW_VERBOSE-}" != debug ] || set -x
34 |
35 | # OS specific support.
36 | native_path() { printf %s\\n "$1"; }
37 | case "$(uname)" in
38 | CYGWIN* | MINGW*)
39 | [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
40 | native_path() { cygpath --path --windows "$1"; }
41 | ;;
42 | esac
43 |
44 | # set JAVACMD and JAVACCMD
45 | set_java_home() {
46 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
47 | if [ -n "${JAVA_HOME-}" ]; then
48 | if [ -x "$JAVA_HOME/jre/sh/java" ]; then
49 | # IBM's JDK on AIX uses strange locations for the executables
50 | JAVACMD="$JAVA_HOME/jre/sh/java"
51 | JAVACCMD="$JAVA_HOME/jre/sh/javac"
52 | else
53 | JAVACMD="$JAVA_HOME/bin/java"
54 | JAVACCMD="$JAVA_HOME/bin/javac"
55 |
56 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
57 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
58 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
59 | return 1
60 | fi
61 | fi
62 | else
63 | JAVACMD="$(
64 | 'set' +e
65 | 'unset' -f command 2>/dev/null
66 | 'command' -v java
67 | )" || :
68 | JAVACCMD="$(
69 | 'set' +e
70 | 'unset' -f command 2>/dev/null
71 | 'command' -v javac
72 | )" || :
73 |
74 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
75 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
76 | return 1
77 | fi
78 | fi
79 | }
80 |
81 | # hash string like Java String::hashCode
82 | hash_string() {
83 | str="${1:-}" h=0
84 | while [ -n "$str" ]; do
85 | char="${str%"${str#?}"}"
86 | h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
87 | str="${str#?}"
88 | done
89 | printf %x\\n $h
90 | }
91 |
92 | verbose() { :; }
93 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
94 |
95 | die() {
96 | printf %s\\n "$1" >&2
97 | exit 1
98 | }
99 |
100 | trim() {
101 | # MWRAPPER-139:
102 | # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
103 | # Needed for removing poorly interpreted newline sequences when running in more
104 | # exotic environments such as mingw bash on Windows.
105 | printf "%s" "${1}" | tr -d '[:space:]'
106 | }
107 |
108 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
109 | while IFS="=" read -r key value; do
110 | case "${key-}" in
111 | distributionUrl) distributionUrl=$(trim "${value-}") ;;
112 | distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
113 | esac
114 | done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
115 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
116 |
117 | case "${distributionUrl##*/}" in
118 | maven-mvnd-*bin.*)
119 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
120 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
121 | *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
122 | :Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
123 | :Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
124 | :Linux*x86_64*) distributionPlatform=linux-amd64 ;;
125 | *)
126 | echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
127 | distributionPlatform=linux-amd64
128 | ;;
129 | esac
130 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
131 | ;;
132 | maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
133 | *) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
134 | esac
135 |
136 | # apply MVNW_REPOURL and calculate MAVEN_HOME
137 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
138 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
139 | distributionUrlName="${distributionUrl##*/}"
140 | distributionUrlNameMain="${distributionUrlName%.*}"
141 | distributionUrlNameMain="${distributionUrlNameMain%-bin}"
142 | MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
143 | MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
144 |
145 | exec_maven() {
146 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
147 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
148 | }
149 |
150 | if [ -d "$MAVEN_HOME" ]; then
151 | verbose "found existing MAVEN_HOME at $MAVEN_HOME"
152 | exec_maven "$@"
153 | fi
154 |
155 | case "${distributionUrl-}" in
156 | *?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
157 | *) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
158 | esac
159 |
160 | # prepare tmp dir
161 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
162 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
163 | trap clean HUP INT TERM EXIT
164 | else
165 | die "cannot create temp dir"
166 | fi
167 |
168 | mkdir -p -- "${MAVEN_HOME%/*}"
169 |
170 | # Download and Install Apache Maven
171 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
172 | verbose "Downloading from: $distributionUrl"
173 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
174 |
175 | # select .zip or .tar.gz
176 | if ! command -v unzip >/dev/null; then
177 | distributionUrl="${distributionUrl%.zip}.tar.gz"
178 | distributionUrlName="${distributionUrl##*/}"
179 | fi
180 |
181 | # verbose opt
182 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
183 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
184 |
185 | # normalize http auth
186 | case "${MVNW_PASSWORD:+has-password}" in
187 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
188 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
189 | esac
190 |
191 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
192 | verbose "Found wget ... using wget"
193 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
194 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
195 | verbose "Found curl ... using curl"
196 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
197 | elif set_java_home; then
198 | verbose "Falling back to use Java to download"
199 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
200 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
201 | cat >"$javaSource" <<-END
202 | public class Downloader extends java.net.Authenticator
203 | {
204 | protected java.net.PasswordAuthentication getPasswordAuthentication()
205 | {
206 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
207 | }
208 | public static void main( String[] args ) throws Exception
209 | {
210 | setDefault( new Downloader() );
211 | java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
212 | }
213 | }
214 | END
215 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java
216 | verbose " - Compiling Downloader.java ..."
217 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
218 | verbose " - Running Downloader.java ..."
219 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
220 | fi
221 |
222 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
223 | if [ -n "${distributionSha256Sum-}" ]; then
224 | distributionSha256Result=false
225 | if [ "$MVN_CMD" = mvnd.sh ]; then
226 | echo "Checksum validation is not supported for maven-mvnd." >&2
227 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
228 | exit 1
229 | elif command -v sha256sum >/dev/null; then
230 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then
231 | distributionSha256Result=true
232 | fi
233 | elif command -v shasum >/dev/null; then
234 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
235 | distributionSha256Result=true
236 | fi
237 | else
238 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
239 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
240 | exit 1
241 | fi
242 | if [ $distributionSha256Result = false ]; then
243 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
244 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
245 | exit 1
246 | fi
247 | fi
248 |
249 | # unzip and move
250 | if command -v unzip >/dev/null; then
251 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
252 | else
253 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
254 | fi
255 | printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
256 | mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
257 |
258 | clean || :
259 | exec_maven "$@"
260 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | <# : batch portion
2 | @REM ----------------------------------------------------------------------------
3 | @REM Licensed to the Apache Software Foundation (ASF) under one
4 | @REM or more contributor license agreements. See the NOTICE file
5 | @REM distributed with this work for additional information
6 | @REM regarding copyright ownership. The ASF licenses this file
7 | @REM to you under the Apache License, Version 2.0 (the
8 | @REM "License"); you may not use this file except in compliance
9 | @REM with the License. You may obtain a copy of the License at
10 | @REM
11 | @REM http://www.apache.org/licenses/LICENSE-2.0
12 | @REM
13 | @REM Unless required by applicable law or agreed to in writing,
14 | @REM software distributed under the License is distributed on an
15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | @REM KIND, either express or implied. See the License for the
17 | @REM specific language governing permissions and limitations
18 | @REM under the License.
19 | @REM ----------------------------------------------------------------------------
20 |
21 | @REM ----------------------------------------------------------------------------
22 | @REM Apache Maven Wrapper startup batch script, version 3.3.2
23 | @REM
24 | @REM Optional ENV vars
25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution
26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
28 | @REM ----------------------------------------------------------------------------
29 |
30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
31 | @SET __MVNW_CMD__=
32 | @SET __MVNW_ERROR__=
33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
34 | @SET PSModulePath=
35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
37 | )
38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
39 | @SET __MVNW_PSMODULEP_SAVE=
40 | @SET __MVNW_ARG0_NAME__=
41 | @SET MVNW_USERNAME=
42 | @SET MVNW_PASSWORD=
43 | @IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
44 | @echo Cannot start maven from wrapper >&2 && exit /b 1
45 | @GOTO :EOF
46 | : end batch / begin powershell #>
47 |
48 | $ErrorActionPreference = "Stop"
49 | if ($env:MVNW_VERBOSE -eq "true") {
50 | $VerbosePreference = "Continue"
51 | }
52 |
53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
55 | if (!$distributionUrl) {
56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
57 | }
58 |
59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
60 | "maven-mvnd-*" {
61 | $USE_MVND = $true
62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
63 | $MVN_CMD = "mvnd.cmd"
64 | break
65 | }
66 | default {
67 | $USE_MVND = $false
68 | $MVN_CMD = $script -replace '^mvnw','mvn'
69 | break
70 | }
71 | }
72 |
73 | # apply MVNW_REPOURL and calculate MAVEN_HOME
74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
75 | if ($env:MVNW_REPOURL) {
76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
78 | }
79 | $distributionUrlName = $distributionUrl -replace '^.*/',''
80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
82 | if ($env:MAVEN_USER_HOME) {
83 | $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
84 | }
85 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
86 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
87 |
88 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
89 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
90 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
91 | exit $?
92 | }
93 |
94 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
95 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
96 | }
97 |
98 | # prepare tmp dir
99 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
100 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
101 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
102 | trap {
103 | if ($TMP_DOWNLOAD_DIR.Exists) {
104 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
105 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
106 | }
107 | }
108 |
109 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
110 |
111 | # Download and Install Apache Maven
112 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
113 | Write-Verbose "Downloading from: $distributionUrl"
114 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
115 |
116 | $webclient = New-Object System.Net.WebClient
117 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
118 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
119 | }
120 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
121 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
122 |
123 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
124 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
125 | if ($distributionSha256Sum) {
126 | if ($USE_MVND) {
127 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
128 | }
129 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
130 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
131 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
132 | }
133 | }
134 |
135 | # unzip and move
136 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
137 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
138 | try {
139 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
140 | } catch {
141 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
142 | Write-Error "fail to move MAVEN_HOME"
143 | }
144 | } finally {
145 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
146 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
147 | }
148 |
149 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
150 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.tagger
6 | Tagger
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | Tagger
11 | https://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | junit
20 | junit
21 | 3.8.1
22 | test
23 |
24 |
25 |
26 | mysql
27 | mysql-connector-java
28 | 8.0.28
29 |
30 |
31 |
32 | org.json
33 | json
34 | 20230618
35 |
36 |
37 | org.jetbrains
38 | annotations
39 | RELEASE
40 | compile
41 |
42 |
43 |
44 |
45 |
46 |
47 | org.apache.maven.plugins
48 | maven-compiler-plugin
49 |
50 | 20
51 | 20
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/src/main/java/com/tagger/Changelog:
--------------------------------------------------------------------------------
1 | CHANGELOG FILE :
2 |
3 |
4 | Version History:
5 |
6 | Version 0.1 (Initial Development):
7 |
8 | Created the basic structure of the Tag Replacement Tool program.
9 | Implemented database connectivity to fetch MO names.
10 | Provided a simple GUI with a combo box to select MO names.
11 | Supported loading MO content from the database based on the selected MO name.
12 | Implemented basic tag replacement functionality for tags with content only.
13 | Version 0.2:
14 |
15 | Added support for tags with only names and no content during the replacement process.
16 | Updated the GUI to show a welcome heading on the MO name selection dialog.
17 | Improved validation and error handling for database connections.
18 | Enhanced the JSON configuration loading to handle errors more gracefully.
19 | Version 0.3:
20 |
21 | Refactored the code to use the MVC design pattern.
22 | Separated frontend (View) and business logic (Model) into different classes.
23 | Used lambda expressions and functional interfaces for event handling.
24 | Introduced a Controller class to manage interactions between Model and View.
25 | Implemented toolbar with "Open," "Save," "Load," "Help," and "About" buttons.
26 | Added "Help" and "About" dialogs to display relevant information to the user.
27 | Version 0.4:
28 |
29 | Enabled opening a specific website when the "Open" button is clicked.
30 | Supported saving and loading MO data to and from custom .trt files.
31 | Implemented custom dialog for tag replacement, including tag name, comments, and replacement text input.
32 | Introduced a separate final content window to display the processed MO content after replacement.
33 | Handled errors related to database connections and configuration file loading.
34 | Improved the GUI design for a better user experience.
35 | Version 0.5 (Upcoming Changes):
36 |
37 | Updated the TagReplacementToolConfig class to use properties file or environment variables for configuration.
38 | Added support for internationalization (i18n) and localization (l10n) for the user interface.
39 | Implemented data persistence to store processed MO content back into the database.
40 | Enhanced the GUI with keyboard shortcuts for important actions in the application.
41 | Included unit tests to ensure the correctness of the core functionality.
42 | Optimized database queries and handling of large datasets.
43 | Version 1.0 (Future Release):
44 |
45 | Finalized and polished the Tag Replacement Tool for production use.
46 | Documented the code and provided user documentation.
47 | Performed extensive testing and bug fixing for a stable release.
48 | Prepared for official deployment and distribution.
49 | Note: The version history provided here is just an example and can be modified based on the actual progress and updates of the project. The version numbers and features are subject to change as development continues.
--------------------------------------------------------------------------------
/src/main/java/com/tagger/DeveloperDoc:
--------------------------------------------------------------------------------
1 | Developer Docs
2 |
3 |
4 | Tag Replacement Tool Developer Documentation
5 |
6 | Introduction
7 |
8 | The Tag Replacement Tool is a Java desktop application designed to simplify the process of tag replacement in Managed Object (MO) content. This document provides a comprehensive guide for developers working on the application. It covers the architecture, classes, methods, and attributes used in the application.
9 |
10 | Architecture
11 |
12 | The Tag Replacement Tool follows the Model-View-Controller (MVC) design pattern to separate the concerns of data management, user interface, and application logic. The architecture consists of three main components:
13 |
14 | Model: Represents the data and business logic of the application. Includes classes related to database management and tag processing.
15 |
16 | View: Represents the user interface of the application. Includes classes related to GUI components and user interactions.
17 |
18 | Controller: Acts as an intermediary between the Model and View. Handles user input, invokes business logic, and updates the View accordingly.
19 |
20 | Architecture Diagram
21 |
22 | Package Structure
23 |
24 | The application is organized into the following packages:
25 |
26 | releasemvc: Contains the main class to launch the application.
27 |
28 | model: Contains classes related to the data model and database management.
29 |
30 | view: Contains classes related to the user interface and GUI components.
31 |
32 | controller: Contains classes related to the application's logic and user interactions.
33 |
34 | Class Details
35 |
36 | Model Package
37 |
38 | TagReplacementToolModel: Represents the data model of the application. Contains attributes to store database connection details and methods to handle database operations and tag processing.
39 |
40 | Attributes:
41 |
42 | DB_URL: String, the JDBC URL for the database connection.
43 | USER: String, the username for the database connection.
44 | PASS: String, the password for the database connection.
45 | DB_NAME: String, the name of the database to use.
46 | TABLE1_NAME: String, the name of the table containing MO names, content, and tags.
47 | TABLE2_NAME: String, the name of the table containing tag comments.
48 | Methods:
49 |
50 | connectToDatabase(): Establishes a connection to the database.
51 | getMoNames(): Retrieves an array of available MO names from the database.
52 | processMoContent(String moName): Processes the MO content for tag replacement.
53 | extractTags(String moContent): Extracts tags from the MO content.
54 | getTagName(String tag): Gets the tag name from the tag (handles tags with and without content).
55 | getTagComment(String tagName): Retrieves the tag comment from the database for a given tag name.
56 | replaceTag(String moName, String tagName, String replacement): Replaces a tag in the MO content with the provided replacement value.
57 | saveMoContent(String moName, String moContent): Saves the processed MO content back to the database.
58 | View Package
59 |
60 | TagReplacementToolView: Represents the user interface of the application. Contains GUI components and methods for UI interactions.
61 |
62 | Methods:
63 | createAndShowGUI(): Creates and displays the main application window.
64 | createToolBar(): Creates the toolbar with buttons and their action listeners.
65 | createInputPanel(): Creates the input panel with MO name selection and process button.
66 | createOutputPanel(): Creates the output panel to display the processed content.
67 | showHelpDialog(): Displays the "Help" dialog with additional information.
68 | showAboutDialog(): Displays the "About" dialog with version and author information.
69 | showInputDialogWithInfo(String message, String moName, String tagName, String tagComment): Displays the replacement dialog with tag information.
70 | showFinalContentWindow(String moContent): Displays the final processed MO content in a separate window.
71 | Controller Package
72 |
73 | TagReplacementToolController: Represents the controller of the application. Handles user interactions and updates the Model and View accordingly.
74 |
75 | Methods:
76 | attachEventListeners(): Attaches event listeners to GUI components.
77 | processMoContent(): Invokes the tag replacement process for the selected MO name.
78 | openWebsite(String url): Opens a website URL in the default web browser.
79 | saveData(): Saves the processed MO content to a custom ".trt" file.
80 | loadData(): Loads MO content from a ".trt" file.
81 | loadConfig(): Loads configuration settings from "trtconfig.json".
82 | Version History
83 |
84 | Refer to the version history section for a detailed list of updates made to the application.
85 |
86 | Conclusion
87 |
88 | The Tag Replacement Tool provides a structured and modular approach to tag replacement in Managed Object content. Developers can easily extend and modify the application to suit specific requirements. The MVC architecture ensures a clear separation of concerns and enhances code maintainability and scalability.
--------------------------------------------------------------------------------
/src/main/java/com/tagger/Readme:
--------------------------------------------------------------------------------
1 | Sure! Let's provide a detailed description of the Tag Replacement Tool application and its architecture:
2 |
3 | Tag Replacement Tool Application Description:
4 |
5 | The Tag Replacement Tool is a desktop application designed to help users perform tag replacement in MO (Managed Object) content. Managed Objects are entities managed by a network management system in telecommunications or network domains. These MOs often contain tags that need to be replaced with specific values, and the application simplifies this process.
6 |
7 | Application Features:
8 |
9 | GUI Interface: The application provides a user-friendly Graphical User Interface (GUI) for easy interaction with the users. It uses Swing, a Java GUI toolkit, to build the UI components.
10 |
11 | Database Integration: The application integrates with an external relational database to store and retrieve MO-related data. This database holds MO names, their content, and tag information.
12 |
13 | Tag Replacement: The main functionality of the application is to replace tags within MO content with user-defined values. Users can select an MO from a dropdown list, view its content, and replace tags interactively.
14 |
15 | Configurable Settings: The application loads configuration settings from a JSON file named "trtconfig.json." These settings include database credentials, table names, and other options, making the application flexible for different environments.
16 |
17 | File Operations: The application supports saving the processed MO content to custom ".trt" files and loading data from these files for future use.
18 |
19 | Help and About Dialogs: The application provides "Help" and "About" dialogs that display relevant information about the tool.
20 |
21 | Application Architecture:
22 |
23 | The Tag Replacement Tool follows the Model-View-Controller (MVC) architectural pattern, which separates the application into three main components:
24 |
25 | Model:
26 |
27 | The Model represents the data and business logic of the application. It encapsulates the interaction with the database and tag replacement operations.
28 | Key components:
29 | TagReplacementToolModel: Manages data related to MOs, tags, and processed content. It interacts with the database to fetch and update data.
30 | TagReplacementToolConfig: Handles loading configuration from "trtconfig.json."
31 | View:
32 |
33 | The View handles the user interface and presentation layer. It is responsible for displaying information to the user and capturing user inputs.
34 | Key components:
35 | TagReplacementToolView: Builds and manages the GUI components like combo boxes, buttons, text areas, and dialogs.
36 | Controller:
37 |
38 | The Controller acts as an intermediary between the Model and View. It facilitates communication and coordination between the two.
39 | Key components:
40 | TagReplacementToolController: Listens to user actions, processes user inputs, and triggers appropriate operations in the Model.
41 | Interaction Flow:
42 |
43 | When the application starts (TagReplacementToolApp), it initializes the Model (TagReplacementToolModel) and loads the configuration from "trtconfig.json" using TagReplacementToolConfig.
44 |
45 | The Model establishes a connection to the external database using the database credentials from the configuration.
46 |
47 | The Model retrieves a list of MO names from the database and populates the dropdown list in the View.
48 |
49 | When the user selects an MO from the dropdown list and clicks the "Process" button, the Controller (TagReplacementToolController) captures the event.
50 |
51 | The Controller communicates with the Model to fetch the MO content and extract tags from it.
52 |
53 | The Controller then interacts with the View to display the MO content and initiate the tag replacement process.
54 |
55 | For each tag, the Controller shows a replacement dialog (showInputDialogWithInfo) and takes the user's input for the replacement value.
56 |
57 | The Controller updates the Model with the user's input and performs tag replacement in the MO content.
58 |
59 | The Controller communicates with the View to display the final processed MO content in a separate window (showFinalContentWindow).
60 |
61 | The user can copy the final processed MO content to the clipboard or save it to a custom ".trt" file.
62 |
63 | Version History:
64 |
65 | Version 1.0:
66 |
67 | Basic application framework with MVC architecture.
68 | GUI interface with "Process," "Open," "Save," "Load," "Help," and "About" buttons.
69 | Tag replacement for MOs with tags containing both name and content.
70 | Version 1.1:
71 |
72 | Improved error handling and GUI feedback for database connection failures.
73 | Added "Welcome" heading on the MO name selection dialog.
74 | Refactored code for better organization and readability.
75 | Version 1.2:
76 |
77 | Enhanced getTagName method to handle tags with only name and no content.
78 | Version 1.3:
79 |
80 | Improved user experience by removing {# and } characters from tag names in the replacement dialog.
81 | Bug fix for tag replacement not working for tags with only name.
82 | Version 1.4:
83 |
84 | Shortened code and optimized loading of configuration settings from "trtconfig.json."
85 | Added extensive logging for debugging and error tracking.
86 | Please note that this version history is fictional and provided for illustrative purposes. In a real development scenario, each version would include detailed release notes, bug fixes, enhancements, and other relevant changes.
--------------------------------------------------------------------------------
/src/main/java/com/tagger/TagReplacementToolApp.java:
--------------------------------------------------------------------------------
1 | package com.tagger;
2 |
3 | import java.util.Vector;
4 | import javax.swing.SwingUtilities;
5 |
6 | public class TagReplacementToolApp {
7 | public static void main(String[] args) {
8 | SwingUtilities.invokeLater(() -> {
9 | TagReplacementToolConfig tc = new TagReplacementToolConfig();
10 | Vector vec = new Vector<>();
11 | tc.getClass().getDeclaredFields();
12 | for (var field : tc.getClass().getDeclaredFields()) {
13 | field.setAccessible(true);
14 | try { vec.add((String) field.get(tc));}
15 | catch (IllegalAccessException e) { e.printStackTrace();}
16 | }
17 | TagReplacementToolModel model = new TagReplacementToolModel(
18 | vec.get(1), vec.get(2), vec.get(3), vec.get(4), vec.get(5));
19 | TagReplacementToolView view = new TagReplacementToolView();
20 | new TagReplacementToolController(model, view);
21 | });
22 | }
23 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/TagReplacementToolConfig.java:
--------------------------------------------------------------------------------
1 | package com.tagger;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.FileReader;
5 | import java.io.IOException;
6 |
7 | import javax.swing.JOptionPane;
8 |
9 | import org.json.JSONObject;
10 | import org.json.JSONTokener;
11 |
12 | public class TagReplacementToolConfig {
13 |
14 | public TagReplacementToolConfig()
15 | {
16 | loadConfig();
17 | }
18 |
19 | static final String CONFIG_FILE_PATH = System.getProperty("user.dir") + "\\trtconfig.json";
20 |
21 | // Configuration variables (from trtconfig.json) - Replace with your own values
22 |
23 | private String DB_URL = "";
24 | private String USER = "";
25 | private String PASS = "";
26 | private String TABLE1_NAME = "";
27 | private String TABLE2_NAME = "";
28 |
29 | private void loadConfig() {
30 | try {
31 | String configData = readFile(CONFIG_FILE_PATH);
32 | JSONObject configJson = new JSONObject(new JSONTokener(configData));
33 |
34 | setDB_URL(configJson.getString("DB_URL"));
35 | setUSER(configJson.getString("USER"));
36 | setPASS(configJson.getString("PASS"));
37 | //DB_NAME = configJson.getString("DB_NAME");
38 | setTABLE1_NAME(configJson.getString("TABLE1_NAME"));
39 | setTABLE2_NAME(configJson.getString("TABLE2_NAME"));
40 | } catch (Exception ex) {
41 | ex.printStackTrace();
42 | JOptionPane.showMessageDialog(null, "Error loading configuration from " + CONFIG_FILE_PATH,
43 | "Error", JOptionPane.ERROR_MESSAGE);
44 | System.exit(1);
45 | }
46 | }
47 |
48 | private static String readFile(String filePath) throws IOException {
49 | StringBuilder content = new StringBuilder();
50 | try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
51 | String line;
52 | while ((line = reader.readLine()) != null) {
53 | content.append(line);
54 | }
55 | }
56 | return content.toString();
57 | }
58 |
59 | /**
60 | * @return the dB_URL
61 | */
62 | public String getDB_URL() {
63 | return DB_URL;
64 | }
65 |
66 | /**
67 | * @param dB_URL the dB_URL to set
68 | */
69 | public void setDB_URL(String dB_URL) {
70 | DB_URL = dB_URL;
71 | }
72 |
73 | /**
74 | * @return the uSER
75 | */
76 | public String getUSER() {
77 | return USER;
78 | }
79 |
80 | /**
81 | * @param uSER the uSER to set
82 | */
83 | public void setUSER(String uSER) {
84 | USER = uSER;
85 | }
86 |
87 | /**
88 | * @return the pASS
89 | */
90 | public String getPASS() {
91 | return PASS;
92 | }
93 |
94 | /**
95 | * @param pASS the pASS to set
96 | */
97 | public void setPASS(String pASS) {
98 | PASS = pASS;
99 | }
100 |
101 | /**
102 | * @return the tABLE1_NAME
103 | */
104 | public String getTABLE1_NAME() {
105 | return TABLE1_NAME;
106 | }
107 |
108 | /**
109 | * @param tABLE1_NAME the tABLE1_NAME to set
110 | */
111 | public void setTABLE1_NAME(String tABLE1_NAME) {
112 | TABLE1_NAME = tABLE1_NAME;
113 | }
114 |
115 | /**
116 | * @return the tABLE2_NAME
117 | */
118 | public String getTABLE2_NAME() {
119 | return TABLE2_NAME;
120 | }
121 |
122 | /**
123 | * @param tABLE2_NAME the tABLE2_NAME to set
124 | */
125 | public void setTABLE2_NAME(String tABLE2_NAME) {
126 | TABLE2_NAME = tABLE2_NAME;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/main/java/com/tagger/TagReplacementToolController.java:
--------------------------------------------------------------------------------
1 | package com.tagger;
2 |
3 | public class TagReplacementToolController {
4 | @SuppressWarnings("unused")
5 | private TagReplacementToolModel model;
6 | private TagReplacementToolView view;
7 |
8 | public TagReplacementToolController(TagReplacementToolModel model, TagReplacementToolView view) {
9 | this.model = model;
10 | this.view = view;
11 | initController();
12 | }
13 | private void initController() {
14 | // Attach event listeners and handle user interactions
15 | loadMoNames();
16 | }
17 | private void loadMoNames() {
18 | String[] moNames = TagReplacementToolModel.getMoNames();
19 | view.setMoNames(moNames);
20 | }
21 | // Other methods for handling events and updating the model and view
22 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/TagReplacementToolModel.java:
--------------------------------------------------------------------------------
1 | package com.tagger;
2 |
3 | import java.sql.*;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 | import java.util.regex.Matcher;
7 | import java.util.regex.Pattern;
8 |
9 | public class TagReplacementToolModel {
10 | static String DB_URL;
11 | static String USER;
12 | static String PASS;
13 | static String TABLE1_NAME;
14 | static String TABLE2_NAME;
15 |
16 |
17 | public TagReplacementToolModel(String dbUrl, String user, String pass, String table1, String table2) {
18 | TagReplacementToolModel.DB_URL = dbUrl;
19 | TagReplacementToolModel.USER = user;
20 | TagReplacementToolModel.PASS = pass;
21 | TagReplacementToolModel.TABLE1_NAME = table1;
22 | TagReplacementToolModel.TABLE2_NAME = table2;
23 | }
24 |
25 | // Create the tables if they don't exist
26 | static void createTables(Connection conn) throws SQLException {
27 | try (Statement stmt = conn.createStatement()) {
28 | String createTable1Query = "CREATE TABLE IF NOT EXISTS " + TABLE1_NAME + " (" +
29 | "mo_name TEXT PRIMARY KEY, " +
30 | "mo_content TEXT, " +
31 | "mo_tags TEXT)";
32 | stmt.execute(createTable1Query);
33 |
34 | String createTable2Query = "CREATE TABLE IF NOT EXISTS " + TABLE2_NAME + " (" +
35 | "mo_tags TEXT PRIMARY KEY, " +
36 | "tag_comment TEXT)";
37 | stmt.execute(createTable2Query);
38 | }
39 | }
40 |
41 | public static String[] getMoNames() {
42 | List moNameList = new ArrayList<>();
43 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
44 | Statement stmt = conn.createStatement();
45 | ResultSet rs = stmt.executeQuery("SELECT mo_name FROM " + TABLE1_NAME)) {
46 |
47 | while (rs.next()) {
48 | moNameList.add(rs.getString("mo_name"));
49 | }
50 | } catch (SQLException e) {
51 | TagReplacementToolView.showSQLErrorMessage(e);
52 | e.printStackTrace();
53 | }
54 | return moNameList.toArray(new String[0]);
55 | }
56 |
57 | public static boolean isMoNameExists(String moName) {
58 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
59 | PreparedStatement pstmt = conn.prepareStatement("SELECT mo_name FROM " + TABLE1_NAME + " WHERE mo_name = ?")) {
60 | pstmt.setString(1, moName);
61 | try (ResultSet rs = pstmt.executeQuery()) {
62 | return rs.next(); // Return true if a row with the given mo_name exists
63 | }
64 | } catch (SQLException e) {
65 | e.printStackTrace();
66 | }
67 | return false;
68 | }
69 |
70 | // Retrieve mo_content based on mo_name
71 | static String getMoContent(Connection conn, String moName) throws SQLException {
72 | String moContent = null;
73 | String query = "SELECT mo_content FROM " + TABLE1_NAME + " WHERE mo_name = ?";
74 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
75 | pstmt.setString(1, moName);
76 | try (ResultSet rs = pstmt.executeQuery()) {
77 | if (rs.next()) {
78 | moContent = rs.getString("mo_content");
79 | }
80 | }
81 | }
82 | return moContent;
83 | }
84 |
85 |
86 | // Get the tag name from the tag
87 | public static String getTagName(String tag) {
88 | // Check if the tag contains any content (anything after the space)
89 | int spaceIndex = tag.indexOf(' ');
90 | if (spaceIndex != -1) {
91 | // If the tag has content, extract the tag name
92 | return tag.substring(2, spaceIndex);
93 | } else {
94 | // If the tag has no content, return the entire tag without the {# and } characters
95 | return tag.substring(2, tag.length() - 1);
96 | }
97 | }
98 |
99 | static String getTagComment(Connection conn, String tagName) throws SQLException {
100 | String tagComment = null;
101 | String query = "SELECT tag_comment FROM " + TABLE2_NAME + " WHERE mo_tags = ?";
102 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
103 | pstmt.setString(1, tagName);
104 | try (ResultSet rs = pstmt.executeQuery()) {
105 | if (rs.next()) {
106 | tagComment = rs.getString("tag_comment");
107 | }
108 | }
109 | }
110 | return tagComment;
111 | }
112 |
113 | public static List extractTags(String moContent) {
114 | List tags = new ArrayList<>();
115 | Pattern pattern = Pattern.compile("\\{#(.*?)}");
116 | Matcher matcher = pattern.matcher(moContent);
117 | while (matcher.find()) {
118 | tags.add(matcher.group());
119 | }
120 | return tags;
121 | }
122 | // Other methods for database operations, e.g., retrieving mo_content, tags, tag comments, etc.
123 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/TagReplacementToolView.java:
--------------------------------------------------------------------------------
1 | package com.tagger;
2 |
3 | import javax.swing.*;
4 |
5 | import javax.swing.event.PopupMenuEvent;
6 | import javax.swing.event.PopupMenuListener;
7 |
8 |
9 | import java.awt.*;
10 | import java.awt.datatransfer.Clipboard;
11 | import java.awt.datatransfer.StringSelection;
12 | import java.io.BufferedReader;
13 | import java.io.File;
14 | import java.io.FileReader;
15 | import java.io.PrintWriter;
16 | import java.net.URI;
17 | import java.sql.Connection;
18 | import java.sql.DriverManager;
19 | import java.sql.SQLException;
20 | import java.util.List;
21 | import java.util.Objects;
22 |
23 |
24 | public class TagReplacementToolView {
25 | JFrame mainFrame;
26 | private JComboBox moNameComboBox;
27 | JTextArea outputArea;
28 |
29 | public TagReplacementToolView() {
30 | createAndShowGUI();
31 | }
32 |
33 | private void createAndShowGUI() {
34 | mainFrame = new JFrame("Tag Replacement Tool");
35 | mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
36 | mainFrame.setLayout(new BorderLayout());
37 |
38 | createToolBar();
39 | createInputPanel();
40 | createOutputPanel();
41 |
42 | mainFrame.pack();
43 | mainFrame.setLocationRelativeTo(null); // Center the window
44 | mainFrame.setVisible(true);
45 | }
46 |
47 |
48 | private void createToolBar() {
49 | JToolBar toolBar = new JToolBar();
50 | toolBar.setFloatable(false);
51 |
52 | JButton openButton = new JButton("Open URL");
53 | JButton saveButton = new JButton("Save");
54 | JButton loadButton = new JButton("Load");
55 | JButton refreshButton = new JButton("Refresh");
56 | toolBar.add(openButton);
57 | toolBar.add(saveButton);
58 | toolBar.add(loadButton);
59 | toolBar.add(refreshButton);
60 |
61 | JButton helpButton = new JButton("Help");
62 | toolBar.add(Box.createHorizontalGlue());
63 | toolBar.add(helpButton);
64 |
65 | JButton aboutButton = new JButton("About");
66 | toolBar.add(aboutButton);
67 |
68 | // Add action listeners for the buttons here if needed
69 |
70 | mainFrame.add(toolBar, BorderLayout.NORTH);
71 |
72 | helpButton.addActionListener(e -> showHelpDialog()); // Help button action
73 | aboutButton.addActionListener(e -> showAboutDialog());// About button action
74 | openButton.addActionListener(e -> openWebsite("https://google.com")); //Open button action
75 | saveButton.addActionListener(e -> saveData()); // Add ActionListener to the "Save" button
76 | loadButton.addActionListener(e -> loadData()); // Add ActionListener to the "Load" button
77 | refreshButton.addActionListener(e -> refreshData());
78 | }
79 |
80 | private void refreshData() {
81 | // Update the JComboBox with fresh data from the database
82 | moNameComboBox.removeAllItems();
83 | String[] moNames = TagReplacementToolModel.getMoNames();
84 | for (String moName : moNames) {
85 | outputArea.setText("Refreshing..");
86 | moNameComboBox.addItem(moName);
87 | }
88 | // Clear the output area
89 | outputArea.setText("");
90 | }
91 |
92 | private void saveData() {
93 | try {
94 | // Get the current state of the application data
95 | String moName = Objects.requireNonNull(moNameComboBox.getSelectedItem()).toString();
96 | String moContent = outputArea.getText();
97 |
98 | // Choose the save file location using JFileChooser with custom file filter
99 | JFileChooser fileChooser = new JFileChooser();
100 | fileChooser.setFileFilter(new TRTFileFilter());
101 |
102 | int returnValue = fileChooser.showSaveDialog(mainFrame);
103 |
104 | if (returnValue == JFileChooser.APPROVE_OPTION) {
105 | File selectedFile = fileChooser.getSelectedFile();
106 | if (!selectedFile.getAbsolutePath().toLowerCase().endsWith(".trt")) {
107 | selectedFile = new File(selectedFile.getAbsolutePath() + ".trt");
108 | }
109 |
110 | if (selectedFile.exists()) {
111 | // File already exists, ask for confirmation to overwrite
112 | int overwriteConfirmation = JOptionPane.showConfirmDialog(mainFrame,
113 | "The selected file already exists. Do you want to overwrite it?",
114 | "File Exists", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
115 |
116 | if (overwriteConfirmation == JOptionPane.NO_OPTION) {
117 | // User chose not to overwrite, return without saving
118 | return;
119 | }
120 | }
121 |
122 | // Write the data to the selected file in custom save file format
123 | try (PrintWriter writer = new PrintWriter(selectedFile)) {
124 | writer.println("MO_NAME:" + moName);
125 | writer.println("MO_CONTENT:");
126 | writer.println(moContent);
127 | writer.flush();
128 | }
129 |
130 | JOptionPane.showMessageDialog(mainFrame, "Data saved successfully!",
131 | "Save", JOptionPane.INFORMATION_MESSAGE);
132 | }
133 | } catch (Exception ex) {
134 | ex.printStackTrace();
135 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while saving the data.",
136 | "Error", JOptionPane.ERROR_MESSAGE);
137 | }
138 | }
139 |
140 | private void loadData() {
141 | try {
142 | // Choose the file to load data from using JFileChooser with custom file filter
143 | JFileChooser fileChooser = new JFileChooser();
144 | fileChooser.setFileFilter(new TRTFileFilter());
145 |
146 | int returnValue = fileChooser.showOpenDialog(mainFrame);
147 |
148 | if (returnValue == JFileChooser.APPROVE_OPTION) {
149 | File selectedFile = fileChooser.getSelectedFile();
150 |
151 | // Read the data from the selected file in custom save file format
152 | try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) {
153 | StringBuilder moContentBuilder = new StringBuilder();
154 | String line;
155 | boolean readingMoContent = false;
156 |
157 | while ((line = reader.readLine()) != null) {
158 | if (line.startsWith("MO_NAME:")) {
159 | moNameComboBox.setSelectedItem(line.substring(8));
160 | } else if (line.startsWith("MO_CONTENT:")) {
161 | readingMoContent = true;
162 | } else if (readingMoContent) {
163 | moContentBuilder.append(line).append("\n");
164 | }
165 | }
166 |
167 | // Set the loaded MO content to the output area
168 | outputArea.setText(moContentBuilder.toString());
169 |
170 | JOptionPane.showMessageDialog(mainFrame, "Data loaded successfully!",
171 | "Load", JOptionPane.INFORMATION_MESSAGE);
172 | }
173 | }
174 | } catch (Exception ex) {
175 | ex.printStackTrace();
176 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while loading the data.",
177 | "Error", JOptionPane.ERROR_MESSAGE);
178 | }
179 | }
180 |
181 | // Custom file filter for ".trt" files
182 | private static class TRTFileFilter extends javax.swing.filechooser.FileFilter {
183 | public boolean accept(File file) {
184 | return file.isDirectory() || file.getName().toLowerCase().endsWith(".trt");
185 | }
186 |
187 | public String getDescription() {
188 | return "Tag Replacement Tool Files (*.trt)";
189 | }
190 | }
191 |
192 | private void openWebsite(String url) {
193 | try {
194 | // Use Desktop to open the default web browser
195 | if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
196 | Desktop.getDesktop().browse(new URI(url));
197 | } else {
198 | JOptionPane.showMessageDialog(mainFrame, "Opening the default web browser is not supported on this platform.",
199 | "Error", JOptionPane.ERROR_MESSAGE);
200 | }
201 | } catch (Exception ex) {
202 | ex.printStackTrace();
203 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while trying to open the website.",
204 | "Error", JOptionPane.ERROR_MESSAGE);
205 | }
206 | }
207 |
208 | private static void showHelpDialog() {
209 | JOptionPane.showMessageDialog(null,
210 | "Help content goes here.",
211 | "Help",
212 | JOptionPane.INFORMATION_MESSAGE);
213 | }
214 |
215 | private static void showAboutDialog() {
216 | JOptionPane.showMessageDialog(null,
217 | "Tag Replacement Tool\nVersion 1.0\nAuthor: Amit Kumar Nandi",
218 | "About",
219 | JOptionPane.INFORMATION_MESSAGE);
220 | }
221 | private void createInputPanel() {
222 | JPanel inputPanel = new JPanel(new FlowLayout());
223 | JLabel moNameLabel = new JLabel("Select mo_name:");
224 | moNameComboBox = new JComboBox<>(TagReplacementToolModel.getMoNames());
225 | moNameComboBox.setEditable(true);
226 | JButton processButton = new JButton("Process");
227 | inputPanel.add(moNameLabel);
228 | inputPanel.add(moNameComboBox);
229 | inputPanel.add(processButton);
230 |
231 | // Add action listener for the "Process" button
232 | processButton.addActionListener(e -> processMoContent());
233 |
234 | mainFrame.add(inputPanel, BorderLayout.CENTER);
235 | }
236 |
237 | private void processMoContent() {
238 | String moName = getSelectedMoName();
239 | StringBuilder resultBuilder = new StringBuilder();
240 |
241 | // Check if the selected mo name exists in the database
242 | if (!TagReplacementToolModel.isMoNameExists(moName)) {
243 | JOptionPane.showMessageDialog(mainFrame, "The selected mo_name does not exist in the database.",
244 | "Error", JOptionPane.ERROR_MESSAGE);
245 | return;
246 | }
247 |
248 |
249 | try (Connection conn = DriverManager.getConnection(TagReplacementToolModel.DB_URL, TagReplacementToolModel.USER, TagReplacementToolModel.PASS)) {
250 | TagReplacementToolModel.createTables(conn);
251 | String moContent = TagReplacementToolModel.getMoContent(conn, moName);
252 | List tags = TagReplacementToolModel.extractTags(moContent);
253 |
254 | for (String tag : tags) {
255 | String tagName = TagReplacementToolModel.getTagName(tag);
256 | String tagComment = null;
257 | try {
258 | tagComment = TagReplacementToolModel.getTagComment(conn, tagName);
259 | } catch (Exception e) {
260 | // TODO Auto-generated catch block
261 | e.printStackTrace();
262 | }
263 | resultBuilder.append("Mo Name: ").append(moName).append("\n");
264 | resultBuilder.append("Tag Name: ").append(tagName).append("\n");
265 | resultBuilder.append("Tag Comment: ").append(tagComment).append("\n");
266 |
267 | String replacementText = showInputDialogWithInfo("Enter replacement text for the tag '" + tagName + "':",
268 | moName, tagName, tagComment);
269 |
270 | if (replacementText.equals("__ABORT__")) {
271 | break; // Abort tag replacement for this mo_name
272 | }
273 |
274 | moContent = moContent.replace(tag, replacementText);
275 | }
276 |
277 | showFinalContentWindow(moContent);
278 | outputArea.setText(resultBuilder.toString());
279 |
280 | } catch (SQLException se) {
281 | se.printStackTrace();
282 | }
283 | }
284 |
285 | private void createOutputPanel() {
286 | outputArea = new JTextArea(20, 50);
287 | outputArea.setEditable(false);
288 | outputArea.setFont(new Font("Monospaced", Font.BOLD, 14));
289 | JScrollPane outputScrollPane = new JScrollPane(outputArea);
290 | mainFrame.add(outputScrollPane, BorderLayout.SOUTH);
291 | }
292 |
293 |
294 | public void setMoNames(String[] moNames) {
295 | moNameComboBox.setModel(new DefaultComboBoxModel<>(moNames));
296 | }
297 |
298 | public String getSelectedMoName() {
299 | return Objects.requireNonNull(moNameComboBox.getSelectedItem()).toString();
300 | }
301 |
302 | // Implement the custom dialog logic here
303 | static String showInputDialogWithInfo(String message, String moName, String tagName, String tagComment) {
304 | JPanel panel = new JPanel(new GridLayout(0, 1));
305 | panel.add(new JLabel("Mo Name: " + moName));
306 | panel.add(new JLabel("Tag Name: " + tagName));
307 | panel.add(new JLabel("\nTag Comments: "));
308 |
309 | JTextArea commentArea = new JTextArea(tagComment);
310 | commentArea.setEditable(false);
311 | JScrollPane commentScrollPane = new JScrollPane(commentArea);
312 | panel.add(commentScrollPane);
313 | panel.add(new JLabel("\n\nReplacement: "));
314 | JTextField textField = new JTextField(20);
315 | panel.add(textField);
316 |
317 | JButton abortButton = new JButton("Abort");
318 | panel.add(abortButton);
319 |
320 | int result = JOptionPane.showOptionDialog(null, panel, message, JOptionPane.OK_CANCEL_OPTION,
321 | JOptionPane.PLAIN_MESSAGE, null, null, null);
322 |
323 | if (result == JOptionPane.OK_OPTION) {
324 | return textField.getText();
325 | } else if (result == JOptionPane.CANCEL_OPTION) {
326 | // Return a special value to indicate "Abort" button was clicked
327 | return "__ABORT__";
328 | } else {
329 | return "";
330 | }
331 | }
332 |
333 | // Implement the final content window logic here
334 | static void showFinalContentWindow(String moContent) {
335 | JFrame finalContentFrame = new JFrame("Final Content");
336 | finalContentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
337 | finalContentFrame.setLayout(new BorderLayout());
338 |
339 | // Final content panel
340 | JTextArea finalContentArea = new JTextArea(moContent);
341 | finalContentArea.setFont(new Font("Monospaced", Font.BOLD, 14));
342 | finalContentArea.setEditable(true);
343 | JScrollPane finalContentScrollPane = new JScrollPane(finalContentArea);
344 |
345 | // Add a popup menu to the final content area
346 | JPopupMenu popupMenu = new JPopupMenu();
347 | JMenuItem copyItem = new JMenuItem("Copy");
348 | JMenuItem editItem = new JMenuItem("Edit");
349 | popupMenu.add(copyItem);
350 | popupMenu.add(editItem);
351 |
352 | finalContentArea.setComponentPopupMenu(popupMenu);
353 |
354 | // "Copy" action to copy the content to the clipboard
355 | copyItem.addActionListener(e -> {
356 | StringSelection selection = new StringSelection(finalContentArea.getText());
357 | Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
358 | clipboard.setContents(selection, null);
359 | });
360 |
361 | // "Edit" action to enable editing of the content
362 | editItem.addActionListener(e -> finalContentArea.setEditable(true));
363 |
364 | // Disable editing when the popup menu is closed
365 | popupMenu.addPopupMenuListener(new PopupMenuListener() {
366 | @Override
367 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
368 | // Do nothing
369 | }
370 |
371 | @Override
372 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
373 | finalContentArea.setEditable(false);
374 | }
375 |
376 | @Override
377 | public void popupMenuCanceled(PopupMenuEvent e) {
378 | // Do nothing
379 | }
380 | });
381 |
382 | finalContentFrame.add(finalContentScrollPane, BorderLayout.CENTER);
383 | finalContentFrame.setPreferredSize(new Dimension(800, 600));
384 | finalContentFrame.pack();
385 | // Center the final content window on the screen
386 | finalContentFrame.setLocationRelativeTo(null);
387 | finalContentFrame.setVisible(true);
388 | }
389 |
390 | static void showSQLErrorMessage(Exception e)
391 | {
392 | JOptionPane.showMessageDialog(null,
393 | "Error connecting to the database: " + e.getMessage(),
394 | "Database Error", JOptionPane.ERROR_MESSAGE);
395 | e.printStackTrace();
396 | }
397 |
398 | // Other methods for handling GUI components, events, and dialogs
399 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/console/Driver.java:
--------------------------------------------------------------------------------
1 | package com.tagger.console;
2 |
3 | import java.awt.BorderLayout;
4 | import java.awt.Dimension;
5 | import java.awt.FlowLayout;
6 | import java.awt.Font;
7 | import java.awt.GridLayout;
8 | import java.awt.Toolkit;
9 | import java.awt.datatransfer.Clipboard;
10 | import java.awt.datatransfer.StringSelection;
11 | import java.security.MessageDigest;
12 | import java.security.NoSuchAlgorithmException;
13 | import java.sql.*;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 | import java.util.Scanner;
17 | import java.util.regex.Matcher;
18 | import java.util.regex.Pattern;
19 | import java.util.Date;
20 | import javax.swing.JButton;
21 | import javax.swing.JFrame;
22 | import javax.swing.JLabel;
23 | import javax.swing.JMenuItem;
24 | import javax.swing.JOptionPane;
25 | import javax.swing.JPanel;
26 | import javax.swing.JPopupMenu;
27 | import javax.swing.JScrollPane;
28 | import javax.swing.JTextArea;
29 | import javax.swing.JTextField;
30 | import javax.swing.event.PopupMenuEvent;
31 | import javax.swing.event.PopupMenuListener;
32 |
33 | public class Driver {
34 |
35 | // JDBC URL, database credentials, and table names
36 | static final String DB_URL = "jdbc:mysql://localhost/mydb";
37 | static final String USER = "root";
38 | static final String PASS = "";
39 | static final String TABLE1_NAME = "table1";
40 | static final String TABLE2_NAME = "table2";
41 |
42 | public static void main(String[] args) {
43 | createGUI();
44 | }
45 |
46 | private static void createGUI() {
47 | JFrame frame = new JFrame("Tag Replacement Tool");
48 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
49 | frame.setLayout(new BorderLayout());
50 |
51 | // Input panel
52 | JPanel inputPanel = new JPanel(new FlowLayout());
53 | JLabel moNameLabel = new JLabel("Enter mo_name:");
54 | JTextField moNameField = new JTextField(15);
55 | JButton processButton = new JButton("Process");
56 | inputPanel.add(moNameLabel);
57 | inputPanel.add(moNameField);
58 | inputPanel.add(processButton);
59 |
60 | // Output panel
61 | JTextArea outputArea = new JTextArea(20, 50);
62 | outputArea.setEditable(false);
63 | outputArea.setFont(new Font("Monospaced", Font.BOLD, 14));
64 | JScrollPane outputScrollPane = new JScrollPane(outputArea);
65 |
66 | frame.add(inputPanel, BorderLayout.NORTH);
67 | frame.add(outputScrollPane, BorderLayout.CENTER);
68 | frame.pack();
69 | frame.setVisible(true);
70 |
71 | // Button action listener
72 | processButton.addActionListener(e -> {
73 | String moName = moNameField.getText();
74 | String result = processMoContent(moName);
75 | outputArea.setText(result);
76 | });
77 | }
78 |
79 | private static String processMoContent(String moName) {
80 | StringBuilder resultBuilder = new StringBuilder();
81 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS)) {
82 | // Create the tables if they don't exist
83 | createTables(conn);
84 |
85 | // Retrieve mo_content based on mo_name
86 | String moContent = getMoContent(conn, moName);
87 |
88 | // Get the tags for the given mo_name and store them in a collection
89 | List tags = extractTags(moContent);
90 |
91 | // Process and replace tags in mo_content
92 | for (String tag : tags) {
93 | String tagName = getTagName(tag);
94 | String tagComment = getTagComment(conn, tagName);
95 | resultBuilder.append("Mo Name: ").append(moName).append("\n");
96 | resultBuilder.append("Tag Name: ").append(tagName).append("\n");
97 | resultBuilder.append("Tag Comment: ").append(tagComment).append("\n");
98 |
99 | // Get user input for the replacement text using a custom dialog
100 | String replacementText = showInputDialogWithInfo("Enter replacement text for the tag '" + tagName + "':",
101 | moName, tagName, tagComment);
102 |
103 | // Replace the tag with the user's input
104 | moContent = moContent.replace(tag, replacementText);
105 | }
106 |
107 | // Display the final content in a separate window
108 | showFinalContentWindow(moContent);
109 |
110 | } catch (SQLException se) {
111 | se.printStackTrace();
112 | }
113 |
114 | return resultBuilder.toString();
115 | }
116 |
117 | // Custom dialog to show tag information along with input field
118 | private static String showInputDialogWithInfo(String message, String moName, String tagName, String tagComment) {
119 | JPanel panel = new JPanel(new GridLayout(0, 1));
120 | panel.add(new JLabel("Mo Name: " + moName));
121 | panel.add(new JLabel("Tag Name: " + tagName));
122 | panel.add(new JLabel("\nTag Comments: "));
123 |
124 | JTextArea commentArea = new JTextArea(tagComment);
125 | commentArea.setEditable(false);
126 | JScrollPane commentScrollPane = new JScrollPane(commentArea);
127 | panel.add(commentScrollPane);
128 | panel.add(new JLabel("\n\nReplacement: "));
129 | JTextField textField = new JTextField(20);
130 | panel.add(textField);
131 |
132 | int result = JOptionPane.showOptionDialog(null, panel, message, JOptionPane.OK_CANCEL_OPTION,
133 | JOptionPane.PLAIN_MESSAGE, null, null, null);
134 |
135 | return (result == JOptionPane.OK_OPTION) ? textField.getText() : "";
136 | }
137 |
138 | private static void showFinalContentWindow(String moContent) {
139 | JFrame finalContentFrame = new JFrame("Final Content");
140 | finalContentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
141 | finalContentFrame.setLayout(new BorderLayout());
142 |
143 | // Final content panel
144 | JTextArea finalContentArea = new JTextArea(moContent);
145 | finalContentArea.setFont(new Font("Monospaced", Font.BOLD, 14));
146 | finalContentArea.setEditable(true);
147 | JScrollPane finalContentScrollPane = new JScrollPane(finalContentArea);
148 |
149 | // Add a popup menu to the final content area
150 | JPopupMenu popupMenu = new JPopupMenu();
151 | JMenuItem copyItem = new JMenuItem("Copy");
152 | JMenuItem editItem = new JMenuItem("Edit");
153 | popupMenu.add(copyItem);
154 | popupMenu.add(editItem);
155 |
156 | finalContentArea.setComponentPopupMenu(popupMenu);
157 |
158 | // "Copy" action to copy the content to the clipboard
159 | copyItem.addActionListener(e -> {
160 | StringSelection selection = new StringSelection(finalContentArea.getText());
161 | Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
162 | clipboard.setContents(selection, null);
163 | });
164 |
165 | // "Edit" action to enable editing of the content
166 | editItem.addActionListener(e -> finalContentArea.setEditable(true));
167 |
168 | // Disable editing when the popup menu is closed
169 | popupMenu.addPopupMenuListener(new PopupMenuListener() {
170 | @Override
171 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
172 | // Do nothing
173 | }
174 |
175 | @Override
176 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
177 | finalContentArea.setEditable(false);
178 | }
179 |
180 | @Override
181 | public void popupMenuCanceled(PopupMenuEvent e) {
182 | // Do nothing
183 | }
184 | });
185 |
186 | finalContentFrame.add(finalContentScrollPane, BorderLayout.CENTER);
187 | finalContentFrame.setPreferredSize(new Dimension(800, 600));
188 | finalContentFrame.pack();
189 | // Center the final content window on the screen
190 | finalContentFrame.setLocationRelativeTo(null);
191 | finalContentFrame.setVisible(true);
192 | }
193 |
194 |
195 | // Rest of the code remains unchanged
196 | // ...
197 | // ...
198 |
199 |
200 |
201 | // Create the tables if they don't exist
202 | private static void createTables(Connection conn) throws SQLException {
203 | try (Statement stmt = conn.createStatement()) {
204 | String createTable1Query = "CREATE TABLE IF NOT EXISTS " + TABLE1_NAME + " (" +
205 | "mo_name TEXT PRIMARY KEY, " +
206 | "mo_content TEXT, " +
207 | "mo_tags TEXT)";
208 | stmt.execute(createTable1Query);
209 |
210 | String createTable2Query = "CREATE TABLE IF NOT EXISTS " + TABLE2_NAME + " (" +
211 | "mo_tags TEXT PRIMARY KEY, " +
212 | "tag_comment TEXT)";
213 | stmt.execute(createTable2Query);
214 | }
215 | }
216 |
217 | // Retrieve mo_content based on mo_name
218 | private static String getMoContent(Connection conn, String moName) throws SQLException {
219 | String moContent = null;
220 | String query = "SELECT mo_content FROM " + TABLE1_NAME + " WHERE mo_name = ?";
221 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
222 | pstmt.setString(1, moName);
223 | try (ResultSet rs = pstmt.executeQuery()) {
224 | if (rs.next()) {
225 | moContent = rs.getString("mo_content");
226 | }
227 | }
228 | }
229 | return moContent;
230 | }
231 |
232 | // Extract tags from mo_content
233 | private static List extractTags(String moContent) {
234 | List tags = new ArrayList<>();
235 | Pattern pattern = Pattern.compile("\\{#(.*?)\\}");
236 | Matcher matcher = pattern.matcher(moContent);
237 | while (matcher.find()) {
238 | tags.add(matcher.group());
239 | }
240 | return tags;
241 | }
242 |
243 | // Get the tag name from the tag
244 | private static String getTagName(String tag) {
245 | // Assuming the tag format is {#tagname this is a tag}
246 | int start = tag.indexOf('#') + 1;
247 | int end = tag.indexOf(' ', start);
248 | return tag.substring(start, end);
249 | }
250 |
251 | // Get tag comment from table2
252 | private static String getTagComment(Connection conn, String tagName) throws SQLException {
253 | String tagComment = null;
254 | String query = "SELECT tag_comment FROM " + TABLE2_NAME + " WHERE mo_tags = ?";
255 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
256 | pstmt.setString(1, tagName);
257 | try (ResultSet rs = pstmt.executeQuery()) {
258 | if (rs.next()) {
259 | tagComment = rs.getString("tag_comment");
260 | }
261 | }
262 | }
263 | return tagComment;
264 | }
265 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/console/Driverv2.java:
--------------------------------------------------------------------------------
1 | package com.tagger.console;
2 |
3 | import java.awt.BorderLayout;
4 | import java.awt.Dimension;
5 | import java.awt.FlowLayout;
6 | import java.awt.Font;
7 | import java.awt.GridLayout;
8 | import java.awt.Toolkit;
9 | import java.awt.datatransfer.Clipboard;
10 | import java.awt.datatransfer.StringSelection;
11 | import java.security.MessageDigest;
12 | import java.security.NoSuchAlgorithmException;
13 | import java.sql.*;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 | import java.util.Objects;
17 | import java.util.Scanner;
18 | import java.util.regex.Matcher;
19 | import java.util.regex.Pattern;
20 | import java.util.Date;
21 |
22 | import javax.swing.Box;
23 | import javax.swing.JButton;
24 | import javax.swing.JComboBox;
25 | import javax.swing.JFrame;
26 | import javax.swing.JLabel;
27 | import javax.swing.JMenuItem;
28 | import javax.swing.JOptionPane;
29 | import javax.swing.JPanel;
30 | import javax.swing.JPopupMenu;
31 | import javax.swing.JScrollPane;
32 | import javax.swing.JTextArea;
33 | import javax.swing.JTextField;
34 | import javax.swing.JToolBar;
35 | import javax.swing.event.PopupMenuEvent;
36 | import javax.swing.event.PopupMenuListener;
37 |
38 | public class Driverv2 {
39 |
40 | static final String DB_NAME = "mydb";
41 |
42 | // JDBC URL, database credentials, and table names
43 | static final String DB_URL = "jdbc:mysql://localhost/"+DB_NAME;
44 | static final String USER = "root";
45 | static final String PASS = "";
46 | static final String TABLE1_NAME = "table1";
47 | static final String TABLE2_NAME = "table2";
48 |
49 | public static void main(String[] args) {
50 | createGUI();
51 | }
52 |
53 | private static void createGUI() {
54 | JFrame frame = new JFrame("Tag Replacement Tool");
55 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
56 | frame.setLayout(new BorderLayout());
57 |
58 | // Create the toolbar
59 | JToolBar toolBar = new JToolBar();
60 | toolBar.setFloatable(false);
61 |
62 | // File section in the toolbar
63 | JButton openButton = new JButton("Open");
64 | JButton saveButton = new JButton("Save");
65 | toolBar.add(openButton);
66 | toolBar.add(saveButton);
67 |
68 | // Help section in the toolbar
69 | JButton helpButton = new JButton("Help");
70 | toolBar.add(Box.createHorizontalGlue());
71 | toolBar.add(helpButton);
72 |
73 | // About section in the toolbar
74 | JButton aboutButton = new JButton("About");
75 | toolBar.add(aboutButton);
76 |
77 | // Input panel
78 | JPanel inputPanel = new JPanel(new FlowLayout());
79 | JLabel moNameLabel = new JLabel("Select mo_name:");
80 | JComboBox moNameComboBox = new JComboBox<>(getMoNames());
81 | moNameComboBox.setEditable(true); // Allow custom text input
82 | JButton processButton = new JButton("Process");
83 | inputPanel.add(moNameLabel);
84 | inputPanel.add(moNameComboBox);
85 | inputPanel.add(processButton);
86 |
87 | // Output panel
88 | JTextArea outputArea = new JTextArea(20, 50);
89 | outputArea.setEditable(false);
90 | outputArea.setFont(new Font("Monospaced", Font.BOLD, 14));
91 | JScrollPane outputScrollPane = new JScrollPane(outputArea);
92 |
93 | frame.add(toolBar, BorderLayout.NORTH);
94 | frame.add(inputPanel, BorderLayout.CENTER);
95 | frame.add(outputScrollPane, BorderLayout.SOUTH);
96 | frame.pack();
97 | frame.setVisible(true);
98 |
99 | // Button action listener
100 | processButton.addActionListener(e -> {
101 | String moName = Objects.requireNonNull(moNameComboBox.getSelectedItem()).toString();
102 | String result = processMoContent(moName);
103 | outputArea.setText(result);
104 | });
105 |
106 | // Help button action
107 | helpButton.addActionListener(e -> showHelpDialog());
108 |
109 | // About button action
110 | aboutButton.addActionListener(e -> showAboutDialog());
111 | }
112 |
113 | private static void showHelpDialog() {
114 | JOptionPane.showMessageDialog(null,
115 | "Help content goes here.",
116 | "Help",
117 | JOptionPane.INFORMATION_MESSAGE);
118 | }
119 |
120 | private static void showAboutDialog() {
121 | JOptionPane.showMessageDialog(null,
122 | "Tag Replacement Tool\nVersion 1.0\nAuthor: Your Name",
123 | "About",
124 | JOptionPane.INFORMATION_MESSAGE);
125 | }
126 |
127 | private static String[] getMoNames() {
128 | List moNameList = new ArrayList<>();
129 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
130 | Statement stmt = conn.createStatement();
131 | ResultSet rs = stmt.executeQuery("SELECT mo_name FROM " + TABLE1_NAME)) {
132 |
133 | while (rs.next()) {
134 | moNameList.add(rs.getString("mo_name"));
135 | }
136 | } catch (SQLException e) {
137 | e.printStackTrace();
138 | }
139 | return moNameList.toArray(new String[0]);
140 | }
141 |
142 |
143 | private static String processMoContent(String moName) {
144 | StringBuilder resultBuilder = new StringBuilder();
145 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS)) {
146 | // Create the tables if they don't exist
147 | createTables(conn);
148 |
149 | // Retrieve mo_content based on mo_name
150 | String moContent = getMoContent(conn, moName);
151 |
152 | // Get the tags for the given mo_name and store them in a collection
153 | List tags = extractTags(moContent);
154 |
155 | // Process and replace tags in mo_content
156 | for (String tag : tags) {
157 | String tagName = getTagName(tag);
158 | String tagComment = getTagComment(conn, tagName);
159 | resultBuilder.append("Mo Name: ").append(moName).append("\n");
160 | resultBuilder.append("Tag Name: ").append(tagName).append("\n");
161 | resultBuilder.append("Tag Comment: ").append(tagComment).append("\n");
162 |
163 | // Get user input for the replacement text using a custom dialog
164 | String replacementText = showInputDialogWithInfo("Enter replacement text for the tag '" + tagName + "':",
165 | moName, tagName, tagComment);
166 |
167 | // Replace the tag with the user's input
168 | moContent = moContent.replace(tag, replacementText);
169 | }
170 |
171 | // Display the final content in a separate window
172 | showFinalContentWindow(moContent);
173 |
174 | } catch (SQLException se) {
175 | se.printStackTrace();
176 | }
177 |
178 | return resultBuilder.toString();
179 | }
180 |
181 | // Custom dialog to show tag information along with input field
182 | private static String showInputDialogWithInfo(String message, String moName, String tagName, String tagComment) {
183 | JPanel panel = new JPanel(new GridLayout(0, 1));
184 | panel.add(new JLabel("Mo Name: " + moName));
185 | panel.add(new JLabel("Tag Name: " + tagName));
186 | panel.add(new JLabel("\nTag Comments: "));
187 |
188 | JTextArea commentArea = new JTextArea(tagComment);
189 | commentArea.setEditable(false);
190 | JScrollPane commentScrollPane = new JScrollPane(commentArea);
191 | panel.add(commentScrollPane);
192 | panel.add(new JLabel("\n\nReplacement: "));
193 | JTextField textField = new JTextField(20);
194 | panel.add(textField);
195 |
196 | JButton abortButton = new JButton("Abort");
197 | panel.add(abortButton);
198 |
199 | int result = JOptionPane.showOptionDialog(null, panel, message, JOptionPane.OK_CANCEL_OPTION,
200 | JOptionPane.PLAIN_MESSAGE, null, null, null);
201 |
202 | if (result == JOptionPane.OK_OPTION) {
203 | return textField.getText();
204 | } else if (result == JOptionPane.CANCEL_OPTION) {
205 | // Return a special value to indicate "Abort" button was clicked
206 | return "__ABORT__";
207 | } else {
208 | return "";
209 | }
210 | }
211 |
212 | private static void showFinalContentWindow(String moContent) {
213 | JFrame finalContentFrame = new JFrame("Final Content");
214 | finalContentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
215 | finalContentFrame.setLayout(new BorderLayout());
216 |
217 | // Final content panel
218 | JTextArea finalContentArea = new JTextArea(moContent);
219 | finalContentArea.setFont(new Font("Monospaced", Font.BOLD, 14));
220 | finalContentArea.setEditable(true);
221 | JScrollPane finalContentScrollPane = new JScrollPane(finalContentArea);
222 |
223 | // Add a popup menu to the final content area
224 | JPopupMenu popupMenu = new JPopupMenu();
225 | JMenuItem copyItem = new JMenuItem("Copy");
226 | JMenuItem editItem = new JMenuItem("Edit");
227 | popupMenu.add(copyItem);
228 | popupMenu.add(editItem);
229 |
230 | finalContentArea.setComponentPopupMenu(popupMenu);
231 |
232 | // "Copy" action to copy the content to the clipboard
233 | copyItem.addActionListener(e -> {
234 | StringSelection selection = new StringSelection(finalContentArea.getText());
235 | Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
236 | clipboard.setContents(selection, null);
237 | });
238 |
239 | // "Edit" action to enable editing of the content
240 | editItem.addActionListener(e -> finalContentArea.setEditable(true));
241 |
242 | // Disable editing when the popup menu is closed
243 | popupMenu.addPopupMenuListener(new PopupMenuListener() {
244 | @Override
245 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
246 | // Do nothing
247 | }
248 |
249 | @Override
250 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
251 | finalContentArea.setEditable(false);
252 | }
253 |
254 | @Override
255 | public void popupMenuCanceled(PopupMenuEvent e) {
256 | // Do nothing
257 | }
258 | });
259 |
260 | finalContentFrame.add(finalContentScrollPane, BorderLayout.CENTER);
261 | finalContentFrame.setPreferredSize(new Dimension(800, 600));
262 | finalContentFrame.pack();
263 | // Center the final content window on the screen
264 | finalContentFrame.setLocationRelativeTo(null);
265 | finalContentFrame.setVisible(true);
266 | }
267 |
268 |
269 | // Rest of the code remains unchanged
270 | // ...
271 | // ...
272 |
273 |
274 |
275 | // Create the tables if they don't exist
276 | private static void createTables(Connection conn) throws SQLException {
277 | try (Statement stmt = conn.createStatement()) {
278 | String createTable1Query = "CREATE TABLE IF NOT EXISTS " + TABLE1_NAME + " (" +
279 | "mo_name TEXT PRIMARY KEY, " +
280 | "mo_content TEXT, " +
281 | "mo_tags TEXT)";
282 | stmt.execute(createTable1Query);
283 |
284 | String createTable2Query = "CREATE TABLE IF NOT EXISTS " + TABLE2_NAME + " (" +
285 | "mo_tags TEXT PRIMARY KEY, " +
286 | "tag_comment TEXT)";
287 | stmt.execute(createTable2Query);
288 | }
289 | }
290 |
291 | // Retrieve mo_content based on mo_name
292 | private static String getMoContent(Connection conn, String moName) throws SQLException {
293 | String moContent = null;
294 | String query = "SELECT mo_content FROM " + TABLE1_NAME + " WHERE mo_name = ?";
295 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
296 | pstmt.setString(1, moName);
297 | try (ResultSet rs = pstmt.executeQuery()) {
298 | if (rs.next()) {
299 | moContent = rs.getString("mo_content");
300 | }
301 | }
302 | }
303 | return moContent;
304 | }
305 |
306 | // Extract tags from mo_content
307 | private static List extractTags(String moContent) {
308 | List tags = new ArrayList<>();
309 | Pattern pattern = Pattern.compile("\\{#(.*?)\\}");
310 | Matcher matcher = pattern.matcher(moContent);
311 | while (matcher.find()) {
312 | tags.add(matcher.group());
313 | }
314 | return tags;
315 | }
316 |
317 | // Get the tag name from the tag
318 | private static String getTagName(String tag) {
319 | // Assuming the tag format is {#tagname this is a tag}
320 | int start = tag.indexOf('#') + 1;
321 | int end = tag.indexOf(' ', start);
322 | return tag.substring(start, end);
323 | }
324 |
325 | // Get tag comment from table2
326 | private static String getTagComment(Connection conn, String tagName) throws SQLException {
327 | String tagComment = null;
328 | String query = "SELECT tag_comment FROM " + TABLE2_NAME + " WHERE mo_tags = ?";
329 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
330 | pstmt.setString(1, tagName);
331 | try (ResultSet rs = pstmt.executeQuery()) {
332 | if (rs.next()) {
333 | tagComment = rs.getString("tag_comment");
334 | }
335 | }
336 | }
337 | return tagComment;
338 | }
339 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/console/TagReplacementTool.java:
--------------------------------------------------------------------------------
1 | package com.tagger.console;
2 |
3 | import javax.swing.*;
4 | import javax.swing.event.PopupMenuEvent;
5 | import javax.swing.event.PopupMenuListener;
6 |
7 | import java.awt.*;
8 | import java.awt.datatransfer.Clipboard;
9 | import java.awt.datatransfer.StringSelection;
10 | import java.sql.*;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 | import java.util.regex.Matcher;
14 | import java.util.regex.Pattern;
15 |
16 | public class TagReplacementTool {
17 |
18 | static final String DB_NAME = "mydb";
19 |
20 | // JDBC URL, database credentials, and table names
21 | static final String DB_URL = "jdbc:mysql://localhost/"+DB_NAME;
22 | private static final String USER = "root";
23 | private static final String PASS = "";
24 | private static final String TABLE1_NAME = "table1";
25 | private static final String TABLE2_NAME = "table2";
26 |
27 | private JFrame mainFrame;
28 | private JComboBox moNameComboBox;
29 | private JTextArea outputArea;
30 |
31 | public static void main(String[] args) {
32 | SwingUtilities.invokeLater(() -> {
33 | TagReplacementTool tool = new TagReplacementTool();
34 | tool.createAndShowGUI();
35 | });
36 | }
37 |
38 | private void createAndShowGUI() {
39 | mainFrame = new JFrame("Tag Replacement Tool");
40 | mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
41 | mainFrame.setLayout(new BorderLayout());
42 |
43 | createToolBar();
44 | createInputPanel();
45 | createOutputPanel();
46 |
47 | mainFrame.pack();
48 | mainFrame.setLocationRelativeTo(null); // Center the window
49 | mainFrame.setVisible(true);
50 | }
51 |
52 | private void createToolBar() {
53 | JToolBar toolBar = new JToolBar();
54 | toolBar.setFloatable(false);
55 |
56 | JButton openButton = new JButton("Open");
57 | JButton saveButton = new JButton("Save");
58 | toolBar.add(openButton);
59 | toolBar.add(saveButton);
60 |
61 | JButton helpButton = new JButton("Help");
62 | toolBar.add(Box.createHorizontalGlue());
63 | toolBar.add(helpButton);
64 |
65 | JButton aboutButton = new JButton("About");
66 | toolBar.add(aboutButton);
67 |
68 | // Add action listeners for the buttons here if needed
69 |
70 | mainFrame.add(toolBar, BorderLayout.NORTH);
71 |
72 | // Help button action
73 | helpButton.addActionListener(e -> showHelpDialog());
74 |
75 | // About button action
76 | aboutButton.addActionListener(e -> showAboutDialog());
77 | }
78 |
79 | private static void showHelpDialog() {
80 | JOptionPane.showMessageDialog(null,
81 | "Help content goes here.",
82 | "Help",
83 | JOptionPane.INFORMATION_MESSAGE);
84 | }
85 |
86 | private static void showAboutDialog() {
87 | JOptionPane.showMessageDialog(null,
88 | "Tag Replacement Tool\nVersion 1.0\nAuthor: Your Name",
89 | "About",
90 | JOptionPane.INFORMATION_MESSAGE);
91 | }
92 |
93 | private void createInputPanel() {
94 | JPanel inputPanel = new JPanel(new FlowLayout());
95 | JLabel moNameLabel = new JLabel("Select mo_name:");
96 | moNameComboBox = new JComboBox<>(getMoNames());
97 | moNameComboBox.setEditable(true);
98 | JButton processButton = new JButton("Process");
99 | inputPanel.add(moNameLabel);
100 | inputPanel.add(moNameComboBox);
101 | inputPanel.add(processButton);
102 |
103 | // Add action listener for the "Process" button
104 | processButton.addActionListener(e -> processMoContent());
105 |
106 | mainFrame.add(inputPanel, BorderLayout.CENTER);
107 | }
108 |
109 | private void createOutputPanel() {
110 | outputArea = new JTextArea(20, 50);
111 | outputArea.setEditable(false);
112 | outputArea.setFont(new Font("Monospaced", Font.BOLD, 14));
113 | JScrollPane outputScrollPane = new JScrollPane(outputArea);
114 | mainFrame.add(outputScrollPane, BorderLayout.SOUTH);
115 | }
116 |
117 | private String[] getMoNames() {
118 | List moNameList = new ArrayList<>();
119 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
120 | Statement stmt = conn.createStatement();
121 | ResultSet rs = stmt.executeQuery("SELECT mo_name FROM " + TABLE1_NAME)) {
122 |
123 | while (rs.next()) {
124 | moNameList.add(rs.getString("mo_name"));
125 | }
126 | } catch (SQLException e) {
127 | e.printStackTrace();
128 | }
129 | return moNameList.toArray(new String[0]);
130 | }
131 |
132 | private void processMoContent() {
133 | String moName = moNameComboBox.getSelectedItem().toString();
134 | StringBuilder resultBuilder = new StringBuilder();
135 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS)) {
136 | createTables(conn);
137 | String moContent = getMoContent(conn, moName);
138 | List tags = extractTags(moContent);
139 |
140 | for (String tag : tags) {
141 | String tagName = getTagName(tag);
142 | String tagComment = getTagComment(conn, tagName);
143 | resultBuilder.append("Mo Name: ").append(moName).append("\n");
144 | resultBuilder.append("Tag Name: ").append(tagName).append("\n");
145 | resultBuilder.append("Tag Comment: ").append(tagComment).append("\n");
146 |
147 | String replacementText = showInputDialogWithInfo("Enter replacement text for the tag '" + tagName + "':",
148 | moName, tagName, tagComment);
149 |
150 | if (replacementText.equals("__ABORT__")) {
151 | break; // Abort tag replacement for this mo_name
152 | }
153 |
154 | moContent = moContent.replace(tag, replacementText);
155 | }
156 |
157 | showFinalContentWindow(moContent);
158 | outputArea.setText(resultBuilder.toString());
159 |
160 | } catch (SQLException se) {
161 | se.printStackTrace();
162 | }
163 | }
164 |
165 | // Implement the custom dialog logic here
166 | private static String showInputDialogWithInfo(String message, String moName, String tagName, String tagComment) {
167 | JPanel panel = new JPanel(new GridLayout(0, 1));
168 | panel.add(new JLabel("Mo Name: " + moName));
169 | panel.add(new JLabel("Tag Name: " + tagName));
170 | panel.add(new JLabel("\nTag Comments: "));
171 |
172 | JTextArea commentArea = new JTextArea(tagComment);
173 | commentArea.setEditable(false);
174 | JScrollPane commentScrollPane = new JScrollPane(commentArea);
175 | panel.add(commentScrollPane);
176 | panel.add(new JLabel("\n\nReplacement: "));
177 | JTextField textField = new JTextField(20);
178 | panel.add(textField);
179 |
180 | JButton abortButton = new JButton("Abort");
181 | panel.add(abortButton);
182 |
183 | int result = JOptionPane.showOptionDialog(null, panel, message, JOptionPane.OK_CANCEL_OPTION,
184 | JOptionPane.PLAIN_MESSAGE, null, null, null);
185 |
186 | if (result == JOptionPane.OK_OPTION) {
187 | return textField.getText();
188 | } else if (result == JOptionPane.CANCEL_OPTION) {
189 | // Return a special value to indicate "Abort" button was clicked
190 | return "__ABORT__";
191 | } else {
192 | return "";
193 | }
194 | }
195 |
196 | // Implement the final content window logic here
197 | private static void showFinalContentWindow(String moContent) {
198 | JFrame finalContentFrame = new JFrame("Final Content");
199 | finalContentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
200 | finalContentFrame.setLayout(new BorderLayout());
201 |
202 | // Final content panel
203 | JTextArea finalContentArea = new JTextArea(moContent);
204 | finalContentArea.setFont(new Font("Monospaced", Font.BOLD, 14));
205 | finalContentArea.setEditable(true);
206 | JScrollPane finalContentScrollPane = new JScrollPane(finalContentArea);
207 |
208 | // Add a popup menu to the final content area
209 | JPopupMenu popupMenu = new JPopupMenu();
210 | JMenuItem copyItem = new JMenuItem("Copy");
211 | JMenuItem editItem = new JMenuItem("Edit");
212 | popupMenu.add(copyItem);
213 | popupMenu.add(editItem);
214 |
215 | finalContentArea.setComponentPopupMenu(popupMenu);
216 |
217 | // "Copy" action to copy the content to the clipboard
218 | copyItem.addActionListener(e -> {
219 | StringSelection selection = new StringSelection(finalContentArea.getText());
220 | Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
221 | clipboard.setContents(selection, null);
222 | });
223 |
224 | // "Edit" action to enable editing of the content
225 | editItem.addActionListener(e -> finalContentArea.setEditable(true));
226 |
227 | // Disable editing when the popup menu is closed
228 | popupMenu.addPopupMenuListener(new PopupMenuListener() {
229 | @Override
230 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
231 | // Do nothing
232 | }
233 |
234 | @Override
235 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
236 | finalContentArea.setEditable(false);
237 | }
238 |
239 | @Override
240 | public void popupMenuCanceled(PopupMenuEvent e) {
241 | // Do nothing
242 | }
243 | });
244 |
245 | finalContentFrame.add(finalContentScrollPane, BorderLayout.CENTER);
246 | finalContentFrame.setPreferredSize(new Dimension(800, 600));
247 | finalContentFrame.pack();
248 | // Center the final content window on the screen
249 | finalContentFrame.setLocationRelativeTo(null);
250 | finalContentFrame.setVisible(true);
251 | }
252 |
253 | // Create the tables if they don't exist
254 | private static void createTables(Connection conn) throws SQLException {
255 | try (Statement stmt = conn.createStatement()) {
256 | String createTable1Query = "CREATE TABLE IF NOT EXISTS " + TABLE1_NAME + " (" +
257 | "mo_name TEXT PRIMARY KEY, " +
258 | "mo_content TEXT, " +
259 | "mo_tags TEXT)";
260 | stmt.execute(createTable1Query);
261 |
262 | String createTable2Query = "CREATE TABLE IF NOT EXISTS " + TABLE2_NAME + " (" +
263 | "mo_tags TEXT PRIMARY KEY, " +
264 | "tag_comment TEXT)";
265 | stmt.execute(createTable2Query);
266 | }
267 | }
268 |
269 | // Retrieve mo_content based on mo_name
270 | private static String getMoContent(Connection conn, String moName) throws SQLException {
271 | String moContent = null;
272 | String query = "SELECT mo_content FROM " + TABLE1_NAME + " WHERE mo_name = ?";
273 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
274 | pstmt.setString(1, moName);
275 | try (ResultSet rs = pstmt.executeQuery()) {
276 | if (rs.next()) {
277 | moContent = rs.getString("mo_content");
278 | }
279 | }
280 | }
281 | return moContent;
282 | }
283 |
284 | // Extract tags from mo_content
285 | private static List extractTags(String moContent) {
286 | List tags = new ArrayList<>();
287 | Pattern pattern = Pattern.compile("\\{#(.*?)\\}");
288 | Matcher matcher = pattern.matcher(moContent);
289 | while (matcher.find()) {
290 | tags.add(matcher.group());
291 | }
292 | return tags;
293 | }
294 |
295 | // Get the tag name from the tag
296 | private static String getTagName(String tag) {
297 | // Assuming the tag format is {#tagname this is a tag}
298 | int start = tag.indexOf('#') + 1;
299 | int end = tag.indexOf(' ', start);
300 | return tag.substring(start, end);
301 | }
302 |
303 | private static String getTagComment(Connection conn, String tagName) throws SQLException {
304 | String tagComment = null;
305 | String query = "SELECT tag_comment FROM " + TABLE2_NAME + " WHERE mo_tags = ?";
306 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
307 | pstmt.setString(1, tagName);
308 | try (ResultSet rs = pstmt.executeQuery()) {
309 | if (rs.next()) {
310 | tagComment = rs.getString("tag_comment");
311 | }
312 | }
313 | }
314 | return tagComment;
315 | }
316 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/console/TagReplacementToolv2.java:
--------------------------------------------------------------------------------
1 | package com.tagger.console;
2 |
3 | import javax.swing.*;
4 | import javax.swing.event.PopupMenuEvent;
5 | import javax.swing.event.PopupMenuListener;
6 |
7 | import java.awt.*;
8 | import java.awt.datatransfer.Clipboard;
9 | import java.awt.datatransfer.StringSelection;
10 | import java.io.BufferedReader;
11 | import java.io.File;
12 | import java.io.FileReader;
13 | import java.io.PrintWriter;
14 | import java.net.URI;
15 | import java.sql.*;
16 | import java.util.ArrayList;
17 | import java.util.List;
18 | import java.util.Objects;
19 | import java.util.regex.Matcher;
20 | import java.util.regex.Pattern;
21 |
22 | public class TagReplacementToolv2 {
23 |
24 | static final String DB_NAME = "mydb";
25 |
26 | // JDBC URL, database credentials, and table names
27 | static final String DB_URL = "jdbc:mysql://localhost/"+DB_NAME;
28 | private static final String USER = "root";
29 | private static final String PASS = "";
30 | private static final String TABLE1_NAME = "table1";
31 | private static final String TABLE2_NAME = "table2";
32 |
33 | private JFrame mainFrame;
34 | private JComboBox moNameComboBox;
35 | private JTextArea outputArea;
36 |
37 | public static void main(String[] args) {
38 | SwingUtilities.invokeLater(() -> {
39 | TagReplacementToolv2 tool = new TagReplacementToolv2();
40 | tool.createAndShowGUI();
41 | });
42 | }
43 |
44 | void createAndShowGUI() {
45 | mainFrame = new JFrame("Tag Replacement Tool");
46 | mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
47 | mainFrame.setLayout(new BorderLayout());
48 |
49 | createToolBar();
50 | createInputPanel();
51 | createOutputPanel();
52 |
53 | mainFrame.pack();
54 | mainFrame.setLocationRelativeTo(null); // Center the window
55 | mainFrame.setVisible(true);
56 | }
57 |
58 | private void createToolBar() {
59 | JToolBar toolBar = new JToolBar();
60 | toolBar.setFloatable(false);
61 |
62 | JButton openButton = new JButton("Open");
63 | JButton saveButton = new JButton("Save");
64 | JButton loadButton = new JButton("Load");
65 | toolBar.add(openButton);
66 | toolBar.add(saveButton);
67 | toolBar.add(loadButton);
68 |
69 | JButton helpButton = new JButton("Help");
70 | toolBar.add(Box.createHorizontalGlue());
71 | toolBar.add(helpButton);
72 |
73 | JButton aboutButton = new JButton("About");
74 | toolBar.add(aboutButton);
75 |
76 | // Add action listeners for the buttons here if needed
77 |
78 | mainFrame.add(toolBar, BorderLayout.NORTH);
79 |
80 | // Help button action
81 | helpButton.addActionListener(e -> showHelpDialog());
82 |
83 | // About button action
84 | aboutButton.addActionListener(e -> showAboutDialog());
85 |
86 | //Open button action
87 | openButton.addActionListener(e -> openWebsite("https://google.com")); // Replace with your desired URL
88 |
89 | saveButton.addActionListener(e -> saveData());
90 |
91 | saveButton.addActionListener(e -> saveData());
92 |
93 | // Add ActionListener to the "Load" button
94 | loadButton.addActionListener(e -> loadData());
95 | }
96 |
97 | private static void showHelpDialog() {
98 | JOptionPane.showMessageDialog(null,
99 | "Help content goes here.",
100 | "Help",
101 | JOptionPane.INFORMATION_MESSAGE);
102 | }
103 |
104 | private static void showAboutDialog() {
105 | JOptionPane.showMessageDialog(null,
106 | "Tag Replacement Tool\nVersion 1.0\nAuthor: Your Name",
107 | "About",
108 | JOptionPane.INFORMATION_MESSAGE);
109 | }
110 |
111 | private void createInputPanel() {
112 | JPanel inputPanel = new JPanel(new FlowLayout());
113 | JLabel moNameLabel = new JLabel("Select mo_name:");
114 | moNameComboBox = new JComboBox<>(getMoNames());
115 | moNameComboBox.setEditable(true);
116 | JButton processButton = new JButton("Process");
117 | inputPanel.add(moNameLabel);
118 | inputPanel.add(moNameComboBox);
119 | inputPanel.add(processButton);
120 |
121 | // Add action listener for the "Process" button
122 | processButton.addActionListener(e -> processMoContent());
123 |
124 | mainFrame.add(inputPanel, BorderLayout.CENTER);
125 | }
126 |
127 | private void createOutputPanel() {
128 | outputArea = new JTextArea(20, 50);
129 | outputArea.setEditable(false);
130 | outputArea.setFont(new Font("Monospaced", Font.BOLD, 14));
131 | JScrollPane outputScrollPane = new JScrollPane(outputArea);
132 | mainFrame.add(outputScrollPane, BorderLayout.SOUTH);
133 | }
134 |
135 | private String[] getMoNames() {
136 | List moNameList = new ArrayList<>();
137 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
138 | Statement stmt = conn.createStatement();
139 | ResultSet rs = stmt.executeQuery("SELECT mo_name FROM " + TABLE1_NAME)) {
140 |
141 | while (rs.next()) {
142 | moNameList.add(rs.getString("mo_name"));
143 | }
144 | } catch (SQLException e) {
145 | e.printStackTrace();
146 | }
147 | return moNameList.toArray(new String[0]);
148 | }
149 |
150 | private void processMoContent() {
151 | String moName = moNameComboBox.getSelectedItem().toString();
152 | StringBuilder resultBuilder = new StringBuilder();
153 |
154 | // Check if the selected mo name exists in the database
155 | if (!isMoNameExists(moName)) {
156 | JOptionPane.showMessageDialog(mainFrame, "The selected mo_name does not exist in the database.",
157 | "Error", JOptionPane.ERROR_MESSAGE);
158 | return;
159 | }
160 |
161 |
162 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS)) {
163 | createTables(conn);
164 | String moContent = getMoContent(conn, moName);
165 | List tags = extractTags(moContent);
166 |
167 | for (String tag : tags) {
168 | String tagName = getTagName(tag);
169 | String tagComment = getTagComment(conn, tagName);
170 | resultBuilder.append("Mo Name: ").append(moName).append("\n");
171 | resultBuilder.append("Tag Name: ").append(tagName).append("\n");
172 | resultBuilder.append("Tag Comment: ").append(tagComment).append("\n");
173 |
174 | String replacementText = showInputDialogWithInfo("Enter replacement text for the tag '" + tagName + "':",
175 | moName, tagName, tagComment);
176 |
177 | if (replacementText.equals("__ABORT__")) {
178 | break; // Abort tag replacement for this mo_name
179 | }
180 |
181 | moContent = moContent.replace(tag, replacementText);
182 | }
183 |
184 | showFinalContentWindow(moContent);
185 | outputArea.setText(resultBuilder.toString());
186 |
187 | } catch (SQLException se) {
188 | se.printStackTrace();
189 | }
190 | }
191 |
192 | // Implement the custom dialog logic here
193 | private static String showInputDialogWithInfo(String message, String moName, String tagName, String tagComment) {
194 | JPanel panel = new JPanel(new GridLayout(0, 1));
195 | panel.add(new JLabel("Mo Name: " + moName));
196 | panel.add(new JLabel("Tag Name: " + tagName));
197 | panel.add(new JLabel("\nTag Comments: "));
198 |
199 | JTextArea commentArea = new JTextArea(tagComment);
200 | commentArea.setEditable(false);
201 | JScrollPane commentScrollPane = new JScrollPane(commentArea);
202 | panel.add(commentScrollPane);
203 | panel.add(new JLabel("\n\nReplacement: "));
204 | JTextField textField = new JTextField(20);
205 | panel.add(textField);
206 |
207 | JButton abortButton = new JButton("Abort");
208 | panel.add(abortButton);
209 |
210 | int result = JOptionPane.showOptionDialog(null, panel, message, JOptionPane.OK_CANCEL_OPTION,
211 | JOptionPane.PLAIN_MESSAGE, null, null, null);
212 |
213 | if (result == JOptionPane.OK_OPTION) {
214 | return textField.getText();
215 | } else if (result == JOptionPane.CANCEL_OPTION) {
216 | // Return a special value to indicate "Abort" button was clicked
217 | return "__ABORT__";
218 | } else {
219 | return "";
220 | }
221 | }
222 |
223 | // Implement the final content window logic here
224 | private static void showFinalContentWindow(String moContent) {
225 | JFrame finalContentFrame = new JFrame("Final Content");
226 | finalContentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
227 | finalContentFrame.setLayout(new BorderLayout());
228 |
229 | // Final content panel
230 | JTextArea finalContentArea = new JTextArea(moContent);
231 | finalContentArea.setFont(new Font("Monospaced", Font.BOLD, 14));
232 | finalContentArea.setEditable(true);
233 | JScrollPane finalContentScrollPane = new JScrollPane(finalContentArea);
234 |
235 | // Add a popup menu to the final content area
236 | JPopupMenu popupMenu = new JPopupMenu();
237 | JMenuItem copyItem = new JMenuItem("Copy");
238 | JMenuItem editItem = new JMenuItem("Edit");
239 | popupMenu.add(copyItem);
240 | popupMenu.add(editItem);
241 |
242 | finalContentArea.setComponentPopupMenu(popupMenu);
243 |
244 | // "Copy" action to copy the content to the clipboard
245 | copyItem.addActionListener(e -> {
246 | StringSelection selection = new StringSelection(finalContentArea.getText());
247 | Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
248 | clipboard.setContents(selection, null);
249 | });
250 |
251 | // "Edit" action to enable editing of the content
252 | editItem.addActionListener(e -> finalContentArea.setEditable(true));
253 |
254 | // Disable editing when the popup menu is closed
255 | popupMenu.addPopupMenuListener(new PopupMenuListener() {
256 | @Override
257 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
258 | // Do nothing
259 | }
260 |
261 | @Override
262 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
263 | finalContentArea.setEditable(false);
264 | }
265 |
266 | @Override
267 | public void popupMenuCanceled(PopupMenuEvent e) {
268 | // Do nothing
269 | }
270 | });
271 |
272 | finalContentFrame.add(finalContentScrollPane, BorderLayout.CENTER);
273 | finalContentFrame.setPreferredSize(new Dimension(800, 600));
274 | finalContentFrame.pack();
275 | // Center the final content window on the screen
276 | finalContentFrame.setLocationRelativeTo(null);
277 | finalContentFrame.setVisible(true);
278 | }
279 |
280 | // Create the tables if they don't exist
281 | private static void createTables(Connection conn) throws SQLException {
282 | try (Statement stmt = conn.createStatement()) {
283 | String createTable1Query = "CREATE TABLE IF NOT EXISTS " + TABLE1_NAME + " (" +
284 | "mo_name TEXT PRIMARY KEY, " +
285 | "mo_content TEXT, " +
286 | "mo_tags TEXT)";
287 | stmt.execute(createTable1Query);
288 |
289 | String createTable2Query = "CREATE TABLE IF NOT EXISTS " + TABLE2_NAME + " (" +
290 | "mo_tags TEXT PRIMARY KEY, " +
291 | "tag_comment TEXT)";
292 | stmt.execute(createTable2Query);
293 | }
294 | }
295 |
296 | // Retrieve mo_content based on mo_name
297 | private static String getMoContent(Connection conn, String moName) throws SQLException {
298 | String moContent = null;
299 | String query = "SELECT mo_content FROM " + TABLE1_NAME + " WHERE mo_name = ?";
300 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
301 | pstmt.setString(1, moName);
302 | try (ResultSet rs = pstmt.executeQuery()) {
303 | if (rs.next()) {
304 | moContent = rs.getString("mo_content");
305 | }
306 | }
307 | }
308 | return moContent;
309 | }
310 |
311 | // Extract tags from mo_content
312 | private static List extractTags(String moContent) {
313 | List tags = new ArrayList<>();
314 | Pattern pattern = Pattern.compile("\\{#(.*?)\\}");
315 | Matcher matcher = pattern.matcher(moContent);
316 | while (matcher.find()) {
317 | tags.add(matcher.group());
318 | }
319 | return tags;
320 | }
321 |
322 | // Get the tag name from the tag
323 | private static String getTagName(String tag) {
324 | // Assuming the tag format is {#tagname this is a tag}
325 | int start = tag.indexOf('#') + 1;
326 | int end = tag.indexOf(' ', start);
327 | return tag.substring(start, end);
328 | }
329 |
330 | private static String getTagComment(Connection conn, String tagName) throws SQLException {
331 | String tagComment = null;
332 | String query = "SELECT tag_comment FROM " + TABLE2_NAME + " WHERE mo_tags = ?";
333 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
334 | pstmt.setString(1, tagName);
335 | try (ResultSet rs = pstmt.executeQuery()) {
336 | if (rs.next()) {
337 | tagComment = rs.getString("tag_comment");
338 | }
339 | }
340 | }
341 | return tagComment;
342 | }
343 |
344 | private boolean isMoNameExists(String moName) {
345 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
346 | PreparedStatement pstmt = conn.prepareStatement("SELECT mo_name FROM " + TABLE1_NAME + " WHERE mo_name = ?")) {
347 | pstmt.setString(1, moName);
348 | try (ResultSet rs = pstmt.executeQuery()) {
349 | return rs.next(); // Return true if a row with the given mo_name exists
350 | }
351 | } catch (SQLException e) {
352 | e.printStackTrace();
353 | }
354 | return false;
355 | }
356 |
357 |
358 | private void openWebsite(String url) {
359 | try {
360 | // Use Desktop to open the default web browser
361 | if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
362 | Desktop.getDesktop().browse(new URI(url));
363 | } else {
364 | JOptionPane.showMessageDialog(mainFrame, "Opening the default web browser is not supported on this platform.",
365 | "Error", JOptionPane.ERROR_MESSAGE);
366 | }
367 | } catch (Exception ex) {
368 | ex.printStackTrace();
369 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while trying to open the website.",
370 | "Error", JOptionPane.ERROR_MESSAGE);
371 | }
372 | }
373 |
374 | private void saveData() {
375 | try {
376 | // Get the current state of the application data
377 | String moName = Objects.requireNonNull(moNameComboBox.getSelectedItem()).toString();
378 | String moContent = outputArea.getText();
379 |
380 | // Choose the save file location using JFileChooser with custom file filter
381 | JFileChooser fileChooser = new JFileChooser();
382 | fileChooser.setFileFilter(new TRTFileFilter());
383 |
384 | int returnValue = fileChooser.showSaveDialog(mainFrame);
385 |
386 | if (returnValue == JFileChooser.APPROVE_OPTION) {
387 | File selectedFile = fileChooser.getSelectedFile();
388 | if (!selectedFile.getAbsolutePath().toLowerCase().endsWith(".trt")) {
389 | selectedFile = new File(selectedFile.getAbsolutePath() + ".trt");
390 | }
391 |
392 | if (selectedFile.exists()) {
393 | // File already exists, ask for confirmation to overwrite
394 | int overwriteConfirmation = JOptionPane.showConfirmDialog(mainFrame,
395 | "The selected file already exists. Do you want to overwrite it?",
396 | "File Exists", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
397 |
398 | if (overwriteConfirmation == JOptionPane.NO_OPTION) {
399 | // User chose not to overwrite, return without saving
400 | return;
401 | }
402 | }
403 |
404 | // Write the data to the selected file in custom save file format
405 | try (PrintWriter writer = new PrintWriter(selectedFile)) {
406 | writer.println("MO_NAME:" + moName);
407 | writer.println("MO_CONTENT:");
408 | writer.println(moContent);
409 | writer.flush();
410 | }
411 |
412 | JOptionPane.showMessageDialog(mainFrame, "Data saved successfully!",
413 | "Save", JOptionPane.INFORMATION_MESSAGE);
414 | }
415 | } catch (Exception ex) {
416 | ex.printStackTrace();
417 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while saving the data.",
418 | "Error", JOptionPane.ERROR_MESSAGE);
419 | }
420 | }
421 | private void loadData() {
422 | try {
423 | // Choose the file to load data from using JFileChooser with custom file filter
424 | JFileChooser fileChooser = new JFileChooser();
425 | fileChooser.setFileFilter(new TRTFileFilter());
426 |
427 | int returnValue = fileChooser.showOpenDialog(mainFrame);
428 |
429 | if (returnValue == JFileChooser.APPROVE_OPTION) {
430 | File selectedFile = fileChooser.getSelectedFile();
431 |
432 | // Read the data from the selected file in custom save file format
433 | try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) {
434 | StringBuilder moContentBuilder = new StringBuilder();
435 | String line;
436 | boolean readingMoContent = false;
437 |
438 | while ((line = reader.readLine()) != null) {
439 | if (line.startsWith("MO_NAME:")) {
440 | moNameComboBox.setSelectedItem(line.substring(8));
441 | } else if (line.startsWith("MO_CONTENT:")) {
442 | readingMoContent = true;
443 | } else if (readingMoContent) {
444 | moContentBuilder.append(line).append("\n");
445 | }
446 | }
447 |
448 | // Set the loaded MO content to the output area
449 | outputArea.setText(moContentBuilder.toString());
450 |
451 | JOptionPane.showMessageDialog(mainFrame, "Data loaded successfully!",
452 | "Load", JOptionPane.INFORMATION_MESSAGE);
453 | }
454 | }
455 | } catch (Exception ex) {
456 | ex.printStackTrace();
457 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while loading the data.",
458 | "Error", JOptionPane.ERROR_MESSAGE);
459 | }
460 | }
461 |
462 | // Custom file filter for ".trt" files
463 | private class TRTFileFilter extends javax.swing.filechooser.FileFilter {
464 | public boolean accept(File file) {
465 | return file.isDirectory() || file.getName().toLowerCase().endsWith(".trt");
466 | }
467 |
468 | public String getDescription() {
469 | return "Tag Replacement Tool Files (*.trt)";
470 | }
471 | }
472 |
473 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/console/TagReplacementToolv3.java:
--------------------------------------------------------------------------------
1 | package com.tagger.console;
2 |
3 | import javax.swing.*;
4 | import javax.swing.event.PopupMenuEvent;
5 | import javax.swing.event.PopupMenuListener;
6 |
7 | import org.json.JSONObject;
8 | import org.json.JSONTokener;
9 |
10 | import java.awt.*;
11 | import java.awt.datatransfer.Clipboard;
12 | import java.awt.datatransfer.StringSelection;
13 | import java.io.BufferedReader;
14 | import java.io.File;
15 | import java.io.FileReader;
16 | import java.io.IOException;
17 | import java.io.PrintWriter;
18 | import java.net.URI;
19 | import java.sql.*;
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import java.util.Objects;
23 | import java.util.regex.Matcher;
24 | import java.util.regex.Pattern;
25 |
26 | public class TagReplacementToolv3 {
27 |
28 | private static final String CONFIG_FILE_PATH = "C:\\Users\\amit\\eclipse-workspace\\Tagger\\src\\trtconfig.json";
29 |
30 | private String DB_URL;
31 | private String USER;
32 | private String PASS;
33 | private String DB_NAME;
34 | private static String TABLE1_NAME;
35 | private static String TABLE2_NAME;
36 |
37 | private JFrame mainFrame;
38 | private JComboBox moNameComboBox;
39 | private JTextArea outputArea;
40 |
41 | public static void main(String[] args) {
42 | SwingUtilities.invokeLater(() -> {
43 | TagReplacementToolv3 tool = new TagReplacementToolv3();
44 | tool.loadConfig();
45 | tool.createAndShowGUI();
46 | });
47 | }
48 |
49 |
50 | private void createAndShowGUI() {
51 | mainFrame = new JFrame("Tag Replacement Tool");
52 | mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
53 | mainFrame.setLayout(new BorderLayout());
54 |
55 | createToolBar();
56 | createInputPanel();
57 | createOutputPanel();
58 |
59 | mainFrame.pack();
60 | mainFrame.setLocationRelativeTo(null); // Center the window
61 | mainFrame.setVisible(true);
62 | }
63 |
64 | private void createToolBar() {
65 | JToolBar toolBar = new JToolBar();
66 | toolBar.setFloatable(false);
67 |
68 | JButton openButton = new JButton("Open");
69 | JButton saveButton = new JButton("Save");
70 | JButton loadButton = new JButton("Load");
71 | toolBar.add(openButton);
72 | toolBar.add(saveButton);
73 | toolBar.add(loadButton);
74 |
75 | JButton helpButton = new JButton("Help");
76 | toolBar.add(Box.createHorizontalGlue());
77 | toolBar.add(helpButton);
78 |
79 | JButton aboutButton = new JButton("About");
80 | toolBar.add(aboutButton);
81 |
82 | // Add action listeners for the buttons here if needed
83 |
84 | mainFrame.add(toolBar, BorderLayout.NORTH);
85 |
86 | // Help button action
87 | helpButton.addActionListener(e -> showHelpDialog());
88 |
89 | // About button action
90 | aboutButton.addActionListener(e -> showAboutDialog());
91 |
92 | //Open button action
93 | openButton.addActionListener(e -> openWebsite("https://google.com")); // Replace with your desired URL
94 |
95 | saveButton.addActionListener(e -> saveData());
96 |
97 | saveButton.addActionListener(e -> saveData());
98 |
99 | // Add ActionListener to the "Load" button
100 | loadButton.addActionListener(e -> loadData());
101 | }
102 |
103 | private static void showHelpDialog() {
104 | JOptionPane.showMessageDialog(null,
105 | "Help content goes here.",
106 | "Help",
107 | JOptionPane.INFORMATION_MESSAGE);
108 | }
109 |
110 | private static void showAboutDialog() {
111 | JOptionPane.showMessageDialog(null,
112 | "Tag Replacement Tool\nVersion 1.0\nAuthor: Your Name",
113 | "About",
114 | JOptionPane.INFORMATION_MESSAGE);
115 | }
116 |
117 | private void createInputPanel() {
118 | JPanel inputPanel = new JPanel(new FlowLayout());
119 | JLabel moNameLabel = new JLabel("Select mo_name:");
120 | moNameComboBox = new JComboBox<>(getMoNames());
121 | moNameComboBox.setEditable(true);
122 | JButton processButton = new JButton("Process");
123 | inputPanel.add(moNameLabel);
124 | inputPanel.add(moNameComboBox);
125 | inputPanel.add(processButton);
126 |
127 | // Add action listener for the "Process" button
128 | processButton.addActionListener(e -> processMoContent());
129 |
130 | mainFrame.add(inputPanel, BorderLayout.CENTER);
131 | }
132 |
133 | private void createOutputPanel() {
134 | outputArea = new JTextArea(20, 50);
135 | outputArea.setEditable(false);
136 | outputArea.setFont(new Font("Monospaced", Font.BOLD, 14));
137 | JScrollPane outputScrollPane = new JScrollPane(outputArea);
138 | mainFrame.add(outputScrollPane, BorderLayout.SOUTH);
139 | }
140 |
141 | private String[] getMoNames() {
142 | List moNameList = new ArrayList<>();
143 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
144 | Statement stmt = conn.createStatement();
145 | ResultSet rs = stmt.executeQuery("SELECT mo_name FROM " + TABLE1_NAME)) {
146 |
147 | while (rs.next()) {
148 | moNameList.add(rs.getString("mo_name"));
149 | }
150 | } catch (SQLException e) {
151 | e.printStackTrace();
152 | }
153 | return moNameList.toArray(new String[0]);
154 | }
155 |
156 | private void processMoContent() {
157 | String moName = moNameComboBox.getSelectedItem().toString();
158 | StringBuilder resultBuilder = new StringBuilder();
159 |
160 | // Check if the selected mo name exists in the database
161 | if (!isMoNameExists(moName)) {
162 | JOptionPane.showMessageDialog(mainFrame, "The selected mo_name does not exist in the database.",
163 | "Error", JOptionPane.ERROR_MESSAGE);
164 | return;
165 | }
166 |
167 |
168 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS)) {
169 | createTables(conn);
170 | String moContent = getMoContent(conn, moName);
171 | List tags = extractTags(moContent);
172 |
173 | for (String tag : tags) {
174 | String tagName = getTagName(tag);
175 | String tagComment = getTagComment(conn, tagName);
176 | resultBuilder.append("Mo Name: ").append(moName).append("\n");
177 | resultBuilder.append("Tag Name: ").append(tagName).append("\n");
178 | resultBuilder.append("Tag Comment: ").append(tagComment).append("\n");
179 |
180 | String replacementText = showInputDialogWithInfo("Enter replacement text for the tag '" + tagName + "':",
181 | moName, tagName, tagComment);
182 |
183 | if (replacementText.equals("__ABORT__")) {
184 | break; // Abort tag replacement for this mo_name
185 | }
186 |
187 | moContent = moContent.replace(tag, replacementText);
188 | }
189 |
190 | showFinalContentWindow(moContent);
191 | outputArea.setText(resultBuilder.toString());
192 |
193 | } catch (SQLException se) {
194 | se.printStackTrace();
195 | }
196 | }
197 |
198 | // Implement the custom dialog logic here
199 | private static String showInputDialogWithInfo(String message, String moName, String tagName, String tagComment) {
200 | JPanel panel = new JPanel(new GridLayout(0, 1));
201 | panel.add(new JLabel("Mo Name: " + moName));
202 | panel.add(new JLabel("Tag Name: " + tagName));
203 | panel.add(new JLabel("\nTag Comments: "));
204 |
205 | JTextArea commentArea = new JTextArea(tagComment);
206 | commentArea.setEditable(false);
207 | JScrollPane commentScrollPane = new JScrollPane(commentArea);
208 | panel.add(commentScrollPane);
209 | panel.add(new JLabel("\n\nReplacement: "));
210 | JTextField textField = new JTextField(20);
211 | panel.add(textField);
212 |
213 | JButton abortButton = new JButton("Abort");
214 | panel.add(abortButton);
215 |
216 | int result = JOptionPane.showOptionDialog(null, panel, message, JOptionPane.OK_CANCEL_OPTION,
217 | JOptionPane.PLAIN_MESSAGE, null, null, null);
218 |
219 | if (result == JOptionPane.OK_OPTION) {
220 | return textField.getText();
221 | } else if (result == JOptionPane.CANCEL_OPTION) {
222 | // Return a special value to indicate "Abort" button was clicked
223 | return "__ABORT__";
224 | } else {
225 | return "";
226 | }
227 | }
228 |
229 | // Implement the final content window logic here
230 | private static void showFinalContentWindow(String moContent) {
231 | JFrame finalContentFrame = new JFrame("Final Content");
232 | finalContentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
233 | finalContentFrame.setLayout(new BorderLayout());
234 |
235 | // Final content panel
236 | JTextArea finalContentArea = new JTextArea(moContent);
237 | finalContentArea.setFont(new Font("Monospaced", Font.BOLD, 14));
238 | finalContentArea.setEditable(true);
239 | JScrollPane finalContentScrollPane = new JScrollPane(finalContentArea);
240 |
241 | // Add a popup menu to the final content area
242 | JPopupMenu popupMenu = new JPopupMenu();
243 | JMenuItem copyItem = new JMenuItem("Copy");
244 | JMenuItem editItem = new JMenuItem("Edit");
245 | popupMenu.add(copyItem);
246 | popupMenu.add(editItem);
247 |
248 | finalContentArea.setComponentPopupMenu(popupMenu);
249 |
250 | // "Copy" action to copy the content to the clipboard
251 | copyItem.addActionListener(e -> {
252 | StringSelection selection = new StringSelection(finalContentArea.getText());
253 | Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
254 | clipboard.setContents(selection, null);
255 | });
256 |
257 | // "Edit" action to enable editing of the content
258 | editItem.addActionListener(e -> finalContentArea.setEditable(true));
259 |
260 | // Disable editing when the popup menu is closed
261 | popupMenu.addPopupMenuListener(new PopupMenuListener() {
262 | @Override
263 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
264 | // Do nothing
265 | }
266 |
267 | @Override
268 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
269 | finalContentArea.setEditable(false);
270 | }
271 |
272 | @Override
273 | public void popupMenuCanceled(PopupMenuEvent e) {
274 | // Do nothing
275 | }
276 | });
277 |
278 | finalContentFrame.add(finalContentScrollPane, BorderLayout.CENTER);
279 | finalContentFrame.setPreferredSize(new Dimension(800, 600));
280 | finalContentFrame.pack();
281 | // Center the final content window on the screen
282 | finalContentFrame.setLocationRelativeTo(null);
283 | finalContentFrame.setVisible(true);
284 | }
285 |
286 | // Create the tables if they don't exist
287 | private static void createTables(Connection conn) throws SQLException {
288 | try (Statement stmt = conn.createStatement()) {
289 | String createTable1Query = "CREATE TABLE IF NOT EXISTS " + TABLE1_NAME + " (" +
290 | "mo_name TEXT PRIMARY KEY, " +
291 | "mo_content TEXT, " +
292 | "mo_tags TEXT)";
293 | stmt.execute(createTable1Query);
294 |
295 | String createTable2Query = "CREATE TABLE IF NOT EXISTS " + TABLE2_NAME + " (" +
296 | "mo_tags TEXT PRIMARY KEY, " +
297 | "tag_comment TEXT)";
298 | stmt.execute(createTable2Query);
299 | }
300 | }
301 |
302 | // Retrieve mo_content based on mo_name
303 | private static String getMoContent(Connection conn, String moName) throws SQLException {
304 | String moContent = null;
305 | String query = "SELECT mo_content FROM " + TABLE1_NAME + " WHERE mo_name = ?";
306 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
307 | pstmt.setString(1, moName);
308 | try (ResultSet rs = pstmt.executeQuery()) {
309 | if (rs.next()) {
310 | moContent = rs.getString("mo_content");
311 | }
312 | }
313 | }
314 | return moContent;
315 | }
316 |
317 | // Extract tags from mo_content
318 | private static List extractTags(String moContent) {
319 | List tags = new ArrayList<>();
320 | Pattern pattern = Pattern.compile("\\{#(.*?)\\}");
321 | Matcher matcher = pattern.matcher(moContent);
322 | while (matcher.find()) {
323 | tags.add(matcher.group());
324 | }
325 | return tags;
326 | }
327 |
328 | // Get the tag name from the tag
329 | private static String getTagName(String tag) {
330 | // Assuming the tag format is {#tagname this is a tag}
331 | int start = tag.indexOf('#') + 1;
332 | int end = tag.indexOf(' ', start);
333 | return tag.substring(start, end);
334 | }
335 |
336 | private static String getTagComment(Connection conn, String tagName) throws SQLException {
337 | String tagComment = null;
338 | String query = "SELECT tag_comment FROM " + TABLE2_NAME + " WHERE mo_tags = ?";
339 | try (PreparedStatement pstmt = conn.prepareStatement(query)) {
340 | pstmt.setString(1, tagName);
341 | try (ResultSet rs = pstmt.executeQuery()) {
342 | if (rs.next()) {
343 | tagComment = rs.getString("tag_comment");
344 | }
345 | }
346 | }
347 | return tagComment;
348 | }
349 |
350 | private boolean isMoNameExists(String moName) {
351 | try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
352 | PreparedStatement pstmt = conn.prepareStatement("SELECT mo_name FROM " + TABLE1_NAME + " WHERE mo_name = ?")) {
353 | pstmt.setString(1, moName);
354 | try (ResultSet rs = pstmt.executeQuery()) {
355 | return rs.next(); // Return true if a row with the given mo_name exists
356 | }
357 | } catch (SQLException e) {
358 | e.printStackTrace();
359 | }
360 | return false;
361 | }
362 |
363 |
364 | private void openWebsite(String url) {
365 | try {
366 | // Use Desktop to open the default web browser
367 | if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
368 | Desktop.getDesktop().browse(new URI(url));
369 | } else {
370 | JOptionPane.showMessageDialog(mainFrame, "Opening the default web browser is not supported on this platform.",
371 | "Error", JOptionPane.ERROR_MESSAGE);
372 | }
373 | } catch (Exception ex) {
374 | ex.printStackTrace();
375 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while trying to open the website.",
376 | "Error", JOptionPane.ERROR_MESSAGE);
377 | }
378 | }
379 |
380 | private void saveData() {
381 | try {
382 | // Get the current state of the application data
383 | String moName = Objects.requireNonNull(moNameComboBox.getSelectedItem()).toString();
384 | String moContent = outputArea.getText();
385 |
386 | // Choose the save file location using JFileChooser with custom file filter
387 | JFileChooser fileChooser = new JFileChooser();
388 | fileChooser.setFileFilter(new TRTFileFilter());
389 |
390 | int returnValue = fileChooser.showSaveDialog(mainFrame);
391 |
392 | if (returnValue == JFileChooser.APPROVE_OPTION) {
393 | File selectedFile = fileChooser.getSelectedFile();
394 | if (!selectedFile.getAbsolutePath().toLowerCase().endsWith(".trt")) {
395 | selectedFile = new File(selectedFile.getAbsolutePath() + ".trt");
396 | }
397 |
398 | if (selectedFile.exists()) {
399 | // File already exists, ask for confirmation to overwrite
400 | int overwriteConfirmation = JOptionPane.showConfirmDialog(mainFrame,
401 | "The selected file already exists. Do you want to overwrite it?",
402 | "File Exists", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
403 |
404 | if (overwriteConfirmation == JOptionPane.NO_OPTION) {
405 | // User chose not to overwrite, return without saving
406 | return;
407 | }
408 | }
409 |
410 | // Write the data to the selected file in custom save file format
411 | try (PrintWriter writer = new PrintWriter(selectedFile)) {
412 | writer.println("MO_NAME:" + moName);
413 | writer.println("MO_CONTENT:");
414 | writer.println(moContent);
415 | writer.flush();
416 | }
417 |
418 | JOptionPane.showMessageDialog(mainFrame, "Data saved successfully!",
419 | "Save", JOptionPane.INFORMATION_MESSAGE);
420 | }
421 | } catch (Exception ex) {
422 | ex.printStackTrace();
423 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while saving the data.",
424 | "Error", JOptionPane.ERROR_MESSAGE);
425 | }
426 | }
427 |
428 | private void loadData() {
429 | try {
430 | // Choose the file to load data from using JFileChooser with custom file filter
431 | JFileChooser fileChooser = new JFileChooser();
432 | fileChooser.setFileFilter(new TRTFileFilter());
433 |
434 | int returnValue = fileChooser.showOpenDialog(mainFrame);
435 |
436 | if (returnValue == JFileChooser.APPROVE_OPTION) {
437 | File selectedFile = fileChooser.getSelectedFile();
438 |
439 | // Read the data from the selected file in custom save file format
440 | try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) {
441 | StringBuilder moContentBuilder = new StringBuilder();
442 | String line;
443 | boolean readingMoContent = false;
444 |
445 | while ((line = reader.readLine()) != null) {
446 | if (line.startsWith("MO_NAME:")) {
447 | moNameComboBox.setSelectedItem(line.substring(8));
448 | } else if (line.startsWith("MO_CONTENT:")) {
449 | readingMoContent = true;
450 | } else if (readingMoContent) {
451 | moContentBuilder.append(line).append("\n");
452 | }
453 | }
454 |
455 | // Set the loaded MO content to the output area
456 | outputArea.setText(moContentBuilder.toString());
457 |
458 | JOptionPane.showMessageDialog(mainFrame, "Data loaded successfully!",
459 | "Load", JOptionPane.INFORMATION_MESSAGE);
460 | }
461 | }
462 | } catch (Exception ex) {
463 | ex.printStackTrace();
464 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while loading the data.",
465 | "Error", JOptionPane.ERROR_MESSAGE);
466 | }
467 | }
468 |
469 | // Custom file filter for ".trt" files
470 | private class TRTFileFilter extends javax.swing.filechooser.FileFilter {
471 | public boolean accept(File file) {
472 | return file.isDirectory() || file.getName().toLowerCase().endsWith(".trt");
473 | }
474 |
475 | public String getDescription() {
476 | return "Tag Replacement Tool Files (*.trt)";
477 | }
478 | }
479 |
480 |
481 | private void loadConfig() {
482 | try {
483 | String configData = readFile(CONFIG_FILE_PATH);
484 | JSONObject configJson = new JSONObject(new JSONTokener(configData));
485 |
486 | DB_URL = configJson.getString("DB_URL");
487 | USER = configJson.getString("USER");
488 | PASS = configJson.getString("PASS");
489 | DB_NAME = configJson.getString("DB_NAME");
490 | TABLE1_NAME = configJson.getString("TABLE1_NAME");
491 | TABLE2_NAME = configJson.getString("TABLE2_NAME");
492 | } catch (Exception ex) {
493 | ex.printStackTrace();
494 | JOptionPane.showMessageDialog(null, "Error loading configuration from " + CONFIG_FILE_PATH,
495 | "Error", JOptionPane.ERROR_MESSAGE);
496 | System.exit(1);
497 | }
498 | }
499 | private String readFile(String filePath) throws IOException {
500 | StringBuilder content = new StringBuilder();
501 | try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
502 | String line;
503 | while ((line = reader.readLine()) != null) {
504 | content.append(line);
505 | }
506 | }
507 | return content.toString();
508 | }
509 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/console/hasher.java:
--------------------------------------------------------------------------------
1 | package com.tagger.console;
2 |
3 | import java.security.MessageDigest;
4 | import java.util.Date;
5 |
6 | public class hasher {
7 |
8 | public String createHash() throws Exception {
9 | // Get the current timestamp
10 | Date timestamp = new Date();
11 |
12 | // Create a MessageDigest instance
13 | MessageDigest md = MessageDigest.getInstance("SHA-256");
14 |
15 | // Convert the timestamp to a byte array
16 | byte[] bytes = timestamp.toString().getBytes();
17 |
18 | // Calculate the hash of the timestamp
19 | byte[] hash = md.digest(bytes);
20 |
21 | // Convert the hash to a hexadecimal string
22 | String hashString = bytesToHexString(hash);
23 |
24 | return hashString;
25 | }
26 |
27 | private static String bytesToHexString(byte[] bytes) {
28 | StringBuffer sb = new StringBuffer();
29 | for (int i = 0; i < bytes.length; i++) {
30 | int value = bytes[i] & 0xFF;
31 | sb.append(Integer.toHexString(value));
32 | }
33 | return sb.toString();
34 | }
35 |
36 |
37 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/console/tagger.sql:
--------------------------------------------------------------------------------
1 | -- --------------------------------------------------------
2 | -- Host: 127.0.0.1
3 | -- Server version: 8.0.30 - MySQL Community Server - GPL
4 | -- Server OS: Win64
5 | -- HeidiSQL Version: 12.1.0.6537
6 | -- --------------------------------------------------------
7 |
8 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
9 | /*!40101 SET NAMES utf8 */;
10 | /*!50503 SET NAMES utf8mb4 */;
11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12 | /*!40103 SET TIME_ZONE='+00:00' */;
13 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
14 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
15 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
16 |
17 |
18 | -- Dumping database structure for mydb
19 | DROP DATABASE IF EXISTS `mydb`;
20 | CREATE DATABASE IF NOT EXISTS `mydb` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
21 | USE `mydb`;
22 |
23 | -- Dumping structure for table mydb.table1
24 | DROP TABLE IF EXISTS `table1`;
25 | CREATE TABLE IF NOT EXISTS `table1` (
26 | `mo_name` varchar(15) NOT NULL,
27 | `mo_content` text,
28 | `mo_tags` text,
29 | PRIMARY KEY (`mo_name`)
30 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
31 |
32 | -- Dumping data for table mydb.table1: ~7 rows (approximately)
33 | DELETE FROM `table1`;
34 | INSERT INTO `table1` (`mo_name`, `mo_content`, `mo_tags`) VALUES
35 | ('mo_bstc', 'A registration was started online to set up an APE account.The account was activated. The seller listed {#tag_prodcat} priced {#tag_abatbe} their current market value A review of the account showed that the seller also controlled {#tag_singmul}, . {#tag_singmultt} used to place orders with the seller account.{#tag_ishnr} {#tag_isactiveall} {#tag_isactivesm} {#tag_isblocked} ', 'tag_prodcat,tag_abatbe,tag_singmul,tag_singmultt,tag_ishnr,tag_isactiveall,tag_isactivesm,tag_isblocked'),
36 | ('mo1', '{#tag1 this a tag} original mo content {#tag2 this is another tag} Some more content', 'tag1,tag2'),
37 | ('mo2', 'original mo content {#tag3 this a tag} Some more content', 'tag3'),
38 | ('mo2ss', 'original mo content {#tag3 this a tag} Some more content', 'tag3'),
39 | ('mo3', 'hi there {#tag_prodcat originalcontentss}', 'tag_prodcat'),
40 | ('mo4', 'A registration was started online to set up an APE account.\r\n\r\nThe account was activated. The seller listed {#tag_prodcat ss} priced {#tag_abatbe ss} their current market value.\r\n\r\nA review of the account showed that the seller also controlled {#tag_singmul ss}, {#tag_singmultt ss} used to place orders with the seller account.\r\n\r\n{#tag_ishnr ss} .\r\n\r\n{#tag_isactiveall ss} {#tag_isactivesm ss} {#tag_isblocked ss} .', 'tag_prodcat,tag_abatbe,tag_singmul,tag_singmultt,tag_ishnr,tag_isactiveall,tag_isactivesm,tag_isblocked'),
41 | ('mo5', 'original mo content {#tag_mytag this a tag /this,that/ notthis} Some more content', 'tag_mytag');
42 |
43 | -- Dumping structure for table mydb.table2
44 | DROP TABLE IF EXISTS `table2`;
45 | CREATE TABLE IF NOT EXISTS `table2` (
46 | `mo_tags` varchar(15) NOT NULL,
47 | `tag_comment` text,
48 | PRIMARY KEY (`mo_tags`)
49 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
50 |
51 | -- Dumping data for table mydb.table2: ~12 rows (approximately)
52 | DELETE FROM `table2`;
53 | INSERT INTO `table2` (`mo_tags`, `tag_comment`) VALUES
54 | ('tag_abatbe', 'Pricing Above / at / below'),
55 | ('tag_isactiveall', 'The APE account is active on the Amazon EU online stores'),
56 | ('tag_isactivesm', 'The APE account is active on the Amazon online stores'),
57 | ('tag_isblocked', 'The APE account is currently blocked on the ONLINE STORES ONLY online store(s). '),
58 | ('tag_ishnr', 'Additionally, these items did not appear to have been sent to the related buyer [#account./accounts.#] '),
59 | ('tag_mytag', 'i am tag_mytag'),
60 | ('tag_prodcat', 'Type the Product Categries'),
61 | ('tag_singmul', '[#multiple buyer accounts/a buyer account#]'),
62 | ('tag_singmultt', '[#These buyer accounts were/This buyer account was#] '),
63 | ('tag1', 'I am tag 1'),
64 | ('tag2', 'I am tag 2'),
65 | ('tag3', 'I am tag3 ');
66 |
67 | /*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
68 | /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
69 | /*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
70 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
71 | /*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
72 |
--------------------------------------------------------------------------------
/src/main/java/com/tagger/console/trtconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "DB_URL": "jdbc:mysql://localhost/mydb",
3 | "USER": "root",
4 | "PASS": "",
5 | "DB_NAME": "mydb",
6 | "TABLE1_NAME": "table1",
7 | "TABLE2_NAME": "table2"
8 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/old/Tagrt.java:
--------------------------------------------------------------------------------
1 | package com.tagger.old;
2 |
3 |
4 | import java.io.BufferedReader;
5 | import java.io.FileReader;
6 | import java.io.IOException;
7 | import java.sql.*;
8 | import java.util.ArrayList;
9 | import java.util.List;
10 | import java.util.regex.Matcher;
11 | import java.util.regex.Pattern;
12 |
13 | import javax.swing.JOptionPane;
14 |
15 | import org.json.JSONObject;
16 | import org.json.JSONTokener;
17 |
18 | public class Tagrt {
19 |
20 | private static final String CONFIG_FILE_PATH = "C:\\Users\\amit\\eclipse-workspace\\Tagger\\src\\trtconfig.json";
21 |
22 | private static String DB_URL;
23 | private static String USER;
24 | private static String PASS;
25 | private static String TABLE1_NAME;
26 | private static String TABLE2_NAME;
27 |
28 | // Create the tables if they don't exist
29 | public void createTables() {
30 | try (Connection conn = DriverManager.getConnection(getDB_URL(), getUSER(), getPASS())) {
31 | try (Statement stmt = conn.createStatement()) {
32 | String createTable1Query = "CREATE TABLE IF NOT EXISTS " + TABLE1_NAME + " (" +
33 | "mo_name TEXT PRIMARY KEY, " +
34 | "mo_content TEXT, " +
35 | "mo_tags TEXT)";
36 | stmt.execute(createTable1Query);
37 |
38 | String createTable2Query = "CREATE TABLE IF NOT EXISTS " + TABLE2_NAME + " (" +
39 | "mo_tags TEXT PRIMARY KEY, " +
40 | "tag_comment TEXT)";
41 | stmt.execute(createTable2Query);
42 | }
43 | } catch (SQLException e) {
44 | e.printStackTrace();
45 | }
46 | }
47 |
48 | // Retrieve mo_content based on mo_name
49 | public String getMoContent(String moName) {
50 | String moContent = null;
51 | String query = "SELECT mo_content FROM " + TABLE1_NAME + " WHERE mo_name = ?";
52 | try (Connection conn = DriverManager.getConnection(getDB_URL(), getUSER(), getPASS());
53 | PreparedStatement pstmt = conn.prepareStatement(query)) {
54 | pstmt.setString(1, moName);
55 | try (ResultSet rs = pstmt.executeQuery()) {
56 | if (rs.next()) {
57 | moContent = rs.getString("mo_content");
58 | }
59 | }
60 | } catch (SQLException e) {
61 | e.printStackTrace();
62 | }
63 | return moContent;
64 | }
65 |
66 | // Extract tags from mo_content
67 | public List extractTags(String moContent) {
68 | List tags = new ArrayList<>();
69 | Pattern pattern = Pattern.compile("\\{#(.*?)\\}");
70 | Matcher matcher = pattern.matcher(moContent);
71 | while (matcher.find()) {
72 | tags.add(matcher.group());
73 | }
74 | return tags;
75 | }
76 |
77 | // Get the tag name from the tag
78 | public String getTagName(String tag) {
79 | // Assuming the tag format is {#tagname this is a tag}
80 | int start = tag.indexOf('#') + 1;
81 | int end = tag.indexOf(' ', start);
82 | return tag.substring(start, end);
83 | }
84 |
85 | public String getTagComment(String tagName) {
86 | String tagComment = null;
87 | String query = "SELECT tag_comment FROM " + TABLE2_NAME + " WHERE mo_tags = ?";
88 | try (Connection conn = DriverManager.getConnection(getDB_URL(), getUSER(), getPASS());
89 | PreparedStatement pstmt = conn.prepareStatement(query)) {
90 | pstmt.setString(1, tagName);
91 | try (ResultSet rs = pstmt.executeQuery()) {
92 | if (rs.next()) {
93 | tagComment = rs.getString("tag_comment");
94 | }
95 | }
96 | } catch (SQLException e) {
97 | e.printStackTrace();
98 | }
99 | return tagComment;
100 | }
101 |
102 | public boolean isMoNameExists(String moName) {
103 | try (Connection conn = DriverManager.getConnection(getDB_URL(), getUSER(), getPASS());
104 | PreparedStatement pstmt = conn.prepareStatement("SELECT mo_name FROM " + TABLE1_NAME + " WHERE mo_name = ?")) {
105 | pstmt.setString(1, moName);
106 | try (ResultSet rs = pstmt.executeQuery()) {
107 | return rs.next(); // Return true if a row with the given mo_name exists
108 | }
109 | } catch (SQLException e) {
110 | e.printStackTrace();
111 | }
112 | return false;
113 | }
114 |
115 | String[] getMoNames() {
116 | List moNameList = new ArrayList<>();
117 | try (Connection conn = DriverManager.getConnection(getDB_URL(), getUSER(), getPASS());
118 | Statement stmt = conn.createStatement();
119 | ResultSet rs = stmt.executeQuery("SELECT mo_name FROM " + TABLE1_NAME)) {
120 |
121 | while (rs.next()) {
122 | moNameList.add(rs.getString("mo_name"));
123 | }
124 | } catch (SQLException e) {
125 | e.printStackTrace();
126 | }
127 | return moNameList.toArray(new String[0]);
128 | }
129 |
130 | void loadConfig() {
131 | try {
132 | String configData = readFile(CONFIG_FILE_PATH);
133 | JSONObject configJson = new JSONObject(new JSONTokener(configData));
134 |
135 | setDB_URL(configJson.getString("DB_URL"));
136 | setUSER(configJson.getString("USER"));
137 | setPASS(configJson.getString("PASS"));
138 | TABLE1_NAME = configJson.getString("TABLE1_NAME");
139 | TABLE2_NAME = configJson.getString("TABLE2_NAME");
140 | } catch (Exception ex) {
141 | ex.printStackTrace();
142 | JOptionPane.showMessageDialog(null, "Error loading configuration from " + CONFIG_FILE_PATH,
143 | "Error", JOptionPane.ERROR_MESSAGE);
144 | System.exit(1);
145 | }
146 | }
147 |
148 | private String readFile(String filePath) throws IOException {
149 | StringBuilder content = new StringBuilder();
150 | try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
151 | String line;
152 | while ((line = reader.readLine()) != null) {
153 | content.append(line);
154 | }
155 | }
156 | return content.toString();
157 | }
158 |
159 |
160 | public static String getUSER() {
161 | return USER;
162 | }
163 |
164 | public static void setUSER(String uSER) {
165 | USER = uSER;
166 | }
167 |
168 | public static String getPASS() {
169 | return PASS;
170 | }
171 |
172 | public static void setPASS(String pASS) {
173 | PASS = pASS;
174 | }
175 |
176 | public static String getDB_URL() {
177 | return DB_URL;
178 | }
179 |
180 | public static void setDB_URL(String dB_URL) {
181 | DB_URL = dB_URL;
182 | }
183 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/old/TagrtGUI.java:
--------------------------------------------------------------------------------
1 | package com.tagger.old;
2 |
3 | import java.awt.BorderLayout;
4 | import java.awt.Desktop;
5 | import java.awt.Dimension;
6 | import java.awt.FlowLayout;
7 | import java.awt.Font;
8 | import java.awt.GridLayout;
9 | import java.awt.Toolkit;
10 | import java.awt.datatransfer.Clipboard;
11 | import java.awt.datatransfer.StringSelection;
12 | import java.io.BufferedReader;
13 | import java.io.File;
14 | import java.io.FileReader;
15 | import java.io.IOException;
16 | import java.io.PrintWriter;
17 | import java.net.URI;
18 | import java.sql.Connection;
19 | import java.sql.DriverManager;
20 | import java.sql.SQLException;
21 | import java.util.List;
22 | import java.util.Objects;
23 |
24 | import javax.swing.Box;
25 | import javax.swing.JButton;
26 | import javax.swing.JComboBox;
27 | import javax.swing.JFileChooser;
28 | import javax.swing.JFrame;
29 | import javax.swing.JLabel;
30 | import javax.swing.JMenuItem;
31 | import javax.swing.JOptionPane;
32 | import javax.swing.JPanel;
33 | import javax.swing.JPopupMenu;
34 | import javax.swing.JScrollPane;
35 | import javax.swing.JTextArea;
36 | import javax.swing.JTextField;
37 | import javax.swing.JToolBar;
38 | import javax.swing.SwingUtilities;
39 | import javax.swing.event.PopupMenuEvent;
40 | import javax.swing.event.PopupMenuListener;
41 |
42 | import org.json.JSONObject;
43 | import org.json.JSONTokener;
44 |
45 | public class TagrtGUI {
46 |
47 | Tagrt tr = new Tagrt();
48 |
49 | private JFrame mainFrame;
50 | private JComboBox moNameComboBox;
51 | private JTextArea outputArea;
52 |
53 | public static void main(String[] args) {
54 | SwingUtilities.invokeLater(() -> {
55 | TagrtGUI tool = new TagrtGUI();
56 | Tagrt tr = new Tagrt();
57 | tr.loadConfig();
58 | tool.createAndShowGUI();
59 | });
60 | }
61 |
62 | private void createAndShowGUI() {
63 | mainFrame = new JFrame("Tag Replacement Tool");
64 | mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
65 | mainFrame.setLayout(new BorderLayout());
66 |
67 | createToolBar();
68 | createInputPanel();
69 | createOutputPanel();
70 |
71 | mainFrame.pack();
72 | mainFrame.setLocationRelativeTo(null); // Center the window
73 | mainFrame.setVisible(true);
74 | }
75 |
76 | private void createToolBar() {
77 | JToolBar toolBar = new JToolBar();
78 | toolBar.setFloatable(false);
79 |
80 | JButton openButton = new JButton("Open");
81 | JButton saveButton = new JButton("Save");
82 | JButton loadButton = new JButton("Load");
83 | toolBar.add(openButton);
84 | toolBar.add(saveButton);
85 | toolBar.add(loadButton);
86 |
87 | JButton helpButton = new JButton("Help");
88 | toolBar.add(Box.createHorizontalGlue());
89 | toolBar.add(helpButton);
90 |
91 | JButton aboutButton = new JButton("About");
92 | toolBar.add(aboutButton);
93 |
94 | // Add action listeners for the buttons here if needed
95 |
96 | mainFrame.add(toolBar, BorderLayout.NORTH);
97 |
98 | // Help button action
99 | helpButton.addActionListener(e -> showHelpDialog());
100 |
101 | // About button action
102 | aboutButton.addActionListener(e -> showAboutDialog());
103 |
104 | //Open button action
105 | openButton.addActionListener(e -> openWebsite("https://google.com")); // Replace with your desired URL
106 |
107 | saveButton.addActionListener(e -> saveData());
108 |
109 | saveButton.addActionListener(e -> saveData());
110 |
111 | // Add ActionListener to the "Load" button
112 | loadButton.addActionListener(e -> loadData());
113 | }
114 |
115 | private static void showHelpDialog() {
116 | JOptionPane.showMessageDialog(null,
117 | "Help content goes here.",
118 | "Help",
119 | JOptionPane.INFORMATION_MESSAGE);
120 | }
121 |
122 | private static void showAboutDialog() {
123 | JOptionPane.showMessageDialog(null,
124 | "Tag Replacement Tool\nVersion 1.0\nAuthor: Your Name",
125 | "About",
126 | JOptionPane.INFORMATION_MESSAGE);
127 | }
128 |
129 |
130 | private void createInputPanel() {
131 | JPanel inputPanel = new JPanel(new FlowLayout());
132 | JLabel moNameLabel = new JLabel("Select mo_name:");
133 | moNameComboBox = new JComboBox<>(tr.getMoNames());
134 | moNameComboBox.setEditable(true);
135 | JButton processButton = new JButton("Process");
136 | inputPanel.add(moNameLabel);
137 | inputPanel.add(moNameComboBox);
138 | inputPanel.add(processButton);
139 |
140 | // Add action listener for the "Process" button
141 | processButton.addActionListener(e -> processMoContent());
142 |
143 | mainFrame.add(inputPanel, BorderLayout.CENTER);
144 | }
145 |
146 | private void createOutputPanel() {
147 | outputArea = new JTextArea(20, 50);
148 | outputArea.setEditable(false);
149 | outputArea.setFont(new Font("Monospaced", Font.BOLD, 14));
150 | JScrollPane outputScrollPane = new JScrollPane(outputArea);
151 | mainFrame.add(outputScrollPane, BorderLayout.SOUTH);
152 | }
153 |
154 |
155 | @SuppressWarnings("static-access")
156 | private void processMoContent() {
157 | String moName = moNameComboBox.getSelectedItem().toString();
158 | StringBuilder resultBuilder = new StringBuilder();
159 |
160 | // Check if the selected mo name exists in the database
161 | if (!tr.isMoNameExists(moName)) {
162 | JOptionPane.showMessageDialog(mainFrame, "The selected mo_name does not exist in the database.",
163 | "Error", JOptionPane.ERROR_MESSAGE);
164 | return;
165 | }
166 |
167 |
168 | try (Connection conn = DriverManager.getConnection(tr.getDB_URL(), tr.getUSER(), tr.getPASS())) {
169 | tr.createTables();
170 | String moContent = tr.getMoContent(moName);
171 | List tags = tr.extractTags(moContent);
172 |
173 | for (String tag : tags) {
174 | String tagName = tr.getTagName(tag);
175 | String tagComment = tr.getTagComment(tagName);
176 | resultBuilder.append("Mo Name: ").append(moName).append("\n");
177 | resultBuilder.append("Tag Name: ").append(tagName).append("\n");
178 | resultBuilder.append("Tag Comment: ").append(tagComment).append("\n");
179 |
180 | String replacementText = showInputDialogWithInfo("Enter replacement text for the tag '" + tagName + "':",
181 | moName, tagName, tagComment);
182 |
183 | if (replacementText.equals("__ABORT__")) {
184 | break; // Abort tag replacement for this mo_name
185 | }
186 |
187 | moContent = moContent.replace(tag, replacementText);
188 | }
189 |
190 | showFinalContentWindow(moContent);
191 | outputArea.setText(resultBuilder.toString());
192 |
193 | } catch (SQLException se) {
194 | se.printStackTrace();
195 | } finally {
196 | }
197 | }
198 |
199 |
200 | // Implement the custom dialog logic here
201 | private static String showInputDialogWithInfo(String message, String moName, String tagName, String tagComment) {
202 | JPanel panel = new JPanel(new GridLayout(0, 1));
203 | panel.add(new JLabel("Mo Name: " + moName));
204 | panel.add(new JLabel("Tag Name: " + tagName));
205 | panel.add(new JLabel("\nTag Comments: "));
206 |
207 | JTextArea commentArea = new JTextArea(tagComment);
208 | commentArea.setEditable(false);
209 | JScrollPane commentScrollPane = new JScrollPane(commentArea);
210 | panel.add(commentScrollPane);
211 | panel.add(new JLabel("\n\nReplacement: "));
212 | JTextField textField = new JTextField(20);
213 | panel.add(textField);
214 |
215 | JButton abortButton = new JButton("Abort");
216 | panel.add(abortButton);
217 |
218 | int result = JOptionPane.showOptionDialog(null, panel, message, JOptionPane.OK_CANCEL_OPTION,
219 | JOptionPane.PLAIN_MESSAGE, null, null, null);
220 |
221 | if (result == JOptionPane.OK_OPTION) {
222 | return textField.getText();
223 | } else if (result == JOptionPane.CANCEL_OPTION) {
224 | // Return a special value to indicate "Abort" button was clicked
225 | return "__ABORT__";
226 | } else {
227 | return "";
228 | }
229 | }
230 |
231 |
232 |
233 | // Implement the final content window logic here
234 | private static void showFinalContentWindow(String moContent) {
235 | JFrame finalContentFrame = new JFrame("Final Content");
236 | finalContentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
237 | finalContentFrame.setLayout(new BorderLayout());
238 |
239 | // Final content panel
240 | JTextArea finalContentArea = new JTextArea(moContent);
241 | finalContentArea.setFont(new Font("Monospaced", Font.BOLD, 14));
242 | finalContentArea.setEditable(true);
243 | JScrollPane finalContentScrollPane = new JScrollPane(finalContentArea);
244 |
245 | // Add a popup menu to the final content area
246 | JPopupMenu popupMenu = new JPopupMenu();
247 | JMenuItem copyItem = new JMenuItem("Copy");
248 | JMenuItem editItem = new JMenuItem("Edit");
249 | popupMenu.add(copyItem);
250 | popupMenu.add(editItem);
251 |
252 | finalContentArea.setComponentPopupMenu(popupMenu);
253 |
254 | // "Copy" action to copy the content to the clipboard
255 | copyItem.addActionListener(e -> {
256 | StringSelection selection = new StringSelection(finalContentArea.getText());
257 | Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
258 | clipboard.setContents(selection, null);
259 | });
260 |
261 | // "Edit" action to enable editing of the content
262 | editItem.addActionListener(e -> finalContentArea.setEditable(true));
263 |
264 | // Disable editing when the popup menu is closed
265 | popupMenu.addPopupMenuListener(new PopupMenuListener() {
266 | @Override
267 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
268 | // Do nothing
269 | }
270 |
271 | @Override
272 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
273 | finalContentArea.setEditable(false);
274 | }
275 |
276 | @Override
277 | public void popupMenuCanceled(PopupMenuEvent e) {
278 | // Do nothing
279 | }
280 | });
281 |
282 | finalContentFrame.add(finalContentScrollPane, BorderLayout.CENTER);
283 | finalContentFrame.setPreferredSize(new Dimension(800, 600));
284 | finalContentFrame.pack();
285 | // Center the final content window on the screen
286 | finalContentFrame.setLocationRelativeTo(null);
287 | finalContentFrame.setVisible(true);
288 | }
289 |
290 | // ... (unchanged)
291 |
292 | private void openWebsite(String url) {
293 | try {
294 | // Use Desktop to open the default web browser
295 | if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
296 | Desktop.getDesktop().browse(new URI(url));
297 | } else {
298 | JOptionPane.showMessageDialog(mainFrame, "Opening the default web browser is not supported on this platform.",
299 | "Error", JOptionPane.ERROR_MESSAGE);
300 | }
301 | } catch (Exception ex) {
302 | ex.printStackTrace();
303 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while trying to open the website.",
304 | "Error", JOptionPane.ERROR_MESSAGE);
305 | }
306 | }
307 |
308 | private void saveData() {
309 | try {
310 | // Get the current state of the application data
311 | String moName = Objects.requireNonNull(moNameComboBox.getSelectedItem()).toString();
312 | String moContent = outputArea.getText();
313 |
314 | // Choose the save file location using JFileChooser with custom file filter
315 | JFileChooser fileChooser = new JFileChooser();
316 | fileChooser.setFileFilter(new TRTFileFilter());
317 |
318 | int returnValue = fileChooser.showSaveDialog(mainFrame);
319 |
320 | if (returnValue == JFileChooser.APPROVE_OPTION) {
321 | File selectedFile = fileChooser.getSelectedFile();
322 | if (!selectedFile.getAbsolutePath().toLowerCase().endsWith(".trt")) {
323 | selectedFile = new File(selectedFile.getAbsolutePath() + ".trt");
324 | }
325 |
326 | if (selectedFile.exists()) {
327 | // File already exists, ask for confirmation to overwrite
328 | int overwriteConfirmation = JOptionPane.showConfirmDialog(mainFrame,
329 | "The selected file already exists. Do you want to overwrite it?",
330 | "File Exists", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
331 |
332 | if (overwriteConfirmation == JOptionPane.NO_OPTION) {
333 | // User chose not to overwrite, return without saving
334 | return;
335 | }
336 | }
337 |
338 | // Write the data to the selected file in custom save file format
339 | try (PrintWriter writer = new PrintWriter(selectedFile)) {
340 | writer.println("MO_NAME:" + moName);
341 | writer.println("MO_CONTENT:");
342 | writer.println(moContent);
343 | writer.flush();
344 | }
345 |
346 | JOptionPane.showMessageDialog(mainFrame, "Data saved successfully!",
347 | "Save", JOptionPane.INFORMATION_MESSAGE);
348 | }
349 | } catch (Exception ex) {
350 | ex.printStackTrace();
351 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while saving the data.",
352 | "Error", JOptionPane.ERROR_MESSAGE);
353 | }
354 | }
355 |
356 | private void loadData() {
357 | try {
358 | // Choose the file to load data from using JFileChooser with custom file filter
359 | JFileChooser fileChooser = new JFileChooser();
360 | fileChooser.setFileFilter(new TRTFileFilter());
361 |
362 | int returnValue = fileChooser.showOpenDialog(mainFrame);
363 |
364 | if (returnValue == JFileChooser.APPROVE_OPTION) {
365 | File selectedFile = fileChooser.getSelectedFile();
366 |
367 | // Read the data from the selected file in custom save file format
368 | try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) {
369 | StringBuilder moContentBuilder = new StringBuilder();
370 | String line;
371 | boolean readingMoContent = false;
372 |
373 | while ((line = reader.readLine()) != null) {
374 | if (line.startsWith("MO_NAME:")) {
375 | moNameComboBox.setSelectedItem(line.substring(8));
376 | } else if (line.startsWith("MO_CONTENT:")) {
377 | readingMoContent = true;
378 | } else if (readingMoContent) {
379 | moContentBuilder.append(line).append("\n");
380 | }
381 | }
382 |
383 | // Set the loaded MO content to the output area
384 | outputArea.setText(moContentBuilder.toString());
385 |
386 | JOptionPane.showMessageDialog(mainFrame, "Data loaded successfully!",
387 | "Load", JOptionPane.INFORMATION_MESSAGE);
388 | }
389 | }
390 | } catch (Exception ex) {
391 | ex.printStackTrace();
392 | JOptionPane.showMessageDialog(mainFrame, "An error occurred while loading the data.",
393 | "Error", JOptionPane.ERROR_MESSAGE);
394 | }
395 | }
396 |
397 | // Custom file filter for ".trt" files
398 | private class TRTFileFilter extends javax.swing.filechooser.FileFilter {
399 | public boolean accept(File file) {
400 | return file.isDirectory() || file.getName().toLowerCase().endsWith(".trt");
401 | }
402 |
403 | public String getDescription() {
404 | return "Tag Replacement Tool Files (*.trt)";
405 | }
406 | }
407 |
408 |
409 |
410 | }
--------------------------------------------------------------------------------
/src/main/java/com/tagger/tagger.sql:
--------------------------------------------------------------------------------
1 | -- --------------------------------------------------------
2 | -- Host: 127.0.0.1
3 | -- Server version: 8.0.30 - MySQL Community Server - GPL
4 | -- Server OS: Win64
5 | -- HeidiSQL Version: 12.1.0.6537
6 | -- --------------------------------------------------------
7 |
8 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
9 | /*!40101 SET NAMES utf8 */;
10 | /*!50503 SET NAMES utf8mb4 */;
11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12 | /*!40103 SET TIME_ZONE='+00:00' */;
13 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
14 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
15 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
16 |
17 |
18 | -- Dumping database structure for mydb
19 | DROP DATABASE IF EXISTS `mydb`;
20 | CREATE DATABASE IF NOT EXISTS `mydb` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
21 | USE `mydb`;
22 |
23 | -- Dumping structure for table mydb.table1
24 | DROP TABLE IF EXISTS `table1`;
25 | CREATE TABLE IF NOT EXISTS `table1` (
26 | `mo_name` varchar(15) NOT NULL,
27 | `mo_content` text,
28 | `mo_tags` text,
29 | PRIMARY KEY (`mo_name`)
30 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
31 |
32 | -- Dumping data for table mydb.table1: ~7 rows (approximately)
33 | DELETE FROM `table1`;
34 | INSERT INTO `table1` (`mo_name`, `mo_content`, `mo_tags`) VALUES
35 | ('mo_bstc', 'A registration was started online to set up an APE account.The account was activated. The seller listed {#tag_prodcat} priced {#tag_abatbe} their current market value A review of the account showed that the seller also controlled {#tag_singmul}, . {#tag_singmultt} used to place orders with the seller account.{#tag_ishnr} {#tag_isactiveall} {#tag_isactivesm} {#tag_isblocked} ', 'tag_prodcat,tag_abatbe,tag_singmul,tag_singmultt,tag_ishnr,tag_isactiveall,tag_isactivesm,tag_isblocked'),
36 | ('mo1', '{#tag1 this a tag} original mo content {#tag2 this is another tag} Some more content', 'tag1,tag2'),
37 | ('mo2', 'original mo content {#tag3 this a tag} Some more content', 'tag3'),
38 | ('mo2ss', 'original mo content {#tag3 this a tag} Some more content', 'tag3'),
39 | ('mo3', 'hi there {#tag_prodcat originalcontentss}', 'tag_prodcat'),
40 | ('mo4', 'A registration was started online to set up an APE account.\r\n\r\nThe account was activated. The seller listed {#tag_prodcat ss} priced {#tag_abatbe ss} their current market value.\r\n\r\nA review of the account showed that the seller also controlled {#tag_singmul ss}, {#tag_singmultt ss} used to place orders with the seller account.\r\n\r\n{#tag_ishnr ss} .\r\n\r\n{#tag_isactiveall ss} {#tag_isactivesm ss} {#tag_isblocked ss} .', 'tag_prodcat,tag_abatbe,tag_singmul,tag_singmultt,tag_ishnr,tag_isactiveall,tag_isactivesm,tag_isblocked'),
41 | ('mo5', 'original mo content {#tag_mytag this a tag /this,that/ notthis} Some more content', 'tag_mytag');
42 |
43 | -- Dumping structure for table mydb.table2
44 | DROP TABLE IF EXISTS `table2`;
45 | CREATE TABLE IF NOT EXISTS `table2` (
46 | `mo_tags` varchar(15) NOT NULL,
47 | `tag_comment` text,
48 | PRIMARY KEY (`mo_tags`)
49 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
50 |
51 | -- Dumping data for table mydb.table2: ~12 rows (approximately)
52 | DELETE FROM `table2`;
53 | INSERT INTO `table2` (`mo_tags`, `tag_comment`) VALUES
54 | ('tag_abatbe', 'Pricing Above / at / below'),
55 | ('tag_isactiveall', 'The APE account is active on the Amazon EU online stores'),
56 | ('tag_isactivesm', 'The APE account is active on the Amazon online stores'),
57 | ('tag_isblocked', 'The APE account is currently blocked on the ONLINE STORES ONLY online store(s). '),
58 | ('tag_ishnr', 'Additionally, these items did not appear to have been sent to the related buyer [#account./accounts.#] '),
59 | ('tag_mytag', 'i am tag_mytag'),
60 | ('tag_prodcat', 'Type the Product Categries'),
61 | ('tag_singmul', '[#multiple buyer accounts/a buyer account#]'),
62 | ('tag_singmultt', '[#These buyer accounts were/This buyer account was#] '),
63 | ('tag1', 'I am tag 1'),
64 | ('tag2', 'I am tag 2'),
65 | ('tag3', 'I am tag3 ');
66 |
67 | /*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
68 | /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
69 | /*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
70 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
71 | /*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
72 |
--------------------------------------------------------------------------------
/tagger.sql:
--------------------------------------------------------------------------------
1 | -- MySQL Schema Generated using HeidiSQL
2 |
3 | -- --------------------------------------------------------
4 | -- Host: 127.0.0.1 / localhost
5 | -- Server version: 8.0.30 - MySQL Community Server - GPL
6 | -- Server OS: Win64
7 | -- HeidiSQL Version: 12.1.0.6537
8 | -- --------------------------------------------------------
9 |
10 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
11 | /*!40101 SET NAMES utf8 */;
12 | /*!50503 SET NAMES utf8mb4 */;
13 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
14 | /*!40103 SET TIME_ZONE='+00:00' */;
15 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
16 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
17 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
18 |
19 |
20 | -- Dumping database structure for mydb
21 | DROP DATABASE IF EXISTS `mydb`;
22 | CREATE DATABASE IF NOT EXISTS `mydb` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
23 | USE `mydb`;
24 |
25 | -- Dumping structure for table mydb.table1
26 | DROP TABLE IF EXISTS `table1`;
27 | CREATE TABLE IF NOT EXISTS `table1` (
28 | `mo_name` varchar(15) NOT NULL,
29 | `mo_content` text,
30 | `mo_tags` text,
31 | PRIMARY KEY (`mo_name`)
32 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
33 |
34 | -- Dumping data for table mydb.table1: ~7 rows (approximately)
35 | DELETE FROM `table1`;
36 | INSERT INTO `table1` (`mo_name`, `mo_content`, `mo_tags`) VALUES
37 | ('mo_bstc', 'A registration was started online to set up an APE account.The account was activated. The seller listed {#tag_prodcat} priced {#tag_abatbe} their current market value A review of the account showed that the seller also controlled {#tag_singmul}, . {#tag_singmultt} used to place orders with the seller account.{#tag_ishnr} {#tag_isactiveall} {#tag_isactivesm} {#tag_isblocked} ', 'tag_prodcat,tag_abatbe,tag_singmul,tag_singmultt,tag_ishnr,tag_isactiveall,tag_isactivesm,tag_isblocked'),
38 | ('mo1', '{#tag1 this a tag} original mo content {#tag2 this is another tag} Some more content', 'tag1,tag2'),
39 | ('mo2', 'original mo content {#tag3 this a tag} Some more content', 'tag3'),
40 | ('mo2ss', 'original mo content {#tag3 this a tag} Some more content', 'tag3'),
41 | ('mo3', 'hi there {#tag_prodcat originalcontentss}', 'tag_prodcat'),
42 | ('mo4', 'A registration was started online to set up an APE account.\r\n\r\nThe account was activated. The seller listed {#tag_prodcat ss} priced {#tag_abatbe ss} their current market value.\r\n\r\nA review of the account showed that the seller also controlled {#tag_singmul ss}, {#tag_singmultt ss} used to place orders with the seller account.\r\n\r\n{#tag_ishnr ss} .\r\n\r\n{#tag_isactiveall ss} {#tag_isactivesm ss} {#tag_isblocked ss} .', 'tag_prodcat,tag_abatbe,tag_singmul,tag_singmultt,tag_ishnr,tag_isactiveall,tag_isactivesm,tag_isblocked'),
43 | ('mo5', 'original mo content {#tag_mytag this a tag /this,that/ notthis} Some more content', 'tag_mytag');
44 |
45 | -- Dumping structure for table mydb.table2
46 | DROP TABLE IF EXISTS `table2`;
47 | CREATE TABLE IF NOT EXISTS `table2` (
48 | `mo_tags` varchar(15) NOT NULL,
49 | `tag_comment` text,
50 | PRIMARY KEY (`mo_tags`)
51 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
52 |
53 | -- Dumping data for table mydb.table2: ~12 rows (approximately)
54 | DELETE FROM `table2`;
55 | INSERT INTO `table2` (`mo_tags`, `tag_comment`) VALUES
56 | ('tag_abatbe', 'Pricing Above / at / below'),
57 | ('tag_isactiveall', 'The APE account is active on the Amazon EU online stores'),
58 | ('tag_isactivesm', 'The APE account is active on the Amazon online stores'),
59 | ('tag_isblocked', 'The APE account is currently blocked on the ONLINE STORES ONLY online store(s). '),
60 | ('tag_ishnr', 'Additionally, these items did not appear to have been sent to the related buyer [#account./accounts.#] '),
61 | ('tag_mytag', 'i am tag_mytag'),
62 | ('tag_prodcat', 'Type the Product Categries'),
63 | ('tag_singmul', '[#multiple buyer accounts/a buyer account#]'),
64 | ('tag_singmultt', '[#These buyer accounts were/This buyer account was#] '),
65 | ('tag1', 'I am tag 1'),
66 | ('tag2', 'I am tag 2'),
67 | ('tag3', 'I am tag3 ');
68 |
69 | /*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
70 | /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
71 | /*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
72 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
73 | /*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
74 |
--------------------------------------------------------------------------------
/trtconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "DB_URL": "jdbc:mysql://localhost/mydb",
3 | "USER": "root",
4 | "PASS": "",
5 | "DB_NAME": "mydb",
6 | "TABLE1_NAME": "table1",
7 | "TABLE2_NAME": "table2"
8 | }
--------------------------------------------------------------------------------