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


Java Document类代码示例

本文整理汇总了Java中org.kxml2.kdom.Document的典型用法代码示例。如果您正苦于以下问题:Java Document类的具体用法?Java Document怎么用?Java Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Document类属于org.kxml2.kdom包,在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getXMLResponse

import org.kxml2.kdom.Document; //导入依赖的package包/类
public static Document getXMLResponse (Reader reader) {
    Document doc = new Document();

    try{
        KXmlParser parser = new KXmlParser();
        parser.setInput(reader);
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

        doc.parse(parser);
    } catch (Exception e) {
        System.err.println("couldn't process response payload from server!!");
        doc = null;
    }

    try {
        doc.getRootElement();
    } catch (RuntimeException re) {
        doc = null; //work around kxml bug where it should have failed to parse xml (doc == null)
                    //but instead returned an empty doc that throws an exception when you try to
                    //get its root element
    }

    return doc;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:25,代码来源:CommUtil.java

示例2: generateXmlManifestList

import org.kxml2.kdom.Document; //导入依赖的package包/类
public void generateXmlManifestList(PrintWriter output, CallingContext cc) throws IOException, ODKDatastoreException {
  Document d = new Document();
  d.setStandalone(true);
  d.setEncoding(HtmlConsts.UTF8_ENCODE);
  Element e = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.MANIFEST_TAG);
  e.setPrefix(null, XML_TAG_NAMESPACE);
  d.addChild(0, Node.ELEMENT, e);
  int idx = 0;
  e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);

  // build XML table of form information
  BinaryContentManipulator manifest = form.getManifestFileset();
  if ( manifest != null ) {
      int fileCount = manifest.getAttachmentCount(cc);
      for ( int i = 1 ; i <= fileCount ; ++i ) {
        idx = generateManifestXmlEntry(d, e, idx, form.getUri(), manifest, i, cc);
      }
  }

  KXmlSerializer serializer = new KXmlSerializer();
  serializer.setOutput(output);
  // setting the response content type emits the xml header.
  // just write the body here...
  d.writeChildren(serializer); 
  serializer.flush();
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:27,代码来源:XFormsManifestXmlTable.java

示例3: generateXmlListOfForms

import org.kxml2.kdom.Document; //导入依赖的package包/类
public void generateXmlListOfForms(PrintWriter output, CallingContext cc) throws IOException, ODKDatastoreException {
  Document d = new Document();
  d.setStandalone(true);
  d.setEncoding(HtmlConsts.UTF8_ENCODE);
  Element e = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.XFORMS_TAG);
  e.setPrefix(null, XML_TAG_NAMESPACE);
  d.addChild(0, Node.ELEMENT, e);
  int idx = 0;
  e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);

  // build XML table of form information
  for (IForm form : forms) {
    if (!form.hasValidFormDefinition() || !form.getDownloadEnabled())
      continue;

    idx = generateFormXmlEntry(d, e, idx, form, cc);
  }

  KXmlSerializer serializer = new KXmlSerializer();
  serializer.setOutput(output);
  // setting the response content type emits the xml header.
  // just write the body here...
  d.writeChildren(serializer);
  serializer.flush();
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:26,代码来源:XFormsXmlTable.java

示例4: loadXmlInstance

import org.kxml2.kdom.Document; //导入依赖的package包/类
/**
 * Load a compatible xml instance into FormDef f
 *
 * call before f.initialize()!
 */
public static void loadXmlInstance(FormDef f, Document xmlInst) {
       TreeElement savedRoot = XFormParser.restoreDataModel(xmlInst, null).getRoot();
       TreeElement templateRoot = f.getMainInstance().getRoot().deepCopy(true);

       // weak check for matching forms
       // TODO: should check that namespaces match?
    if (!savedRoot.getName().equals(templateRoot.getName()) || savedRoot.getMult() != 0) {
    	throw new RuntimeException("Saved form instance does not match template form definition");
    }

    // populate the data model
    TreeReference tr = TreeReference.rootRef();
    tr.add(templateRoot.getName(), TreeReference.INDEX_UNBOUND);
    templateRoot.populate(savedRoot, f);

    // populated model to current form
    f.getMainInstance().setRoot(templateRoot);

    // if the new instance is inserted into the formdef before f.initialize() is called, this
    // locale refresh is unnecessary
    //   Localizer loc = f.getLocalizer();
    //   if (loc != null) {
    //       f.localeChanged(loc.getLocale(), loc);
    //	 }
}
 
