Skip to content

Commit

Permalink
init save
Browse files Browse the repository at this point in the history
  • Loading branch information
libang committed Sep 28, 2017
1 parent 119ca5b commit 07de366
Show file tree
Hide file tree
Showing 8 changed files with 502 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Compiled class file
*.class

out
.DS_store
# Log file
*.log

.idea
# BlueJ files
*.ctxt

Expand Down
12 changes: 12 additions & 0 deletions sjtu.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

4 changes: 4 additions & 0 deletions sjtu.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
path.variable.kotlin_bundled=/Applications/IntelliJ IDEA.app/Contents/plugins/Kotlin/kotlinc
path.variable.maven_repository=/Users/mosaice/.m2/repository
jdk.home.1.8=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home
javac2.instrumentation.includeJavaRuntime=false
252 changes: 252 additions & 0 deletions sjtu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="sjtu" default="all">


<property file="sjtu.properties"/>
<!-- Uncomment the following property if no tests compilation is needed -->
<!--
<property name="skip.tests" value="true"/>
-->

<!-- Compiler options -->

<property name="compiler.debug" value="on"/>
<property name="compiler.generate.no.warnings" value="off"/>
<property name="compiler.args" value=""/>
<property name="compiler.max.memory" value="700m"/>
<patternset id="ignored.files">
<exclude name="**/*.hprof/**"/>
<exclude name="**/*.pyc/**"/>
<exclude name="**/*.pyo/**"/>
<exclude name="**/*.rbc/**"/>
<exclude name="**/*.yarb/**"/>
<exclude name="**/*~/**"/>
<exclude name="**/.DS_Store/**"/>
<exclude name="**/.git/**"/>
<exclude name="**/.hg/**"/>
<exclude name="**/.svn/**"/>
<exclude name="**/CVS/**"/>
<exclude name="**/__pycache__/**"/>
<exclude name="**/_svn/**"/>
<exclude name="**/vssver.scc/**"/>
<exclude name="**/vssver2.scc/**"/>
</patternset>
<patternset id="library.patterns">
<include name="*.egg"/>
<include name="*.jar"/>
<include name="*.ear"/>
<include name="*.swc"/>
<include name="*.war"/>
<include name="*.ane"/>
<include name="*.zip"/>
</patternset>
<patternset id="compiler.resources">
<exclude name="**/?*.java"/>
<exclude name="**/?*.form"/>
<exclude name="**/?*.class"/>
<exclude name="**/?*.groovy"/>
<exclude name="**/?*.scala"/>
<exclude name="**/?*.flex"/>
<exclude name="**/?*.kt"/>
<exclude name="**/?*.clj"/>
</patternset>

<!-- JDK definitions -->

<property name="jdk.bin.1.8" value="${jdk.home.1.8}/bin"/>
<path id="jdk.classpath.1.8">
<fileset dir="${jdk.home.1.8}">
<include name="jre/lib/charsets.jar"/>
<include name="jre/lib/deploy.jar"/>
<include name="jre/lib/ext/cldrdata.jar"/>
<include name="jre/lib/ext/dnsns.jar"/>
<include name="jre/lib/ext/jaccess.jar"/>
<include name="jre/lib/ext/jfxrt.jar"/>
<include name="jre/lib/ext/localedata.jar"/>
<include name="jre/lib/ext/nashorn.jar"/>
<include name="jre/lib/ext/sunec.jar"/>
<include name="jre/lib/ext/sunjce_provider.jar"/>
<include name="jre/lib/ext/sunpkcs11.jar"/>
<include name="jre/lib/ext/zipfs.jar"/>
<include name="jre/lib/javaws.jar"/>
<include name="jre/lib/jce.jar"/>
<include name="jre/lib/jfr.jar"/>
<include name="jre/lib/jfxswt.jar"/>
<include name="jre/lib/jsse.jar"/>
<include name="jre/lib/management-agent.jar"/>
<include name="jre/lib/plugin.jar"/>
<include name="jre/lib/resources.jar"/>
<include name="jre/lib/rt.jar"/>
<include name="lib/ant-javafx.jar"/>
<include name="lib/dt.jar"/>
<include name="lib/javafx-mx.jar"/>
<include name="lib/jconsole.jar"/>
<include name="lib/packager.jar"/>
<include name="lib/sa-jdi.jar"/>
<include name="lib/tools.jar"/>
</fileset>
</path>

