Yuta HIGUCHI | 7d7d46e | 2017-08-29 12:19:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.cli; |
| 17 | |
| 18 | import java.io.IOException; |
| 19 | import java.io.InputStreamReader; |
| 20 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.Command; |
| 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Yuta HIGUCHI | 7d7d46e | 2017-08-29 12:19:10 -0700 | [diff] [blame] | 23 | import org.onlab.util.XmlString; |
| 24 | |
| 25 | import com.google.common.io.CharStreams; |
| 26 | |
| 27 | /** |
| 28 | * Pretty print previous command output XML. |
| 29 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 30 | @Service |
Yuta HIGUCHI | 7d7d46e | 2017-08-29 12:19:10 -0700 | [diff] [blame] | 31 | @Command(scope = "onos", name = "ppxml", |
| 32 | description = "Pretty print XML output from previous command") |
| 33 | public class PrettyXml extends AbstractShellCommand { |
| 34 | |
| 35 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 36 | protected void doExecute() { |
Yuta HIGUCHI | 7d7d46e | 2017-08-29 12:19:10 -0700 | [diff] [blame] | 37 | try { |
| 38 | String xmlS = CharStreams.toString(new InputStreamReader(System.in)); |
| 39 | |
| 40 | print("%s", XmlString.prettifyXml(xmlS)); |
| 41 | } catch (IOException e) { |
| 42 | log.error("Failed parsing XML.", e); |
| 43 | print("%s", e); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | } |