repo_name
stringlengths 7
104
| file_path
stringlengths 13
198
| context
stringlengths 67
7.15k
| import_statement
stringlengths 16
4.43k
| code
stringlengths 40
6.98k
| prompt
stringlengths 227
8.27k
| next_line
stringlengths 8
795
|
---|---|---|---|---|---|---|
rkapsi/ardverk-commons | src/main/java/org/ardverk/concurrent/Duration.java | // Path: src/main/java/org/ardverk/lang/Longs.java
// public class Longs {
//
// private Longs() {}
//
// /**
// * Compares the given {@code long} values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compare(long l1, long l2) {
// if (l1 < l2) {
// return -1;
// } else if (l2 < l1) {
// return 1;
// }
// return 0;
// }
// }
| import java.io.Serializable;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.ardverk.lang.Longs; | /*
* Copyright 2009-2011 Roger Kapsi
*
* 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 org.ardverk.concurrent;
public class Duration implements Comparable<Duration>, Serializable {
private static final long serialVersionUID = -7966576555871244178L;
public static final Duration ZERO = new Duration(0L, TimeUnit.MILLISECONDS);
private final long duration;
private final TimeUnit unit;
public Duration(long duration, TimeUnit unit) {
this.duration = duration;
this.unit = unit;
}
public long getDuration(TimeUnit unit) {
return unit.convert(duration, this.unit);
}
public long getDurationInMillis() {
return getDuration(TimeUnit.MILLISECONDS);
}
public long getTime() {
return System.currentTimeMillis() + getDurationInMillis();
}
public Date getDate() {
return new Date(getTime());
}
@Override
public int compareTo(Duration o) { | // Path: src/main/java/org/ardverk/lang/Longs.java
// public class Longs {
//
// private Longs() {}
//
// /**
// * Compares the given {@code long} values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compare(long l1, long l2) {
// if (l1 < l2) {
// return -1;
// } else if (l2 < l1) {
// return 1;
// }
// return 0;
// }
// }
// Path: src/main/java/org/ardverk/concurrent/Duration.java
import java.io.Serializable;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.ardverk.lang.Longs;
/*
* Copyright 2009-2011 Roger Kapsi
*
* 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 org.ardverk.concurrent;
public class Duration implements Comparable<Duration>, Serializable {
private static final long serialVersionUID = -7966576555871244178L;
public static final Duration ZERO = new Duration(0L, TimeUnit.MILLISECONDS);
private final long duration;
private final TimeUnit unit;
public Duration(long duration, TimeUnit unit) {
this.duration = duration;
this.unit = unit;
}
public long getDuration(TimeUnit unit) {
return unit.convert(duration, this.unit);
}
public long getDurationInMillis() {
return getDuration(TimeUnit.MILLISECONDS);
}
public long getTime() {
return System.currentTimeMillis() + getDurationInMillis();
}
public Date getDate() {
return new Date(getTime());
}
@Override
public int compareTo(Duration o) { | return Longs.compare(getDurationInMillis(), o.getDurationInMillis()); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/io/ZlibCompressor.java | // Path: src/main/java/org/ardverk/lang/MathUtils.java
// public class MathUtils {
//
// private MathUtils() {}
//
// /**
// * Returns the closest power of two value that's greater or
// * equal to the given argument.
// */
// public static int nextPowOfTwo(int expected) {
// int value = 1;
// while (value < expected) {
// value <<= 1;
// }
// return value;
// }
// }
| import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
import java.util.zip.InflaterOutputStream;
import org.ardverk.lang.MathUtils; | /*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.io;
/**
* An implementation of {@link Compressor} that uses Java's
* {@link InflaterInputStream} and {@link DeflaterOutputStream}.
*/
public class ZlibCompressor extends AbstractCompressor {
public static final ZlibCompressor ZLIB = new ZlibCompressor();
private ZlibCompressor() {
super("ZLIB");
}
@Override
public byte[] compress(byte[] value, int offset, int length)
throws IOException {
| // Path: src/main/java/org/ardverk/lang/MathUtils.java
// public class MathUtils {
//
// private MathUtils() {}
//
// /**
// * Returns the closest power of two value that's greater or
// * equal to the given argument.
// */
// public static int nextPowOfTwo(int expected) {
// int value = 1;
// while (value < expected) {
// value <<= 1;
// }
// return value;
// }
// }
// Path: src/main/java/org/ardverk/io/ZlibCompressor.java
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
import java.util.zip.InflaterOutputStream;
import org.ardverk.lang.MathUtils;
/*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.io;
/**
* An implementation of {@link Compressor} that uses Java's
* {@link InflaterInputStream} and {@link DeflaterOutputStream}.
*/
public class ZlibCompressor extends AbstractCompressor {
public static final ZlibCompressor ZLIB = new ZlibCompressor();
private ZlibCompressor() {
super("ZLIB");
}
@Override
public byte[] compress(byte[] value, int offset, int length)
throws IOException {
| ByteArrayOutputStream baos = new ByteArrayOutputStream(MathUtils.nextPowOfTwo(length)); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/lang/ByteArray.java | // Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
//
// private CodingUtils() {}
//
// /**
// * Encodes the given {@link String} in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(String data) {
// return encodeBase2(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data) {
// return encodeBase2(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data, int offset, int length) {
// return StringUtils.toString(Base2.encodeBase2(data, offset, length));
// }
//
// /**
// * Encodes the given {@link String} in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(String data) {
// return encodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data) {
// return encodeBase16(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data, int offset, int length) {
// return StringUtils.toString(Base16.encodeBase16(data, offset, length));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded {@link String}.
// */
// public static byte[] decodeBase16(String data) {
// return decodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data) {
// return decodeBase16(data, 0, data.length);
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data, int offset, int length) {
// return Base16.decodeBase16(data, offset, length);
// }
// }
//
// Path: src/main/java/org/ardverk/io/Streamable.java
// public interface Streamable {
//
// /**
// * Writes this Object to the given {@link OutputStream} and returns
// * the number of bytes that were written.
// */
// public void writeTo(OutputStream out) throws IOException;
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
| import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Arrays;
import org.ardverk.coding.CodingUtils;
import org.ardverk.io.Streamable;
import org.ardverk.utils.ByteArrayComparator; | /*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.lang;
public class ByteArray<T extends ByteArray<T>>
implements Comparable<T>, Streamable, Serializable {
private static final long serialVersionUID = -3599578418695385540L;
protected final byte[] value;
private int hashCode = 0;
public ByteArray(byte[] value) {
this.value = value;
}
/**
* Returns the length of the {@link ByteArray} in {@code byte}s.
*/
public int length() {
return value.length;
}
/**
* Returns a copy of the underlying {@code byte[]}.
*/
public byte[] getBytes() {
return getBytes(true);
}
/**
* Returns the underlying {@code byte[]}.
*/
public byte[] getBytes(boolean copy) {
return copy ? value.clone() : value;
}
/**
* Copies and returns the underlying {@code byte[]}.
*/
public byte[] getBytes(byte[] dst, int destPos) {
assert (dst != value); // Who would be so stupid?
System.arraycopy(value, 0, dst, destPos, value.length);
return dst;
}
@Override
public void writeTo(OutputStream out) throws IOException {
out.write(value);
}
@Override
public int compareTo(T o) { | // Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
//
// private CodingUtils() {}
//
// /**
// * Encodes the given {@link String} in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(String data) {
// return encodeBase2(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data) {
// return encodeBase2(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data, int offset, int length) {
// return StringUtils.toString(Base2.encodeBase2(data, offset, length));
// }
//
// /**
// * Encodes the given {@link String} in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(String data) {
// return encodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data) {
// return encodeBase16(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data, int offset, int length) {
// return StringUtils.toString(Base16.encodeBase16(data, offset, length));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded {@link String}.
// */
// public static byte[] decodeBase16(String data) {
// return decodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data) {
// return decodeBase16(data, 0, data.length);
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data, int offset, int length) {
// return Base16.decodeBase16(data, offset, length);
// }
// }
//
// Path: src/main/java/org/ardverk/io/Streamable.java
// public interface Streamable {
//
// /**
// * Writes this Object to the given {@link OutputStream} and returns
// * the number of bytes that were written.
// */
// public void writeTo(OutputStream out) throws IOException;
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
// Path: src/main/java/org/ardverk/lang/ByteArray.java
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Arrays;
import org.ardverk.coding.CodingUtils;
import org.ardverk.io.Streamable;
import org.ardverk.utils.ByteArrayComparator;
/*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.lang;
public class ByteArray<T extends ByteArray<T>>
implements Comparable<T>, Streamable, Serializable {
private static final long serialVersionUID = -3599578418695385540L;
protected final byte[] value;
private int hashCode = 0;
public ByteArray(byte[] value) {
this.value = value;
}
/**
* Returns the length of the {@link ByteArray} in {@code byte}s.
*/
public int length() {
return value.length;
}
/**
* Returns a copy of the underlying {@code byte[]}.
*/
public byte[] getBytes() {
return getBytes(true);
}
/**
* Returns the underlying {@code byte[]}.
*/
public byte[] getBytes(boolean copy) {
return copy ? value.clone() : value;
}
/**
* Copies and returns the underlying {@code byte[]}.
*/
public byte[] getBytes(byte[] dst, int destPos) {
assert (dst != value); // Who would be so stupid?
System.arraycopy(value, 0, dst, destPos, value.length);
return dst;
}
@Override
public void writeTo(OutputStream out) throws IOException {
out.write(value);
}
@Override
public int compareTo(T o) { | return ByteArrayComparator.COMPARATOR.compare(value, o.value); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/lang/ByteArray.java | // Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
//
// private CodingUtils() {}
//
// /**
// * Encodes the given {@link String} in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(String data) {
// return encodeBase2(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data) {
// return encodeBase2(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data, int offset, int length) {
// return StringUtils.toString(Base2.encodeBase2(data, offset, length));
// }
//
// /**
// * Encodes the given {@link String} in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(String data) {
// return encodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data) {
// return encodeBase16(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data, int offset, int length) {
// return StringUtils.toString(Base16.encodeBase16(data, offset, length));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded {@link String}.
// */
// public static byte[] decodeBase16(String data) {
// return decodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data) {
// return decodeBase16(data, 0, data.length);
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data, int offset, int length) {
// return Base16.decodeBase16(data, offset, length);
// }
// }
//
// Path: src/main/java/org/ardverk/io/Streamable.java
// public interface Streamable {
//
// /**
// * Writes this Object to the given {@link OutputStream} and returns
// * the number of bytes that were written.
// */
// public void writeTo(OutputStream out) throws IOException;
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
| import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Arrays;
import org.ardverk.coding.CodingUtils;
import org.ardverk.io.Streamable;
import org.ardverk.utils.ByteArrayComparator; | public void writeTo(OutputStream out) throws IOException {
out.write(value);
}
@Override
public int compareTo(T o) {
return ByteArrayComparator.COMPARATOR.compare(value, o.value);
}
@Override
public int hashCode() {
if (hashCode == 0) {
hashCode = Arrays.hashCode(value);
}
return hashCode;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (!(o instanceof ByteArray<?>)) {
return false;
}
ByteArray<?> other = (ByteArray<?>)o;
return Arrays.equals(value, other.value);
}
public String toBinString() { | // Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
//
// private CodingUtils() {}
//
// /**
// * Encodes the given {@link String} in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(String data) {
// return encodeBase2(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data) {
// return encodeBase2(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data, int offset, int length) {
// return StringUtils.toString(Base2.encodeBase2(data, offset, length));
// }
//
// /**
// * Encodes the given {@link String} in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(String data) {
// return encodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data) {
// return encodeBase16(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data, int offset, int length) {
// return StringUtils.toString(Base16.encodeBase16(data, offset, length));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded {@link String}.
// */
// public static byte[] decodeBase16(String data) {
// return decodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data) {
// return decodeBase16(data, 0, data.length);
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data, int offset, int length) {
// return Base16.decodeBase16(data, offset, length);
// }
// }
//
// Path: src/main/java/org/ardverk/io/Streamable.java
// public interface Streamable {
//
// /**
// * Writes this Object to the given {@link OutputStream} and returns
// * the number of bytes that were written.
// */
// public void writeTo(OutputStream out) throws IOException;
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
// Path: src/main/java/org/ardverk/lang/ByteArray.java
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Arrays;
import org.ardverk.coding.CodingUtils;
import org.ardverk.io.Streamable;
import org.ardverk.utils.ByteArrayComparator;
public void writeTo(OutputStream out) throws IOException {
out.write(value);
}
@Override
public int compareTo(T o) {
return ByteArrayComparator.COMPARATOR.compare(value, o.value);
}
@Override
public int hashCode() {
if (hashCode == 0) {
hashCode = Arrays.hashCode(value);
}
return hashCode;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (!(o instanceof ByteArray<?>)) {
return false;
}
ByteArray<?> other = (ByteArray<?>)o;
return Arrays.equals(value, other.value);
}
public String toBinString() { | return CodingUtils.encodeBase2(value); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/utils/LongComparator.java | // Path: src/main/java/org/ardverk/lang/Longs.java
// public class Longs {
//
// private Longs() {}
//
// /**
// * Compares the given {@code long} values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compare(long l1, long l2) {
// if (l1 < l2) {
// return -1;
// } else if (l2 < l1) {
// return 1;
// }
// return 0;
// }
// }
| import java.io.Serializable;
import java.util.Comparator;
import org.ardverk.lang.Longs; | /*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.utils;
/**
* A {@link Comparator} for long values.
*/
public class LongComparator implements Comparator<Long>, Serializable {
private static final long serialVersionUID = -611530289701062817L;
public static final LongComparator COMPARATOR = new LongComparator();
@Override
public int compare(Long o1, Long o2) { | // Path: src/main/java/org/ardverk/lang/Longs.java
// public class Longs {
//
// private Longs() {}
//
// /**
// * Compares the given {@code long} values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compare(long l1, long l2) {
// if (l1 < l2) {
// return -1;
// } else if (l2 < l1) {
// return 1;
// }
// return 0;
// }
// }
// Path: src/main/java/org/ardverk/utils/LongComparator.java
import java.io.Serializable;
import java.util.Comparator;
import org.ardverk.lang.Longs;
/*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.utils;
/**
* A {@link Comparator} for long values.
*/
public class LongComparator implements Comparator<Long>, Serializable {
private static final long serialVersionUID = -611530289701062817L;
public static final LongComparator COMPARATOR = new LongComparator();
@Override
public int compare(Long o1, Long o2) { | return Longs.compare(o1.longValue(), o2.longValue()); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/net/AddressTracker.java | // Path: src/main/java/org/ardverk/collection/FixedSizeHashSet.java
// public class FixedSizeHashSet<E> implements Set<E>, FixedSize, Serializable {
//
// private static final long serialVersionUID = -7937957462093712348L;
//
// private static final Object VALUE = new Object();
//
// private final FixedSizeHashMap<E, Object> map;
//
// public FixedSizeHashSet(int maxSize) {
// this(16, 0.75f, false, maxSize);
// }
//
// public FixedSizeHashSet(int initialSize, float loadFactor, int maxSize) {
// this(initialSize, loadFactor, false, maxSize);
// }
//
// public FixedSizeHashSet(int initialCapacity, float loadFactor,
// boolean accessOrder, int maxSize) {
//
// map = new FixedSizeHashMap<E, Object>(
// initialCapacity, loadFactor, accessOrder, maxSize) {
//
// private static final long serialVersionUID = -2214875570521398012L;
//
// @Override
// protected boolean removeEldestEntry(Map.Entry<E, Object> eldest) {
// return FixedSizeHashSet.this.removeEldestEntry(eldest.getKey());
// }
//
// @Override
// protected void removing(Entry<E, Object> eldest) {
// FixedSizeHashSet.this.removing(eldest.getKey());
// }
// };
// }
//
// protected boolean removeEldestEntry(E eldest) {
// int maxSize = getMaxSize();
// return maxSize != -1 && size() > maxSize;
// }
//
// /**
// *
// */
// protected void removing(E eldest) {
// // OVERRIDE
// }
//
// @Override
// public boolean add(E e) {
// return map.put(e, VALUE) == null;
// }
//
// @Override
// public boolean addAll(Collection<? extends E> c) {
// boolean changed = false;
// for (E e : c) {
// changed |= add(e);
// }
// return changed;
// }
//
// @Override
// public void clear() {
// map.clear();
// }
//
// @Override
// public boolean contains(Object o) {
// return map.keySet().contains(o);
// }
//
// @Override
// public boolean containsAll(Collection<?> c) {
// return map.keySet().containsAll(c);
// }
//
// @Override
// public boolean isEmpty() {
// return map.isEmpty();
// }
//
// @Override
// public Iterator<E> iterator() {
// return map.keySet().iterator();
// }
//
// @Override
// public boolean remove(Object o) {
// return map.remove(o) != null;
// }
//
// @Override
// public boolean removeAll(Collection<?> c) {
// return map.keySet().removeAll(c);
// }
//
// @Override
// public boolean retainAll(Collection<?> c) {
// return map.keySet().retainAll(c);
// }
//
// @Override
// public int size() {
// return map.size();
// }
//
// @Override
// public Object[] toArray() {
// return map.keySet().toArray();
// }
//
// @Override
// public <T> T[] toArray(T[] a) {
// return map.keySet().toArray(a);
// }
//
// @Override
// public int getMaxSize() {
// return map.getMaxSize();
// }
//
// @Override
// public boolean isFull() {
// return map.isFull();
// }
//
// @Override
// public String toString() {
// return map.keySet().toString();
// }
// }
| import java.net.InetAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import org.ardverk.collection.FixedSizeHashSet; | /*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.net;
/**
* The {@link AddressTracker} helps us to determinate our external/public
* {@link InetAddress} in a distributed but possibly NAT'ed environment.
*/
public class AddressTracker {
/**
* The {@link NetworkMask} makes sure that consecutive {@code set}
* calls from the same clients are being ignored.
*/
private final NetworkMask mask;
// We use a ByteBuffer because it implements equals() and hashCode() | // Path: src/main/java/org/ardverk/collection/FixedSizeHashSet.java
// public class FixedSizeHashSet<E> implements Set<E>, FixedSize, Serializable {
//
// private static final long serialVersionUID = -7937957462093712348L;
//
// private static final Object VALUE = new Object();
//
// private final FixedSizeHashMap<E, Object> map;
//
// public FixedSizeHashSet(int maxSize) {
// this(16, 0.75f, false, maxSize);
// }
//
// public FixedSizeHashSet(int initialSize, float loadFactor, int maxSize) {
// this(initialSize, loadFactor, false, maxSize);
// }
//
// public FixedSizeHashSet(int initialCapacity, float loadFactor,
// boolean accessOrder, int maxSize) {
//
// map = new FixedSizeHashMap<E, Object>(
// initialCapacity, loadFactor, accessOrder, maxSize) {
//
// private static final long serialVersionUID = -2214875570521398012L;
//
// @Override
// protected boolean removeEldestEntry(Map.Entry<E, Object> eldest) {
// return FixedSizeHashSet.this.removeEldestEntry(eldest.getKey());
// }
//
// @Override
// protected void removing(Entry<E, Object> eldest) {
// FixedSizeHashSet.this.removing(eldest.getKey());
// }
// };
// }
//
// protected boolean removeEldestEntry(E eldest) {
// int maxSize = getMaxSize();
// return maxSize != -1 && size() > maxSize;
// }
//
// /**
// *
// */
// protected void removing(E eldest) {
// // OVERRIDE
// }
//
// @Override
// public boolean add(E e) {
// return map.put(e, VALUE) == null;
// }
//
// @Override
// public boolean addAll(Collection<? extends E> c) {
// boolean changed = false;
// for (E e : c) {
// changed |= add(e);
// }
// return changed;
// }
//
// @Override
// public void clear() {
// map.clear();
// }
//
// @Override
// public boolean contains(Object o) {
// return map.keySet().contains(o);
// }
//
// @Override
// public boolean containsAll(Collection<?> c) {
// return map.keySet().containsAll(c);
// }
//
// @Override
// public boolean isEmpty() {
// return map.isEmpty();
// }
//
// @Override
// public Iterator<E> iterator() {
// return map.keySet().iterator();
// }
//
// @Override
// public boolean remove(Object o) {
// return map.remove(o) != null;
// }
//
// @Override
// public boolean removeAll(Collection<?> c) {
// return map.keySet().removeAll(c);
// }
//
// @Override
// public boolean retainAll(Collection<?> c) {
// return map.keySet().retainAll(c);
// }
//
// @Override
// public int size() {
// return map.size();
// }
//
// @Override
// public Object[] toArray() {
// return map.keySet().toArray();
// }
//
// @Override
// public <T> T[] toArray(T[] a) {
// return map.keySet().toArray(a);
// }
//
// @Override
// public int getMaxSize() {
// return map.getMaxSize();
// }
//
// @Override
// public boolean isFull() {
// return map.isFull();
// }
//
// @Override
// public String toString() {
// return map.keySet().toString();
// }
// }
// Path: src/main/java/org/ardverk/net/AddressTracker.java
import java.net.InetAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import org.ardverk.collection.FixedSizeHashSet;
/*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.net;
/**
* The {@link AddressTracker} helps us to determinate our external/public
* {@link InetAddress} in a distributed but possibly NAT'ed environment.
*/
public class AddressTracker {
/**
* The {@link NetworkMask} makes sure that consecutive {@code set}
* calls from the same clients are being ignored.
*/
private final NetworkMask mask;
// We use a ByteBuffer because it implements equals() and hashCode() | private final FixedSizeHashSet<ByteBuffer> history; |
rkapsi/ardverk-commons | src/main/java/org/ardverk/lang/BindableObject.java | // Path: src/main/java/org/ardverk/concurrent/EventUtils.java
// public class EventUtils {
//
// private static final EventThreadProvider PROVIDER = newEventThreadProvider();
//
// private static EventThreadProvider newEventThreadProvider() {
// for (EventThreadProvider element : ServiceLoader.load(
// EventThreadProvider.class)) {
// return element;
// }
//
// return new DefaultEventThreadProvider();
// }
//
// private EventUtils() {}
//
// /**
// * Returns true if the caller {@link Thread} is the same as the event
// * {@link Thread}. In other words {@link Thread}s can use method to
// * determinate if they are the event {@link Thread}.
// */
// public static boolean isEventThread() {
// return PROVIDER.isEventThread();
// }
//
// /**
// * Executes the given {@link Runnable} on the event {@link Thread}.
// */
// public static void fireEvent(Runnable event) {
// PROVIDER.fireEvent(event);
// }
//
// /**
// * The default event {@link Thread} provider that is being used
// * if no other {@link EventThreadProvider} was given.
// */
// private static class DefaultEventThreadProvider
// implements EventThreadProvider {
//
// private final AtomicReference<Thread> reference
// = new AtomicReference<Thread>();
//
// private final ThreadFactory factory
// = new DefaultThreadFactory("DefaultEventThread") {
// @Override
// public Thread newThread(Runnable r) {
// Thread thread = super.newThread(r);
// reference.set(thread);
// return thread;
// }
// };
//
// private final Executor executor
// = Executors.newSingleThreadExecutor(factory);
//
// @Override
// public boolean isEventThread() {
// return reference.get() == Thread.currentThread();
// }
//
// @Override
// public void fireEvent(Runnable event) {
// if (event == null) {
// throw new NullPointerException("event");
// }
//
// executor.execute(event);
// }
// }
// }
| import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.ardverk.concurrent.EventUtils; | this.t = null;
fireUnbind(t);
}
}
public void addBindingListener(BindingListener<T> l) {
listeners.add(l);
}
public void removeBindingListener(BindingListener<T> l) {
listeners.remove(l);
}
@SuppressWarnings("unchecked")
public BindingListener<T>[] getBindingListeners() {
return listeners.toArray(new BindingListener[0]);
}
protected void fireBind(final T t) {
if (!listeners.isEmpty()) {
Runnable event = new Runnable() {
@Override
public void run() {
for (BindingListener<T> l : listeners) {
l.handleBind(t);
}
}
};
| // Path: src/main/java/org/ardverk/concurrent/EventUtils.java
// public class EventUtils {
//
// private static final EventThreadProvider PROVIDER = newEventThreadProvider();
//
// private static EventThreadProvider newEventThreadProvider() {
// for (EventThreadProvider element : ServiceLoader.load(
// EventThreadProvider.class)) {
// return element;
// }
//
// return new DefaultEventThreadProvider();
// }
//
// private EventUtils() {}
//
// /**
// * Returns true if the caller {@link Thread} is the same as the event
// * {@link Thread}. In other words {@link Thread}s can use method to
// * determinate if they are the event {@link Thread}.
// */
// public static boolean isEventThread() {
// return PROVIDER.isEventThread();
// }
//
// /**
// * Executes the given {@link Runnable} on the event {@link Thread}.
// */
// public static void fireEvent(Runnable event) {
// PROVIDER.fireEvent(event);
// }
//
// /**
// * The default event {@link Thread} provider that is being used
// * if no other {@link EventThreadProvider} was given.
// */
// private static class DefaultEventThreadProvider
// implements EventThreadProvider {
//
// private final AtomicReference<Thread> reference
// = new AtomicReference<Thread>();
//
// private final ThreadFactory factory
// = new DefaultThreadFactory("DefaultEventThread") {
// @Override
// public Thread newThread(Runnable r) {
// Thread thread = super.newThread(r);
// reference.set(thread);
// return thread;
// }
// };
//
// private final Executor executor
// = Executors.newSingleThreadExecutor(factory);
//
// @Override
// public boolean isEventThread() {
// return reference.get() == Thread.currentThread();
// }
//
// @Override
// public void fireEvent(Runnable event) {
// if (event == null) {
// throw new NullPointerException("event");
// }
//
// executor.execute(event);
// }
// }
// }
// Path: src/main/java/org/ardverk/lang/BindableObject.java
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.ardverk.concurrent.EventUtils;
this.t = null;
fireUnbind(t);
}
}
public void addBindingListener(BindingListener<T> l) {
listeners.add(l);
}
public void removeBindingListener(BindingListener<T> l) {
listeners.remove(l);
}
@SuppressWarnings("unchecked")
public BindingListener<T>[] getBindingListeners() {
return listeners.toArray(new BindingListener[0]);
}
protected void fireBind(final T t) {
if (!listeners.isEmpty()) {
Runnable event = new Runnable() {
@Override
public void run() {
for (BindingListener<T> l : listeners) {
l.handleBind(t);
}
}
};
| EventUtils.fireEvent(event); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/utils/StringUtils.java | // Path: src/main/java/org/ardverk/io/ByteUtils.java
// public class ByteUtils {
//
// private ByteUtils() {}
//
// /**
// * @see DataInput#readFully(byte[])
// */
// public static byte[] readFully(InputStream in, byte[] dst) throws IOException {
// return readFully(in, dst, 0, dst.length);
// }
//
// /**
// * @see DataInput#readFully(byte[])
// */
// public static byte[] readFully(InputStream in, byte[] dst,
// int offset, int length) throws IOException {
//
// int total = 0;
// while (total < length) {
// int r = in.read(dst, offset + total, length - total);
// if (r == -1) {
// throw new EOFException();
// }
//
// total += r;
// }
//
// return dst;
// }
//
// public static void writeBytes(byte[] data, OutputStream out) throws IOException {
// writeBytes(data, 0, data.length, out);
// }
//
// public static void writeBytes(byte[] data, int offset, int length,
// OutputStream out) throws IOException {
// DataUtils.int2vbeb(length, out);
// out.write(data, offset, length);
// }
//
// public static byte[] readBytes(InputStream in) throws IOException {
// int length = DataUtils.vbeb2int(in);
// byte[] data = new byte[length];
// return readFully(in, data);
// }
// }
| import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import org.ardverk.io.ByteUtils; | return getBytes(data, UTF8_CHARSET);
}
public static byte[] getBytes(String data, String encoding) {
return getBytes(data, Charset.forName(encoding));
}
public static byte[] getBytes(String data, Charset encoding) {
return data.getBytes(encoding);
}
/**
* Writes the {@link String} to the given {@link OutputStream}.
*/
public static void writeString(String value, OutputStream out) throws IOException {
writeString(value, UTF8_CHARSET, out);
}
/**
* Writes the {@link String} to the given {@link OutputStream}.
*/
public static void writeString(String value, String encoding, OutputStream out) throws IOException {
writeString(value, Charset.forName(encoding), out);
}
/**
* Writes the {@link String} to the given {@link OutputStream}.
*/
public static void writeString(String value, Charset encoding, OutputStream out) throws IOException {
byte[] data = getBytes(value, encoding); | // Path: src/main/java/org/ardverk/io/ByteUtils.java
// public class ByteUtils {
//
// private ByteUtils() {}
//
// /**
// * @see DataInput#readFully(byte[])
// */
// public static byte[] readFully(InputStream in, byte[] dst) throws IOException {
// return readFully(in, dst, 0, dst.length);
// }
//
// /**
// * @see DataInput#readFully(byte[])
// */
// public static byte[] readFully(InputStream in, byte[] dst,
// int offset, int length) throws IOException {
//
// int total = 0;
// while (total < length) {
// int r = in.read(dst, offset + total, length - total);
// if (r == -1) {
// throw new EOFException();
// }
//
// total += r;
// }
//
// return dst;
// }
//
// public static void writeBytes(byte[] data, OutputStream out) throws IOException {
// writeBytes(data, 0, data.length, out);
// }
//
// public static void writeBytes(byte[] data, int offset, int length,
// OutputStream out) throws IOException {
// DataUtils.int2vbeb(length, out);
// out.write(data, offset, length);
// }
//
// public static byte[] readBytes(InputStream in) throws IOException {
// int length = DataUtils.vbeb2int(in);
// byte[] data = new byte[length];
// return readFully(in, data);
// }
// }
// Path: src/main/java/org/ardverk/utils/StringUtils.java
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import org.ardverk.io.ByteUtils;
return getBytes(data, UTF8_CHARSET);
}
public static byte[] getBytes(String data, String encoding) {
return getBytes(data, Charset.forName(encoding));
}
public static byte[] getBytes(String data, Charset encoding) {
return data.getBytes(encoding);
}
/**
* Writes the {@link String} to the given {@link OutputStream}.
*/
public static void writeString(String value, OutputStream out) throws IOException {
writeString(value, UTF8_CHARSET, out);
}
/**
* Writes the {@link String} to the given {@link OutputStream}.
*/
public static void writeString(String value, String encoding, OutputStream out) throws IOException {
writeString(value, Charset.forName(encoding), out);
}
/**
* Writes the {@link String} to the given {@link OutputStream}.
*/
public static void writeString(String value, Charset encoding, OutputStream out) throws IOException {
byte[] data = getBytes(value, encoding); | ByteUtils.writeBytes(data, out); |
rkapsi/ardverk-commons | src/test/java/org/ardverk/io/ProgressInputStreamTest.java | // Path: src/main/java/org/ardverk/io/ProgressInputStream.java
// public static class ProgressAdapter implements ProgressCallback {
// @Override
// public void in(InputStream in, int count) {
// }
//
// @Override
// public void eof(InputStream in) {
// }
//
// @Override
// public void closed(InputStream in) {
// }
// }
//
// Path: src/main/java/org/ardverk/io/ProgressInputStream.java
// public static interface ProgressCallback {
// /**
// * Called every time some data has been read from
// * the {@link ProgressInputStream}.
// */
// public void in(InputStream in, int count);
//
// /**
// * Called if the {@link ProgressInputStream}'s EOF has been reached.
// */
// public void eof(InputStream in);
//
// /**
// * Called if the {@link ProgressInputStream} has been closed.
// *
// * @see ProgressInputStream#close()
// */
// public void closed(InputStream in);
// }
| import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.ardverk.io.ProgressInputStream.ProgressAdapter;
import org.ardverk.io.ProgressInputStream.ProgressCallback;
import org.junit.Test; | package org.ardverk.io;
public class ProgressInputStreamTest {
@Test
public void close() throws IOException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1); | // Path: src/main/java/org/ardverk/io/ProgressInputStream.java
// public static class ProgressAdapter implements ProgressCallback {
// @Override
// public void in(InputStream in, int count) {
// }
//
// @Override
// public void eof(InputStream in) {
// }
//
// @Override
// public void closed(InputStream in) {
// }
// }
//
// Path: src/main/java/org/ardverk/io/ProgressInputStream.java
// public static interface ProgressCallback {
// /**
// * Called every time some data has been read from
// * the {@link ProgressInputStream}.
// */
// public void in(InputStream in, int count);
//
// /**
// * Called if the {@link ProgressInputStream}'s EOF has been reached.
// */
// public void eof(InputStream in);
//
// /**
// * Called if the {@link ProgressInputStream} has been closed.
// *
// * @see ProgressInputStream#close()
// */
// public void closed(InputStream in);
// }
// Path: src/test/java/org/ardverk/io/ProgressInputStreamTest.java
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.ardverk.io.ProgressInputStream.ProgressAdapter;
import org.ardverk.io.ProgressInputStream.ProgressCallback;
import org.junit.Test;
package org.ardverk.io;
public class ProgressInputStreamTest {
@Test
public void close() throws IOException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1); | ProgressCallback callback = new ProgressAdapter() { |
rkapsi/ardverk-commons | src/test/java/org/ardverk/io/ProgressInputStreamTest.java | // Path: src/main/java/org/ardverk/io/ProgressInputStream.java
// public static class ProgressAdapter implements ProgressCallback {
// @Override
// public void in(InputStream in, int count) {
// }
//
// @Override
// public void eof(InputStream in) {
// }
//
// @Override
// public void closed(InputStream in) {
// }
// }
//
// Path: src/main/java/org/ardverk/io/ProgressInputStream.java
// public static interface ProgressCallback {
// /**
// * Called every time some data has been read from
// * the {@link ProgressInputStream}.
// */
// public void in(InputStream in, int count);
//
// /**
// * Called if the {@link ProgressInputStream}'s EOF has been reached.
// */
// public void eof(InputStream in);
//
// /**
// * Called if the {@link ProgressInputStream} has been closed.
// *
// * @see ProgressInputStream#close()
// */
// public void closed(InputStream in);
// }
| import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.ardverk.io.ProgressInputStream.ProgressAdapter;
import org.ardverk.io.ProgressInputStream.ProgressCallback;
import org.junit.Test; | package org.ardverk.io;
public class ProgressInputStreamTest {
@Test
public void close() throws IOException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1); | // Path: src/main/java/org/ardverk/io/ProgressInputStream.java
// public static class ProgressAdapter implements ProgressCallback {
// @Override
// public void in(InputStream in, int count) {
// }
//
// @Override
// public void eof(InputStream in) {
// }
//
// @Override
// public void closed(InputStream in) {
// }
// }
//
// Path: src/main/java/org/ardverk/io/ProgressInputStream.java
// public static interface ProgressCallback {
// /**
// * Called every time some data has been read from
// * the {@link ProgressInputStream}.
// */
// public void in(InputStream in, int count);
//
// /**
// * Called if the {@link ProgressInputStream}'s EOF has been reached.
// */
// public void eof(InputStream in);
//
// /**
// * Called if the {@link ProgressInputStream} has been closed.
// *
// * @see ProgressInputStream#close()
// */
// public void closed(InputStream in);
// }
// Path: src/test/java/org/ardverk/io/ProgressInputStreamTest.java
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.ardverk.io.ProgressInputStream.ProgressAdapter;
import org.ardverk.io.ProgressInputStream.ProgressCallback;
import org.junit.Test;
package org.ardverk.io;
public class ProgressInputStreamTest {
@Test
public void close() throws IOException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1); | ProgressCallback callback = new ProgressAdapter() { |
rkapsi/ardverk-commons | src/main/java/org/ardverk/utils/ReverseComparator.java | // Path: src/main/java/org/ardverk/lang/Precoditions.java
// public class Precoditions {
//
// private Precoditions() {}
//
// public static void argument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// public static void argument(boolean expression, String message) {
// if (!expression) {
// throw new IllegalArgumentException(message);
// }
// }
//
// public static void argument(boolean expression,
// String message, Object... arguments) {
// if (!expression) {
// throw new IllegalArgumentException(String.format(message, arguments));
// }
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t) {
// return notNull(t, null);
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t, String message) {
// if (t == null) {
// if (message != null) {
// throw new NullPointerException(message);
// }
// throw new NullPointerException();
// }
// return t;
// }
// }
| import java.io.Serializable;
import java.util.Comparator;
import org.ardverk.lang.Precoditions; | /*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.utils;
/**
* A {@link ReverseComparator} takes a {@link Comparator} as input and reverses
* the {@link Comparator}'s output. It's useful for changing the sorting order
* for example.
*/
public class ReverseComparator<T> implements Comparator<T>, Serializable {
private static final long serialVersionUID = 563094817278176159L;
private final Comparator<? super T> comparator;
public ReverseComparator(Comparator<? super T> comparator) { | // Path: src/main/java/org/ardverk/lang/Precoditions.java
// public class Precoditions {
//
// private Precoditions() {}
//
// public static void argument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// public static void argument(boolean expression, String message) {
// if (!expression) {
// throw new IllegalArgumentException(message);
// }
// }
//
// public static void argument(boolean expression,
// String message, Object... arguments) {
// if (!expression) {
// throw new IllegalArgumentException(String.format(message, arguments));
// }
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t) {
// return notNull(t, null);
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t, String message) {
// if (t == null) {
// if (message != null) {
// throw new NullPointerException(message);
// }
// throw new NullPointerException();
// }
// return t;
// }
// }
// Path: src/main/java/org/ardverk/utils/ReverseComparator.java
import java.io.Serializable;
import java.util.Comparator;
import org.ardverk.lang.Precoditions;
/*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.utils;
/**
* A {@link ReverseComparator} takes a {@link Comparator} as input and reverses
* the {@link Comparator}'s output. It's useful for changing the sorting order
* for example.
*/
public class ReverseComparator<T> implements Comparator<T>, Serializable {
private static final long serialVersionUID = 563094817278176159L;
private final Comparator<? super T> comparator;
public ReverseComparator(Comparator<? super T> comparator) { | this.comparator = Precoditions.notNull(comparator, "comparator"); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/utils/ByteArrayComparator.java | // Path: src/main/java/org/ardverk/lang/Bytes.java
// public class Bytes {
//
// /**
// * An empty {@code byte} array.
// */
// public static final byte[] EMPTY = new byte[0];
//
// private Bytes() {}
//
// /**
// * Compares the given {@code byte} values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compare(byte b1, byte b2) {
// if (b1 < b2) {
// return -1;
// } else if (b2 < b1) {
// return 1;
// }
// return 0;
// }
//
// /**
// * Compares the given {@code byte}s as unsigned values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compareUnsigned(int b1, int b2) {
// return (b1 & 0xFF) - (b2 & 0xFF);
// }
// }
| import java.io.Serializable;
import java.util.Comparator;
import org.ardverk.lang.Bytes; | /*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.utils;
/**
* A {@link Comparator} for byte-arrays.
*/
public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
private static final long serialVersionUID = 6625000716332463624L;
public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
@Override
public int compare(byte[] o1, byte[] o2) {
if (o1.length != o2.length) {
return o1.length - o2.length;
}
for (int i = 0; i < o1.length; i++) { | // Path: src/main/java/org/ardverk/lang/Bytes.java
// public class Bytes {
//
// /**
// * An empty {@code byte} array.
// */
// public static final byte[] EMPTY = new byte[0];
//
// private Bytes() {}
//
// /**
// * Compares the given {@code byte} values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compare(byte b1, byte b2) {
// if (b1 < b2) {
// return -1;
// } else if (b2 < b1) {
// return 1;
// }
// return 0;
// }
//
// /**
// * Compares the given {@code byte}s as unsigned values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compareUnsigned(int b1, int b2) {
// return (b1 & 0xFF) - (b2 & 0xFF);
// }
// }
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
import java.io.Serializable;
import java.util.Comparator;
import org.ardverk.lang.Bytes;
/*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.utils;
/**
* A {@link Comparator} for byte-arrays.
*/
public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
private static final long serialVersionUID = 6625000716332463624L;
public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
@Override
public int compare(byte[] o1, byte[] o2) {
if (o1.length != o2.length) {
return o1.length - o2.length;
}
for (int i = 0; i < o1.length; i++) { | int diff = Bytes.compareUnsigned(o1[i], o2[i]); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/io/GzipCompressor.java | // Path: src/main/java/org/ardverk/lang/MathUtils.java
// public class MathUtils {
//
// private MathUtils() {}
//
// /**
// * Returns the closest power of two value that's greater or
// * equal to the given argument.
// */
// public static int nextPowOfTwo(int expected) {
// int value = 1;
// while (value < expected) {
// value <<= 1;
// }
// return value;
// }
// }
| import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.ardverk.lang.MathUtils; | /*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.io;
/**
* An implementation of {@link Compressor} that uses Java's
* {@link GZIPInputStream} and {@link GZIPOutputStream}.
*/
public class GzipCompressor extends AbstractCompressor {
public static final GzipCompressor GZIP = new GzipCompressor();
private GzipCompressor() {
super("GZIP");
}
@Override
public byte[] compress(byte[] value, int offset, int length)
throws IOException {
| // Path: src/main/java/org/ardverk/lang/MathUtils.java
// public class MathUtils {
//
// private MathUtils() {}
//
// /**
// * Returns the closest power of two value that's greater or
// * equal to the given argument.
// */
// public static int nextPowOfTwo(int expected) {
// int value = 1;
// while (value < expected) {
// value <<= 1;
// }
// return value;
// }
// }
// Path: src/main/java/org/ardverk/io/GzipCompressor.java
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.ardverk.lang.MathUtils;
/*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.io;
/**
* An implementation of {@link Compressor} that uses Java's
* {@link GZIPInputStream} and {@link GZIPOutputStream}.
*/
public class GzipCompressor extends AbstractCompressor {
public static final GzipCompressor GZIP = new GzipCompressor();
private GzipCompressor() {
super("GZIP");
}
@Override
public byte[] compress(byte[] value, int offset, int length)
throws IOException {
| ByteArrayOutputStream baos = new ByteArrayOutputStream(MathUtils.nextPowOfTwo(length)); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/security/token/DefaultSecurityToken.java | // Path: src/main/java/org/ardverk/security/SecurityUtils.java
// public class SecurityUtils {
//
// private static final int SEED_LENGTH = 32;
//
// private SecurityUtils() {}
//
// /**
// * Creates and returns a {@link SecureRandom}. The difference between
// * this factory method and {@link SecureRandom}'s default constructor
// * is that this will try to initialize the {@link SecureRandom} with
// * an initial seed from /dev/urandom while the default constructor will
// * attempt to do the same from /dev/random which may block if there is
// * not enough data available.
// */
// public static SecureRandom createSecureRandom() {
// // All Unix like Systems should have this device.
// File file = new File("/dev/urandom");
//
// if (file.exists() && file.canRead()) {
// try (DataInputStream in = new DataInputStream(new FileInputStream(file))) {
// byte[] seed = new byte[SEED_LENGTH];
// in.readFully(seed);
// return new SecureRandom(seed);
// } catch (SecurityException | IOException ignore) {}
// }
//
// // We're either on Windows or something else happened.
// return new SecureRandom();
// }
// }
| import java.io.Closeable;
import java.security.MessageDigest;
import java.util.Random;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.ardverk.concurrent.ExecutorUtils;
import org.ardverk.concurrent.FutureUtils;
import org.ardverk.security.SecurityUtils; | /*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.security.token;
/**
* A default implementation of {@link SecurityToken}.
*/
public class DefaultSecurityToken extends AbstractSecurityToken implements Closeable {
private static final ScheduledExecutorService EXECUTOR
= ExecutorUtils.newSingleThreadScheduledExecutor("SecurityTokenThread");
| // Path: src/main/java/org/ardverk/security/SecurityUtils.java
// public class SecurityUtils {
//
// private static final int SEED_LENGTH = 32;
//
// private SecurityUtils() {}
//
// /**
// * Creates and returns a {@link SecureRandom}. The difference between
// * this factory method and {@link SecureRandom}'s default constructor
// * is that this will try to initialize the {@link SecureRandom} with
// * an initial seed from /dev/urandom while the default constructor will
// * attempt to do the same from /dev/random which may block if there is
// * not enough data available.
// */
// public static SecureRandom createSecureRandom() {
// // All Unix like Systems should have this device.
// File file = new File("/dev/urandom");
//
// if (file.exists() && file.canRead()) {
// try (DataInputStream in = new DataInputStream(new FileInputStream(file))) {
// byte[] seed = new byte[SEED_LENGTH];
// in.readFully(seed);
// return new SecureRandom(seed);
// } catch (SecurityException | IOException ignore) {}
// }
//
// // We're either on Windows or something else happened.
// return new SecureRandom();
// }
// }
// Path: src/main/java/org/ardverk/security/token/DefaultSecurityToken.java
import java.io.Closeable;
import java.security.MessageDigest;
import java.util.Random;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.ardverk.concurrent.ExecutorUtils;
import org.ardverk.concurrent.FutureUtils;
import org.ardverk.security.SecurityUtils;
/*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.security.token;
/**
* A default implementation of {@link SecurityToken}.
*/
public class DefaultSecurityToken extends AbstractSecurityToken implements Closeable {
private static final ScheduledExecutorService EXECUTOR
= ExecutorUtils.newSingleThreadScheduledExecutor("SecurityTokenThread");
| private static final Random RANDOM = SecurityUtils.createSecureRandom(); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/net/NetworkMask.java | // Path: src/main/java/org/ardverk/io/Streamable.java
// public interface Streamable {
//
// /**
// * Writes this Object to the given {@link OutputStream} and returns
// * the number of bytes that were written.
// */
// public void writeTo(OutputStream out) throws IOException;
// }
//
// Path: src/main/java/org/ardverk/lang/Bytes.java
// public class Bytes {
//
// /**
// * An empty {@code byte} array.
// */
// public static final byte[] EMPTY = new byte[0];
//
// private Bytes() {}
//
// /**
// * Compares the given {@code byte} values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compare(byte b1, byte b2) {
// if (b1 < b2) {
// return -1;
// } else if (b2 < b1) {
// return 1;
// }
// return 0;
// }
//
// /**
// * Compares the given {@code byte}s as unsigned values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compareUnsigned(int b1, int b2) {
// return (b1 & 0xFF) - (b2 & 0xFF);
// }
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
| import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import org.ardverk.io.Streamable;
import org.ardverk.lang.Bytes;
import org.ardverk.utils.ByteArrayComparator; | /*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.net;
/**
* A Network Mask
*/
public class NetworkMask implements Comparable<NetworkMask>,
Serializable, Streamable, Cloneable {
private static final long serialVersionUID = 7628001660790804026L;
/**
* A {@link NetworkMask} that does nothing
*/
public static final NetworkMask NOP | // Path: src/main/java/org/ardverk/io/Streamable.java
// public interface Streamable {
//
// /**
// * Writes this Object to the given {@link OutputStream} and returns
// * the number of bytes that were written.
// */
// public void writeTo(OutputStream out) throws IOException;
// }
//
// Path: src/main/java/org/ardverk/lang/Bytes.java
// public class Bytes {
//
// /**
// * An empty {@code byte} array.
// */
// public static final byte[] EMPTY = new byte[0];
//
// private Bytes() {}
//
// /**
// * Compares the given {@code byte} values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compare(byte b1, byte b2) {
// if (b1 < b2) {
// return -1;
// } else if (b2 < b1) {
// return 1;
// }
// return 0;
// }
//
// /**
// * Compares the given {@code byte}s as unsigned values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compareUnsigned(int b1, int b2) {
// return (b1 & 0xFF) - (b2 & 0xFF);
// }
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
// Path: src/main/java/org/ardverk/net/NetworkMask.java
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import org.ardverk.io.Streamable;
import org.ardverk.lang.Bytes;
import org.ardverk.utils.ByteArrayComparator;
/*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.net;
/**
* A Network Mask
*/
public class NetworkMask implements Comparable<NetworkMask>,
Serializable, Streamable, Cloneable {
private static final long serialVersionUID = 7628001660790804026L;
/**
* A {@link NetworkMask} that does nothing
*/
public static final NetworkMask NOP | = new NetworkMask(Bytes.EMPTY); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/net/NetworkMask.java | // Path: src/main/java/org/ardverk/io/Streamable.java
// public interface Streamable {
//
// /**
// * Writes this Object to the given {@link OutputStream} and returns
// * the number of bytes that were written.
// */
// public void writeTo(OutputStream out) throws IOException;
// }
//
// Path: src/main/java/org/ardverk/lang/Bytes.java
// public class Bytes {
//
// /**
// * An empty {@code byte} array.
// */
// public static final byte[] EMPTY = new byte[0];
//
// private Bytes() {}
//
// /**
// * Compares the given {@code byte} values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compare(byte b1, byte b2) {
// if (b1 < b2) {
// return -1;
// } else if (b2 < b1) {
// return 1;
// }
// return 0;
// }
//
// /**
// * Compares the given {@code byte}s as unsigned values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compareUnsigned(int b1, int b2) {
// return (b1 & 0xFF) - (b2 & 0xFF);
// }
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
| import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import org.ardverk.io.Streamable;
import org.ardverk.lang.Bytes;
import org.ardverk.utils.ByteArrayComparator; | /**
* Returns true if the two given addresses are in the same network.
*/
boolean isSameNetwork(byte[] a, byte[] b, boolean copy) {
return Arrays.equals(mask(a, copy), mask(b, copy));
}
@Override
public NetworkMask clone() {
return this;
}
@Override
public int hashCode() {
return hashCode;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (!(o instanceof NetworkMask)) {
return false;
}
return compareTo((NetworkMask)o) == 0;
}
@Override
public int compareTo(NetworkMask o) { | // Path: src/main/java/org/ardverk/io/Streamable.java
// public interface Streamable {
//
// /**
// * Writes this Object to the given {@link OutputStream} and returns
// * the number of bytes that were written.
// */
// public void writeTo(OutputStream out) throws IOException;
// }
//
// Path: src/main/java/org/ardverk/lang/Bytes.java
// public class Bytes {
//
// /**
// * An empty {@code byte} array.
// */
// public static final byte[] EMPTY = new byte[0];
//
// private Bytes() {}
//
// /**
// * Compares the given {@code byte} values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compare(byte b1, byte b2) {
// if (b1 < b2) {
// return -1;
// } else if (b2 < b1) {
// return 1;
// }
// return 0;
// }
//
// /**
// * Compares the given {@code byte}s as unsigned values.
// *
// * @see Comparable
// * @see Comparator
// */
// public static int compareUnsigned(int b1, int b2) {
// return (b1 & 0xFF) - (b2 & 0xFF);
// }
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
// Path: src/main/java/org/ardverk/net/NetworkMask.java
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import org.ardverk.io.Streamable;
import org.ardverk.lang.Bytes;
import org.ardverk.utils.ByteArrayComparator;
/**
* Returns true if the two given addresses are in the same network.
*/
boolean isSameNetwork(byte[] a, byte[] b, boolean copy) {
return Arrays.equals(mask(a, copy), mask(b, copy));
}
@Override
public NetworkMask clone() {
return this;
}
@Override
public int hashCode() {
return hashCode;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (!(o instanceof NetworkMask)) {
return false;
}
return compareTo((NetworkMask)o) == 0;
}
@Override
public int compareTo(NetworkMask o) { | return ByteArrayComparator.COMPARATOR.compare(mask, o.mask); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/net/NetworkCounter.java | // Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
//
// private CodingUtils() {}
//
// /**
// * Encodes the given {@link String} in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(String data) {
// return encodeBase2(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data) {
// return encodeBase2(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data, int offset, int length) {
// return StringUtils.toString(Base2.encodeBase2(data, offset, length));
// }
//
// /**
// * Encodes the given {@link String} in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(String data) {
// return encodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data) {
// return encodeBase16(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data, int offset, int length) {
// return StringUtils.toString(Base16.encodeBase16(data, offset, length));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded {@link String}.
// */
// public static byte[] decodeBase16(String data) {
// return decodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data) {
// return decodeBase16(data, 0, data.length);
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data, int offset, int length) {
// return Base16.decodeBase16(data, offset, length);
// }
// }
//
// Path: src/main/java/org/ardverk/lang/Precoditions.java
// public class Precoditions {
//
// private Precoditions() {}
//
// public static void argument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// public static void argument(boolean expression, String message) {
// if (!expression) {
// throw new IllegalArgumentException(message);
// }
// }
//
// public static void argument(boolean expression,
// String message, Object... arguments) {
// if (!expression) {
// throw new IllegalArgumentException(String.format(message, arguments));
// }
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t) {
// return notNull(t, null);
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t, String message) {
// if (t == null) {
// if (message != null) {
// throw new NullPointerException(message);
// }
// throw new NullPointerException();
// }
// return t;
// }
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
| import org.ardverk.utils.ByteArrayComparator;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import org.ardverk.coding.CodingUtils;
import org.ardverk.lang.Precoditions; | /*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.net;
/**
* A special purpose counter that counts {@link InetAddress}es
* by their network class.
*/
public class NetworkCounter implements Serializable {
private static final long serialVersionUID = -7103271018736085248L;
private final NetworkMask mask;
private final Map<byte[], AtomicInteger> map
= new TreeMap<byte[], AtomicInteger>( | // Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
//
// private CodingUtils() {}
//
// /**
// * Encodes the given {@link String} in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(String data) {
// return encodeBase2(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data) {
// return encodeBase2(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data, int offset, int length) {
// return StringUtils.toString(Base2.encodeBase2(data, offset, length));
// }
//
// /**
// * Encodes the given {@link String} in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(String data) {
// return encodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data) {
// return encodeBase16(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data, int offset, int length) {
// return StringUtils.toString(Base16.encodeBase16(data, offset, length));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded {@link String}.
// */
// public static byte[] decodeBase16(String data) {
// return decodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data) {
// return decodeBase16(data, 0, data.length);
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data, int offset, int length) {
// return Base16.decodeBase16(data, offset, length);
// }
// }
//
// Path: src/main/java/org/ardverk/lang/Precoditions.java
// public class Precoditions {
//
// private Precoditions() {}
//
// public static void argument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// public static void argument(boolean expression, String message) {
// if (!expression) {
// throw new IllegalArgumentException(message);
// }
// }
//
// public static void argument(boolean expression,
// String message, Object... arguments) {
// if (!expression) {
// throw new IllegalArgumentException(String.format(message, arguments));
// }
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t) {
// return notNull(t, null);
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t, String message) {
// if (t == null) {
// if (message != null) {
// throw new NullPointerException(message);
// }
// throw new NullPointerException();
// }
// return t;
// }
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
// Path: src/main/java/org/ardverk/net/NetworkCounter.java
import org.ardverk.utils.ByteArrayComparator;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import org.ardverk.coding.CodingUtils;
import org.ardverk.lang.Precoditions;
/*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.net;
/**
* A special purpose counter that counts {@link InetAddress}es
* by their network class.
*/
public class NetworkCounter implements Serializable {
private static final long serialVersionUID = -7103271018736085248L;
private final NetworkMask mask;
private final Map<byte[], AtomicInteger> map
= new TreeMap<byte[], AtomicInteger>( | ByteArrayComparator.COMPARATOR); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/net/NetworkCounter.java | // Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
//
// private CodingUtils() {}
//
// /**
// * Encodes the given {@link String} in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(String data) {
// return encodeBase2(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data) {
// return encodeBase2(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data, int offset, int length) {
// return StringUtils.toString(Base2.encodeBase2(data, offset, length));
// }
//
// /**
// * Encodes the given {@link String} in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(String data) {
// return encodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data) {
// return encodeBase16(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data, int offset, int length) {
// return StringUtils.toString(Base16.encodeBase16(data, offset, length));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded {@link String}.
// */
// public static byte[] decodeBase16(String data) {
// return decodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data) {
// return decodeBase16(data, 0, data.length);
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data, int offset, int length) {
// return Base16.decodeBase16(data, offset, length);
// }
// }
//
// Path: src/main/java/org/ardverk/lang/Precoditions.java
// public class Precoditions {
//
// private Precoditions() {}
//
// public static void argument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// public static void argument(boolean expression, String message) {
// if (!expression) {
// throw new IllegalArgumentException(message);
// }
// }
//
// public static void argument(boolean expression,
// String message, Object... arguments) {
// if (!expression) {
// throw new IllegalArgumentException(String.format(message, arguments));
// }
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t) {
// return notNull(t, null);
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t, String message) {
// if (t == null) {
// if (message != null) {
// throw new NullPointerException(message);
// }
// throw new NullPointerException();
// }
// return t;
// }
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
| import org.ardverk.utils.ByteArrayComparator;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import org.ardverk.coding.CodingUtils;
import org.ardverk.lang.Precoditions; | /*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.net;
/**
* A special purpose counter that counts {@link InetAddress}es
* by their network class.
*/
public class NetworkCounter implements Serializable {
private static final long serialVersionUID = -7103271018736085248L;
private final NetworkMask mask;
private final Map<byte[], AtomicInteger> map
= new TreeMap<byte[], AtomicInteger>(
ByteArrayComparator.COMPARATOR);
/**
* Creates a {@link NetworkCounter} with the given {@link NetworkMask}.
*/
public NetworkCounter(NetworkMask mask) { | // Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
//
// private CodingUtils() {}
//
// /**
// * Encodes the given {@link String} in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(String data) {
// return encodeBase2(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data) {
// return encodeBase2(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data, int offset, int length) {
// return StringUtils.toString(Base2.encodeBase2(data, offset, length));
// }
//
// /**
// * Encodes the given {@link String} in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(String data) {
// return encodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data) {
// return encodeBase16(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data, int offset, int length) {
// return StringUtils.toString(Base16.encodeBase16(data, offset, length));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded {@link String}.
// */
// public static byte[] decodeBase16(String data) {
// return decodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data) {
// return decodeBase16(data, 0, data.length);
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data, int offset, int length) {
// return Base16.decodeBase16(data, offset, length);
// }
// }
//
// Path: src/main/java/org/ardverk/lang/Precoditions.java
// public class Precoditions {
//
// private Precoditions() {}
//
// public static void argument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// public static void argument(boolean expression, String message) {
// if (!expression) {
// throw new IllegalArgumentException(message);
// }
// }
//
// public static void argument(boolean expression,
// String message, Object... arguments) {
// if (!expression) {
// throw new IllegalArgumentException(String.format(message, arguments));
// }
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t) {
// return notNull(t, null);
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t, String message) {
// if (t == null) {
// if (message != null) {
// throw new NullPointerException(message);
// }
// throw new NullPointerException();
// }
// return t;
// }
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
// Path: src/main/java/org/ardverk/net/NetworkCounter.java
import org.ardverk.utils.ByteArrayComparator;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import org.ardverk.coding.CodingUtils;
import org.ardverk.lang.Precoditions;
/*
* Copyright 2010-2012 Roger Kapsi
*
* 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 org.ardverk.net;
/**
* A special purpose counter that counts {@link InetAddress}es
* by their network class.
*/
public class NetworkCounter implements Serializable {
private static final long serialVersionUID = -7103271018736085248L;
private final NetworkMask mask;
private final Map<byte[], AtomicInteger> map
= new TreeMap<byte[], AtomicInteger>(
ByteArrayComparator.COMPARATOR);
/**
* Creates a {@link NetworkCounter} with the given {@link NetworkMask}.
*/
public NetworkCounter(NetworkMask mask) { | this.mask = Precoditions.notNull(mask, "mask"); |
rkapsi/ardverk-commons | src/main/java/org/ardverk/net/NetworkCounter.java | // Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
//
// private CodingUtils() {}
//
// /**
// * Encodes the given {@link String} in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(String data) {
// return encodeBase2(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data) {
// return encodeBase2(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data, int offset, int length) {
// return StringUtils.toString(Base2.encodeBase2(data, offset, length));
// }
//
// /**
// * Encodes the given {@link String} in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(String data) {
// return encodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data) {
// return encodeBase16(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data, int offset, int length) {
// return StringUtils.toString(Base16.encodeBase16(data, offset, length));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded {@link String}.
// */
// public static byte[] decodeBase16(String data) {
// return decodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data) {
// return decodeBase16(data, 0, data.length);
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data, int offset, int length) {
// return Base16.decodeBase16(data, offset, length);
// }
// }
//
// Path: src/main/java/org/ardverk/lang/Precoditions.java
// public class Precoditions {
//
// private Precoditions() {}
//
// public static void argument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// public static void argument(boolean expression, String message) {
// if (!expression) {
// throw new IllegalArgumentException(message);
// }
// }
//
// public static void argument(boolean expression,
// String message, Object... arguments) {
// if (!expression) {
// throw new IllegalArgumentException(String.format(message, arguments));
// }
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t) {
// return notNull(t, null);
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t, String message) {
// if (t == null) {
// if (message != null) {
// throw new NullPointerException(message);
// }
// throw new NullPointerException();
// }
// return t;
// }
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
| import org.ardverk.utils.ByteArrayComparator;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import org.ardverk.coding.CodingUtils;
import org.ardverk.lang.Precoditions; | return copy.entrySet();
}
/**
* Returns the number of networks
*/
public synchronized int size() {
return map.size();
}
/**
* Returns true if this {@link NetworkCounter} is empty
*/
public synchronized boolean isEmpty() {
return map.isEmpty();
}
/**
* Clears the {@link NetworkCounter}
*/
public synchronized void clear() {
map.clear();
}
@Override
public synchronized String toString() {
StringBuilder buffer = new StringBuilder("[");
if (!map.isEmpty()) {
for (Map.Entry<byte[], AtomicInteger> entry : map.entrySet()) { | // Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
//
// private CodingUtils() {}
//
// /**
// * Encodes the given {@link String} in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(String data) {
// return encodeBase2(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data) {
// return encodeBase2(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-2 (binary) and returns it
// * as a {@link String}.
// */
// public static String encodeBase2(byte[] data, int offset, int length) {
// return StringUtils.toString(Base2.encodeBase2(data, offset, length));
// }
//
// /**
// * Encodes the given {@link String} in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(String data) {
// return encodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data) {
// return encodeBase16(data, 0, data.length);
// }
//
// /**
// * Encodes the given byte-array in Base-16 (hex) and returns it
// * as a {@link String}.
// */
// public static String encodeBase16(byte[] data, int offset, int length) {
// return StringUtils.toString(Base16.encodeBase16(data, offset, length));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded {@link String}.
// */
// public static byte[] decodeBase16(String data) {
// return decodeBase16(StringUtils.getBytes(data));
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data) {
// return decodeBase16(data, 0, data.length);
// }
//
// /**
// * Decodes a Base-16 (hex) encoded value.
// */
// public static byte[] decodeBase16(byte[] data, int offset, int length) {
// return Base16.decodeBase16(data, offset, length);
// }
// }
//
// Path: src/main/java/org/ardverk/lang/Precoditions.java
// public class Precoditions {
//
// private Precoditions() {}
//
// public static void argument(boolean expression) {
// if (!expression) {
// throw new IllegalArgumentException();
// }
// }
//
// public static void argument(boolean expression, String message) {
// if (!expression) {
// throw new IllegalArgumentException(message);
// }
// }
//
// public static void argument(boolean expression,
// String message, Object... arguments) {
// if (!expression) {
// throw new IllegalArgumentException(String.format(message, arguments));
// }
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t) {
// return notNull(t, null);
// }
//
// /**
// * Makes sure the given argument is not {@code null}.
// */
// public static <T> T notNull(T t, String message) {
// if (t == null) {
// if (message != null) {
// throw new NullPointerException(message);
// }
// throw new NullPointerException();
// }
// return t;
// }
// }
//
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
//
// private static final long serialVersionUID = 6625000716332463624L;
//
// public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//
// @Override
// public int compare(byte[] o1, byte[] o2) {
// if (o1.length != o2.length) {
// return o1.length - o2.length;
// }
//
// for (int i = 0; i < o1.length; i++) {
// int diff = Bytes.compareUnsigned(o1[i], o2[i]);
// if (diff != 0) {
// return diff;
// }
// }
//
// return 0;
// }
// }
// Path: src/main/java/org/ardverk/net/NetworkCounter.java
import org.ardverk.utils.ByteArrayComparator;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import org.ardverk.coding.CodingUtils;
import org.ardverk.lang.Precoditions;
return copy.entrySet();
}
/**
* Returns the number of networks
*/
public synchronized int size() {
return map.size();
}
/**
* Returns true if this {@link NetworkCounter} is empty
*/
public synchronized boolean isEmpty() {
return map.isEmpty();
}
/**
* Clears the {@link NetworkCounter}
*/
public synchronized void clear() {
map.clear();
}
@Override
public synchronized String toString() {
StringBuilder buffer = new StringBuilder("[");
if (!map.isEmpty()) {
for (Map.Entry<byte[], AtomicInteger> entry : map.entrySet()) { | buffer.append(CodingUtils.encodeBase16(entry.getKey())) |
fipro78/osgi-ds-getting-started-pde | org.fipro.inverter.integration.tests/src/org/fipro/inverter/integration/tests/IntegrationTest.java | // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.fipro.inverter.StringInverter;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.util.tracker.ServiceTracker; | package org.fipro.inverter.integration.tests;
public class IntegrationTest {
@Test
public void shouldInvertWithService() { | // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
// Path: org.fipro.inverter.integration.tests/src/org/fipro/inverter/integration/tests/IntegrationTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.fipro.inverter.StringInverter;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.util.tracker.ServiceTracker;
package org.fipro.inverter.integration.tests;
public class IntegrationTest {
@Test
public void shouldInvertWithService() { | StringInverter inverter = getService(StringInverter.class); |
fipro78/osgi-ds-getting-started-pde | org.fipro.ds.data.offline/src/org/fipro/ds/data/offline/OfflineDataService.java | // Path: org.fipro.ds.data.api/src/org/fipro/ds/data/DataService.java
// public interface DataService {
//
// /**
// * @param id
// * The id of the requested data value.
// * @return The data value for the given id.
// */
// String getData(int id);
// }
| import java.util.Map;
import org.fipro.ds.data.DataService;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component; | package org.fipro.ds.data.offline;
@Component(
property= {
"fipro.connectivity=offline",
"service.ranking:Integer=5",
".private=private configuration"
}
) | // Path: org.fipro.ds.data.api/src/org/fipro/ds/data/DataService.java
// public interface DataService {
//
// /**
// * @param id
// * The id of the requested data value.
// * @return The data value for the given id.
// */
// String getData(int id);
// }
// Path: org.fipro.ds.data.offline/src/org/fipro/ds/data/offline/OfflineDataService.java
import java.util.Map;
import org.fipro.ds.data.DataService;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
package org.fipro.ds.data.offline;
@Component(
property= {
"fipro.connectivity=offline",
"service.ranking:Integer=5",
".private=private configuration"
}
) | public class OfflineDataService implements DataService { |
fipro78/osgi-ds-getting-started-pde | org.fipro.oneshot.assassinate/src/org/fipro/oneshot/assassinate/EliminateCommand.java | // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
| import org.fipro.oneshot.OneShot;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference; | package org.fipro.oneshot.assassinate;
@Component(
property= {
"osgi.command.scope=fipro",
"osgi.command.function=eliminate"},
service=EliminateCommand.class
)
public class EliminateCommand {
private ComponentContext context; | // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
// Path: org.fipro.oneshot.assassinate/src/org/fipro/oneshot/assassinate/EliminateCommand.java
import org.fipro.oneshot.OneShot;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
package org.fipro.oneshot.assassinate;
@Component(
property= {
"osgi.command.scope=fipro",
"osgi.command.function=eliminate"},
service=EliminateCommand.class
)
public class EliminateCommand {
private ComponentContext context; | private ServiceReference<OneShot> sr; |
fipro78/osgi-ds-getting-started-pde | org.fipro.mafia.soldier/src/org/fipro/mafia/soldier/Mario.java | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
| import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler; | package org.fipro.mafia.soldier;
@Component(
property = EventConstants.EVENT_TOPIC | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
// Path: org.fipro.mafia.soldier/src/org/fipro/mafia/soldier/Mario.java
import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
package org.fipro.mafia.soldier;
@Component(
property = EventConstants.EVENT_TOPIC | + "=" + MafiaBossConstants.TOPIC_ENCASH) |
fipro78/osgi-ds-getting-started-pde | org.fipro.headless.app/src/org/fipro/headless/app/EquinoxStarter.java | // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
| import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import org.eclipse.osgi.service.environment.EnvironmentInfo;
import org.fipro.inverter.StringInverter;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference; | package org.fipro.headless.app;
@Component(immediate = true)
public class EquinoxStarter {
/**
* Launcher arguments provided by the Equinox launcher.
*/
@Reference
EnvironmentInfo environmentInfo;
@Reference | // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
// Path: org.fipro.headless.app/src/org/fipro/headless/app/EquinoxStarter.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import org.eclipse.osgi.service.environment.EnvironmentInfo;
import org.fipro.inverter.StringInverter;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
package org.fipro.headless.app;
@Component(immediate = true)
public class EquinoxStarter {
/**
* Launcher arguments provided by the Equinox launcher.
*/
@Reference
EnvironmentInfo environmentInfo;
@Reference | StringInverter inverter; |
fipro78/osgi-ds-getting-started-pde | org.fipro.inverter.command/src/org/fipro/inverter/command/StringInverterCommand.java | // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
| import org.fipro.inverter.StringInverter;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference; | package org.fipro.inverter.command;
@Component(
property= {
"osgi.command.scope:String=fipro",
"osgi.command.function:String=invert"},
service=StringInverterCommand.class
)
public class StringInverterCommand {
| // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
// Path: org.fipro.inverter.command/src/org/fipro/inverter/command/StringInverterCommand.java
import org.fipro.inverter.StringInverter;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
package org.fipro.inverter.command;
@Component(
property= {
"osgi.command.scope:String=fipro",
"osgi.command.function:String=invert"},
service=StringInverterCommand.class
)
public class StringInverterCommand {
| private StringInverter inverter; |
fipro78/osgi-ds-getting-started-pde | org.fipro.mafia.soldier/src/org/fipro/mafia/soldier/Pete.java | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
| import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler; | package org.fipro.mafia.soldier;
@Component(
property = { | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
// Path: org.fipro.mafia.soldier/src/org/fipro/mafia/soldier/Pete.java
import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
package org.fipro.mafia.soldier;
@Component(
property = { | EventConstants.EVENT_TOPIC + "=" + MafiaBossConstants.TOPIC_CONVINCE, |
fipro78/osgi-ds-getting-started-pde | org.fipro.oneshot.command/src/org/fipro/oneshot/command/KillCommand.java | // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
| import org.fipro.oneshot.OneShot;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference; | package org.fipro.oneshot.command;
@Component(
property= {
"osgi.command.scope=fipro",
"osgi.command.function=kill"},
service=KillCommand.class
)
public class KillCommand {
| // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
// Path: org.fipro.oneshot.command/src/org/fipro/oneshot/command/KillCommand.java
import org.fipro.oneshot.OneShot;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
package org.fipro.oneshot.command;
@Component(
property= {
"osgi.command.scope=fipro",
"osgi.command.function=kill"},
service=KillCommand.class
)
public class KillCommand {
| private OneShot killer; |
fipro78/osgi-ds-getting-started-pde | org.fipro.headless.app/src/org/fipro/headless/app/BndStarter.java | // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
| import java.util.Arrays;
import java.util.Map;
import org.fipro.inverter.StringInverter;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference; | package org.fipro.headless.app;
@Component(immediate = true)
public class BndStarter {
/**
* Launcher arguments provided by the bnd launcher.
*/
String[] launcherArgs;
@Reference(target = "(launcher.arguments=*)")
void setLauncherArguments(Object object, Map<String, Object> map) {
this.launcherArgs = (String[]) map.get("launcher.arguments");
}
@Reference | // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
// Path: org.fipro.headless.app/src/org/fipro/headless/app/BndStarter.java
import java.util.Arrays;
import java.util.Map;
import org.fipro.inverter.StringInverter;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
package org.fipro.headless.app;
@Component(immediate = true)
public class BndStarter {
/**
* Launcher arguments provided by the bnd launcher.
*/
String[] launcherArgs;
@Reference(target = "(launcher.arguments=*)")
void setLauncherArguments(Object object, Map<String, Object> map) {
this.launcherArgs = (String[]) map.get("launcher.arguments");
}
@Reference | StringInverter inverter; |
fipro78/osgi-ds-getting-started-pde | org.fipro.mafia.soldier/src/org/fipro/mafia/soldier/Luigi.java | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
| import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler; | package org.fipro.mafia.soldier;
@Component(
property = EventConstants.EVENT_TOPIC | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
// Path: org.fipro.mafia.soldier/src/org/fipro/mafia/soldier/Luigi.java
import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
package org.fipro.mafia.soldier;
@Component(
property = EventConstants.EVENT_TOPIC | + "=" + MafiaBossConstants.TOPIC_CONVINCE) |
fipro78/osgi-ds-getting-started-pde | org.fipro.mafia.soldier/src/org/fipro/mafia/soldier/Giovanni.java | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
| import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler; | package org.fipro.mafia.soldier;
@Component(
property = EventConstants.EVENT_TOPIC | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
// Path: org.fipro.mafia.soldier/src/org/fipro/mafia/soldier/Giovanni.java
import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
package org.fipro.mafia.soldier;
@Component(
property = EventConstants.EVENT_TOPIC | + "=" + MafiaBossConstants.TOPIC_SOLVE) |
fipro78/osgi-ds-getting-started-pde | org.fipro.ds.configurator/src/org/fipro/ds/configurator/DataGetter.java | // Path: org.fipro.ds.data.api/src/org/fipro/ds/data/DataService.java
// public interface DataService {
//
// /**
// * @param id
// * The id of the requested data value.
// * @return The data value for the given id.
// */
// String getData(int id);
// }
| import java.util.Map;
import org.fipro.ds.data.DataService;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption; | package org.fipro.ds.configurator;
@Component(
property= {
"osgi.command.scope:String=fipro",
"osgi.command.function:String=get"
},
service=DataGetter.class
)
public class DataGetter {
| // Path: org.fipro.ds.data.api/src/org/fipro/ds/data/DataService.java
// public interface DataService {
//
// /**
// * @param id
// * The id of the requested data value.
// * @return The data value for the given id.
// */
// String getData(int id);
// }
// Path: org.fipro.ds.configurator/src/org/fipro/ds/configurator/DataGetter.java
import java.util.Map;
import org.fipro.ds.data.DataService;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
package org.fipro.ds.configurator;
@Component(
property= {
"osgi.command.scope:String=fipro",
"osgi.command.function:String=get"
},
service=DataGetter.class
)
public class DataGetter {
| private DataService dataService; |
fipro78/osgi-ds-getting-started-pde | org.fipro.ds.data.online/src/org/fipro/ds/data/online/OnlineDataService.java | // Path: org.fipro.ds.data.api/src/org/fipro/ds/data/DataService.java
// public interface DataService {
//
// /**
// * @param id
// * The id of the requested data value.
// * @return The data value for the given id.
// */
// String getData(int id);
// }
| import org.fipro.ds.data.DataService;
import org.osgi.service.component.annotations.Component; | package org.fipro.ds.data.online;
@Component(
property = {
"fipro.connectivity=online",
"service.ranking:Integer=7"
}
) | // Path: org.fipro.ds.data.api/src/org/fipro/ds/data/DataService.java
// public interface DataService {
//
// /**
// * @param id
// * The id of the requested data value.
// * @return The data value for the given id.
// */
// String getData(int id);
// }
// Path: org.fipro.ds.data.online/src/org/fipro/ds/data/online/OnlineDataService.java
import org.fipro.ds.data.DataService;
import org.osgi.service.component.annotations.Component;
package org.fipro.ds.data.online;
@Component(
property = {
"fipro.connectivity=online",
"service.ranking:Integer=7"
}
) | public class OnlineDataService implements DataService { |
fipro78/osgi-ds-getting-started-pde | org.fipro.inverter.http/src/org/fipro/inverter/http/InverterServlet.java | // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
| import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.fipro.inverter.StringInverter;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ServiceScope; | package org.fipro.inverter.http;
@Component(
service=Servlet.class,
property= "osgi.http.whiteboard.servlet.pattern=/invert",
scope=ServiceScope.PROTOTYPE)
public class InverterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Reference | // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
// Path: org.fipro.inverter.http/src/org/fipro/inverter/http/InverterServlet.java
import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.fipro.inverter.StringInverter;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ServiceScope;
package org.fipro.inverter.http;
@Component(
service=Servlet.class,
property= "osgi.http.whiteboard.servlet.pattern=/invert",
scope=ServiceScope.PROTOTYPE)
public class InverterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Reference | private StringInverter inverter; |
fipro78/osgi-ds-getting-started-pde | org.fipro.oneshot.provider/src/org/fipro/oneshot/provider/Borg.java | // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
| import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.fipro.oneshot.OneShot;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Modified; | package org.fipro.oneshot.provider;
@Component(
configurationPid="org.fipro.oneshot.Borg",
configurationPolicy=ConfigurationPolicy.REQUIRE) | // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
// Path: org.fipro.oneshot.provider/src/org/fipro/oneshot/provider/Borg.java
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.fipro.oneshot.OneShot;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Modified;
package org.fipro.oneshot.provider;
@Component(
configurationPid="org.fipro.oneshot.Borg",
configurationPolicy=ConfigurationPolicy.REQUIRE) | public class Borg implements OneShot { |
fipro78/osgi-ds-getting-started-pde | org.fipro.oneshot.assassinate/src/org/fipro/oneshot/assassinate/AssassinateCommand.java | // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
| import org.fipro.oneshot.OneShot;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference; | package org.fipro.oneshot.assassinate;
@Component(
property= {
"osgi.command.scope=fipro",
"osgi.command.function=assassinate"},
service=AssassinateCommand.class
)
public class AssassinateCommand {
| // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
// Path: org.fipro.oneshot.assassinate/src/org/fipro/oneshot/assassinate/AssassinateCommand.java
import org.fipro.oneshot.OneShot;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
package org.fipro.oneshot.assassinate;
@Component(
property= {
"osgi.command.scope=fipro",
"osgi.command.function=assassinate"},
service=AssassinateCommand.class
)
public class AssassinateCommand {
| private OneShot hitman; |
fipro78/osgi-ds-getting-started-pde | org.fipro.mafia.soldier/src/org/fipro/mafia/soldier/Ray.java | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
| import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler; | package org.fipro.mafia.soldier;
@Component(
property = { | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
// Path: org.fipro.mafia.soldier/src/org/fipro/mafia/soldier/Ray.java
import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
package org.fipro.mafia.soldier;
@Component(
property = { | EventConstants.EVENT_TOPIC + "=" + MafiaBossConstants.TOPIC_ALL, |
fipro78/osgi-ds-getting-started-pde | org.fipro.ds.configurator/src/org/fipro/ds/configurator/DataRetriever.java | // Path: org.fipro.ds.data.api/src/org/fipro/ds/data/DataService.java
// public interface DataService {
//
// /**
// * @param id
// * The id of the requested data value.
// * @return The data value for the given id.
// */
// String getData(int id);
// }
| import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.fipro.ds.data.DataService;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy; | package org.fipro.ds.configurator;
@Component(
property= {
"osgi.command.scope:String=fipro",
"osgi.command.function:String=retrieve"},
service=DataRetriever.class
)
public class DataRetriever {
| // Path: org.fipro.ds.data.api/src/org/fipro/ds/data/DataService.java
// public interface DataService {
//
// /**
// * @param id
// * The id of the requested data value.
// * @return The data value for the given id.
// */
// String getData(int id);
// }
// Path: org.fipro.ds.configurator/src/org/fipro/ds/configurator/DataRetriever.java
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.fipro.ds.data.DataService;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
package org.fipro.ds.configurator;
@Component(
property= {
"osgi.command.scope:String=fipro",
"osgi.command.function:String=retrieve"},
service=DataRetriever.class
)
public class DataRetriever {
| private List<DataService> dataServices = new ArrayList<>(); |
fipro78/osgi-ds-getting-started-pde | org.fipro.inverter.provider.tests/src/org/fipro/inverter/provider/StringInverterImplTest.java | // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
| import static org.junit.Assert.assertEquals;
import org.fipro.inverter.StringInverter;
import org.junit.Test; | package org.fipro.inverter.provider;
public class StringInverterImplTest {
@Test
public void shouldInvertText() { | // Path: org.fipro.inverter.api/src/org/fipro/inverter/StringInverter.java
// public interface StringInverter {
//
// String invert(String input);
//
// }
// Path: org.fipro.inverter.provider.tests/src/org/fipro/inverter/provider/StringInverterImplTest.java
import static org.junit.Assert.assertEquals;
import org.fipro.inverter.StringInverter;
import org.junit.Test;
package org.fipro.inverter.provider;
public class StringInverterImplTest {
@Test
public void shouldInvertText() { | StringInverter inverter = new StringInverterImpl(); |
fipro78/osgi-ds-getting-started-pde | org.fipro.mafia.boss/src/org/fipro/mafia/boss/BossCommand.java | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
| import java.util.HashMap;
import java.util.Map;
import org.apache.felix.service.command.Descriptor;
import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin; | package org.fipro.mafia.boss;
@Component(
property = {
"osgi.command.scope=fipro",
"osgi.command.function=boss" },
service = BossCommand.class)
public class BossCommand {
@Reference
EventAdmin eventAdmin;
@Descriptor("As a mafia boss you want something to be done")
public void boss(
@Descriptor("the command that should be executed. "
+ "possible values are: convince, encash, solve")
String command,
@Descriptor("who should be 'convinced', "
+ "'asked for protection money' or 'finally solved'")
String target) {
// create the event properties object
Map<String, Object> properties = new HashMap<>(); | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
// Path: org.fipro.mafia.boss/src/org/fipro/mafia/boss/BossCommand.java
import java.util.HashMap;
import java.util.Map;
import org.apache.felix.service.command.Descriptor;
import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
package org.fipro.mafia.boss;
@Component(
property = {
"osgi.command.scope=fipro",
"osgi.command.function=boss" },
service = BossCommand.class)
public class BossCommand {
@Reference
EventAdmin eventAdmin;
@Descriptor("As a mafia boss you want something to be done")
public void boss(
@Descriptor("the command that should be executed. "
+ "possible values are: convince, encash, solve")
String command,
@Descriptor("who should be 'convinced', "
+ "'asked for protection money' or 'finally solved'")
String target) {
// create the event properties object
Map<String, Object> properties = new HashMap<>(); | properties.put(MafiaBossConstants.PROPERTY_KEY_TARGET, target); |
fipro78/osgi-ds-getting-started-pde | org.fipro.mafia.ui/src/org/fipro/mafia/ui/MafiaPart.java | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
| import java.util.Dictionary;
import java.util.Hashtable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler; | package org.fipro.mafia.ui;
public class MafiaPart {
private Label handlerLabel;
private Label e4HandlerLabel;
private ServiceRegistration<?> eventHandler;
@PostConstruct
public void postConstruct(Composite parent) {
parent.setLayout(new GridLayout(2, false));
Label l1 = new Label(parent, SWT.NONE);
l1.setText("Received via handler:");
GridDataFactory.defaultsFor(l1).applyTo(l1);
handlerLabel = new Label(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(handlerLabel);
Label l2 = new Label(parent, SWT.NONE);
l2.setText("Received via E4 handler:");
GridDataFactory.defaultsFor(l2).applyTo(l2);
e4HandlerLabel = new Label(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(e4HandlerLabel);
// retrieve the bundle of the calling class
Bundle bundle = FrameworkUtil.getBundle(getClass());
BundleContext bc = (bundle != null) ? bundle.getBundleContext() : null;
if (bc != null) {
// create the service properties instance
Dictionary<String, Object> properties = new Hashtable<>(); | // Path: org.fipro.mafia.common/src/org/fipro/mafia/common/MafiaBossConstants.java
// public final class MafiaBossConstants {
//
// private MafiaBossConstants() {
// // private default constructor for constants class
// // to avoid someone extends the class
// }
//
// public static final String TOPIC_BASE = "org/fipro/mafia/Boss/";
// public static final String TOPIC_CONVINCE = TOPIC_BASE + "CONVINCE";
// public static final String TOPIC_ENCASH = TOPIC_BASE + "ENCASH";
// public static final String TOPIC_SOLVE = TOPIC_BASE + "SOLVE";
// public static final String TOPIC_ALL = TOPIC_BASE + "*";
//
// public static final String PROPERTY_KEY_TARGET = "target";
//
// }
// Path: org.fipro.mafia.ui/src/org/fipro/mafia/ui/MafiaPart.java
import java.util.Dictionary;
import java.util.Hashtable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.fipro.mafia.common.MafiaBossConstants;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
package org.fipro.mafia.ui;
public class MafiaPart {
private Label handlerLabel;
private Label e4HandlerLabel;
private ServiceRegistration<?> eventHandler;
@PostConstruct
public void postConstruct(Composite parent) {
parent.setLayout(new GridLayout(2, false));
Label l1 = new Label(parent, SWT.NONE);
l1.setText("Received via handler:");
GridDataFactory.defaultsFor(l1).applyTo(l1);
handlerLabel = new Label(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(handlerLabel);
Label l2 = new Label(parent, SWT.NONE);
l2.setText("Received via E4 handler:");
GridDataFactory.defaultsFor(l2).applyTo(l2);
e4HandlerLabel = new Label(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(e4HandlerLabel);
// retrieve the bundle of the calling class
Bundle bundle = FrameworkUtil.getBundle(getClass());
BundleContext bc = (bundle != null) ? bundle.getBundleContext() : null;
if (bc != null) {
// create the service properties instance
Dictionary<String, Object> properties = new Hashtable<>(); | properties.put(EventConstants.EVENT_TOPIC, MafiaBossConstants.TOPIC_ALL); |
fipro78/osgi-ds-getting-started-pde | org.fipro.oneshot.command/src/org/fipro/oneshot/command/ShootCommand.java | // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
| import org.fipro.oneshot.OneShot;
import org.osgi.service.component.ComponentFactory;
import org.osgi.service.component.ComponentInstance;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference; | package org.fipro.oneshot.command;
@Component(
property= {
"osgi.command.scope=fipro",
"osgi.command.function=shoot"},
service=ShootCommand.class
)
public class ShootCommand {
private ComponentFactory factory;
@Reference(target = "(component.factory=fipro.oneshot.factory)")
void setComponentFactory(ComponentFactory factory) {
this.factory = factory;
}
public void shoot(String target) {
// create a new service instance
ComponentInstance instance = this.factory.newInstance(null); | // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
// Path: org.fipro.oneshot.command/src/org/fipro/oneshot/command/ShootCommand.java
import org.fipro.oneshot.OneShot;
import org.osgi.service.component.ComponentFactory;
import org.osgi.service.component.ComponentInstance;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
package org.fipro.oneshot.command;
@Component(
property= {
"osgi.command.scope=fipro",
"osgi.command.function=shoot"},
service=ShootCommand.class
)
public class ShootCommand {
private ComponentFactory factory;
@Reference(target = "(component.factory=fipro.oneshot.factory)")
void setComponentFactory(ComponentFactory factory) {
this.factory = factory;
}
public void shoot(String target) {
// create a new service instance
ComponentInstance instance = this.factory.newInstance(null); | OneShot shooter = (OneShot) instance.getInstance(); |
fipro78/osgi-ds-getting-started-pde | org.fipro.oneshot.command/src/org/fipro/oneshot/command/ExecuteCommand.java | // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
| import java.util.ArrayList;
import java.util.List;
import org.fipro.oneshot.OneShot;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy; | package org.fipro.oneshot.command;
@Component(
property= {
"osgi.command.scope=fipro",
"osgi.command.function=execute"},
service=ExecuteCommand.class
)
public class ExecuteCommand {
| // Path: org.fipro.oneshot.api/src/org/fipro/oneshot/OneShot.java
// public interface OneShot {
//
// void shoot(String target);
//
// }
// Path: org.fipro.oneshot.command/src/org/fipro/oneshot/command/ExecuteCommand.java
import java.util.ArrayList;
import java.util.List;
import org.fipro.oneshot.OneShot;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
package org.fipro.oneshot.command;
@Component(
property= {
"osgi.command.scope=fipro",
"osgi.command.function=execute"},
service=ExecuteCommand.class
)
public class ExecuteCommand {
| private List<OneShot> borgs = new ArrayList<>(); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/service/ICommentService.java | // Path: src/main/java/com/lixiaocong/cms/entity/Comment.java
// @Entity(name = "Comment")
// public class Comment extends AbstractEntity {
// @Lob
// @Column(nullable = false)
// private String content;
//
// @ManyToOne(optional = false)
// private Article article;
//
// @ManyToOne(optional = false)
// private User user;
//
// public Comment() {
// }
//
// public Comment(String content, Article article, User user) {
// this.content = content;
// this.article = article;
// this.user = user;
// }
//
// public String getContent() {
// return content;
// }
//
// public void setContent(String content) {
// this.content = content;
// }
//
// public Article getArticle() {
// return article;
// }
//
// public void setArticle(Article article) {
// this.article = article;
// }
//
// public User getUser() {
// return user;
// }
//
// public void setUser(User user) {
// this.user = user;
// }
//
// @Override
// public String toString() {
// return "Comment{" + "content='" + content + '\'' + ", article=" + article + ", user=" + user + "} " + super.toString();
// }
// }
| import com.lixiaocong.cms.entity.Comment;
import org.springframework.data.domain.Page;
import java.util.List; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service;
public interface ICommentService {
void create(long articleId, long userId, String content);
void delete(long id);
| // Path: src/main/java/com/lixiaocong/cms/entity/Comment.java
// @Entity(name = "Comment")
// public class Comment extends AbstractEntity {
// @Lob
// @Column(nullable = false)
// private String content;
//
// @ManyToOne(optional = false)
// private Article article;
//
// @ManyToOne(optional = false)
// private User user;
//
// public Comment() {
// }
//
// public Comment(String content, Article article, User user) {
// this.content = content;
// this.article = article;
// this.user = user;
// }
//
// public String getContent() {
// return content;
// }
//
// public void setContent(String content) {
// this.content = content;
// }
//
// public Article getArticle() {
// return article;
// }
//
// public void setArticle(Article article) {
// this.article = article;
// }
//
// public User getUser() {
// return user;
// }
//
// public void setUser(User user) {
// this.user = user;
// }
//
// @Override
// public String toString() {
// return "Comment{" + "content='" + content + '\'' + ", article=" + article + ", user=" + user + "} " + super.toString();
// }
// }
// Path: src/main/java/com/lixiaocong/cms/service/ICommentService.java
import com.lixiaocong.cms.entity.Comment;
import org.springframework.data.domain.Page;
import java.util.List;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service;
public interface ICommentService {
void create(long articleId, long userId, String content);
void delete(long id);
| void update(Comment comment); |
lixiaocong/lxcCMS | src/test/java/com/lixiaocong/cms/test/SpringTest.java | // Path: src/main/java/com/lixiaocong/cms/repository/IConfigRepository.java
// public interface IConfigRepository extends JpaRepository<Config, Long> {
// Config findByKey(String key);
// }
| import com.lixiaocong.cms.repository.IConfigRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.test;
@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
@ActiveProfiles("develop")
public class SpringTest {
@Autowired | // Path: src/main/java/com/lixiaocong/cms/repository/IConfigRepository.java
// public interface IConfigRepository extends JpaRepository<Config, Long> {
// Config findByKey(String key);
// }
// Path: src/test/java/com/lixiaocong/cms/test/SpringTest.java
import com.lixiaocong.cms.repository.IConfigRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.test;
@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
@ActiveProfiles("develop")
public class SpringTest {
@Autowired | private IConfigRepository configRepository; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/rest/UserController.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/exception/RestParamException.java
// public class RestParamException extends Exception {
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.exception.RestParamException;
import com.lixiaocong.cms.model.UserUpdateForm;
import com.lixiaocong.cms.service.IUserService;
import com.lixiaocong.social.qq.api.QQ;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.security.RolesAllowed;
import javax.inject.Provider;
import javax.validation.Valid;
import java.security.Principal;
import java.util.Map; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.rest;
@RestController
@RolesAllowed("ROLE_ADMIN")
@RequestMapping("/user")
public class UserController {
private static final Log log = LogFactory.getLog(UserController.class);
| // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/exception/RestParamException.java
// public class RestParamException extends Exception {
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/rest/UserController.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.exception.RestParamException;
import com.lixiaocong.cms.model.UserUpdateForm;
import com.lixiaocong.cms.service.IUserService;
import com.lixiaocong.social.qq.api.QQ;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.security.RolesAllowed;
import javax.inject.Provider;
import javax.validation.Valid;
import java.security.Principal;
import java.util.Map;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.rest;
@RestController
@RolesAllowed("ROLE_ADMIN")
@RequestMapping("/user")
public class UserController {
private static final Log log = LogFactory.getLog(UserController.class);
| private final IUserService userService; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/rest/UserController.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/exception/RestParamException.java
// public class RestParamException extends Exception {
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.exception.RestParamException;
import com.lixiaocong.cms.model.UserUpdateForm;
import com.lixiaocong.cms.service.IUserService;
import com.lixiaocong.social.qq.api.QQ;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.security.RolesAllowed;
import javax.inject.Provider;
import javax.validation.Valid;
import java.security.Principal;
import java.util.Map; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.rest;
@RestController
@RolesAllowed("ROLE_ADMIN")
@RequestMapping("/user")
public class UserController {
private static final Log log = LogFactory.getLog(UserController.class);
private final IUserService userService;
private final BCryptPasswordEncoder encoder;
private final Provider<ConnectionRepository> connectionRepositoryProvider;
@Autowired
public UserController(IUserService userService, Provider<ConnectionRepository> connectionRepositoryProvider) {
this.userService = userService;
this.encoder = new BCryptPasswordEncoder();
this.connectionRepositoryProvider = connectionRepositoryProvider;
}
@RequestMapping(value = "/info", method = RequestMethod.GET)
public Map<String, Object> info(Principal principal) { | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/exception/RestParamException.java
// public class RestParamException extends Exception {
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/rest/UserController.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.exception.RestParamException;
import com.lixiaocong.cms.model.UserUpdateForm;
import com.lixiaocong.cms.service.IUserService;
import com.lixiaocong.social.qq.api.QQ;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.security.RolesAllowed;
import javax.inject.Provider;
import javax.validation.Valid;
import java.security.Principal;
import java.util.Map;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.rest;
@RestController
@RolesAllowed("ROLE_ADMIN")
@RequestMapping("/user")
public class UserController {
private static final Log log = LogFactory.getLog(UserController.class);
private final IUserService userService;
private final BCryptPasswordEncoder encoder;
private final Provider<ConnectionRepository> connectionRepositoryProvider;
@Autowired
public UserController(IUserService userService, Provider<ConnectionRepository> connectionRepositoryProvider) {
this.userService = userService;
this.encoder = new BCryptPasswordEncoder();
this.connectionRepositoryProvider = connectionRepositoryProvider;
}
@RequestMapping(value = "/info", method = RequestMethod.GET)
public Map<String, Object> info(Principal principal) { | User user = userService.getByUsername(principal.getName()); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/rest/UserController.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/exception/RestParamException.java
// public class RestParamException extends Exception {
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.exception.RestParamException;
import com.lixiaocong.cms.model.UserUpdateForm;
import com.lixiaocong.cms.service.IUserService;
import com.lixiaocong.social.qq.api.QQ;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.security.RolesAllowed;
import javax.inject.Provider;
import javax.validation.Valid;
import java.security.Principal;
import java.util.Map; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.rest;
@RestController
@RolesAllowed("ROLE_ADMIN")
@RequestMapping("/user")
public class UserController {
private static final Log log = LogFactory.getLog(UserController.class);
private final IUserService userService;
private final BCryptPasswordEncoder encoder;
private final Provider<ConnectionRepository> connectionRepositoryProvider;
@Autowired
public UserController(IUserService userService, Provider<ConnectionRepository> connectionRepositoryProvider) {
this.userService = userService;
this.encoder = new BCryptPasswordEncoder();
this.connectionRepositoryProvider = connectionRepositoryProvider;
}
@RequestMapping(value = "/info", method = RequestMethod.GET)
public Map<String, Object> info(Principal principal) {
User user = userService.getByUsername(principal.getName());
Map<String, Object> ret = ResponseMsgFactory.createSuccessResponse("user", user);
ConnectionRepository connectionRepository = connectionRepositoryProvider.get();
Connection<QQ> qqConnection = connectionRepository.findPrimaryConnection(QQ.class);
ret.put("qq", qqConnection != null);
return ret;
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public Map<String, Object> delete(@PathVariable long id) {
userService.delete(id);
return ResponseMsgFactory.createSuccessResponse();
}
@RequestMapping(method = RequestMethod.PUT) | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/exception/RestParamException.java
// public class RestParamException extends Exception {
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/rest/UserController.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.exception.RestParamException;
import com.lixiaocong.cms.model.UserUpdateForm;
import com.lixiaocong.cms.service.IUserService;
import com.lixiaocong.social.qq.api.QQ;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.security.RolesAllowed;
import javax.inject.Provider;
import javax.validation.Valid;
import java.security.Principal;
import java.util.Map;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.rest;
@RestController
@RolesAllowed("ROLE_ADMIN")
@RequestMapping("/user")
public class UserController {
private static final Log log = LogFactory.getLog(UserController.class);
private final IUserService userService;
private final BCryptPasswordEncoder encoder;
private final Provider<ConnectionRepository> connectionRepositoryProvider;
@Autowired
public UserController(IUserService userService, Provider<ConnectionRepository> connectionRepositoryProvider) {
this.userService = userService;
this.encoder = new BCryptPasswordEncoder();
this.connectionRepositoryProvider = connectionRepositoryProvider;
}
@RequestMapping(value = "/info", method = RequestMethod.GET)
public Map<String, Object> info(Principal principal) {
User user = userService.getByUsername(principal.getName());
Map<String, Object> ret = ResponseMsgFactory.createSuccessResponse("user", user);
ConnectionRepository connectionRepository = connectionRepositoryProvider.get();
Connection<QQ> qqConnection = connectionRepository.findPrimaryConnection(QQ.class);
ret.put("qq", qqConnection != null);
return ret;
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public Map<String, Object> delete(@PathVariable long id) {
userService.delete(id);
return ResponseMsgFactory.createSuccessResponse();
}
@RequestMapping(method = RequestMethod.PUT) | public Map<String, Object> put(@RequestBody @Valid UserUpdateForm userUpdateForm, BindingResult result, Principal principal) throws RestParamException { |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/interceptor/QQInterceptor.java | // Path: src/main/java/com/lixiaocong/cms/exception/ModuleDisabledException.java
// public class ModuleDisabledException extends Exception {
// public ModuleDisabledException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
| import com.lixiaocong.cms.exception.ModuleDisabledException;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.social.connect.web.ConnectController;
import org.springframework.social.connect.web.ProviderSignInController;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.interceptor;
public class QQInterceptor extends HandlerInterceptorAdapter {
private final IConfigService configService;
private final ConnectController connectController;
private final ProviderSignInController signInController;
private String applicationUrl;
public QQInterceptor(IConfigService configService, ConnectController connectController, ProviderSignInController signInController) {
this.configService = configService;
this.connectController = connectController;
this.signInController = signInController;
this.applicationUrl = configService.getApplicationUrl();
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (this.configService.isQQEnabled()) {
String newApplicationUrl = this.configService.getApplicationUrl();
if (!newApplicationUrl.equals(this.applicationUrl)) {
this.applicationUrl = newApplicationUrl;
connectController.setApplicationUrl(newApplicationUrl);
connectController.afterPropertiesSet();
signInController.setApplicationUrl(newApplicationUrl);
signInController.afterPropertiesSet();
}
return true;
} | // Path: src/main/java/com/lixiaocong/cms/exception/ModuleDisabledException.java
// public class ModuleDisabledException extends Exception {
// public ModuleDisabledException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
// Path: src/main/java/com/lixiaocong/cms/interceptor/QQInterceptor.java
import com.lixiaocong.cms.exception.ModuleDisabledException;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.social.connect.web.ConnectController;
import org.springframework.social.connect.web.ProviderSignInController;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.interceptor;
public class QQInterceptor extends HandlerInterceptorAdapter {
private final IConfigService configService;
private final ConnectController connectController;
private final ProviderSignInController signInController;
private String applicationUrl;
public QQInterceptor(IConfigService configService, ConnectController connectController, ProviderSignInController signInController) {
this.configService = configService;
this.connectController = connectController;
this.signInController = signInController;
this.applicationUrl = configService.getApplicationUrl();
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (this.configService.isQQEnabled()) {
String newApplicationUrl = this.configService.getApplicationUrl();
if (!newApplicationUrl.equals(this.applicationUrl)) {
this.applicationUrl = newApplicationUrl;
connectController.setApplicationUrl(newApplicationUrl);
connectController.afterPropertiesSet();
signInController.setApplicationUrl(newApplicationUrl);
signInController.afterPropertiesSet();
}
return true;
} | throw new ModuleDisabledException("QQ module is disabled"); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/security/DaoBasedUserDetailsService.java | // Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/impl/ImageCodeService.java
// @Service
// public class ImageCodeService {
// private static final char[] ch = "ABCDEFGHJKLMNPQRSTUVWXY3456789".toCharArray();
// private static final int WIDTH = 70;
// private static final int HEIGHT = 30;
//
// public BufferedImage getImage(HttpSession session) {
// //background
// BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
// Graphics graphics = bi.getGraphics();
// graphics.setColor(randomColor());
// graphics.fillRect(0, 0, WIDTH, HEIGHT);
//
// //content
// StringBuilder sb = new StringBuilder();
// int len = ch.length;
// Random random = new Random();
// for (int i = 0; i < 4; i++) {
// int index = random.nextInt(len);
// graphics.setColor(randomColor());
// graphics.setFont(new Font(null, Font.BOLD + Font.ITALIC, 30));
// graphics.drawString(ch[index] + "", i * 15 + 5, 25);
// sb.append(ch[index]);
// }
// session.setAttribute("imagecode", sb.toString());
//
// //lines
// for (int i = 0; i < 4; i++) {
// graphics.setColor(randomColor());
// graphics.drawLine(random.nextInt(WIDTH), random.nextInt(HEIGHT), random.nextInt(WIDTH), random.nextInt(HEIGHT));
// }
//
// return bi;
// }
//
// public boolean check(String code, HttpSession session) {
// Object imagecode = session.getAttribute("imagecode");
// return imagecode != null && code.toLowerCase().equals(((String) imagecode).toLowerCase());
// }
//
// private Color randomColor() {
// Random random = new Random();
// return new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
// }
// }
| import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.service.impl.ImageCodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.Set; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.security;
@Component
public class DaoBasedUserDetailsService implements UserDetailsService { | // Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/impl/ImageCodeService.java
// @Service
// public class ImageCodeService {
// private static final char[] ch = "ABCDEFGHJKLMNPQRSTUVWXY3456789".toCharArray();
// private static final int WIDTH = 70;
// private static final int HEIGHT = 30;
//
// public BufferedImage getImage(HttpSession session) {
// //background
// BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
// Graphics graphics = bi.getGraphics();
// graphics.setColor(randomColor());
// graphics.fillRect(0, 0, WIDTH, HEIGHT);
//
// //content
// StringBuilder sb = new StringBuilder();
// int len = ch.length;
// Random random = new Random();
// for (int i = 0; i < 4; i++) {
// int index = random.nextInt(len);
// graphics.setColor(randomColor());
// graphics.setFont(new Font(null, Font.BOLD + Font.ITALIC, 30));
// graphics.drawString(ch[index] + "", i * 15 + 5, 25);
// sb.append(ch[index]);
// }
// session.setAttribute("imagecode", sb.toString());
//
// //lines
// for (int i = 0; i < 4; i++) {
// graphics.setColor(randomColor());
// graphics.drawLine(random.nextInt(WIDTH), random.nextInt(HEIGHT), random.nextInt(WIDTH), random.nextInt(HEIGHT));
// }
//
// return bi;
// }
//
// public boolean check(String code, HttpSession session) {
// Object imagecode = session.getAttribute("imagecode");
// return imagecode != null && code.toLowerCase().equals(((String) imagecode).toLowerCase());
// }
//
// private Color randomColor() {
// Random random = new Random();
// return new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
// }
// }
// Path: src/main/java/com/lixiaocong/cms/security/DaoBasedUserDetailsService.java
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.service.impl.ImageCodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.Set;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.security;
@Component
public class DaoBasedUserDetailsService implements UserDetailsService { | private final IUserRepository userRepository; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/security/DaoBasedUserDetailsService.java | // Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/impl/ImageCodeService.java
// @Service
// public class ImageCodeService {
// private static final char[] ch = "ABCDEFGHJKLMNPQRSTUVWXY3456789".toCharArray();
// private static final int WIDTH = 70;
// private static final int HEIGHT = 30;
//
// public BufferedImage getImage(HttpSession session) {
// //background
// BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
// Graphics graphics = bi.getGraphics();
// graphics.setColor(randomColor());
// graphics.fillRect(0, 0, WIDTH, HEIGHT);
//
// //content
// StringBuilder sb = new StringBuilder();
// int len = ch.length;
// Random random = new Random();
// for (int i = 0; i < 4; i++) {
// int index = random.nextInt(len);
// graphics.setColor(randomColor());
// graphics.setFont(new Font(null, Font.BOLD + Font.ITALIC, 30));
// graphics.drawString(ch[index] + "", i * 15 + 5, 25);
// sb.append(ch[index]);
// }
// session.setAttribute("imagecode", sb.toString());
//
// //lines
// for (int i = 0; i < 4; i++) {
// graphics.setColor(randomColor());
// graphics.drawLine(random.nextInt(WIDTH), random.nextInt(HEIGHT), random.nextInt(WIDTH), random.nextInt(HEIGHT));
// }
//
// return bi;
// }
//
// public boolean check(String code, HttpSession session) {
// Object imagecode = session.getAttribute("imagecode");
// return imagecode != null && code.toLowerCase().equals(((String) imagecode).toLowerCase());
// }
//
// private Color randomColor() {
// Random random = new Random();
// return new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
// }
// }
| import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.service.impl.ImageCodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.Set; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.security;
@Component
public class DaoBasedUserDetailsService implements UserDetailsService {
private final IUserRepository userRepository;
private Log log = LogFactory.getLog(getClass()); | // Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/impl/ImageCodeService.java
// @Service
// public class ImageCodeService {
// private static final char[] ch = "ABCDEFGHJKLMNPQRSTUVWXY3456789".toCharArray();
// private static final int WIDTH = 70;
// private static final int HEIGHT = 30;
//
// public BufferedImage getImage(HttpSession session) {
// //background
// BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
// Graphics graphics = bi.getGraphics();
// graphics.setColor(randomColor());
// graphics.fillRect(0, 0, WIDTH, HEIGHT);
//
// //content
// StringBuilder sb = new StringBuilder();
// int len = ch.length;
// Random random = new Random();
// for (int i = 0; i < 4; i++) {
// int index = random.nextInt(len);
// graphics.setColor(randomColor());
// graphics.setFont(new Font(null, Font.BOLD + Font.ITALIC, 30));
// graphics.drawString(ch[index] + "", i * 15 + 5, 25);
// sb.append(ch[index]);
// }
// session.setAttribute("imagecode", sb.toString());
//
// //lines
// for (int i = 0; i < 4; i++) {
// graphics.setColor(randomColor());
// graphics.drawLine(random.nextInt(WIDTH), random.nextInt(HEIGHT), random.nextInt(WIDTH), random.nextInt(HEIGHT));
// }
//
// return bi;
// }
//
// public boolean check(String code, HttpSession session) {
// Object imagecode = session.getAttribute("imagecode");
// return imagecode != null && code.toLowerCase().equals(((String) imagecode).toLowerCase());
// }
//
// private Color randomColor() {
// Random random = new Random();
// return new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
// }
// }
// Path: src/main/java/com/lixiaocong/cms/security/DaoBasedUserDetailsService.java
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.service.impl.ImageCodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.Set;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.security;
@Component
public class DaoBasedUserDetailsService implements UserDetailsService {
private final IUserRepository userRepository;
private Log log = LogFactory.getLog(getClass()); | private ImageCodeService codeService; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/service/impl/UserServiceImpl.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service.impl;
@Service
@Transactional | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/service/impl/UserServiceImpl.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service.impl;
@Service
@Transactional | public class UserServiceImpl implements IUserService { |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/service/impl/UserServiceImpl.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service.impl;
@Service
@Transactional
public class UserServiceImpl implements IUserService { | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/service/impl/UserServiceImpl.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service.impl;
@Service
@Transactional
public class UserServiceImpl implements IUserService { | private final IUserRepository userRepository; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/service/impl/UserServiceImpl.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service.impl;
@Service
@Transactional
public class UserServiceImpl implements IUserService {
private final IUserRepository userRepository;
@Autowired
public UserServiceImpl(IUserRepository userRepository) {
this.userRepository = userRepository;
}
@Override | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/service/impl/UserServiceImpl.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service.impl;
@Service
@Transactional
public class UserServiceImpl implements IUserService {
private final IUserRepository userRepository;
@Autowired
public UserServiceImpl(IUserRepository userRepository) {
this.userRepository = userRepository;
}
@Override | public User create(String username, String password) { |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/config/WebSecurityConfig.java | // Path: src/main/java/com/lixiaocong/cms/security/DaoBasedUserDetailsService.java
// @Component
// public class DaoBasedUserDetailsService implements UserDetailsService {
// private final IUserRepository userRepository;
// private Log log = LogFactory.getLog(getClass());
// private ImageCodeService codeService;
//
// @Autowired
// public DaoBasedUserDetailsService(IUserRepository userRepository, ImageCodeService codeService) {
// this.userRepository = userRepository;
// this.codeService = codeService;
// }
//
// @Override
// public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
// if (request.getRequestURI().equals("/signin")) {
// String postcode = request.getParameter("imagecode");
// if (!codeService.check(postcode, request.getSession()))
// throw new UsernameNotFoundException("image code error");
// }
// com.lixiaocong.cms.entity.User user = userRepository.findByUsername(username);
// if (user == null) {
// log.info("user not exists");
// throw new UsernameNotFoundException("user not exists");
// }
// Set<GrantedAuthority> authorities = new HashSet<>();
//
// authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
// if (user.isAdmin()) {
// authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
// request.getSession().setAttribute("admin", true);
// }
//
// return new DaoBasedUserDetails(user.getId(), user.getUsername(), user.getPassword(), authorities);
// }
// }
| import com.lixiaocong.cms.security.DaoBasedUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.config;
@Configuration
@EnableGlobalMethodSecurity(jsr250Enabled = true) // this is the key to enable RolesAllowed annotation
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | // Path: src/main/java/com/lixiaocong/cms/security/DaoBasedUserDetailsService.java
// @Component
// public class DaoBasedUserDetailsService implements UserDetailsService {
// private final IUserRepository userRepository;
// private Log log = LogFactory.getLog(getClass());
// private ImageCodeService codeService;
//
// @Autowired
// public DaoBasedUserDetailsService(IUserRepository userRepository, ImageCodeService codeService) {
// this.userRepository = userRepository;
// this.codeService = codeService;
// }
//
// @Override
// public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
// if (request.getRequestURI().equals("/signin")) {
// String postcode = request.getParameter("imagecode");
// if (!codeService.check(postcode, request.getSession()))
// throw new UsernameNotFoundException("image code error");
// }
// com.lixiaocong.cms.entity.User user = userRepository.findByUsername(username);
// if (user == null) {
// log.info("user not exists");
// throw new UsernameNotFoundException("user not exists");
// }
// Set<GrantedAuthority> authorities = new HashSet<>();
//
// authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
// if (user.isAdmin()) {
// authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
// request.getSession().setAttribute("admin", true);
// }
//
// return new DaoBasedUserDetails(user.getId(), user.getUsername(), user.getPassword(), authorities);
// }
// }
// Path: src/main/java/com/lixiaocong/cms/config/WebSecurityConfig.java
import com.lixiaocong.cms.security.DaoBasedUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.config;
@Configuration
@EnableGlobalMethodSecurity(jsr250Enabled = true) // this is the key to enable RolesAllowed annotation
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | private final DaoBasedUserDetailsService detailsService; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/config/DownloaderConfig.java | // Path: src/main/java/com/lixiaocong/cms/downloader/DownloaderProxyHandler.java
// public class DownloaderProxyHandler implements InvocationHandler {
//
// private UnionDownloader downloader;
//
// public DownloaderProxyHandler(UnionDownloader downloader) {
// this.downloader = downloader;
// }
//
// @Override
// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// this.downloader.checkAria();
// this.downloader.checkTransmission();
// return method.invoke(this.downloader, args);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
| import com.lixiaocong.cms.downloader.DownloaderProxyHandler;
import com.lixiaocong.cms.downloader.UnionDownloader;
import com.lixiaocong.cms.service.IConfigService;
import com.lixiaocong.downloader.DownloaderConfigurer;
import com.lixiaocong.downloader.EnableDownloader;
import com.lixiaocong.downloader.IDownloader;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.lang.reflect.Proxy; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.config;
@Configuration
@EnableDownloader
public class DownloaderConfig implements DownloaderConfigurer {
| // Path: src/main/java/com/lixiaocong/cms/downloader/DownloaderProxyHandler.java
// public class DownloaderProxyHandler implements InvocationHandler {
//
// private UnionDownloader downloader;
//
// public DownloaderProxyHandler(UnionDownloader downloader) {
// this.downloader = downloader;
// }
//
// @Override
// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// this.downloader.checkAria();
// this.downloader.checkTransmission();
// return method.invoke(this.downloader, args);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
// Path: src/main/java/com/lixiaocong/cms/config/DownloaderConfig.java
import com.lixiaocong.cms.downloader.DownloaderProxyHandler;
import com.lixiaocong.cms.downloader.UnionDownloader;
import com.lixiaocong.cms.service.IConfigService;
import com.lixiaocong.downloader.DownloaderConfigurer;
import com.lixiaocong.downloader.EnableDownloader;
import com.lixiaocong.downloader.IDownloader;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.lang.reflect.Proxy;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.config;
@Configuration
@EnableDownloader
public class DownloaderConfig implements DownloaderConfigurer {
| private final IConfigService configService; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/config/DownloaderConfig.java | // Path: src/main/java/com/lixiaocong/cms/downloader/DownloaderProxyHandler.java
// public class DownloaderProxyHandler implements InvocationHandler {
//
// private UnionDownloader downloader;
//
// public DownloaderProxyHandler(UnionDownloader downloader) {
// this.downloader = downloader;
// }
//
// @Override
// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// this.downloader.checkAria();
// this.downloader.checkTransmission();
// return method.invoke(this.downloader, args);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
| import com.lixiaocong.cms.downloader.DownloaderProxyHandler;
import com.lixiaocong.cms.downloader.UnionDownloader;
import com.lixiaocong.cms.service.IConfigService;
import com.lixiaocong.downloader.DownloaderConfigurer;
import com.lixiaocong.downloader.EnableDownloader;
import com.lixiaocong.downloader.IDownloader;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.lang.reflect.Proxy; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.config;
@Configuration
@EnableDownloader
public class DownloaderConfig implements DownloaderConfigurer {
private final IConfigService configService;
@Autowired
public DownloaderConfig(IConfigService configService) {
this.configService = configService;
}
@NotNull
@Override
public IDownloader getDownloader() {
return downloader();
}
@Bean
public IDownloader downloader() {
UnionDownloader unionDownloader = new UnionDownloader(configService); | // Path: src/main/java/com/lixiaocong/cms/downloader/DownloaderProxyHandler.java
// public class DownloaderProxyHandler implements InvocationHandler {
//
// private UnionDownloader downloader;
//
// public DownloaderProxyHandler(UnionDownloader downloader) {
// this.downloader = downloader;
// }
//
// @Override
// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// this.downloader.checkAria();
// this.downloader.checkTransmission();
// return method.invoke(this.downloader, args);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
// Path: src/main/java/com/lixiaocong/cms/config/DownloaderConfig.java
import com.lixiaocong.cms.downloader.DownloaderProxyHandler;
import com.lixiaocong.cms.downloader.UnionDownloader;
import com.lixiaocong.cms.service.IConfigService;
import com.lixiaocong.downloader.DownloaderConfigurer;
import com.lixiaocong.downloader.EnableDownloader;
import com.lixiaocong.downloader.IDownloader;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.lang.reflect.Proxy;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.config;
@Configuration
@EnableDownloader
public class DownloaderConfig implements DownloaderConfigurer {
private final IConfigService configService;
@Autowired
public DownloaderConfig(IConfigService configService) {
this.configService = configService;
}
@NotNull
@Override
public IDownloader getDownloader() {
return downloader();
}
@Bean
public IDownloader downloader() {
UnionDownloader unionDownloader = new UnionDownloader(configService); | return (IDownloader) Proxy.newProxyInstance(unionDownloader.getClass().getClassLoader(), unionDownloader.getClass().getInterfaces(), new DownloaderProxyHandler(unionDownloader)); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/interceptor/WeixinInterceptor.java | // Path: src/main/java/com/lixiaocong/cms/exception/ModuleDisabledException.java
// public class ModuleDisabledException extends Exception {
// public ModuleDisabledException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
| import com.lixiaocong.cms.exception.ModuleDisabledException;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.interceptor;
public class WeixinInterceptor extends HandlerInterceptorAdapter {
private final IConfigService configService;
public WeixinInterceptor(IConfigService configService) {
this.configService = configService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (this.configService.isWeixinEnabled())
return true; | // Path: src/main/java/com/lixiaocong/cms/exception/ModuleDisabledException.java
// public class ModuleDisabledException extends Exception {
// public ModuleDisabledException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
// Path: src/main/java/com/lixiaocong/cms/interceptor/WeixinInterceptor.java
import com.lixiaocong.cms.exception.ModuleDisabledException;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.interceptor;
public class WeixinInterceptor extends HandlerInterceptorAdapter {
private final IConfigService configService;
public WeixinInterceptor(IConfigService configService) {
this.configService = configService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (this.configService.isWeixinEnabled())
return true; | throw new ModuleDisabledException("Weixin module is disabled"); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/service/impl/SystemService.java | // Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
| import com.lixiaocong.cms.service.IConfigService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service.impl;
@Service
public class SystemService {
private static final Log log = LogFactory.getLog(SystemService.class);
| // Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
// Path: src/main/java/com/lixiaocong/cms/service/impl/SystemService.java
import com.lixiaocong.cms.service.IConfigService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service.impl;
@Service
public class SystemService {
private static final Log log = LogFactory.getLog(SystemService.class);
| private final IConfigService configService; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/dev/DevSigninFilter.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/security/DaoBasedUserDetails.java
// public class DaoBasedUserDetails extends User {
// private long id;
//
// public DaoBasedUserDetails(long id, String username, String password, Collection<? extends GrantedAuthority> authorities) {
// super(username, password, authorities);
// this.id = id;
// }
//
// public long getId() {
// return id;
// }
//
// public void setId(long id) {
// this.id = id;
// }
//
// @Override
// public String toString() {
// return "User " + id;
// }
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.security.DaoBasedUserDetails;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import javax.servlet.*;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.dev;
public class DevSigninFilter implements Filter {
private final IUserRepository userRepository;
DevSigninFilter(IUserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Set<GrantedAuthority> authorities = new HashSet<>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
| // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/security/DaoBasedUserDetails.java
// public class DaoBasedUserDetails extends User {
// private long id;
//
// public DaoBasedUserDetails(long id, String username, String password, Collection<? extends GrantedAuthority> authorities) {
// super(username, password, authorities);
// this.id = id;
// }
//
// public long getId() {
// return id;
// }
//
// public void setId(long id) {
// this.id = id;
// }
//
// @Override
// public String toString() {
// return "User " + id;
// }
// }
// Path: src/main/java/com/lixiaocong/cms/dev/DevSigninFilter.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.security.DaoBasedUserDetails;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import javax.servlet.*;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.dev;
public class DevSigninFilter implements Filter {
private final IUserRepository userRepository;
DevSigninFilter(IUserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Set<GrantedAuthority> authorities = new HashSet<>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
| User admin = userRepository.findByUsername("admin"); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/dev/DevSigninFilter.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/security/DaoBasedUserDetails.java
// public class DaoBasedUserDetails extends User {
// private long id;
//
// public DaoBasedUserDetails(long id, String username, String password, Collection<? extends GrantedAuthority> authorities) {
// super(username, password, authorities);
// this.id = id;
// }
//
// public long getId() {
// return id;
// }
//
// public void setId(long id) {
// this.id = id;
// }
//
// @Override
// public String toString() {
// return "User " + id;
// }
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.security.DaoBasedUserDetails;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import javax.servlet.*;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.dev;
public class DevSigninFilter implements Filter {
private final IUserRepository userRepository;
DevSigninFilter(IUserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Set<GrantedAuthority> authorities = new HashSet<>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
User admin = userRepository.findByUsername("admin"); | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
//
// Path: src/main/java/com/lixiaocong/cms/security/DaoBasedUserDetails.java
// public class DaoBasedUserDetails extends User {
// private long id;
//
// public DaoBasedUserDetails(long id, String username, String password, Collection<? extends GrantedAuthority> authorities) {
// super(username, password, authorities);
// this.id = id;
// }
//
// public long getId() {
// return id;
// }
//
// public void setId(long id) {
// this.id = id;
// }
//
// @Override
// public String toString() {
// return "User " + id;
// }
// }
// Path: src/main/java/com/lixiaocong/cms/dev/DevSigninFilter.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import com.lixiaocong.cms.security.DaoBasedUserDetails;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import javax.servlet.*;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.dev;
public class DevSigninFilter implements Filter {
private final IUserRepository userRepository;
DevSigninFilter(IUserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Set<GrantedAuthority> authorities = new HashSet<>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
User admin = userRepository.findByUsername("admin"); | UserDetails user = new DaoBasedUserDetails(admin.getId(), admin.getUsername(), admin.getPassword(), authorities); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/interceptor/BlogInterceptor.java | // Path: src/main/java/com/lixiaocong/cms/exception/ModuleDisabledException.java
// public class ModuleDisabledException extends Exception {
// public ModuleDisabledException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
| import com.lixiaocong.cms.exception.ModuleDisabledException;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.interceptor;
public class BlogInterceptor extends HandlerInterceptorAdapter {
private final IConfigService configService;
public BlogInterceptor(IConfigService configService) {
this.configService = configService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (this.configService.isBlogEnabled())
return true; | // Path: src/main/java/com/lixiaocong/cms/exception/ModuleDisabledException.java
// public class ModuleDisabledException extends Exception {
// public ModuleDisabledException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
// Path: src/main/java/com/lixiaocong/cms/interceptor/BlogInterceptor.java
import com.lixiaocong.cms.exception.ModuleDisabledException;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.interceptor;
public class BlogInterceptor extends HandlerInterceptorAdapter {
private final IConfigService configService;
public BlogInterceptor(IConfigService configService) {
this.configService = configService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (this.configService.isBlogEnabled())
return true; | throw new ModuleDisabledException("blog module is disabled"); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/dev/DevWebSecurityConfig.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.context.SecurityContextPersistenceFilter; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.dev;
//TODO if don't set order, there will be an error, to be fixed
@Profile("develop")
@Order(1)
@Configuration
public class DevWebSecurityConfig extends WebSecurityConfigurerAdapter {
private Log log = LogFactory.getLog(getClass());
| // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/dev/DevWebSecurityConfig.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.context.SecurityContextPersistenceFilter;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.dev;
//TODO if don't set order, there will be an error, to be fixed
@Profile("develop")
@Order(1)
@Configuration
public class DevWebSecurityConfig extends WebSecurityConfigurerAdapter {
private Log log = LogFactory.getLog(getClass());
| private IUserRepository userRepository; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/dev/DevWebSecurityConfig.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.context.SecurityContextPersistenceFilter; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.dev;
//TODO if don't set order, there will be an error, to be fixed
@Profile("develop")
@Order(1)
@Configuration
public class DevWebSecurityConfig extends WebSecurityConfigurerAdapter {
private Log log = LogFactory.getLog(getClass());
private IUserRepository userRepository;
@Autowired
public DevWebSecurityConfig(IUserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll().and().formLogin().loginPage("/signin").defaultSuccessUrl("/blog").and().logout().logoutUrl("/logout").logoutSuccessUrl("/blog").and().rememberMe().rememberMeParameter("remember-me").and().csrf().disable(); | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/dev/DevWebSecurityConfig.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.context.SecurityContextPersistenceFilter;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.dev;
//TODO if don't set order, there will be an error, to be fixed
@Profile("develop")
@Order(1)
@Configuration
public class DevWebSecurityConfig extends WebSecurityConfigurerAdapter {
private Log log = LogFactory.getLog(getClass());
private IUserRepository userRepository;
@Autowired
public DevWebSecurityConfig(IUserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll().and().formLogin().loginPage("/signin").defaultSuccessUrl("/blog").and().logout().logoutUrl("/logout").logoutSuccessUrl("/blog").and().rememberMe().rememberMeParameter("remember-me").and().csrf().disable(); | User admin = userRepository.findByUsername("admin"); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/interceptor/DownloaderInterceptor.java | // Path: src/main/java/com/lixiaocong/cms/exception/ModuleDisabledException.java
// public class ModuleDisabledException extends Exception {
// public ModuleDisabledException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
| import com.lixiaocong.cms.exception.ModuleDisabledException;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.interceptor;
public class DownloaderInterceptor extends HandlerInterceptorAdapter {
private final IConfigService configService;
public DownloaderInterceptor(IConfigService configService) {
this.configService = configService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (configService.isDownloaderEnabled())
return true; | // Path: src/main/java/com/lixiaocong/cms/exception/ModuleDisabledException.java
// public class ModuleDisabledException extends Exception {
// public ModuleDisabledException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
// Path: src/main/java/com/lixiaocong/cms/interceptor/DownloaderInterceptor.java
import com.lixiaocong.cms.exception.ModuleDisabledException;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.interceptor;
public class DownloaderInterceptor extends HandlerInterceptorAdapter {
private final IConfigService configService;
public DownloaderInterceptor(IConfigService configService) {
this.configService = configService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (configService.isDownloaderEnabled())
return true; | throw new ModuleDisabledException("Downloader is disabled"); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/controller/SignController.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/exception/ControllerParamException.java
// public class ControllerParamException extends Exception {
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.exception.ControllerParamException;
import com.lixiaocong.cms.model.UserSignUpForm;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.controller;
@Controller
public class SignController {
private final ProviderSignInUtils providerSignInUtils; | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/exception/ControllerParamException.java
// public class ControllerParamException extends Exception {
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/controller/SignController.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.exception.ControllerParamException;
import com.lixiaocong.cms.model.UserSignUpForm;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.controller;
@Controller
public class SignController {
private final ProviderSignInUtils providerSignInUtils; | private final IUserService userService; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/controller/SignController.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/exception/ControllerParamException.java
// public class ControllerParamException extends Exception {
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.exception.ControllerParamException;
import com.lixiaocong.cms.model.UserSignUpForm;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid; | public SignController(ConnectionFactoryLocator connectionFactoryLocator, UsersConnectionRepository connectionRepository, IUserService userService, UserDetailsService userDetailsService) {
this.providerSignInUtils = new ProviderSignInUtils(connectionFactoryLocator, connectionRepository);
this.userService = userService;
this.encoder = new BCryptPasswordEncoder();
this.userDetailsService = userDetailsService;
}
@RequestMapping(value = "signin", method = RequestMethod.GET)
public String signin() {
return "sign/signin";
}
@RequestMapping(value = "/signup", method = RequestMethod.GET)
public ModelAndView signup(WebRequest request) {
ModelAndView ret = new ModelAndView("sign/signup");
Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);
if (connection != null) {
String name = connection.fetchUserProfile().getName();
ret.addObject("username", name);
ret.addObject("message", "please set your password");
}
return ret;
}
@RequestMapping(value = "/singup", method = RequestMethod.POST)
public ModelAndView post(@Valid UserSignUpForm user, BindingResult result, WebRequest request) throws ControllerParamException {
if (result.hasErrors()) throw new ControllerParamException();
try { | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/exception/ControllerParamException.java
// public class ControllerParamException extends Exception {
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/controller/SignController.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.exception.ControllerParamException;
import com.lixiaocong.cms.model.UserSignUpForm;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
public SignController(ConnectionFactoryLocator connectionFactoryLocator, UsersConnectionRepository connectionRepository, IUserService userService, UserDetailsService userDetailsService) {
this.providerSignInUtils = new ProviderSignInUtils(connectionFactoryLocator, connectionRepository);
this.userService = userService;
this.encoder = new BCryptPasswordEncoder();
this.userDetailsService = userDetailsService;
}
@RequestMapping(value = "signin", method = RequestMethod.GET)
public String signin() {
return "sign/signin";
}
@RequestMapping(value = "/signup", method = RequestMethod.GET)
public ModelAndView signup(WebRequest request) {
ModelAndView ret = new ModelAndView("sign/signup");
Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);
if (connection != null) {
String name = connection.fetchUserProfile().getName();
ret.addObject("username", name);
ret.addObject("message", "please set your password");
}
return ret;
}
@RequestMapping(value = "/singup", method = RequestMethod.POST)
public ModelAndView post(@Valid UserSignUpForm user, BindingResult result, WebRequest request) throws ControllerParamException {
if (result.hasErrors()) throw new ControllerParamException();
try { | User localUser = userService.create(user.getUsername(), encoder.encode(user.getPassword())); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/service/IArticleService.java | // Path: src/main/java/com/lixiaocong/cms/entity/Article.java
// @Entity(name = "Article")
// public class Article extends AbstractEntity {
// @Column(nullable = false)
// private String title;
//
// @Lob
// @Column(nullable = false)
// private String content;
//
// @ManyToOne(optional = false)
// private User user;
//
// @Column(nullable = false)
// private String summary;
//
// @Lob
// @Column
// private String image;
//
// @JsonIgnore
// @OneToMany(mappedBy = "article", fetch = FetchType.EAGER, cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public Article() {
// comments = new HashSet<>();
// }
//
// public Article(String title, String content, User user) {
// comments = new HashSet<>();
// this.title = title;
// this.content = content;
// this.user = user;
// }
//
// @PrePersist
// public void prePersist() {
// super.prePersist();
// getSummaryAndImage();
// }
//
// @PreUpdate
// public void preUpdate() {
// super.preUpdate();
// getSummaryAndImage();
// }
//
// private void getSummaryAndImage() {
// String summary = this.getContent();
// Source source = new Source(summary);
//
// //设置摘要
// Segment segment = new Segment(source, 0, summary.length() - 1);
// TextExtractor textExtractor = new TextExtractor(segment);
// summary = textExtractor.toString();
// if (summary.length() > 200) summary = summary.substring(0, 200) + "......";
// this.setSummary(summary);
//
// //处理图片
// Element img = source.getFirstElement(HTMLElementName.IMG);
// if (img != null) {
// String href = img.getAttributeValue("src");
// if (href != null) this.setImage(href);
// }
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public String getTitle() {
// return title;
// }
//
// public void setTitle(String title) {
// this.title = title;
// }
//
// public String getContent() {
// return content;
// }
//
// public void setContent(String content) {
// this.content = content;
// }
//
// public User getUser() {
// return user;
// }
//
// public void setUser(User user) {
// this.user = user;
// }
//
// public String getSummary() {
// return summary;
// }
//
// public void setSummary(String summary) {
// this.summary = summary;
// }
//
// public String getImage() {
// return image;
// }
//
// public void setImage(String image) {
// this.image = image;
// }
//
// }
//
// Path: src/main/java/com/lixiaocong/cms/utils/PageInfo.java
// public class PageInfo<T> {
// public long totalItems;
// public long totalPages;
// public List<T> items;
//
// public PageInfo() {
// this.items = new LinkedList<T>();
// this.totalItems = 0;
// this.totalPages = 0;
// }
//
// public PageInfo(long totalItems, long totalPages, List<T> items) {
// this.totalItems = totalItems;
// this.totalPages = totalPages;
// this.items = items;
// }
// }
| import com.lixiaocong.cms.entity.Article;
import com.lixiaocong.cms.utils.PageInfo;
import org.springframework.data.domain.Page; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service;
public interface IArticleService {
Article create(long userId, String title, String content);
void delete(long id);
void update(Article article);
Article get(long id);
| // Path: src/main/java/com/lixiaocong/cms/entity/Article.java
// @Entity(name = "Article")
// public class Article extends AbstractEntity {
// @Column(nullable = false)
// private String title;
//
// @Lob
// @Column(nullable = false)
// private String content;
//
// @ManyToOne(optional = false)
// private User user;
//
// @Column(nullable = false)
// private String summary;
//
// @Lob
// @Column
// private String image;
//
// @JsonIgnore
// @OneToMany(mappedBy = "article", fetch = FetchType.EAGER, cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public Article() {
// comments = new HashSet<>();
// }
//
// public Article(String title, String content, User user) {
// comments = new HashSet<>();
// this.title = title;
// this.content = content;
// this.user = user;
// }
//
// @PrePersist
// public void prePersist() {
// super.prePersist();
// getSummaryAndImage();
// }
//
// @PreUpdate
// public void preUpdate() {
// super.preUpdate();
// getSummaryAndImage();
// }
//
// private void getSummaryAndImage() {
// String summary = this.getContent();
// Source source = new Source(summary);
//
// //设置摘要
// Segment segment = new Segment(source, 0, summary.length() - 1);
// TextExtractor textExtractor = new TextExtractor(segment);
// summary = textExtractor.toString();
// if (summary.length() > 200) summary = summary.substring(0, 200) + "......";
// this.setSummary(summary);
//
// //处理图片
// Element img = source.getFirstElement(HTMLElementName.IMG);
// if (img != null) {
// String href = img.getAttributeValue("src");
// if (href != null) this.setImage(href);
// }
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public String getTitle() {
// return title;
// }
//
// public void setTitle(String title) {
// this.title = title;
// }
//
// public String getContent() {
// return content;
// }
//
// public void setContent(String content) {
// this.content = content;
// }
//
// public User getUser() {
// return user;
// }
//
// public void setUser(User user) {
// this.user = user;
// }
//
// public String getSummary() {
// return summary;
// }
//
// public void setSummary(String summary) {
// this.summary = summary;
// }
//
// public String getImage() {
// return image;
// }
//
// public void setImage(String image) {
// this.image = image;
// }
//
// }
//
// Path: src/main/java/com/lixiaocong/cms/utils/PageInfo.java
// public class PageInfo<T> {
// public long totalItems;
// public long totalPages;
// public List<T> items;
//
// public PageInfo() {
// this.items = new LinkedList<T>();
// this.totalItems = 0;
// this.totalPages = 0;
// }
//
// public PageInfo(long totalItems, long totalPages, List<T> items) {
// this.totalItems = totalItems;
// this.totalPages = totalPages;
// this.items = items;
// }
// }
// Path: src/main/java/com/lixiaocong/cms/service/IArticleService.java
import com.lixiaocong.cms.entity.Article;
import com.lixiaocong.cms.utils.PageInfo;
import org.springframework.data.domain.Page;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.service;
public interface IArticleService {
Article create(long userId, String title, String content);
void delete(long id);
void update(Article article);
Article get(long id);
| PageInfo<Article> get(int page, int size, String keyWord); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/service/impl/ConfigService.java | // Path: src/main/java/com/lixiaocong/cms/entity/Config.java
// @Entity(name = "Config")
// public class Config extends AbstractEntity {
// @Column(nullable = false, unique = true, name = "config_key")
// private String key;
//
// @Column(nullable = false, name = "config_value")
// private String value;
//
// public String getKey() {
// return key;
// }
//
// public void setKey(String key) {
// this.key = key;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IConfigRepository.java
// public interface IConfigRepository extends JpaRepository<Config, Long> {
// Config findByKey(String key);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
| import com.lixiaocong.cms.entity.Config;
import com.lixiaocong.cms.repository.IConfigRepository;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map; | public static final String DOWNLOADER_ARIA2C_URL = "aria2cUrl";
public static final String DOWNLOADER_ARIA2C_PASSWORD = "aria2cPassword";
public static final String DOWNLOADER_TRANSMISSION_URL = "transmissionUrl";
public static final String DOWNLOADER_TRANSMISSION_USERNAME = "transmissionUsername";
public static final String DOWNLOADER_TRANSMISSION_PASSWORD = "transmissionPassword";
public static final String STORAGE_DIR = "storageDir";
private static final String VALUE_TRUE = "1";
private static final String VALUE_FALSE = "0";
private static Map<String, String> defaultKeyValueMap = new HashMap<>();
static {
defaultKeyValueMap.put(BLOG_ENABLED, "1");
defaultKeyValueMap.put(APPLICATION_URL, "127.0.0.1");
defaultKeyValueMap.put(QQ_ENABLED, "0");
defaultKeyValueMap.put(QQ_ID, "");
defaultKeyValueMap.put(QQ_SECRET, "");
defaultKeyValueMap.put(WEIXIN_ENABLED, "0");
defaultKeyValueMap.put(WEIXIN_ID, "");
defaultKeyValueMap.put(WEIXIN_KEY, "");
defaultKeyValueMap.put(WEIXIN_SECRET, "");
defaultKeyValueMap.put(WEIXIN_TOKEN, "");
defaultKeyValueMap.put(DOWNLOADER_ENABLED, "0");
defaultKeyValueMap.put(DOWNLOADER_ARIA2C_URL, "http://127.0.0.1:6800/jsonrpc");
defaultKeyValueMap.put(DOWNLOADER_ARIA2C_PASSWORD, "password");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_URL, "http://127.0.0.1:9091/transmission/rpc");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_USERNAME, "username");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_PASSWORD, "password");
defaultKeyValueMap.put(STORAGE_DIR, "/downloads");
}
| // Path: src/main/java/com/lixiaocong/cms/entity/Config.java
// @Entity(name = "Config")
// public class Config extends AbstractEntity {
// @Column(nullable = false, unique = true, name = "config_key")
// private String key;
//
// @Column(nullable = false, name = "config_value")
// private String value;
//
// public String getKey() {
// return key;
// }
//
// public void setKey(String key) {
// this.key = key;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IConfigRepository.java
// public interface IConfigRepository extends JpaRepository<Config, Long> {
// Config findByKey(String key);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
// Path: src/main/java/com/lixiaocong/cms/service/impl/ConfigService.java
import com.lixiaocong.cms.entity.Config;
import com.lixiaocong.cms.repository.IConfigRepository;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
public static final String DOWNLOADER_ARIA2C_URL = "aria2cUrl";
public static final String DOWNLOADER_ARIA2C_PASSWORD = "aria2cPassword";
public static final String DOWNLOADER_TRANSMISSION_URL = "transmissionUrl";
public static final String DOWNLOADER_TRANSMISSION_USERNAME = "transmissionUsername";
public static final String DOWNLOADER_TRANSMISSION_PASSWORD = "transmissionPassword";
public static final String STORAGE_DIR = "storageDir";
private static final String VALUE_TRUE = "1";
private static final String VALUE_FALSE = "0";
private static Map<String, String> defaultKeyValueMap = new HashMap<>();
static {
defaultKeyValueMap.put(BLOG_ENABLED, "1");
defaultKeyValueMap.put(APPLICATION_URL, "127.0.0.1");
defaultKeyValueMap.put(QQ_ENABLED, "0");
defaultKeyValueMap.put(QQ_ID, "");
defaultKeyValueMap.put(QQ_SECRET, "");
defaultKeyValueMap.put(WEIXIN_ENABLED, "0");
defaultKeyValueMap.put(WEIXIN_ID, "");
defaultKeyValueMap.put(WEIXIN_KEY, "");
defaultKeyValueMap.put(WEIXIN_SECRET, "");
defaultKeyValueMap.put(WEIXIN_TOKEN, "");
defaultKeyValueMap.put(DOWNLOADER_ENABLED, "0");
defaultKeyValueMap.put(DOWNLOADER_ARIA2C_URL, "http://127.0.0.1:6800/jsonrpc");
defaultKeyValueMap.put(DOWNLOADER_ARIA2C_PASSWORD, "password");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_URL, "http://127.0.0.1:9091/transmission/rpc");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_USERNAME, "username");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_PASSWORD, "password");
defaultKeyValueMap.put(STORAGE_DIR, "/downloads");
}
| private final IConfigRepository configRepository; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/service/impl/ConfigService.java | // Path: src/main/java/com/lixiaocong/cms/entity/Config.java
// @Entity(name = "Config")
// public class Config extends AbstractEntity {
// @Column(nullable = false, unique = true, name = "config_key")
// private String key;
//
// @Column(nullable = false, name = "config_value")
// private String value;
//
// public String getKey() {
// return key;
// }
//
// public void setKey(String key) {
// this.key = key;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IConfigRepository.java
// public interface IConfigRepository extends JpaRepository<Config, Long> {
// Config findByKey(String key);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
| import com.lixiaocong.cms.entity.Config;
import com.lixiaocong.cms.repository.IConfigRepository;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map; | private static Map<String, String> defaultKeyValueMap = new HashMap<>();
static {
defaultKeyValueMap.put(BLOG_ENABLED, "1");
defaultKeyValueMap.put(APPLICATION_URL, "127.0.0.1");
defaultKeyValueMap.put(QQ_ENABLED, "0");
defaultKeyValueMap.put(QQ_ID, "");
defaultKeyValueMap.put(QQ_SECRET, "");
defaultKeyValueMap.put(WEIXIN_ENABLED, "0");
defaultKeyValueMap.put(WEIXIN_ID, "");
defaultKeyValueMap.put(WEIXIN_KEY, "");
defaultKeyValueMap.put(WEIXIN_SECRET, "");
defaultKeyValueMap.put(WEIXIN_TOKEN, "");
defaultKeyValueMap.put(DOWNLOADER_ENABLED, "0");
defaultKeyValueMap.put(DOWNLOADER_ARIA2C_URL, "http://127.0.0.1:6800/jsonrpc");
defaultKeyValueMap.put(DOWNLOADER_ARIA2C_PASSWORD, "password");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_URL, "http://127.0.0.1:9091/transmission/rpc");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_USERNAME, "username");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_PASSWORD, "password");
defaultKeyValueMap.put(STORAGE_DIR, "/downloads");
}
private final IConfigRepository configRepository;
@Autowired
public ConfigService(IConfigRepository configRepository) {
this.configRepository = configRepository;
}
private String getValue(String key) { | // Path: src/main/java/com/lixiaocong/cms/entity/Config.java
// @Entity(name = "Config")
// public class Config extends AbstractEntity {
// @Column(nullable = false, unique = true, name = "config_key")
// private String key;
//
// @Column(nullable = false, name = "config_value")
// private String value;
//
// public String getKey() {
// return key;
// }
//
// public void setKey(String key) {
// this.key = key;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IConfigRepository.java
// public interface IConfigRepository extends JpaRepository<Config, Long> {
// Config findByKey(String key);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
// Path: src/main/java/com/lixiaocong/cms/service/impl/ConfigService.java
import com.lixiaocong.cms.entity.Config;
import com.lixiaocong.cms.repository.IConfigRepository;
import com.lixiaocong.cms.service.IConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
private static Map<String, String> defaultKeyValueMap = new HashMap<>();
static {
defaultKeyValueMap.put(BLOG_ENABLED, "1");
defaultKeyValueMap.put(APPLICATION_URL, "127.0.0.1");
defaultKeyValueMap.put(QQ_ENABLED, "0");
defaultKeyValueMap.put(QQ_ID, "");
defaultKeyValueMap.put(QQ_SECRET, "");
defaultKeyValueMap.put(WEIXIN_ENABLED, "0");
defaultKeyValueMap.put(WEIXIN_ID, "");
defaultKeyValueMap.put(WEIXIN_KEY, "");
defaultKeyValueMap.put(WEIXIN_SECRET, "");
defaultKeyValueMap.put(WEIXIN_TOKEN, "");
defaultKeyValueMap.put(DOWNLOADER_ENABLED, "0");
defaultKeyValueMap.put(DOWNLOADER_ARIA2C_URL, "http://127.0.0.1:6800/jsonrpc");
defaultKeyValueMap.put(DOWNLOADER_ARIA2C_PASSWORD, "password");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_URL, "http://127.0.0.1:9091/transmission/rpc");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_USERNAME, "username");
defaultKeyValueMap.put(DOWNLOADER_TRANSMISSION_PASSWORD, "password");
defaultKeyValueMap.put(STORAGE_DIR, "/downloads");
}
private final IConfigRepository configRepository;
@Autowired
public ConfigService(IConfigRepository configRepository) {
this.configRepository = configRepository;
}
private String getValue(String key) { | Config config = this.configRepository.findByKey(key); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/exception/ExceptionControllerAdvice.java | // Path: src/main/java/com/lixiaocong/cms/rest/ResponseMsgFactory.java
// public class ResponseMsgFactory {
// static Map<String, Object> createSuccessResponse() {
// Map<String, Object> ret = new HashMap<>();
// ret.put("result", "success");
// return ret;
// }
//
// static Map<String, Object> createSuccessResponse(String name, Object value) {
// Map<String, Object> ret = createSuccessResponse();
// ret.put(name, value);
// return ret;
// }
//
// public static Map<String, Object> createFailedResponse(String msg) {
// Map<String, Object> ret = new HashMap<>();
// ret.put("result", "failed");
// ret.put("message", msg);
// return ret;
// }
// }
| import com.lixiaocong.cms.rest.ResponseMsgFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;
import java.util.Map; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.exception;
@ControllerAdvice
public class ExceptionControllerAdvice {
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(ControllerParamException.class)
public ModelAndView handleIOException() {
return new ModelAndView("/error/500");
}
@ResponseBody
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(RestParamException.class)
public Map<String, Object> handleRestParamException() { | // Path: src/main/java/com/lixiaocong/cms/rest/ResponseMsgFactory.java
// public class ResponseMsgFactory {
// static Map<String, Object> createSuccessResponse() {
// Map<String, Object> ret = new HashMap<>();
// ret.put("result", "success");
// return ret;
// }
//
// static Map<String, Object> createSuccessResponse(String name, Object value) {
// Map<String, Object> ret = createSuccessResponse();
// ret.put(name, value);
// return ret;
// }
//
// public static Map<String, Object> createFailedResponse(String msg) {
// Map<String, Object> ret = new HashMap<>();
// ret.put("result", "failed");
// ret.put("message", msg);
// return ret;
// }
// }
// Path: src/main/java/com/lixiaocong/cms/exception/ExceptionControllerAdvice.java
import com.lixiaocong.cms.rest.ResponseMsgFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;
import java.util.Map;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.exception;
@ControllerAdvice
public class ExceptionControllerAdvice {
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(ControllerParamException.class)
public ModelAndView handleIOException() {
return new ModelAndView("/error/500");
}
@ResponseBody
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(RestParamException.class)
public Map<String, Object> handleRestParamException() { | return ResponseMsgFactory.createFailedResponse("参数错误"); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/socket/SocketInterceptor.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;
import java.util.Map; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.socket;
public class SocketInterceptor implements HandshakeInterceptor {
private static final Log log = LogFactory.getLog(SocketInterceptor.class);
| // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/socket/SocketInterceptor.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;
import java.util.Map;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.socket;
public class SocketInterceptor implements HandshakeInterceptor {
private static final Log log = LogFactory.getLog(SocketInterceptor.class);
| private final IUserRepository userRepository; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/socket/SocketInterceptor.java | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
| import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;
import java.util.Map; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.socket;
public class SocketInterceptor implements HandshakeInterceptor {
private static final Log log = LogFactory.getLog(SocketInterceptor.class);
private final IUserRepository userRepository;
public SocketInterceptor(IUserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
String name = request.getPrincipal().getName(); | // Path: src/main/java/com/lixiaocong/cms/entity/User.java
// @Entity(name = "User")
// public class User extends AbstractEntity {
// @Column(nullable = false, unique = true)
// private String username;
//
// @JsonIgnore
// @Column(nullable = false)
// private String password;
//
// @Column(nullable = false)
// private boolean admin;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Article> articles;
//
// @JsonIgnore
// @OneToMany(mappedBy = "user", cascade = {CascadeType.REMOVE})
// private Set<Comment> comments;
//
// public User() {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
// }
//
// public User(String username, String password) {
// admin = false;
// articles = new HashSet<>();
// comments = new HashSet<>();
//
// this.username = username;
// this.password = password;
// }
//
// public Set<Comment> getComments() {
// return comments;
// }
//
// public void setComments(Set<Comment> comments) {
// this.comments = comments;
// }
//
// public Set<Article> getArticles() {
// return articles;
// }
//
// public void setArticles(Set<Article> articles) {
// this.articles = articles;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public boolean isAdmin() {
// return admin;
// }
//
// public void setAdmin(boolean admin) {
// this.admin = admin;
// }
// }
//
// Path: src/main/java/com/lixiaocong/cms/repository/IUserRepository.java
// public interface IUserRepository extends JpaRepository<User, Long> {
// User findByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/socket/SocketInterceptor.java
import com.lixiaocong.cms.entity.User;
import com.lixiaocong.cms.repository.IUserRepository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;
import java.util.Map;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.socket;
public class SocketInterceptor implements HandshakeInterceptor {
private static final Log log = LogFactory.getLog(SocketInterceptor.class);
private final IUserRepository userRepository;
public SocketInterceptor(IUserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
String name = request.getPrincipal().getName(); | User user = userRepository.findByUsername(name); |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/controller/DispatchController.java | // Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
| import com.lixiaocong.cms.service.IConfigService;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.RedirectView;
import javax.annotation.security.RolesAllowed; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.controller;
@Controller
public class DispatchController { | // Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/controller/DispatchController.java
import com.lixiaocong.cms.service.IConfigService;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.RedirectView;
import javax.annotation.security.RolesAllowed;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.controller;
@Controller
public class DispatchController { | private final IUserService userService; |
lixiaocong/lxcCMS | src/main/java/com/lixiaocong/cms/controller/DispatchController.java | // Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
| import com.lixiaocong.cms.service.IConfigService;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.RedirectView;
import javax.annotation.security.RolesAllowed; | /*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.controller;
@Controller
public class DispatchController {
private final IUserService userService; | // Path: src/main/java/com/lixiaocong/cms/service/IConfigService.java
// public interface IConfigService {
// String getApplicationUrl();
//
// void setApplicationUrl(String applicationUrl);
//
// boolean isBlogEnabled();
//
// void setBlogEnabled(boolean isEnabled);
//
// boolean isQQEnabled();
//
// void setQQEnabled(boolean isEnabled);
//
// String getQQId();
//
// void setQQId(String qqId);
//
// String getQQSecret();
//
// void setQQSecret(String qqSecret);
//
// boolean isWeixinEnabled();
//
// void setWeixinEnabled(boolean isEnabled);
//
// String getWeixinId();
//
// void setWeixinId(String weixinId);
//
// String getWeixinSecret();
//
// void setWeixinSecret(String weixinSecret);
//
// String getWeixinToken();
//
// void setWeixinToken(String weixinToken);
//
// String getWeixinKey();
//
// void setWeixinKey(String weixinKey);
//
// boolean isDownloaderEnabled();
//
// void setDownloaderEnabled(boolean isEnabled);
//
// String getDownloaderAria2cUrl();
//
// void setDownloaderAria2cUrl(String aria2cUrl);
//
// String getDownloaderAria2cPassword();
//
// void setDownloaderAria2cPassword(String aria2cPassword);
//
// String getDownloaderTransmissionUrl();
//
// void setDownloaderTransmissionUrl(String transmissionUrl);
//
// String getDownloaderTransmissionUsername();
//
// void setDownloaderTransmissionUsername(String transmissionUsername);
//
// String getDownloaderTransmissionPassword();
//
// void setDownloaderTransmissionPassword(String transmissionPassword);
//
// String getStorageDir();
//
// void setStorageDir(String storageDir);
//
// void setValue(String key, String value);
// }
//
// Path: src/main/java/com/lixiaocong/cms/service/IUserService.java
// public interface IUserService {
// User create(String username, String password);
//
// void delete(long id);
//
// void update(User user);
//
// User get(long id);
//
// Page<User> get(int page, int size);
//
// User getByUsername(String username);
// }
// Path: src/main/java/com/lixiaocong/cms/controller/DispatchController.java
import com.lixiaocong.cms.service.IConfigService;
import com.lixiaocong.cms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.RedirectView;
import javax.annotation.security.RolesAllowed;
/*
BSD 3-Clause License
Copyright (c) 2016, lixiaocong([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.lixiaocong.cms.controller;
@Controller
public class DispatchController {
private final IUserService userService; | private final IConfigService configService; |
phxql/argon2-jvm | argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2Factory.java | // Path: argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/jna/Argon2_type.java
// public class Argon2_type extends NativeLong {
// /**
// * Constructor.
// */
// public Argon2_type() {
// this(0);
// }
//
// /**
// * Constructor.
// *
// * @param value Value.
// */
// public Argon2_type(long value) {
// super(value);
// }
// }
| import de.mkammerer.argon2.jna.Argon2_type; | private static Argon2Advanced createInternal(Argon2Types type, int defaultSaltLength, int defaultHashLength) {
switch (type) {
case ARGON2i:
return new Argon2i(defaultSaltLength, defaultHashLength);
case ARGON2d:
return new Argon2d(defaultSaltLength, defaultHashLength);
case ARGON2id:
return new Argon2id(defaultSaltLength, defaultHashLength);
default:
throw new IllegalArgumentException("Invalid argon2 type");
}
}
/**
* Argon2 type.
*/
public enum Argon2Types {
/**
* Argon2i.
*/
ARGON2i(1),
/**
* Argon2d.
*/
ARGON2d(0),
/**
* Argon2id
*/
ARGON2id(2);
| // Path: argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/jna/Argon2_type.java
// public class Argon2_type extends NativeLong {
// /**
// * Constructor.
// */
// public Argon2_type() {
// this(0);
// }
//
// /**
// * Constructor.
// *
// * @param value Value.
// */
// public Argon2_type(long value) {
// super(value);
// }
// }
// Path: argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2Factory.java
import de.mkammerer.argon2.jna.Argon2_type;
private static Argon2Advanced createInternal(Argon2Types type, int defaultSaltLength, int defaultHashLength) {
switch (type) {
case ARGON2i:
return new Argon2i(defaultSaltLength, defaultHashLength);
case ARGON2d:
return new Argon2d(defaultSaltLength, defaultHashLength);
case ARGON2id:
return new Argon2id(defaultSaltLength, defaultHashLength);
default:
throw new IllegalArgumentException("Invalid argon2 type");
}
}
/**
* Argon2 type.
*/
public enum Argon2Types {
/**
* Argon2i.
*/
ARGON2i(1),
/**
* Argon2d.
*/
ARGON2d(0),
/**
* Argon2id
*/
ARGON2id(2);
| private final Argon2_type jnaType; |
phxql/argon2-jvm | argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/jna/Argon2_version.java | // Path: argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2Version.java
// public enum Argon2Version {
// V10(0x10),
// V13(0x13),
// DEFAULT_VERSION(V13.version);
//
// private final int version;
// private final Argon2_version jnaType;
//
// Argon2Version(int version) {
// this.version = version;
// this.jnaType = new Argon2_version(version);
// }
//
// public Argon2_version getJnaType() {
// return jnaType;
// }
//
// public int getVersion() {
// return version;
// }
// }
| import de.mkammerer.argon2.Argon2Version; | package de.mkammerer.argon2.jna;
/**
* argon2_type type for C interaction.
*/
public class Argon2_version extends JnaUint32 {
/**
* Constructor.
*/
public Argon2_version() { | // Path: argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2Version.java
// public enum Argon2Version {
// V10(0x10),
// V13(0x13),
// DEFAULT_VERSION(V13.version);
//
// private final int version;
// private final Argon2_version jnaType;
//
// Argon2Version(int version) {
// this.version = version;
// this.jnaType = new Argon2_version(version);
// }
//
// public Argon2_version getJnaType() {
// return jnaType;
// }
//
// public int getVersion() {
// return version;
// }
// }
// Path: argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/jna/Argon2_version.java
import de.mkammerer.argon2.Argon2Version;
package de.mkammerer.argon2.jna;
/**
* argon2_type type for C interaction.
*/
public class Argon2_version extends JnaUint32 {
/**
* Constructor.
*/
public Argon2_version() { | this(Argon2Version.DEFAULT_VERSION.getVersion()); |
phxql/argon2-jvm | argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2Version.java | // Path: argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/jna/Argon2_version.java
// public class Argon2_version extends JnaUint32 {
//
// /**
// * Constructor.
// */
// public Argon2_version() {
// this(Argon2Version.DEFAULT_VERSION.getVersion());
// }
//
// /**
// * Constructor.
// *
// * @param version Version.
// */
// public Argon2_version(int version) {
// super(version);
// }
// }
| import de.mkammerer.argon2.jna.Argon2_version; | package de.mkammerer.argon2;
/**
* Version of the Argon2 algorithm.
*/
public enum Argon2Version {
V10(0x10),
V13(0x13),
DEFAULT_VERSION(V13.version);
private final int version; | // Path: argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/jna/Argon2_version.java
// public class Argon2_version extends JnaUint32 {
//
// /**
// * Constructor.
// */
// public Argon2_version() {
// this(Argon2Version.DEFAULT_VERSION.getVersion());
// }
//
// /**
// * Constructor.
// *
// * @param version Version.
// */
// public Argon2_version(int version) {
// super(version);
// }
// }
// Path: argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2Version.java
import de.mkammerer.argon2.jna.Argon2_version;
package de.mkammerer.argon2;
/**
* Version of the Argon2 algorithm.
*/
public enum Argon2Version {
V10(0x10),
V13(0x13),
DEFAULT_VERSION(V13.version);
private final int version; | private final Argon2_version jnaType; |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/frsky/FrskyHubProtocol.java | // Path: src/com/ezio/multiwii/helpers/Functions.java
// public class Functions {
//
//
// public static long ConcatInt(int x, int y) {
// return (int) ((x * Math.pow(10, numberOfDigits(y))) + y);
// }
//
// public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int map(int x, int in_min, int in_max, int out_min, int out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int numberOfDigits(long n) {
// // Guessing 4 digit numbers will be more probable.
// // They are set in the first branch.
// if (n < 10000L) { // from 1 to 4
// if (n < 100L) { // 1 or 2
// if (n < 10L) {
// return 1;
// } else {
// return 2;
// }
// } else { // 3 or 4
// if (n < 1000L) {
// return 3;
// } else {
// return 4;
// }
// }
// } else { // from 5 a 20 (albeit longs can't have more than 18 or 19)
// if (n < 1000000000000L) { // from 5 to 12
// if (n < 100000000L) { // from 5 to 8
// if (n < 1000000L) { // 5 or 6
// if (n < 100000L) {
// return 5;
// } else {
// return 6;
// }
// } else { // 7 u 8
// if (n < 10000000L) {
// return 7;
// } else {
// return 8;
// }
// }
// } else { // from 9 to 12
// if (n < 10000000000L) { // 9 or 10
// if (n < 1000000000L) {
// return 9;
// } else {
// return 10;
// }
// } else { // 11 or 12
// if (n < 100000000000L) {
// return 11;
// } else {
// return 12;
// }
// }
// }
// } else { // from 13 to ... (18 or 20)
// if (n < 10000000000000000L) { // from 13 to 16
// if (n < 100000000000000L) { // 13 or 14
// if (n < 10000000000000L) {
// return 13;
// } else {
// return 14;
// }
// } else { // 15 or 16
// if (n < 1000000000000000L) {
// return 15;
// } else {
// return 16;
// }
// }
// } else { // from 17 to ...¿20?
// if (n < 1000000000000000000L) { // 17 or 18
// if (n < 100000000000000000L) {
// return 17;
// } else {
// return 18;
// }
// } else { // 19? Can it be?
// // 10000000000000000000L is'nt a valid long.
// return 19;
// }
// }
// }
// }
// }
// }
| import java.util.LinkedList;
import java.util.List;
import android.util.Log;
import com.ezio.multiwii.helpers.Functions;
| log("FuelLevel", getHex(new int[] { frame[2], frame[3] }));
break; // 0x04;// Fuel Level % U 0, 25, 50, 75, 100
case Temperature2:
log("+Temperature2 (Distance to home)", String.valueOf(getIntFromFrame(frame)));
break;// 0x05;// Temprature2 °C S 1°C / -30~250
case Volt:
log("Volt", getHex(new int[] { frame[2], frame[3] }));
break; // 0x06;// Volt v 0.01v / 0~4.2v
case AltitudeBefore:
AltitudeTemp = (float) getIntFromFrame(frame);
log("+AltitudeBefore", String.valueOf(Altitude));
break;// 0x10;// Altitude m S 0.01m / -500~9000m Before “.”
case AltutudeAfter:
Altitude = AltitudeTemp + ((float) getIntFromFrame(frame)) / 100f;
log("+AltutudeAfter", String.valueOf(Altitude));
break;// 0x21;// U After “.”
case GPSspeedBefore:
GPS_Speed = getIntFromFrame(frame);
log("+GPSspeedBefore", String.valueOf(getIntFromFrame(frame)));
break;// 0x11;// GPS speed Knots U Before “.”
case GPSspeedAfter:
log("GPSspeedAfter", getHex(new int[] { frame[2], frame[3] }));
break; // 0x11 + 8;// U After “.”
case LongitudeBefore:
GPS_LongitudeBefore = getIntFromFrame(frame);
log("+LongitudeBefore", String.valueOf(getIntFromFrame(frame)));
break; // 0x12;// Longitude dddmm.mmmm Before “.”
case LongitudeAfter:
GPS_LongitudeAfter = getIntFromFrame(frame);
| // Path: src/com/ezio/multiwii/helpers/Functions.java
// public class Functions {
//
//
// public static long ConcatInt(int x, int y) {
// return (int) ((x * Math.pow(10, numberOfDigits(y))) + y);
// }
//
// public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int map(int x, int in_min, int in_max, int out_min, int out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int numberOfDigits(long n) {
// // Guessing 4 digit numbers will be more probable.
// // They are set in the first branch.
// if (n < 10000L) { // from 1 to 4
// if (n < 100L) { // 1 or 2
// if (n < 10L) {
// return 1;
// } else {
// return 2;
// }
// } else { // 3 or 4
// if (n < 1000L) {
// return 3;
// } else {
// return 4;
// }
// }
// } else { // from 5 a 20 (albeit longs can't have more than 18 or 19)
// if (n < 1000000000000L) { // from 5 to 12
// if (n < 100000000L) { // from 5 to 8
// if (n < 1000000L) { // 5 or 6
// if (n < 100000L) {
// return 5;
// } else {
// return 6;
// }
// } else { // 7 u 8
// if (n < 10000000L) {
// return 7;
// } else {
// return 8;
// }
// }
// } else { // from 9 to 12
// if (n < 10000000000L) { // 9 or 10
// if (n < 1000000000L) {
// return 9;
// } else {
// return 10;
// }
// } else { // 11 or 12
// if (n < 100000000000L) {
// return 11;
// } else {
// return 12;
// }
// }
// }
// } else { // from 13 to ... (18 or 20)
// if (n < 10000000000000000L) { // from 13 to 16
// if (n < 100000000000000L) { // 13 or 14
// if (n < 10000000000000L) {
// return 13;
// } else {
// return 14;
// }
// } else { // 15 or 16
// if (n < 1000000000000000L) {
// return 15;
// } else {
// return 16;
// }
// }
// } else { // from 17 to ...¿20?
// if (n < 1000000000000000000L) { // 17 or 18
// if (n < 100000000000000000L) {
// return 17;
// } else {
// return 18;
// }
// } else { // 19? Can it be?
// // 10000000000000000000L is'nt a valid long.
// return 19;
// }
// }
// }
// }
// }
// }
// Path: src/com/ezio/multiwii/frsky/FrskyHubProtocol.java
import java.util.LinkedList;
import java.util.List;
import android.util.Log;
import com.ezio.multiwii.helpers.Functions;
log("FuelLevel", getHex(new int[] { frame[2], frame[3] }));
break; // 0x04;// Fuel Level % U 0, 25, 50, 75, 100
case Temperature2:
log("+Temperature2 (Distance to home)", String.valueOf(getIntFromFrame(frame)));
break;// 0x05;// Temprature2 °C S 1°C / -30~250
case Volt:
log("Volt", getHex(new int[] { frame[2], frame[3] }));
break; // 0x06;// Volt v 0.01v / 0~4.2v
case AltitudeBefore:
AltitudeTemp = (float) getIntFromFrame(frame);
log("+AltitudeBefore", String.valueOf(Altitude));
break;// 0x10;// Altitude m S 0.01m / -500~9000m Before “.”
case AltutudeAfter:
Altitude = AltitudeTemp + ((float) getIntFromFrame(frame)) / 100f;
log("+AltutudeAfter", String.valueOf(Altitude));
break;// 0x21;// U After “.”
case GPSspeedBefore:
GPS_Speed = getIntFromFrame(frame);
log("+GPSspeedBefore", String.valueOf(getIntFromFrame(frame)));
break;// 0x11;// GPS speed Knots U Before “.”
case GPSspeedAfter:
log("GPSspeedAfter", getHex(new int[] { frame[2], frame[3] }));
break; // 0x11 + 8;// U After “.”
case LongitudeBefore:
GPS_LongitudeBefore = getIntFromFrame(frame);
log("+LongitudeBefore", String.valueOf(getIntFromFrame(frame)));
break; // 0x12;// Longitude dddmm.mmmm Before “.”
case LongitudeAfter:
GPS_LongitudeAfter = getIntFromFrame(frame);
| GPS_Longtitude = GPS_EW * 10 * Functions.ConcatInt(GPS_LongitudeBefore, GPS_LongitudeAfter);
|
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/graph/LineGraphView.java | // Path: src/com/ezio/multiwii/graph/GraphViewSeries.java
// static public class GraphViewSeriesStyle {
// public int color = 0xff0077cc;
// public int thickness = 3;
// private ValueDependentColor valueDependentColor;
//
// public GraphViewSeriesStyle() {
// super();
// }
//
// public GraphViewSeriesStyle(int color, int thickness) {
// super();
// this.color = color;
// this.thickness = thickness;
// }
//
// public void setValueDependentColor(ValueDependentColor valueDependentColor) {
// this.valueDependentColor = valueDependentColor;
// }
//
// public ValueDependentColor getValueDependentColor() {
// return valueDependentColor;
// }
// }
| import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import com.ezio.multiwii.graph.GraphViewSeries.GraphViewSeriesStyle; | package com.ezio.multiwii.graph;
/**
* Line Graph View. This draws a line chart.
* @author jjoe64 - jonas gehring - http://www.jjoe64.com
*
* Copyright (C) 2011 Jonas Gehring
* Licensed under the GNU Lesser General Public License (LGPL)
* http://www.gnu.org/licenses/lgpl.html
*/
public class LineGraphView extends GraphView {
private final Paint paintBackground;
private boolean drawBackground;
public LineGraphView(Context context, String title) {
super(context, title);
paintBackground = new Paint();
paintBackground.setARGB(255, 20, 40, 60);
paintBackground.setStrokeWidth(4);
}
@Override | // Path: src/com/ezio/multiwii/graph/GraphViewSeries.java
// static public class GraphViewSeriesStyle {
// public int color = 0xff0077cc;
// public int thickness = 3;
// private ValueDependentColor valueDependentColor;
//
// public GraphViewSeriesStyle() {
// super();
// }
//
// public GraphViewSeriesStyle(int color, int thickness) {
// super();
// this.color = color;
// this.thickness = thickness;
// }
//
// public void setValueDependentColor(ValueDependentColor valueDependentColor) {
// this.valueDependentColor = valueDependentColor;
// }
//
// public ValueDependentColor getValueDependentColor() {
// return valueDependentColor;
// }
// }
// Path: src/com/ezio/multiwii/graph/LineGraphView.java
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import com.ezio.multiwii.graph.GraphViewSeries.GraphViewSeriesStyle;
package com.ezio.multiwii.graph;
/**
* Line Graph View. This draws a line chart.
* @author jjoe64 - jonas gehring - http://www.jjoe64.com
*
* Copyright (C) 2011 Jonas Gehring
* Licensed under the GNU Lesser General Public License (LGPL)
* http://www.gnu.org/licenses/lgpl.html
*/
public class LineGraphView extends GraphView {
private final Paint paintBackground;
private boolean drawBackground;
public LineGraphView(Context context, String title) {
super(context, title);
paintBackground = new Paint();
paintBackground.setARGB(255, 20, 40, 60);
paintBackground.setStrokeWidth(4);
}
@Override | public void drawSeries(Canvas canvas, GraphViewData[] values, float graphwidth, float graphheight, float border, double minX, double minY, double diffX, double diffY, float horstart, GraphViewSeriesStyle style) { |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/dashboard/dashboard3/AltitudeView.java | // Path: src/com/ezio/multiwii/helpers/LowPassFilter.java
// public class LowPassFilter {
// /*
// * time smoothing constant for low-pass filter 0 ≤ alpha ≤ 1 ; a smaller
// * value basically means more smoothing See: http://en.wikipedia.org/wiki
// * /Low-pass_filter#Discrete-time_realization
// */
// float ALPHA = 0f;
// float lastOutput = 0;
//
// public LowPassFilter(float ALPHA) {
// this.ALPHA = ALPHA;
// }
//
// public float lowPass(float input) {
// if (Math.abs(input - lastOutput) > 170) {
// lastOutput = input;
// return lastOutput;
// }
// lastOutput = lastOutput + ALPHA * (input - lastOutput);
// return lastOutput;
// }
// }
| import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.LowPassFilter; | /* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.dashboard.dashboard3;
public class AltitudeView extends View {
boolean D = false;
Paint mPaint;
Rect DrawingRec;
int ww = 0, hh = 0;
int tmp = 0;
Bitmap[] bmp = new Bitmap[4];
Matrix matrix = new Matrix();
Context context;
public float alt = 150;
| // Path: src/com/ezio/multiwii/helpers/LowPassFilter.java
// public class LowPassFilter {
// /*
// * time smoothing constant for low-pass filter 0 ≤ alpha ≤ 1 ; a smaller
// * value basically means more smoothing See: http://en.wikipedia.org/wiki
// * /Low-pass_filter#Discrete-time_realization
// */
// float ALPHA = 0f;
// float lastOutput = 0;
//
// public LowPassFilter(float ALPHA) {
// this.ALPHA = ALPHA;
// }
//
// public float lowPass(float input) {
// if (Math.abs(input - lastOutput) > 170) {
// lastOutput = input;
// return lastOutput;
// }
// lastOutput = lastOutput + ALPHA * (input - lastOutput);
// return lastOutput;
// }
// }
// Path: src/com/ezio/multiwii/dashboard/dashboard3/AltitudeView.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.LowPassFilter;
/* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.dashboard.dashboard3;
public class AltitudeView extends View {
boolean D = false;
Paint mPaint;
Rect DrawingRec;
int ww = 0, hh = 0;
int tmp = 0;
Bitmap[] bmp = new Bitmap[4];
Matrix matrix = new Matrix();
Context context;
public float alt = 150;
| LowPassFilter lowPassFilter = new LowPassFilter(0.05f); |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/dashboard/dashboard3/HeadingView.java | // Path: src/com/ezio/multiwii/helpers/LowPassFilter.java
// public class LowPassFilter {
// /*
// * time smoothing constant for low-pass filter 0 ≤ alpha ≤ 1 ; a smaller
// * value basically means more smoothing See: http://en.wikipedia.org/wiki
// * /Low-pass_filter#Discrete-time_realization
// */
// float ALPHA = 0f;
// float lastOutput = 0;
//
// public LowPassFilter(float ALPHA) {
// this.ALPHA = ALPHA;
// }
//
// public float lowPass(float input) {
// if (Math.abs(input - lastOutput) > 170) {
// lastOutput = input;
// return lastOutput;
// }
// lastOutput = lastOutput + ALPHA * (input - lastOutput);
// return lastOutput;
// }
// }
| import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.LowPassFilter; | /* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.dashboard.dashboard3;
public class HeadingView extends View {
boolean D = false;
Paint mPaint;
Rect DrawingRec;
int ww = 0, hh = 0;
int tmp = 0;
Bitmap[] bmp = new Bitmap[2];
Matrix matrix = new Matrix();
Context context;
public float heading = 0;
| // Path: src/com/ezio/multiwii/helpers/LowPassFilter.java
// public class LowPassFilter {
// /*
// * time smoothing constant for low-pass filter 0 ≤ alpha ≤ 1 ; a smaller
// * value basically means more smoothing See: http://en.wikipedia.org/wiki
// * /Low-pass_filter#Discrete-time_realization
// */
// float ALPHA = 0f;
// float lastOutput = 0;
//
// public LowPassFilter(float ALPHA) {
// this.ALPHA = ALPHA;
// }
//
// public float lowPass(float input) {
// if (Math.abs(input - lastOutput) > 170) {
// lastOutput = input;
// return lastOutput;
// }
// lastOutput = lastOutput + ALPHA * (input - lastOutput);
// return lastOutput;
// }
// }
// Path: src/com/ezio/multiwii/dashboard/dashboard3/HeadingView.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.LowPassFilter;
/* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.dashboard.dashboard3;
public class HeadingView extends View {
boolean D = false;
Paint mPaint;
Rect DrawingRec;
int ww = 0, hh = 0;
int tmp = 0;
Bitmap[] bmp = new Bitmap[2];
Matrix matrix = new Matrix();
Context context;
public float heading = 0;
| LowPassFilter lowPassFilter = new LowPassFilter(0.2f); |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/radio/StickView.java | // Path: src/com/ezio/multiwii/helpers/Functions.java
// public class Functions {
//
//
// public static long ConcatInt(int x, int y) {
// return (int) ((x * Math.pow(10, numberOfDigits(y))) + y);
// }
//
// public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int map(int x, int in_min, int in_max, int out_min, int out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int numberOfDigits(long n) {
// // Guessing 4 digit numbers will be more probable.
// // They are set in the first branch.
// if (n < 10000L) { // from 1 to 4
// if (n < 100L) { // 1 or 2
// if (n < 10L) {
// return 1;
// } else {
// return 2;
// }
// } else { // 3 or 4
// if (n < 1000L) {
// return 3;
// } else {
// return 4;
// }
// }
// } else { // from 5 a 20 (albeit longs can't have more than 18 or 19)
// if (n < 1000000000000L) { // from 5 to 12
// if (n < 100000000L) { // from 5 to 8
// if (n < 1000000L) { // 5 or 6
// if (n < 100000L) {
// return 5;
// } else {
// return 6;
// }
// } else { // 7 u 8
// if (n < 10000000L) {
// return 7;
// } else {
// return 8;
// }
// }
// } else { // from 9 to 12
// if (n < 10000000000L) { // 9 or 10
// if (n < 1000000000L) {
// return 9;
// } else {
// return 10;
// }
// } else { // 11 or 12
// if (n < 100000000000L) {
// return 11;
// } else {
// return 12;
// }
// }
// }
// } else { // from 13 to ... (18 or 20)
// if (n < 10000000000000000L) { // from 13 to 16
// if (n < 100000000000000L) { // 13 or 14
// if (n < 10000000000000L) {
// return 13;
// } else {
// return 14;
// }
// } else { // 15 or 16
// if (n < 1000000000000000L) {
// return 15;
// } else {
// return 16;
// }
// }
// } else { // from 17 to ...¿20?
// if (n < 1000000000000000000L) { // 17 or 18
// if (n < 100000000000000000L) {
// return 17;
// } else {
// return 18;
// }
// } else { // 19? Can it be?
// // 10000000000000000000L is'nt a valid long.
// return 19;
// }
// }
// }
// }
// }
// }
| import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import com.ezio.multiwii.helpers.Functions; | /* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.radio;
public class StickView extends View {
public float x, y;
int hh, ww;
Paint paint = new Paint();
Paint paint1 = new Paint();
Paint paint2 = new Paint();
Paint paint3 = new Paint();
float scaledDensity = 0;
public float InputX(float x) { | // Path: src/com/ezio/multiwii/helpers/Functions.java
// public class Functions {
//
//
// public static long ConcatInt(int x, int y) {
// return (int) ((x * Math.pow(10, numberOfDigits(y))) + y);
// }
//
// public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int map(int x, int in_min, int in_max, int out_min, int out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int numberOfDigits(long n) {
// // Guessing 4 digit numbers will be more probable.
// // They are set in the first branch.
// if (n < 10000L) { // from 1 to 4
// if (n < 100L) { // 1 or 2
// if (n < 10L) {
// return 1;
// } else {
// return 2;
// }
// } else { // 3 or 4
// if (n < 1000L) {
// return 3;
// } else {
// return 4;
// }
// }
// } else { // from 5 a 20 (albeit longs can't have more than 18 or 19)
// if (n < 1000000000000L) { // from 5 to 12
// if (n < 100000000L) { // from 5 to 8
// if (n < 1000000L) { // 5 or 6
// if (n < 100000L) {
// return 5;
// } else {
// return 6;
// }
// } else { // 7 u 8
// if (n < 10000000L) {
// return 7;
// } else {
// return 8;
// }
// }
// } else { // from 9 to 12
// if (n < 10000000000L) { // 9 or 10
// if (n < 1000000000L) {
// return 9;
// } else {
// return 10;
// }
// } else { // 11 or 12
// if (n < 100000000000L) {
// return 11;
// } else {
// return 12;
// }
// }
// }
// } else { // from 13 to ... (18 or 20)
// if (n < 10000000000000000L) { // from 13 to 16
// if (n < 100000000000000L) { // 13 or 14
// if (n < 10000000000000L) {
// return 13;
// } else {
// return 14;
// }
// } else { // 15 or 16
// if (n < 1000000000000000L) {
// return 15;
// } else {
// return 16;
// }
// }
// } else { // from 17 to ...¿20?
// if (n < 1000000000000000000L) { // 17 or 18
// if (n < 100000000000000000L) {
// return 17;
// } else {
// return 18;
// }
// } else { // 19? Can it be?
// // 10000000000000000000L is'nt a valid long.
// return 19;
// }
// }
// }
// }
// }
// }
// Path: src/com/ezio/multiwii/radio/StickView.java
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import com.ezio.multiwii.helpers.Functions;
/* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.radio;
public class StickView extends View {
public float x, y;
int hh, ww;
Paint paint = new Paint();
Paint paint1 = new Paint();
Paint paint2 = new Paint();
Paint paint3 = new Paint();
float scaledDensity = 0;
public float InputX(float x) { | float a = Functions.map(x, 0, ww, 1000, 2000); |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/raw/RawDataActivity.java | // Path: src/com/ezio/multiwii/mw/ServoConfClass.java
// public class ServoConfClass {
// public int Min = 0;
// public int Max = 0;
// public int MidPoint = 0;
// public int Rate = 0;
//
// public ServoConfClass() {
// }
//
// }
| import com.ezio.multiwii.mw.ServoConfClass;
import com.ezio.sec.Sec;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
import com.ezio.multiwii.R;
import com.ezio.multiwii.app.App; | log("rcAUX4", app.mw.rcAUX4);
log("debug1", app.mw.debug1);
log("debug2", app.mw.debug2);
log("debug3", app.mw.debug3);
log("debug4", app.mw.debug4);
log("MSP_DEBUGMSG", app.mw.DebugMSG);
for (int i = 0; i < app.mw.mot.length; i++) {
log("Motor" + String.valueOf(i + 1), app.mw.mot[i]);
}
for (int i = 0; i < app.mw.PIDITEMS; i++) {
log("P=" + String.valueOf(app.mw.byteP[i]) + " I=" + String.valueOf(app.mw.byteI[i]) + " D", app.mw.byteD[i]);
}
log("confSetting", app.mw.confSetting);
log("multiCapability", app.mw.multiCapability);
log("rssi", app.mw.rssi);
log("declination", app.mw.mag_decliniation);
for (String s : app.mw.BoxNames) {
log("buttonCheckboxLabel", s);
}
int Si = 0; | // Path: src/com/ezio/multiwii/mw/ServoConfClass.java
// public class ServoConfClass {
// public int Min = 0;
// public int Max = 0;
// public int MidPoint = 0;
// public int Rate = 0;
//
// public ServoConfClass() {
// }
//
// }
// Path: src/com/ezio/multiwii/raw/RawDataActivity.java
import com.ezio.multiwii.mw.ServoConfClass;
import com.ezio.sec.Sec;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
import com.ezio.multiwii.R;
import com.ezio.multiwii.app.App;
log("rcAUX4", app.mw.rcAUX4);
log("debug1", app.mw.debug1);
log("debug2", app.mw.debug2);
log("debug3", app.mw.debug3);
log("debug4", app.mw.debug4);
log("MSP_DEBUGMSG", app.mw.DebugMSG);
for (int i = 0; i < app.mw.mot.length; i++) {
log("Motor" + String.valueOf(i + 1), app.mw.mot[i]);
}
for (int i = 0; i < app.mw.PIDITEMS; i++) {
log("P=" + String.valueOf(app.mw.byteP[i]) + " I=" + String.valueOf(app.mw.byteI[i]) + " D", app.mw.byteD[i]);
}
log("confSetting", app.mw.confSetting);
log("multiCapability", app.mw.multiCapability);
log("rssi", app.mw.rssi);
log("declination", app.mw.mag_decliniation);
for (String s : app.mw.BoxNames) {
log("buttonCheckboxLabel", s);
}
int Si = 0; | for (ServoConfClass s : app.mw.ServoConf) { |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/graph/GraphViewSeries.java | // Path: src/com/ezio/multiwii/graph/GraphView.java
// static public class GraphViewData {
// public final double valueX;
// public final double valueY;
// public GraphViewData(double valueX, double valueY) {
// super();
// this.valueX = valueX;
// this.valueY = valueY;
// }
// }
| import java.util.ArrayList;
import java.util.List;
import com.ezio.multiwii.graph.GraphView.GraphViewData; | package com.ezio.multiwii.graph;
public class GraphViewSeries {
/**
* graph series style: color and thickness
*/
static public class GraphViewSeriesStyle {
public int color = 0xff0077cc;
public int thickness = 3;
private ValueDependentColor valueDependentColor;
public GraphViewSeriesStyle() {
super();
}
public GraphViewSeriesStyle(int color, int thickness) {
super();
this.color = color;
this.thickness = thickness;
}
public void setValueDependentColor(ValueDependentColor valueDependentColor) {
this.valueDependentColor = valueDependentColor;
}
public ValueDependentColor getValueDependentColor() {
return valueDependentColor;
}
}
final String description;
final GraphViewSeriesStyle style; | // Path: src/com/ezio/multiwii/graph/GraphView.java
// static public class GraphViewData {
// public final double valueX;
// public final double valueY;
// public GraphViewData(double valueX, double valueY) {
// super();
// this.valueX = valueX;
// this.valueY = valueY;
// }
// }
// Path: src/com/ezio/multiwii/graph/GraphViewSeries.java
import java.util.ArrayList;
import java.util.List;
import com.ezio.multiwii.graph.GraphView.GraphViewData;
package com.ezio.multiwii.graph;
public class GraphViewSeries {
/**
* graph series style: color and thickness
*/
static public class GraphViewSeriesStyle {
public int color = 0xff0077cc;
public int thickness = 3;
private ValueDependentColor valueDependentColor;
public GraphViewSeriesStyle() {
super();
}
public GraphViewSeriesStyle(int color, int thickness) {
super();
this.color = color;
this.thickness = thickness;
}
public void setValueDependentColor(ValueDependentColor valueDependentColor) {
this.valueDependentColor = valueDependentColor;
}
public ValueDependentColor getValueDependentColor() {
return valueDependentColor;
}
}
final String description;
final GraphViewSeriesStyle style; | GraphViewData[] values; |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/frsky/FrskyProtocol.java | // Path: src/communication/Communication.java
// public abstract class Communication {
// public Handler mHandler;
//
// public static final String TAG = "MULTIWII"; // debug
//
// public boolean Connected = false;
// public String address = "";
//
// Context context;
//
// protected int mState;
//
// public long BytesSent=0;
// public long BytesRecieved=0;
//
// // Constants that indicate the current connection state
// public static final int STATE_NONE = 0; // we're doing nothing
// public static final int STATE_CONNECTING = 2; // now initiating an outgoing
// // connection
// public static final int STATE_CONNECTED = 3; // now connected to a remote
// // device
//
// // Message types sent from the BluetoothChatService Handler
// public static final int MESSAGE_STATE_CHANGE = 1;
// public static final int MESSAGE_READ = 2;
// public static final int MESSAGE_WRITE = 3;
// public static final int MESSAGE_DEVICE_NAME = 4;
// public static final int MESSAGE_TOAST = 5;
//
// // Key names received from the BluetoothChatService Handler
// public static final String DEVICE_NAME = "device_name";
// public static final String TOAST = "toast";
//
// public Communication(Context context) {
// this.context = context;
// }
//
// public void SetHandler(Handler handler) {
// mHandler = handler;
// Log.d("ccc", "Communication Got Handler. SetHandler()");
// }
//
// /**
// * Set the current state of the chat connection
// *
// * @param state
// * An integer defining the current connection state
// */
// protected synchronized void setState(int state) {
// // if (D)
// Log.d(TAG, "setState() " + mState + " -> " + state);
// mState = state;
//
// // Give the new state to the Handler so the UI Activity can update
// if (mHandler != null)
// mHandler.obtainMessage(MESSAGE_STATE_CHANGE, state, -1).sendToTarget();
// else
// Log.d("ccc", "setState() Handle=null error state" + " -> " + state);
//
// }
//
// /**
// * Return the current connection state.
// */
// public synchronized int getState() {
// return mState;
// }
//
// /**
// * Sends Message to UI via Handler
// *
// * @param message
// */
// protected void sendMessageToUI_Toast(String message) {
// // Send a failure message back to the Activity
// if (mHandler != null) {
// Message msg = mHandler.obtainMessage(MESSAGE_TOAST);
// Bundle bundle = new Bundle();
// bundle.putString(TOAST, message);
// msg.setData(bundle);
// mHandler.sendMessage(msg);
// }
// }
//
// public void sendDeviceName(String deviceName) {
// // Send the name of the connected device back to the UI Activity
// if (mHandler != null) {
// Message msg = mHandler.obtainMessage(MESSAGE_DEVICE_NAME);
// Bundle bundle = new Bundle();
// bundle.putString(DEVICE_NAME, deviceName);
// msg.setData(bundle);
// mHandler.sendMessage(msg);
// }
// }
//
// public abstract void Enable();
//
// /**
// * After connection is made set Connected=true
// *
// * @param address
// * -address of device
// */
// public abstract void Connect(String address, int speed);
//
// public abstract boolean dataAvailable();
//
// public abstract byte Read();
//
// public void Write(byte[] arr){
// BytesSent+=arr.length;
// }
//
// public abstract void Close();
//
// public abstract void Disable();
// }
| import java.util.ArrayList;
import android.util.Log;
import communication.Communication; | /* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.frsky;
public class FrskyProtocol {
public FrskyHubProtocol frskyHubProtocol = new FrskyHubProtocol();
public int Analog1 = 0;
public int Analog2 = 0;
public int RxRSSI = 0;
public int TxRSSI = 0;
int f = 0;
int frame[] = new int[11];
| // Path: src/communication/Communication.java
// public abstract class Communication {
// public Handler mHandler;
//
// public static final String TAG = "MULTIWII"; // debug
//
// public boolean Connected = false;
// public String address = "";
//
// Context context;
//
// protected int mState;
//
// public long BytesSent=0;
// public long BytesRecieved=0;
//
// // Constants that indicate the current connection state
// public static final int STATE_NONE = 0; // we're doing nothing
// public static final int STATE_CONNECTING = 2; // now initiating an outgoing
// // connection
// public static final int STATE_CONNECTED = 3; // now connected to a remote
// // device
//
// // Message types sent from the BluetoothChatService Handler
// public static final int MESSAGE_STATE_CHANGE = 1;
// public static final int MESSAGE_READ = 2;
// public static final int MESSAGE_WRITE = 3;
// public static final int MESSAGE_DEVICE_NAME = 4;
// public static final int MESSAGE_TOAST = 5;
//
// // Key names received from the BluetoothChatService Handler
// public static final String DEVICE_NAME = "device_name";
// public static final String TOAST = "toast";
//
// public Communication(Context context) {
// this.context = context;
// }
//
// public void SetHandler(Handler handler) {
// mHandler = handler;
// Log.d("ccc", "Communication Got Handler. SetHandler()");
// }
//
// /**
// * Set the current state of the chat connection
// *
// * @param state
// * An integer defining the current connection state
// */
// protected synchronized void setState(int state) {
// // if (D)
// Log.d(TAG, "setState() " + mState + " -> " + state);
// mState = state;
//
// // Give the new state to the Handler so the UI Activity can update
// if (mHandler != null)
// mHandler.obtainMessage(MESSAGE_STATE_CHANGE, state, -1).sendToTarget();
// else
// Log.d("ccc", "setState() Handle=null error state" + " -> " + state);
//
// }
//
// /**
// * Return the current connection state.
// */
// public synchronized int getState() {
// return mState;
// }
//
// /**
// * Sends Message to UI via Handler
// *
// * @param message
// */
// protected void sendMessageToUI_Toast(String message) {
// // Send a failure message back to the Activity
// if (mHandler != null) {
// Message msg = mHandler.obtainMessage(MESSAGE_TOAST);
// Bundle bundle = new Bundle();
// bundle.putString(TOAST, message);
// msg.setData(bundle);
// mHandler.sendMessage(msg);
// }
// }
//
// public void sendDeviceName(String deviceName) {
// // Send the name of the connected device back to the UI Activity
// if (mHandler != null) {
// Message msg = mHandler.obtainMessage(MESSAGE_DEVICE_NAME);
// Bundle bundle = new Bundle();
// bundle.putString(DEVICE_NAME, deviceName);
// msg.setData(bundle);
// mHandler.sendMessage(msg);
// }
// }
//
// public abstract void Enable();
//
// /**
// * After connection is made set Connected=true
// *
// * @param address
// * -address of device
// */
// public abstract void Connect(String address, int speed);
//
// public abstract boolean dataAvailable();
//
// public abstract byte Read();
//
// public void Write(byte[] arr){
// BytesSent+=arr.length;
// }
//
// public abstract void Close();
//
// public abstract void Disable();
// }
// Path: src/com/ezio/multiwii/frsky/FrskyProtocol.java
import java.util.ArrayList;
import android.util.Log;
import communication.Communication;
/* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.frsky;
public class FrskyProtocol {
public FrskyHubProtocol frskyHubProtocol = new FrskyHubProtocol();
public int Analog1 = 0;
public int Analog2 = 0;
public int RxRSSI = 0;
public int TxRSSI = 0;
int f = 0;
int frame[] = new int[11];
| Communication communicationFrsky; |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/dashboard/dashboard3/VarioView.java | // Path: src/com/ezio/multiwii/helpers/LowPassFilter.java
// public class LowPassFilter {
// /*
// * time smoothing constant for low-pass filter 0 ≤ alpha ≤ 1 ; a smaller
// * value basically means more smoothing See: http://en.wikipedia.org/wiki
// * /Low-pass_filter#Discrete-time_realization
// */
// float ALPHA = 0f;
// float lastOutput = 0;
//
// public LowPassFilter(float ALPHA) {
// this.ALPHA = ALPHA;
// }
//
// public float lowPass(float input) {
// if (Math.abs(input - lastOutput) > 170) {
// lastOutput = input;
// return lastOutput;
// }
// lastOutput = lastOutput + ALPHA * (input - lastOutput);
// return lastOutput;
// }
// }
| import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.LowPassFilter; | /* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.dashboard.dashboard3;
public class VarioView extends View {
boolean D = false;
Paint mPaint;
Rect DrawingRec;
int ww = 0, hh = 0;
int tmp = 0;
Bitmap[] bmp = new Bitmap[2];
Matrix matrix = new Matrix();
Context context;
public float vairo = 0;
| // Path: src/com/ezio/multiwii/helpers/LowPassFilter.java
// public class LowPassFilter {
// /*
// * time smoothing constant for low-pass filter 0 ≤ alpha ≤ 1 ; a smaller
// * value basically means more smoothing See: http://en.wikipedia.org/wiki
// * /Low-pass_filter#Discrete-time_realization
// */
// float ALPHA = 0f;
// float lastOutput = 0;
//
// public LowPassFilter(float ALPHA) {
// this.ALPHA = ALPHA;
// }
//
// public float lowPass(float input) {
// if (Math.abs(input - lastOutput) > 170) {
// lastOutput = input;
// return lastOutput;
// }
// lastOutput = lastOutput + ALPHA * (input - lastOutput);
// return lastOutput;
// }
// }
// Path: src/com/ezio/multiwii/dashboard/dashboard3/VarioView.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.LowPassFilter;
/* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.dashboard.dashboard3;
public class VarioView extends View {
boolean D = false;
Paint mPaint;
Rect DrawingRec;
int ww = 0, hh = 0;
int tmp = 0;
Bitmap[] bmp = new Bitmap[2];
Matrix matrix = new Matrix();
Context context;
public float vairo = 0;
| LowPassFilter lowPassFilter = new LowPassFilter(0.2f); |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/dashboard/Dashboard2View.java | // Path: src/com/ezio/multiwii/helpers/Functions.java
// public class Functions {
//
//
// public static long ConcatInt(int x, int y) {
// return (int) ((x * Math.pow(10, numberOfDigits(y))) + y);
// }
//
// public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int map(int x, int in_min, int in_max, int out_min, int out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int numberOfDigits(long n) {
// // Guessing 4 digit numbers will be more probable.
// // They are set in the first branch.
// if (n < 10000L) { // from 1 to 4
// if (n < 100L) { // 1 or 2
// if (n < 10L) {
// return 1;
// } else {
// return 2;
// }
// } else { // 3 or 4
// if (n < 1000L) {
// return 3;
// } else {
// return 4;
// }
// }
// } else { // from 5 a 20 (albeit longs can't have more than 18 or 19)
// if (n < 1000000000000L) { // from 5 to 12
// if (n < 100000000L) { // from 5 to 8
// if (n < 1000000L) { // 5 or 6
// if (n < 100000L) {
// return 5;
// } else {
// return 6;
// }
// } else { // 7 u 8
// if (n < 10000000L) {
// return 7;
// } else {
// return 8;
// }
// }
// } else { // from 9 to 12
// if (n < 10000000000L) { // 9 or 10
// if (n < 1000000000L) {
// return 9;
// } else {
// return 10;
// }
// } else { // 11 or 12
// if (n < 100000000000L) {
// return 11;
// } else {
// return 12;
// }
// }
// }
// } else { // from 13 to ... (18 or 20)
// if (n < 10000000000000000L) { // from 13 to 16
// if (n < 100000000000000L) { // 13 or 14
// if (n < 10000000000000L) {
// return 13;
// } else {
// return 14;
// }
// } else { // 15 or 16
// if (n < 1000000000000000L) {
// return 15;
// } else {
// return 16;
// }
// }
// } else { // from 17 to ...¿20?
// if (n < 1000000000000000000L) { // 17 or 18
// if (n < 100000000000000000L) {
// return 17;
// } else {
// return 18;
// }
// } else { // 19? Can it be?
// // 10000000000000000000L is'nt a valid long.
// return 19;
// }
// }
// }
// }
// }
// }
| import android.graphics.Typeface;
import android.view.MotionEvent;
import android.view.View;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.Functions;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect; |
a += textSizeMedium;
if (SatNum > 0)
c.drawText(String.valueOf(DirectionToHome), 0, a, p2);
a += textSizeSmall;
if (SatNum > 0)
c.drawText(context.getString(R.string.GPS_speed), 0, a, p);
a += textSizeMedium;
if (SatNum > 0)
c.drawText(String.valueOf(Speed), 0, a, p2);
a += textSizeSmall;
if (SatNum > 0)
c.drawText(context.getString(R.string.GPS_altitude), 0, a, p);
a += textSizeMedium;
if (SatNum > 0)
c.drawText(String.valueOf(GPSAltitude), 0, a, p2);
a += textSizeSmall;
if (TXRSSI != 0)
c.drawText(context.getString(R.string.TxRSSI), 0, a, p);
a += 5;
if (TXRSSI != 0)
c.drawRect(0, a, (int) (80 * scaledDensity), a + textSizeSmall, p);
if (TXRSSI != 0) | // Path: src/com/ezio/multiwii/helpers/Functions.java
// public class Functions {
//
//
// public static long ConcatInt(int x, int y) {
// return (int) ((x * Math.pow(10, numberOfDigits(y))) + y);
// }
//
// public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int map(int x, int in_min, int in_max, int out_min, int out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int numberOfDigits(long n) {
// // Guessing 4 digit numbers will be more probable.
// // They are set in the first branch.
// if (n < 10000L) { // from 1 to 4
// if (n < 100L) { // 1 or 2
// if (n < 10L) {
// return 1;
// } else {
// return 2;
// }
// } else { // 3 or 4
// if (n < 1000L) {
// return 3;
// } else {
// return 4;
// }
// }
// } else { // from 5 a 20 (albeit longs can't have more than 18 or 19)
// if (n < 1000000000000L) { // from 5 to 12
// if (n < 100000000L) { // from 5 to 8
// if (n < 1000000L) { // 5 or 6
// if (n < 100000L) {
// return 5;
// } else {
// return 6;
// }
// } else { // 7 u 8
// if (n < 10000000L) {
// return 7;
// } else {
// return 8;
// }
// }
// } else { // from 9 to 12
// if (n < 10000000000L) { // 9 or 10
// if (n < 1000000000L) {
// return 9;
// } else {
// return 10;
// }
// } else { // 11 or 12
// if (n < 100000000000L) {
// return 11;
// } else {
// return 12;
// }
// }
// }
// } else { // from 13 to ... (18 or 20)
// if (n < 10000000000000000L) { // from 13 to 16
// if (n < 100000000000000L) { // 13 or 14
// if (n < 10000000000000L) {
// return 13;
// } else {
// return 14;
// }
// } else { // 15 or 16
// if (n < 1000000000000000L) {
// return 15;
// } else {
// return 16;
// }
// }
// } else { // from 17 to ...¿20?
// if (n < 1000000000000000000L) { // 17 or 18
// if (n < 100000000000000000L) {
// return 17;
// } else {
// return 18;
// }
// } else { // 19? Can it be?
// // 10000000000000000000L is'nt a valid long.
// return 19;
// }
// }
// }
// }
// }
// }
// Path: src/com/ezio/multiwii/dashboard/Dashboard2View.java
import android.graphics.Typeface;
import android.view.MotionEvent;
import android.view.View;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.Functions;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
a += textSizeMedium;
if (SatNum > 0)
c.drawText(String.valueOf(DirectionToHome), 0, a, p2);
a += textSizeSmall;
if (SatNum > 0)
c.drawText(context.getString(R.string.GPS_speed), 0, a, p);
a += textSizeMedium;
if (SatNum > 0)
c.drawText(String.valueOf(Speed), 0, a, p2);
a += textSizeSmall;
if (SatNum > 0)
c.drawText(context.getString(R.string.GPS_altitude), 0, a, p);
a += textSizeMedium;
if (SatNum > 0)
c.drawText(String.valueOf(GPSAltitude), 0, a, p2);
a += textSizeSmall;
if (TXRSSI != 0)
c.drawText(context.getString(R.string.TxRSSI), 0, a, p);
a += 5;
if (TXRSSI != 0)
c.drawRect(0, a, (int) (80 * scaledDensity), a + textSizeSmall, p);
if (TXRSSI != 0) | c.drawRect(0, a, (int) Functions.map(TXRSSI, 0, 110, 0, 80 * scaledDensity), a + textSizeSmall, p4); |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/dashboard/HorizonClass.java | // Path: src/com/ezio/multiwii/helpers/Functions.java
// public class Functions {
//
//
// public static long ConcatInt(int x, int y) {
// return (int) ((x * Math.pow(10, numberOfDigits(y))) + y);
// }
//
// public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int map(int x, int in_min, int in_max, int out_min, int out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int numberOfDigits(long n) {
// // Guessing 4 digit numbers will be more probable.
// // They are set in the first branch.
// if (n < 10000L) { // from 1 to 4
// if (n < 100L) { // 1 or 2
// if (n < 10L) {
// return 1;
// } else {
// return 2;
// }
// } else { // 3 or 4
// if (n < 1000L) {
// return 3;
// } else {
// return 4;
// }
// }
// } else { // from 5 a 20 (albeit longs can't have more than 18 or 19)
// if (n < 1000000000000L) { // from 5 to 12
// if (n < 100000000L) { // from 5 to 8
// if (n < 1000000L) { // 5 or 6
// if (n < 100000L) {
// return 5;
// } else {
// return 6;
// }
// } else { // 7 u 8
// if (n < 10000000L) {
// return 7;
// } else {
// return 8;
// }
// }
// } else { // from 9 to 12
// if (n < 10000000000L) { // 9 or 10
// if (n < 1000000000L) {
// return 9;
// } else {
// return 10;
// }
// } else { // 11 or 12
// if (n < 100000000000L) {
// return 11;
// } else {
// return 12;
// }
// }
// }
// } else { // from 13 to ... (18 or 20)
// if (n < 10000000000000000L) { // from 13 to 16
// if (n < 100000000000000L) { // 13 or 14
// if (n < 10000000000000L) {
// return 13;
// } else {
// return 14;
// }
// } else { // 15 or 16
// if (n < 1000000000000000L) {
// return 15;
// } else {
// return 16;
// }
// }
// } else { // from 17 to ...¿20?
// if (n < 1000000000000000000L) { // 17 or 18
// if (n < 100000000000000000L) {
// return 17;
// } else {
// return 18;
// }
// } else { // 19? Can it be?
// // 10000000000000000000L is'nt a valid long.
// return 19;
// }
// }
// }
// }
// }
// }
| import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.Functions; | bmp[3] = BitmapFactory.decodeResource(context.getResources(), R.drawable.ati3);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Color.rgb(50, 50, 50));
mPaint.setStyle(Style.FILL_AND_STROKE);
mPaint.setTextSize(12);
DrawingRec = new Rect();
}
public void Set(float pitch, float roll) {
this.roll = -roll;
this.pitch = pitch;
}
public void Draw(Canvas c, int x, int y) {
// super.onDraw(c);
// c.drawRect(DrawingRec, mPaint);
if (!D) {
matrix.reset();
matrix.postRotate(roll, bmp[0].getWidth() / 2, bmp[0].getHeight() / 2);
matrix.postTranslate(x + (ww - bmp[0].getWidth()) / 2, y + (hh - bmp[0].getHeight()) / 2);
c.drawBitmap(bmp[0], matrix, null);
matrix.reset();
if (pitch > 90)
pitch = 90;
if (pitch < -90)
pitch = -90; | // Path: src/com/ezio/multiwii/helpers/Functions.java
// public class Functions {
//
//
// public static long ConcatInt(int x, int y) {
// return (int) ((x * Math.pow(10, numberOfDigits(y))) + y);
// }
//
// public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int map(int x, int in_min, int in_max, int out_min, int out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int numberOfDigits(long n) {
// // Guessing 4 digit numbers will be more probable.
// // They are set in the first branch.
// if (n < 10000L) { // from 1 to 4
// if (n < 100L) { // 1 or 2
// if (n < 10L) {
// return 1;
// } else {
// return 2;
// }
// } else { // 3 or 4
// if (n < 1000L) {
// return 3;
// } else {
// return 4;
// }
// }
// } else { // from 5 a 20 (albeit longs can't have more than 18 or 19)
// if (n < 1000000000000L) { // from 5 to 12
// if (n < 100000000L) { // from 5 to 8
// if (n < 1000000L) { // 5 or 6
// if (n < 100000L) {
// return 5;
// } else {
// return 6;
// }
// } else { // 7 u 8
// if (n < 10000000L) {
// return 7;
// } else {
// return 8;
// }
// }
// } else { // from 9 to 12
// if (n < 10000000000L) { // 9 or 10
// if (n < 1000000000L) {
// return 9;
// } else {
// return 10;
// }
// } else { // 11 or 12
// if (n < 100000000000L) {
// return 11;
// } else {
// return 12;
// }
// }
// }
// } else { // from 13 to ... (18 or 20)
// if (n < 10000000000000000L) { // from 13 to 16
// if (n < 100000000000000L) { // 13 or 14
// if (n < 10000000000000L) {
// return 13;
// } else {
// return 14;
// }
// } else { // 15 or 16
// if (n < 1000000000000000L) {
// return 15;
// } else {
// return 16;
// }
// }
// } else { // from 17 to ...¿20?
// if (n < 1000000000000000000L) { // 17 or 18
// if (n < 100000000000000000L) {
// return 17;
// } else {
// return 18;
// }
// } else { // 19? Can it be?
// // 10000000000000000000L is'nt a valid long.
// return 19;
// }
// }
// }
// }
// }
// }
// Path: src/com/ezio/multiwii/dashboard/HorizonClass.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.Functions;
bmp[3] = BitmapFactory.decodeResource(context.getResources(), R.drawable.ati3);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Color.rgb(50, 50, 50));
mPaint.setStyle(Style.FILL_AND_STROKE);
mPaint.setTextSize(12);
DrawingRec = new Rect();
}
public void Set(float pitch, float roll) {
this.roll = -roll;
this.pitch = pitch;
}
public void Draw(Canvas c, int x, int y) {
// super.onDraw(c);
// c.drawRect(DrawingRec, mPaint);
if (!D) {
matrix.reset();
matrix.postRotate(roll, bmp[0].getWidth() / 2, bmp[0].getHeight() / 2);
matrix.postTranslate(x + (ww - bmp[0].getWidth()) / 2, y + (hh - bmp[0].getHeight()) / 2);
c.drawBitmap(bmp[0], matrix, null);
matrix.reset();
if (pitch > 90)
pitch = 90;
if (pitch < -90)
pitch = -90; | tmp = Functions.map(pitch, -90, 90, -(bmp[1].getHeight() / 2), bmp[1].getHeight() / 2); |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/graph/GraphView.java | // Path: src/com/ezio/multiwii/graph/GraphViewSeries.java
// static public class GraphViewSeriesStyle {
// public int color = 0xff0077cc;
// public int thickness = 3;
// private ValueDependentColor valueDependentColor;
//
// public GraphViewSeriesStyle() {
// super();
// }
//
// public GraphViewSeriesStyle(int color, int thickness) {
// super();
// this.color = color;
// this.thickness = thickness;
// }
//
// public void setValueDependentColor(ValueDependentColor valueDependentColor) {
// this.valueDependentColor = valueDependentColor;
// }
//
// public ValueDependentColor getValueDependentColor() {
// return valueDependentColor;
// }
// }
| import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.RectF;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.widget.LinearLayout;
import com.ezio.multiwii.graph.GraphViewSeries.GraphViewSeriesStyle; | // rect
paint.setARGB(180, 100, 100, 100);
float legendHeight = (shapeSize+5)*graphSeries.size() +5;
float lLeft = width-legendWidth - 10;
float lTop;
switch (legendAlign) {
case TOP:
lTop = 10;
break;
case MIDDLE:
lTop = height/2 - legendHeight/2;
break;
default:
lTop = height - GraphViewConfig.BORDER - legendHeight -10;
}
float lRight = lLeft+legendWidth;
float lBottom = lTop+legendHeight;
canvas.drawRoundRect(new RectF(lLeft, lTop, lRight, lBottom), 8, 8, paint);
for (int i=0; i<graphSeries.size(); i++) {
paint.setColor(graphSeries.get(i).style.color);
canvas.drawRect(new RectF(lLeft+5, lTop+5+(i*(shapeSize+5)), lLeft+5+shapeSize, lTop+((i+1)*(shapeSize+5))), paint);
if (graphSeries.get(i).description != null) {
paint.setColor(Color.WHITE);
paint.setTextAlign(Align.LEFT);
canvas.drawText(graphSeries.get(i).description, lLeft+5+shapeSize+5, lTop+shapeSize+(i*(shapeSize+5)), paint);
}
}
}
| // Path: src/com/ezio/multiwii/graph/GraphViewSeries.java
// static public class GraphViewSeriesStyle {
// public int color = 0xff0077cc;
// public int thickness = 3;
// private ValueDependentColor valueDependentColor;
//
// public GraphViewSeriesStyle() {
// super();
// }
//
// public GraphViewSeriesStyle(int color, int thickness) {
// super();
// this.color = color;
// this.thickness = thickness;
// }
//
// public void setValueDependentColor(ValueDependentColor valueDependentColor) {
// this.valueDependentColor = valueDependentColor;
// }
//
// public ValueDependentColor getValueDependentColor() {
// return valueDependentColor;
// }
// }
// Path: src/com/ezio/multiwii/graph/GraphView.java
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.RectF;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.widget.LinearLayout;
import com.ezio.multiwii.graph.GraphViewSeries.GraphViewSeriesStyle;
// rect
paint.setARGB(180, 100, 100, 100);
float legendHeight = (shapeSize+5)*graphSeries.size() +5;
float lLeft = width-legendWidth - 10;
float lTop;
switch (legendAlign) {
case TOP:
lTop = 10;
break;
case MIDDLE:
lTop = height/2 - legendHeight/2;
break;
default:
lTop = height - GraphViewConfig.BORDER - legendHeight -10;
}
float lRight = lLeft+legendWidth;
float lBottom = lTop+legendHeight;
canvas.drawRoundRect(new RectF(lLeft, lTop, lRight, lBottom), 8, 8, paint);
for (int i=0; i<graphSeries.size(); i++) {
paint.setColor(graphSeries.get(i).style.color);
canvas.drawRect(new RectF(lLeft+5, lTop+5+(i*(shapeSize+5)), lLeft+5+shapeSize, lTop+((i+1)*(shapeSize+5))), paint);
if (graphSeries.get(i).description != null) {
paint.setColor(Color.WHITE);
paint.setTextAlign(Align.LEFT);
canvas.drawText(graphSeries.get(i).description, lLeft+5+shapeSize+5, lTop+shapeSize+(i*(shapeSize+5)), paint);
}
}
}
| abstract public void drawSeries(Canvas canvas, GraphViewData[] values, float graphwidth, float graphheight, float border, double minX, double minY, double diffX, double diffY, float horstart, GraphViewSeriesStyle style); |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/dashboard/dashboard3/HorizonView.java | // Path: src/com/ezio/multiwii/helpers/LowPassFilter.java
// public class LowPassFilter {
// /*
// * time smoothing constant for low-pass filter 0 ≤ alpha ≤ 1 ; a smaller
// * value basically means more smoothing See: http://en.wikipedia.org/wiki
// * /Low-pass_filter#Discrete-time_realization
// */
// float ALPHA = 0f;
// float lastOutput = 0;
//
// public LowPassFilter(float ALPHA) {
// this.ALPHA = ALPHA;
// }
//
// public float lowPass(float input) {
// if (Math.abs(input - lastOutput) > 170) {
// lastOutput = input;
// return lastOutput;
// }
// lastOutput = lastOutput + ALPHA * (input - lastOutput);
// return lastOutput;
// }
// }
| import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.LowPassFilter; | /* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.dashboard.dashboard3;
public class HorizonView extends View {
boolean D = false;
Paint mPaint;
Rect DrawingRec;
int ww = 0, hh = 0;
float tmp = 0;
Bitmap[] bmp = new Bitmap[4];
Matrix matrix = new Matrix();
Context context;
public float roll = 15;
public float pitch = 20;
| // Path: src/com/ezio/multiwii/helpers/LowPassFilter.java
// public class LowPassFilter {
// /*
// * time smoothing constant for low-pass filter 0 ≤ alpha ≤ 1 ; a smaller
// * value basically means more smoothing See: http://en.wikipedia.org/wiki
// * /Low-pass_filter#Discrete-time_realization
// */
// float ALPHA = 0f;
// float lastOutput = 0;
//
// public LowPassFilter(float ALPHA) {
// this.ALPHA = ALPHA;
// }
//
// public float lowPass(float input) {
// if (Math.abs(input - lastOutput) > 170) {
// lastOutput = input;
// return lastOutput;
// }
// lastOutput = lastOutput + ALPHA * (input - lastOutput);
// return lastOutput;
// }
// }
// Path: src/com/ezio/multiwii/dashboard/dashboard3/HorizonView.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.LowPassFilter;
/* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.dashboard.dashboard3;
public class HorizonView extends View {
boolean D = false;
Paint mPaint;
Rect DrawingRec;
int ww = 0, hh = 0;
float tmp = 0;
Bitmap[] bmp = new Bitmap[4];
Matrix matrix = new Matrix();
Context context;
public float roll = 15;
public float pitch = 20;
| LowPassFilter lowPassFilterRoll = new LowPassFilter(0.2f); |
eziosoft/MultiWii_EZ_GUI | src/com/ezio/multiwii/radio/Stick2View.java | // Path: src/com/ezio/multiwii/helpers/Functions.java
// public class Functions {
//
//
// public static long ConcatInt(int x, int y) {
// return (int) ((x * Math.pow(10, numberOfDigits(y))) + y);
// }
//
// public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int map(int x, int in_min, int in_max, int out_min, int out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int numberOfDigits(long n) {
// // Guessing 4 digit numbers will be more probable.
// // They are set in the first branch.
// if (n < 10000L) { // from 1 to 4
// if (n < 100L) { // 1 or 2
// if (n < 10L) {
// return 1;
// } else {
// return 2;
// }
// } else { // 3 or 4
// if (n < 1000L) {
// return 3;
// } else {
// return 4;
// }
// }
// } else { // from 5 a 20 (albeit longs can't have more than 18 or 19)
// if (n < 1000000000000L) { // from 5 to 12
// if (n < 100000000L) { // from 5 to 8
// if (n < 1000000L) { // 5 or 6
// if (n < 100000L) {
// return 5;
// } else {
// return 6;
// }
// } else { // 7 u 8
// if (n < 10000000L) {
// return 7;
// } else {
// return 8;
// }
// }
// } else { // from 9 to 12
// if (n < 10000000000L) { // 9 or 10
// if (n < 1000000000L) {
// return 9;
// } else {
// return 10;
// }
// } else { // 11 or 12
// if (n < 100000000000L) {
// return 11;
// } else {
// return 12;
// }
// }
// }
// } else { // from 13 to ... (18 or 20)
// if (n < 10000000000000000L) { // from 13 to 16
// if (n < 100000000000000L) { // 13 or 14
// if (n < 10000000000000L) {
// return 13;
// } else {
// return 14;
// }
// } else { // 15 or 16
// if (n < 1000000000000000L) {
// return 15;
// } else {
// return 16;
// }
// }
// } else { // from 17 to ...¿20?
// if (n < 1000000000000000000L) { // 17 or 18
// if (n < 100000000000000000L) {
// return 17;
// } else {
// return 18;
// }
// } else { // 19? Can it be?
// // 10000000000000000000L is'nt a valid long.
// return 19;
// }
// }
// }
// }
// }
// }
| import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.Functions;
import java.text.NumberFormat;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View; | super(context, attrs);
this.context = context;
init();
}
public void init() {
bmp[0] = BitmapFactory.decodeResource(context.getResources(), R.drawable.radio2);
bmp[1] = BitmapFactory.decodeResource(context.getResources(), R.drawable.radio1);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Color.TRANSPARENT);
mPaint.setStyle(Style.FILL_AND_STROKE);
mPaint.setTextSize(12);
DrawingRec = new Rect();
paint2.setAntiAlias(true);
paint2.setColor(Color.YELLOW);
paint2.setStyle(Paint.Style.FILL_AND_STROKE);
paint2.setStrokeWidth(2);
paint2.setTextSize(30);
format = NumberFormat.getNumberInstance();
format.setMinimumFractionDigits(1);
format.setMaximumFractionDigits(1);
format.setGroupingUsed(false);
}
public void SetPosition(float xx, float yy) { | // Path: src/com/ezio/multiwii/helpers/Functions.java
// public class Functions {
//
//
// public static long ConcatInt(int x, int y) {
// return (int) ((x * Math.pow(10, numberOfDigits(y))) + y);
// }
//
// public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int map(int x, int in_min, int in_max, int out_min, int out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// }
//
// public static int numberOfDigits(long n) {
// // Guessing 4 digit numbers will be more probable.
// // They are set in the first branch.
// if (n < 10000L) { // from 1 to 4
// if (n < 100L) { // 1 or 2
// if (n < 10L) {
// return 1;
// } else {
// return 2;
// }
// } else { // 3 or 4
// if (n < 1000L) {
// return 3;
// } else {
// return 4;
// }
// }
// } else { // from 5 a 20 (albeit longs can't have more than 18 or 19)
// if (n < 1000000000000L) { // from 5 to 12
// if (n < 100000000L) { // from 5 to 8
// if (n < 1000000L) { // 5 or 6
// if (n < 100000L) {
// return 5;
// } else {
// return 6;
// }
// } else { // 7 u 8
// if (n < 10000000L) {
// return 7;
// } else {
// return 8;
// }
// }
// } else { // from 9 to 12
// if (n < 10000000000L) { // 9 or 10
// if (n < 1000000000L) {
// return 9;
// } else {
// return 10;
// }
// } else { // 11 or 12
// if (n < 100000000000L) {
// return 11;
// } else {
// return 12;
// }
// }
// }
// } else { // from 13 to ... (18 or 20)
// if (n < 10000000000000000L) { // from 13 to 16
// if (n < 100000000000000L) { // 13 or 14
// if (n < 10000000000000L) {
// return 13;
// } else {
// return 14;
// }
// } else { // 15 or 16
// if (n < 1000000000000000L) {
// return 15;
// } else {
// return 16;
// }
// }
// } else { // from 17 to ...¿20?
// if (n < 1000000000000000000L) { // 17 or 18
// if (n < 100000000000000000L) {
// return 17;
// } else {
// return 18;
// }
// } else { // 19? Can it be?
// // 10000000000000000000L is'nt a valid long.
// return 19;
// }
// }
// }
// }
// }
// }
// Path: src/com/ezio/multiwii/radio/Stick2View.java
import com.ezio.multiwii.R;
import com.ezio.multiwii.helpers.Functions;
import java.text.NumberFormat;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
super(context, attrs);
this.context = context;
init();
}
public void init() {
bmp[0] = BitmapFactory.decodeResource(context.getResources(), R.drawable.radio2);
bmp[1] = BitmapFactory.decodeResource(context.getResources(), R.drawable.radio1);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Color.TRANSPARENT);
mPaint.setStyle(Style.FILL_AND_STROKE);
mPaint.setTextSize(12);
DrawingRec = new Rect();
paint2.setAntiAlias(true);
paint2.setColor(Color.YELLOW);
paint2.setStyle(Paint.Style.FILL_AND_STROKE);
paint2.setStrokeWidth(2);
paint2.setTextSize(30);
format = NumberFormat.getNumberInstance();
format.setMinimumFractionDigits(1);
format.setMaximumFractionDigits(1);
format.setGroupingUsed(false);
}
public void SetPosition(float xx, float yy) { | x = Functions.map(xx - 1500, -500, 500, -bmp[0].getWidth() / 3, bmp[0].getWidth() / 3); |
nukc/ApkMultiChannelPlugin | src/com/github/nukc/plugin/helper/OptionsHelper.java | // Path: src/com/github/nukc/plugin/model/Options.java
// public class Options {
// public List<String> channels = new ArrayList<>(0);
// public String keyStorePath;
// public String keyStorePassword;
// public String keyAlias;
// public String keyPassword;
// public String zipalignPath;
// public String buildType;
// public String signer;
// }
| import com.github.nukc.plugin.model.Options;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List; | package com.github.nukc.plugin.helper;
/**
* Created by Nukc.
*/
public class OptionsHelper {
private static final Logger log = Logger.getInstance(OptionsHelper.class);
private static final String CHANNELS_PROPERTIES = "channels.properties";
private static final String KEY_STORE_PATH = "key.store.path";
private static final String KEY_STORE_PASSWORD = "key.store.password";
private static final String KEY_ALIAS = "key.alias";
private static final String KEY_PASSWORD = "key.password";
private static final String ZIPALIGN_PATH = "zipalign.path";
private static final String BUILD_TYPE = "build.type";
private static final String SIGNER_PATH = "signer.path";
public static final String BUILD_TYPE_UPDATE = "update AndroidManifest.xml";
public static final String BUILD_TYPE_ADD = "add channel file to META-INF";
public static final String BUILD_TYPE_ZIP_COMMENT = "write zip comment";
private static String getPathName(Project project) {
return project.getBasePath() + File.separator + CHANNELS_PROPERTIES;
}
| // Path: src/com/github/nukc/plugin/model/Options.java
// public class Options {
// public List<String> channels = new ArrayList<>(0);
// public String keyStorePath;
// public String keyStorePassword;
// public String keyAlias;
// public String keyPassword;
// public String zipalignPath;
// public String buildType;
// public String signer;
// }
// Path: src/com/github/nukc/plugin/helper/OptionsHelper.java
import com.github.nukc.plugin.model.Options;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
package com.github.nukc.plugin.helper;
/**
* Created by Nukc.
*/
public class OptionsHelper {
private static final Logger log = Logger.getInstance(OptionsHelper.class);
private static final String CHANNELS_PROPERTIES = "channels.properties";
private static final String KEY_STORE_PATH = "key.store.path";
private static final String KEY_STORE_PASSWORD = "key.store.password";
private static final String KEY_ALIAS = "key.alias";
private static final String KEY_PASSWORD = "key.password";
private static final String ZIPALIGN_PATH = "zipalign.path";
private static final String BUILD_TYPE = "build.type";
private static final String SIGNER_PATH = "signer.path";
public static final String BUILD_TYPE_UPDATE = "update AndroidManifest.xml";
public static final String BUILD_TYPE_ADD = "add channel file to META-INF";
public static final String BUILD_TYPE_ZIP_COMMENT = "write zip comment";
private static String getPathName(Project project) {
return project.getBasePath() + File.separator + CHANNELS_PROPERTIES;
}
| public static Options load(Project project) { |
nukc/ApkMultiChannelPlugin | src/com/github/nukc/plugin/axml/decode/BXMLTree.java | // Path: src/com/github/nukc/plugin/axml/utils/Pair.java
// public class Pair<T1,T2> {
// public T1 first;
// public T2 second;
//
// public Pair(T1 t1, T2 t2){
// first = t1;
// second = t2;
// }
//
// public Pair(){}
// }
| import com.github.nukc.plugin.axml.utils.Pair;
import java.io.IOException;
import java.util.Stack; | mRoot = new BNSNode();
mVisitor = new Stack<BXMLNode>();
}
public void print(IVisitor visitor){
mRoot.accept(visitor);
}
public void write(IntWriter writer) throws IOException{
write(mRoot, writer);
}
public void prepare(){
mSize = 0;
prepare(mRoot);
}
private void write(BXMLNode node, IntWriter writer) throws IOException{
node.writeStart(writer);
if(node.hasChild()){
for(BXMLNode child : node.getChildren()){
write(child, writer);
}
}
node.writeEnd(writer);
}
private void prepare(BXMLNode node){
node.prepare(); | // Path: src/com/github/nukc/plugin/axml/utils/Pair.java
// public class Pair<T1,T2> {
// public T1 first;
// public T2 second;
//
// public Pair(T1 t1, T2 t2){
// first = t1;
// second = t2;
// }
//
// public Pair(){}
// }
// Path: src/com/github/nukc/plugin/axml/decode/BXMLTree.java
import com.github.nukc.plugin.axml.utils.Pair;
import java.io.IOException;
import java.util.Stack;
mRoot = new BNSNode();
mVisitor = new Stack<BXMLNode>();
}
public void print(IVisitor visitor){
mRoot.accept(visitor);
}
public void write(IntWriter writer) throws IOException{
write(mRoot, writer);
}
public void prepare(){
mSize = 0;
prepare(mRoot);
}
private void write(BXMLNode node, IntWriter writer) throws IOException{
node.writeStart(writer);
if(node.hasChild()){
for(BXMLNode child : node.getChildren()){
write(child, writer);
}
}
node.writeEnd(writer);
}
private void prepare(BXMLNode node){
node.prepare(); | Pair<Integer,Integer> p = node.getSize(); |
nukc/ApkMultiChannelPlugin | src/com/github/nukc/plugin/helper/CommandHelper.java | // Path: src/com/github/nukc/plugin/model/Options.java
// public class Options {
// public List<String> channels = new ArrayList<>(0);
// public String keyStorePath;
// public String keyStorePassword;
// public String keyAlias;
// public String keyPassword;
// public String zipalignPath;
// public String buildType;
// public String signer;
// }
| import com.github.nukc.plugin.model.Options;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import java.io.IOException;
import java.io.InputStream; | package com.github.nukc.plugin.helper;
/**
* Created by Nukc.
*/
public class CommandHelper {
private static final Logger log = Logger.getInstance(CommandHelper.class);
public static String exec(String command) {
try {
Process process = Runtime.getRuntime().exec(command);
InputStream errorStream = process.getErrorStream();
byte[] buffer = new byte[1024];
int readBytes;
StringBuilder stringBuilder = new StringBuilder();
while ((readBytes = errorStream.read(buffer)) > 0) {
stringBuilder.append(new String(buffer, 0, readBytes));
}
return stringBuilder.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
| // Path: src/com/github/nukc/plugin/model/Options.java
// public class Options {
// public List<String> channels = new ArrayList<>(0);
// public String keyStorePath;
// public String keyStorePassword;
// public String keyAlias;
// public String keyPassword;
// public String zipalignPath;
// public String buildType;
// public String signer;
// }
// Path: src/com/github/nukc/plugin/helper/CommandHelper.java
import com.github.nukc.plugin.model.Options;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import java.io.IOException;
import java.io.InputStream;
package com.github.nukc.plugin.helper;
/**
* Created by Nukc.
*/
public class CommandHelper {
private static final Logger log = Logger.getInstance(CommandHelper.class);
public static String exec(String command) {
try {
Process process = Runtime.getRuntime().exec(command);
InputStream errorStream = process.getErrorStream();
byte[] buffer = new byte[1024];
int readBytes;
StringBuilder stringBuilder = new StringBuilder();
while ((readBytes = errorStream.read(buffer)) > 0) {
stringBuilder.append(new String(buffer, 0, readBytes));
}
return stringBuilder.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
| public static void execSigner(Options options, String apkPath) { |
nukc/ApkMultiChannelPlugin | src/com/github/nukc/plugin/axml/decode/XMLVisitor.java | // Path: src/com/github/nukc/plugin/axml/decode/BTagNode.java
// public static class Attribute {
// public static final int SIZE = 5;
//
// public int mNameSpace;
// public int mName;
// public int mString;
// public int mType;
// public int mValue;
//
// public Attribute(int ns, int name, int type){
// mNameSpace = ns;
// mName = name;
// mType = type<<24;
// }
//
// public void setString(int str){
// if((mType>>24) != TypedValue.TYPE_STRING){
// throw new RuntimeException("Can't set string for none string type");
// }
//
// mString = str;
// mValue = str;
// }
//
// /**
// * TODO type >>> 16 = real type , so how to fix it
// * @param type
// * @param value
// */
// public void setValue(int type, int value){
// mType = type<<24;
// if(type == TypedValue.TYPE_STRING){
// mValue = value;
// mString = value;
// }else{
// mValue = value;
// mString = -1;
// }
//
// }
//
// public Attribute(int[] raw){
// mNameSpace = raw[0];
// mName = raw[1];
// mString = raw[2];
// mType = raw[3];
// mValue = raw[4];
// }
//
// public boolean hasNamespace(){
// return (mNameSpace != -1);
// }
// }
//
// Path: src/com/github/nukc/plugin/axml/utils/TypedValue.java
// public class TypedValue {
//
// public int type;
// public CharSequence string;
// public int data;
// public int assetCookie;
// public int resourceId;
// public int changingConfigurations;
//
// public static final int
// TYPE_NULL =0,
// TYPE_REFERENCE =1,
// TYPE_ATTRIBUTE =2,
// TYPE_STRING =3,
// TYPE_FLOAT =4,
// TYPE_DIMENSION =5,
// TYPE_FRACTION =6,
// TYPE_FIRST_INT =16,
// TYPE_INT_DEC =16,
// TYPE_INT_HEX =17,
// TYPE_INT_BOOLEAN =18,
// TYPE_FIRST_COLOR_INT =28,
// TYPE_INT_COLOR_ARGB8 =28,
// TYPE_INT_COLOR_RGB8 =29,
// TYPE_INT_COLOR_ARGB4 =30,
// TYPE_INT_COLOR_RGB4 =31,
// TYPE_LAST_COLOR_INT =31,
// TYPE_LAST_INT =31;
//
// public static final int
// COMPLEX_UNIT_PX =0,
// COMPLEX_UNIT_DIP =1,
// COMPLEX_UNIT_SP =2,
// COMPLEX_UNIT_PT =3,
// COMPLEX_UNIT_IN =4,
// COMPLEX_UNIT_MM =5,
// COMPLEX_UNIT_SHIFT =0,
// COMPLEX_UNIT_MASK =15,
// COMPLEX_UNIT_FRACTION =0,
// COMPLEX_UNIT_FRACTION_PARENT=1,
// COMPLEX_RADIX_23p0 =0,
// COMPLEX_RADIX_16p7 =1,
// COMPLEX_RADIX_8p15 =2,
// COMPLEX_RADIX_0p23 =3,
// COMPLEX_RADIX_SHIFT =4,
// COMPLEX_RADIX_MASK =3,
// COMPLEX_MANTISSA_SHIFT =8,
// COMPLEX_MANTISSA_MASK =0xFFFFFF;
//
// }
| import com.github.nukc.plugin.axml.decode.BTagNode.Attribute;
import com.github.nukc.plugin.axml.utils.TypedValue; | for(BXMLNode child : node.getChildren()){
child.accept(this);
}
}
}
@Override
public void visit(BTagNode node) {
if(!node.hasChild()){
print("<"+ getStringAt(node.getName()));
printAttribute(node.getAttribute());
print("/>");
}else{
print("<"+ getStringAt(node.getName()));
depth ++;
printAttribute(node.getAttribute());
print(">");
for(BXMLNode child : node.getChildren()){
child.accept(this);
}
depth --;
print("</" + getStringAt(node.getName()) + ">");
}
}
public void visit(BTXTNode node){
print("Text node");
}
| // Path: src/com/github/nukc/plugin/axml/decode/BTagNode.java
// public static class Attribute {
// public static final int SIZE = 5;
//
// public int mNameSpace;
// public int mName;
// public int mString;
// public int mType;
// public int mValue;
//
// public Attribute(int ns, int name, int type){
// mNameSpace = ns;
// mName = name;
// mType = type<<24;
// }
//
// public void setString(int str){
// if((mType>>24) != TypedValue.TYPE_STRING){
// throw new RuntimeException("Can't set string for none string type");
// }
//
// mString = str;
// mValue = str;
// }
//
// /**
// * TODO type >>> 16 = real type , so how to fix it
// * @param type
// * @param value
// */
// public void setValue(int type, int value){
// mType = type<<24;
// if(type == TypedValue.TYPE_STRING){
// mValue = value;
// mString = value;
// }else{
// mValue = value;
// mString = -1;
// }
//
// }
//
// public Attribute(int[] raw){
// mNameSpace = raw[0];
// mName = raw[1];
// mString = raw[2];
// mType = raw[3];
// mValue = raw[4];
// }
//
// public boolean hasNamespace(){
// return (mNameSpace != -1);
// }
// }
//
// Path: src/com/github/nukc/plugin/axml/utils/TypedValue.java
// public class TypedValue {
//
// public int type;
// public CharSequence string;
// public int data;
// public int assetCookie;
// public int resourceId;
// public int changingConfigurations;
//
// public static final int
// TYPE_NULL =0,
// TYPE_REFERENCE =1,
// TYPE_ATTRIBUTE =2,
// TYPE_STRING =3,
// TYPE_FLOAT =4,
// TYPE_DIMENSION =5,
// TYPE_FRACTION =6,
// TYPE_FIRST_INT =16,
// TYPE_INT_DEC =16,
// TYPE_INT_HEX =17,
// TYPE_INT_BOOLEAN =18,
// TYPE_FIRST_COLOR_INT =28,
// TYPE_INT_COLOR_ARGB8 =28,
// TYPE_INT_COLOR_RGB8 =29,
// TYPE_INT_COLOR_ARGB4 =30,
// TYPE_INT_COLOR_RGB4 =31,
// TYPE_LAST_COLOR_INT =31,
// TYPE_LAST_INT =31;
//
// public static final int
// COMPLEX_UNIT_PX =0,
// COMPLEX_UNIT_DIP =1,
// COMPLEX_UNIT_SP =2,
// COMPLEX_UNIT_PT =3,
// COMPLEX_UNIT_IN =4,
// COMPLEX_UNIT_MM =5,
// COMPLEX_UNIT_SHIFT =0,
// COMPLEX_UNIT_MASK =15,
// COMPLEX_UNIT_FRACTION =0,
// COMPLEX_UNIT_FRACTION_PARENT=1,
// COMPLEX_RADIX_23p0 =0,
// COMPLEX_RADIX_16p7 =1,
// COMPLEX_RADIX_8p15 =2,
// COMPLEX_RADIX_0p23 =3,
// COMPLEX_RADIX_SHIFT =4,
// COMPLEX_RADIX_MASK =3,
// COMPLEX_MANTISSA_SHIFT =8,
// COMPLEX_MANTISSA_MASK =0xFFFFFF;
//
// }
// Path: src/com/github/nukc/plugin/axml/decode/XMLVisitor.java
import com.github.nukc.plugin.axml.decode.BTagNode.Attribute;
import com.github.nukc.plugin.axml.utils.TypedValue;
for(BXMLNode child : node.getChildren()){
child.accept(this);
}
}
}
@Override
public void visit(BTagNode node) {
if(!node.hasChild()){
print("<"+ getStringAt(node.getName()));
printAttribute(node.getAttribute());
print("/>");
}else{
print("<"+ getStringAt(node.getName()));
depth ++;
printAttribute(node.getAttribute());
print(">");
for(BXMLNode child : node.getChildren()){
child.accept(this);
}
depth --;
print("</" + getStringAt(node.getName()) + ">");
}
}
public void visit(BTXTNode node){
print("Text node");
}
| private void printAttribute(Attribute[] attrs){ |
nukc/ApkMultiChannelPlugin | src/com/github/nukc/plugin/axml/decode/XMLVisitor.java | // Path: src/com/github/nukc/plugin/axml/decode/BTagNode.java
// public static class Attribute {
// public static final int SIZE = 5;
//
// public int mNameSpace;
// public int mName;
// public int mString;
// public int mType;
// public int mValue;
//
// public Attribute(int ns, int name, int type){
// mNameSpace = ns;
// mName = name;
// mType = type<<24;
// }
//
// public void setString(int str){
// if((mType>>24) != TypedValue.TYPE_STRING){
// throw new RuntimeException("Can't set string for none string type");
// }
//
// mString = str;
// mValue = str;
// }
//
// /**
// * TODO type >>> 16 = real type , so how to fix it
// * @param type
// * @param value
// */
// public void setValue(int type, int value){
// mType = type<<24;
// if(type == TypedValue.TYPE_STRING){
// mValue = value;
// mString = value;
// }else{
// mValue = value;
// mString = -1;
// }
//
// }
//
// public Attribute(int[] raw){
// mNameSpace = raw[0];
// mName = raw[1];
// mString = raw[2];
// mType = raw[3];
// mValue = raw[4];
// }
//
// public boolean hasNamespace(){
// return (mNameSpace != -1);
// }
// }
//
// Path: src/com/github/nukc/plugin/axml/utils/TypedValue.java
// public class TypedValue {
//
// public int type;
// public CharSequence string;
// public int data;
// public int assetCookie;
// public int resourceId;
// public int changingConfigurations;
//
// public static final int
// TYPE_NULL =0,
// TYPE_REFERENCE =1,
// TYPE_ATTRIBUTE =2,
// TYPE_STRING =3,
// TYPE_FLOAT =4,
// TYPE_DIMENSION =5,
// TYPE_FRACTION =6,
// TYPE_FIRST_INT =16,
// TYPE_INT_DEC =16,
// TYPE_INT_HEX =17,
// TYPE_INT_BOOLEAN =18,
// TYPE_FIRST_COLOR_INT =28,
// TYPE_INT_COLOR_ARGB8 =28,
// TYPE_INT_COLOR_RGB8 =29,
// TYPE_INT_COLOR_ARGB4 =30,
// TYPE_INT_COLOR_RGB4 =31,
// TYPE_LAST_COLOR_INT =31,
// TYPE_LAST_INT =31;
//
// public static final int
// COMPLEX_UNIT_PX =0,
// COMPLEX_UNIT_DIP =1,
// COMPLEX_UNIT_SP =2,
// COMPLEX_UNIT_PT =3,
// COMPLEX_UNIT_IN =4,
// COMPLEX_UNIT_MM =5,
// COMPLEX_UNIT_SHIFT =0,
// COMPLEX_UNIT_MASK =15,
// COMPLEX_UNIT_FRACTION =0,
// COMPLEX_UNIT_FRACTION_PARENT=1,
// COMPLEX_RADIX_23p0 =0,
// COMPLEX_RADIX_16p7 =1,
// COMPLEX_RADIX_8p15 =2,
// COMPLEX_RADIX_0p23 =3,
// COMPLEX_RADIX_SHIFT =4,
// COMPLEX_RADIX_MASK =3,
// COMPLEX_MANTISSA_SHIFT =8,
// COMPLEX_MANTISSA_MASK =0xFFFFFF;
//
// }
| import com.github.nukc.plugin.axml.decode.BTagNode.Attribute;
import com.github.nukc.plugin.axml.utils.TypedValue; | String name = getStringAt(attr.mName);
if("id".equals(name)){
System.out.println("hehe");
}
sb.append(name).append('=');
sb.append('\"').append(getAttributeValue(attr)).append('\"');
print(sb.toString());
}
}
final String intent = " ";
final int step = 4;
private void print(String str){
System.out.println(intent.substring(0, depth*step)+str);
}
private String getStringAt(int index){
return mStrings.getStringFor(index);
}
@SuppressWarnings("unused")
private int getResIdAt(int index){
//TODO final res result in resources.arsc
return mRes.getResourceIdAt(index);
}
private String getAttributeValue(Attribute attr) {
int type = attr.mType >> 24;
int data = attr.mValue;
| // Path: src/com/github/nukc/plugin/axml/decode/BTagNode.java
// public static class Attribute {
// public static final int SIZE = 5;
//
// public int mNameSpace;
// public int mName;
// public int mString;
// public int mType;
// public int mValue;
//
// public Attribute(int ns, int name, int type){
// mNameSpace = ns;
// mName = name;
// mType = type<<24;
// }
//
// public void setString(int str){
// if((mType>>24) != TypedValue.TYPE_STRING){
// throw new RuntimeException("Can't set string for none string type");
// }
//
// mString = str;
// mValue = str;
// }
//
// /**
// * TODO type >>> 16 = real type , so how to fix it
// * @param type
// * @param value
// */
// public void setValue(int type, int value){
// mType = type<<24;
// if(type == TypedValue.TYPE_STRING){
// mValue = value;
// mString = value;
// }else{
// mValue = value;
// mString = -1;
// }
//
// }
//
// public Attribute(int[] raw){
// mNameSpace = raw[0];
// mName = raw[1];
// mString = raw[2];
// mType = raw[3];
// mValue = raw[4];
// }
//
// public boolean hasNamespace(){
// return (mNameSpace != -1);
// }
// }
//
// Path: src/com/github/nukc/plugin/axml/utils/TypedValue.java
// public class TypedValue {
//
// public int type;
// public CharSequence string;
// public int data;
// public int assetCookie;
// public int resourceId;
// public int changingConfigurations;
//
// public static final int
// TYPE_NULL =0,
// TYPE_REFERENCE =1,
// TYPE_ATTRIBUTE =2,
// TYPE_STRING =3,
// TYPE_FLOAT =4,
// TYPE_DIMENSION =5,
// TYPE_FRACTION =6,
// TYPE_FIRST_INT =16,
// TYPE_INT_DEC =16,
// TYPE_INT_HEX =17,
// TYPE_INT_BOOLEAN =18,
// TYPE_FIRST_COLOR_INT =28,
// TYPE_INT_COLOR_ARGB8 =28,
// TYPE_INT_COLOR_RGB8 =29,
// TYPE_INT_COLOR_ARGB4 =30,
// TYPE_INT_COLOR_RGB4 =31,
// TYPE_LAST_COLOR_INT =31,
// TYPE_LAST_INT =31;
//
// public static final int
// COMPLEX_UNIT_PX =0,
// COMPLEX_UNIT_DIP =1,
// COMPLEX_UNIT_SP =2,
// COMPLEX_UNIT_PT =3,
// COMPLEX_UNIT_IN =4,
// COMPLEX_UNIT_MM =5,
// COMPLEX_UNIT_SHIFT =0,
// COMPLEX_UNIT_MASK =15,
// COMPLEX_UNIT_FRACTION =0,
// COMPLEX_UNIT_FRACTION_PARENT=1,
// COMPLEX_RADIX_23p0 =0,
// COMPLEX_RADIX_16p7 =1,
// COMPLEX_RADIX_8p15 =2,
// COMPLEX_RADIX_0p23 =3,
// COMPLEX_RADIX_SHIFT =4,
// COMPLEX_RADIX_MASK =3,
// COMPLEX_MANTISSA_SHIFT =8,
// COMPLEX_MANTISSA_MASK =0xFFFFFF;
//
// }
// Path: src/com/github/nukc/plugin/axml/decode/XMLVisitor.java
import com.github.nukc.plugin.axml.decode.BTagNode.Attribute;
import com.github.nukc.plugin.axml.utils.TypedValue;
String name = getStringAt(attr.mName);
if("id".equals(name)){
System.out.println("hehe");
}
sb.append(name).append('=');
sb.append('\"').append(getAttributeValue(attr)).append('\"');
print(sb.toString());
}
}
final String intent = " ";
final int step = 4;
private void print(String str){
System.out.println(intent.substring(0, depth*step)+str);
}
private String getStringAt(int index){
return mStrings.getStringFor(index);
}
@SuppressWarnings("unused")
private int getResIdAt(int index){
//TODO final res result in resources.arsc
return mRes.getResourceIdAt(index);
}
private String getAttributeValue(Attribute attr) {
int type = attr.mType >> 24;
int data = attr.mValue;
| if (type==TypedValue.TYPE_STRING) { |
nukc/ApkMultiChannelPlugin | src/com/github/nukc/plugin/axml/decode/BTagNode.java | // Path: src/com/github/nukc/plugin/axml/utils/TypedValue.java
// public class TypedValue {
//
// public int type;
// public CharSequence string;
// public int data;
// public int assetCookie;
// public int resourceId;
// public int changingConfigurations;
//
// public static final int
// TYPE_NULL =0,
// TYPE_REFERENCE =1,
// TYPE_ATTRIBUTE =2,
// TYPE_STRING =3,
// TYPE_FLOAT =4,
// TYPE_DIMENSION =5,
// TYPE_FRACTION =6,
// TYPE_FIRST_INT =16,
// TYPE_INT_DEC =16,
// TYPE_INT_HEX =17,
// TYPE_INT_BOOLEAN =18,
// TYPE_FIRST_COLOR_INT =28,
// TYPE_INT_COLOR_ARGB8 =28,
// TYPE_INT_COLOR_RGB8 =29,
// TYPE_INT_COLOR_ARGB4 =30,
// TYPE_INT_COLOR_RGB4 =31,
// TYPE_LAST_COLOR_INT =31,
// TYPE_LAST_INT =31;
//
// public static final int
// COMPLEX_UNIT_PX =0,
// COMPLEX_UNIT_DIP =1,
// COMPLEX_UNIT_SP =2,
// COMPLEX_UNIT_PT =3,
// COMPLEX_UNIT_IN =4,
// COMPLEX_UNIT_MM =5,
// COMPLEX_UNIT_SHIFT =0,
// COMPLEX_UNIT_MASK =15,
// COMPLEX_UNIT_FRACTION =0,
// COMPLEX_UNIT_FRACTION_PARENT=1,
// COMPLEX_RADIX_23p0 =0,
// COMPLEX_RADIX_16p7 =1,
// COMPLEX_RADIX_8p15 =2,
// COMPLEX_RADIX_0p23 =3,
// COMPLEX_RADIX_SHIFT =4,
// COMPLEX_RADIX_MASK =3,
// COMPLEX_MANTISSA_SHIFT =8,
// COMPLEX_MANTISSA_MASK =0xFFFFFF;
//
// }
| import com.github.nukc.plugin.axml.utils.TypedValue;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; | public void setAttribute(Attribute attr){
if(mRawAttrs == null){
mRawAttrs = new ArrayList<Attribute>();
}
mRawAttrs.add(attr);
}
/**
*
* @param key
* @return String mapping id
*/
public int getAttrStringForKey(int key){
Attribute[] attrs = getAttribute();
for(Attribute attr : attrs){
if(attr.mName == key){
return attr.mString;
}
}
return -1;
}
public boolean setAttrStringForKey(int key, int string_value){
Attribute[] attrs = getAttribute();
for(Attribute attr : attrs){
if(attr.mName == key){ | // Path: src/com/github/nukc/plugin/axml/utils/TypedValue.java
// public class TypedValue {
//
// public int type;
// public CharSequence string;
// public int data;
// public int assetCookie;
// public int resourceId;
// public int changingConfigurations;
//
// public static final int
// TYPE_NULL =0,
// TYPE_REFERENCE =1,
// TYPE_ATTRIBUTE =2,
// TYPE_STRING =3,
// TYPE_FLOAT =4,
// TYPE_DIMENSION =5,
// TYPE_FRACTION =6,
// TYPE_FIRST_INT =16,
// TYPE_INT_DEC =16,
// TYPE_INT_HEX =17,
// TYPE_INT_BOOLEAN =18,
// TYPE_FIRST_COLOR_INT =28,
// TYPE_INT_COLOR_ARGB8 =28,
// TYPE_INT_COLOR_RGB8 =29,
// TYPE_INT_COLOR_ARGB4 =30,
// TYPE_INT_COLOR_RGB4 =31,
// TYPE_LAST_COLOR_INT =31,
// TYPE_LAST_INT =31;
//
// public static final int
// COMPLEX_UNIT_PX =0,
// COMPLEX_UNIT_DIP =1,
// COMPLEX_UNIT_SP =2,
// COMPLEX_UNIT_PT =3,
// COMPLEX_UNIT_IN =4,
// COMPLEX_UNIT_MM =5,
// COMPLEX_UNIT_SHIFT =0,
// COMPLEX_UNIT_MASK =15,
// COMPLEX_UNIT_FRACTION =0,
// COMPLEX_UNIT_FRACTION_PARENT=1,
// COMPLEX_RADIX_23p0 =0,
// COMPLEX_RADIX_16p7 =1,
// COMPLEX_RADIX_8p15 =2,
// COMPLEX_RADIX_0p23 =3,
// COMPLEX_RADIX_SHIFT =4,
// COMPLEX_RADIX_MASK =3,
// COMPLEX_MANTISSA_SHIFT =8,
// COMPLEX_MANTISSA_MASK =0xFFFFFF;
//
// }
// Path: src/com/github/nukc/plugin/axml/decode/BTagNode.java
import com.github.nukc.plugin.axml.utils.TypedValue;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public void setAttribute(Attribute attr){
if(mRawAttrs == null){
mRawAttrs = new ArrayList<Attribute>();
}
mRawAttrs.add(attr);
}
/**
*
* @param key
* @return String mapping id
*/
public int getAttrStringForKey(int key){
Attribute[] attrs = getAttribute();
for(Attribute attr : attrs){
if(attr.mName == key){
return attr.mString;
}
}
return -1;
}
public boolean setAttrStringForKey(int key, int string_value){
Attribute[] attrs = getAttribute();
for(Attribute attr : attrs){
if(attr.mName == key){ | attr.setValue(TypedValue.TYPE_STRING, string_value); |
jenkinsci/promoted-builds-plugin | src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java | // Path: src/main/java/hudson/plugins/promoted_builds/conditions/ManualCondition.java
// public static final class ManualApproval extends InvisibleAction {
// public String name;
// public Badge badge;
//
// public ManualApproval(String name, List<ParameterValue> values) {
// this.name = name;
// badge = new Badge(values);
// }
// }
| import antlr.ANTLRException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.BulkChange;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.AutoCompletionCandidates;
import hudson.model.ParameterValue;
import hudson.model.BuildableItemWithBuildWrappers;
import hudson.model.Cause;
import hudson.model.Cause.UserCause;
import hudson.model.DependencyGraph;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.model.Failure;
import hudson.model.FreeStyleProject;
import hudson.model.ItemGroup;
import hudson.model.JDK;
import hudson.model.Job;
import hudson.model.Label;
import hudson.model.ParameterDefinition;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.PermalinkProjectAction.Permalink;
import hudson.model.Queue.Item;
import hudson.model.Run;
import hudson.model.Saveable;
import hudson.model.StringParameterValue;
import hudson.model.labels.LabelAtom;
import hudson.model.labels.LabelExpression;
import hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval;
import hudson.security.ACL;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrappers;
import hudson.tasks.Publisher;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import jenkins.model.Jenkins;
import jenkins.util.TimeDuration;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull; | PromotionBadge b = cond.isMet(this, build);
if(b==null)
return null;
badges.add(b);
}
return new Status(this,badges);
}
/**
* @deprecated
* Use {@link #considerPromotion2(AbstractBuild)}
*/
@Deprecated
public boolean considerPromotion(AbstractBuild<?,?> build) throws IOException {
return considerPromotion2(build)!=null;
}
/**
* Checks if the build is promotable, and if so, promote it.
*
* @param build Build to be promoted
* @return
* {@code null} if the build was not promoted, otherwise Future that kicks in when the build is completed.
* @throws IOException
*/
@CheckForNull
public Future<Promotion> considerPromotion2(AbstractBuild<?, ?> build) throws IOException {
LOGGER.fine("Considering the promotion of "+build+" via "+getName()+" without parmeters");
// If the build has manual approvals, use the parameters from it
List<ParameterValue> params = new ArrayList<ParameterValue>(); | // Path: src/main/java/hudson/plugins/promoted_builds/conditions/ManualCondition.java
// public static final class ManualApproval extends InvisibleAction {
// public String name;
// public Badge badge;
//
// public ManualApproval(String name, List<ParameterValue> values) {
// this.name = name;
// badge = new Badge(values);
// }
// }
// Path: src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java
import antlr.ANTLRException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.BulkChange;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.AutoCompletionCandidates;
import hudson.model.ParameterValue;
import hudson.model.BuildableItemWithBuildWrappers;
import hudson.model.Cause;
import hudson.model.Cause.UserCause;
import hudson.model.DependencyGraph;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.model.Failure;
import hudson.model.FreeStyleProject;
import hudson.model.ItemGroup;
import hudson.model.JDK;
import hudson.model.Job;
import hudson.model.Label;
import hudson.model.ParameterDefinition;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.PermalinkProjectAction.Permalink;
import hudson.model.Queue.Item;
import hudson.model.Run;
import hudson.model.Saveable;
import hudson.model.StringParameterValue;
import hudson.model.labels.LabelAtom;
import hudson.model.labels.LabelExpression;
import hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval;
import hudson.security.ACL;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrappers;
import hudson.tasks.Publisher;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import jenkins.model.Jenkins;
import jenkins.util.TimeDuration;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
PromotionBadge b = cond.isMet(this, build);
if(b==null)
return null;
badges.add(b);
}
return new Status(this,badges);
}
/**
* @deprecated
* Use {@link #considerPromotion2(AbstractBuild)}
*/
@Deprecated
public boolean considerPromotion(AbstractBuild<?,?> build) throws IOException {
return considerPromotion2(build)!=null;
}
/**
* Checks if the build is promotable, and if so, promote it.
*
* @param build Build to be promoted
* @return
* {@code null} if the build was not promoted, otherwise Future that kicks in when the build is completed.
* @throws IOException
*/
@CheckForNull
public Future<Promotion> considerPromotion2(AbstractBuild<?, ?> build) throws IOException {
LOGGER.fine("Considering the promotion of "+build+" via "+getName()+" without parmeters");
// If the build has manual approvals, use the parameters from it
List<ParameterValue> params = new ArrayList<ParameterValue>(); | List<ManualApproval> approvals = build.getActions(ManualApproval.class); |
jenkinsci/promoted-builds-plugin | src/main/java/hudson/plugins/promoted_builds/integrations/jobdsl/JobDslPromotionProcess.java | // Path: src/main/java/hudson/plugins/promoted_builds/PromotionCondition.java
// public abstract class PromotionCondition implements ExtensionPoint, Describable<PromotionCondition> {
// /**
// * Checks if the promotion criteria is met.
// *
// * @param build
// * The build for which the promotion is considered.
// * @return
// * non-null if the promotion condition is met. This object is then recorded so that
// * we know how a build was promoted.
// * Null if otherwise, meaning it shouldn't be promoted.
// * @deprecated
// */
// @CheckForNull
// public PromotionBadge isMet(AbstractBuild<?,?> build) {
// return null;
// }
//
// /**
// * Checks if the promotion criteria is met.
// *
// * @param promotionProcess
// * The promotion process being evaluated for qualification
// * @param build
// * The build for which the promotion is considered.
// * @return
// * non-null if the promotion condition is met. This object is then recorded so that
// * we know how a build was promoted.
// * Null if otherwise, meaning it shouldn't be promoted.
// */
// public PromotionBadge isMet(PromotionProcess promotionProcess, AbstractBuild<?,?> build) {
// // just call the deprecated version to support legacy conditions
// return isMet(build);
// }
//
// public PromotionConditionDescriptor getDescriptor() {
// return (PromotionConditionDescriptor)Jenkins.get().getDescriptor(getClass());
// }
//
// /**
// * Returns all the registered {@link PromotionConditionDescriptor}s.
// */
// public static DescriptorExtensionList<PromotionCondition,PromotionConditionDescriptor> all() {
// return Jenkins.get().<PromotionCondition,PromotionConditionDescriptor>getDescriptorList(PromotionCondition.class);
// }
//
// /**
// * Returns a subset of {@link PromotionConditionDescriptor}s that applys to the given project.
// */
// public static List<PromotionConditionDescriptor> getApplicableTriggers(AbstractProject<?,?> p) {
// List<PromotionConditionDescriptor> r = new ArrayList<PromotionConditionDescriptor>();
// for (PromotionConditionDescriptor t : all()) {
// if(t.isApplicable(p))
// r.add(t);
// }
// return r;
// }
// }
| import java.util.ArrayList;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import groovy.util.Node;
import hudson.plugins.promoted_builds.PromotionCondition; | package hudson.plugins.promoted_builds.integrations.jobdsl;
/**
* Special holder for the PromotionProcess generated by the Job DSL Plugin
*
* @author Dennis Schulte
*/
@XStreamAlias("hudson.plugins.promoted_builds.PromotionProcess")
public final class JobDslPromotionProcess {
private String name;
/**
* The icon that represents this promotion process. This is the name of
* the GIF icon that can be found in ${rootURL}/plugin/promoted-builds/icons/16x16/
* and ${rootURL}/plugin/promoted-builds/icons/32x32/, e.g. <code>"star-gold"</code>.
*/
private String icon;
/**
* The label that promotion process can be run on.
*/
private String assignedLabel;
/**
* {@link PromotionCondition}s. All have to be met for a build to be promoted.
*/ | // Path: src/main/java/hudson/plugins/promoted_builds/PromotionCondition.java
// public abstract class PromotionCondition implements ExtensionPoint, Describable<PromotionCondition> {
// /**
// * Checks if the promotion criteria is met.
// *
// * @param build
// * The build for which the promotion is considered.
// * @return
// * non-null if the promotion condition is met. This object is then recorded so that
// * we know how a build was promoted.
// * Null if otherwise, meaning it shouldn't be promoted.
// * @deprecated
// */
// @CheckForNull
// public PromotionBadge isMet(AbstractBuild<?,?> build) {
// return null;
// }
//
// /**
// * Checks if the promotion criteria is met.
// *
// * @param promotionProcess
// * The promotion process being evaluated for qualification
// * @param build
// * The build for which the promotion is considered.
// * @return
// * non-null if the promotion condition is met. This object is then recorded so that
// * we know how a build was promoted.
// * Null if otherwise, meaning it shouldn't be promoted.
// */
// public PromotionBadge isMet(PromotionProcess promotionProcess, AbstractBuild<?,?> build) {
// // just call the deprecated version to support legacy conditions
// return isMet(build);
// }
//
// public PromotionConditionDescriptor getDescriptor() {
// return (PromotionConditionDescriptor)Jenkins.get().getDescriptor(getClass());
// }
//
// /**
// * Returns all the registered {@link PromotionConditionDescriptor}s.
// */
// public static DescriptorExtensionList<PromotionCondition,PromotionConditionDescriptor> all() {
// return Jenkins.get().<PromotionCondition,PromotionConditionDescriptor>getDescriptorList(PromotionCondition.class);
// }
//
// /**
// * Returns a subset of {@link PromotionConditionDescriptor}s that applys to the given project.
// */
// public static List<PromotionConditionDescriptor> getApplicableTriggers(AbstractProject<?,?> p) {
// List<PromotionConditionDescriptor> r = new ArrayList<PromotionConditionDescriptor>();
// for (PromotionConditionDescriptor t : all()) {
// if(t.isApplicable(p))
// r.add(t);
// }
// return r;
// }
// }
// Path: src/main/java/hudson/plugins/promoted_builds/integrations/jobdsl/JobDslPromotionProcess.java
import java.util.ArrayList;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import groovy.util.Node;
import hudson.plugins.promoted_builds.PromotionCondition;
package hudson.plugins.promoted_builds.integrations.jobdsl;
/**
* Special holder for the PromotionProcess generated by the Job DSL Plugin
*
* @author Dennis Schulte
*/
@XStreamAlias("hudson.plugins.promoted_builds.PromotionProcess")
public final class JobDslPromotionProcess {
private String name;
/**
* The icon that represents this promotion process. This is the name of
* the GIF icon that can be found in ${rootURL}/plugin/promoted-builds/icons/16x16/
* and ${rootURL}/plugin/promoted-builds/icons/32x32/, e.g. <code>"star-gold"</code>.
*/
private String icon;
/**
* The label that promotion process can be run on.
*/
private String assignedLabel;
/**
* {@link PromotionCondition}s. All have to be met for a build to be promoted.
*/ | private List<PromotionCondition> conditions = new ArrayList<PromotionCondition>(); |
jenkinsci/promoted-builds-plugin | src/test/java/hudson/plugins/promoted_builds/integrations/jobdsl/JobDslPromotionProcessConverterTest.java | // Path: src/main/java/hudson/plugins/promoted_builds/PromotionCondition.java
// public abstract class PromotionCondition implements ExtensionPoint, Describable<PromotionCondition> {
// /**
// * Checks if the promotion criteria is met.
// *
// * @param build
// * The build for which the promotion is considered.
// * @return
// * non-null if the promotion condition is met. This object is then recorded so that
// * we know how a build was promoted.
// * Null if otherwise, meaning it shouldn't be promoted.
// * @deprecated
// */
// @CheckForNull
// public PromotionBadge isMet(AbstractBuild<?,?> build) {
// return null;
// }
//
// /**
// * Checks if the promotion criteria is met.
// *
// * @param promotionProcess
// * The promotion process being evaluated for qualification
// * @param build
// * The build for which the promotion is considered.
// * @return
// * non-null if the promotion condition is met. This object is then recorded so that
// * we know how a build was promoted.
// * Null if otherwise, meaning it shouldn't be promoted.
// */
// public PromotionBadge isMet(PromotionProcess promotionProcess, AbstractBuild<?,?> build) {
// // just call the deprecated version to support legacy conditions
// return isMet(build);
// }
//
// public PromotionConditionDescriptor getDescriptor() {
// return (PromotionConditionDescriptor)Jenkins.get().getDescriptor(getClass());
// }
//
// /**
// * Returns all the registered {@link PromotionConditionDescriptor}s.
// */
// public static DescriptorExtensionList<PromotionCondition,PromotionConditionDescriptor> all() {
// return Jenkins.get().<PromotionCondition,PromotionConditionDescriptor>getDescriptorList(PromotionCondition.class);
// }
//
// /**
// * Returns a subset of {@link PromotionConditionDescriptor}s that applys to the given project.
// */
// public static List<PromotionConditionDescriptor> getApplicableTriggers(AbstractProject<?,?> p) {
// List<PromotionConditionDescriptor> r = new ArrayList<PromotionConditionDescriptor>();
// for (PromotionConditionDescriptor t : all()) {
// if(t.isApplicable(p))
// r.add(t);
// }
// return r;
// }
// }
| import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import com.thoughtworks.xstream.XStream;
import groovy.util.Node;
import hudson.plugins.promoted_builds.PromotionCondition;
import hudson.plugins.promoted_builds.conditions.SelfPromotionCondition;
import hudson.util.XStream2;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.matchesPattern;
import static org.hamcrest.Matchers.notNullValue; | package hudson.plugins.promoted_builds.integrations.jobdsl;
public class JobDslPromotionProcessConverterTest {
private static final XStream XSTREAM = new XStream2();
@Test
public void testShouldGenerateValidXml() throws Exception {
// Given
JobDslPromotionProcess pp = new JobDslPromotionProcess();
//Conditions | // Path: src/main/java/hudson/plugins/promoted_builds/PromotionCondition.java
// public abstract class PromotionCondition implements ExtensionPoint, Describable<PromotionCondition> {
// /**
// * Checks if the promotion criteria is met.
// *
// * @param build
// * The build for which the promotion is considered.
// * @return
// * non-null if the promotion condition is met. This object is then recorded so that
// * we know how a build was promoted.
// * Null if otherwise, meaning it shouldn't be promoted.
// * @deprecated
// */
// @CheckForNull
// public PromotionBadge isMet(AbstractBuild<?,?> build) {
// return null;
// }
//
// /**
// * Checks if the promotion criteria is met.
// *
// * @param promotionProcess
// * The promotion process being evaluated for qualification
// * @param build
// * The build for which the promotion is considered.
// * @return
// * non-null if the promotion condition is met. This object is then recorded so that
// * we know how a build was promoted.
// * Null if otherwise, meaning it shouldn't be promoted.
// */
// public PromotionBadge isMet(PromotionProcess promotionProcess, AbstractBuild<?,?> build) {
// // just call the deprecated version to support legacy conditions
// return isMet(build);
// }
//
// public PromotionConditionDescriptor getDescriptor() {
// return (PromotionConditionDescriptor)Jenkins.get().getDescriptor(getClass());
// }
//
// /**
// * Returns all the registered {@link PromotionConditionDescriptor}s.
// */
// public static DescriptorExtensionList<PromotionCondition,PromotionConditionDescriptor> all() {
// return Jenkins.get().<PromotionCondition,PromotionConditionDescriptor>getDescriptorList(PromotionCondition.class);
// }
//
// /**
// * Returns a subset of {@link PromotionConditionDescriptor}s that applys to the given project.
// */
// public static List<PromotionConditionDescriptor> getApplicableTriggers(AbstractProject<?,?> p) {
// List<PromotionConditionDescriptor> r = new ArrayList<PromotionConditionDescriptor>();
// for (PromotionConditionDescriptor t : all()) {
// if(t.isApplicable(p))
// r.add(t);
// }
// return r;
// }
// }
// Path: src/test/java/hudson/plugins/promoted_builds/integrations/jobdsl/JobDslPromotionProcessConverterTest.java
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import com.thoughtworks.xstream.XStream;
import groovy.util.Node;
import hudson.plugins.promoted_builds.PromotionCondition;
import hudson.plugins.promoted_builds.conditions.SelfPromotionCondition;
import hudson.util.XStream2;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.matchesPattern;
import static org.hamcrest.Matchers.notNullValue;
package hudson.plugins.promoted_builds.integrations.jobdsl;
public class JobDslPromotionProcessConverterTest {
private static final XStream XSTREAM = new XStream2();
@Test
public void testShouldGenerateValidXml() throws Exception {
// Given
JobDslPromotionProcess pp = new JobDslPromotionProcess();
//Conditions | List<PromotionCondition> conditions = new ArrayList<PromotionCondition>(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.