Subversion Repositories XServices

Compare Revisions

No changes between revisions

Ignore whitespace Rev 122 → Rev 123

/xservices/tags/20130205r/src/java/net/brutex/xservices/util/CVSRoot.java
0,0 → 1,82
/* */ package net.brutex.xservices.util;
/* */
/* */ import java.io.BufferedReader;
/* */ import java.io.File;
/* */ import java.io.FileReader;
/* */ import java.io.IOException;
/* */ import java.io.PrintStream;
/* */
/* */ public class CVSRoot
/* */ {
/* */ public String connectionType;
/* */ public String user;
/* */ public String host;
/* */ public String repository;
/* */
/* */ public CVSRoot(String root)
/* */ throws IllegalArgumentException
/* */ {
/* 19 */ if (!root.startsWith(":")) {
/* 20 */ throw new IllegalArgumentException();
/* */ }
/* 22 */ int oldColonPosition = 0;
/* 23 */ int colonPosition = root.indexOf(':', 1);
/* 24 */ if (colonPosition == -1)
/* 25 */ throw new IllegalArgumentException();
/* 26 */ this.connectionType = root.substring(oldColonPosition + 1, colonPosition);
/* 27 */ oldColonPosition = colonPosition;
/* 28 */ colonPosition = root.indexOf('@', colonPosition + 1);
/* 29 */ if (colonPosition == -1)
/* 30 */ throw new IllegalArgumentException();
/* 31 */ this.user = root.substring(oldColonPosition + 1, colonPosition);
/* 32 */ oldColonPosition = colonPosition;
/* 33 */ colonPosition = root.indexOf(':', colonPosition + 1);
/* 34 */ if (colonPosition == -1)
/* 35 */ throw new IllegalArgumentException();
/* 36 */ this.host = root.substring(oldColonPosition + 1, colonPosition);
/* 37 */ this.repository = root.substring(colonPosition + 1);
/* 38 */ if ((this.connectionType == null) || (this.user == null) || (this.host == null) ||
/* 39 */ (this.repository == null))
/* 40 */ throw new IllegalArgumentException();
/* */ }
/* */
/* */ public String getCVSRoot(File directory) {
/* 44 */ String root = null;
/* 45 */ BufferedReader r = null;
/* */ try {
/* 47 */ File rootFile = new File(directory, "CVS/Root");
/* 48 */ if (rootFile.exists()) {
/* 49 */ r = new BufferedReader(new FileReader(rootFile));
/* 50 */ root = r.readLine();
/* */ }
/* */ }
/* */ catch (IOException localIOException1)
/* */ {
/* */ try {
/* 56 */ if (r != null)
/* 57 */ r.close();
/* */ } catch (IOException e) {
/* 59 */ System.err.println("Warning: could not close CVS/Root file!");
/* */ }
/* */ }
/* */ finally
/* */ {
/* */ try
/* */ {
/* 56 */ if (r != null)
/* 57 */ r.close();
/* */ } catch (IOException e) {
/* 59 */ System.err.println("Warning: could not close CVS/Root file!");
/* */ }
/* */ }
/* 62 */ if (root == null) {
/* 63 */ root = System.getProperty("cvs.root");
/* */ }
/* 65 */ return root;
/* */ }
/* */ }
 
/* Location: C:\Users\brosenberger\Documents\My Box Files\XBridgeNG-download\XServices-20130131 - Kopie\WEB-INF\classes\net.zip
* Qualified Name: net.brutex.xservices.util.CVSRoot
* JD-Core Version: 0.6.2
*/
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/BasicCVSListener.java
0,0 → 1,78
/* */ package net.brutex.xservices.util;
/* */
/* */ import java.io.PrintStream;
/* */ import org.netbeans.lib.cvsclient.event.BinaryMessageEvent;
/* */ import org.netbeans.lib.cvsclient.event.CVSListener;
/* */ import org.netbeans.lib.cvsclient.event.FileAddedEvent;
/* */ import org.netbeans.lib.cvsclient.event.FileInfoEvent;
/* */ import org.netbeans.lib.cvsclient.event.FileRemovedEvent;
/* */ import org.netbeans.lib.cvsclient.event.FileToRemoveEvent;
/* */ import org.netbeans.lib.cvsclient.event.FileUpdatedEvent;
/* */ import org.netbeans.lib.cvsclient.event.MessageEvent;
/* */ import org.netbeans.lib.cvsclient.event.ModuleExpansionEvent;
/* */ import org.netbeans.lib.cvsclient.event.TerminationEvent;
/* */
/* */ public abstract class BasicCVSListener
/* */ implements CVSListener
/* */ {
/* 24 */ private final StringBuffer taggedLine = new StringBuffer();
/* */
/* 26 */ private final boolean showEvents = true;
/* */
/* */ public void messageSent(MessageEvent e)
/* */ {
/* 36 */ String line = e.getMessage();
/* 37 */ PrintStream stream = e.isError() ? System.err :
/* 38 */ System.out;
/* */
/* 40 */ if (e.isTagged())
/* */ {
/* 42 */ String str1 = MessageEvent.parseTaggedMessage(this.taggedLine, line);
/* */ }
/* */ }
/* */
/* */ public void commandTerminated(TerminationEvent arg0)
/* */ {
/* 59 */ System.out.println("commandTerminated");
/* */ }
/* */
/* */ public void fileAdded(FileAddedEvent arg0)
/* */ {
/* 65 */ System.out.println("fileAdded");
/* */ }
/* */
/* */ public void fileInfoGenerated(FileInfoEvent arg0)
/* */ {
/* 71 */ System.out.println("fileInfoGenerated");
/* */ }
/* */
/* */ public void fileRemoved(FileRemovedEvent arg0)
/* */ {
/* 76 */ System.out.println("fileRemoved");
/* */ }
/* */
/* */ public void fileToRemove(FileToRemoveEvent arg0)
/* */ {
/* 82 */ System.out.println("fileToRemove");
/* */ }
/* */
/* */ public void fileUpdated(FileUpdatedEvent arg0)
/* */ {
/* 88 */ System.out.println("fileUpdated");
/* */ }
/* */
/* */ public void messageSent(BinaryMessageEvent arg0)
/* */ {
/* 94 */ System.out.println("messageSent_Binary");
/* */ }
/* */
/* */ public void moduleExpanded(ModuleExpansionEvent arg0)
/* */ {
/* 100 */ System.out.println("ModuleExpansionEvent");
/* */ }
/* */ }
 
