Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9082/org/jrobin/core Modified Files: ArcDef.java ArcState.java Archive.java ConsolFuns.java DataImporter.java Datasource.java DsDef.java DsTypes.java FetchData.java FetchRequest.java Header.java Robin.java RrdAllocator.java RrdBackend.java RrdBackendFactory.java RrdDb.java RrdDbPool.java RrdDef.java RrdDefTemplate.java RrdDouble.java RrdDoubleArray.java RrdException.java RrdFileBackend.java RrdFileBackendFactory.java RrdInt.java RrdLong.java RrdMemoryBackend.java RrdMemoryBackendFactory.java RrdNioBackend.java RrdNioBackendFactory.java RrdPrimitive.java RrdSafeFileBackend.java RrdSafeFileBackendFactory.java RrdString.java RrdToolReader.java RrdToolkit.java RrdUpdater.java Sample.java Util.java XmlReader.java XmlTemplate.java XmlWriter.java Log Message: Adding the new 1.5.4 code Index: FetchData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchData.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** FetchData.java 23 Jan 2005 20:31:24 -0000 1.18 --- FetchData.java 21 Dec 2006 18:02:41 -0000 1.19 *************** *** 1,540 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) [...1039 lines suppressed...] ! } ! ! private DataProcessor createDataProcessor(String rpnExpression) throws RrdException { ! DataProcessor dataProcessor = new DataProcessor(request.getFetchStart(), request.getFetchEnd()); ! for (String dsName : dsNames) { ! dataProcessor.addDatasource(dsName, this); ! } ! if (rpnExpression != null) { ! dataProcessor.addDatasource(RPN_SOURCE_NAME, rpnExpression); ! try { ! dataProcessor.processData(); ! } ! catch (IOException ioe) { ! // highly unlikely, since all datasources have already calculated values ! throw new RuntimeException("Impossible error: " + ioe); ! } ! } ! return dataProcessor; ! } ! } Index: RrdFileBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFileBackend.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** RrdFileBackend.java 17 Dec 2004 09:27:47 -0000 1.13 --- RrdFileBackend.java 21 Dec 2006 18:02:41 -0000 1.14 *************** *** 1,219 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! import java.io.RandomAccessFile; ! import java.nio.channels.FileLock; ! import java.util.HashSet; ! import java.util.Set; ! ! /** ! * JRobin backend which is used to store RRD data to ordinary files on the disk. This was the ! * default factory before 1.4.0 version<p> ! * <p/> ! * This backend is based on the RandomAccessFile class (java.io.* package). ! */ ! public class RrdFileBackend extends RrdBackend { ! private static final long LOCK_DELAY = 100; // 0.1sec ! ! private static Set openFiles = new HashSet(); ! ! /** read/write file status */ ! protected boolean readOnly; ! /** locking mode */ ! protected int lockMode; ! ! /** radnom access file handle */ ! protected RandomAccessFile file; ! /** file lock */ ! protected FileLock fileLock; ! ! /** ! * Creates RrdFileBackend object for the given file path, backed by RandomAccessFile object. ! * @param path Path to a file ! * @param readOnly True, if file should be open in a read-only mode. False otherwise ! * @param lockMode Locking mode, as described in {@link RrdDb#getLockMode()} ! * @throws IOException Thrown in case of I/O error ! */ ! protected RrdFileBackend(String path, boolean readOnly, int lockMode) throws IOException { ! super(path); ! this.readOnly = readOnly; ! this.lockMode = lockMode; ! file = new RandomAccessFile(path, readOnly ? "r" : "rw"); ! try { ! lockFile(); ! registerWriter(); ! } ! catch(IOException ioe) { ! close(); ! throw ioe; ! } ! } ! ! private void lockFile() throws IOException { ! switch (lockMode) { ! case RrdDb.EXCEPTION_IF_LOCKED: ! fileLock = file.getChannel().tryLock(); ! if (fileLock == null) { ! // could not obtain lock ! throw new IOException("Access denied. " + "File [" + getPath() + "] already locked"); ! } ! break; ! case RrdDb.WAIT_IF_LOCKED: ! while (fileLock == null) { ! fileLock = file.getChannel().tryLock(); ! if (fileLock == null) { ! // could not obtain lock, wait a little, than try again ! try { ! Thread.sleep(LOCK_DELAY); ! } ! catch (InterruptedException e) { ! // NOP ! } ! } ! } ! break; ! case RrdDb.NO_LOCKS: ! break; ! } ! } ! ! private void registerWriter() throws IOException { ! if (!readOnly) { ! String path = getPath(); ! String canonicalPath = getCanonicalPath(path); ! synchronized (openFiles) { ! if (openFiles.contains(canonicalPath)) { ! throw new IOException("File \"" + path + "\" already open for R/W access. " + ! "You cannot open the same file for R/W access twice"); ! } ! else { ! openFiles.add(canonicalPath); ! } ! } ! } ! } ! ! /** ! * Closes the underlying RRD file. ! * ! * @throws IOException Thrown in case of I/O error ! */ ! public void close() throws IOException { ! unregisterWriter(); ! try { ! unlockFile(); ! } ! finally { ! file.close(); ! } ! } ! ! private void unlockFile() throws IOException { ! if (fileLock != null) { ! fileLock.release(); ! } ! } ! ! private void unregisterWriter() throws IOException { ! if (!readOnly) { ! String path = getPath(); ! String canonicalPath = getCanonicalPath(path); ! synchronized (openFiles) { ! openFiles.remove(canonicalPath); ! } ! } ! } ! ! /** ! * Returns canonical path to the file on the disk. ! * ! * @param path File path ! * @return Canonical file path ! * @throws IOException Thrown in case of I/O error ! */ ! public static String getCanonicalPath(String path) throws IOException { ! return Util.getCanonicalPath(path); ! } ! ! /** ! * Returns canonical path to the file on the disk. ! * ! * @return Canonical file path ! * @throws IOException Thrown in case of I/O error ! */ ! public String getCanonicalPath() throws IOException { ! return RrdFileBackend.getCanonicalPath(getPath()); ! } ! ! /** ! * Writes bytes to the underlying RRD file on the disk ! * ! * @param offset Starting file offset ! * @param b Bytes to be written. ! * @throws IOException Thrown in case of I/O error ! */ ! protected void write(long offset, byte[] b) throws IOException { ! file.seek(offset); ! file.write(b); ! } ! ! /** ! * Reads a number of bytes from the RRD file on the disk ! * ! * @param offset Starting file offset ! * @param b Buffer which receives bytes read from the file. ! * @throws IOException Thrown in case of I/O error. ! */ ! protected void read(long offset, byte[] b) throws IOException { ! file.seek(offset); ! if (file.read(b) != b.length) { ! throw new IOException("Not enough bytes available in file " + getPath()); ! } ! } ! ! /** ! * Returns RRD file length. ! * ! * @return File length. ! * @throws IOException Thrown in case of I/O error. ! */ ! public long getLength() throws IOException { ! return file.length(); ! } ! ! /** ! * Sets length of the underlying RRD file. This method is called only once, immediately ! * after a new RRD file gets created. ! * ! * @param length Length of the RRD file ! * @throws IOException Thrown in case of I/O error. ! */ ! protected void setLength(long length) throws IOException { ! file.setLength(length); ! } ! } --- 1,136 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! import java.io.RandomAccessFile; ! ! /** ! * JRobin backend which is used to store RRD data to ordinary files on the disk. This was the ! * default factory before 1.4.0 version<p> ! * <p/> ! * This backend is based on the RandomAccessFile class (java.io.* package). ! */ ! public class RrdFileBackend extends RrdBackend { ! /** ! * read/write file status ! */ ! protected boolean readOnly; ! /** ! * radnom access file handle ! */ ! protected RandomAccessFile file; ! ! /** ! * Creates RrdFileBackend object for the given file path, backed by RandomAccessFile object. ! * ! * @param path Path to a file ! * @param readOnly True, if file should be open in a read-only mode. False otherwise ! * @throws IOException Thrown in case of I/O error ! */ ! protected RrdFileBackend(String path, boolean readOnly) throws IOException { ! super(path); ! this.readOnly = readOnly; ! this.file = new RandomAccessFile(path, readOnly ? "r" : "rw"); ! } ! ! /** ! * Closes the underlying RRD file. ! * ! * @throws IOException Thrown in case of I/O error ! */ ! public void close() throws IOException { ! file.close(); ! } ! ! /** ! * Returns canonical path to the file on the disk. ! * ! * @param path File path ! * @return Canonical file path ! * @throws IOException Thrown in case of I/O error ! */ ! public static String getCanonicalPath(String path) throws IOException { ! return Util.getCanonicalPath(path); ! } ! ! /** ! * Returns canonical path to the file on the disk. ! * ! * @return Canonical file path ! * @throws IOException Thrown in case of I/O error ! */ ! public String getCanonicalPath() throws IOException { ! return RrdFileBackend.getCanonicalPath(getPath()); ! } ! ! /** ! * Writes bytes to the underlying RRD file on the disk ! * ! * @param offset Starting file offset ! * @param b Bytes to be written. ! * @throws IOException Thrown in case of I/O error ! */ ! protected void write(long offset, byte[] b) throws IOException { ! file.seek(offset); ! file.write(b); ! } ! ! /** ! * Reads a number of bytes from the RRD file on the disk ! * ! * @param offset Starting file offset ! * @param b Buffer which receives bytes read from the file. ! * @throws IOException Thrown in case of I/O error. ! */ ! protected void read(long offset, byte[] b) throws IOException { ! file.seek(offset); ! if (file.read(b) != b.length) { ! throw new IOException("Not enough bytes available in file " + getPath()); ! } ! } ! ! /** ! * Returns RRD file length. ! * ! * @return File length. ! * @throws IOException Thrown in case of I/O error. ! */ ! public long getLength() throws IOException { ! return file.length(); ! } ! ! /** ! * Sets length of the underlying RRD file. This method is called only once, immediately ! * after a new RRD file gets created. ! * ! * @param length Length of the RRD file ! * @throws IOException Thrown in case of I/O error. ! */ ! protected void setLength(long length) throws IOException { ! file.setLength(length); ! } ! } Index: RrdFileBackendFactory.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFileBackendFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdFileBackendFactory.java 13 Jul 2004 18:42:24 -0000 1.5 --- RrdFileBackendFactory.java 21 Dec 2006 18:02:41 -0000 1.6 *************** *** 1,69 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! import java.io.File; ! ! /** ! * Factory class which creates actual {@link RrdFileBackend} objects. This was the default ! * backend factory in JRobin before 1.4.0 release. ! */ ! public class RrdFileBackendFactory extends RrdBackendFactory { ! /** factory name, "FILE" */ ! public static final String NAME = "FILE"; ! ! /** ! * Creates RrdFileBackend object for the given file path. ! * @param path File path ! * @param readOnly True, if the file should be accessed in read/only mode. ! * False otherwise. ! * @param lockMode One of the following constants: {@link RrdDb#NO_LOCKS}, ! * {@link RrdDb#EXCEPTION_IF_LOCKED} or {@link RrdDb#WAIT_IF_LOCKED}. ! * @return RrdFileBackend object which handles all I/O operations for the given file path ! * @throws IOException Thrown in case of I/O error. ! */ ! protected RrdBackend open(String path, boolean readOnly, int lockMode) throws IOException { ! return new RrdFileBackend(path, readOnly, lockMode); ! } ! ! /** ! * Method to determine if a file with the given path already exists. ! * @param path File path ! * @return True, if such file exists, false otherwise. ! */ ! protected boolean exists(String path) { ! return new File(path).exists(); ! } ! ! /** ! * Returns the name of this factory. ! * @return Factory name (equals to string "FILE") ! */ ! public String getFactoryName() { ! return NAME; ! } ! } --- 1,71 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Factory class which creates actual {@link RrdFileBackend} objects. This was the default ! * backend factory in JRobin before 1.4.0 release. ! */ ! public class RrdFileBackendFactory extends RrdBackendFactory { ! /** ! * factory name, "FILE" ! */ ! public static final String NAME = "FILE"; ! ! /** ! * Creates RrdFileBackend object for the given file path. ! * ! * @param path File path ! * @param readOnly True, if the file should be accessed in read/only mode. ! * False otherwise. ! * @return RrdFileBackend object which handles all I/O operations for the given file path ! * @throws IOException Thrown in case of I/O error. ! */ ! protected RrdBackend open(String path, boolean readOnly) throws IOException { ! return new RrdFileBackend(path, readOnly); ! } ! ! /** ! * Method to determine if a file with the given path already exists. ! * ! * @param path File path ! * @return True, if such file exists, false otherwise. ! */ ! protected boolean exists(String path) { ! return Util.fileExists(path); ! } ! ! /** ! * Returns the name of this factory. ! * ! * @return Factory name (equals to string "FILE") ! */ ! public String getFactoryName() { ! return NAME; ! } ! } Index: XmlTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/XmlTemplate.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** XmlTemplate.java 11 Jul 2004 22:02:52 -0000 1.9 --- XmlTemplate.java 21 Dec 2006 18:02:42 -0000 1.10 *************** *** 1,325 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import org.w3c.dom.Node; ! import org.w3c.dom.Element; ! import org.xml.sax.InputSource; ! ! import java.io.IOException; ! import java.io.File; ! import java.util.*; ! import java.util.regex.Pattern; ! import java.util.regex.Matcher; ! import java.awt.*; ! ! /** ! * Class used as a base class for various XML template related classes. Class provides ! * methods for XML source parsing and XML tree traversing. XML source may have unlimited ! * number of placeholders (variables) in the format <code>${variable_name}</code>. ! * Methods are provided to specify variable values at runtime. ! * Note that this class has limited functionality: XML source gets parsed, and variable ! * values are collected. You have to extend this class to do something more useful.<p> ! */ ! public abstract class XmlTemplate { ! private static final String PATTERN_STRING = "\\$\\{(\\w+)\\}"; ! private static final Pattern PATTERN = Pattern.compile(PATTERN_STRING); ! ! protected Element root; ! private HashMap valueMap = new HashMap(); ! private HashSet validatedNodes = new HashSet(); ! ! protected XmlTemplate(InputSource xmlSource) throws IOException, RrdException { ! root = Util.Xml.getRootElement(xmlSource); ! } ! ! protected XmlTemplate(String xmlString) throws IOException, RrdException { ! root = Util.Xml.getRootElement(xmlString); ! } ! ! protected XmlTemplate(File xmlFile) throws IOException, RrdException { ! root = Util.Xml.getRootElement(xmlFile); ! } ! ! /** ! * Removes all placeholder-value mappings. ! */ ! public void clearValues() { ! valueMap.clear(); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, String value) { ! valueMap.put(name, value); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, int value) { ! valueMap.put(name, new Integer(value)); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, long value) { ! valueMap.put(name, new Long(value)); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, double value) { ! valueMap.put(name, new Double(value)); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, Color value) { ! valueMap.put(name, "#" + Integer.toHexString(value.getRGB() & 0xFFFFFF)); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, Date value) { ! setVariable(name, Util.getTimestamp(value)); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, GregorianCalendar value) { ! setVariable(name, Util.getTimestamp(value)); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, boolean value) { ! valueMap.put(name, "" + value); ! } ! ! /** ! * Searches the XML template to see if there are variables in there that ! * will need to be set. ! * ! * @return True if variables were detected, false if not. ! */ ! public boolean hasVariables() { ! return PATTERN.matcher( root.toString() ).find(); ! } ! ! /** ! * Returns the list of variables that should be set in this template. ! * ! * @return List of variable names as an array of strings. ! */ ! public String[] getVariables() ! { ! ArrayList list = new ArrayList(); ! Matcher m = PATTERN.matcher( root.toString() ); ! ! while ( m.find() ) ! { ! String var = m.group(1); ! if ( !list.contains( var ) ) ! list.add( var ); ! } ! ! return (String[]) list.toArray( new String[list.size()] ); ! } ! ! protected static Node[] getChildNodes(Node parentNode, String childName) { ! return Util.Xml.getChildNodes(parentNode, childName); ! } ! ! protected static Node[] getChildNodes(Node parentNode) { ! return Util.Xml.getChildNodes(parentNode, null); ! } ! ! protected static Node getFirstChildNode(Node parentNode, String childName) throws RrdException { ! return Util.Xml.getFirstChildNode(parentNode, childName); ! } ! ! protected boolean hasChildNode(Node parentNode, String childName) { ! return Util.Xml.hasChildNode(parentNode, childName); ! } ! ! protected String getChildValue( Node parentNode, String childName ) throws RrdException { ! return getChildValue( parentNode, childName, true ); ! } ! ! protected String getChildValue(Node parentNode, String childName, boolean trim) throws RrdException { ! String value = Util.Xml.getChildValue(parentNode, childName, trim); ! return resolveMappings(value); ! } ! ! protected String getValue( Node parentNode ) { ! return getValue( parentNode, true ); ! } ! ! protected String getValue(Node parentNode, boolean trim ) { ! String value = Util.Xml.getValue(parentNode, trim); ! return resolveMappings(value); ! } ! ! private String resolveMappings(String templateValue) { ! if(templateValue == null) { ! return null; ! } ! Matcher matcher = PATTERN.matcher(templateValue); ! StringBuffer result = new StringBuffer(); ! int lastMatchEnd = 0; ! while(matcher.find()) { ! String var = matcher.group(1); ! if(valueMap.containsKey(var)) { ! // mapping found ! result.append(templateValue.substring(lastMatchEnd, matcher.start())); ! result.append(valueMap.get(var).toString()); ! lastMatchEnd = matcher.end(); ! } ! else { ! // no mapping found - this is illegal ! // throw runtime exception ! throw new IllegalArgumentException( ! "No mapping found for template variable ${" + var + "}"); ! } ! } ! result.append(templateValue.substring(lastMatchEnd)); ! return result.toString(); ! } ! ! protected int getChildValueAsInt(Node parentNode, String childName) throws RrdException { ! String valueStr = getChildValue(parentNode, childName); ! return Integer.parseInt(valueStr); ! } ! ! protected int getValueAsInt(Node parentNode) { ! String valueStr = getValue(parentNode); ! return Integer.parseInt(valueStr); ! } ! ! protected long getChildValueAsLong(Node parentNode, String childName) throws RrdException { ! String valueStr = getChildValue(parentNode, childName); ! return Long.parseLong(valueStr); ! } ! ! protected long getValueAsLong(Node parentNode) { ! String valueStr = getValue(parentNode); ! return Long.parseLong(valueStr); ! } ! ! protected double getChildValueAsDouble(Node parentNode, String childName) throws RrdException { ! String valueStr = getChildValue(parentNode, childName); ! return Util.parseDouble(valueStr); ! } ! ! protected double getValueAsDouble(Node parentNode) { ! String valueStr = getValue(parentNode); ! return Util.parseDouble(valueStr); ! } ! ! protected boolean getChildValueAsBoolean(Node parentNode, String childName) throws RrdException { ! String valueStr = getChildValue(parentNode, childName); ! return Util.parseBoolean(valueStr); ! } ! ! protected boolean getValueAsBoolean(Node parentNode) { ! String valueStr = getValue(parentNode); ! return Util.parseBoolean(valueStr); ! } ! ! protected boolean isEmptyNode(Node node) { ! // comment node or empty text node ! return node.getNodeName().equals("#comment") || ! (node.getNodeName().equals("#text") && node.getNodeValue().trim().length() == 0); ! } ! ! protected void validateTagsOnlyOnce(Node parentNode, String[] allowedChildNames) throws RrdException { ! // validate node only once ! if(validatedNodes.contains(parentNode)) { ! return; ! } ! Node[] childs = getChildNodes(parentNode); ! main: ! for(int i = 0; i < childs.length; i++) { ! String childName = childs[i].getNodeName(); ! for(int j = 0; j < allowedChildNames.length; j++) { ! if(allowedChildNames[j].equals(childName)) { ! // only one such tag is allowed ! allowedChildNames[j] = "<--removed-->"; ! continue main; ! } ! else if(allowedChildNames[j].equals(childName + "*")) { ! // several tags allowed ! continue main; ! } ! } ! if(!isEmptyNode(childs[i])) { ! throw new RrdException("Unexpected tag encountered: <" + childName + ">"); ! } ! } ! // everything is OK ! validatedNodes.add(parentNode); ! } ! } --- 1,348 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import org.w3c.dom.Element; ! import org.w3c.dom.Node; ! import org.xml.sax.InputSource; ! ! import java.awt.*; ! import java.io.File; ! import java.io.IOException; ! import java.util.*; ! import java.util.regex.Matcher; ! import java.util.regex.Pattern; ! ! /** ! * Class used as a base class for various XML template related classes. Class provides ! * methods for XML source parsing and XML tree traversing. XML source may have unlimited ! * number of placeholders (variables) in the format <code>${variable_name}</code>. ! * Methods are provided to specify variable values at runtime. ! * Note that this class has limited functionality: XML source gets parsed, and variable ! * values are collected. You have to extend this class to do something more useful.<p> ! */ ! public abstract class XmlTemplate { ! private static final String PATTERN_STRING = "\\$\\{(\\w+)\\}"; ! private static final Pattern PATTERN = Pattern.compile(PATTERN_STRING); ! ! protected Element root; ! private HashMap<String, Object> valueMap = new HashMap<String, Object>(); ! private HashSet<Node> validatedNodes = new HashSet<Node>(); ! ! protected XmlTemplate(InputSource xmlSource) throws IOException, RrdException { ! root = Util.Xml.getRootElement(xmlSource); ! } ! ! protected XmlTemplate(String xmlString) throws IOException, RrdException { ! root = Util.Xml.getRootElement(xmlString); ! } ! ! protected XmlTemplate(File xmlFile) throws IOException, RrdException { ! root = Util.Xml.getRootElement(xmlFile); ! } ! ! /** ! * Removes all placeholder-value mappings. ! */ ! public void clearValues() { ! valueMap.clear(); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, String value) { ! valueMap.put(name, value); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, int value) { ! valueMap.put(name, value); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, long value) { ! valueMap.put(name, value); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, double value) { ! valueMap.put(name, value); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, Color value) { ! String r = byteToHex(value.getRed()); ! String g = byteToHex(value.getGreen()); ! String b = byteToHex(value.getBlue()); ! String a = byteToHex(value.getAlpha()); ! valueMap.put(name, "#" + r + g + b + a); ! } ! ! private String byteToHex(int i) { ! String s = Integer.toHexString(i); ! while (s.length() < 2) { ! s = "0" + s; ! } ! return s; ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, Date value) { ! setVariable(name, Util.getTimestamp(value)); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, Calendar value) { ! setVariable(name, Util.getTimestamp(value)); ! } ! ! /** ! * Sets value for a single XML template variable. Variable name should be specified ! * without leading '${' and ending '}' placeholder markers. For example, for a placeholder ! * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. ! * ! * @param name variable name ! * @param value value to be set in the XML template ! */ ! public void setVariable(String name, boolean value) { ! valueMap.put(name, "" + value); ! } ! ! /** ! * Searches the XML template to see if there are variables in there that ! * will need to be set. ! * ! * @return True if variables were detected, false if not. ! */ ! public boolean hasVariables() { ! return PATTERN.matcher(root.toString()).find(); ! } ! ! /** ! * Returns the list of variables that should be set in this template. ! * ! * @return List of variable names as an array of strings. ! */ ! public String[] getVariables() { ! ArrayList<String> list = new ArrayList<String>(); ! Matcher m = PATTERN.matcher(root.toString()); ! ! while (m.find()) { ! String var = m.group(1); ! if (!list.contains(var)) { ! list.add(var); ! } ! } ! ! return list.toArray(new String[list.size()]); ! } ! ! protected static Node[] getChildNodes(Node parentNode, String childName) { ! return Util.Xml.getChildNodes(parentNode, childName); ! } ! ! protected static Node[] getChildNodes(Node parentNode) { ! return Util.Xml.getChildNodes(parentNode, null); ! } ! ! protected static Node getFirstChildNode(Node parentNode, String childName) throws RrdException { ! return Util.Xml.getFirstChildNode(parentNode, childName); ! } ! ! protected boolean hasChildNode(Node parentNode, String childName) { ! return Util.Xml.hasChildNode(parentNode, childName); ! } ! ! protected String getChildValue(Node parentNode, String childName) throws RrdException { ! return getChildValue(parentNode, childName, true); ! } ! ! protected String getChildValue(Node parentNode, String childName, boolean trim) throws RrdException { ! String value = Util.Xml.getChildValue(parentNode, childName, trim); ! return resolveMappings(value); ! } ! ! protected String getValue(Node parentNode) { ! return getValue(parentNode, true); ! } ! ! protected String getValue(Node parentNode, boolean trim) { ! String value = Util.Xml.getValue(parentNode, trim); ! return resolveMappings(value); ! } ! ! private String resolveMappings(String templateValue) { ! if (templateValue == null) { ! return null; ! } ! Matcher matcher = PATTERN.matcher(templateValue); ! StringBuffer result = new StringBuffer(); ! int lastMatchEnd = 0; ! while (matcher.find()) { ! String var = matcher.group(1); ! if (valueMap.containsKey(var)) { ! // mapping found ! result.append(templateValue.substring(lastMatchEnd, matcher.start())); ! result.append(valueMap.get(var).toString()); ! lastMatchEnd = matcher.end(); ! } ! else { ! // no mapping found - this is illegal ! // throw runtime exception ! throw new IllegalArgumentException("No mapping found for template variable ${" + var + "}"); ! } ! } ! result.append(templateValue.substring(lastMatchEnd)); ! return result.toString(); ! } ! ! protected int getChildValueAsInt(Node parentNode, String childName) throws RrdException { ! String valueStr = getChildValue(parentNode, childName); ! return Integer.parseInt(valueStr); ! } ! ! protected int getValueAsInt(Node parentNode) { ! String valueStr = getValue(parentNode); ! return Integer.parseInt(valueStr); ! } ! ! protected long getChildValueAsLong(Node parentNode, String childName) throws RrdException { ! String valueStr = getChildValue(parentNode, childName); ! return Long.parseLong(valueStr); ! } ! ! protected long getValueAsLong(Node parentNode) { ! String valueStr = getValue(parentNode); ! return Long.parseLong(valueStr); ! } ! ! protected double getChildValueAsDouble(Node parentNode, String childName) throws RrdException { ! String valueStr = getChildValue(parentNode, childName); ! return Util.parseDouble(valueStr); ! } ! ! protected double getValueAsDouble(Node parentNode) { ! String valueStr = getValue(parentNode); ! return Util.parseDouble(valueStr); ! } ! ! protected boolean getChildValueAsBoolean(Node parentNode, String childName) throws RrdException { ! String valueStr = getChildValue(parentNode, childName); ! return Util.parseBoolean(valueStr); ! } ! ! protected boolean getValueAsBoolean(Node parentNode) { ! String valueStr = getValue(parentNode); ! return Util.parseBoolean(valueStr); ! } ! ! protected Paint getValueAsColor(Node parentNode) throws RrdException { ! String rgbStr = getValue(parentNode); ! return Util.parseColor(rgbStr); ! } ! ! protected boolean isEmptyNode(Node node) { ! // comment node or empty text node ! return node.getNodeName().equals("#comment") || ! (node.getNodeName().equals("#text") && node.getNodeValue().trim().length() == 0); ! } ! ! protected void validateTagsOnlyOnce(Node parentNode, String[] allowedChildNames) throws RrdException { ! // validate node only once ! if (validatedNodes.contains(parentNode)) { ! return; ! } ! Node[] childs = getChildNodes(parentNode); ! main: ! for (Node child : childs) { ! String childName = child.getNodeName(); ! for (int j = 0; j < allowedChildNames.length; j++) { ! if (allowedChildNames[j].equals(childName)) { ! // only one such tag is allowed ! allowedChildNames[j] = "<--removed-->"; ! continue main; ! } ! else if (allowedChildNames[j].equals(childName + "*")) { ! // several tags allowed ! continue main; ! } ! } ! if (!isEmptyNode(child)) { ! throw new RrdException("Unexpected tag encountered: <" + childName + ">"); ! } ! } ! // everything is OK ! validatedNodes.add(parentNode); ! } ! } Index: RrdDouble.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDouble.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RrdDouble.java 9 Nov 2004 11:36:53 -0000 1.11 --- RrdDouble.java 21 Dec 2006 18:02:41 -0000 1.12 *************** *** 1,57 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! class RrdDouble extends RrdPrimitive { ! private double cache; ! private boolean cached = false; ! ! RrdDouble(RrdUpdater updater, boolean isConstant) throws IOException { ! super(updater, RrdDouble.RRD_DOUBLE, isConstant); ! } ! ! RrdDouble(RrdUpdater updater) throws IOException { ! super(updater, RrdDouble.RRD_DOUBLE, false); ! } ! ! void set(double value) throws IOException { ! if(!isCachingAllowed()) { ! writeDouble(value); ! } ! // caching allowed ! else if(!cached || !Util.equal(cache, value)) { ! // update cache ! writeDouble(cache = value); ! cached = true; ! } ! } ! ! double get() throws IOException { ! return cached? cache: readDouble(); ! } ! } --- 1,57 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! class RrdDouble extends RrdPrimitive { ! private double cache; ! private boolean cached = false; ! ! RrdDouble(RrdUpdater updater, boolean isConstant) throws IOException { ! super(updater, RrdDouble.RRD_DOUBLE, isConstant); ! } ! ! RrdDouble(RrdUpdater updater) throws IOException { ! super(updater, RrdDouble.RRD_DOUBLE, false); ! } ! ! void set(double value) throws IOException { ! if (!isCachingAllowed()) { ! writeDouble(value); ! } ! // caching allowed ! else if (!cached || !Util.equal(cache, value)) { ! // update cache ! writeDouble(cache = value); ! cached = true; ! } ! } ! ! double get() throws IOException { ! return cached ? cache : readDouble(); ! } ! } Index: RrdUpdater.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdUpdater.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdUpdater.java 20 May 2004 10:29:33 -0000 1.4 --- RrdUpdater.java 21 Dec 2006 18:02:42 -0000 1.5 *************** *** 1,34 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! interface RrdUpdater { ! public RrdBackend getRrdBackend(); ! public void copyStateTo(RrdUpdater updater) throws IOException, RrdException; ! public RrdAllocator getRrdAllocator(); ! } --- 1,36 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! interface RrdUpdater { ! public RrdBackend getRrdBackend(); ! ! public void copyStateTo(RrdUpdater updater) throws IOException, RrdException; ! ! public RrdAllocator getRrdAllocator(); ! } Index: RrdString.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdString.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RrdString.java 9 Nov 2004 11:36:53 -0000 1.11 --- RrdString.java 21 Dec 2006 18:02:41 -0000 1.12 *************** *** 1,55 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! class RrdString extends RrdPrimitive { ! private String cache; ! ! RrdString(RrdUpdater updater, boolean isConstant) throws IOException { ! super(updater, RrdPrimitive.RRD_STRING, isConstant); ! } ! ! RrdString(RrdUpdater updater) throws IOException { ! this(updater, false); ! } ! ! void set(String value) throws IOException { ! if(!isCachingAllowed()) { ! writeString(value); ! } ! // caching allowed ! else if(cache == null || !cache.equals(value)) { ! // update cache ! writeString(cache = value); ! } ! } ! ! String get() throws IOException { ! return (cache != null)? cache: readString(); ! } ! } --- 1,55 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! class RrdString extends RrdPrimitive { ! private String cache; ! ! RrdString(RrdUpdater updater, boolean isConstant) throws IOException { ! super(updater, RrdPrimitive.RRD_STRING, isConstant); ! } ! ! RrdString(RrdUpdater updater) throws IOException { ! this(updater, false); ! } ! ! void set(String value) throws IOException { ! if (!isCachingAllowed()) { ! writeString(value); ! } ! // caching allowed ! else if (cache == null || !cache.equals(value)) { ! // update cache ! writeString(cache = value); ! } ! } ! ! String get() throws IOException { ! return (cache != null) ? cache : readString(); ! } ! } Index: XmlWriter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/XmlWriter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** XmlWriter.java 8 Mar 2004 13:14:39 -0000 1.6 --- XmlWriter.java 21 Dec 2006 18:02:42 -0000 1.7 *************** *** 1,197 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library 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 Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.OutputStream; ! import java.io.PrintWriter; ! import java.io.File; ! import java.util.Stack; ! import java.awt.*; ! ! /** ! * Extremely simple utility class used to create XML documents. ! */ ! public class XmlWriter { ! static final String INDENT_STR = " "; ! ! private PrintWriter writer; ! private StringBuffer indent = new StringBuffer(""); ! private Stack openTags = new Stack(); ! ! /** ! * Creates XmlWriter with the specified output stream to send XML code to. ! * @param stream Output stream which receives XML code ! */ ! public XmlWriter(OutputStream stream) { ! writer = new PrintWriter(stream); ! } ! ! /** ! * Opens XML tag ! * @param tag XML tag name ! */ ! public void startTag(String tag) { ! writer.println(indent + "<" + tag + ">"); ! openTags.push(tag); ! indent.append(INDENT_STR); ! } ! ! /** ! * Closes the corresponding XML tag ! */ ! public void closeTag() { ! String tag = (String) openTags.pop(); ! indent.setLength(indent.length() - INDENT_STR.length()); ! writer.println(indent + "</" + tag + ">"); ! } ! ! /** ! * Writes <tag>value</tag> to output stream ! * @param tag XML tag name ! * @param value value to be placed between <code><tag></code> and <code></tag></code> ! */ ! public void writeTag(String tag, Object value) { ! if(value != null) { ! writer.println(indent + "<" + tag + ">" + ! escape(value.toString()) + "</" + tag + ">"); ! } ! else { ! writer.println(indent + "<" + tag + "></" + tag + ">"); ! } ! } ! ! /** ! * Writes <tag>value</tag> to output stream ! * @param tag XML tag name ! * @param value value to be placed between <code><tag></code> and <code></tag></code> ! */ ! public void writeTag(String tag, int value) { ! writeTag(tag, "" + value); ! } ! ! /** ! * Writes <tag>value</tag> to output stream ! * @param tag XML tag name ! * @param value value to be placed between <code><tag></code> and <code></tag></code> ! */ ! public void writeTag(String tag, long value) { ! writeTag(tag, "" + value); ! } ! ! /** ! * Writes <tag>value</tag> to output stream ! * @param tag XML tag name ! * @param value value to be placed between <code><tag></code> and <code></tag></code> ! */ ! public void writeTag(String tag, double value, String nanString) { ! writeTag(tag, Util.formatDouble(value, nanString, true)); ! } ! ! /** ! * Writes <tag>value</tag> to output stream ! * @param tag XML tag name ! * @param value value to be placed between <code><tag></code> and <code></tag></code> ! */ ! public void writeTag(String tag, double value) { ! writeTag(tag, Util.formatDouble(value, true)); ! } ! ! /** ! * Writes <tag>value</tag> to output stream ! * @param tag XML ta... [truncated message content] |