<property name="project.jdk.home" value="${jdk.home.1.8}"/>
<property name="project.jdk.bin" value="${jdk.bin.1.8}"/>
<property name="project.jdk.classpath" value="jdk.classpath.1.8"/>
<!-- Register Custom Compiler Taskdefs -->
<property name="javac2.home" value="${idea.home}/lib"/>
<path id="javac2.classpath">
<pathelement location="${javac2.home}/javac2.jar"/>
<pathelement location="${javac2.home}/jdom.jar"/>
<pathelement location="${javac2.home}/asm-all.jar"/>
<pathelement location="${javac2.home}/jgoodies-forms.jar"/>
</path>
<target name="register.custom.compilers">
<taskdef name="javac2" classname="com.intellij.ant.Javac2" classpathref="javac2.classpath"/>
<taskdef name="instrumentIdeaExtensions" classname="com.intellij.ant.InstrumentIdeaExtensions" classpathref="javac2.classpath"/>
</target>

<!-- Modules -->


<!-- Module sjtu -->

<dirname property="module.sjtu.basedir" file="${ant.file}"/>


<property name="module.jdk.home.sjtu" value="${project.jdk.home}"/>
<property name="module.jdk.bin.sjtu" value="${project.jdk.bin}"/>
<property name="module.jdk.classpath.sjtu" value="${project.jdk.classpath}"/>

<property name="compiler.args.sjtu" value="-encoding UTF-8 -source 1.8 -target 1.8 ${compiler.args}"/>

<property name="sjtu.output.dir" value="${module.sjtu.basedir}/out/production/sjtu"/>
<property name="sjtu.testoutput.dir" value="${module.sjtu.basedir}/out/test/sjtu"/>

<path id="sjtu.module.bootclasspath">
<!-- Paths to be included in compilation bootclasspath -->
</path>

<path id="sjtu.module.production.classpath">
<path refid="${module.jdk.classpath.sjtu}"/>
</path>

<path id="sjtu.runtime.production.module.classpath">
<pathelement location="${sjtu.output.dir}"/>
</path>

<path id="sjtu.module.classpath">
<path refid="${module.jdk.classpath.sjtu}"/>
<pathelement location="${sjtu.output.dir}"/>
</path>

<path id="sjtu.runtime.module.classpath">
<pathelement location="${sjtu.testoutput.dir}"/>
<pathelement location="${sjtu.output.dir}"/>
</path>


<patternset id="excluded.from.module.sjtu">
<patternset refid="ignored.files"/>
</patternset>

<patternset id="excluded.from.compilation.sjtu">
<patternset refid="excluded.from.module.sjtu"/>
</patternset>

<path id="sjtu.module.sourcepath">
<dirset dir="${module.sjtu.basedir}">
<include name="src"/>
</dirset>
</path>


<target name="compile.module.sjtu" depends="compile.module.sjtu.production,compile.module.sjtu.tests" description="Compile module sjtu"/>

<target name="compile.module.sjtu.production" depends="register.custom.compilers" description="Compile module sjtu; production classes">
<mkdir dir="${sjtu.output.dir}"/>
<javac2 destdir="${sjtu.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true" executable="${module.jdk.bin.sjtu}/javac">
<compilerarg line="${compiler.args.sjtu}"/>
<bootclasspath refid="sjtu.module.bootclasspath"/>
<classpath refid="sjtu.module.production.classpath"/>
<src refid="sjtu.module.sourcepath"/>
<patternset refid="excluded.from.compilation.sjtu"/>
</javac2>

<copy todir="${sjtu.output.dir}">
<fileset dir="${module.sjtu.basedir}/src">
<patternset refid="compiler.resources"/>
<type type="file"/>
</fileset>
</copy>
</target>

<target name="compile.module.sjtu.tests" depends="register.custom.compilers,compile.module.sjtu.production" description="compile module sjtu; test classes" unless="skip.tests"/>

<target name="clean.module.sjtu" description="cleanup module">
<delete dir="${sjtu.output.dir}"/>
<delete dir="${sjtu.testoutput.dir}"/>
</target>

<target name="init" description="Build initialization">
<!-- Perform any build initialization in this target -->
</target>

<target name="clean" depends="clean.module.sjtu, clean.artifact.sjtu" description="cleanup all"/>

<target name="build.modules" depends="init, clean, compile.module.sjtu" description="build all modules"/>

<target name="init.artifacts">
<property name="artifacts.temp.dir" value="${basedir}/__artifacts_temp"/>
<property name="artifact.output.sjtu" value="${basedir}/out/artifacts/sjtu"/>
<mkdir dir="${artifacts.temp.dir}"/>
<property name="artifact.temp.output.sjtu" value="${artifacts.temp.dir}/sjtu.jar"/>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant" classpath="${jdk.home.1.8}/lib/ant-javafx.jar"/>
</target>

<target name="clean.artifact.sjtu" description="clean sjtu artifact output">
<delete dir="${artifact.output.sjtu}"/>
</target>

<target name="artifact.sjtu" depends="init.artifacts, compile.module.sjtu" description="Build &#39;sjtu&#39; artifact" xmlns:fx="javafx:com.sun.javafx.tools.ant">
<mkdir dir="${artifact.output.sjtu}"/>
<copy todir="${artifact.temp.output.sjtu}">
<fileset dir="${sjtu.output.dir}"/>
</copy>
<fx:fileset id="all_but_sjtu" dir="${artifact.temp.output.sjtu}" includes="**/*.jar">
<exclude name="sjtu.jar"/>
</fx:fileset>
<fx:fileset id="all_sjtu" dir="${artifact.temp.output.sjtu}" includes="**/*.jar"/>
<fx:application id="sjtu_id" name="sjtu" mainClass="sample.Main"/>
<fx:jar destfile="${artifact.temp.output.sjtu}/sjtu.jar">
<fx:application refid="sjtu_id"/>
<fileset dir="${artifact.temp.output.sjtu}" excludes="**/*.jar"/>
<fx:resources>
<fx:fileset refid="all_but_sjtu"/>
</fx:resources>
<manifest>
<attribute name="Implementation-Title" value="sjtu"/>
<attribute name="Implementation-Version" value=""/>
<attribute name="Implementation-Vendor" value="xiabi"/>
</manifest>
</fx:jar>
<fx:deploy width="600" height="400" updatemode="background" outdir="${artifact.temp.output.sjtu}/deploy" outfile="sjtu">
<fx:application refid="sjtu_id"/>
<fx:info title="sjtu" vendor="xiabi"/>
<fx:resources>
<fx:fileset refid="all_sjtu"/>
</fx:resources>
</fx:deploy>
<copy todir="${artifact.output.sjtu}">
<fileset dir="${artifact.temp.output.sjtu}/deploy"/>
</copy>
<delete includeemptydirs="true">
<fileset dir="${artifact.temp.output.sjtu}"/>
</delete>
</target>

<target name="build.all.artifacts" depends="artifact.sjtu" description="Build all artifacts">

<!-- Delete temporary files -->
<delete dir="${artifacts.temp.dir}"/>
</target>

<target name="all" depends="build.modules, build.all.artifacts" description="build all"/>
</project>
88 changes: 88 additions & 0 deletions src/sample/HttpRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package sample;

import com.oracle.javafx.jmx.json.JSONFactory;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HttpRequest {
private final String BASIC_URL = "http://www.onlinesjtu.com/SCEPlayer/Default.aspx";
private String studentid;
private String cookie;
private String term;

public void requestCourse(String courseid) {
try {
String addr = String.format("%s?studentid=%s&courseid=%s&termidentify=%s", this.BASIC_URL, this.studentid, courseid, this.term);
URL url = new URL(addr);

InputStream in = url.openStream();
InputStreamReader isr = new InputStreamReader(in);
BufferedReader buff = new BufferedReader(isr);
String str;
StringBuilder body = new StringBuilder();
while ((str = buff.readLine()) != null) {
body.append(str);
body.append("\n");
}
System.out.println("request over");
in.close();
isr.close();
buff.close();
System.out.println(url.toString());
String reg = "id=\"list-item-(\\d+)\"\\sclass=\"status-no\"";
Pattern p = Pattern.compile(reg);

Matcher m = p.matcher(body);
while (m.find()) {
String resouce = m.group(1);
this.attendCourse(resouce);
}
System.out.println("end");
} catch (IOException e) {
e.printStackTrace();
}
}

private void attendCourse (String resouce) {
try {
URL url = new URL(this.BASIC_URL + "/AddDacLog");
URLConnection conn = url.openConnection();

conn.setDoOutput(true);// 使用 URL 连接进行输出
conn.setDoInput(true);// 使用 URL 连接进行输入
conn.setUseCaches(false);// 忽略缓存
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
// conn.setRequestProperty("Charset", "UTF-8");
conn.setRequestProperty("Cookie", this.cookie);

PrintWriter out = new PrintWriter(conn.getOutputStream());
String jsonPayload = String.format("{\"resourceId\":\"%s\",\"studentId\":\"%s\"}", resouce, this.studentid);
System.out.println("START POST: " + jsonPayload);
out.print(jsonPayload);
out.close();

BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
StringBuilder body = new StringBuilder();
while ((line = reader.readLine()) != null) {
body.append(line + "\n");
}
reader.close();

} catch (IOException e) {
e.printStackTrace();
}
}

HttpRequest(String studentid, String cookie, String term) {
this.studentid = studentid;
this.cookie = cookie;
this.term = term;
}

}
23 changes: 23 additions & 0 deletions src/sample/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("sjtu");
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
}


public static void main(String[] args) {
launch(args);
}
}
Loading

0 comments on commit 07de366

Please sign in to comment.