Coverage report

| %line | %branch
--- | --- | ---

org.apache.commons.jelly.tags.core.IncludeTag

47%

74%

1

     /*

2

      * Copyright 2002,2004 The Apache Software 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

17

     package org.apache.commons.jelly.tags.core;

18

19

     import java.io.File;

20

21

     import org.apache.commons.jelly.JellyException;

22

     import org.apache.commons.jelly.JellyTagException;

23

     import org.apache.commons.jelly.MissingAttributeException;

24

     import org.apache.commons.jelly.TagSupport;

25

     import org.apache.commons.jelly.XMLOutput;

26

27

     /** A tag which conditionally evaluates its body based on some condition

28

       *

29

       * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>

30

       * @version $Revision: 155420 $

31

       */

32

33

     public class IncludeTag extends TagSupport {

34

35

         private String uri;

36

         private File file;

37

38

         private boolean shouldExport;

39

         private boolean shouldInherit;

40

41

65

         public IncludeTag() {

42

65

             this.shouldExport = false;

43

65

             this.shouldInherit = true;

44

65

         }

45

46

         public void setInherit(String inherit) {

47

0

             if ("true".equals(inherit)) {

48

0

                 this.shouldInherit = true;

49

0

             } else {

50

0

                 this.shouldInherit = false;

51

             }

52

0

         }

53

54

         public void setExport(String export) {

55

0

             if ("true".equals(export)) {

56

0

                 this.shouldExport = true;

57

0

             } else {

58

0

                 this.shouldExport = false;

59

             }

60

0

         }

61

62

         public boolean isInherit() {

63

65

             return this.shouldInherit;

64

         }

65

66

         public boolean isExport() {

67

65

             return this.shouldExport;

68

         }

69

70

         /**

71

          * @return

72

          */

73

         public File getFile() {

74

0

             return file;

75

         }

76

77

         /**

78

          * Sets the file to be included which is either an absolute file or a file

79

          * relative to the current directory

80

          */

81

         public void setFile(File file) {

82

0

             this.file = file;

83

0

         }

84

85

86

         // Tag interface

87

         //-------------------------------------------------------------------------

88

         public void doTag(XMLOutput output)

89

             throws MissingAttributeException, JellyTagException {

90

91

65

             if (uri == null && file == <span class="keyword">null) {

92

0

                 throw new MissingAttributeException("uri");

93

             }

94

95

             // we need to create a new JellyContext of the URI

96

             // take off the script name from the URL

97

65

             String text = null;

98

             try {

99

65

                 if (uri != null) {

100

65

                     text = uri;

101

65

                     context.runScript(uri, output, isExport(), isInherit());

102

65

                 }

103

                 else {

104

0

                     text = file.toString();

105

0

                     context.runScript(file, output, isExport(), isInherit());

106

                 }

107

             }

108

0

             catch (JellyException e) {

109

0

                 throw new JellyTagException("could not include jelly script: " + text + ". Reason: " + e, e);

110

65

             }

111

65

         }

112

113

         // Properties

114

         //-------------------------------------------------------------------------

115

         /** Sets the URI (relative URI or absolute URL) for the script to evaluate. */

116

         public void setUri(String uri) {

117

65

             this.uri = uri;

118

65

         }

119

     }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.