You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2003/10/20 19:03:21 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ac FileIPRange.java IPRange.java
andreas 2003/10/20 10:03:21
Modified: src/java/org/apache/lenya/cms/ac FileIPRange.java
IPRange.java
Log:
saving & loading IP ranges
Revision Changes Path
1.4 +153 -139 cocoon-lenya/src/java/org/apache/lenya/cms/ac/FileIPRange.java
Index: FileIPRange.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/FileIPRange.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FileIPRange.java 12 Aug 2003 15:14:15 -0000 1.3
+++ FileIPRange.java 20 Oct 2003 17:03:20 -0000 1.4
@@ -1,57 +1,43 @@
/*
-<License>
-
- ============================================================================
- The Apache Software License, Version 1.1
- ============================================================================
-
- Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modifica-
- tion, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. 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.
-
- 3. The end-user documentation included with the redistribution, if any, must
- include the following acknowledgment: "This product includes software
- developed by the Apache Software Foundation (http://www.apache.org/)."
- Alternately, this acknowledgment may appear in the software itself, if
- and wherever such third-party acknowledgments normally appear.
-
- 4. The names "Apache Lenya" and "Apache Software Foundation" must not be
- used to endorse or promote products derived from this software without
- prior written permission. For written permission, please contact
- apache@apache.org.
-
- 5. Products derived from this software may not be called "Apache", nor may
- "Apache" appear in their name, without prior written permission of the
- Apache Software Foundation.
-
- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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
- APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
- DING, 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.
-
- This software consists of voluntary contributions made by many individuals
- on behalf of the Apache Software Foundation and was originally created by
- Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
- ware Foundation, please see <http://www.apache.org/>.
-
- Lenya includes software developed by the Apache Software Foundation, W3C,
- DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
-</License>
-*/
+ * <License>
+ *
+ * ============================================================================ The Apache Software
+ * License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica- tion, are permitted
+ * provided that the following conditions are met: 1. Redistributions of source code must retain
+ * the above copyright notice, this list of conditions and the following disclaimer. 2.
+ * 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. 3. The end-user documentation included with the redistribution, if any,
+ * must include the following acknowledgment: "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4.
+ * The names "Apache Lenya" and "Apache Software Foundation" must not be used to endorse or promote
+ * products derived from this software without prior written permission. For written permission,
+ * please contact apache@apache.org. 5. Products derived from this software may not be called
+ * "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache
+ * Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, 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.
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation and was originally created by Michael Wechner <mi...@apache.org> .
+ * For more information on the Apache Soft- ware Foundation, please see <http://www.apache.org/> .
+ *
+ * Lenya includes software developed by the Apache Software Foundation, W3C, DOM4J Project,
+ * BitfluxEditor, Xopus, and WebSHPINX. </License>
+ */
package org.apache.lenya.cms.ac;
import java.io.File;
@@ -70,89 +56,117 @@
*/
public class FileIPRange extends IPRange {
- /**
- * Main method.
- * @param args The command-line arguments.
- * @deprecated This should bemoved to a JUnit test.
- */
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println("Usage: network, netmask, ip (e.g. 192.168.0.64 255.255.255.240 192.168.0.70)");
- return;
- }
- IPRange ipr = new FileIPRange();
- try {
- ipr.setNetworkAddress(args[0]);
- ipr.setSubnetMask(args[1]);
- if (ipr.contains(new Machine(args[2]))) {
- System.out.println("true");
- } else {
- System.out.println("false");
- }
- } catch(Exception e) {
- System.err.println(e);
- }
- }
-
- /**
- * Ctor.
- */
- public FileIPRange() {
- }
-
- /**
- * Ctor.
- * @param configurationDirectory The configuration directory.
- * @param id The IP range ID.
- */
- public FileIPRange(File configurationDirectory, String id) {
- super(id);
- setConfigurationDirectory(configurationDirectory);
- }
-
- /**
- * @see org.apache.lenya.cms.ac.IPRange#save()
- */
- public void save() throws AccessControlException {
- DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer();
- Configuration config = createConfiguration();
-
- try {
- serializer.serializeToFile(getFile(), config);
- } catch (Exception e) {
- throw new AccessControlException(e);
- }
- }
-
- /**
- * Returns the configuration file.
- * @return A file object.
- */
- protected File getFile() {
- File xmlPath = getConfigurationDirectory();
- File xmlFile = new File(xmlPath, getId() + IPRangeManager.SUFFIX);
- return xmlFile;
- }
-
- /**
- * @see org.apache.lenya.cms.ac.Item#configure(org.apache.avalon.framework.configuration.Configuration)
- */
- public void configure(Configuration config) throws ConfigurationException {
- new ItemConfiguration().configure(this, config);
-
- }
-
- public static final String IP_RANGE = "ip-range";
-
- /**
- * Create a configuration from the current user details. Can
- * be used for saving.
- *
- * @return a <code>Configuration</code>
- */
- protected Configuration createConfiguration() {
- DefaultConfiguration config = new DefaultConfiguration(IP_RANGE);
- new ItemConfiguration().save(this, config);
- return config;
- }
+ /**
+ * Main method.
+ *
+ * @param args
+ * The command-line arguments.
+ * @deprecated This should bemoved to a JUnit test.
+ */
+ public static void main(String[] args) {
+ if (args.length == 0) {
+ System.out.println(
+ "Usage: network, netmask, ip (e.g. 192.168.0.64 255.255.255.240 192.168.0.70)");
+ return;
+ }
+ IPRange ipr = new FileIPRange();
+ try {
+ ipr.setNetworkAddress(args[0]);
+ ipr.setSubnetMask(args[1]);
+ if (ipr.contains(new Machine(args[2]))) {
+ System.out.println("true");
+ } else {
+ System.out.println("false");
+ }
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+ }
+
+ /**
+ * Ctor.
+ */
+ public FileIPRange() {
+ }
+
+ /**
+ * Ctor.
+ *
+ * @param configurationDirectory
+ * The configuration directory.
+ * @param id
+ * The IP range ID.
+ */
+ public FileIPRange(File configurationDirectory, String id) {
+ super(id);
+ setConfigurationDirectory(configurationDirectory);
+ }
+
+ /**
+ * @see org.apache.lenya.cms.ac.IPRange#save()
+ */
+ public void save() throws AccessControlException {
+ DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer();
+ Configuration config = createConfiguration();
+
+ try {
+ serializer.serializeToFile(getFile(), config);
+ } catch (Exception e) {
+ throw new AccessControlException(e);
+ }
+ }
+
+ /**
+ * Returns the configuration file.
+ *
+ * @return A file object.
+ */
+ protected File getFile() {
+ File xmlPath = getConfigurationDirectory();
+ File xmlFile = new File(xmlPath, getId() + IPRangeManager.SUFFIX);
+ return xmlFile;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.ac.Item#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void configure(Configuration config) throws ConfigurationException {
+ new ItemConfiguration().configure(this, config);
+
+ String networkAddress = config.getChild(ELEMENT_NETWORK_ADDRESS).getValue();
+ String subnetMask = config.getChild(ELEMENT_SUBNET_MASK).getValue();
+
+ try {
+ setNetworkAddress(networkAddress);
+ setSubnetMask(subnetMask);
+ } catch (AccessControlException e) {
+ throw new ConfigurationException("Configuring IP range [" + getId() + "] failed: ", e);
+ }
+
+ }
+
+ public static final String IP_RANGE = "ip-range";
+ public static final String ELEMENT_NETWORK_ADDRESS = "network-address";
+ public static final String ELEMENT_SUBNET_MASK = "subnet-mask";
+
+ /**
+ * Create a configuration from the current user details. Can be used for saving.
+ *
+ * @return a <code>Configuration</code>
+ */
+ protected Configuration createConfiguration() {
+ DefaultConfiguration config = new DefaultConfiguration(IP_RANGE);
+ new ItemConfiguration().save(this, config);
+
+ DefaultConfiguration networkAddressConfig =
+ new DefaultConfiguration(ELEMENT_NETWORK_ADDRESS);
+ networkAddressConfig.setValue(getNetworkAddress().getHostAddress());
+ config.addChild(networkAddressConfig);
+
+ DefaultConfiguration subnetMaskConfig = new DefaultConfiguration(ELEMENT_SUBNET_MASK);
+ subnetMaskConfig.setValue(getSubnetMask().getHostAddress());
+ config.addChild(subnetMaskConfig);
+
+ return config;
+ }
}
1.6 +5 -1 cocoon-lenya/src/java/org/apache/lenya/cms/ac/IPRange.java
Index: IPRange.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/IPRange.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- IPRange.java 4 Aug 2003 13:48:03 -0000 1.5
+++ IPRange.java 20 Oct 2003 17:03:20 -0000 1.6
@@ -59,6 +59,7 @@
import java.net.UnknownHostException;
import org.apache.lenya.net.InetAddressUtil;
+import org.apache.log4j.Category;
/**
* A range of IP addresses, expressed by a network address and a
@@ -69,6 +70,8 @@
* @version $Id$
*/
public abstract class IPRange extends AbstractGroupable {
+
+ private static final Category log = Category.getInstance(IPRange.class);
/**
* Ctor.
@@ -219,6 +222,7 @@
* @return A boolean value.
*/
public boolean contains(Machine machine) {
+ log.debug("Checking IP range: [" + getId() + "]");
return InetAddressUtil.contains(networkAddress, subnetMask, machine.getAddress());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org