本文整理汇总了Java中com.google.gwt.xml.client.XMLParser类的典型用法代码示例。如果您正苦于以下问题:Java XMLParser类的具体用法?Java XMLParser怎么用?Java XMLParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XMLParser类属于com.google.gwt.xml.client包,在下文中一共展示了XMLParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadStructure
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
private void loadStructure(final JavaScriptObject assessmentData, final JavaScriptObject itemDatas) {
GWT.runAsync(new RunAsyncCallback() {
@Override
public void onSuccess() {
Document assessmentDoc = XMLParser.parse(decodeXmlDataDocument(assessmentData));
XmlData assessmentXmlData = new XmlData(assessmentDoc, decodeXmlDataBaseURL(assessmentData));
JsArray<JavaScriptObject> itemDatasArray = itemDatas.cast();
XmlData itemXmlDatas[] = new XmlData[itemDatasArray.length()];
for (int i = 0; i < itemDatasArray.length(); i++) {
Document itemDoc = XMLParser.parse(decodeXmlDataDocument(itemDatasArray.get(i)));
itemXmlDatas[i] = new XmlData(itemDoc, decodeXmlDataBaseURL(itemDatasArray.get(i)));
}
player = playerFactory.createPlayer(node_id, jsObject);
player.load(assessmentXmlData, itemXmlDatas);
}
@Override
public void onFailure(Throwable reason) {
throw new RuntimeException("Error while loading player!", reason);
}
});
}
示例2: Assessment
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
/**
* C'tor
*
* @param data XMLData object as data source
*/
@Inject
public Assessment(@Assisted AssessmentData data, @Assisted DisplayContentOptions options, @Assisted ModulesRegistrySocket modulesRegistrySocket,
AssessmentFactory assessmentFactory, InlineBodyGeneratorFactory inlineBodyGeneratorFactory) {
this.assessmentFactory = assessmentFactory;
this.inlineBodyGeneratorFactory = inlineBodyGeneratorFactory;
this.xmlData = data.getData();
this.modulesRegistrySocket = modulesRegistrySocket;
this.options = options;
Document document = xmlData.getDocument();
Element rootNode = (Element) document.getElementsByTagName("assessmentTest").item(0);
Element skinBody = getSkinBody(data.getSkinData());
if (skinBody == null) {
skinBody = XMLParser.parse("<itemBody><pageInPage /></itemBody>").getDocumentElement();
}
styleDeclaration = new StyleLinkDeclaration(xmlData.getDocument().getElementsByTagName("styleDeclaration"), xmlData.getBaseURL());
title = rootNode.getAttribute("title");
initializeBody(skinBody);
}
示例3: XmlDocument
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
public XmlDocument(String url, DocumentLoadCallback<Document> callback) {
this.callback = callback;
this.url = url;
new TextDocument(this.url, new DocumentLoadCallback<String>() {
@Override
public void loadingError(String message) {
XmlDocument.this.callback.loadingError(message);
}
@Override
public void finishedLoading(String text, String baseUrl) {
try {
Document dom = XMLParser.parse(text);
XmlDocument.this.callback.finishedLoading(dom, baseUrl);
} catch (DOMParseException e) {
e.printStackTrace();
XmlDocument.this.callback.loadingError("Could not parse file: " + XmlDocument.this.url);
}
}
});
}
示例4: testUserAgent
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
public void testUserAgent() {
String xml = "<styleDeclaration><link href=\"common/default.css\" userAgent=\"^((?!(iPad|iPhone)).)*\"/><link href=\"common/ipad.css\" userAgent=\".*iPad.*\"/><link href=\"common/iphone.css\" userAgent=\".*iPhone.*\"/></styleDeclaration>";
String baseUrl = "";
NodeList nodes = XMLParser.parse(xml).getElementsByTagName("styleDeclaration");
StyleLinkDeclaration sld = new StyleLinkDeclaration(nodes, baseUrl);
List<String> output;
output = sld
.getStyleLinksForUserAgent("Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405");
assertEquals(1, output.size());
assertTrue(output.contains("/common/ipad.css"));
output = sld
.getStyleLinksForUserAgent("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");
assertEquals(1, output.size());
assertTrue(output.contains("/common/iphone.css"));
output = sld
.getStyleLinksForUserAgent("Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)");
assertEquals(1, output.size());
assertTrue(output.contains("/common/default.css"));
}
示例5: testStylesForDifferentPages
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
public void testStylesForDifferentPages() {
scriptsLoader.inject(new SynchronousScriptsCallback() {
@Override
public void onLoad() {
testObj.addAssessmentStyle(new StyleDocument(CssParser.parseCss(css1), ""));
testObj.addItemStyle(0, new StyleDocument(CssParser.parseCss(css2), ""));
testObj.addItemStyle(1, new StyleDocument(CssParser.parseCss(css3), ""));
testObj.setCurrentPages(new PageReference(PageType.TEST, new int[]{0}, null, null));
Document doc = XMLParser.parse("<h2 />");
Element e = doc.getDocumentElement();
Map<String, String> styles = testObj.getStyleProperties(e, true);
assertTrue(styles.containsKey("font-size"));
assertFalse(styles.containsKey("font-weight"));
testObj.setCurrentPages(new PageReference(PageType.TEST, new int[]{1}, null, null));
doc = XMLParser.parse("<h1 />");
e = doc.getDocumentElement();
styles = testObj.getStyleProperties(e, true);
assertFalse(styles.containsKey("font-size"));
assertTrue(styles.containsKey("font-weight"));
finishTest();
}
});
}
示例6: testXmlProcessing
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
public void testXmlProcessing() {
Document doc = XMLParser
.parse("<nodes><responseDeclaration identifier='RESPONSE' cardinality='multiple' baseType='identifier'><correctResponse><value>ChoiceA</value></correctResponse></responseDeclaration></nodes>");
VariableManager<CustomVariable> vm = new VariableManager<CustomVariable>(doc.getDocumentElement().getChildNodes(),
new IVariableCreator<CustomVariable>() {
@Override
public CustomVariable createVariable(Node node) {
assertTrue(node.getNodeType() == Node.ELEMENT_NODE);
Element el = (Element) node;
String identifier = el.getAttribute("identifier");
assertEquals("RESPONSE", identifier);
return new CustomVariable();
}
}
);
assertTrue(vm.getVariableIdentifiers().size() == 1);
assertTrue(vm.getVariable("RESPONSE") instanceof CustomVariable);
}
示例7: parse
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
/**
* @param wadlXmlString
*/
public void parse(String wadlXmlString) {
// remove unnecessary whitespaces
wadlXmlString = wadlXmlString.replaceAll(">\\s*<", "><");
// remove <!-- comment nodes -->
wadlXmlString = wadlXmlString.replaceAll("<!--.*?-->", "");
try {
// reset the application
GuiFactory.resetApplication();
Document wadl = XMLParser.parse(wadlXmlString);
if (startParsing(wadl)) {
uploadDialogBox.setVisible(true);
uploadDialogBox.hide();
// if the parsing succeeded render a tree from the parsed wadl
WadlTreeRoot wadlTreeRoot = new WadlTreeRoot();
Tree wadlTree = wadlTreeRoot.buildTree(application);
WadlPanel.wadlArea.setWidget(wadlTree);
GuiFactory.toggleButtonsEnabled(true);
WadlPanel.fullscreenButton.click();
}
} catch (DOMParseException e) {
alertInvalidWadlAndRetry(GuiFactory.strings.invalidWadl());
}
}
示例8: deserializeAsCollection
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
/**
* Deserialize the plain text into an object of type T.
*
* @param collectionType The class of the collection
* @param response Http response body content
* @param context Context of deserialization
*
* @return The object deserialized
*/
@Override
public <C extends Collection<Book>> C deserializeAsCollection(Class<C> collectionType, String response,
DeserializationContext context) {
C col = context.getContainerInstance(collectionType);
Document xml;
try {
xml = XMLParser.parse(response);
} catch (DOMParseException e) {
throw new UnableToDeserializeException("Could not read response as xml.", e);
}
Collections.addAll(col, parseXmlDocumentAsBook(xml));
return col;
}
示例9: createCompleteSessionObject
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
/**
* Conveniencemethod to create a <code>complete</code> session object.
* @param recomm The recommendation to be sent with this sessionobject.
* @param infos A map containing all infos to be sent with this sessionobject.
* @return The sessionobject as a dataobject.
*/
public static JavaScriptObject createCompleteSessionObject(RecommendationObject recomm, Map<String, String> infos, String timestamp) {
String namespace = "mirror:application:activityrecommendationapp:session";
Document doc = XMLParser.createDocument();
Element root = Parser.createElement("session", namespace);
root.setAttribute("type", "complete");
if (timestamp != null) {
root.setAttribute("timestamp", timestamp);
}
root.appendChild(recomm.createRecommendationXMLElement());
for (String tagName:infos.keySet()) {
Element tag = Parser.createElement(tagName, namespace);
tag.appendChild(doc.createTextNode(infos.get(tagName)));
root.appendChild(tag);
}
return stringToDataObject(root.toString());
}
示例10: parse
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
public void parse(InputStream is) throws SAXException {
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
int read;
try {
while ((read = is.read(buf)) >= 0) {
if (read > 0)
sb.append(new String(buf, 0, read));
}
} catch (IOException e) {
e.printStackTrace();
}
Document d = XMLParser.parse(sb.toString());
handleElement(d.getFirstChild());
mHandler.endDocument();
}
示例11: onResponseReceived
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
public void onResponseReceived(Request request, Response response) {
hasSession = true;
try {
String s = Utils.getXmlNodeValue(XMLParser.parse(response.getText()), TAG_BLOBSTORE);
blobstore = "true".equalsIgnoreCase(s);
// with blobstore status does not make sense
if (blobstore) {
updateStatusTimer.setInterval(5000);
}
uploadForm.submit();
} catch (Exception e) {
String message = e.getMessage().contains("error:")
? i18nStrs.uploaderServerUnavailable() + " (3) " + getServletPath() + "\n\n" + i18nStrs.uploaderServerError() + "\nAction: " + getServletPath() + "\nException: " + e.getMessage() + response.getText()
: i18nStrs.submitError();
cancelUpload( message);
}
}
示例12: getStyle
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
private JavaScriptObject getStyle(com.google.gwt.dom.client.Element element) {
Element xmlElement = XMLParser.createDocument().createElement(element.getNodeName().toLowerCase());
Map<String, String> styles = styleSocket.getStyles(xmlElement);
JavaScriptObject stylesJsArray = JavaScriptObject.createObject();
for (String currKey : styles.keySet()) {
JSArrayUtils.fillArray(stylesJsArray, currKey, styles.get(currKey));
}
return stylesJsArray;
}
示例13: testCreateReportFeedbacksFromNodeList
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
public void testCreateReportFeedbacksFromNodeList() {
// given
NodeList feedbacks = XMLParser.parse(INPUT).getElementsByTagName("reportFeedbackText");
// when
ProgressToStringRangeMap reportFeedbacks = testObj.parse(feedbacks);
// then
assertEquals(reportFeedbacks.getValueForProgress(0), "");
assertEquals(reportFeedbacks.getValueForProgress(10), FEEDBACK_FOR_10_19);
assertEquals(reportFeedbacks.getValueForProgress(99), FEEDBACK_FOR_20_99);
assertEquals(reportFeedbacks.getValueForProgress(100), "");
}
示例14: processLoad
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
protected void processLoad(DataSourceManager dsm, String itemXml) {
String assessmentXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><assessmentTest xmlns=\"http://www.ydp.eu/empiria\" identifier=\"RTEST-13\" title=\"Show player supported functionality\"><testPart><assessmentSection identifier=\"sectionA\" title=\"Section A\" visible=\"true\"><assessmentItemRef identifier=\"inline_choice\" href=\"demo/inline_choice.xml\"/></assessmentSection></testPart></assessmentTest>";
Document assessmentDoc = XMLParser.parse(assessmentXml);
XmlData assessmentData = new XmlData(assessmentDoc, "");
Document itemDoc = XMLParser.parse(itemXml);
XmlData itemData = new XmlData(itemDoc, "");
XmlData[] itemDatas = new XmlData[1];
itemDatas[0] = itemData;
dsm.loadData(assessmentData, itemDatas);
}
示例15: testStyleDataSourceManager
import com.google.gwt.xml.client.XMLParser; //导入依赖的package包/类
public void testStyleDataSourceManager() {
delayTestFinish(1000);
scriptsLoader.inject(new SynchronousScriptsCallback() {
@Override
public void onLoad() {
Document doc = XMLParser.parse("<orderInteraction responseIdentifier=\"RESPONSE\" shuffle=\"true\" />");
Element e = doc.getDocumentElement();
assertNotNull(testObj);
assertEquals("no styles were added yet", 0, testObj.getStyleProperties(e, true).size());
doc = XMLParser.parse("<customselector />");
e = doc.getDocumentElement();
testObj.addAssessmentStyle(new StyleDocument(CssParser.parseCss(css1), ""));
testObj.addItemStyle(0, new StyleDocument(CssParser.parseCss(css2), ""));
testObj.setCurrentPages(new PageReference(PageType.TEST, new int[]{0}, new FlowOptions(), new DisplayOptions()));
Map<String, String> styles = testObj.getStyleProperties(e, true);
Set<String> keys = styles.keySet();
assertEquals("customProperty has properties only from assessement style", 3, keys.size());
assertFalse("StyleDataSourceManager returns correct style values", styles.containsKey("nonExistingStyle"));
assertTrue("style names are converted to lower case", styles.containsKey("customproperty"));
assertFalse("style names are converted to lower case", styles.containsKey("customProperty"));
testObj.setCurrentPages(new PageReference(PageType.TEST, new int[]{0}, null, null));
styles = testObj.getStyleProperties(e, true);
keys = styles.keySet();
assertEquals("when page is set customProperty has properties from assessement and pages style", 3, keys.size());
assertEquals("assessment style is overriden by page style", "200px", styles.get("width"));
assertEquals("styles added later override existing values", "xyz", styles.get("customproperty"));
finishTest();
}
});
}