使用的XML文件:
<!--
The profile service
$Id: profile.xml 89131 2009-05-19 20:18:52Z scott.stark@jboss.org $
-->
<deployment xmlns="urn:jboss:bean-deployer:2.0">
<classloader><inject bean="profile-classloader:0.0.0" /></classloader>
<classloader name="profile-classloader" xmlns="urn:jboss:classloader:1.0" export-all="NON_EMPTY" import-all="true">
<root>${jboss.lib.url}jboss-profileservice-spi.jar</root>
</classloader>
<!--
The profile configuration
This contains required properties:
The uri to jboss-service.xml.
The uri to the deployers folder.
A list of uris to deploy folders. -->
<bean name="BootstrapProfileFactory" class="org.jboss.system.server.profileservice.repository.StaticProfileFactory">
<property name="bindingsURI">${jboss.server.home.url}conf/bindingservice.beans</property>
<property name="bootstrapURI">${jboss.server.home.url}conf/jboss-service.xml</property>
<property name="deployersURI">${jboss.server.home.url}deployers</property>
<property name="applicationURIs">
<list elementClass="java.net.URI">
<value>${jboss.server.home.url}deploy</value>
<value> </value>
</list>
</property>
<property name="attachmentStoreRoot">${jboss.server.data.dir}/attachments</property>
<property name="profileFactory"><inject bean="ProfileFactory" /></property>
</bean>
<!-- The default profile key -->
<bean name="DefaultProfileKey" class="org.jboss.profileservice.spi.ProfileKey">
<constructor><parameter>${jboss.server.name}</parameter></constructor>
</bean>
<!-- The ProfileService -->
<bean name="ProfileService" class="org.jboss.system.server.profileservice.repository.AbstractProfileService">
<constructor><parameter><inject bean="jboss.kernel:service=KernelController" /></parameter></constructor>
<property name="deployer"><inject bean="ProfileServiceDeployer" /></property>
<property name="defaultProfile"><inject bean="DefaultProfileKey" /></property>
</bean>
<!-- The Bootstrap implementation that loads the Profile from the ProfileService -->
<bean name="ProfileServiceBootstrap" class="org.jboss.system.server.profileservice.ProfileServiceBootstrap">
<property name="profileKey"><inject bean="DefaultProfileKey" /></property>
<property name="mainDeployer"><inject bean="MainDeployer" /></property>
<property name="profileService"><inject bean="ProfileService" /></property>
<property name="mof"><inject bean="ManagedObjectFactory" /></property>
<property name="mgtDeploymentCreator"><inject bean="ManagedDeploymentCreator" /></property>
<property name="bootstrapProfileFactory"><inject bean="BootstrapProfileFactory" /></property>
<property name="configurator"><inject bean="jboss.kernel:service=Kernel" property="configurator"/></property>
</bean>
<!-- The profile factory -->
<bean name="ProfileFactory" class="org.jboss.system.server.profileservice.repository.TypedProfileFactory">
<!-- Accept any AbstractprofileFactory -->
<incallback method="addProfileFactory" />
<uncallback method="removeProfileFactory" />
</bean>
<!-- The profile repository factory -->
<bean name="ProfileRepositoryFactory" class="org.jboss.system.server.profileservice.repository.TypedProfileRepository">
<!-- Accept any DeploymentRepositoryFactory -->
<incallback method="addRepositoryFactory" />
<uncallback method="removeRepositoryFactory" />
</bean>
<!-- The structure modification cache and checker -->
<bean name="StructureModCache" class="org.jboss.deployers.vfs.spi.structure.modified.DefaultStructureCache">
<destroy method="flush"/>
</bean>
<!-- This just checks metadata locations -->
<bean name="MetaDataStructureModificationChecker" class="org.jboss.deployers.vfs.spi.structure.modified.MetaDataStructureModificationChecker">
<constructor>
<parameter><inject bean="MainDeployer" /></parameter>
</constructor>
<property name="cache"><inject bean="StructureModCache" /></property>
<property name="filter"><bean class="org.jboss.system.server.profile.basic.XmlIncludeVirtualFileFilter" /></property>
</bean>
<!-- Synchs modifed files -->
<bean name="SynchAdapter" class="org.jboss.deployers.vfs.spi.structure.modified.OverrideSynchAdapter"/>
<!-- We just visit wars, but exclude classes, lib, dev dirs -->
<bean name="WebVisitorAttributes" class="org.jboss.system.server.profile.basic.IncludeExcludeVisitorAttributes">
<constructor>
<parameter>
<set>
<value>.war</value>
</set>
</parameter>
<parameter>
<set>
<value>WEB-INF/classes</value>
<value>WEB-INF/lib</value>
<value>WEB-INF/dev</value>
</set>
</parameter>
</constructor>
</bean>
<bean name="StructureModificationChecker" class="org.jboss.deployers.vfs.spi.structure.modified.SynchWrapperModificationChecker">
<constructor>
<parameter><inject bean="MetaDataStructureModificationChecker"/></parameter>
<parameter><inject bean="SynchAdapter"/></parameter>
</constructor>
<property name="originalAttributes"><inject bean="WebVisitorAttributes"/></property>
<property name="tempAttributes"><inject bean="WebVisitorAttributes"/></property>
</bean>
<bean name="BasicProfileFactory" class="org.jboss.system.server.profileservice.repository.BasicProfileFactory">
<property name="profileRepository"><inject bean="ProfileRepositoryFactory" /></property>
</bean>
<bean name="FilteredProfileFactory" class="org.jboss.system.server.profileservice.repository.FilteredProfileFactory"/>
<!-- The default deployment repository factory -->
<bean name="DefaultDeploymentRepositoryFactory" class="org.jboss.system.server.profileservice.repository.DefaultDeploymentRepositoryFactory">
<property name="deploymentFilter"><inject bean="DeploymentFilter" /></property>
<property name="checker"><inject bean="StructureModificationChecker" /></property>
</bean>
<bean name="ComponentMapperRegistry"
class="org.jboss.system.server.profileservice.persistence.component.ComponentMapperRegistry">
<constructor factoryClass="org.jboss.system.server.profileservice.persistence.component.ComponentMapperRegistry" factoryMethod="getInstance"/>
<!-- Accept any AbstractprofileFactory -->
<incallback method="addMapper" />
<uncallback method="removeComponentMapper" />
</bean>
<!-- A persistence factory for creating the persisted format of ManagedComponents -->
<bean name="PersistenceFactory" class="org.jboss.system.server.profileservice.persistence.AbstractPersistenceFactory">
<constructor><parameter><inject bean="ManagedObjectFactory" /></parameter></constructor>
<!-- Accept any ComponentMapper -->
<incallback method="addComponentMapper" />
<uncallback method="removeComponentMapper" />
<!-- Accept any ManagedObjectPersistencePlugin -->
<incallback method="addPersistencePlugin" />
<uncallback method="removePersistencePlugin" />
</bean>
<!-- The attachment store -->
<bean name="AttachmentStore" class="org.jboss.system.server.profileservice.repository.AbstractAttachmentStore">
<constructor><parameter class="java.io.File"><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>
<property name="mainDeployer"><inject bean="MainDeployer" /></property>
<property name="serializer"><inject bean="AttachmentsSerializer" /></property>
<property name="persistenceFactory"><inject bean="PersistenceFactory" /></property>
</bean>
<bean name="AttachmentsSerializer" class="org.jboss.system.server.profileservice.repository.JAXBAttachmentSerializer">
<constructor><parameter><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>
</bean>
<bean name="ProfileServiceDeployer" class="org.jboss.system.server.profileservice.repository.MainDeployerAdapter">
<property name="mainDeployer"><inject bean="MainDeployer" /></property>
<property name="attachmentStore"><inject bean="AttachmentStore" /></property>
</bean>
<bean name="ProfileServicePersistenceDeployer" class="org.jboss.system.server.profileservice.persistence.deployer.ProfileServicePersistenceDeployer">
<property name="persistenceFactory"><inject bean="PersistenceFactory" /></property>
<property name="attachmentStore"><inject bean="AttachmentStore" /></property>
</bean>
<bean name="KernelDeploymentComponentMapper" class="org.jboss.deployers.plugins.managed.KernelDeploymentComponentMapper">
<constructor><parameter><inject bean="PersistenceFactory" /></parameter></constructor>
<!-- Register under the attachment interface name as well -->
<install bean="ComponentMapperRegistry" method="addMapper">
<parameter class="java.lang.String">org.jboss.kernel.spi.deployment.KernelDeployment</parameter>
<parameter class="org.jboss.system.server.profileservice.persistence.component.ComponentMapper"><this/></parameter>
</install>
<uninstall bean="ComponentMapperRegistry" method="removeComponentMapper">
<parameter class="java.lang.String">org.jboss.kernel.spi.deployment.KernelDeployment</parameter>
</uninstall>
</bean>
<bean name="ServiceDeploymentComponentMapper" class="org.jboss.system.deployers.managed.ServiceDeploymentComponentMapper">
<constructor><parameter><inject bean="PersistenceFactory" /></parameter></constructor>
</bean>
<!-- A filter for excluding files from the scanner -->
<bean name="DeploymentFilter" class="org.jboss.virtual.plugins.vfs.helpers.ExtensibleFilter">
<!-- Files starting with theses strings are ignored -->
<property name="prefixes">#,%,\,,.,_$</property>
<!-- Files ending with theses strings are ignored -->
<property name="suffixes">#,$,%,~,\,v,.BAK,.bak,.old,.orig,.tmp,.rej,.sh</property>
<!-- Files matching with theses strings are ignored -->
<property name="matches">.make.state,.nse_depinfo,CVS,CVS.admin,RCS,RCSLOG,SCCS,TAGS,core,tags</property>
</bean>
</deployment>
代码段:
procedure SaveAttributeValueToXML(const AFileName, APath,
AValue: string);
var
XMLNode: Variant;
XMLDocument: Variant;
ResultValue: String;
begin
XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0');
try
XMLDocument.async := False;
XMLDocument.load(AFileName);
if (XMLDocument.parseError.errorCode <> 0) then
MsgBox('The XML file could not be parsed. ' +
XMLDocument.parseError.reason, mbError, MB_OK)
else
begin
XMLDocument.setProperty('SelectionLanguage', 'XPath');
XMLNode := XMLDocument.selectSingleNode(APath);
ResultValue := XMLNode.text;
XMLDocument.save(AFileName);
end;
except
MsgBox('An error occured!' + #13#10 + GetExceptionMessage,
mbError, MB_OK);
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
var
UnicodeStr: string;
ANSIStr: AnsiString;
serverAnsiStr: AnsiString;
serverString: string;
profileXmlAnsiStr: AnsiString;
profileXmlString: string;
jdkDir: string;
begin
if CurStep=ssDone then
begin
hibernateDir := MPFWDestDir + '\hpfw\portal.war\WEB-INF\classes\config\hibernate\hibernate.properties';
LoadStringFromFile(hibernateDir, ANSIStr);
UnicodeStr := String(ANSIStr);
StringChangeEx(UnicodeStr, '$!JDBC_USERID!$', ConfigContinuedPage.Values[0], True);
StringChangeEx(UnicodeStr, '$!JDBC_PASSWORD1!$', ConfigContinuedPage.Values[1], True);
StringChangeEx(UnicodeStr, '$!JDBC_HPF_HOSTNAME!$', ConfigPage.Values[2], True);
SaveStringToFile(hibernateDir, AnsiString(UnicodeStr), False);
serverXmlDir := JBossDestDir + '\server\default\deploy\jbossweb.sar\server.xml';
LoadStringFromFile(serverXmlDir, serverAnsiStr);
serverString := String(serverAnsiStr);
StringChangeEx(serverString, '$!WEBSERVER_PORT!$', ConfigPage.Values[0], True);
SaveStringToFile(serverXmlDir, AnsiString(serverString), False);
profileXmlDir := 'C:\Jboss' + '\server\default\conf\bootstrap\profile.xml';
LoadStringFromFile(profileXmlDir, profileXmlAnsiStr);
profileXmlString := String(profileXmlAnsiStr);
StringChangeEx(profileXmlString, '<value>', '<value> file:/' + MPFWDestDir + '/hpfw/</value>', True);
//LoadValueFromXML(profileXmlDir, '//settings/Mail/MailServer');
SaveAttributeValueToXML(profileXmlDir, '//deployment/bean/property/list[@elementClass=''java.net.URI'']/value', 'C:\MPFW');
jdkDir := 'C:\JBOSS\jdk1.7.0_11_64';
if CompareText(checked, 'true') = 0 then
begin
DelTree(jdkDir, True, True, True);
end
end
end;
问题: 我在尝试将数据保存在xml文件的空白标记部分时获取变量是null错误。在$ {jboss.server.home.url}部署此标记后,需要为空值标记设置值。请告诉我代码中的错误。
答案 0 :(得分:1)
我知道这是一个旧线程,所以把我的建议留给你。
错误信息是“Variant is null”,你可以在做下一步之前检查variant是否为null,就像你对XMLDocument
所做的一样:
XMLDocument.load(AFileName);
if (XMLDocument.parseError.errorCode <> 0) then
MsgBox('The XML file could not be parsed. ' + XMLDocument.parseError.reason, mbError, MB_OK)
else
......
因此,在检索其文本之前对 XMLNode
进行类似的检查:
XMLNode := XMLDocument.selectSingleNode(APath);
if not (IDispatch(XMLNode) = nil) then
ResultValue := XMLNode.text;