/* Location: C:\Users\brosenberger\Documents\My Box Files\XBridgeNG-download\XServices-20130131 - Kopie\WEB-INF\classes\net.zip
* Qualified Name: net.brutex.xservices.util.BasicCVSListener
* JD-Core Version: 0.6.2
*/
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/BrutexHSQLQuartzConnectionProvider.java
0,0 → 1,181
/*
* Copyright 2011 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util;
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
 
 
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.quartz.utils.ConnectionProvider;
 
/**
* @author Brian Rosenberger
*
*/
public class BrutexHSQLQuartzConnectionProvider implements ConnectionProvider {
private Connection conn = null;
private final Logger logger = Logger.getLogger(this.getClass().getCanonicalName());
 
public Connection getConnection() throws SQLException {
if( conn!= null ) { // Todo: && conn.conn.isValid(5)) {
logger.debug("Checking tables on pre-exisiting database connection.");
checkTables();
return conn;
}
try {
// Class.forName("org.hsqldb.jdbc.JDBCDriver" );
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
} catch (Exception e) {
logger.fatal("Failed to load Derby JDBC driver.");
e.printStackTrace();
return null;
}
 
if(isConnected(false)) {
checkTables();
} else {
return null;
}
return conn;
}
 
public void shutdown() throws SQLException {
try {
// Class.forName("org.hsqldb.jdbc.JDBCDriver" );
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
} catch (Exception e) {
System.err.println("ERROR: failed to load Derby JDBC driver.");
e.printStackTrace();
return;
}
String t = this.getClass().getClassLoader().getResource("/").toString()
.substring(6);
t += "../data/db";
System.out.println("Shut down embedded database now.");
Connection c = DriverManager.getConnection("jdbc:derby:" + t
+ ";shutdown=true;");
 
}
 
private synchronized void recursiveDelete(File dbDir) {
File[] files = dbDir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
files[i].delete();
} else {
recursiveDelete(files[i]);
files[i].delete();
}
}
dbDir.delete();
}
private synchronized void checkTables() throws SQLException {
logger.debug("Checking QUARTZ database schema.");
if(!isConnected(false)) {
logger.error("Failed to validate QUARTZ database schema.");
return;
}
List<String> ddl_list = new ArrayList<String>(11);
ddl_list.add("QRTZ_JOB_DETAILS");
ddl_list.add("QRTZ_TRIGGERS");
ddl_list.add("QRTZ_SIMPLE_TRIGGERS");
ddl_list.add("QRTZ_CRON_TRIGGERS");
ddl_list.add("QRTZ_SIMPROP_TRIGGERS");
ddl_list.add("QRTZ_BLOB_TRIGGERS");
ddl_list.add("QRTZ_CALENDARS");
ddl_list.add("QRTZ_PAUSED_TRIGGER_GRPS");
ddl_list.add("QRTZ_FIRED_TRIGGERS");
ddl_list.add("QRTZ_SCHEDULER_STATE");
ddl_list.add("QRTZ_LOCKS");
String ddl = this.getClass().getClassLoader().getResource("/").toString()
.substring(6)+ "../data/";
 
DatabaseMetaData dmd = conn.getMetaData();
for (String tbl : ddl_list) {
ResultSet rs = dmd.getTables(null, "APP", tbl, null);
if (!rs.next()) {
logger.log(Level.INFO, "Adding DDL for table "+ tbl);
Statement st = conn.createStatement();
File ddlFile = new File(ddl + tbl + ".ddl");
String create = "";
try {
BufferedReader r = new BufferedReader(new FileReader(ddlFile));
while (r.ready()) {
create += r.readLine() + "\n";
}
create.trim();
if( st.execute(create)) {
logger.log(Level.INFO, "Table " + tbl + " created.");
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
logger.log(Level.ERROR, "Error executing statement "+ create );
System.out.println(ex.getMessage());
}
} else {
logger.trace("Table "+tbl+" exists.");
}
}
}
private synchronized boolean isConnected(boolean fail) throws SQLException {
if(conn!=null ) { // Todo: && conn.conn.isValid(5)) {) {
return true;
} else {
String t = this.getClass().getClassLoader().getResource("/").toString().substring(6); // WEB-INF/classes
t += "../data/db";
logger.debug("Database directory is set to '" + t + "'");
try {
this.conn = DriverManager.getConnection("jdbc:derby:" + t + ";create=true;");
} catch (SQLException ex) {
logger.error(ex.getMessage(), ex);
if(!fail) {
logger.warn("Deleting database directory.");
recursiveDelete(new File(t));
logger.warn("Retrying to connect to database.");
return isConnected(true);
} else {
return false;
}
}
}
return false;
}
}
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/XServicesDocumentation.java
0,0 → 1,71
/*
* Copyright 2011 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util;
 
/**
* Holds static documentation.
*
*
* @author Brian Rosenberger, bru@brutex.de
*/
public class XServicesDocumentation {
 
public static final String BRUTEX_COPYRIGHT = "" +
"/*\n" +
"* Copyright 2010 Brian Rosenberger (Brutex Network)\n" +
"*\n" +
"* Licensed under the Apache License, Version 2.0 (the \"License\")\n" +
"* you may not use this file except in compliance with the License.\n" +
"* You may obtain a copy of the License at\n" +
"*\n" +
"* http://www.apache.org/licenses/LICENSE-2.0\n" +
"*\n" +
"* Unless required by applicable law or agreed to in writing, software\n" +
"* distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
"* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
"* See the License for the specific language governing permissions and\n" +
"* limitations under the License.\n" +
"*/";
 
 
public static final String SERVICE_OPERATION_DOWNLOADFILE = "Download a file from the maschine where the service is running in order " +
"to process it with the client. The file is either downloaded as a MTOM attachment or " +
"as inline base64 encoded block. Keep in mind that unless you are using MTOM, a lot of " +
"java heap memory is used.";
public static final String SERVICE_OPERATION_UPLOADFILE = "Send a file from client to web service server using either " +
"MTOM attachment or base64 inline attachment.";
public static final String SERVICE_OPERATION_COPY = "Copies a fileset locally on the server.";
public static final String SERVICE_OPERATION_COPYFILE = "Copies a single file locally on the server";
public static final String SERVICE_OPERATION_LOADRESOURCE = "Load the content of a resource";
public static final String SERVICE_OPERATION_LOADRESOURCEFROMARCHIVE = "Load the content of a resource";
public static final String SERVICE_OPERATION_ECHOTOFILE = "Write or append a string to a file";
public static final String SERVICE_OPERATION_REPLACEINFILE = "Replaces every <pattern> with a string in an ascii file";
public static final String SERVICE_OPERATION_REPLACEINFILE2 = "Replaces every <pattern> with a string in an ascii file";
public static final String SERVICE_OPERATION_REPLACEINFILEREGEX = "Replaces every <regex pattern> with a string in an ascii file";
private XServicesDocumentation() {};
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/CVSClient.java
0,0 → 1,94
/* */ package net.brutex.xservices.util;
/* */
/* */ import java.io.File;
/* */ import net.brutex.xservices.types.scm.ItemType;
/* */ import net.brutex.xservices.ws.rs.CVSInfoImpl;
/* */ import org.apache.commons.configuration.Configuration;
/* */ import org.apache.commons.configuration.ConfigurationException;
/* */ import org.apache.commons.configuration.PropertiesConfiguration;
/* */ import org.apache.log4j.Logger;
/* */ import org.netbeans.lib.cvsclient.Client;
/* */ import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
/* */ import org.netbeans.lib.cvsclient.command.CommandAbortedException;
/* */ import org.netbeans.lib.cvsclient.command.GlobalOptions;
/* */ import org.netbeans.lib.cvsclient.connection.AuthenticationException;
/* */ import org.netbeans.lib.cvsclient.connection.PServerConnection;
/* */
/* */ public class CVSClient
/* */ {
/* */ private final File configfile;
/* */ private final PServerConnection connection;
/* */ private final CVSRoot root;
/* */ private final GlobalOptions globalOptions;
/* 41 */ final Logger logger = Logger.getLogger(CVSInfoImpl.class);
/* */ public final Client client;
/* */
/* */ public Client getClient()
/* */ {
/* 49 */ return this.client;
/* */ }
/* */
/* */ public CVSClient(File config) throws CommandAbortedException, AuthenticationException, ConfigurationException {
/* 53 */ System.setProperty("cvsClientLog", "c:/temp/cvs.log");
/* 54 */ if ((config == null) || (!config.exists()) || (config.isDirectory())) {
/* 55 */ throw new ConfigurationException("Config file not found");
/* */ }
/* 57 */ this.configfile = config;
/* 58 */ Configuration configuration = new PropertiesConfiguration(this.configfile);
/* */
/* 60 */ String cvsroot = configuration.getString("CVSROOT");
/* 61 */ String workdir = configuration.getString("WORKDIR");
/* 62 */ String password = configuration.getString("PASSWORD");
/* */
/* 64 */ this.root = new CVSRoot(cvsroot);
/* 65 */ this.globalOptions = new GlobalOptions();
/* 66 */ this.globalOptions.setCVSRoot(cvsroot);
/* */
/* 68 */ this.connection = new PServerConnection();
/* 69 */ this.connection.setUserName(this.root.user);
/* 70 */ if (password != null)
/* 71 */ this.connection.setEncodedPassword(CvsPassword.encode(password));
/* */ else {
/* 73 */ this.connection.setEncodedPassword(password);
/* */ }
/* */
/* 76 */ this.connection.setHostName(this.root.host);
/* 77 */ this.connection.setRepository(this.root.repository);
/* */ try {
/* 79 */ this.connection.open();
/* */ } catch (AuthenticationException ex) {
/* 81 */ this.logger.error(ex.getMessage());
/* */ }
/* */
/* 84 */ this.client = new Client(this.connection, new StandardAdminHandler());
/* 85 */ this.client.setLocalPath(workdir);
/* */ }
/* */
/* */ public File getConfigFile()
/* */ {
/* 91 */ return this.configfile;
/* */ }
/* */
/* */ public GlobalOptions getGlobalOptions() {
/* 95 */ return this.globalOptions;
/* */ }
/* */
/* */ public PServerConnection getConnection()
/* */ {
/* 101 */ return this.connection;
/* */ }
/* */
/* */ public CVSRoot getRoot()
/* */ {
/* 107 */ return this.root;
/* */ }
/* */
/* */ public static String generateID(ItemType item) {
/* 111 */ return "::[" + item.getRemotename() + "]";
/* */ }
/* */ }
 
/* Location: C:\Users\brosenberger\Documents\My Box Files\XBridgeNG-download\XServices-20130131 - Kopie\WEB-INF\classes\net.zip
* Qualified Name: net.brutex.xservices.util.CVSClient
* JD-Core Version: 0.6.2
*/
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/BrutexQuartzConnectionProvider.java
0,0 → 1,181
/*
* Copyright 2011 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util;
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
 
 
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.quartz.utils.ConnectionProvider;
 
/**
* @author Brian Rosenberger
*
*/
public class BrutexQuartzConnectionProvider implements ConnectionProvider {
private Connection conn = null;
private final Logger logger = Logger.getLogger(this.getClass().getCanonicalName());
 
public Connection getConnection() throws SQLException {
if( conn!= null) { // Todo: && conn.conn.isValid(5)) {) {
logger.debug("Checking tables on pre-exisiting database connection.");
checkTables();
return conn;
}
try {
// Class.forName("org.hsqldb.jdbc.JDBCDriver" );
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
} catch (Exception e) {
logger.fatal("Failed to load Derby JDBC driver.");
e.printStackTrace();
return null;
}
 
if(isConnected(false)) {
checkTables();
} else {
return null;
}
return conn;
}
 
public void shutdown() throws SQLException {
try {
// Class.forName("org.hsqldb.jdbc.JDBCDriver" );
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
} catch (Exception e) {
System.err.println("ERROR: failed to load Derby JDBC driver.");
e.printStackTrace();
return;
}
String t = this.getClass().getClassLoader().getResource("/").toString()
.substring(6);
t += "../data/db";
System.out.println("Shut down embedded database now.");
Connection c = DriverManager.getConnection("jdbc:derby:" + t
+ ";shutdown=true;");
 
}
 
private synchronized void recursiveDelete(File dbDir) {
File[] files = dbDir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
files[i].delete();
} else {
recursiveDelete(files[i]);
files[i].delete();
}
}
dbDir.delete();
}
private synchronized void checkTables() throws SQLException {
logger.debug("Checking QUARTZ database schema.");
if(!isConnected(false)) {
logger.error("Failed to validate QUARTZ database schema.");
return;
}
List<String> ddl_list = new ArrayList<String>(11);
ddl_list.add("QRTZ_JOB_DETAILS");
ddl_list.add("QRTZ_TRIGGERS");
ddl_list.add("QRTZ_SIMPLE_TRIGGERS");
ddl_list.add("QRTZ_CRON_TRIGGERS");
ddl_list.add("QRTZ_SIMPROP_TRIGGERS");
ddl_list.add("QRTZ_BLOB_TRIGGERS");
ddl_list.add("QRTZ_CALENDARS");
ddl_list.add("QRTZ_PAUSED_TRIGGER_GRPS");
ddl_list.add("QRTZ_FIRED_TRIGGERS");
ddl_list.add("QRTZ_SCHEDULER_STATE");
ddl_list.add("QRTZ_LOCKS");
String ddl = this.getClass().getClassLoader().getResource("/").toString()
.substring(6)+ "../data/";
 
DatabaseMetaData dmd = conn.getMetaData();
for (String tbl : ddl_list) {
ResultSet rs = dmd.getTables(null, "APP", tbl, null);
if (!rs.next()) {
logger.log(Level.INFO, "Adding DDL for table "+ tbl);
Statement st = conn.createStatement();
File ddlFile = new File(ddl + tbl + ".ddl");
String create = "";
try {
BufferedReader r = new BufferedReader(new FileReader(ddlFile));
while (r.ready()) {
create += r.readLine() + "\n";
}
create.trim();
if( st.execute(create)) {
logger.log(Level.INFO, "Table " + tbl + " created.");
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
logger.log(Level.ERROR, "Error executing statement "+ create );
System.out.println(ex.getMessage());
}
} else {
logger.trace("Table "+tbl+" exists.");
}
}
}
private synchronized boolean isConnected(boolean fail) throws SQLException {
if(conn!=null ) { // Todo: && conn.conn.isValid(5)) {) {
return true;
} else {
String t = this.getClass().getClassLoader().getResource("/").toString().substring(6); // WEB-INF/classes
t += "../data/db";
logger.debug("Database directory is set to '" + t + "'");
try {
this.conn = DriverManager.getConnection("jdbc:derby:" + t + ";create=true;");
} catch (SQLException ex) {
logger.error(ex.getMessage(), ex);
if(!fail) {
logger.warn("Deleting database directory.");
recursiveDelete(new File(t));
logger.warn("Retrying to connect to database.");
return isConnected(true);
} else {
return false;
}
}
}
return false;
}
}
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/CvsPassword.java
0,0 → 1,69
/* */ package net.brutex.xservices.util;
/* */
/* */ import java.io.PrintStream;
/* */
/* */ public class CvsPassword
/* */ {
/* 46 */ private static final char[] LOOKUP_TABLE = {
/* 47 */ '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 'r', 'x', '5',
/* 48 */ 'O', '\000', 'm', 'H', 'l', 'F', '@', 'L', 'C', 't', 'J', 'D', 'W', 'o', '4', 'K',
/* 49 */ 'w', '1', '"', 'R', 'Q', '_', 'A', 'p', 'V', 'v', 'n', 'z', 'i', ')', '9',
/* 50 */ 'S', '+', '.', 'f', '(', 'Y', '&', 'g', '-', '2', '*', '{', '[', '#', '}', '7',
/* 51 */ '6', 'B', '|', '~', ';', '/', '\\', 'G', 's', 'N', 'X', 'k', 'j', '8',
/* 52 */ '\000', 'y', 'u', 'h', 'e', 'd', 'E', 'I', 'c', '?', '^', ']', '\'', '%', '=', '0',
/* 53 */ ':', 'q', ' ', 'Z', ',', 'b', '<', '3', '!', 'a', '>', 'M', 'T', 'P', 'U' };
/* */
/* */ public static String encode(String clearText)
/* */ {
/* 68 */ char[] encoded = new char[clearText.length() + 1];
/* 69 */ encoded[0] = 'A';
/* */
/* 72 */ int counter = 1;
/* 73 */ for (char c : clearText.toCharArray())
/* */ {
/* 75 */ if ((c == '`') || (c == '$') || (c < ' '))
/* */ {
/* 77 */ throw new IllegalArgumentException(
/* 78 */ "Illegal character was found in clear password.");
/* */ }
/* */
/* 81 */ encoded[(counter++)] = LOOKUP_TABLE[c];
/* */ }
/* */
/* 84 */ return String.valueOf(encoded);
/* */ }
/* */
/* */ public static String decode(String encodedPassword)
/* */ {
/* 98 */ String rtn = null;
/* */
/* 100 */ if ((encodedPassword != null) && (encodedPassword.length() > 0))
/* */ {
/* 102 */ if (encodedPassword.startsWith("A"))
/* */ {
/* 104 */ rtn = encode(encodedPassword.substring(1)).substring(1);
/* */ }
/* */ else
/* */ {
/* 108 */ rtn = encode(encodedPassword).substring(1);
/* */ }
/* */ }
/* */
/* 112 */ return rtn;
/* */ }
/* */
/* */ public static void main(String[] sArgs)
/* */ {
/* 117 */ String TEST_WORD = "i07w91";
/* 118 */ String encoded = encode("i07w91");
/* 119 */ System.out.println("Encoded: <" + encoded + ">");
/* 120 */ String decoded = decode(encoded);
/* 121 */ System.out.println("Decoded: <" + decoded + ">");
/* 122 */ System.out.println(decoded.equals("i07w91") ? "Test Passed" : "Test Failed");
/* */ }
/* */ }
 
