コード例 #1
0
  private void runPlugin() throws Exception {
    File rootDir = new File(camelCoreDir, pathToModelDir);
    Document document = XmlHelper.buildNamespaceAwareDocument(inputCamelSchemaFile);
    XPath xPath = XmlHelper.buildXPath(new CamelSpringNamespace());
    DomFinder domFinder = new DomFinder(document, xPath);
    DocumentationEnricher documentationEnricher = new DocumentationEnricher(document);
    Map<String, File> jsonFiles = PackageHelper.findJsonFiles(rootDir);

    NodeList elementsAndTypes = domFinder.findElementsAndTypes();
    documentationEnricher.enrichTopLevelElementsDocumentation(elementsAndTypes, jsonFiles);
    Map<String, String> typeToNameMap = buildTypeToNameMap(elementsAndTypes);
    Set<String> injectedTypes = new HashSet<String>();

    for (Map.Entry<String, String> entry : typeToNameMap.entrySet()) {
      String elementType = entry.getKey();
      String elementName = entry.getValue();
      if (jsonFileExistsForElement(jsonFiles, elementName)) {
        injectAttributesDocumentation(
            domFinder,
            documentationEnricher,
            jsonFiles.get(elementName),
            elementType,
            injectedTypes);
      }
    }

    saveToFile(document, outputCamelSchemaFile, XmlHelper.buildTransformer());
  }
コード例 #2
0
  private void generateStage(
      Element[] parents, Class stage, Set<Class<? extends Stage>> generatedStages) {
    if (generatedStages.contains(stage)) return;
    boolean hasParentStage = Stage.class.isAssignableFrom(stage.getSuperclass());
    if (hasParentStage) {
      generateStage(parents, stage.getSuperclass(), generatedStages);
    }
    org.radargun.config.Stage stageAnnotation =
        (org.radargun.config.Stage) stage.getAnnotation(org.radargun.config.Stage.class);
    if (stageAnnotation == null) return; // not a proper stage

    String stageType = generateClass(stage);
    if (!Modifier.isAbstract(stage.getModifiers()) && !stageAnnotation.internal()) {
      for (Element parent : parents) {
        createReference(
            parent, XmlHelper.camelCaseToDash(StageHelper.getStageName(stage)), stageType);
      }
      if (!stageAnnotation.deprecatedName().equals(org.radargun.config.Stage.NO_DEPRECATED_NAME)) {
        for (Element parent : parents) {
          createReference(
              parent, XmlHelper.camelCaseToDash(stageAnnotation.deprecatedName()), stageType);
        }
      }
    }
    generatedStages.add(stage);
  }
コード例 #3
0
ファイル: Foo.java プロジェクト: ssta/rfcreader
 public static void main(String[] args) throws Exception {
   XmlHelper instance = XmlHelper.getInstance();
   List<String> a = instance.getAllAuthorNames();
   for (String s : a) {
     System.out.println(s);
   }
   System.out.println(a.size());
 }
 @Test
 public void removeAllElements() throws Exception {
   List<ParserFeature> features = Collections.emptyList();
   document =
       XmlHelper.parse(
           getClass()
               .getResourceAsStream(
                   "/com/google/code/configprocessor/data/xml-target-config-2.xml"),
           features);
   RemoveAction action =
       new RemoveAction("/root/property[@attribute='value3']", NodeSetPolicy.ALL);
   XmlActionProcessingAdvisor advisor =
       new XmlRemoveActionProcessingAdvisor(
           action, expressionResolver, namespaceContext, Collections.<ParserFeature>emptyList());
   String expected =
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
           + LINE_SEPARATOR
           + "<root>"
           + LINE_SEPARATOR
           + " <property5>"
           + LINE_SEPARATOR
           + "  <nested1 a=\"1\"/>"
           + LINE_SEPARATOR
           + " </property5>"
           + LINE_SEPARATOR
           + "</root>"
           + LINE_SEPARATOR;
   executeTest(advisor, expected);
 }
コード例 #5
0
 // TransformerHandler
 public void setResult(Result result) throws IllegalArgumentException {
   Check.notNull(result);
   if (result instanceof SAXResult) {
     setTarget((SAXResult) result);
   } else {
     TransformerHandler th = saxHelper.newIdentityTransformerHandler();
     th.setResult(result);
     setTarget(new SAXResult(th));
   }
 }
