use of com.google.cloud.dialogflow.v2.Context in project webtools.servertools by eclipse.
the class TomcatVersionHelper method loadContextFile.
private static Context loadContextFile(File contextFile) {
FileInputStream fis = null;
Context context = null;
if (contextFile != null && contextFile.exists()) {
try {
Factory factory = new Factory();
factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
fis = new FileInputStream(contextFile);
context = (Context) factory.loadDocument(fis);
if (context != null) {
String path = context.getPath();
// If path attribute is not set, derive from file name
if (path == null) {
String fileName = contextFile.getName();
path = fileName.substring(0, fileName.length() - ".xml".length());
if ("ROOT".equals(path))
path = "";
// Assuming this use for "#" since Tomcat has "reserved" this use of "#" since 5.5.
path = path.replace('#', '/');
context.setPath("/" + path);
}
}
} catch (Exception e) {
// may be a spurious xml file in the host dir?
Trace.trace(Trace.FINER, "Unable to read context " + contextFile.getAbsolutePath());
} finally {
try {
fis.close();
} catch (IOException e) {
// ignore
}
}
}
return context;
}
use of com.google.cloud.dialogflow.v2.Context in project webtools.servertools by eclipse.
the class TomcatVersionHelper method addCatalinaContextConfig.
/**
* If the specified Context is linked to a project, try to
* update it with any configuration from a META-INF/context.xml found
* relative to the specified web applications directory and context docBase.
*
* @param webappsDir Path to server's web applications directory.
* @param context Context object to receive context.xml contents.
* @param ms MultiStatus object to receive error status.
* @return Returns true if context is modified.
*/
private static boolean addCatalinaContextConfig(IPath webappsDir, Context context, MultiStatus ms) {
boolean modified = false;
String source = context.getSource();
if (source != null && source.length() > 0) {
File docBase = new File(context.getDocBase());
if (!docBase.isAbsolute())
docBase = new File(webappsDir.toOSString(), docBase.getPath());
try {
Context contextConfig = loadCatalinaContextConfig(docBase);
if (null != contextConfig) {
if (context.hasChildNodes())
context.removeChildren();
contextConfig.copyChildrenTo(context);
Map attrs = contextConfig.getAttributes();
Iterator iter = attrs.keySet().iterator();
while (iter.hasNext()) {
String name = (String) iter.next();
if (!name.equalsIgnoreCase("path") && !name.equalsIgnoreCase("docBase") && !name.equalsIgnoreCase("source")) {
String value = (String) attrs.get(name);
context.setAttributeValue(name, value);
}
}
modified = true;
}
} catch (Exception e) {
String contextPath = context.getPath();
if (contextPath.startsWith("/")) {
contextPath = contextPath.substring(1);
}
Trace.trace(Trace.SEVERE, "Error reading context.xml file for " + contextPath, e);
IStatus s = new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadContextXml, contextPath), e);
ms.add(s);
}
}
return modified;
}
use of com.google.cloud.dialogflow.v2.Context in project webtools.servertools by eclipse.
the class TomcatVersionHelper method loadSeparateContextFiles.
private static void loadSeparateContextFiles(File contextDir, Factory factory, Map<File, Context> projectContexts) {
File[] contextFiles = contextDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".xml");
}
});
for (int j = 0; j < contextFiles.length; j++) {
File ctx = contextFiles[j];
Context context = loadContextFile(ctx);
if (context != null) {
// TODO Handle non-project contexts when their removal can be addressed
String memento = context.getSource();
if (memento != null) {
projectContexts.put(ctx, context);
}
}
}
}
use of com.google.cloud.dialogflow.v2.Context in project webtools.servertools by eclipse.
the class TomcatVersionHelper method getCatalinaServerInstance.
/**
* Gets a ServerInstance for the specified server.xml, Service name,
* and Host name. Returns null if server.xml does not exist
* or an error occurs.
*
* @param serverXml path to previously published server.xml
* @param serviceName name of Service to be used by this instance or null
* @param hostName name of Host to be used by this instance or null
* @return ServerInstance for specified server.xml using specified
* Service and Host names. null if server.xml does not exist.
* @throws FileNotFoundException should not occur since existence is tested
* @throws IOException if there is an error reading server.xml
* @throws SAXException if there is a syntax error in server.xml
*/
public static ServerInstance getCatalinaServerInstance(IPath serverXml, String serviceName, String hostName) throws FileNotFoundException, IOException, SAXException {
ServerInstance serverInstance = null;
Factory factory = new Factory();
factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
File serverFile = serverXml.toFile();
if (serverFile.exists()) {
Server server = (Server) factory.loadDocument(new FileInputStream(serverFile));
serverInstance = new ServerInstance(server, serviceName, hostName);
IPath contextPath = serverInstance.getContextXmlDirectory(serverXml.removeLastSegments(1));
File contextDir = contextPath.toFile();
if (contextDir.exists()) {
Map<File, Context> projectContexts = new HashMap<File, Context>();
loadSeparateContextFiles(contextPath.toFile(), factory, projectContexts);
// add any separately saved contexts
Host host = serverInstance.getHost();
Collection contexts = projectContexts.values();
Iterator iter = contexts.iterator();
while (iter.hasNext()) {
Context context = (Context) iter.next();
host.importNode(context.getElementNode(), true);
}
// TODO Add handling for non-project contexts when there removal can be addressed
}
}
return serverInstance;
}
use of com.google.cloud.dialogflow.v2.Context in project webtools.servertools by eclipse.
the class Tomcat50Configuration method modifyWebModule.
/**
* Change a web module.
* @param index int
* @param docBase java.lang.String
* @param path java.lang.String
* @param reloadable boolean
*/
public void modifyWebModule(int index, String docBase, String path, boolean reloadable) {
try {
Context context = serverInstance.getContext(index);
if (context != null) {
context.setPath(path);
context.setDocBase(docBase);
context.setReloadable(reloadable ? "true" : "false");
isServerDirty = true;
WebModule module = new WebModule(path, docBase, null, reloadable);
firePropertyChangeEvent(MODIFY_WEB_MODULE_PROPERTY, new Integer(index), module);
}
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Error modifying web module " + index, e);
}
}
Aggregations