RequestInterface req,
String name,
Hashtable defs)
{
ResourceReference rr = null;
FramedResource template = null;
Resource newres = null;
Class proto = null;
try {
proto = Class.forName("org.w3c.tools.resources.ProtocolFrame");
} catch (Exception ex) {
// fatal error!
return null;
}
// Check that at least one class is defined for all the extensions:
String exts[] = getFileExtensions(name) ;
if ( exts == null )
return null ;
for (int i = exts.length-1 ; i >= 0 ; i--) {
rr = getTemplateFor(exts[i]) ;
if ( rr != null )
break ;
}
if ( rr == null ) {
// Look for a default template:
if ((rr = loadExtension(defname)) == null)
return null ;
}
// Create the runtime-time default values for attributes.
if ( defs == null ) {
defs = new Hashtable(5) ;
}
String s_dir = "directory".intern();
String s_ide = "identifier".intern();
String s_fil = "filename".intern();
String s_con = "context".intern();
if ( defs.get(s_dir) == null ) {
defs.put(s_dir, directory) ;
}
if ( defs.get(s_ide) == null ) {
defs.put(s_ide, getIndexedFileName(name)) ;
} else {
defs.put(s_ide, getIndexedFileName((String)defs.get(s_ide))) ;
}
if ( defs.get(s_fil) == null) {
defs.put(s_fil, name) ;
}
if ( defs.get(s_con) == null ) {
defs.put(s_con, getContext());
}
try {
template = (FramedResource) rr.lock();
if (exts != null) {
// Merge with values defined by the extension:
for (int i = exts.length ; --i >= 0 ; )
mergeDefaultAttributes(template, exts[i], defs) ;
}
// Create, initialize and return the new resouce
try {
newres = (FramedResource) template.getClone(defs);
} catch (Exception ex) {
ex.printStackTrace() ;
return null ;
}
} catch (InvalidResourceException ex) {
ex.printStackTrace();
return null;
} finally {
rr.unlock();
}
// clone has been done, merge frames now
if (exts != null) {
ResourceFrame rf[] = newres.collectFrames(proto);
if (rf != null) {
for (int j=0; j < rf.length; j++) {
for (int i = exts.length-1 ; i >= 0 ; i--) {
rr = getTemplateFor(exts[i]) ;
if ( rr != null ) {
FramedResource fr = null;
try {
fr = (FramedResource) rr.lock();
ResourceReference trr = null;
trr = fr.getFrameReference(proto);
if (trr != null) {
mergeFrameAttributes(rf[j], exts[i], trr);
}
} catch (InvalidResourceException iex) {
iex.printStackTrace();