コード例 #6
0
  /**
   * Load all data from automation.config.xml
   *
   * @param filename: file xml
   * @param instanceTag
   * @throws XmlException
   * @throws ConfigDataException
   */
  private void load(String filename, String instanceTag) {
    XmlHelper xml = new XmlHelper();

    System.out.println("Loading configuration from file " + filename);
    xml.parseResource(filename);

    if (instanceTag == null) {
      instanceTag = xml.getStringAttribute(xml.getElement("/automation"), "instance");
      if (instanceTag == null) {
        System.out.println(
            "You must provide an instance name to the load function or define a default in the XML file <automation instance=\"DEFAULT INSTANCE NAME\"");
      }
    }

    System.out.println("Using the test configuration instance " + instanceTag);

    instance = null;
    for (Element element : xml.getElements("/automation/instances/instance")) {
      instance = new DataInstanceConfiguration();
      instance.fromElement(xml, element);
      if (instance.getTag().equals(instanceTag) == false) {
        instance = null;
      } else {
        break;
      }
    }

    if (instance == null) {
      System.out.println(
          "The test configuration instance "
              + instanceTag
              + " has not been defined in "
              + filename);
    }

    System.out.println("Configuration loaded");
  }
コード例 #7
0
  private static PersistenceMetadata parsePersistenceUnit(Element top) throws Exception {
    PersistenceMetadata metadata = new PersistenceMetadata();
    String puName = top.getAttribute("name");
    if (StringHelper.isNotEmpty(puName)) {
      LOG.trace("Persistent Unit name from persistence.xml: " + puName);
      metadata.setName(puName);
    }
    NodeList children = top.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) children.item(i);
        String tag = element.getTagName();
        //				if ( tag.equals( "name" ) ) {
        //					String puName = XmlHelper.getElementContent( element );
        //					log.trace( "FOUND PU NAME: " + puName );
        //					metadata.setName( puName );
        //				}
        //				else
        if (tag.equals("non-jta-data-source")) {
          metadata.setNonJtaDatasource(XmlHelper.getElementContent(element));
        } else if (tag.equals("jta-data-source")) {
          metadata.setJtaDatasource(XmlHelper.getElementContent(element));
        } else if (tag.equals("provider")) {
          metadata.setProvider(XmlHelper.getElementContent(element));
        } else if (tag.equals("class")) {
          metadata.getClasses().add(XmlHelper.getElementContent(element));
        } else if (tag.equals("mapping-file")) {
          metadata.getMappingFiles().add(XmlHelper.getElementContent(element));
        } else if (tag.equals("jar-file")) {
          metadata.getJarFiles().add(XmlHelper.getElementContent(element));
        } else if (tag.equals("exclude-unlisted-classes")) {
          metadata.setExcludeUnlistedClasses(true);
        } else if (tag.equals("delimited-identifiers")) {
          metadata.setUseQuotedIdentifiers(true);
        } else if (tag.equals("validation-mode")) {
          metadata.setValidationMode(XmlHelper.getElementContent(element));
        } else if (tag.equals("shared-cache-mode")) {
          metadata.setSharedCacheMode(XmlHelper.getElementContent(element));
        } else if (tag.equals("properties")) {
          NodeList props = element.getChildNodes();
          for (int j = 0; j < props.getLength(); j++) {
            if (props.item(j).getNodeType() == Node.ELEMENT_NODE) {
              Element propElement = (Element) props.item(j);
              if (!"property".equals(propElement.getTagName())) continue;
              String propName = propElement.getAttribute("name").trim();
              String propValue = propElement.getAttribute("value").trim();
              if (StringHelper.isEmpty(propValue)) {
                // fall back to the natural (Hibernate) way of description
                propValue = XmlHelper.getElementContent(propElement, "");
              }
              metadata.getProps().put(propName, propValue);
            }
          }
        }
      }
    }
    PersistenceUnitTransactionType transactionType =
        getTransactionType(top.getAttribute("transaction-type"));
    if (transactionType != null) metadata.setTransactionType(transactionType);

    return metadata;
  }
