-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e08abdf
Showing
6 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.6.4" level="project" /> | ||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.0.13" level="project" /> | ||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.0.13" level="project" /> | ||
<orderEntry type="library" name="Maven: org.jsoup:jsoup:1.7.2" level="project" /> | ||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>ru.devsaider</groupId> | ||
<artifactId>TFMXMLParser</artifactId> | ||
<version>1.0</version> | ||
|
||
<properties> | ||
<slf4j.version>1.6.4</slf4j.version> | ||
<logback.version>1.0.13</logback.version> | ||
|
||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>${logback.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jsoup</groupId> | ||
<artifactId>jsoup</artifactId> | ||
<version>1.7.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.4</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ru.devsaider.tfmxml.SimpleFetchForm"> | ||
<grid id="27dc6" binding="SimpleFetchForm" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<xy x="20" y="20" width="273" height="95"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none" title="Input a code"/> | ||
<children> | ||
<component id="9d87b" class="javax.swing.JButton" binding="OKButton" default-binding="true"> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="OK"/> | ||
</properties> | ||
</component> | ||
<component id="14a2e" class="javax.swing.JTextField" binding="textField1" default-binding="true"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> | ||
<preferred-size width="150" height="-1"/> | ||
</grid> | ||
</constraints> | ||
<properties/> | ||
</component> | ||
</children> | ||
</grid> | ||
<inspectionSuppressions> | ||
<suppress inspection="SpellCheckingInspection" id="27dc6"/> | ||
</inspectionSuppressions> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ru.devsaider.tfmxml; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.datatransfer.Clipboard; | ||
import java.awt.datatransfer.StringSelection; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author Ruslan Devsaider <[email protected]> | ||
*/ | ||
public class SimpleFetchForm { | ||
|
||
private JButton OKButton; | ||
private JPanel SimpleFetchForm; | ||
private JTextField textField1; | ||
|
||
public static void main(String[] args) { | ||
JFrame frame = new JFrame("Devsaider's XML parser"); | ||
SimpleFetchForm sff = new SimpleFetchForm(); | ||
|
||
sff.OKButton.addActionListener((ae) -> { | ||
try { | ||
String finalXML; | ||
String mapCodeRaw = sff.textField1.getText().replace("@", ""); | ||
if (StringUtils.isNumeric(mapCodeRaw) && (finalXML = XMLParser.fetchSingle(Integer.parseInt(mapCodeRaw))) != null) { | ||
StringSelection selection = new StringSelection(finalXML); | ||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | ||
clipboard.setContents(selection, selection); | ||
|
||
JOptionPane.showMessageDialog(null, "XML code was copied to your clipboard"); | ||
} else { | ||
JOptionPane.showMessageDialog(null, "Invalid XML code"); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}); | ||
frame.setLocationRelativeTo(null); | ||
frame.setPreferredSize(new Dimension(300, 125)); | ||
|
||
frame.setContentPane(sff.SimpleFetchForm); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.pack(); | ||
frame.setVisible(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package ru.devsaider.tfmxml; | ||
|
||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.net.URLDecoder; | ||
import java.util.Base64; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* @author Ruslan Devsaider <[email protected]> | ||
*/ | ||
|
||
public class XMLParser { | ||
private final static Logger logger = LoggerFactory.getLogger(XMLParser.class); | ||
private final static String CRYPT_KEY = "59A[XG^znsqsq8v{`Xhp3P9G"; | ||
|
||
public static void main(String[] args) throws IOException { | ||
} | ||
|
||
public static String fetchSingle(int mapCode) throws IOException { | ||
Document doc = Jsoup.connect("http://api.micetigri.fr/maps/@" + String.valueOf(mapCode)) | ||
.userAgent("Devsaider XML parser/1.0") | ||
.get(); | ||
String cryptedXML; | ||
Pattern p = Pattern.compile("(?is)map:\"(.*?)\","); | ||
Matcher m = p.matcher(doc.html()); | ||
|
||
if (m.find() && !(cryptedXML = URLDecoder.decode(m.group(1), "UTF-8")).equals("")) { | ||
String finalXML = XMLParser.decrypt(cryptedXML, CRYPT_KEY); | ||
File file = new File("cache/" + String.valueOf(mapCode) + ".xml"); | ||
|
||
// if file doesn't exists, then create it | ||
if (!file.exists()) { | ||
file.getParentFile().mkdir(); | ||
file.createNewFile(); | ||
} | ||
|
||
FileWriter fw = new FileWriter(file.getAbsoluteFile()); | ||
BufferedWriter bw = new BufferedWriter(fw); | ||
bw.write(finalXML); | ||
bw.close(); | ||
return finalXML; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static String decrypt(String cryptedXML, String key) throws IOException { | ||
int c; | ||
String finalXML = ""; | ||
byte[] str = Base64.getDecoder().decode(cryptedXML); | ||
for (int i = 0; i < str.length; i++) { | ||
c = str[i]; | ||
c -= key.charAt((i + 1) % key.length()); | ||
finalXML += (char) (c & 255); | ||
} | ||
|
||
return finalXML; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: ru.devsaider.tfmxml.SimpleFetchForm | ||
|