本文整理汇总了Java中com.ximpleware.VTDGen.setDoc方法的典型用法代码示例。如果您正苦于以下问题:Java VTDGen.setDoc方法的具体用法?Java VTDGen.setDoc怎么用?Java VTDGen.setDoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ximpleware.VTDGen
的用法示例。
在下文中一共展示了VTDGen.setDoc方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileId
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
private String getFileId(BufferedReader reader) throws IOException, VTDException {
reader.mark(1024);
String str = reader.readLine();
str += "</FILE>";
reader.reset();
byte[] b = str.getBytes("UTF-8");
VTDGen vg = new VTDGen();
vg.setDoc(b);
vg.parse(false);
VTDNav vn = vg.getNav();
require(vn.toElement(VTDNav.ROOT));
String fileId = vn.toString(vn.getAttrVal(AgigaConstants.FILE_ID));
return fileId;
}
示例2: getNonTextContent
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
/**
* Get rPh & phoneticPr Element fragment
* @return ;
*/
private String getNonTextContent(){
StringBuffer result = new StringBuffer();
VTDGen vg = new VTDGen();
vg.setDoc(content.getBytes());
VTDUtils vu = null;
try {
vg.parse(true);
vu = new VTDUtils(vg.getNav());
AutoPilot ap = new AutoPilot(vu.getVTDNav());
ap.selectXPath("/si/rPh | phoneticPr");
while(ap.evalXPath() != -1){
result.append(vu.getElementFragment());
}
} catch (VTDException e) {
e.printStackTrace();
}
return result.toString();
}
示例3: getTagId
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
/**
* 根据一个<g>标记的头部获取标记的 id 属性值
* @param tagStr
* @return
*/
private String getTagId(String tagStr) throws Exception {
String tagId = "";
VTDGen vg = new VTDGen();
vg.setDoc(tagStr.getBytes());
vg.parse(false);
VTDNav vn = vg.getNav();
tagAP = new AutoPilot(vn);
tagAP.selectXPath("/g");
int index = -1;
if (tagAP.evalXPath() != -1) {
if ((index = vn.getAttrVal("id")) != -1) {
tagId = vn.toRawString(index);
}
}
return tagId;
}
示例4: getLanguages
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
/**
* ,针对插件开发模块 robert 2012-03-15
* @param langXMlLC
* @param _languages
* @throws Exception
*/
private static void getLanguages(String langXMlLC, Hashtable<String, String> _languages) throws Exception {
VTDGen vg = new VTDGen();
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(langXMlLC)));
vg.parse(true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/languages/lang");
while (ap.evalXPath() != -1) {
if (vn.getAttrVal("code") != -1 && vn.getText() != -1) {
_languages.put(vn.toString(vn.getAttrVal("code")).toLowerCase(), vn.toString(vn.getText()).trim());
}
}
}
示例5: loadCellText
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
/**
* 加载Cell的文本内容
* @param content
* @return ;
*/
private String loadCellText(String content) {
String result = "";
VTDGen vg = new VTDGen();
vg.setDoc(content.getBytes());
VTDUtils vu = null;
try {
vg.parse(true);
vu = new VTDUtils(vg.getNav());
AutoPilot ap = new AutoPilot(vu.getVTDNav());
ap.selectXPath("/si/r");
if (ap.evalXPath() != -1) {
StringBuffer bf = new StringBuffer();
do {
String tVal = vu.getChildContent("t");
bf.append(tVal);
} while (ap.evalXPath() != -1);
result = bf.toString();
} else {
vu.pilot("/si/t");
result = vu.getElementContent();
}
} catch (VTDException e) {
e.printStackTrace();
}
return result;
}
示例6: loadXML
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
private void loadXML() {
VTDGen vg = new VTDGen();
vg.setDoc(this.xmlContent.getBytes());
try {
vg.parse(true);
vu = new VTDUtils(vg.getNav());
xm = new XMLModifier(vu.getVTDNav());
} catch (VTDException e) {
logger.error("",e);
}
}
示例7: getSheets
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
/**
* Method to get all sheets from which data was requested.
*
* @param workBook excel document
* @param xssfReader package reader of POI
* @param sheetName name of excel sheet
* @return list of sheets as {@code LinkedHashMap<String, InputStream>}
* @throws IOException can't open file
* @throws EncodingException
* @throws EOFException
* @throws EntityException
* @throws ParseException
* @throws XPathParseException
* @throws XPathEvalException
* @throws NavException
* @throws InvalidFormatException not an OOXML file
*/
private LinkedHashMap<String, InputStream> getSheets(InputStream workBook,
XSSFReader xssfReader, String sheetName) throws IOException, EncodingException,
EOFException, EntityException, ParseException, XPathParseException, XPathEvalException,
NavException, InvalidFormatException {
LinkedHashMap<String, InputStream> sheets = new LinkedHashMap<String, InputStream>();
String relationshipNS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
VTDGen wbkVg = new VTDGen();
byte[] wbByteArr = IOUtils.toByteArray(workBook);
wbkVg.setDoc(wbByteArr);
wbkVg.parse(true);
VTDNav wbVn = wbkVg.getNav();
AutoPilot wbAp = new AutoPilot(wbVn);
wbAp.declareXPathNameSpace("r", relationshipNS);
if (sheetName.equals("*")) {
wbAp.selectXPath("/workbook/sheets/sheet");
} else {
wbAp.selectXPath("/workbook/sheets/sheet[@name=\"" + sheetName + "\"]");
}
while (wbAp.evalXPath() != -1) {
String relId = wbVn.toRawString(wbVn.getAttrValNS(relationshipNS, "id"));
String curSheetName = wbVn.toRawString(wbVn.getAttrVal("name"));
sheets.put(curSheetName, xssfReader.getSheet(relId));
}
if (sheets.isEmpty()) {
throw new WebApplicationException(404);
}
return sheets;
}
示例8: SharedStringsData
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
public SharedStringsData(XSSFReader xssfReader) throws InvalidFormatException, IOException,
EncodingException, EOFException, EntityException, ParseException {
VTDGen sstVg = new VTDGen();
byte[] sstData = IOUtils.toByteArray(xssfReader.getSharedStringsData());
sstVg.setDoc(sstData);
sstVg.parse(true);
sstVn = sstVg.getNav();
sstAp = new AutoPilot(sstVn);
}
示例9: processTextParagraphs
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
/**
* Processing of requests to text paragraphs
*
* @param document main XML document as byte array
* @param resID resource ID to set BaseURI
* @param paragraphRef position of requested paragraph (start at 0)
* @return list of values as {@code ValueExchangeExt}
* @throws EncodingException
* @throws EOFException
* @throws EntityException
* @throws ParseException
* @throws XPathParseException
* @throws NavException
* @throws XPathEvalException
*/
private ValueExchangeExt processTextParagraphs(byte[] document, String resID,
String requestType, String paraRef) throws EncodingException, EOFException,
EntityException, ParseException, XPathParseException, XPathEvalException, NavException {
ValueExchangeExt valList = new ValueExchangeExt();
valList.setBaseURI("/" + resID + "/" + requestType + "/");
VTDGen vg = new VTDGen();
vg.setDoc(document);
vg.parse(true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
declareNameSpaces(ap);
setStartEndParagraph(paraRef, "*");
// element list for evaluation of subtree
ArrayList<String> elements = new ArrayList<String>();
elements.add("w:p");
// list of according indexes of subtree elements, "*" if all elements
ArrayList<EvalRange> elementIndex = new ArrayList<EvalRange>();
elementIndex.add(new EvalRange(this.startPara, this.endPara));
// XPath expression for evaluation
String xpathExp = "/w:document/w:body";
ap.selectXPath(xpathExp);
// prefix to build subURI
String pathPrefix = new String();
while (ap.evalXPath() != -1) {
// evaluate subtree of selected node
valList.addValues(evalSubTree(ap, vn, elements, elementIndex, 0, pathPrefix));
}
return valList;
}
示例10: plugin_loadCoutries
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
/**
* 加载国家名称,针对插件开发模块 robert 2012-03-15
* @param langXMlLC
* @param _languages
* @throws Exception
*/
public static Hashtable<String, String> plugin_loadCoutries() throws Exception {
// 国家文件位置
String countryXmlLC = CoreActivator.ISO3166_1_PAHT;
Hashtable<String, String> _countries = new Hashtable<String, String>();
VTDGen vg = new VTDGen();
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(countryXmlLC)));
vg.parse(true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
AutoPilot childAP = new AutoPilot(vn);
ap.selectXPath("/ISO_3166-1_List_en/ISO_3166-1_Entry");
while (ap.evalXPath() != -1) {
String code = "";
String name = "";
int index;
vn.push();
childAP.selectXPath("./ISO_3166-1_Alpha-2_Code_element");
if (childAP.evalXPath() != -1) {
if ((index = vn.getText()) != -1) {
code = vn.toString(index).trim().toUpperCase();
}
}
vn.pop();
vn.push();
childAP.selectXPath("./ISO_3166-1_Country_name");
if (childAP.evalXPath() != -1) {
if ((index = vn.getText()) != -1) {
name = vn.toString(index).trim();
}
}
vn.pop();
if (!"".equals(code) && !"".equals(name)) {
_countries.put(code, name);
}
}
return _countries;
}
示例11: replacePH
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
/**
* 处理 ph 节点
* @return
* @throws Exception
*/
private String replacePH(String phFrag) throws Exception{
String replaceText = "";
VTDGen vg = new VTDGen();
vg.setDoc(phFrag.getBytes());
vg.parse(true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
VTDUtils vu = new VTDUtils(vn);
ap.selectXPath("/ph");
String phContent = "";
int attrIdx = -1;
String utType = "";
String edgeStr = "";
if (ap.evalXPath() != -1) {
phContent = vu.getElementContent();
// 有type属性的,一般是cf标记
if ((attrIdx = vn.getAttrVal("type")) != -1) {
if ("cf".equals(vn.toString(attrIdx))) {
// 这个cf是开始还是结束<cf size="11" complexscriptssize="11">
if (phContent.indexOf("<cf") != -1) {
utType = "start";
edgeStr = "RightEdge=\"angle\"";
}else {
utType = "end";
edgeStr = "LeftEdge=\"angle\"";
}
replaceText += "<ut Type=\"" + utType + "\" "+ edgeStr +" DisplayText=\"cf\">" + phContent + "</ut>";
}
}else {
//没有type的,是其他标记,如<symbol font="Symbol" character="F0E2"/>
String tagName = "";
int startIdx = -1;
int endIdx = -1;
// 针对起始标记如<symbol font="Symbol" character="F0E2"/>
if ((startIdx = phContent.trim().indexOf("<")) != -1) {
//针对结束标记如</null?>
if ("/".equals(phContent.trim().substring(startIdx + 4, startIdx + 5))) {
tagName = phContent.trim().substring(startIdx + 5, phContent.trim().indexOf(">"));
utType = "end";
edgeStr = " LeftEdge=\"angle\"";
}else {
if ((endIdx = phContent.trim().indexOf(" ")) != -1) {
tagName = phContent.trim().substring(startIdx + 4, endIdx);
if (phContent.indexOf("/>") != -1) {
utType = "";
}else {
utType = "start";
edgeStr = " RightEdge=\"angle\"";
}
}else if((endIdx = phContent.trim().indexOf("/")) != -1) {
//针对没有空格的如<ph><field/></ph>
tagName = phContent.trim().substring(startIdx + 4, phContent.trim().indexOf("/"));
utType = "";
}else{
//针对 <field>
tagName = phContent.trim().substring(startIdx + 4, phContent.trim().indexOf(">"));
utType = "start";
edgeStr = " RightEdge=\"angle\"";
}
}
}
String utTypeAttrStr = utType.length() > 0 ? " Type=\""+utType+"\"" : "";
replaceText = "<ut"+ utTypeAttrStr + edgeStr +" DisplayText=\"" + tagName + "\">" + phContent + "</ut>";
}
}
return replaceText;
}
示例12: replacePH
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
/**
* 处理 ph 节点
* @return
* @throws Exception
*/
private String replacePH(String phFrag) throws Exception{
String replaceText = "";
VTDGen vg = new VTDGen();
vg.setDoc(phFrag.getBytes());
vg.parse(true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
VTDUtils vu = new VTDUtils(vn);
ap.selectXPath("/ph");
String phContent = "";
int attrIdx = -1;
String utType = "";
String edgeStr = "";
if (ap.evalXPath() != -1) {
phContent = vu.getElementContent();
// 有type属性的,一般是cf标记
if ((attrIdx = vn.getAttrVal("type")) != -1) {
if ("cf".equals(vn.toString(attrIdx))) {
// 这个cf是开始还是结束<cf size="11" complexscriptssize="11">
if (phContent.indexOf("<cf") != -1) {
utType = "start";
edgeStr = "RightEdge=\"angle\"";
}else {
utType = "end";
edgeStr = "LeftEdge=\"angle\"";
}
replaceText += "<ut Type=\"" + utType + "\" "+ edgeStr +" DisplayText=\"cf\">" + cleanString(phContent) + "</ut>";
}
}else {
//没有type的,是其他标记,如<symbol font="Symbol" character="F0E2"/>
String tagName = "";
int startIdx = -1;
int endIdx = -1;
// 针对起始标记如<symbol font="Symbol" character="F0E2"/>
if ((startIdx = phContent.trim().indexOf("<")) != -1) {
//针对结束标记如</null?>
if ("/".equals(phContent.trim().substring(startIdx + 4, startIdx + 5))) {
tagName = phContent.trim().substring(startIdx + 5, phContent.trim().indexOf(">"));
utType = "end";
edgeStr = " LeftEdge=\"angle\"";
}else {
if ((endIdx = phContent.trim().indexOf(" ")) != -1) {
tagName = phContent.trim().substring(startIdx + 4, endIdx);
if (phContent.indexOf("/>") != -1) {
utType = "";
}else {
utType = "start";
edgeStr = " RightEdge=\"angle\"";
}
}else if((endIdx = phContent.trim().indexOf("/")) != -1) {
//针对没有空格的如<ph><field/></ph>
tagName = phContent.trim().substring(startIdx + 4, phContent.trim().indexOf("/"));
utType = "";
}else{
//针对 <field>
tagName = phContent.trim().substring(startIdx + 4, phContent.trim().indexOf(">"));
utType = "start";
edgeStr = " RightEdge=\"angle\"";
}
}
}
String utTypeAttrStr = utType.length() > 0 ? " Type=\""+utType+"\"" : "";
replaceText = "<ut"+ utTypeAttrStr + edgeStr +" DisplayText=\"" + tagName + "\">" + cleanString(phContent) + "</ut>";
}
}
return replaceText;
}
示例13: evalSheet
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
/**
* Method that evaluates the XPath expression for a single worksheet.
*
* @param sheetAp VTD auto pilot for XPath evaluation
* @param sheetVn VTD navigator
* @param sharedStrings - shared string table of excel document
* @param styles styles table of excel document
* @param pathPrefix prefix of subURI
* @return list of sheet values as {@code LinkedList<Value>}
* @throws EncodingException
* @throws EOFException
* @throws EntityException
* @throws ParseException
* @throws XPathEvalException
* @throws NavException
* @throws XPathParseException
*/
private LinkedList<Value> evalSheet(byte[] sheet, String xpathExp, String reference,
StylesTable styles, String pathPrefix) throws EncodingException, EOFException,
EntityException, ParseException, XPathEvalException, NavException, XPathParseException {
LinkedList<Value> sheetValues = new LinkedList<Value>();
// setup VTD
VTDGen sheetVg = new VTDGen();
sheetVg.setDoc(sheet);
sheetVg.parse(true);
VTDNav sheetVn = sheetVg.getNav();
AutoPilot sheetAp = new AutoPilot(sheetVn);
sheetAp.selectXPath(xpathExp);
// evaluate XPath and select cells
// a cell can hold information about location (reference), value, data
// type, formatting, and formula
while (sheetAp.evalXPath() != -1) {
// move to first cell
if (sheetVn.toElement(VTDNav.FIRST_CHILD)) {
// iterate cells
while (moveToSibling(sheetVn, "c")) {
Value cellValue = null;
String cellRef = "";
if (sheetVn.hasAttr("r")) {
cellRef = sheetVn.toRawString(sheetVn.getAttrVal("r"));
if (this.tableArea.getColStart() == -1) {
cellValue = evalCell(sheetVn, styles, cellRef, pathPrefix);
} else {
// replaces empty character between letters and
// digits with ";" and split both parts
String[] cellRefTokens = cellRef.replaceAll("(?<=\\p{L})(?=\\d)", ";")
.split(";");
Integer colID = ResourceHelper.convertColRefToColNum(cellRefTokens[0]);
if (this.tableArea.getColStart() <= colID
&& colID <= this.tableArea.getColEnd()) {
cellValue = evalCell(sheetVn, styles, cellRef, pathPrefix);
}
}
}
// add value to list
if (cellValue != null)
sheetValues.add(cellValue);
// stop if no other siblings
if (!sheetVn.toElement(VTDNav.NEXT_SIBLING)) {
break;
}
}
// move back to cell
sheetVn.toElement(VTDNav.PARENT);
}
}
return sheetValues;
}