コード例 #8
0
  /**
   * Construct from a dom element.
   *
   * @param service the UiService.
   * @param xml The dom element.
   */
  protected UiSelection(UiServiceImpl service, Element xml) {
    // component stuff
    super(service, xml);

    // short form for title - attribute "title" as the selector
    String title = StringUtil.trimToNull(xml.getAttribute("title"));
    if (title != null) {
      setTitle(title);
    }

    // short for model
    String model = StringUtil.trimToNull(xml.getAttribute("model"));
    if (model != null) {
      PropertyReference pRef = service.newPropertyReference().setReference(model);
      setProperty(pRef);
    }

    // short for correct
    String correct = StringUtil.trimToNull(xml.getAttribute("correct"));
    if (model != null) {
      PropertyReference pRef = service.newPropertyReference().setReference(correct);
      setCorrect(pRef);
    }

    // short form for destination - attribute "destination" as the destination
    String destination = StringUtil.trimToNull(xml.getAttribute("destination"));
    if (destination != null) {
      setDestination(service.newDestination().setDestination(destination));
    }

    // selected value
    String value = StringUtil.trimToNull(xml.getAttribute("value"));
    if (value != null) this.selectedValue = value;

    // select all
    String selectAll = StringUtil.trimToNull(xml.getAttribute("selectAll"));
    if ((selectAll != null) && ("FALSE".equals(selectAll))) setSelectAll(false);

    // orientation
    String orientation = StringUtil.trimToNull(xml.getAttribute("orientation"));
    if (orientation != null) {
      if (orientation.equals("HORIZONTAL")) {
        setOrientation(Orientation.horizontal);
      } else if (orientation.equals("DROPDOWN")) {
        setOrientation(Orientation.dropdown);
      }
    }

    if (xml.getAttribute("noprint") != null) {
      String noprintflag = StringUtil.trimToNull(xml.getAttribute("noprint"));
      if (noprintflag != null) {
        this.noprintflag = Boolean.parseBoolean(noprintflag);
      }
    }

    // title
    Element settingsXml = XmlHelper.getChildElementNamed(xml, "title");
    if (settingsXml != null) {
      // let Message parse this
      this.titleMessage = new UiMessage(service, settingsXml);
    }

    // model
    settingsXml = XmlHelper.getChildElementNamed(xml, "model");
    if (settingsXml != null) {
      PropertyReference pRef = service.parsePropertyReference(settingsXml);
      if (pRef != null) setProperty(pRef);
    }

    // correct
    settingsXml = XmlHelper.getChildElementNamed(xml, "correct");
    if (settingsXml != null) {
      Element innerXml = XmlHelper.getChildElementNamed(settingsXml, "model");
      if (innerXml != null) {
        PropertyReference pRef = service.parsePropertyReference(innerXml);
        if (pRef != null) setCorrect(pRef);
      }
    }

    // correct decision
    settingsXml = XmlHelper.getChildElementNamed(xml, "correctDecision");
    if (settingsXml != null) {
      setCorrectDecision(service.parseDecisions(settingsXml));
    }

    // selection choices
    settingsXml = XmlHelper.getChildElementNamed(xml, "selectionChoices");
    if (settingsXml != null) {
      NodeList contained = settingsXml.getChildNodes();
      for (int i = 0; i < contained.getLength(); i++) {
        Node node = contained.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
          Element innerXml = (Element) node;
          if ("selectionChoice".equals(innerXml.getTagName())) {
            Message displayMsg = null;
            Message valueMsg = null;
            Element wayInnerXml = XmlHelper.getChildElementNamed(innerXml, "displayMessage");
            if (wayInnerXml != null) {
              displayMsg = new UiMessage(service, wayInnerXml);
            }
            wayInnerXml = XmlHelper.getChildElementNamed(innerXml, "valueMessage");
            if (wayInnerXml != null) {
              valueMsg = new UiMessage(service, wayInnerXml);
            }
            this.selectionMessages.add(displayMsg);
            this.selectionValues.add(valueMsg);

            // is there a container?
            Container container = null;
            boolean separate = false;
            boolean reversed = false;
            boolean indented = false;
            Element containerXml = XmlHelper.getChildElementNamed(innerXml, "container");
            if (containerXml != null) {
              String separateCode = StringUtil.trimToNull(containerXml.getAttribute("separate"));
              separate = "TRUE".equals(separateCode);

              String reversedCode = StringUtil.trimToNull(containerXml.getAttribute("reversed"));
              reversed = "TRUE".equals(reversedCode);

              String indentedCode = StringUtil.trimToNull(containerXml.getAttribute("indented"));
              indented = "TRUE".equals(indentedCode);

              container = new UiContainer(service, innerXml);
            }
            this.selectionContainers.add(new ContainerRef(container, separate, reversed, indented));
          }
        }
      }
    }

    // selection choices from model
    settingsXml = XmlHelper.getChildElementNamed(xml, "selectionModel");
    if (settingsXml != null) {
      String name = StringUtil.trimToNull(settingsXml.getAttribute("name"));
      if (name != null) this.iteratorName = name;

      // short for model
      model = StringUtil.trimToNull(settingsXml.getAttribute("model"));
      if (model != null) {
        this.selectionReference = service.newPropertyReference().setReference(model);
      }

      Element innerXml = XmlHelper.getChildElementNamed(settingsXml, "model");
      if (innerXml != null) {
        this.selectionReference = service.parsePropertyReference(innerXml);
      }

      // value message
      innerXml = XmlHelper.getChildElementNamed(settingsXml, "valueMessage");
      if (innerXml != null) {
        this.selectionValueMessage = new UiMessage(service, innerXml);
      }

      // display model
      innerXml = XmlHelper.getChildElementNamed(settingsXml, "displayMessage");
      if (innerXml != null) {
        this.selectionDisplayMessage = new UiMessage(service, innerXml);
      }
    }

    // read only shortcut
    String readOnly = StringUtil.trimToNull(xml.getAttribute("readOnly"));
    if ((readOnly != null) && ("TRUE".equals(readOnly))) {
      this.readOnly =
          new UiDecision().setProperty(new UiConstantPropertyReference().setValue("true"));
    }

    // read only collapsed shortcut
    String readOnlyCollapsed = StringUtil.trimToNull(xml.getAttribute("readOnlyCollapsed"));
    if ((readOnlyCollapsed != null) && ("TRUE".equals(readOnlyCollapsed))) {
      this.readOnlyCollapsed =
          new UiDecision().setProperty(new UiConstantPropertyReference().setValue("true"));
    }

    // read only
    settingsXml = XmlHelper.getChildElementNamed(xml, "readOnly");
    if (settingsXml != null) {
      this.readOnly = service.parseDecisions(settingsXml);
    }

    // read only collapsed
    settingsXml = XmlHelper.getChildElementNamed(xml, "readOnlyCollapsed");
    if (settingsXml != null) {
      this.readOnlyCollapsed = service.parseDecisions(settingsXml);
    }

    // single select
    settingsXml = XmlHelper.getChildElementNamed(xml, "singleSelect");
    if (settingsXml != null) {
      this.singleSelectDecision = service.parseDecisions(settingsXml);
    }

    // short for height
    String height = StringUtil.trimToNull(xml.getAttribute("height"));
    if (height != null) {
      this.setHeight(Integer.parseInt(height));
    }

    // submit value
    String submitValue = StringUtil.trimToNull(xml.getAttribute("submitValue"));
    if ((submitValue != null) && ("TRUE".equals(submitValue))) {
      this.submitValue = true;
    }

    // submitDestination
    settingsXml = XmlHelper.getChildElementNamed(xml, "destination");
    if (settingsXml != null) {
      // let Destination parse this
      this.submitDestination = new UiDestination(service, settingsXml);
    }

    // onEmptyAlert
    settingsXml = XmlHelper.getChildElementNamed(xml, "onEmptyAlert");
    if (settingsXml != null) {
      Element innerXml = XmlHelper.getChildElementNamed(settingsXml, "message");
      if (innerXml != null) {
        this.onEmptyAlertMsg = new UiMessage(service, innerXml);
      }

      this.onEmptyAlertDecision = service.parseDecisions(settingsXml);
    }
  }
コード例 #9
0
 public String getDeviceName() {
   XmlHelper xml = new XmlHelper();
   xml.parseResource(Constant.AUTOMATION_CONFIG_XML);
   Element element = xml.getElement("/automation/instances/instance/deviceName");
   return element.getTextContent();
 }
コード例 #10
0
 public String getApplicationActivity() {
   XmlHelper xml = new XmlHelper();
   xml.parseResource(Constant.AUTOMATION_CONFIG_XML);
   Element element = xml.getElement("/automation/instances/instance/applicationActivity");
   return element.getTextContent();
 }