diff options
Diffstat (limited to 'plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst')
11 files changed, 0 insertions, 802 deletions
diff --git a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/IMemento.java b/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/IMemento.java deleted file mode 100644 index a0e8d8ea7..000000000 --- a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/IMemento.java +++ /dev/null @@ -1,74 +0,0 @@ -/********************************************************************** - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - **********************************************************************/ -package org.eclipse.wst.server.preview.internal; -/** - * Interface to a memento used for saving the important state of an object - * in a form that can be persisted in the file system. - * <p> - * Mementos were designed with the following requirements in mind: - * <ol> - * <li>Certain objects need to be saved and restored across platform sessions. - * </li> - * <li>When an object is restored, an appropriate class for an object might not - * be available. It must be possible to skip an object in this case.</li> - * <li>When an object is restored, the appropriate class for the object may be - * different from the one when the object was originally saved. If so, the - * new class should still be able to read the old form of the data.</li> - * </ol> - * </p> - * <p> - * Mementos meet these requirements by providing support for storing a - * mapping of arbitrary string keys to primitive values, and by allowing - * mementos to have other mementos as children (arranged into a tree). - * A robust external storage format based on XML is used. - * </p><p> - * The key for an attribute may be any alpha numeric value. However, the - * value of <code>TAG_ID</code> is reserved for internal use. - * </p><p> - * This interface is not intended to be implemented by clients. - * </p> - */ -public interface IMemento { - - /** - * Returns the first child with the given type id. - * - * @param type the type id - * @return the first child with the given type - */ - public IMemento getChild(String type); - - /** - * Returns all children with the given type id. - * - * @param type the type id - * @return the list of children with the given type - */ - public IMemento[] getChildren(String type); - - /** - * Returns the integer value of the given key. - * - * @param key the key - * @return the value, or <code>null</code> if the key was not found or was found - * but was not an integer - */ - public Integer getInteger(String key); - - /** - * Returns the string value of the given key. - * - * @param key the key - * @return the value, or <code>null</code> if the key was not found or was found - * but was not an integer - */ - public String getString(String key); -}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Messages.java b/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Messages.java deleted file mode 100644 index d0d3b8a5e..000000000 --- a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Messages.java +++ /dev/null @@ -1,41 +0,0 @@ -/********************************************************************** - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - **********************************************************************/ -package org.eclipse.wst.server.preview.internal; - -import org.eclipse.osgi.util.NLS; -/** - * Translated messages. - */ -public class Messages extends NLS { - public static String errorLocation; - public static String errorJRE; - public static String classpathContainerDescription; - public static String classpathContainer; - public static String classpathContainerUnbound; - - public static String copyingTask; - public static String deletingTask; - public static String errorCopyingFile; - public static String errorCreatingZipFile; - public static String errorDelete; - public static String errorRename; - public static String errorReading; - public static String updateClasspathContainers; - public static String errorNoRuntime; - public static String errorFacet; - public static String errorDeleting; - public static String errorNotADirectory; - public static String errorMkdir; - - static { - NLS.initializeMessages(PreviewServerPlugin.PLUGIN_ID + ".internal.Messages", Messages.class); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Messages.properties b/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Messages.properties deleted file mode 100644 index 185c62195..000000000 --- a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Messages.properties +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################### -# Copyright (c) 2007 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### - -classpathContainerDescription=Server Library -classpathContainer={0} [{1}] -classpathContainerUnbound={0} [{1}] (unbound) - -errorLocation=Invalid location. -errorJRE=Invalid JRE. - -copyingTask=Copying from {0} to {1} -deletingTask=Deleting {0} -errorCopyingFile=Error copying file {0}: {1} -errorCreatingZipFile=Error creating zip file {0}: {1} -errorDelete=Could not delete previous copy, which may be locked by another process. -errorRename=Could not replace with temp file {0}. -errorReading=Error reading file {0} -errorNoRuntime=Cannot verify facets because there is no runtime associated with the server. -errorFacet=Project facet {0} version {1} is not supported. -errorDeleting=Could not delete {0}. May be locked by another process. -errorNotADirectory=Could not delete {0} since it is not a directory. -errorMkdir=Could not create directory {0}. - -updateClasspathContainers=Updating classpath container for {0}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Module.java b/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Module.java deleted file mode 100644 index a45784fa6..000000000 --- a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Module.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.server.preview.internal; -/** - * - */ -public class Module { - private String name; - private boolean isStatic; - private String context; - private String projectPath; - - public Module(String name, boolean isStatic, String context, String projectPath) { - this.name = name; - this.isStatic = isStatic; - this.context = context; - this.projectPath = projectPath; - } - - public String getName() { - return name; - } - - public boolean isStaticWeb() { - return isStatic; - } - - public String getContext() { - return context; - } - - public String getPath() { - return projectPath; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/PreviewApplication.java b/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/PreviewApplication.java deleted file mode 100644 index 2bfcf6cde..000000000 --- a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/PreviewApplication.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.server.preview.internal; - -import org.eclipse.equinox.app.IApplication; -import org.eclipse.equinox.app.IApplicationContext; - -public class PreviewApplication implements IApplication { - protected PreviewStarter starter; - - public Object start(IApplicationContext appContext) throws Exception { - starter = new PreviewStarter(null); - starter.run(); - return EXIT_OK; - } - - public void stop() { - starter.stop(); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/PreviewServerPlugin.java b/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/PreviewServerPlugin.java deleted file mode 100644 index 5e9d2bdee..000000000 --- a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/PreviewServerPlugin.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.server.preview.internal; - -import org.eclipse.core.runtime.*; -import org.osgi.framework.BundleContext; -/** - * - */ -public class PreviewServerPlugin extends Plugin { - public static final String PLUGIN_ID = "org.eclipse.wst.server.preview"; - - // singleton instance of this class - private static PreviewServerPlugin singleton; - - protected BundleContext context; - - /** - * Create the JavaServerPlugin. - */ - public PreviewServerPlugin() { - super(); - singleton = this; - } - - /** - * Returns the singleton instance of this plugin. - * - * @return a singleton instance - */ - public static PreviewServerPlugin getInstance() { - return singleton; - } - - /** - * @see Plugin#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context2) throws Exception { - super.start(context2); - context = context2; - } - - /** - * @see Plugin#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext context2) throws Exception { - super.stop(context2); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/PreviewStarter.java b/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/PreviewStarter.java deleted file mode 100644 index ca2144e78..000000000 --- a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/PreviewStarter.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.server.preview.internal; - -import java.io.File; -import java.util.logging.Filter; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - -import org.mortbay.http.HttpContext; -import org.mortbay.http.handler.ResourceHandler; -import org.mortbay.jetty.*; -import org.mortbay.jetty.servlet.WebApplicationContext; - -public class PreviewStarter { - private static final String[] AVERTED_LOGS = new String[] { - "org.mortbay.util.Container", "org.mortbay.http.HttpServer", - "org.mortbay.util.Credential", "org.mortbay.http.SocketListener", - "org.mortbay.http.HttpServer", "org.mortbay.jetty.Server" - }; - - protected String configPath; - protected Server server; - - public PreviewStarter(String configPath) { - this.configPath = configPath; - } - - public static void main(String[] args) { - PreviewStarter app = new PreviewStarter(args[0]); - app.run(); - } - - protected void run() { - System.out.println("Starting preview server"); - System.out.println(); - try { - ServerConfig config = new ServerConfig(configPath); - System.out.println("Port " + config.getPort()); - Module[] m = config.getModules(); - int size = m.length; - if (size > 0) { - System.out.println("Modules:"); - for (Module mm : m) - System.out.println(" " + mm.getName()); - System.out.println(); - } - - for (String log : AVERTED_LOGS) { - Logger logger = Logger.getLogger(log); - logger.setFilter(new Filter() { - public boolean isLoggable(LogRecord record) { - //Trace.trace(Trace.FINEST, "Averted Jetty log: " + record.getMessage()); - //System.out.println("averted: " + record.getLoggerName() + ": " + record.getMessage()); - return false; - } - }); - } - - // helper code to find jetty loggers - /*Logger logger = Logger.getLogger("org.mortbay.http.HttpServer"); - logger.addHandler(new java.util.logging.Handler() { - public void close() throws SecurityException { - // ignore - } - - public void flush() { - // ignore - } - - public void publish(LogRecord record) { - System.out.println("Logger found: " + record.getLoggerName()); - } - });*/ - - server = new Server(); - server.addListener(":" + config.getPort()); - server.setTrace(false); - server.setStatsOn(false); - - HttpContext context2 = new HttpContext(); - context2.setContextPath("/"); - context2.addHandler(new WTPErrorPageHandler()); - context2.setAttribute(HttpContext.__ErrorHandler, new WTPErrorPageHandler()); - server.addContext(context2); - server.setRootWebApp("/"); - - for (Module module : m) { - if (module.isStaticWeb()) { - HttpContext context = new HttpContext(); - context.setContextPath(module.getContext()); - context.setResourceBase(module.getPath()); - context.addHandler(new ResourceHandler()); - context.addHandler(new WTPErrorPageHandler()); - context.setAttribute(HttpContext.__ErrorHandler, new WTPErrorPageHandler()); - server.addContext(context); - } else { - WebApplicationContext context = server.addWebApplication(module.getContext(), module.getPath()); - //context.getWebApplicationHandler(); - //context.addHandler(new WTPErrorPageHandler()); - context.setAttribute(HttpContext.__ErrorHandler, new WTPErrorPageHandler()); - } - } - - try { - server.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } catch (Throwable e) { - e.printStackTrace(); - } - } - - public void stop() { - try { - System.out.println("Stop!"); - server.stop(); - //File contextWorkDir = new File(workDir, DIR_PREFIX + pid.hashCode()); - //deleteDirectory(contextWorkDir); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * deleteDirectory is a convenience method to recursively delete a directory - * @param directory - the directory to delete. - * @return was the delete succesful - */ - protected static boolean deleteDirectory(File directory) { - if (directory.exists() && directory.isDirectory()) { - File[] files = directory.listFiles(); - for (File file : files) { - if (file.isDirectory()) { - deleteDirectory(file); - } else { - file.delete(); - } - } - } - return directory.delete(); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/ServerConfig.java b/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/ServerConfig.java deleted file mode 100644 index ea1cc4119..000000000 --- a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/ServerConfig.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.server.preview.internal; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -public class ServerConfig { - private String configPath; - private Module[] modules; - private int port = 8080; - - public ServerConfig(String configPath) { - this.configPath = configPath; - init(); - } - - private void init() { - File f = new File(configPath); - if (!f.exists()) - System.err.println("Config doesn't exist at " + configPath); - else { - try { - IMemento memento = XMLMemento.loadMemento(f); - Integer prt = memento.getInteger("port"); - if (prt != null) - port = prt.intValue(); - - IMemento[] modules2 = memento.getChildren("module"); - int size = modules2.length; - List<Module> list = new ArrayList<Module>(size); - for (IMemento mod : modules2) { - String name = mod.getString("name"); - boolean isStatic = "static".equals(mod.getString("type")); - String path = mod.getString("path"); - String context = mod.getString("context"); - Module module = new Module(name, isStatic, context, path); - list.add(module); - } - - modules = new Module[list.size()]; - list.toArray(modules); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - public int getPort() { - return port; - } - - public Module[] getModules() { - return modules; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Trace.java b/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Trace.java deleted file mode 100644 index 8a86d6496..000000000 --- a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/Trace.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.server.preview.internal; -/** - * Helper class to route trace output. - */ -public class Trace { - /** - * Config tracing - */ - public static final byte CONFIG = 0; - /** - * Warning tracing - */ - public static final byte WARNING = 1; - /** - * Severe tracing - */ - public static final byte SEVERE = 2; - /** - * Finest tracing - */ - public static final byte FINEST = 3; - - public static final byte PUBLISHING = 4; - - /** - * Trace constructor comment. - */ - private Trace() { - super(); - } - - /** - * Trace the given text. - * - * @param level trace level - * @param s String - */ - public static void trace(byte level, String s) { - Trace.trace(level, s, null); - } - - /** - * Trace the given message and exception. - * - * @param level trace level - * @param s String - * @param t Throwable - */ - public static void trace(byte level, String s, Throwable t) { - if (!PreviewServerPlugin.getInstance().isDebugging()) - return; - - System.out.println(PreviewServerPlugin.PLUGIN_ID + " " + s); - if (t != null) - t.printStackTrace(); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/WTPErrorPageHandler.java b/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/WTPErrorPageHandler.java deleted file mode 100644 index e679edb5d..000000000 --- a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/WTPErrorPageHandler.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.server.preview.internal; - -import java.io.IOException; -import java.io.Writer; -import java.net.URLDecoder; - -import org.mortbay.http.HttpException; -import org.mortbay.http.HttpFields; -import org.mortbay.http.HttpRequest; -import org.mortbay.http.HttpResponse; -import org.mortbay.http.handler.AbstractHttpHandler; -import org.mortbay.util.ByteArrayISO8859Writer; -import org.mortbay.util.StringUtil; - -public class WTPErrorPageHandler extends AbstractHttpHandler { - private static final long serialVersionUID = 1L; - - public void handle(String pathInContext, String pathParams, HttpRequest request, - HttpResponse response) throws HttpException, IOException { - response.setContentType(HttpFields.__TextHtml); - ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(2048); - writeErrorPage(request, writer, response.getStatus(), response.getReason()); - - // workaround for IE, which overrides 404 errors to present its own page - if (response.getStatus() == 404) - response.setStatus(200, "OK"); - - writer.flush(); - response.setContentLength(writer.size()); - writer.writeTo(response.getOutputStream()); - writer.destroy(); - } - - protected void writeErrorPage(HttpRequest request, Writer writer, int code, - String message) throws IOException { - if (message != null) { - message = URLDecoder.decode(message, "UTF-8"); - message = StringUtil.replace(message, "<", "<"); - message = StringUtil.replace(message, ">", ">"); - } - String uri = request.getPath(); - uri = StringUtil.replace(uri, "<", "<"); - uri = StringUtil.replace(uri, ">", ">"); - writer.write("<html>\n<head>\n<title>Error "); - writer.write(Integer.toString(code)); - writer.write(' '); - writer.write(message); - writer.write("</title>\n</head>\n<body>\n<h2>HTTP ERROR: "); - writer.write(Integer.toString(code)); - writer.write("</h2><pre>"); - writer.write(message); - writer.write("</pre>\n"); - writer.write("<p>RequestURI="); - writer.write(uri); - writer.write("</p>"); - writer.write("\n</body>\n</html>\n"); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/XMLMemento.java b/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/XMLMemento.java deleted file mode 100644 index d43134f26..000000000 --- a/plugins/org.eclipse.wst.server.preview/src/org/eclipse/wst/server/preview/internal/XMLMemento.java +++ /dev/null @@ -1,175 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.server.preview.internal; - -import java.io.*; -import java.util.*; - -import org.w3c.dom.*; -import org.xml.sax.*; - -import javax.xml.parsers.*; -/** - * A Memento is a class independent container for persistence - * info. It is a reflection of 3 storage requirements. - * - * 1) We need the ability to persist an object and restore it. - * 2) The class for an object may be absent. If so we would - * like to skip the object and keep reading. - * 3) The class for an object may change. If so the new class - * should be able to read the old persistence info. - * - * We could ask the objects to serialize themselves into an - * ObjectOutputStream, DataOutputStream, or Hashtable. However - * all of these approaches fail to meet the second requirement. - * - * Memento supports binary persistence with a version ID. - */ -public final class XMLMemento implements IMemento { - private Document factory; - private Element element; - - /** - * Answer a memento for the document and element. For simplicity - * you should use createReadRoot and createWriteRoot to create the initial - * mementos on a document. - */ - private XMLMemento(Document doc, Element el) { - factory = doc; - element = el; - } - - /** - * Create a Document from a Reader and answer a root memento for reading - * a document. - */ - private static XMLMemento createReadRoot(InputStream in) { - Document document = null; - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder parser = factory.newDocumentBuilder(); - document = parser.parse(new InputSource(in)); - Node node = document.getFirstChild(); - if (node instanceof Element) - return new XMLMemento(document, (Element) node); - } catch (Exception e) { - // ignore - } finally { - try { - in.close(); - } catch (Exception e) { - // ignore - } - } - return null; - } - - /* - * @see IMemento - */ - public IMemento getChild(String type) { - // Get the nodes. - NodeList nodes = element.getChildNodes(); - int size = nodes.getLength(); - if (size == 0) - return null; - - // Find the first node which is a child of this node. - for (int nX = 0; nX < size; nX ++) { - Node node = nodes.item(nX); - if (node instanceof Element) { - Element element2 = (Element)node; - if (element2.getNodeName().equals(type)) - return new XMLMemento(factory, element2); - } - } - - // A child was not found. - return null; - } - - /* - * @see IMemento - */ - public IMemento [] getChildren(String type) { - // Get the nodes. - NodeList nodes = element.getChildNodes(); - int size = nodes.getLength(); - if (size == 0) - return new IMemento[0]; - - // Extract each node with given type. - List<Element> list = new ArrayList<Element>(size); - for (int nX = 0; nX < size; nX ++) { - Node node = nodes.item(nX); - if (node instanceof Element) { - Element element2 = (Element)node; - if (element2.getNodeName().equals(type)) - list.add(element2); - } - } - - // Create a memento for each node. - size = list.size(); - IMemento [] results = new IMemento[size]; - for (int x = 0; x < size; x ++) { - results[x] = new XMLMemento(factory, list.get(x)); - } - return results; - } - - /* - * @see IMemento - */ - public Integer getInteger(String key) { - Attr attr = element.getAttributeNode(key); - if (attr == null) - return null; - String strValue = attr.getValue(); - try { - return new Integer(strValue); - } catch (NumberFormatException e) { - return null; - } - } - - /* - * @see IMemento - */ - public String getString(String key) { - Attr attr = element.getAttributeNode(key); - if (attr == null) - return null; - return attr.getValue(); - } - - /** - * Loads a memento from the given file. - * - * @param file a file - * @exception java.io.IOException - * @return a memento - */ - public static IMemento loadMemento(File file) throws IOException { - InputStream in = null; - try { - in = new BufferedInputStream(new FileInputStream(file)); - return XMLMemento.createReadRoot(in); - } finally { - try { - if (in != null) - in.close(); - } catch (Exception e) { - // ignore - } - } - } -}
\ No newline at end of file |