diff --git a/FA/thirdparty/xerces_demo/AppScope/app.json5 b/FA/thirdparty/xerces_demo/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b0d7f3943f86c8ea1f49c433db33fd39319e0ce6 --- /dev/null +++ b/FA/thirdparty/xerces_demo/AppScope/app.json5 @@ -0,0 +1,11 @@ +{ + "app": { + "bundleName": "com.example.demo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/FA/thirdparty/xerces_demo/AppScope/resources/base/element/string.json b/FA/thirdparty/xerces_demo/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..6657e53c462260f35136724ac7932613f532c232 --- /dev/null +++ b/FA/thirdparty/xerces_demo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "demo" + } + ] +} diff --git a/FA/thirdparty/xerces_demo/AppScope/resources/base/media/app_icon.png b/FA/thirdparty/xerces_demo/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/FA/thirdparty/xerces_demo/AppScope/resources/base/media/app_icon.png differ diff --git a/FA/thirdparty/xerces_demo/build-profile.json5 b/FA/thirdparty/xerces_demo/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..420d11af84cc295ab215d7bc297260eb4ec0e9b4 --- /dev/null +++ b/FA/thirdparty/xerces_demo/build-profile.json5 @@ -0,0 +1,26 @@ +{ + "app": { + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, + "products": [ + { + "name": "default", + "signingConfig": "default", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/FA/thirdparty/xerces_demo/entry/build-profile.json5 b/FA/thirdparty/xerces_demo/entry/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..e8cfa832347392f7190b0b9b813ac8ffd0ab56f0 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/build-profile.json5 @@ -0,0 +1,22 @@ +{ + "apiType": 'stageMode', + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "-v", + "abiFilters": [ + "arm64-v8a", + "armeabi-v7a" + ], + "cppFlags": "", + } + }, + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/FA/thirdparty/xerces_demo/entry/hvigorfile.js b/FA/thirdparty/xerces_demo/entry/hvigorfile.js new file mode 100755 index 0000000000000000000000000000000000000000..d7720ee6a7aad5c617d1fd2f6fc8c87067bfa32c --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks diff --git a/FA/thirdparty/xerces_demo/entry/package-lock.json b/FA/thirdparty/xerces_demo/entry/package-lock.json new file mode 100755 index 0000000000000000000000000000000000000000..8fe0620a2347567342a28f4f60e98db8091dbae6 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/package-lock.json @@ -0,0 +1,12 @@ +{ + "name": "entry", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/libentry.so": { + "version": "file:src/main/cpp/types/libentry", + "dev": true + } + } +} diff --git a/FA/thirdparty/xerces_demo/entry/package.json b/FA/thirdparty/xerces_demo/entry/package.json new file mode 100755 index 0000000000000000000000000000000000000000..55850f65d9824a848abfe33d8d28d78b025f16e5 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/package.json @@ -0,0 +1,16 @@ +{ + "license": "ISC", + "devDependencies": { + "@types/libentry.so": "file:./src/main/cpp/types/libentry" + }, + "name": "entry", + "ohos": { + "org": "huawei", + "directoryLevel": "module", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/FA/thirdparty/xerces_demo/entry/src/main/cpp/CMakeLists.txt b/FA/thirdparty/xerces_demo/entry/src/main/cpp/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..0a233a271e9c2fc91ebc8b7f73ce60bd1d84f990 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,16 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(xerces_demo) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_subdirectory(thirdparty/xerces-c) +add_library(entry SHARED hello.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so xerces-c) +target_include_directories(entry PRIVATE + thirdparty/xerces-c/xerces-c + thirdparty/xerces-c/xerces-c/src + thirdparty/xerces-c/adapted) diff --git a/FA/thirdparty/xerces_demo/entry/src/main/cpp/hello.cpp b/FA/thirdparty/xerces_demo/entry/src/main/cpp/hello.cpp new file mode 100755 index 0000000000000000000000000000000000000000..f74561a266e3bc6d6b55e74a8dddbdeaad34b500 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/cpp/hello.cpp @@ -0,0 +1,302 @@ +/* +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#include "napi/native_api.h" +#include +#include +#include + +#include +#include + +#include +#include +#include "xercesc/sax2/Attributes.hpp" +#include "xercesc/sax2/DefaultHandler.hpp" + +using namespace xercesc_3_2; + +napi_status SetObjectProperty(napi_env env, napi_value &object, const char *name, char *content) { + napi_value value; + napi_value key; + napi_create_string_utf8(env, name, strlen(name), &key); + napi_create_string_utf8(env, content, strlen(content), &value); + return napi_set_property(env, object, key, value); +} + +napi_status SetObjectProperty(napi_env env, napi_value &object, const char *name, int number) { + napi_value value; + napi_value key; + napi_create_string_utf8(env, name, strlen(name), &key); + napi_create_int32(env, number, &value); + return napi_set_property(env, object, key, value); +} + +napi_status SetObjectProperty(napi_env env, napi_value &object, const char *name, napi_value &obj) { + napi_value key; + napi_create_string_utf8(env, name, strlen(name), &key); + return napi_set_property(env, object, key, obj); +} + +static napi_value DOMParse(napi_env env, napi_callback_info info) { + napi_value result = nullptr; + size_t argc = 1; + napi_value argv = nullptr; + napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr); + char filename[64]; + size_t len; + size_t maxLen = 64; + napi_get_value_string_utf8(env, argv, filename, maxLen, &len); + + if (strlen(filename) <= 0) { + return result; + } + XMLPlatformUtils::Initialize(); + XercesDOMParser *parser = new XercesDOMParser; + parser->setValidationScheme(XercesDOMParser::Val_Never); + parser->setDoNamespaces(false); + parser->setDoSchema(false); + parser->setHandleMultipleImports (true); + parser->setValidationSchemaFullChecking(false); + parser->setCreateEntityReferenceNodes(false); + + + if (parser == nullptr) { + return result; + } + + try { + parser->parse(filename); + + } catch (...){ + return result; + } + DOMDocument *doc = parser->getDocument(); + if (doc == nullptr) { + return result; + } + DOMElement *root = doc->getDocumentElement(); + if(root == nullptr) { + return result; + } + XMLCh *tmp = XMLString::transcode("person"); + DOMNodeList *personNodeList = doc->getElementsByTagName(tmp); + XMLString::release(&tmp); + + if (personNodeList == nullptr || personNodeList->getLength() <= 0) { + return result; + } + napi_create_object(env, &result); + SetObjectProperty(env, result, "personNumber", personNodeList->getLength()); + + napi_value arrayRes; + napi_create_array(env, &arrayRes); + + for (int i = 0; i < personNodeList->getLength(); i++) { + napi_value personInfo; + napi_create_object(env, &personInfo); + //获取节点第一个属性 + DOMNode *personNode = personNodeList->item(i); + + DOMNamedNodeMap *personNodeAttr = personNode->getAttributes(); + char *nodeName = XMLString::transcode(personNodeAttr->item(0)->getNodeName()); + char *nodeValue = XMLString::transcode(personNodeAttr->item(0)->getNodeValue()); + if (strcmp(XMLString::transcode(personNodeAttr->item(0)->getNodeName()),"id") == 0) { + SetObjectProperty(env,personInfo,nodeName,nodeValue); + XMLString::release(&nodeName); + XMLString::release(&nodeValue); + } else { + XMLString::release(&nodeName); + XMLString::release(&nodeValue); + continue; + } + + //遍历节点的每一个子节点,并记录每个节点信息 + DOMNodeList *nodeList = personNode->getChildNodes(); + for (int j = 0; j < nodeList->getLength(); j++) { + if (nodeList->item(j)->getNodeType() == DOMNode::ELEMENT_NODE) { + DOMNode *itm = nodeList->item(j); + char *childNodeName = XMLString::transcode(itm->getNodeName()); + char *childContent = XMLString::transcode(itm->getTextContent()); + if (itm->getNodeName() != nullptr && itm->getTextContent() != nullptr) { + SetObjectProperty(env, personInfo, childNodeName, childContent); + } + XMLString::release(&childNodeName); + XMLString::release(&childContent); + } + } + napi_set_element(env, arrayRes, i, personInfo); + } + SetObjectProperty(env, result, "personInfo", arrayRes); + + delete parser; + XMLPlatformUtils::Terminate(); + + return result; +} + +class MySax2Handler : public DefaultHandler { + public: + MySax2Handler(napi_env env) { + person = false; + personCount = 0; + env_ = env; + arrayRes = nullptr; + personInfo = nullptr; + contentFlag = false; + } + ~MySax2Handler() { + } + + int getPersonCount(void) { + return personCount; + } + + napi_value getArrayRes(void) { + return arrayRes; + } + + void startElement(const XMLCh* const uri, const XMLCh* const localname,\ + const XMLCh* const qname, const Attributes& attrs) { + char *nodeName = XMLString::transcode(qname); + if (strcmp(nodeName,"personnel") == 0) { + napi_create_array(env_, &arrayRes); + } + + if (strcmp(nodeName,"person") == 0) { + person = true; + napi_create_object(env_, &personInfo); + } + + if (person) { + contentFlag = true; + XMLSSize_t len = attrs.getLength(); + curLabel = XMLString::transcode(qname); + for (XMLSSize_t index = 0; index < len; index++) { + char *attrName = XMLString::transcode(attrs.getQName((XMLSize_t)0)); + char *attrValue = XMLString::transcode(attrs.getValue((XMLSize_t)0)); + SetObjectProperty(env_, personInfo, attrName, attrValue); + XMLString::release(&attrName); + XMLString::release(&attrValue); + } + } + + XMLString::release(&nodeName); + } + + void characters(const XMLCh* const chars, const XMLSize_t length) { + if (length <= 0 || chars == nullptr) { + return ; + } + if(person && contentFlag) { + char *charsContent = XMLString::transcode(chars); + SetObjectProperty(env_, personInfo,curLabel, charsContent); + XMLString::release(&charsContent); + XMLString::release(&curLabel); + contentFlag = false; + } + } + + void endElement(const XMLCh* const uri, const XMLCh* const localname,\ + const XMLCh* const qname) { + char *nodeName = XMLString::transcode(qname); + if (strcmp(nodeName,"person") == 0) { + person = false; + napi_set_element(env_, arrayRes, personCount, personInfo); + personCount++; + } + XMLString::release(&nodeName); + } + + private: + bool person; + int personCount; + napi_value arrayRes; + napi_value personInfo; + napi_env env_; + char *curLabel; + bool contentFlag; +}; + + +static napi_value SAXParse(napi_env env, napi_callback_info info) { + napi_value result = nullptr; + size_t argc = 1; + napi_value argv = nullptr; + napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr); + char filename[64]; + size_t len; + size_t maxLen = 64; + napi_get_value_string_utf8(env, argv, filename, maxLen, &len); + + if (strlen(filename) <= 0) { + return result; + } + + XMLPlatformUtils::Initialize(); + + SAX2XMLReader *parser = XMLReaderFactory::createXMLReader(); + parser->setFeature(XMLUni::fgSAX2CoreValidation, true); + parser->setFeature(XMLUni::fgXercesDynamic, true); + parser->setFeature(XMLUni::fgSAX2CoreValidation, false); + parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); + parser->setFeature(XMLUni::fgXercesSchema, true); + parser->setFeature(XMLUni::fgXercesHandleMultipleImports, true); + parser->setFeature(XMLUni::fgXercesSchemaFullChecking, false); + parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false); + + try { + MySax2Handler *mySax2Handler = new MySax2Handler(env); + parser->setContentHandler(mySax2Handler); + parser->setErrorHandler(mySax2Handler); + parser->parse(filename); + napi_value tmp = mySax2Handler->getArrayRes(); + napi_create_object(env, &result); + SetObjectProperty(env, result, "personNumber", mySax2Handler->getPersonCount()); + SetObjectProperty(env, result, "personInfo", tmp); + } catch (...) { + return result; + } + delete parser; + XMLPlatformUtils::Terminate(); + return result; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "DOMParse", nullptr, DOMParse, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "SAXParse", nullptr, SAXParse, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version =1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "hello", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterHelloModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/FA/thirdparty/xerces_demo/entry/src/main/cpp/types/libentry/index.d.ts b/FA/thirdparty/xerces_demo/entry/src/main/cpp/types/libentry/index.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..55d79776f107f9f6c8ef9fc4446f00ffc009ab0a --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/cpp/types/libentry/index.d.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export interface personInfo { + id:string + name:string + email:string + link:string +} + +export interface myobject { + personNumber:number + personInfo : Array +} + +export const DOMParse: (path:string) => myobject +export const SAXParse: (path:string) => myobject diff --git a/FA/thirdparty/xerces_demo/entry/src/main/cpp/types/libentry/package.json b/FA/thirdparty/xerces_demo/entry/src/main/cpp/types/libentry/package.json new file mode 100755 index 0000000000000000000000000000000000000000..395f926a91a01f86098fe39603b1a42d2e1533a8 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/cpp/types/libentry/package.json @@ -0,0 +1,4 @@ +{ + "name": "libentry.so", + "types": "./index.d.ts" +} \ No newline at end of file diff --git a/FA/thirdparty/xerces_demo/entry/src/main/ets/Application/MyAbilityStage.ts b/FA/thirdparty/xerces_demo/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..8675bfde9f5cdfdd5bc8e7a2bf69b7152c0ced79 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/ets/Application/MyAbilityStage.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} diff --git a/FA/thirdparty/xerces_demo/entry/src/main/ets/MainAbility/MainAbility.ts b/FA/thirdparty/xerces_demo/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..407614a35f2847f67bc30115572cd157c4292e24 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + globalThis.abilityContext = this.context + } + + onDestroy() { + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + + windowStage.loadContent("pages/index", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; diff --git a/FA/thirdparty/xerces_demo/entry/src/main/ets/pages/index.ets b/FA/thirdparty/xerces_demo/entry/src/main/ets/pages/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..8e02ec945d0055de37949511dd3e46ec00e518a0 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/ets/pages/index.ets @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { personInfo } from '../../cpp/types/libentry/index.d'; +import testNapi from "libentry.so"; +import fileio from '@ohos.fileio'; +import prompt from '@ohos.prompt'; + +@Entry +@Component +struct Index { + @State personNum: number = 0 + @State perInfo: Array = [] + + private path: string = null + private appContext: any = null + private createFile: number = 0 + + aboutToAppear() { + this.path = globalThis.abilityContext.filesDir + this.appContext = getContext(this) + } + + build() { + Column() { + Text("create XML") + .fontSize(40) + .width('80%') + .height(100) + .textAlign(TextAlign.Center) + .fontColor(Color.Black) + .backgroundColor(Color.Gray) + .onClick(() => { + this.WriteFromResourcesFile("personal.xml") + this.WriteFromResourcesFile("personal.dtd") + prompt.showToast({message:"create personal.xml success"}) + }) + Text().height(20) + Text("DOMParse") + .fontSize(40) + .width('80%') + .height(100) + .textAlign(TextAlign.Center) + .fontColor(Color.Black) + .backgroundColor(Color.Gray) + .onClick(() => { + this.DOMParse("personal.xml") + }) + Text().height(20) + Text("SAXParse") + .fontSize(40) + .width('80%') + .height(100) + .textAlign(TextAlign.Center) + .fontColor(Color.Black) + .backgroundColor(Color.Gray) + .onClick(() => { + this.SAXParse("personal.xml") + }) + Text().height(20) + Text("clean") + .fontSize(40) + .width('80%') + .height(100) + .textAlign(TextAlign.Center) + .fontColor(Color.Black) + .backgroundColor(Color.Gray) + .onClick(() => { + this.personNum = 0 + this.perInfo = [] + }) + + Flex({direction:FlexDirection.Column}) { + Text("person number:" + this.personNum).fontSize(30) + Text().height(10) + + ForEach(this.perInfo, + (item : personInfo) => { + Text("ID:"+item.id).fontSize(30) + Text("Email:"+item.email).fontSize(30) + Text().height(20) + }, + (item : personInfo) => item.email) + + }.width('100%') + } + .width('100%') + } + + WriteFromResourcesFile(filename:string) { + if (this.createFile > 1) { + return + } + this.createFile += 1 + this.appContext.resourceManager.getRawFileDescriptor(filename).then(value => { + let buf = new ArrayBuffer(value.length) + fileio.readSync(value.fd,buf) + fileio.open(this.path + "/" + filename, 0o1 | 0o1000 | 0o100, 0o666).then(function(number) { + fileio.write(number,buf) + fileio.close(number) + }) + + }) + } + + DOMParse(filename:string) { + let tmp = testNapi.DOMParse(this.path + "/" + filename) + this.personNum = tmp.personNumber + this.perInfo = tmp.personInfo + } + + SAXParse(filename:string) { + let tmp = testNapi.SAXParse(this.path + "/" + filename) + this.personNum = tmp.personNumber + this.perInfo = tmp.personInfo + } +} diff --git a/FA/thirdparty/xerces_demo/entry/src/main/module.json5 b/FA/thirdparty/xerces_demo/entry/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..f0061c4cdeedfbd26a44ff6be19bd31bffd28c22 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/module.json5 @@ -0,0 +1,39 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/MyAbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/FA/thirdparty/xerces_demo/entry/src/main/resources/base/element/color.json b/FA/thirdparty/xerces_demo/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..62a137a61b90c14f109ed8c81d9d551ea0a5888a --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/FA/thirdparty/xerces_demo/entry/src/main/resources/base/element/string.json b/FA/thirdparty/xerces_demo/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..9868c7395cb8da3f49e03757842312748780962f --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "MainAbility_desc", + "value": "description" + } + ] +} \ No newline at end of file diff --git a/FA/thirdparty/xerces_demo/entry/src/main/resources/base/media/icon.png b/FA/thirdparty/xerces_demo/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/FA/thirdparty/xerces_demo/entry/src/main/resources/base/media/icon.png differ diff --git a/FA/thirdparty/xerces_demo/entry/src/main/resources/base/profile/main_pages.json b/FA/thirdparty/xerces_demo/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..feec276e105eeb8d621c20aaf838f318b0a94150 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/FA/thirdparty/xerces_demo/entry/src/main/resources/rawfile/personal.dtd b/FA/thirdparty/xerces_demo/entry/src/main/resources/rawfile/personal.dtd new file mode 100755 index 0000000000000000000000000000000000000000..e636266933d8ef3a1ae96408f613faca0c604e6b --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/resources/rawfile/personal.dtd @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + diff --git a/FA/thirdparty/xerces_demo/entry/src/main/resources/rawfile/personal.xml b/FA/thirdparty/xerces_demo/entry/src/main/resources/rawfile/personal.xml new file mode 100755 index 0000000000000000000000000000000000000000..d466a93bd90062a071449b170b695a4685da1e38 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/main/resources/rawfile/personal.xml @@ -0,0 +1,50 @@ + + + + + + + + + Boss Big + chief@foo.com + + + + + Worker One + one@foo.com + + + + + Worker Two + two@foo.com + + + + + Worker Three + three@foo.com + + + + + Worker Four + four@foo.com + + + + + Worker Five + five@foo.com + + + + + Worker Six + six@foo.com + + + + diff --git a/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/Application/TestAbilityStage.ts b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/Application/TestAbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..14533e38ad0f7e6828cca4b0f7b9d65a8dbb7ecd --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/Application/TestAbilityStage.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from "@ohos.application.AbilityStage" + +export default class TestAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] TestAbilityStage onCreate") + } +} diff --git a/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/TestAbility/TestAbility.ts b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/TestAbility/TestAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..2bacf74acba9c923bae0f8d3e97e3c1bcbd7c9d4 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/TestAbility/TestAbility.ts @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Ability from '@ohos.application.Ability' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.loadContent("TestAbility/pages/index", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }); + + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +}; diff --git a/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/TestAbility/pages/index.ets b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/TestAbility/pages/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..ef15bf806a5ec10587e6e2e5d9914d278e63a4da --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/TestAbility/pages/index.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@ohos.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } diff --git a/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100755 index 0000000000000000000000000000000000000000..dc0f9958618745534ad380f4f58422cc55e582ca --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; diff --git a/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/test/Ability.test.ets b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..d5a959b4026db52164a1a48f4bd80c667ea24235 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + it('assertContain',0, function () { + console.info("it begin") + let a = 'abc' + let b = 'b' + expect(a).assertContain(b) + expect(a).assertEqual(a) + }) + }) +} diff --git a/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/test/List.test.ets b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..20d96307df06df34e8dc4a74a57bde253dfdf25d --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} diff --git a/FA/thirdparty/xerces_demo/entry/src/ohosTest/module.json5 b/FA/thirdparty/xerces_demo/entry/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..ecb467ef1e859495b2789dfe9965c477417d1a33 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/ohosTest/module.json5 @@ -0,0 +1,39 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntrance": "./ets/Application/TestAbilityStage.ts", + "description": "$string:entry_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/element/color.json b/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/element/string.json b/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..36d4230c53e9f5a07ae343ad8dc9808341975e3b --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/media/icon.png b/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/profile/test_pages.json b/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..fcef82b4dfc18e28106ff9ecd1c8b48ec74d18a4 --- /dev/null +++ b/FA/thirdparty/xerces_demo/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/index" + ] +} diff --git a/FA/thirdparty/xerces_demo/hvigorfile.js b/FA/thirdparty/xerces_demo/hvigorfile.js new file mode 100755 index 0000000000000000000000000000000000000000..586ced98461bdcdac2b070f2e041e99c7ac678d9 --- /dev/null +++ b/FA/thirdparty/xerces_demo/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').appTasks \ No newline at end of file diff --git a/FA/thirdparty/xerces_demo/package.json b/FA/thirdparty/xerces_demo/package.json new file mode 100755 index 0000000000000000000000000000000000000000..93c8b388ef4fceebbaa615745eb1a8632776cb1e --- /dev/null +++ b/FA/thirdparty/xerces_demo/package.json @@ -0,0 +1,18 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "xerces_demo", + "ohos": { + "org": "huawei", + "directoryLevel": "project", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "@ohos/hypium": "1.0.2", + "@ohos/hvigor-ohos-plugin": "1.2.2", + "@ohos/hvigor": "1.2.2" + } +}