当前位置: 首页>>代码示例>>Java>>正文


Java XMLParser类代码示例

本文整理汇总了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);
        }
    });
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:25,代码来源:PlayerLoader.java

示例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);
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:30,代码来源:Assessment.java

示例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);
                }
            }
        });

    }
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:26,代码来源:XmlDocument.java

示例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"));
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:23,代码来源:StyleLinkDeclarationGWTTestCase.java

示例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();
        }
    });
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:27,代码来源:StyleDataSourceManagerGWTTestCase.java

示例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);
    }
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:25,代码来源:VariableManagerGWTTestCase.java

示例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());
  }    
}
 
开发者ID:tomayac,项目名称:rest-describe-and-compile,代码行数:29,代码来源:WadlParser.java

示例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;
}
 
开发者ID:growbit,项目名称:turbogwt-http,代码行数:26,代码来源:BookXmlSerdes.java

示例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());
}
 
开发者ID:MirrorIP,项目名称:activity-recommendation-app,代码行数:24,代码来源:SessionObject.java

示例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();
}
 
开发者ID:opensciencemap,项目名称:vtm,代码行数:18,代码来源:MyXMLReader.java

示例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);
  }
}
 
开发者ID:mwl,项目名称:gwt-upload,代码行数:18,代码来源:Uploader.java

示例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;
    }
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:13,代码来源:JsStyleSocketUserExtension.java

示例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), "");
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:14,代码来源:ReportFeedbacksParserGWTTestCase.java

示例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);
    }
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:14,代码来源:DataSourceManagerGWTTestCase.java

示例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();
        }
    });
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:37,代码来源:StyleDataSourceManagerGWTTestCase.java


注:本文中的com.google.gwt.xml.client.XMLParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。