diff --git a/utils/UtilUrlString/README.md b/utils/UtilUrlString/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8ba2a46d01385b5b3d344bb4fecf10a31b20bc7b --- /dev/null +++ b/utils/UtilUrlString/README.md @@ -0,0 +1,19 @@ +# URL String Parsing + +### Introduction + +This sample shows how to add, delete, modify, and query URL string search parameters to help you understand the URL structure and usage. + +### Usage + +1. Touch **Insert key-value pair**. The parameter in the text box on the left is inserted behind the search parameter. + +2. Touch **Delete key-value pair** to delete the specified key-value pair. + +3. Touch **Get first value** to search for and display the value of the first occurrence of the specified key. + +4. Touch **Set new value** to delete all key-value pairs associated with the key and assign a new value to the key. + +### Constraints + +This sample can only be run on standard-system devices. diff --git a/utils/UtilUrlString/README_zh.md b/utils/UtilUrlString/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..1da8b62786169bf65a08f8506c398bdef6d23075 --- /dev/null +++ b/utils/UtilUrlString/README_zh.md @@ -0,0 +1,21 @@ +# URL字符串解析 + +### 简介 + +本示例对URL字符串的查找参数进行了增删改查的一系列操作,使得读者对URL的结构用途更加明了。 + +### 使用说明 + +1.点击**插入键值对到查询字符串**按钮,会将左面文本框的参数插入到查找参数后面。 + +2.点击**删除键值对**按钮,会将指定名称的键值对删除。 + +3.点击**获取指定名称对应的第一个值**按钮,将查找参数中该参数名对应的第一个参数值,并显示出来。 + +4.点击**设置键的新值**按钮,将与名称相关联的键值对全部删除,并赋予该键名一个新值。 + +### 约束与限制 + +1.本示例仅支持在标准系统上运行。 + +2.本示例需要使用3.0.0.961及以上的DevEco Studio版本才可编译运行。 \ No newline at end of file diff --git a/utils/UtilUrlString/build-profile.json5 b/utils/UtilUrlString/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3854f71fc436e7d67fb03828698562f4dc8a3abb --- /dev/null +++ b/utils/UtilUrlString/build-profile.json5 @@ -0,0 +1,27 @@ +{ + "app": { + "signingConfigs": [], + "compileSdkVersion": 8, + "compatibleSdkVersion": 8, + "products": [ + { + "name": "default", + "signingConfig": "default", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/utils/UtilUrlString/entry/build-profile.json5 b/utils/UtilUrlString/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ae58d1d0a70c602c9cfe1909b00dfec899ba1944 --- /dev/null +++ b/utils/UtilUrlString/entry/build-profile.json5 @@ -0,0 +1,13 @@ +{ + "apiType": 'faMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/utils/UtilUrlString/entry/hvigorfile.js b/utils/UtilUrlString/entry/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..bcec4c99653062cbf17702c40a2dd2a7b809b81a --- /dev/null +++ b/utils/UtilUrlString/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').legacyHapTasks diff --git a/utils/UtilUrlString/entry/package.json b/utils/UtilUrlString/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..c7685ac4e7c0d79df04c96744f0d8f22cb4a9025 --- /dev/null +++ b/utils/UtilUrlString/entry/package.json @@ -0,0 +1,14 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "entry", + "ohos": { + "org": "huawei", + "directoryLevel": "module", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/utils/UtilUrlString/entry/src/main/config.json b/utils/UtilUrlString/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..e6ceaef27667f3a522147d4786e44f1238ce34d1 --- /dev/null +++ b/utils/UtilUrlString/entry/src/main/config.json @@ -0,0 +1,66 @@ +{ + "app": { + "bundleName": "ohos.samples.etsurlstring", + "vendor": "samples", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.etsurlstring", + "name": ".MyApplication", + "mainAbility": ".MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/utils/UtilUrlString/entry/src/main/ets/MainAbility/app.ets b/utils/UtilUrlString/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf28e58b36cf11db491d3f00768ef2c9e41d05cf --- /dev/null +++ b/utils/UtilUrlString/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,23 @@ +/* + * 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 default { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/utils/UtilUrlString/entry/src/main/ets/MainAbility/common/paramOption.ets b/utils/UtilUrlString/entry/src/main/ets/MainAbility/common/paramOption.ets new file mode 100644 index 0000000000000000000000000000000000000000..0eaded4f779113185a184f202204d3ac35699993 --- /dev/null +++ b/utils/UtilUrlString/entry/src/main/ets/MainAbility/common/paramOption.ets @@ -0,0 +1,102 @@ +/* + * 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 url from '@ohos.url' + +var urlObject = new url.URL('https://developer.harmonyos.com/?') +var paramsObject = new url.URLSearchParams(urlObject.search.slice(1)) + +@Component +export struct FirstOption{ + private options:Resource[] = [$r('app.string.insert'), $r('app.string.delete'), + $r('app.string.getFirst'), $r('app.string.setValue')] + private nodeValue:string = 'nodeValue' + private nodeKey:string = 'node' + private nodeNum:number = 0 + + @Link outputs:string + + insertNode(){ + this.nodeNum ++ + paramsObject.append(this.nodeKey, this.nodeValue + this.nodeNum) + this.outputs = urlObject.toString() + paramsObject.toString() + } + + deleteNode(){ + if(paramsObject.has(this.nodeKey)){ + paramsObject.delete(this.nodeKey) + this.outputs = urlObject.toString() + paramsObject.toString() + this.nodeNum = 0 + } + else{ + this.outputs = "It does not exist. Please insert first" + } + } + + getFirstNode(){ + if(paramsObject.has(this.nodeKey)){ + var fod = paramsObject.get(this.nodeKey); + this.outputs = fod.toString() + } + else{ + this.outputs = "It does not exist. Please insert first" + } + } + + changeValue(){ + paramsObject.set(this.nodeKey, 'newValue') + this.nodeNum = 0 + this.outputs = urlObject.toString() + paramsObject.toString() + } + + build(){ + Column(){ + Flex({direction:FlexDirection.Row,alignItems:ItemAlign.Center,justifyContent:FlexAlign.Center,wrap:FlexWrap.Wrap}){ + ForEach(this.options,item=> { + Button() { + Text(item) + .fontSize(20) + .textAlign(TextAlign.Center) + .fontColor(Color.White) + .width('340') + } + .type(ButtonType.Capsule) + .backgroundColor('#0D9FFB') + .padding(5) + .margin({top:10 }) + .onClick(() => { + var index = this.options.indexOf(item) + switch(index) { + case 0: + this.insertNode() + break + case 1: + this.deleteNode() + break + case 2: + this.getFirstNode() + break + case 3: + this.changeValue() + break + default: + break + } + }) + },item=>JSON.stringify(item)) + }.width('100%') + }.width('100%') + } +} \ No newline at end of file diff --git a/utils/UtilUrlString/entry/src/main/ets/MainAbility/pages/index.ets b/utils/UtilUrlString/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a530339a594d01c20dcec1b15b2c95f640481464 --- /dev/null +++ b/utils/UtilUrlString/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,50 @@ +/* + * 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 {FirstOption} from '../common/paramOption' +const URL_NET: string= "https://developer.harmonyos.com/?" + +@Entry +@Component +struct Index { + @State output: string = URL_NET + + build() { + Column() { + Text($r("app.string.entry_MainAbility")) + .width('100%') + .height(50) + .backgroundColor('#0D9FFB') + .fontColor(Color.White) + .fontSize(20) + .padding({ left: 15 }) + Scroll() { + Column() { + Text(this.output) + .width('95%').height('30%') + .fontSize(15) + .padding(10) + .margin({ left: 10, right: 10, top: 10 }) + .border({ width: 2, radius: 5, color: Color.Gray }) + Text(URL_NET).fontSize(15).margin({top:15}).fontWeight(FontWeight.Bold) + FirstOption({outputs:$output}) + } + } + } + .width('100%') + .height('100%') + } +} + diff --git a/utils/UtilUrlString/entry/src/main/resources/base/element/string.json b/utils/UtilUrlString/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6de6dfb2e5f421584e66ca3dd7bef18efd8dec86 --- /dev/null +++ b/utils/UtilUrlString/entry/src/main/resources/base/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSURLString" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "url", + "value": "URL:" + }, + { + "name": "insert", + "value": "Insert Key-value" + }, + { + "name": "delete", + "value": "Delete Key-value" + }, + { + "name": "getFirst", + "value": "GetFirst Key-value" + }, + { + "name": "setValue", + "value": "Set new value of key" + }, + { + "name": "pleaseInsert", + "value": "It does not exist. Please insert first" + } + ] +} \ No newline at end of file diff --git a/utils/UtilUrlString/entry/src/main/resources/base/media/icon.png b/utils/UtilUrlString/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/utils/UtilUrlString/entry/src/main/resources/base/media/icon.png differ diff --git a/utils/UtilUrlString/entry/src/main/resources/en/element/string.json b/utils/UtilUrlString/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..04b66989c36fcd415ff00d8e4bea7091fd0a3e22 --- /dev/null +++ b/utils/UtilUrlString/entry/src/main/resources/en/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSURLString" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "url", + "value": "URL:" + }, + { + "name": "insert", + "value": "Insert key-value pair" + }, + { + "name": "delete", + "value": "Delete key-value pair" + }, + { + "name": "getFirst", + "value": "Get first value" + }, + { + "name": "setValue", + "value": "Set new value" + }, + { + "name": "pleaseInsert", + "value": "It does not exist. Insert key-value pair first." + } + ] +} \ No newline at end of file diff --git a/utils/UtilUrlString/entry/src/main/resources/zh/element/string.json b/utils/UtilUrlString/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e29a2f9a38694f6a0a3df2c3b5e70af56683eb14 --- /dev/null +++ b/utils/UtilUrlString/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSURLString" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "url", + "value": "URL:" + }, + { + "name": "insert", + "value": "插入键值对到查询字符串" + }, + { + "name": "delete", + "value": "删除键值对" + }, + { + "name": "getFirst", + "value": "获取指定名称对应的第一个值" + }, + { + "name": "setValue", + "value": "设置键的新值" + }, + { + "name": "pleaseInsert", + "value": "不存在,请先插入" + } + ] +} \ No newline at end of file diff --git a/utils/UtilUrlString/hvigorfile.js b/utils/UtilUrlString/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..cff9f0dfcf8cb00cca34e7f50d61380cf5496868 --- /dev/null +++ b/utils/UtilUrlString/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').legacyAppTasks \ No newline at end of file diff --git a/utils/UtilUrlString/package.json b/utils/UtilUrlString/package.json new file mode 100644 index 0000000000000000000000000000000000000000..0e7c62c5a949e0254c04fdf43d93edb2e5f87646 --- /dev/null +++ b/utils/UtilUrlString/package.json @@ -0,0 +1,18 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "myapplication", + "ohos": { + "org": "huawei", + "directoryLevel": "project", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "1.0.6", + "hypium": "^1.0.0", + "@ohos/hvigor": "1.0.6" + } +} diff --git a/utils/UtilUrlString/screenshot/device/screenshot.png b/utils/UtilUrlString/screenshot/device/screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..729d794a0519d476bd47e049421760a9a06bf77b Binary files /dev/null and b/utils/UtilUrlString/screenshot/device/screenshot.png differ diff --git a/utils/XmlTextConvert/README.md b/utils/XmlTextConvert/README.md new file mode 100644 index 0000000000000000000000000000000000000000..6dfc291d302e33ec5c46f3582eea4a961af77022 --- /dev/null +++ b/utils/XmlTextConvert/README.md @@ -0,0 +1,17 @@ +# XML Text Conversion + +### Introduction + +This sample shows how to use **XmlSerializer**, **XmlPullParser**, and **ConvertXML** to generate an XML text, parse the XML text, and convert the XML text into a JavaScript object, respectively. + +### Usage + +1. Touch **Xml Serializer** to generate an XML text and display the text content in the text box above the button. + +2. Touch **Xml Pull Parser** to parse the preset XML text and display the parsed information in the text box above the button. + +3. Touch **XML Convert** to convert the preset XML text into a JavaScript object and display the object in the text box above the button. + +### Constraints + +This sample can only be run on standard-system devices. diff --git a/utils/XmlTextConvert/README_zh.md b/utils/XmlTextConvert/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..2949b356f03611decb21efc6d3146ccc3ab2cce2 --- /dev/null +++ b/utils/XmlTextConvert/README_zh.md @@ -0,0 +1,19 @@ +# xml文本转换 + +### 简介 + +本示例通过XmlSerializer生成xml文本,通过XmlPullParser解析xml文本,通过ConvertXML将xml文本转换为JavaScript对象。 + +### 使用说明 + +1.点击**Xml 生成**按钮,会构建xml文本,并在按钮上方的文本框显示xml文本内容。 + +2.点击**Xml 解析**按钮,会解析已经预置的xml文本,并在文本框显示解析信息。 + +3.点击**Xml 转换**按钮,会将预置的xml文本转换为JavaScript对象,并在文本框显示。 + +### 约束与限制 + +1.本示例仅支持在标准系统上运行。 + +2.本示例需要使用3.0.0.961及以上的DevEco Studio版本才可编译运行。 \ No newline at end of file diff --git a/utils/XmlTextConvert/build-profile.json5 b/utils/XmlTextConvert/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3854f71fc436e7d67fb03828698562f4dc8a3abb --- /dev/null +++ b/utils/XmlTextConvert/build-profile.json5 @@ -0,0 +1,27 @@ +{ + "app": { + "signingConfigs": [], + "compileSdkVersion": 8, + "compatibleSdkVersion": 8, + "products": [ + { + "name": "default", + "signingConfig": "default", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/utils/XmlTextConvert/entry/build-profile.json5 b/utils/XmlTextConvert/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ae58d1d0a70c602c9cfe1909b00dfec899ba1944 --- /dev/null +++ b/utils/XmlTextConvert/entry/build-profile.json5 @@ -0,0 +1,13 @@ +{ + "apiType": 'faMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/utils/XmlTextConvert/entry/hvigorfile.js b/utils/XmlTextConvert/entry/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..bcec4c99653062cbf17702c40a2dd2a7b809b81a --- /dev/null +++ b/utils/XmlTextConvert/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').legacyHapTasks diff --git a/utils/XmlTextConvert/entry/package.json b/utils/XmlTextConvert/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..c7685ac4e7c0d79df04c96744f0d8f22cb4a9025 --- /dev/null +++ b/utils/XmlTextConvert/entry/package.json @@ -0,0 +1,14 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "entry", + "ohos": { + "org": "huawei", + "directoryLevel": "module", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/utils/XmlTextConvert/entry/src/main/config.json b/utils/XmlTextConvert/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..2cedb76fa72fa8b623e5ed26c63c4ef42550b33d --- /dev/null +++ b/utils/XmlTextConvert/entry/src/main/config.json @@ -0,0 +1,67 @@ +{ + "app": { + "bundleName": "ohos.samples.etsxmltextconvert", + "vendor": "samples", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.etsxmltextconvert", + "name": ".MyApplication", + "mainAbility": ".MainAbility", + "srcPath": "", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/Index" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/utils/XmlTextConvert/entry/src/main/ets/MainAbility/app.ets b/utils/XmlTextConvert/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..2eb18d66dc1b9324405a13e48bce34d033da27b2 --- /dev/null +++ b/utils/XmlTextConvert/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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 default { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/utils/XmlTextConvert/entry/src/main/ets/MainAbility/common/SelectOption.ets b/utils/XmlTextConvert/entry/src/main/ets/MainAbility/common/SelectOption.ets new file mode 100644 index 0000000000000000000000000000000000000000..7470a909a527734065fb63794355eadfae92ffde --- /dev/null +++ b/utils/XmlTextConvert/entry/src/main/ets/MainAbility/common/SelectOption.ets @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2022 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 xml from '@ohos.xml' +import Logger from '../model/Logger' +import ConvertXML from '@ohos.convertxml' + +const TAG: string = '[SelectOption]' + +@Component +export struct SelectOption { + private options: Resource[] = [$r('app.string.serializer'), $r('app.string.parser'), $r('app.string.convert')] + @Link outputs: string + @Link inputs: string + + serializerNode() { + let arrayBuffer = new ArrayBuffer(1024) + let serializer = new xml.XmlSerializer(arrayBuffer) + serializer.setDeclaration() + serializer.setNamespace('h', 'https://developer.harmonyos.com/') + serializer.startElement('note') + serializer.setAttributes('importance', 'high') + serializer.addEmptyElement('b') + serializer.setComment('contact information') + serializer.setText('ZhangSan 18712345678') + serializer.setCDATA('CData') + serializer.setDocType('DocType') + serializer.endElement() + let array = new Uint8Array(arrayBuffer) + let serializerStr = '' + for (let i = 0; i < array.length; ++i) { + serializerStr = serializerStr + String.fromCodePoint(array[i]) + } + this.outputs = serializerStr + } + + parserNode() { + let arrayBuffer = new ArrayBuffer(this.inputs.length * 2) + let bufView = new Uint8Array(arrayBuffer) + let strLen = this.inputs.length + for (let k = 0; k < strLen; ++k) { + bufView[k] = this.inputs.charCodeAt(k) + } + let parser = new xml.XmlPullParser(arrayBuffer) + let arr = {} + let i = 0 + + function func(key, info) { + arr[i] = `key:${key}, value:${info.getDepth()} ${info.getColumnNumber()} ` + + `${info.getLineNumber()} ${info.getAttributeCount()} ${info.getName()} ` + + `${info.getText()} ${info.isEmptyElementTag()} ${info.isWhitespace()}\n` + i++ + return true + } + + let options = { supportDoctype: true, ignoreNameSpace: true, tokenValueCallbackFunction: func } + parser.parse(options) + let str = '' + for (let j = 0; j < i; ++j) { + str = str + arr[j] + } + this.outputs = str + } + + convertNode() { + Logger.info(`${TAG}, convertNode start`) + let options = { + trim: false, + declarationKey: "_declaration", + instructionKey: "_instruction", + attributesKey: "_attributes", + textKey: "_text", + cdataKey: "_cdata", + doctypeKey: "_doctype", + commentKey: "_comment", + parentKey: "_parent", + typeKey: "_type", + nameKey: "_name", + elementsKey: "_elements" + } + let conv = new ConvertXML.ConvertXML() + Logger.info(`${TAG}, convertNode new ConvertXML`) + let result = JSON.stringify(conv.convert(this.inputs, options)) + Logger.info(`${TAG}, convertNode conv.convert result = ${result}`) + this.outputs = JSON.stringify(result) + Logger.info(`${TAG}, convertNode end`) + } + + build() { + Column() { + Flex({ + direction: FlexDirection.Row, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center, + wrap: FlexWrap.Wrap + }) { + ForEach(this.options, item => { + Button() { + Text(item) + .fontSize(20) + .textAlign(TextAlign.Center) + .fontColor(Color.White) + .width('70%') + } + .type(ButtonType.Capsule) + .backgroundColor('#0D9FFB') + .padding(5) + .margin({ top: 10 }) + .onClick(() => { + let index = this.options.indexOf(item) + switch (index) { + case 0: + this.serializerNode() + break + case 1: + this.parserNode() + break + case 2: + this.convertNode() + break + default: + break + } + }) + }, item => JSON.stringify(item)) + }.width('100%') + }.width('100%') + } +} \ No newline at end of file diff --git a/utils/XmlTextConvert/entry/src/main/ets/MainAbility/model/Logger.ts b/utils/XmlTextConvert/entry/src/main/ets/MainAbility/model/Logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..bbda985cbcccc46d9e475df5374801a12f65e9f0 --- /dev/null +++ b/utils/XmlTextConvert/entry/src/main/ets/MainAbility/model/Logger.ts @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 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 hilog from '@ohos.hilog' + +class Logger { + private domain: number + private prefix: string + private format: string = "%{public}s" + + constructor(prefix: string) { + this.prefix = prefix + this.domain = 0xFF00 + } + + debug(...args: any[]) { + hilog.debug(this.domain, this.prefix, this.format, args) + } + + info(...args: any[]) { + hilog.info(this.domain, this.prefix, this.format, args) + } + + warn(...args: any[]) { + hilog.warn(this.domain, this.prefix, this.format, args) + } + + error(...args: any[]) { + hilog.error(this.domain, this.prefix, this.format, args) + } +} + +export default new Logger('[XmlTextConvert]') \ No newline at end of file diff --git a/utils/XmlTextConvert/entry/src/main/ets/MainAbility/pages/Index.ets b/utils/XmlTextConvert/entry/src/main/ets/MainAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8be217b1211c9debfa7c106b20e795bb12850cca --- /dev/null +++ b/utils/XmlTextConvert/entry/src/main/ets/MainAbility/pages/Index.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 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 { SelectOption } from '../common/SelectOption' + +@Entry +@Component +struct Index { + @State output: string = `eTSXmlTextConvert` + @State input: string = + ` + + Happy + Work + Play + ` + + build() { + Column() { + Text($r('app.string.entry_MainAbility')) + .width('100%') + .height(50) + .backgroundColor('#0D9FFB') + .fontColor(Color.White) + .fontSize(20) + .padding({ left: 20 }) + Scroll() { + Column() { + Text(this.output) + .width('90%') + .height('60%') + .fontSize(15) + .padding(10) + .margin({ left: 10, right: 10, top: 20, bottom: 10 }) + .border({ width: 2, radius: 5, color: Color.Gray }) + SelectOption({ outputs: $output, inputs: $input }) + } + } + } + .width('100%') + .height('100%') + } +} + diff --git a/utils/XmlTextConvert/entry/src/main/resources/base/element/string.json b/utils/XmlTextConvert/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2b9578cfa1d55efc1a8cb7d2d8675a60c7f9d243 --- /dev/null +++ b/utils/XmlTextConvert/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSXmlTextConvert" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "serializer", + "value": "Xml Serializer" + }, + { + "name": "parser", + "value": "Xml Pull Parser" + }, + { + "name": "convert", + "value": "Xml Convert" + } + ] +} \ No newline at end of file diff --git a/utils/XmlTextConvert/entry/src/main/resources/base/media/icon.png b/utils/XmlTextConvert/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/utils/XmlTextConvert/entry/src/main/resources/base/media/icon.png differ diff --git a/utils/XmlTextConvert/entry/src/main/resources/en/element/string.json b/utils/XmlTextConvert/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2b9578cfa1d55efc1a8cb7d2d8675a60c7f9d243 --- /dev/null +++ b/utils/XmlTextConvert/entry/src/main/resources/en/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSXmlTextConvert" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "serializer", + "value": "Xml Serializer" + }, + { + "name": "parser", + "value": "Xml Pull Parser" + }, + { + "name": "convert", + "value": "Xml Convert" + } + ] +} \ No newline at end of file diff --git a/utils/XmlTextConvert/entry/src/main/resources/zh/element/string.json b/utils/XmlTextConvert/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..239fb6656bf6d38402f59a03b5b94891f9c1933e --- /dev/null +++ b/utils/XmlTextConvert/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSXmlTextConvert" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "serializer", + "value": "Xml 生成" + }, + { + "name": "parser", + "value": "Xml 解析" + }, + { + "name": "convert", + "value": "Xml 转换" + } + ] +} \ No newline at end of file diff --git a/utils/XmlTextConvert/hvigorfile.js b/utils/XmlTextConvert/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..cff9f0dfcf8cb00cca34e7f50d61380cf5496868 --- /dev/null +++ b/utils/XmlTextConvert/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').legacyAppTasks \ No newline at end of file diff --git a/utils/XmlTextConvert/package.json b/utils/XmlTextConvert/package.json new file mode 100644 index 0000000000000000000000000000000000000000..120121d32acd27c4300b59851caf98101e42e81b --- /dev/null +++ b/utils/XmlTextConvert/package.json @@ -0,0 +1,18 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "etsxmltextconvert", + "ohos": { + "org": "huawei", + "directoryLevel": "project", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "1.0.6", + "hypium": "^1.0.0", + "@ohos/hvigor": "1.0.6" + } +} diff --git a/utils/XmlTextConvert/screenshots/devices/main.png b/utils/XmlTextConvert/screenshots/devices/main.png new file mode 100644 index 0000000000000000000000000000000000000000..71fde592fb191a412ff36d39ff287d9ccd68128a Binary files /dev/null and b/utils/XmlTextConvert/screenshots/devices/main.png differ