/* Location: C:\Users\brosenberger\Documents\My Box Files\XBridgeNG-download\XServices-20130131 - Kopie\WEB-INF\classes\net.zip
* Qualified Name: net.brutex.xservices.util.CvsPassword
* JD-Core Version: 0.6.2
*/
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/cache/CacheExecutorService.java
0,0 → 1,60
/*
* Copyright 2013 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util.cache;
 
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
 
/**
* @author Brian Rosenberger, bru(at)brutex.de
*
*/
 
 
 
public class CacheExecutorService
implements ServletContextListener
{
static final String EXECUTOR_NAME = "CACHE_EXECUTOR";
private ExecutorService executor;
 
public void contextInitialized(ServletContextEvent arg0)
{
ServletContext context = arg0.getServletContext();
int nr_executors = 5;
ThreadFactory daemonFactory = new DaemonThreadFactory();
try {
nr_executors = Integer.parseInt(context.getInitParameter("cache:thread-count"));
} catch (NumberFormatException localNumberFormatException) {
}
if (nr_executors <= 1)
this.executor = Executors.newSingleThreadExecutor(daemonFactory);
else {
this.executor = Executors.newFixedThreadPool(nr_executors, daemonFactory);
}
context.setAttribute("CACHE_EXECUTOR", this.executor);
}
 
public void contextDestroyed(ServletContextEvent arg0) {
ServletContext context = arg0.getServletContext();
this.executor.shutdownNow();
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/cache/DaemonThreadFactory.java
0,0 → 1,49
/*
* Copyright 2013 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util.cache;
 
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
/**
* @author Brian Rosenberger, bru(at)brutex.de
*
*/
 
 
public class DaemonThreadFactory
implements ThreadFactory
{
private final ThreadFactory factory;
 
public DaemonThreadFactory()
{
this(Executors.defaultThreadFactory());
}
 
public DaemonThreadFactory(ThreadFactory factory)
{
if (factory == null)
throw new NullPointerException("factory cannot be null");
this.factory = factory;
}
 
public Thread newThread(Runnable r) {
Thread t = this.factory.newThread(r);
t.setDaemon(true);
return t;
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/cache/CacheServlet.java
0,0 → 1,70
/*
* Copyright 2013 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util.cache;
 
import java.io.File;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.ExecutorService;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import net.brutex.xservices.types.scm.ObjectFactory;
import org.apache.log4j.Logger;
 
/**
* @author Brian Rosenberger, bru(at)brutex.de
*
*/
 
 
public class CacheServlet extends HttpServlet
{
private final Logger logger = Logger.getLogger(CacheServlet.class);
List<File> configfiles = new ArrayList();
int cacheinterval;
private final ObjectFactory FACTORY = new ObjectFactory();
 
public void init()
throws ServletException
{
super.init();
ExecutorService executor = (ExecutorService)getServletContext()
.getAttribute("CACHE_EXECUTOR");
 
Enumeration attributes = getServletContext()
.getInitParameterNames();
while (attributes.hasMoreElements()) {
String name = (String)attributes.nextElement();
if (name.startsWith("cvs-config-")) {
String configfile = getServletContext()
.getInitParameter(name);
this.logger.info("CVS configuration file: " + configfile);
this.configfiles.add(new File(configfile));
}
}
this.cacheinterval = 15;
try {
this.cacheinterval = Integer.parseInt(getServletContext()
.getInitParameter("cvs-cache-interval"));
} catch (NumberFormatException e) {
this.logger.debug("Could not read parameter 'cvs-cache-interval' from web.xml. Using default value '" + this.cacheinterval + "' minutes");
}
this.logger.info("CacheServlet set to " + this.cacheinterval + " minutes interval.");
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/cache/FindingsCacheServlet.java
0,0 → 1,346
/*
* Copyright 2013 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util.cache;
 
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.ws.rs.core.Response;
import net.brutex.xservices.types.scm.ItemListType;
import net.brutex.xservices.types.scm.ItemType;
import net.brutex.xservices.types.scmfindings.FindingDetailsType;
import net.brutex.xservices.types.scmfindings.FindingType;
import net.brutex.xservices.types.scmfindings.FindingsListType;
import net.brutex.xservices.types.scmfindings.GroupMatchListType;
import net.brutex.xservices.types.scmfindings.ObjectFactory;
import net.brutex.xservices.ws.rs.CVSInfoImpl;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;
import org.apache.log4j.Logger;
 
/**
* @author Brian Rosenberger, bru(at)brutex.de
*
*/
 
public class FindingsCacheServlet extends HttpServlet {
 
private static final long serialVersionUID = 4041338473949999960L;
private final static Logger logger = Logger
.getLogger(FindingsCacheServlet.class);
private final List<File> configfiles = new ArrayList<File>();
private final ObjectFactory FACTORY = new ObjectFactory();
 
@Override
public void init() throws ServletException {
super.init();
ExecutorService executor = (ExecutorService) getServletContext()
.getAttribute("CACHE_EXECUTOR");
if(! this.initConfigList()) return;
if(! this.initConfigFindings()) return;
 
int i = 1;
for(File f: configfiles) {
//Initialise configuration bean using default values
FindingsConfigBean cbean = new FindingsConfigBean(i, Logger.getLogger("worker-"+i+ "." + this.getClass().getName()));
i++;
//Read cvs-cache-interval parameter
try {
int cacheinterval = Integer.parseInt(getServletContext()
.getInitParameter("cvs-cache-interval"));
cbean.setCacheinterval(cacheinterval);
logger.info("FindingsCacheServlet set to "+ cacheinterval + " minutes interval.");
} catch (NumberFormatException e) {
logger.warn("Could not read parameter 'cvs-cache-interval' from web.xml. Using default value '"
+ cbean.getCacheinterval()+ "' minutes");
}
PropertiesConfiguration config = null;
try {
config = new PropertiesConfiguration(f);
} catch (ConfigurationException e) {
logger.error("Could not read parameter file at '"+f.getAbsolutePath()+"'");
return;
}
File cvsconfig = new File(config.getString("CVSROOTCONFIGFILE"));
cbean.setCvsconfig(cvsconfig);
FindingsCacheServlet.logger.debug("Fetching list of files using '"
+ cvsconfig.getAbsolutePath() + "' config file");
List<Object> filepatterns = config.getList("FILESEARCH");
cbean.setFilepatterns(filepatterns);
FindingsCacheServlet.logger.debug("Checking '"
+ filepatterns.size()
+ "' patterns for file name and path matching.");
List<Object> contentpatterns = config.getList("CONTENTSEARCH");
cbean.setContentpatterns(contentpatterns);
FindingsCacheServlet.logger.debug("Checking '"
+ contentpatterns.size()
+ "' patterns for content matching");
 
executor.submit(new ThisRunnable(cbean));
}
logger.info("FindingsCacheServlet has been initialized.");
 
}
/*
* Initialise CVS findings configuration
*/
private boolean initConfigFindings() {
String filename = getServletContext().getInitParameter(
"cvs-findings-configuration");
if (filename == null) {
logger.warn("'cvs-findings-configuration' init parameter is not specified.");
return false;
}
final File findingsconfig = new File(filename);
logger.info("CVS findings configuration file found at '"
+ findingsconfig.getAbsolutePath() + "'");
if ((!findingsconfig.canRead()) || (findingsconfig.isDirectory())) {
logger.info("CVS findings configuration file '"
+ findingsconfig.getAbsolutePath() + "' does not exist.");
return false;
}
return true;
}
 
/*
* Add all specified CVS configuration files to the list. Parameter pattern
* is "cvs-config-XX".
*/
private boolean initConfigList() {
Enumeration<String> attributes = getServletContext()
.getInitParameterNames();
while (attributes.hasMoreElements()) {
String name = (String) attributes.nextElement();
if (name.startsWith("cvs-config-")) {
String configfile = getServletContext().getInitParameter(name);
logger.info("Adding CVS configuration file: " + configfile);
this.configfiles.add(new File(configfile));
}
}
/*
* Verify, that all configuration files do exists and are readable.
*/
List<File> removelist = new ArrayList<File>();
for (File f : configfiles) {
if (!f.exists()) {
logger.warn("CVS configuration file '"
+ f.getAbsolutePath()
+ "' is specified, but does not exist. Removing from list.");
removelist.add(f);
} else if (!f.canRead()) {
logger.warn("CVS configuration file '"
+ f.getAbsolutePath()
+ "' does exist, but is not readable. Removing from list.");
removelist.add(f);
}
}
configfiles.removeAll(removelist);
return true;
}
 
class ThisRunnable implements Runnable {
boolean isInterrupted = false;
FindingsConfigBean configuration;
 
public ThisRunnable(FindingsConfigBean configuration) {
this.configuration = configuration;
}
 
public void run() {
CVSInfoImpl instance = new CVSInfoImpl();
 
ItemListType fileslist = (ItemListType) instance
.getRepositoryFiles(null, configuration.getCvsconfig(), "", true, true, true)
.getEntity();
ObjectFactory FACTORY = new ObjectFactory();
FindingsListType findingsList = FACTORY.createFindingsListType();
 
FindingsCacheServlet.logger.info("Processing '"
+ fileslist.getItems().size() + "' files and directories.");
 
while (!this.isInterrupted) {
Pattern p;
for (ItemType i : fileslist.getItems()) {
if (this.isInterrupted)
break;
Iterator<Object> iterF = configuration.getFilepatterns().iterator();
while(iterF.hasNext()) {
Object o = iterF.next();
if (this.isInterrupted)
break;
FindingsCacheServlet.logger.debug("Scanning filename '"
+ i.getFullname() + "' for pattern '"
+ (String) o + "'");
p = Pattern.compile((String) o);
Matcher m = p.matcher(i.getFullname());
if (m.find()) {
FindingType finding = FACTORY.createFindingType();
finding.setFilesearch(p.toString());
ItemType it = (ItemType) instance.getFileContent(
null, configuration.getCvsconfig(), i.getFullname(), true)
.getEntity();
finding.setContent(it.getContent());
finding.setData(it.getData());
finding = copyDetails(finding, i);
findingsList.getFindings().add(finding);
FindingsCacheServlet.logger
.debug("Match found for '"
+ i.getFullname() + "'");
break;
}
FindingsCacheServlet.logger
.debug("No match found for '" + i.getFullname()
+ "'");
}
}
FindingsCacheServlet.logger
.debug("Processing file content for '"
+ findingsList.getFindings().size()
+ "' entries in the list.");
 
for (FindingType t : findingsList.getFindings()) {
if (this.isInterrupted)
break;
boolean isFound = false;
Matcher m;
Iterator<Object> iter = configuration.getContentpatterns().iterator();
while (iter.hasNext()) {
 
Object o = iter.next();
if (this.isInterrupted)
break;
FindingsCacheServlet.logger
.debug("Scanning file content for file '"
+ t.getFullname() + "' for pattern '"
+ (String) o + "'");
 
Pattern p1 = Pattern.compile((String) o);
m = p1.matcher(t.getContent());
t.setContentsearch(p1.toString());
 
isFound = true;
int s = m.start();
int e = m.end();
String c = m.group();
 
FindingDetailsType fd = FACTORY
.createFindingDetailsType();
GroupMatchListType gm = FACTORY
.createGroupMatchListType();
gm.setMatchAtIndex(s);
gm.setMatchToIndex(e);
gm.setMatchString(c);
gm.setMatchGroup(0);
fd.setFullmatch(gm);
for (int i = 1; i <= m.groupCount(); i++) {
GroupMatchListType gmg = FACTORY
.createGroupMatchListType();
s = m.start(i);
e = m.end(i);
c = m.group(i);
gmg.setMatchAtIndex(s);
gmg.setMatchToIndex(e);
gmg.setMatchString(c);
gmg.setMatchGroup(i);
fd.getMatchLists().add(gmg);
}
t.getFindingLists().add(fd);
FindingsCacheServlet.logger
.debug("Found matching content at index '" + s
+ "' in file '" + t.getFullname()
+ "' with pattern '" + p1.toString()
+ "'");
}
 
if (!isFound) {
findingsList.getFindings().remove(t);
FindingsCacheServlet.logger
.debug("Found matching filename for '"
+ t.getFullname()
+ "' but content didn't match. Removing.");
}
 
try {
instance.getCacheInstance().put(
"FINDINGS-" + t.getROOT(), findingsList);
FindingsCacheServlet.logger
.info("FINDINGS for CVSROOT '" + t.getROOT()
+ "' have been updated in cache.");
} catch (CacheException e) {
FindingsCacheServlet.logger.error(e.getMessage(), e);
}
}
try {
int cacheinterval = configuration.getCacheinterval();
FindingsCacheServlet.logger.debug("Now sleeping for '"
+ cacheinterval + "' minutes");
Thread.currentThread();
Thread.sleep(cacheinterval * 60000);
FindingsCacheServlet.logger.debug("Waking up after '"
+ cacheinterval + "' minutes of sleep");
} catch (InterruptedException e) {
this.isInterrupted = true;
FindingsCacheServlet.logger
.warn("FindingsCacheServlet cache was interrupted. Shutting down.");
}
}
 
}
 
private FindingType copyDetails(FindingType finding, ItemType item) {
finding.setDescription(item.getDescription());
finding.setFullname(item.getFullname());
finding.setName(item.getName());
finding.setPath(item.getPath());
finding.setRemotefullname(item.getRemotefullname());
finding.setRemotename(item.getRemotename());
finding.setRemotepath(item.getRemotepath());
finding.setROOT(item.getROOT());
return finding;
}
 
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/cache/FindingsConfigBean.java
0,0 → 1,107
/*
* Copyright 2013 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util.cache;
 
import java.io.File;
import java.util.List;
 
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.log4j.Logger;
 
/**
* @author Brian Rosenberger, bru(at)brutex.de
*
*/
public class FindingsConfigBean {
private final Logger logger;
private final int instanceid;
private File cvsconfig;
private int cacheinterval = 15;
private List<Object> filepatterns;
private List<Object> contentpatterns;
 
public FindingsConfigBean(int instanceid, Logger logger) {
this.instanceid = instanceid;
this.logger = logger;
logger.debug("Initialise FindingsConfigBean instance '"+instanceid+"'");
}
 
/**
* @return the cache interval
*/
public int getCacheinterval() {
return cacheinterval;
}
 
/**
* @param cacheinterval the cache interval to set
*/
public void setCacheinterval(int cacheinterval) {
this.cacheinterval = cacheinterval;
}
/**
* @return the cvsconfig
*/
public File getCvsconfig() {
return cvsconfig;
}
 
/**
* @param cvsconfig the cvsconfig to set
*/
public void setCvsconfig(File cvsconfig) {
this.cvsconfig = cvsconfig;
}
 
/**
* @return the filepatterns
*/
public List<Object> getFilepatterns() {
return filepatterns;
}
 
/**
* @param filepatterns the filepatterns to set
*/
public void setFilepatterns(List<Object> filepatterns) {
this.filepatterns = filepatterns;
}
 
/**
* @return the contentpatterns
*/
public List<Object> getContentpatterns() {
return contentpatterns;
}
 
/**
* @param contentpatterns the contentpatterns to set
*/
public void setContentpatterns(List<Object> contentpatterns) {
this.contentpatterns = contentpatterns;
}
 
/**
* @param instanceid
*/
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/RunTask.java
0,0 → 1,101
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.util;
 
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.ant.AntProperty;
 
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.listener.TimestampedLogger;
import org.apache.tools.ant.taskdefs.Echo;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
public class RunTask {
 
Project antproject;
Target anttarget;
Task anttask;
ByteArrayOutputStream myout = new ByteArrayOutputStream();
ByteArrayOutputStream myerr = new ByteArrayOutputStream();
PrintStream out = new PrintStream(myout);
PrintStream err = new PrintStream(myerr);
TimestampedLogger log = null;
 
public RunTask(Task anttask) {
 
antproject = new Project();
antproject.init();
antproject.setBasedir(System.getProperty("java.io.tmpdir"));
log = new TimestampedLogger();
log.setOutputPrintStream(out);
log.setErrorPrintStream(err);
log.setMessageOutputLevel(Echo.EchoLevel.WARN.getLevel());
 
antproject.addBuildListener(log);
 
anttarget = new Target();
anttarget.setName("XBridgeNGDynamicTarget");
anttarget.setProject(antproject);
antproject.addTarget(anttarget);
 
this.anttask = anttask;
prepareTask();
}
 
private void prepareTask()
throws BuildException {
anttask.init();
anttask.setProject(antproject);
anttask.setOwningTarget(anttarget);
anttarget.addTask(anttask);
antproject.addOrReplaceTarget(anttarget);
}
 
/**
* @return ReturnCode type {@link ReturnCode}
* @throws BuildException
*/
public ReturnCode postTask() throws BuildException {
int returnCode = 0;
Map<String, String> origMap = new HashMap<String, String>();
Map<String, String> newMap = null;
origMap.putAll(antproject.getProperties());
antproject.executeTarget(anttarget.getName());
newMap = antproject.getProperties();
newMap.putAll(antproject.getUserProperties());
for (Map.Entry<String, String> e : origMap.entrySet()) {
newMap.remove(e.getKey());
}
 
//anttask.execute();
return new ReturnCode(returnCode,
myout.toString(),
myerr.toString(),
AntProperty.createAntPropertyList(newMap));
 
}
}
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/JobWrapper.java
0,0 → 1,96
/*
* Copyright 2011 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util;
 
import java.io.Serializable;
import java.util.Date;
 
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
 
/**
* Wrapper for jobs that can be executed through quartz scheduler.
*
* @author Brian Rosenberger, bru@brutex.de
* @since 0.5.0
*
*/
public class JobWrapper implements Job, Serializable {
 
public void execute(JobExecutionContext jcontext)
throws JobExecutionException {
try {
 
System.out.println("Executing scheduled job '"+jcontext.getJobDetail().getKey().getName()+"' at " + new Date());
 
JobDataMap jdMap = jcontext.getJobDetail().getJobDataMap();
String script = jdMap.getString("script");
 
// Create and enter a Context. A Context stores information about
// the execution environment of a script.
Context cx = Context.enter();
cx.setOptimizationLevel(0);
cx.setLanguageVersion(Context.VERSION_1_7);
// cx is the Context instance you're using to run scripts
/*
* cx.setClassShutter(new ClassShutter() { public boolean
* visibleToScripts(String className) {
* if(className.startsWith("adapter")) return true;
* if(className.startsWith("java.lang.System") ||
* className.startsWith
* ("org.apache.tomcat.util.log.SystemLogHandler")) return true;
* System.out.println(className + " is blocked."); return false; }
* });
*/
 
// Initialise the standard objects (Object, Function, etc.). This
// must be done before scripts can be
// executed. The null parameter tells initStandardObjects
// to create and return a scope object that we use
// in later calls.
Scriptable scope = cx.initStandardObjects();
//Object wrappedOut = Context.javaToJS(System.out, scope);
//Object wrappedOut2 = Context.javaToJS(this, scope);
//scope.put("out", scope, wrappedOut);
//scope.put("exe", scope, wrappedOut2);
 
// Execute the script
// cx.evaluateString(scope, "importClass('java.lang.System');\n",
// "head", 1, null);
// cx.evaluateString(scope, "importPackage('java.util');\n", "head",
// 2, null);
Object obj = cx
.evaluateString(scope, script, "TestScript", 1, null);
 
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
// Exit the Context. This removes the association between the
// Context and the current thread and is an
// essential cleanup action. There should be a call to exit for
// every call to enter.
Context.exit();
}
 
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/BrutexNamespaces.java
0,0 → 1,54
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util;
 
/**
* Holds static namespace information.
*
*
* @author Brian Rosenberger, bru@brutex.de
*/
public class BrutexNamespaces {
 
/**
* Brutex Network XServices web service name space declaration
*/
public static final String WS_XSERVICES = "http://ws.xservices.brutex.net";
/**
* Copyright and license agreement statement.
*/
public static final String BRUTEX_COPYRIGHT = "" +
"/*\n" +
"* Copyright 2010 Brian Rosenberger (Brutex Network)\n" +
"*\n" +
"* Licensed under the Apache License, Version 2.0 (the \"License\")\n" +
"* you may not use this file except in compliance with the License.\n" +
"* You may obtain a copy of the License at\n" +
"*\n" +
"* http://www.apache.org/licenses/LICENSE-2.0\n" +
"*\n" +
"* Unless required by applicable law or agreed to in writing, software\n" +
"* distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
"* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
"* See the License for the specific language governing permissions and\n" +
"* limitations under the License.\n" +
"*/";
 
 
private BrutexNamespaces() {};
}
/xservices/tags/20130205r/src/java/net/brutex/xservices/util/UnRarTask.java
0,0 → 1,74
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util;
 
import de.innosystec.unrar.Archive;
import de.innosystec.unrar.exception.RarException;
import de.innosystec.unrar.rarfile.FileHeader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
public class UnRarTask extends Task {
 
private File dst = null;
private File src = null;
 
public File getDst() {
return dst;
}
 
public void setDst(File dst) {
this.dst = dst;
}
 
public File getSrc() {
return src;
}
 
public void setSrc(File src) {
this.src = src;
}
 
 
@Override
public void execute() {
if(src==null ) throw new BuildException("Please supply a source archive file.");
if(!src.exists()) throw new BuildException("Archive '"+src.getName()+"' does not exist.");
 
try {
if(dst==null) dst = new File(src.getParent());
Archive ar = new Archive(src);
List<FileHeader> list = ar.getFileHeaders();
for(FileHeader h : list) {
ar.extractFile(h, new FileOutputStream(new File(dst.getAbsolutePath()+"/"+h.getFileNameString())));
}
} catch (RarException ex) {
throw new BuildException(ex.getMessage(), ex);
} catch (IOException ex) {
throw new BuildException(ex.getMessage(), ex);
}
}
 
}