开发者ID:medic,项目名称:javarosa,代码行数:31,代码来源:XFormParser.java

示例5: readResponse

import org.kxml2.kdom.Document; //导入依赖的package包/类
public User readResponse(SimpleHttpTransportMessage message) throws UnrecognizedResponseException {
    this.prompt = null;

    byte[] responseBody = message.getResponseBody();

    //Not actually a response
    if(responseBody == null) {
        throw new UnrecognizedResponseException("No response body");
    }

    String responseVersion = message.getResponseProperties().getORApiVersion();
    if(responseVersion == null) {
        //If there's no version from the server, assume it's the same as the
        //sent version
        responseVersion = orApiVersion;
    }

    Document doc = CommUtil.getXMLResponse(responseBody);
    if (doc == null) {
        throw new UnrecognizedResponseException("can't parse xml");
    }

    return readResponseDocument(doc);
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:25,代码来源:HttpUserRegistrationTranslator.java

示例6: loadXmlInstance

import org.kxml2.kdom.Document; //导入依赖的package包/类
/**
 * Load a compatible xml instance into FormDef f
 *
 * call before f.initialize()!
 */
public static void loadXmlInstance(FormDef f, Document xmlInst) {
    TreeElement savedRoot = XFormParser.restoreDataModel(xmlInst, null).getRoot();
    TreeElement templateRoot = f.getMainInstance().getRoot().deepCopy(true);

    // weak check for matching forms
    // TODO: should check that namespaces match?
    if (!savedRoot.getName().equals(templateRoot.getName()) || savedRoot.getMult() != 0) {
        throw new RuntimeException("Saved form instance does not match template form definition");
    }

    // populate the data model
    TreeReference tr = TreeReference.rootRef();
    tr.add(templateRoot.getName(), TreeReference.INDEX_UNBOUND);
    templateRoot.populate(savedRoot);

    // populated model to current form
    f.getMainInstance().setRoot(templateRoot);

    // if the new instance is inserted into the formdef before f.initialize() is called, this
    // locale refresh is unnecessary
    //   Localizer loc = f.getLocalizer();
    //   if (loc != null) {
    //       f.localeChanged(loc.getLocale(), loc);
    //     }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:31,代码来源:XFormParser.java

示例7: compareCaseDbState

import org.kxml2.kdom.Document; //导入依赖的package包/类
private void compareCaseDbState(String inputTransactions,
                                String caseDbState) throws Exception {
        ParseUtils.parseIntoSandbox(this.getClass().getResourceAsStream(inputTransactions), sandbox);

    EvaluationContext ec =
        MockDataUtils.buildContextWithInstance(this.sandbox, "casedb", CaseTestUtils.CASE_INSTANCE);
    Assert.assertTrue(CaseTestUtils.xpathEvalAndCompare(ec, "instance('casedb')/casedb/case[@case_id = 'case_one']/case_name", "case"));

    byte[] parsedDb = serializeCaseInstanceFromSandbox(sandbox);
    Document parsed = XmlComparator.getDocumentFromStream(new ByteArrayInputStream(parsedDb));
    Document loaded = XmlComparator.getDocumentFromStream(this.getClass().getResourceAsStream(caseDbState));

    try {
        XmlComparator.isDOMEqual(parsed, loaded);
    } catch(Exception e) {
        System.out.print(new String(parsedDb));

        //NOTE: The DOM's definitely don't match here, so the strings cannot be the same.
        //The reason we are asserting equality is because the delta between the strings is
        //likely to do a good job of contextualizing where the DOM's don't match.
        Assert.assertEquals("CaseDB output did not match expected structure(" + e.getMessage() + ")", new String(dumpStream(caseDbState)), new String(parsedDb));
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:24,代码来源:CaseParseAndReadTest.java

示例8: compareCaseDbState

import org.kxml2.kdom.Document; //导入依赖的package包/类
private void compareCaseDbState(String inputTransactions,
                                String caseDbState) throws Exception {
    config.parseIntoSandbox(this.getClass().getResourceAsStream(inputTransactions), sandbox, false);

    byte[] parsedDb = serializeCaseInstanceFromSandbox(sandbox);
    Document parsed = XmlComparator.getDocumentFromStream(new ByteArrayInputStream(parsedDb));
    Document loaded = XmlComparator.getDocumentFromStream(this.getClass().getResourceAsStream(caseDbState));

    try {
        XmlComparator.isDOMEqual(parsed, loaded);
    } catch(Exception e) {
        System.out.print(new String(parsedDb));

        //NOTE: The DOM's definitely don't match here, so the strings cannot be the same.
        //The reason we are asserting equality is because the delta between the strings is
        //likely to do a good job of contextualizing where the DOM's don't match.
        Assert.assertEquals("CaseDB output did not match expected structure(" + e.getMessage() + ")", new String(dumpStream(caseDbState)), new String(parsedDb));
    }
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:20,代码来源:CaseParseAndReadTest.java

示例9: parseFormDefinition

import org.kxml2.kdom.Document; //导入依赖的package包/类
private static synchronized final XFormParserWithBindEnhancements parseFormDefinition(String xml,
    BaseFormParserForJavaRosa parser) throws ODKIncompleteSubmissionData {

  StringReader isr = null;
  try {
    isr = new StringReader(xml);
    Document doc = XFormParser.getXMLDocument(isr);
    return new XFormParserWithBindEnhancements(parser, doc);
  } catch (Exception e) {
    throw new ODKIncompleteSubmissionData(e, Reason.BAD_JR_PARSE);
  } finally {
    isr.close();
  }
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:15,代码来源:BaseFormParserForJavaRosa.java

示例10: generateManifestXmlEntry

import org.kxml2.kdom.Document; //导入依赖的package包/类
private int generateManifestXmlEntry(Document d, Element e, int idx, String uri, BinaryContentManipulator m, int i, CallingContext cc) throws ODKDatastoreException {
    String filename = m.getUnrootedFilename(i, cc);
    String hash = m.getContentHash(i, cc);

    // if we don't have the file (hash==null), then don't emit anything.
    if ( hash == null ) return idx;
    
    int feIdx = 0;
    Element fileEntryElement = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.MEDIA_FILE_TAG);
    e.addChild(idx++, Node.ELEMENT, fileEntryElement);
    Element fileNameElement = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.FILE_NAME_TAG);
    fileEntryElement.addChild(feIdx++, Node.ELEMENT, fileNameElement);
    fileNameElement.addChild(0, Node.TEXT, filename);
    Element hashElement = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.HASH_TAG);
    fileEntryElement.addChild(feIdx++, Node.ELEMENT, hashElement);
    hashElement.addChild(0, Node.TEXT, hash);
    Element downloadElement = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.DOWNLOAD_URL_TAG);
    fileEntryElement.addChild(feIdx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
    fileEntryElement.addChild(feIdx++, Node.ELEMENT, downloadElement);
    {
      Map<String, String> properties = new HashMap<String, String>();
      SubmissionKey k = FormInfo.getManifestSubmissionKey(uri, i);
      properties.put(ServletConsts.BLOB_KEY, k.toString());
      properties.put(ServletConsts.AS_ATTACHMENT, "true");
      String urlLink = HtmlUtil.createLinkWithProperties(downloadRequestURL, properties);
      downloadElement.addChild(0, Node.TEXT, urlLink);
    }
    e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
    return idx;
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:31,代码来源:XFormsManifestXmlTable.java

示例11: emitXmlWrappedCsv

import org.kxml2.kdom.Document; //导入依赖的package包/类
private void emitXmlWrappedCsv(List<Row> resultTable, List<String> headers) throws IOException {

    Document d = new Document();
    d.setStandalone(true);
    d.setEncoding(HtmlConsts.UTF8_ENCODE);
    Element e = d.createElement(XML_TAG_NAMESPACE, XML_TAG_ENTRIES);
    d.addChild(0, Node.ELEMENT, e);
    int idx = 0;
    e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
    if (websafeCursorString != null) {
      Element cursor = d.createElement(XML_TAG_NAMESPACE, XML_TAG_CURSOR);
      e.addChild(idx++, Node.ELEMENT, cursor);
      cursor.addChild(0, Node.TEXT, websafeCursorString);
      e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
    }
    Element header = d.createElement(XML_TAG_NAMESPACE, XML_TAG_HEADER);
    e.addChild(idx++, Node.ELEMENT, header);
    header.addChild(0, Node.TEXT, generateCommaSeperatedElements(headers));
    e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);

    Element resultRow;
    // generate rows
    for (Row row : resultTable) {
      resultRow = d.createElement(XML_TAG_NAMESPACE, XML_TAG_RESULT);
      e.addChild(idx++, Node.ELEMENT, resultRow);
      String csvRow = generateCommaSeperatedElements(row.getFormattedValues());
      resultRow.addChild(0, Node.TEXT, csvRow);
      e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
    }

    KXmlSerializer serializer = new KXmlSerializer();
    serializer.setOutput(output);
    // setting the response content type emits the xml header.
    // just write the body here...
    d.writeChildren(serializer);
    serializer.flush();
  }
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:38,代码来源:FragmentedCsvFormatter.java

示例12: generateInstanceSchema

import org.kxml2.kdom.Document; //导入依赖的package包/类
public static Document generateInstanceSchema (FormDef f) {
	init();

	Element schema = new Element();
	schema.setName("schema");
	schema.setNamespace("http://www.w3.org/2001/XMLSchema");
	schema.setPrefix("", "http://www.w3.org/2001/XMLSchema");
	schema.setPrefix("jr", "http://openrosa.org/javarosa");
	if (f.getInstance().schema != null) {
		schema.setAttribute(null, "targetNamespace", f.getInstance().schema);
	} else {
		System.err.println("Warning: instance has no schema");
	}
	schema.setAttribute(null, "elementFormDefault", "qualified");

	String formVersion = f.getInstance().formVersion;
	String uiVersion = f.getInstance().uiVersion;
	if (formVersion != null)
		schema.setAttribute(null, "version", formVersion);
	if (uiVersion != null)
		schema.setAttribute(null, "uiVersion", uiVersion);

	processSelectChoices(schema, f, f);
	schema.addChild(Node.ELEMENT, schemizeInstance(f.getInstance().getRoot()));

	Document schemaXML = new Document();
	schemaXML.addChild(Node.ELEMENT, schema);

	return schemaXML;
}
 
开发者ID:medic,项目名称:javarosa,代码行数:31,代码来源:InstanceSchema.java

示例13: visit

import org.kxml2.kdom.Document; //导入依赖的package包/类
public void visit(FormInstance tree) {
	theXmlDoc = new Document();
	//TreeElement root = tree.getRoot();

	TreeElement root = tree.resolveReference(rootRef);

	//For some reason resolveReference won't ever return the root, so we'll
	//catch that case and just start at the root.
	if(root == null) {
		root = tree.getRoot();
	}

	if (root != null) {
		theXmlDoc.addChild(Node.ELEMENT, serializeNode(root));
	}

	Element top = theXmlDoc.getElement(0);

	String[] prefixes = tree.getNamespacePrefixes();
	for(int i = 0 ; i < prefixes.length; ++i ) {
		top.setPrefix(prefixes[i], tree.getNamespaceURI(prefixes[i]));
	}
	if (tree.schema != null) {
		top.setNamespace(tree.schema);
		top.setPrefix("", tree.schema);
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:28,代码来源:XFormSerializingVisitor.java

示例14: restoreDataModel

import org.kxml2.kdom.Document; //导入依赖的package包/类
public static FormInstance restoreDataModel (InputStream input, Class restorableType) throws IOException {
	Document doc = getXMLDocument(new InputStreamReader(input));
	if (doc == null) {
		throw new RuntimeException("syntax error in XML instance; could not parse");
	}
	return restoreDataModel(doc, restorableType);
}
 
开发者ID:medic,项目名称:javarosa,代码行数:8,代码来源:XFormParser.java

示例15: getStream

import org.kxml2.kdom.Document; //导入依赖的package包/类
public static ByteArrayOutputStream getStream(Document doc) {
	KXmlSerializer serializer = new KXmlSerializer();
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	DataOutputStream dos = new DataOutputStream(bos);
	try {
		serializer.setOutput(dos, null);
		doc.write(serializer);
		serializer.flush();
		return bos;
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:15,代码来源:XFormSerializer.java


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