用CCPP 解析 user Agent profile 时出现的问题 谢谢!

feixiang2005 2006-12-01 09:30:55
采用 CC/PP Processing 1.0 Reference Implementation
(http://java.sun.com/j2ee/ccpp/) 解析 profile 文件

解析的user Agent profile 如下:

<?xml version="1.0"?>
<!-- ===================================================== -->
<!-- -->
<!-- Copyright (c) 2003 Nokia. All rights reserved. -->
<!-- -->
<!-- ===================================================== -->
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:prf="http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#"
xmlns:mms="http://www.wapforum.org/profiles/MMS/ccppschema-20010111#">
<rdf:Description rdf:ID="Profile">
<prf:component>
<rdf:Description rdf:ID="HardwarePlatform">
<rdf:type rdf:resource="http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#HardwarePlatform"/>
<prf:BluetoothProfile>
<rdf:Bag>
<rdf:li>Headset Profile</rdf:li>
<rdf:li>Handsfree Profile</rdf:li>
<rdf:li>Dial-up Networking Profile</rdf:li>
<rdf:li>Basic Imaging Profile</rdf:li>
<rdf:li>Basic Printing Profile</rdf:li>
<rdf:li>Object Push Profile</rdf:li>
<rdf:li>File Transfer Profile</rdf:li>
<rdf:li>Human Interface Device Profile</rdf:li>
<rdf:li>General Access Profile</rdf:li>
<rdf:li>Service Discovery Profile</rdf:li>
<rdf:li>Serial Port Profile</rdf:li>
<rdf:li>General Object Exchange Profile</rdf:li>
</rdf:Bag>
</prf:BluetoothProfile>
<prf:BitsPerPixel>18</prf:BitsPerPixel>
<prf:ColorCapable>Yes</prf:ColorCapable>
<prf:CPU>ARM</prf:CPU>
<prf:ImageCapable>Yes</prf:ImageCapable>
<prf:InputCharSet>
<rdf:Bag>
<rdf:li>ISO-8859-1</rdf:li>
<rdf:li>ISO-10646-UCS-2</rdf:li>
<rdf:li>US-ASCII</rdf:li>
<rdf:li>UTF-8</rdf:li>
</rdf:Bag>
</prf:InputCharSet>
<prf:Keyboard>PhoneKeyPad</prf:Keyboard>
<prf:Model>N70-1</prf:Model>
<prf:NumberOfSoftKeys>2</prf:NumberOfSoftKeys>
<prf:OutputCharSet>
<rdf:Bag>
<rdf:li>ISO-8859-1</rdf:li>
<rdf:li>ISO-10646-UCS-2</rdf:li>
<rdf:li>US-ASCII</rdf:li>
<rdf:li>UTF-8</rdf:li>
</rdf:Bag>
</prf:OutputCharSet>
<prf:PixelAspectRatio>1x1</prf:PixelAspectRatio>
<prf:PointingResolution>Pixel</prf:PointingResolution>
<prf:ScreenSize>176x208</prf:ScreenSize>
<prf:ScreenSizeChar>15x6</prf:ScreenSizeChar>
<prf:StandardFontProportional>Yes</prf:StandardFontProportional>
<prf:SoundOutputCapable>Yes</prf:SoundOutputCapable>
<prf:TextInputCapable>Yes</prf:TextInputCapable>
<prf:Vendor>Nokia</prf:Vendor>
<prf:VoiceInputCapable>Yes</prf:VoiceInputCapable>
</rdf:Description>
</prf:component>
</rdf:Description>
</rdf:RDF>


解析上述文件代码:

/*****************************************/

import java.io.*;
import java.net.*;
import java.util.*;

import javax.ccpp.*;
import com.sun.ccpp.*;

public class QueryProfile {

// Construct a Profile object from an XML profile file
public Profile getProfileFromFile(File ccppFile) throws FileNotFoundException {
ProfileFactory pf = ProfileFactoryImpl.getInstance();
//ProfileFactory.setInstance(pf);

ProfileFragmentFactory ff = ProfileFragmentFactoryImpl.getInstance();
//ProfileFragmentFactory.setInstance(ff);

//Configure the vocabulary
DescriptionManager dm = DescriptionManager.getInstance();
try {
// set the schema
File schema = new File("vocabulary.xsd");
DescriptionManager.setSchema(schema);

File vocab = null;
vocab = new File("ccppschema-20010430.xml");
dm.addVocabulary(vocab);
vocab = new File("ccppschema-20010430a.xml");
dm.addVocabulary(vocab);
vocab = new File("ccppschema-20010430b.xml");
dm.addVocabulary(vocab);
vocab = new File("ccppschema-20021212.xml");
dm.addVocabulary(vocab);

} catch(Exception e) {
e.printStackTrace();
}

// Read the CC/PP profile from a file
InputStream is = new FileInputStream(ccppFile);
ProfileFragment pfa[] = new ProfileFragment[1];

pfa[0] = ff.newProfileFragment(is);
return pf.newProfile(pfa);
}

// Given a profile, list its attribute name/value pairs
public void processProfile(Profile profile) {
Set comps = profile.getComponents();
for(Iterator i = comps.iterator(); i.hasNext(); ) {
Component comp = (Component) i.next();
System.out.println("Component: " + comp.getName());

Set attrs = comp.getAttributes();

for(Iterator j = attrs.iterator(); j.hasNext(); ) {
Attribute attr = (Attribute) j.next();
Object value = attr.getValue();
System.out.println("\tAttribute: " + attr.getName() +
" = " + attr.getValue());
}
}
}

public static void main(String argv[]) throws Exception {
if(argv.length != 1) {
System.out.println("Usage: java QueryProfile [profileName.xml]");
System.exit(0);
}

QueryProfile p = new QueryProfile();
File f = new File(argv[0]);
Profile profile = p.getProfileFromFile(f);

// If the profile is null then something went wrong
if(profile == null) {
System.out.println("Null profile");
} else {
// Print vocabulary information
ProfileDescription pd = profile.getDescription();
System.out.println("Vocabulary: "+pd.getURI());

// process the profile
p.processProfile(profile);
}
}
}
/*****************************************/

解析结果:

Vocabulary: http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#
Component: HardwarePlatform
Attribute: NumberOfSoftKeys = 2
Attribute: Keyboard = PhoneKeyPad
Attribute: ImageCapable = true
Attribute: OutputCharSet = ISO-8859-1
Attribute: StandardFontProportional = true
Attribute: Vendor = Nokia
Attribute: PixelAspectRatio = 1x1
Attribute: Model = N70-1
Attribute: ScreenSize = 176x208
Attribute: BitsPerPixel = 18
Attribute: PointingResolution = Pixel
Attribute: BluetoothProfile = Headset Profile
Attribute: ScreenSizeChar = 15x6
Attribute: ColorCapable = true
Attribute: TextInputCapable = true
Attribute: InputCharSet = ISO-8859-1
Attribute: SoundOutputCapable = true
Attribute: VoiceInputCapable = true
Attribute: CPU = ARM


/*******************************************************/
问题:
Attribute: BluetoothProfile = Headset Profile
Attribute: InputCharSet = ISO-8859-1
Attribute: OutputCharSet = ISO-8859-1

获得的值为什么只能取到一个? 应该是有多个才对的啊?

...全文
297 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
feixiang2005 2006-12-03
  • 打赏
  • 举报
回复
up for help

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