@@ -39,6 +39,7 @@ public class WpsWordUtils {
}
public static List < WpsWordJudgementDto > getWordInfo ( List < WpsWordReqDto > wpsWordReqDtos ) throws Exception {
String filePath = wpsWordReqDtos . get ( 0 ) . getFilePath ( ) ;
// 创建返回数组
List < WpsWordJudgementDto > judgementList = new ArrayList < > ( ) ;
// 创建文件路径数组
@@ -72,38 +73,40 @@ public class WpsWordUtils {
// 开始查询标签
// 1、段落
if ( " 0 " . equals ( wpsWordReqDto . getBelongTo ( ) ) ) {
StringBuilder function = new StringBuilder ( ) ;
StringBuilder functionAll = new StringBuilder ( ) ;
StringBuilder chineseName = new StringBuilder( ) ;
for ( WpsWordChineseFunctionDto functions : wpsWordReqDto . getFunction ( ) ) {
function . append ( functions . getFunction ( ) ) ;
functionAll . append ( " - " ) . append ( functions. getFunction( ) ) ;
chineseName . append( functions. getChineseName ( ) ) . append ( " - " ) ;
}
String function = wpsWordReqDto . getFunction ( ) ;
// StringBuilder functionAll = new StringBuilder() ;
String chineseName = wpsWordReqDto . getName ( ) ;
// for (WpsWordChineseFunctionDto functions : wpsWordReqDto.getFunction()) {
// function.append( functions. getFunction()) ;
// functionAll.append("-"). append( functions.getFunction()) ;
// chineseName.append(functions.getChineseName()).append("-");
// }
WpsWordJudgementDto judgement = new WpsWordJudgementDto ( ) ;
// 1-1、创建新的数据组
XmlCursor wpCursor = cursor . newCursor ( ) ;
wpCursor . selectPath ( nameSpace + " (// " + wpsWordReqDto . getEnglishName ( ) + function ) ;
wpCursor . selectPath ( nameSpace + function ) ;
if ( wpCursor . toNextSelection ( ) ) {
if ( " 1 " . equals ( wpsWordReqDto . getParameter ( ) ) ) {
judgement . setContentIn ( wpsWordReqDto . getChineseName ( ) + " - " + chineseName + " true " ) ;
judgement . setContent ( wpsWordReqDto . getEnglishName ( ) + functionAll + " -/" + " true " ) ;
if ( " 1 " . equals ( wpsWordReqDto . getIsboo ( ) ) ) {
judgement . setContentIn ( chineseName + " true " ) ;
judgement . setContent ( function + " -/true " ) ;
} else {
String value = wpCursor . getTextValue ( ) ;
judgement . setContentIn ( wpsWordReqDto . getChineseName ( ) + " - " + chineseName + value ) ;
judgement . setContent ( wpsWordReqDto . getEnglishName ( ) + functionAll + " -/ " + value ) ;
judgement . setContentIn ( chineseName + value ) ;
judgement . setContent ( function + " -/ " + value ) ;
}
judgement . setScoreRate ( " 1 " ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getParameter ( ) ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getIsboo ( ) ) ;
// 查询指定值,返回固定的文本
judgementList . add ( judgement ) ;
} else {
// 参数类型( 0: 值; 1: 判断)
if ( " 1 " . equals ( wpsWordReqDto . getParameter ( ) ) ) {
judgement . setContentIn ( wpsWordReqDto . getChineseName ( ) + " - " + chineseName + " false " ) ;
judgement . setContent ( wpsWordReqDto . getEnglishName ( ) + functionAll + " -/" + " false " ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getParameter ( ) ) ;
if ( " 1 " . equals ( wpsWordReqDto . getIsboo ( ) ) ) {
judgement . setContentIn ( chineseName + " false " ) ;
judgement . setContent ( function + " -/false " ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getIsboo ( ) ) ;
judgement . setScoreRate ( " 1 " ) ;
judgementList . add ( judgement ) ;
}
@@ -117,7 +120,7 @@ public class WpsWordUtils {
XmlCursor sectPrCursor = docXml . newCursor ( ) ;
// 内外参数( 0: 内参数; 1: 外参数)
if ( " 1 " . equals ( wpsWordReqDto . getType ( ) ) ) {
sectPrCursor . selectPath ( nameSpace + " (// " + wpsWordReqDto . getEnglishName ( ) + wpsWordReqDto . getFunction ( ) . ge t( 0 ) . getFunction ( ) ) ;
sectPrCursor . selectPath ( nameSpace + wpsWordReqDto . getFunction ( ) . spli t( " # " ) [ 0 ] ) ;
String rId = " " ;
String type = " " ;
List < WordHeaderFooterVo > headerFooterVos = new ArrayList < > ( ) ;
@@ -127,7 +130,7 @@ public class WpsWordUtils {
WordHeaderFooterVo headerFooterVo = new WordHeaderFooterVo ( ) ;
headerFooterVo . setRid ( rId ) ;
headerFooterVo . setType ( type ) ;
headerFooterVo . setXmlType ( wpsWordReqDto . getFunction ( ) . get ( 0 ) . getFunction ( ) );
headerFooterVo . setXmlType ( wpsWordReqDto . getFunction ( ) ) ;
headerFooterVos . add ( headerFooterVo ) ;
}
String fileName = " " ;
@@ -144,12 +147,12 @@ public class WpsWordUtils {
WpsWordJudgementDto judgement = new WpsWordJudgementDto ( ) ;
List < XWPFParagraph > headerpar = header . getParagraphs ( ) ;
XmlCursor headerXml = headerpar . get ( 0 ) . getCTP ( ) . newCursor ( ) ;
headerXml . selectPath ( nameSpace + " ./ " + wpsWordReqDto . getFunction ( ) . ge t( 1 ) . getFunction ( ) ) ;
headerXml . selectPath ( nameSpace + " ./ " + wpsWordReqDto . getFunction ( ) . spli t( " # " ) [ 1 ] ) ;
if ( headerXml . toNextSelection ( ) ) {
String value = headerXml . getTextValue ( ) ;
judgement . setContentIn ( wpsWordReqDto . getChineseName ( ) + " - " + wpsWordReqDto . getFunction ( ) . get ( 0 ) . getChinese Name ( ) + " - " + chineseType + " - " + wpsWordReqDto . getFunction ( ) . get ( 1 ) . getChineseName ( ) + " - " + value ) ;
judgement . setContent ( wpsWordReqDto . getEnglishName ( ) + " - " + wpsWordReqDto . getFunction ( ) . get ( 0 ) . getFunction ( ) + " - " + wpsWordReqDto . getFunction ( ) . get ( 1 ) . getFunction ( ) + " -/ " + value + " - " + headerVo . getType ( ) ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getParameter ( ) ) ;
judgement . setContentIn ( wpsWordReqDto . getName ( ) + " - " + chineseType + " - " + value ) ;
judgement . setContent ( wpsWordReqDto . getFunction ( ) + " -/ " + value + " - " + headerVo . getType ( ) ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getIsboo ( ) ) ;
judgement . setScoreRate ( " 1 " ) ;
judgementList . add ( judgement ) ;
}
@@ -164,12 +167,12 @@ public class WpsWordUtils {
WpsWordJudgementDto judgement = new WpsWordJudgementDto ( ) ;
List < XWPFParagraph > foorerpar = footer . getParagraphs ( ) ;
XmlCursor headerXml = foorerpar . get ( 0 ) . getCTP ( ) . newCursor ( ) ;
headerXml . selectPath ( nameSpace + " ./ " + wpsWordReqDto . getFunction ( ) . ge t( 1 ) . getFunction ( ) ) ;
headerXml . selectPath ( nameSpace + " ./ " + wpsWordReqDto . getFunction ( ) . spli t( " # " ) [ 1 ] ) ;
if ( headerXml . toNextSelection ( ) ) {
String value = headerXml . getTextValue ( ) ;
judgement . setContentIn ( wpsWordReqDto . getChineseName ( ) + " - " + wpsWordReqDto . getFunction ( ) . get ( 0 ) . getChinese Name ( ) + " - " + chineseType + " - " + wpsWordReqDto . getFunction ( ) . get ( 1 ) . getChineseName ( ) + " - " + value ) ;
judgement . setContent ( wpsWordReqDto . getEnglishName ( ) + " - " + wpsWordReqDto . getFunction ( ) . get ( 0 ) . getFunction ( ) + " - " + wpsWordReqDto . getFunction ( ) . get ( 1 ) . getFunction ( ) + " -/ " + value + " - " + headerVo . getType ( ) ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getParameter ( ) ) ;
judgement . setContentIn ( wpsWordReqDto . getName ( ) + " - " + chineseType + " - " + value ) ;
judgement . setContent ( wpsWordReqDto . getFunction ( ) + " -/ " + value + " - " + headerVo . getType ( ) ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getIsboo ( ) ) ;
judgement . setScoreRate ( " 1 " ) ;
judgementList . add ( judgement ) ;
}
@@ -182,13 +185,13 @@ public class WpsWordUtils {
} else {
// 需要查询主页面的方法
XmlCursor sectPrXsml = docXml . newCursor ( ) ;
sectPrXsml . selectPath ( nameSpace + " (// " + wpsWordReqDto . getEnglishName ( ) + wpsWordReqDto . getFunction ( ) . get ( 0 ) . getFunction ( ) + wpsWordReqDto . getFunction ( ) . get ( 1 ) . getFunction ( ) ) ;
sectPrXsml . selectPath ( nameSpace + wpsWordReqDto . getFunction ( ) ) ;
if ( sectPrXsml . toNextSelection ( ) ) {
String value = sectPrXsml . getTextValue ( ) ;
WpsWordJudgementDto judgement = new WpsWordJudgementDto ( ) ;
judgement . setContentIn ( wpsWordReqDto . getChinese Name ( ) +" - " + wpsWordReqDto . getFunction ( ) . get ( 0 ) . getChineseName ( ) + " - " + wpsWordReqDto . getFunction ( ) . get ( 1 ) . getChineseName ( ) + " -/ " + value ) ;
judgement . setContent ( wpsWordReqDto . getEnglishName ( ) + " - " + wpsWordReqDto . getFunction ( ) . get ( 0 ) . getFunction ( ) + " - " + wpsWordReqDto . getFunction ( ) . get ( 1 ) . getFunction ( ) + " -/ " + value ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getParameter ( ) ) ;
judgement . setContentIn ( wpsWordReqDto . getName ( ) + " - " + value ) ;
judgement . setContent ( wpsWordReqDto . getFunction ( ) + " -/ " + value ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getIsboo ( ) ) ;
judgement . setScoreRate ( " 1 " ) ;
judgementList . add ( judgement ) ;
}
@@ -196,39 +199,33 @@ public class WpsWordUtils {
}
// 3、图形
if ( " 2 " . equals ( wpsWordReqDto . getBelongTo ( ) ) ) {
StringBuilder function = new StringBuilder ( ) ;
StringBuilder functionAll = new StringBuilder( ) ;
StringBuilder chineseName = new StringBuilder ( ) ;
for ( WpsWordChineseFunctionDto functions : wpsWordReqDto . getFunction ( ) ) {
function . append ( functions . getFunction ( ) ) ;
functionAll . append ( " - " ) . append ( functions . getFunction ( ) ) ;
chineseName . append ( functions . getChineseName ( ) ) . append ( " - " ) ;
}
String function = wpsWordReqDto . getFunction ( ) ;
// StringBuilder functionAll = new StringBuilder() ;
String chineseName = wpsWordReqDto . getName ( ) ;
WpsWordJudgementDto judgement = new WpsWordJudgementDto ( ) ;
// 1-1、创建新的数据组
XmlCursor wpCursor = cursor . newCursor ( ) ;
System . out . println ( " (// " + wpsWordReqDto . getEnglishName ( ) + function ) ;
wpCursor . selectPath ( nameSpace + " (// " + wpsWordReqDto . getEnglishName ( ) + function ) ;
wpCursor . selectPath ( nameSpace + function ) ;
if ( wpCursor . toNextSelection ( ) ) {
if ( " 1 " . equals ( wpsWordReqDto . getParameter ( ) ) ) {
judgement . setContentIn ( wpsWordReqDto . getChinese Name ( ) + " - " + chineseName + " true " ) ;
judgement . setContent ( wpsWordReqDto . getEnglishName ( ) + functionAll + " -/ " + " true " ) ;
if ( " 1 " . equals ( wpsWordReqDto . getIsboo ( ) ) ) {
judgement . setContentIn ( wpsWordReqDto . getName ( ) + " - " + " true " ) ;
judgement . setContent ( function + " -/ " + " true " ) ;
} else {
String value = wpCursor . getTextValue ( ) ;
judgement . setContentIn ( wpsWordReqDto . getChinese Name ( ) + " - " + chineseName + value ) ;
judgement . setContent ( wpsWordReqDto . getEnglishName ( ) + functionAll + " -/ " + value ) ;
judgement . setContentIn ( wpsWordReqDto . getName ( ) + " - " + value ) ;
judgement . setContent ( function + " -/ " + value ) ;
}
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getParameter ( ) ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getIsboo ( ) ) ;
judgement . setScoreRate ( " 1 " ) ;
// 查询指定值,返回固定的文本
judgementList . add ( judgement ) ;
} else {
// 参数类型( 0: 值; 1: 判断)
if ( " 1 " . equals ( wpsWordReqDto . getParameter ( ) ) ) {
judgement . setContentIn ( wpsWordReqDto . getChinese Name ( ) + " - " + chineseName + " false " ) ;
judgement . setContent ( wpsWordReqDto . getEnglishName ( ) + functionAll + " -/ " + " false " ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getParameter ( ) ) ;
if ( " 1 " . equals ( wpsWordReqDto . getIsboo ( ) ) ) {
judgement . setContentIn ( wpsWordReqDto . getName ( ) + " - " + " false " ) ;
judgement . setContent ( function + " -/ " + " false " ) ;
judgement . setImage ( wpsWordReqDto . getType ( ) + " - " + wpsWordReqDto . getBelongTo ( ) + " - " + wpsWordReqDto . getIsboo ( ) ) ;
judgement . setScoreRate ( " 1 " ) ;
judgementList . add ( judgement ) ;
}
@@ -276,14 +273,14 @@ public class WpsWordUtils {
if ( wpTextXml . toNextSelection ( ) ) {
String secondIdWp = getStringRandom ( ) ;
String text = wpTextXml . getTextValue ( ) ;
setWordInfo ( " 段落 " + wpIndex + " : " + text , " w:p)[ " + wpIndex + " ] " , " w:pPr " , filePath , secondIdWp , firstIdWp , wordInfoReqVos ) ;
setWordInfo ( " 段落 " + wpIndex + " : " + text , " (// w:p)[" + wpIndex + " ] " , " w:pPr " , filePath , secondIdWp , firstIdWp , wordInfoReqVos ) ;
// 使用 。 判断句子
String [ ] texts = text . split ( " 。 " ) ;
int textsIndex = 0 ;
for ( String s : texts ) {
String thirdIdWp = getStringRandom ( ) ;
textsIndex + + ;
setWordInfo ( " 句子 " + textsIndex + " : " + s , " w:p)[ " + wpIndex + " ] " , " w:r " , filePath , thirdIdWp , secondIdWp , wordInfoReqVos ) ;
setWordInfo ( " 句子 " + textsIndex + " : " + s , " (// w:p)[" + wpIndex + " ] " , " w:r " , filePath , thirdIdWp , secondIdWp , wordInfoReqVos ) ;
}
}
}
@@ -299,7 +296,7 @@ public class WpsWordUtils {
while ( wSectPrCursor . toNextSelection ( ) ) {
wSectPrIndex + + ;
String secondIdSectPr = getStringRandom ( ) ;
setWordInfo ( " 节 " + wSectPrIndex , " w:sectPr)[ " + wSectPrIndex + " ] " , " w:sectPr " , filePath , secondIdSectPr , firstIdSectPr , wordInfoReqVos ) ;
setWordInfo ( " 节 " + wSectPrIndex , " (// w:sectPr)[" + wSectPrIndex + " ] " , " w:sectPr " , filePath , secondIdSectPr , firstIdSectPr , wordInfoReqVos ) ;
}
// 3、图形
XmlCursor wDrawingCursor = docXml . newCursor ( ) ;
@@ -312,10 +309,9 @@ public class WpsWordUtils {
wDrawingIndex + + ;
String secondIdDrawing = getStringRandom ( ) ;
XmlCursor wDrawingXml = wDrawingCursor . newCursor ( ) ;
System . out . println ( wDrawingXml . xmlText ( ) ) ;
wDrawingXml . selectPath ( namespace + " .//wp:anchor/wp:docPr/@name " ) ;
if ( wDrawingXml . toNextSelection ( ) ) {
setWordInfo ( " 图形 " + wDrawingIndex + " : " + wDrawingXml . getTextValue ( ) , " w:drawing)[ " + wDrawingIndex + " ] " , " w:drawing " , filePath , secondIdDrawing , firstIdDrawing , wordInfoReqVos ) ;
setWordInfo ( " 图形 " + wDrawingIndex + " : " + wDrawingXml . getTextValue ( ) , " (// w:drawing)[" + wDrawingIndex + " ] " , " w:drawing " , filePath , secondIdDrawing , firstIdDrawing , wordInfoReqVos ) ;
}
}
return wordInfoReqVos ;
@@ -324,8 +320,6 @@ public class WpsWordUtils {
/**
* 获取文档段落W:P标签得数量, 判断出一个有多少段
* @param filePath 文件路径
* @param paragraphList 段落列表
* @param anchorList 锚点列表
* @return List<WordVO>
* @throws Exception Exception
*/