Пример #1
0
  private void loadDecoratorMappers(NodeList nodes) {
    clearDecoratorMappers();
    Properties emptyProps = new Properties();

    pushDecoratorMapper("com.opensymphony.module.sitemesh.mapper.NullDecoratorMapper", emptyProps);

    // note, this works from the bottom node up.
    for (int i = nodes.getLength() - 1; i > 0; i--) {
      if (nodes.item(i) instanceof Element) {
        Element curr = (Element) nodes.item(i);
        if ("mapper".equalsIgnoreCase(curr.getTagName())) {
          String className = curr.getAttribute("class");
          Properties props = new Properties();
          // build properties from <param> tags.
          NodeList children = curr.getChildNodes();
          for (int j = 0; j < children.getLength(); j++) {
            if (children.item(j) instanceof Element) {
              Element currC = (Element) children.item(j);
              if ("param".equalsIgnoreCase(currC.getTagName())) {
                String value = currC.getAttribute("value");
                props.put(currC.getAttribute("name"), replaceProperties(value));
              }
            }
          }
          // add mapper
          pushDecoratorMapper(className, props);
        }
      }
    }

    pushDecoratorMapper(
        "com.opensymphony.module.sitemesh.mapper.InlineDecoratorMapper", emptyProps);
  }
 @Nonnull
 private <T> Class<T> parseAttributeAsType(
     @Nonnull Element element, @Nonnull String attributeName, @Nonnull Class<T> expectedType) {
   requireNonNull("expectedType", expectedType);
   final String attributeValue =
       requireNonNull("element", element)
           .getAttribute(requireNonNull("attributeName", attributeName));
   final Class<?> type;
   try {
     type = _classLoader.loadClass(attributeValue);
   } catch (ClassNotFoundException e) {
     throw new IllegalArgumentException(
         "The value of <"
             + element.getTagName()
             + " "
             + attributeName
             + "=\"..\" ../> is no valid class.",
         e);
   }
   if (!expectedType.isAssignableFrom(type)) {
     throw new IllegalArgumentException(
         "The value of <"
             + element.getTagName()
             + " "
             + attributeName
             + "=\"..\" ../> is no type of '"
             + expectedType.getName()
             + "'.");
   }
   // noinspection unchecked
   return (Class<T>) type;
 }
Пример #3
0
  /*
   * Work down the children tree
   * @param parent
   * @param el
   */
  private void processChildren(ESBNodeWithChildren parent, Element el) {
    el.normalize();
    parent.setData(el);

    if (parent.getEsbObjectType() == null) {
      String tag = el.getTagName();
      if (tag.endsWith("-bus") && el.getAttribute("busid") != null) { // $NON-NLS-1$ //$NON-NLS-2$
        parent.setEsbObjectType(ESBType.BUS);
      } else if (tag.endsWith("-listener")
          && el.getAttribute("busidref") != null) { // $NON-NLS-1$ //$NON-NLS-2$
        parent.setEsbObjectType(ESBType.LISTENER);
      } else if (tag.endsWith("-provider")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.PROVIDER);
      } else if (tag.equalsIgnoreCase("service")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.SERVICE);
      } else if (tag.equalsIgnoreCase("listeners")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.LISTENER);
      } else if (tag.equalsIgnoreCase("Actions")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.ACTION);
      } else if (tag.equalsIgnoreCase("action")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.ACTION);
      } else if (tag.equalsIgnoreCase("property")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.PROPERTY);
        return;
      }
    }
    NodeList children = el.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      if (children.item(i) instanceof Element) {
        Element child = (Element) children.item(i);
        String name = child.getAttribute("name"); // $NON-NLS-1$
        if (name == null || name.trim().length() == 0) {
          name = child.getAttribute("busid"); // $NON-NLS-1$
        }
        if (name == null || name.trim().length() == 0) {
          name = child.getAttribute("dest-name"); // $NON-NLS-1$
        }
        if (name == null || name.trim().length() == 0) {
          name = child.getTagName();
        }
        if (name.equalsIgnoreCase("actions")) { // $NON-NLS-1$
          name = JBossESBUIMessages.ESBDomParser_Actions_Node_Label;
        } else if (name.equalsIgnoreCase("listeners")) { // $NON-NLS-1$
          name = JBossESBUIMessages.ESBDomParser_Listeners_Node_Label;
        }

        ESBNodeWithChildren childNode = new ESBNodeWithChildren(name);
        String ref = child.getAttribute("busidref"); // $NON-NLS-1$
        if (ref != null && ref.trim().length() > 0) {
          childNode.setRef(ref);
        }
        processChildren(childNode, child);
        if (childNode.getEsbObjectType() != null
            && !childNode.getEsbObjectType().equals(ESBType.PROPERTY)) {
          parent.addChild(childNode);
          childNode.setEsbObjectType(parent.getEsbObjectType());
        }
      }
    }
  }
Пример #4
0
  private static SetInfo parseSet(Node parent) throws XmlParserException {
    String id = "";
    String type = "";
    String measurementids = null;

    NodeList nodes = parent.getChildNodes();
    Vector<SetInfo> sets = new Vector<SetInfo>();
    for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) {
      Node node = nodes.item(nodeid);
      if (node.getNodeType() != Node.ELEMENT_NODE) continue;

      Element element = (Element) node;
      if (element.getTagName().equals("id")) id = element.getTextContent();
      else if (element.getTagName().equals("set")) sets.add(parseSet(element));
      else if (element.getTagName().equals("type")) type = element.getTextContent();
      else if (element.getTagName().equals("measurementids"))
        measurementids = element.getTextContent();
    }

    // create the set
    SetInfo set = new SetInfo(id, Integer.parseInt(type));
    if (measurementids != null) {
      int mids[] = ByteArray.toIntArray(Base64.decode(measurementids), ByteArray.ENDIAN_LITTLE, 32);
      for (int mid : mids) set.addMeasurementID(mid);
    }

    // add the children
    for (SetInfo s : sets) set.addChild(s);

    return set;
  }
Пример #5
0
  /** Private helper that parses the file and sets up the DOM tree. */
  private Node getRootNode(File configFile) throws ParsingException {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

    dbFactory.setIgnoringComments(true);
    dbFactory.setNamespaceAware(false);
    dbFactory.setValidating(false);

    DocumentBuilder db = null;
    try {
      db = dbFactory.newDocumentBuilder();
    } catch (ParserConfigurationException pce) {
      throw new ParsingException("couldn't get a document builder", pce);
    }

    Document doc = null;
    try {
      doc = db.parse(new FileInputStream(configFile));
    } catch (IOException ioe) {
      throw new ParsingException("failed to load the file ", ioe);
    } catch (SAXException saxe) {
      throw new ParsingException("error parsing the XML tree", saxe);
    } catch (IllegalArgumentException iae) {
      throw new ParsingException("no data to parse", iae);
    }

    Element root = doc.getDocumentElement();

    if (!root.getTagName().equals("config"))
      throw new ParsingException("unknown document type: " + root.getTagName());

    return root;
  }
Пример #6
0
  // Walk the tree from a specified element,
  // inserting data from a DicomObject where required.
  private static String getElementText(Element element, DicomObject dicomObject) {

    if (dicomTag(element)) return getDicomElementText(element, dicomObject);

    if (element.getTagName().equals("block")) return getBlockText(element, dicomObject);

    StringBuffer sb = new StringBuffer();
    sb.append("<" + element.getTagName());
    NamedNodeMap attributes = element.getAttributes();
    Attr attr;
    for (int i = 0; i < attributes.getLength(); i++) {
      attr = (Attr) attributes.item(i);
      String attrValue = attr.getValue().trim();
      if (dicomTag(attrValue)) {
        attrValue = getDicomElementText(attrValue, dicomObject);
      }
      sb.append(" " + attr.getName() + "=\"" + attrValue + "\"");
    }
    sb.append(">");
    if (element.getTagName().equals("table")) sb.append(getTableText(element, dicomObject));
    else if (element.getTagName().equals("publication-date")) sb.append(StringUtil.getDate());
    else sb.append(getChildrenText(element, dicomObject));
    sb.append("</" + element.getTagName() + ">");
    return sb.toString();
  }
Пример #7
0
  public DataNode(Element node) {

    this.tagName = node.getTagName();

    NamedNodeMap nnm = node.getAttributes();
    attributes.put(tagName, new HashMap<String, String>());
    for (int j = 0; j < nnm.getLength(); j++) {
      attributes.get(tagName).put(nnm.item(j).getNodeName(), nnm.item(j).getNodeValue());
    }

    // TODO: just iterate through all children instead of using predefined list of names?
    for (int j = 0; j < elementNames.length; j++) {
      NodeList elements = node.getElementsByTagName(elementNames[j]);
      if (elements == null || elements.getLength() == 0) {
        continue;
      } else {
        attributes.put(elementNames[j], new HashMap<String, String>());
      }
      Element el = (Element) (elements.item(0));

      String currentTag = el.getTagName();
      nnm = el.getAttributes();
      for (int k = 0; k < nnm.getLength(); k++) {
        attributes.get(currentTag).put(nnm.item(k).getNodeName(), nnm.item(k).getNodeValue());
      }
    }
  }
Пример #8
0
 public void transform(Element element, Element parentSource, Element parentResult) {
   NodeList childNodes = element.getChildNodes();
   logger.log(
       Level.FINE,
       stringManager.getString(
           "upgrade.transform.baseelemnt.transformingMSG", element.getTagName()));
   for (int index = 0; index < childNodes.getLength(); index++) {
     Node aNode = childNodes.item(index);
     try {
       if (aNode.getNodeType() == Node.ELEMENT_NODE) {
         BaseElement baseElement =
             ElementToObjectMapper.getMapper().getElementObject(aNode.getNodeName());
         baseElement.transform((Element) aNode, element, parentResult);
       }
     } catch (Exception ex) {
       // ****** LOG MESSAGE *************
       ex.printStackTrace();
       logger.log(
           Level.WARNING,
           stringManager.getString(
               "upgrade.transform.baseelement.transformexception",
               new String[] {element.getTagName(), ex.getMessage()}));
       // -logger.log(Level.WARNING,
       // stringManager.getString("upgrade.transform.baseelement.transformexception"), ex);
     }
   }
 }
Пример #9
0
 /**
  * Tests if a Element <code>element</code> is valid for the <code>XmlCenter</code>.
  *
  * @param element
  * @return boolean
  */
 public static boolean isMatch(Element element) {
   String tagName = element.getTagName();
   if (!"center".equals(tagName)) {
     return (false);
   }
   RStack target = new RStack(element);
   Element child;
   child = target.popElement();
   if (child == null) {
     return (false);
   }
   if (!"ra".equals(child.getTagName())) {
     return (false);
   }
   child = target.popElement();
   if (child == null) {
     return (false);
   }
   if (!"decl".equals(child.getTagName())) {
     return (false);
   }
   if (!target.isEmptyElement()) {
     return (false);
   }
   return (true);
 }
Пример #10
0
  /**
   * Build a library directive using an XML element.
   *
   * @param base the base directory
   * @param element the module element
   * @return the library directive
   * @exception Exception if an exception occurs
   */
  private LibraryDirective buildLibraryDirective(File base, Element element) throws Exception {
    final String elementName = element.getTagName();
    if (!LIBRARY_ELEMENT_NAME.equals(elementName)) {
      final String error = "Element is not a library.";
      throw new IllegalArgumentException(error);
    }

    // get type descriptors, modules and properties

    Properties properties = null;
    ImportDirective[] imports = new ImportDirective[0];
    List<ResourceDirective> list = new ArrayList<ResourceDirective>();
    Element[] children = ElementHelper.getChildren(element);
    for (int i = 0; i < children.length; i++) {
      Element child = children[i];
      final String tag = child.getTagName();
      if (PROPERTIES_ELEMENT_NAME.equals(tag)) {
        properties = buildProperties(child);
      } else if (IMPORTS_ELEMENT_NAME.equals(tag)) {
        imports = buildImportDirectives(child);
      } else {
        ResourceDirective resource = buildResourceDirectiveFromElement(base, child, null);
        list.add(resource);
      }
    }
    ResourceDirective[] resources = list.toArray(new ResourceDirective[0]);
    return new LibraryDirective(imports, resources, properties);
  }
Пример #11
0
  private MatchTrace parseGameTrace(Element gametrace) {
    String gameName = null;
    List<TracedStep> steps = null;

    NodeList nodes = gametrace.getChildNodes();

    for (int i = 0; i < nodes.getLength(); i++) {
      Node node = nodes.item(i);
      if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        if (element.getTagName().equals(GAME)) {
          if (gameName != null) {
            throw new IllegalArgumentException("Multiple <game> tags in XML file!");
          }
          gameName = parseGame(element);
        } else if (element.getTagName().equals(STEPS)) {
          if (steps != null) {
            throw new IllegalArgumentException("Multiple <steps> tags in XML file!");
          }
          steps = parseSteps(element);
        } else {
          logger.warning("ignoring element (expected <game> or <steps>): " + element);
        }
      }
    }

    if (gameName == null) {
      throw new IllegalArgumentException("Missing <game> tag in XML file!");
    }
    if (steps == null) {
      throw new IllegalArgumentException("Missing <steps> tag in XML file!");
    }
    return new MatchTrace(gameName, steps);
  }
Пример #12
0
  private void emitMenu(SourceWriter writer, Element el) throws UnableToCompleteException {
    for (Node n = el.getFirstChild(); n != null; n = n.getNextSibling()) {
      if (n.getNodeType() != Node.ELEMENT_NODE) continue;

      Element child = (Element) n;

      if (child.getTagName().equals("cmd")) {
        String cmdId = child.getAttribute("refid");
        writer.print("callback.addCommand(");
        writer.print("\"" + Generator.escape(cmdId) + "\", ");
        writer.println("this.cmds." + cmdId + "());");
      } else if (child.getTagName().equals("separator")) {
        writer.println("callback.addSeparator();");
      } else if (child.getTagName().equals("menu")) {
        String label = child.getAttribute("label");
        writer.println("callback.beginMenu(\"" + Generator.escape(label) + "\");");
        emitMenu(writer, child);
        writer.println("callback.endMenu();");
      } else if (child.getTagName().equals("dynamic")) {
        String dynamicClass = child.getAttribute("class");
        writer.println("new " + dynamicClass + "().execute(callback);");
      } else {
        logger_.log(TreeLogger.Type.ERROR, "Unexpected tag " + el.getTagName() + " in menu");
        throw new UnableToCompleteException();
      }
    }
  }
Пример #13
0
  private static MeasurementInfo parseMeasurement(Node parent) throws XmlParserException {
    String id = "";
    String label = "";
    String sampleid = "";
    Vector<FileInfo> files = null;
    Vector<ScanInfo> scans = null;

    NodeList nodes = parent.getChildNodes();
    for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) {
      Node node = nodes.item(nodeid);
      if (node.getNodeType() != Node.ELEMENT_NODE) continue;

      Element element = (Element) node;
      if (element.getTagName().equals("id")) id = element.getTextContent();
      else if (element.getTagName().equals("label")) label = element.getTextContent();
      else if (element.getTagName().equals("sampleid")) sampleid = element.getTextContent();
      else if (element.getTagName().equals("scans")) scans = parseScans(node);
      else if (element.getTagName().equals("files")) files = parseFiles(node);
    }

    MeasurementInfo measurement = new MeasurementInfo(Integer.parseInt(id), sampleid);
    measurement.setLabel(label);
    measurement.addFileInfos(files);
    if (scans != null) measurement.addScanInfos(scans);

    return measurement;
  }
Пример #14
0
 public UPnPDeviceData(URL descriptionURL, Element deviceElem) {
   this.descriptionURL = descriptionURL;
   this.deviceElem = deviceElem;
   NodeList childNodes = deviceElem.getChildNodes();
   for (int i = 0; i < childNodes.getLength(); i++) {
     Node childNode = childNodes.item(i);
     if (childNode instanceof Element) {
       Element childElement = (Element) childNode;
       String tagName = childElement.getTagName();
       if ("deviceList".equalsIgnoreCase(tagName)) {
         NodeList childNodes2 = childElement.getChildNodes();
         for (int j = 0; j < childNodes2.getLength(); j++) {
           Node childNode2 = childNodes2.item(j);
           if (childNode2 instanceof Element) {
             Element childElement2 = (Element) childNode2;
             if ("device".equalsIgnoreCase(childElement2.getTagName())) {
               deviceList.add(new UPnPDeviceData(descriptionURL, childElement2));
             }
           }
         }
       } else if ("serviceList".equalsIgnoreCase(tagName)) {
         NodeList childNodes2 = childElement.getChildNodes();
         for (int j = 0; j < childNodes2.getLength(); j++) {
           Node childNode2 = childNodes2.item(j);
           if (childNode2 instanceof Element) {
             Element childElement2 = (Element) childNode2;
             if ("service".equalsIgnoreCase(childElement2.getTagName())) {
               serviceList.add(new UPnPServiceData(this, childElement2));
             }
           }
         }
       }
     }
   }
 }
Пример #15
0
 private FilterDirective[] buildFilterDirectives(Element element) throws Exception {
   if (null == element) {
     return new FilterDirective[0];
   } else {
     Element[] children = ElementHelper.getChildren(element);
     FilterDirective[] filters = new FilterDirective[children.length];
     for (int i = 0; i < children.length; i++) {
       Element child = children[i];
       String token = ElementHelper.getAttribute(child, "token");
       if ("filter".equals(child.getTagName())) {
         String value = ElementHelper.getAttribute(child, "value");
         filters[i] = new SimpleFilterDirective(token, value);
       } else if ("feature".equals(child.getTagName())) {
         String id = ElementHelper.getAttribute(child, "id").toUpperCase();
         Feature feature = Feature.valueOf(id);
         String ref = ElementHelper.getAttribute(child, "ref");
         String type = ElementHelper.getAttribute(child, "type");
         boolean alias = ElementHelper.getBooleanAttribute(child, "alias");
         filters[i] = new FeatureFilterDirective(token, ref, feature, type, alias);
       } else {
         final String error =
             "Element name not recognized [" + child.getTagName() + "] (expecting 'filter').";
         throw new DecodingException(error, null, element);
       }
     }
     return filters;
   }
 }
Пример #16
0
 @Override
 public void apply(Element e) {
   if (e.getTagName().equals("property")) {
     Element parent = (Element) e.getParentNode();
     if (parent != null && parent.getTagName().equals("ndbx")) {
       Attr name = e.getAttributeNode("name");
       Attr value = e.getAttributeNode("value");
       if (name != null && name.getValue().equals("oscPort")) {
         if (value != null) {
           Element device = e.getOwnerDocument().createElement("device");
           device.setAttribute("name", "osc1");
           device.setAttribute("type", "osc");
           Element portProperty = e.getOwnerDocument().createElement("property");
           portProperty.setAttribute("name", "port");
           portProperty.setAttribute("value", value.getValue());
           device.appendChild(portProperty);
           Element autostartProperty = e.getOwnerDocument().createElement("property");
           autostartProperty.setAttribute("name", "autostart");
           autostartProperty.setAttribute("value", "true");
           device.appendChild(autostartProperty);
           parent.replaceChild(device, e);
         } else {
           parent.removeChild(e);
         }
       }
     }
   }
 }
Пример #17
0
 private Element getParagraph(Element node) {
   Element parent = (Element) node.getParentNode();
   if (parent.getTagName().equals(XMLString.TEXT_P)
       || parent.getTagName().equals(XMLString.TEXT_H)) {
     return parent;
   }
   return getParagraph(parent);
 }
Пример #18
0
    void parsePhase() {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      // Now use the factory to create a DOM parser (a.k.a. a DocumentBuilder)
      DocumentBuilder parser;
      try {
        parser = factory.newDocumentBuilder();
        // Parse the file and build a Document tree to represent its content
        Document document =
            parser.parse(new StringBufferInputStream("<root>" + conf.get("phases") + "</root>"));
        // Ask the document for a list of all phases
        NodeList rows = document.getElementsByTagName(AnalysisProcessorConfiguration.phase);
        int phasenumber = rows.getLength();
        for (int i = 0; i < phasenumber; i++) {
          Node phase = rows.item(i);
          NodeList fields = phase.getChildNodes();
          String phasename = null;
          String stacks = null;
          String funcs = null;
          List<String> functionlist = new ArrayList<String>();
          for (int j = 0; j < fields.getLength(); j++) {
            Node fieldNode = fields.item(j);
            if (!(fieldNode instanceof Element)) continue;
            Element field = (Element) fieldNode;
            if ("phasename".equals(field.getTagName()) && field.hasChildNodes())
              phasename = ((org.w3c.dom.Text) field.getFirstChild()).getData().trim();
            else if ("stack".equals(field.getTagName()) && field.hasChildNodes())
              stacks = ((org.w3c.dom.Text) field.getFirstChild()).getData();
            else if ("functions".equals(field.getTagName()) && field.hasChildNodes())
              funcs = ((org.w3c.dom.Text) field.getFirstChild()).getData();
          }
          if (stacks != null && stacks.length() != 0) stacks = stacks.replace(" ", "");
          else stacks = "";
          phasealias.put(stacks, phasename);

          if (funcs == null) {
            continue;
          }
          for (String func : funcs.split(SEPERATOR_COMMA)) {
            functionlist.add(func);
          }
          this.phases.put(stacks, functionlist);
        }
      } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        log.warn(e);
        e.printStackTrace();
      } catch (SAXException e) {
        // TODO Auto-generated catch block
        log.warn(e);
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        log.warn(e);
        e.printStackTrace();
      }
    }
    /** Determines if not should be skipped from checking. */
    public boolean skip() {
      if (mBucket == Bucket.SKIP) {
        return true;
      }

      // Skip all includes and Views
      if (mNode.getTagName().equals(VIEW_INCLUDE) || mNode.getTagName().equals(VIEW)) {
        return true;
      }
      return false;
    }
Пример #20
0
    private void buildFieldsDefsExtension(Map<Integer, CompositeDef> existingCodecs) {
      NodeList messageExtList = doc.getElementsByTagName(ELEMENT_MESSAGE_EXT);
      Map<Integer, CompositeDef> extensions = new TreeMap<>();
      for (int i = 0; i < messageExtList.getLength(); i++) {
        Element messageDef = (Element) messageExtList.item(i);
        Integer mtiExisting = getOptionalInteger(messageDef, ATTR_EXTENDS);
        Integer mti = getOptionalInteger(messageDef, ATTR_MTI);
        if (existingCodecs.containsKey(mti) || extensions.containsKey(mti)) {
          throw new ConfigException(format("Duplicate message config for mti %d", mti));
        }

        CompositeDef existing = existingCodecs.get(mtiExisting);
        if (existing == null) {
          throw new ConfigException(format("Error extending mti %d, no config available", mti));
        }
        SortedMap<Integer, ComponentDef> clonedFieldsDef =
            cloneSubComponentDefs(existing.getSubComponentDefs());

        Element setElement = null;
        Element removeElement = null;
        for (Element e : getSubElements(messageDef)) {
          switch (e.getTagName()) {
            case ELEMENT_SET:
              setElement = e;
              break;
            case ELEMENT_REMOVE:
              removeElement = e;
              break;
            default:
              throw new ConfigException(
                  format("Unknown message extension instruction %s", e.getTagName()));
          }
        }

        if (setElement != null) {
          setVarFields(clonedFieldsDef, getSubElements(setElement));
        }

        if (removeElement != null) {
          removeFields(clonedFieldsDef, getSubElements(removeElement));
        }

        extensions.put(
            mti,
            new CompositeDef(
                clonedFieldsDef,
                existing.getCompositeCodec(),
                existing.isMandatory(),
                existing.getLengthCodec()));
      }
      existingCodecs.putAll(extensions);
    }
Пример #21
0
    /**
     * Construct from information in XML.
     *
     * @param el The XML DOM Element definining the user.
     */
    public BaseDigest(Element el) {
      // setup for properties
      m_properties = new BaseResourcePropertiesEdit();

      // setup for ranges
      m_ranges = new Hashtable();

      m_id = el.getAttribute("id");

      // the children (properties, messages)
      NodeList children = el.getChildNodes();
      final int length = children.getLength();
      for (int i = 0; i < length; i++) {
        Node child = children.item(i);
        if (child.getNodeType() != Node.ELEMENT_NODE) continue;
        Element element = (Element) child;

        // look for properties
        if (element.getTagName().equals("properties")) {
          // re-create properties
          m_properties = new BaseResourcePropertiesEdit(element);
        }

        // look for a messages
        else if (element.getTagName().equals("messages")) {
          String period = element.getAttribute("period");

          // find the range
          List msgs = (List) m_ranges.get(period);
          if (msgs == null) {
            msgs = new Vector();
            m_ranges.put(period, msgs);
          }

          // do these children for messages
          NodeList msgChildren = element.getChildNodes();
          final int msgChildrenLen = msgChildren.getLength();
          for (int m = 0; m < msgChildrenLen; m++) {
            Node msgChild = msgChildren.item(m);
            if (msgChild.getNodeType() != Node.ELEMENT_NODE) continue;
            Element msgChildEl = (Element) msgChild;

            if (msgChildEl.getTagName().equals("message")) {
              String subject = Xml.decodeAttribute(msgChildEl, "subject");
              String body = Xml.decodeAttribute(msgChildEl, "body");
              msgs.add(new org.sakaiproject.email.impl.DigestMessage(m_id, subject, body));
            }
          }
        }
      }
    }
Пример #22
0
 @Override
 public void apply(Element e) {
   if (e.getTagName().equals("property")) {
     Element parent = (Element) e.getParentNode();
     if (parent != null && parent.getTagName().equals("device")) {
       Attr type = parent.getAttributeNode("type");
       if (type != null && type.getValue().equals(this.deviceType)) {
         Attr name = e.getAttributeNode("name");
         if (name != null && name.getValue().equals(oldPropertyName))
           name.setValue(newPropertyName);
       }
     }
   }
 }
Пример #23
0
 protected void setPh(Element t, String ph) {
   if (!t.getTagName().equals(MaryXML.TOKEN))
     throw new DOMException(
         DOMException.INVALID_ACCESS_ERR,
         "Only t elements allowed, received " + t.getTagName() + ".");
   if (t.hasAttribute("ph")) {
     String prevPh = t.getAttribute("ph");
     // In previous sampa, replace star with sampa:
     String newPh = prevPh.replaceFirst("\\*", ph);
     t.setAttribute("ph", newPh);
   } else {
     t.setAttribute("ph", ph);
   }
 }
 public SetRoleByNameRule(String operatorTypeName, Element element) throws XMLException {
   super(operatorTypeName, element);
   NodeList children = element.getChildNodes();
   for (int i = 0; i < children.getLength(); i++) {
     Node child = children.item(i);
     if (child instanceof Element) {
       Element childElem = (Element) child;
       if (childElem.getTagName().equals("role")) {
         targetRole = childElem.getTextContent();
       } else if (childElem.getTagName().equals("parameter")) {
         parameterName = childElem.getTextContent();
       }
     }
   }
 }
Пример #25
0
  private void loadExcludes() throws ParserConfigurationException, IOException, SAXException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    InputStream is = null;

    if (excludesFile == null) {
      is = config.getServletContext().getResourceAsStream(excludesFileName);
    } else if (excludesFile.exists() && excludesFile.canRead()) {
      is = excludesFile.toURI().toURL().openStream();
    }

    if (is == null) {
      throw new IllegalStateException(
          "Cannot load excludes configuration file \""
              + excludesFileName
              + "\" as specified in \"sitemesh.xml\" or \"sitemesh-default.xml\"");
    }

    Document document = builder.parse(is);
    Element root = document.getDocumentElement();
    NodeList sections = root.getChildNodes();

    // Loop through child elements of root node looking for the <excludes> block
    for (int i = 0; i < sections.getLength(); i++) {
      if (sections.item(i) instanceof Element) {
        Element curr = (Element) sections.item(i);
        if ("excludes".equalsIgnoreCase(curr.getTagName())) {
          loadExcludeUrls(curr.getChildNodes());
        }
      }
    }
  }
Пример #26
0
 private IncludeDirective buildIncludeDirective(Element element, boolean flag)
     throws DecodingException {
   final String tag = element.getTagName();
   final Properties properties = buildProperties(element);
   if (INCLUDE_ELEMENT_NAME.equals(tag)) {
     Category category = buildCategory(element, flag);
     if (element.hasAttribute("key")) {
       final String value = ElementHelper.getAttribute(element, "key", null);
       return new IncludeDirective(IncludeDirective.KEY, category, value, properties);
     } else if (element.hasAttribute("ref")) {
       final String value = ElementHelper.getAttribute(element, "ref", null);
       return new IncludeDirective(IncludeDirective.REF, category, value, properties);
     } else if (element.hasAttribute("uri")) {
       final String value = ElementHelper.getAttribute(element, "uri", null);
       return new IncludeDirective(IncludeDirective.URI, category, value, properties);
     } else {
       final String error =
           "Include directive does not declare a 'uri', 'key' or 'ref' attribute.\n"
               + element.toString();
       throw new IllegalArgumentException(error);
     }
   } else {
     final String error = "Invalid include element name [" + tag + "].";
     throw new DecodingException(error, null, element);
   }
 }
Пример #27
0
 private ImportDirective buildImportDirective(Element element) throws DecodingException {
   final String tag = element.getTagName();
   final Properties properties = buildProperties(element);
   if (IMPORT_ELEMENT_NAME.equals(tag)) {
     try {
       if (element.hasAttribute("file")) {
         final String value = ElementHelper.getAttribute(element, "file", null);
         return new ImportDirective(ImportDirective.FILE, value, properties);
       } else if (element.hasAttribute("uri")) {
         final String value = ElementHelper.getAttribute(element, "uri", null);
         return new ImportDirective(ImportDirective.URI, value, properties);
       } else {
         final String error =
             "Import element does not declare a 'file' or 'uri' attribute.\n" + element.toString();
         throw new IllegalArgumentException(error);
       }
     } catch (Throwable e) {
       final String error = "Internal error while attempting to resolve an import directive.";
       throw new DecodingException(error, e, element);
     }
   } else {
     final String error = "Invalid include element name [" + tag + "].";
     throw new IllegalArgumentException(error);
   }
 }
Пример #28
0
  public Key(Node keyNode, Element commandElement) {
    this(keyNode.getTextContent().trim());

    if (keyNode instanceof Element) {
      Element keyElem = (Element) keyNode;
      String key = keyElem.getAttribute("jawskey");
      if ((key != null) && (key.length() > 0)) {
        jawsKey = new Key(key);
      }
      String jawsHandleVal = keyElem.getAttribute("jawshandle");
      if (jawsHandleVal != null) {
        if (jawsHandleVal.trim().equals("true")) {
          jawsHandle = true;
        }
      }
      String jawsSayAllStopVal = keyElem.getAttribute("jawsSayAllStop");
      if (jawsSayAllStopVal != null) {
        if (jawsSayAllStopVal.trim().equals("false")) {
          jawsSayAllStop = false;
        }
      }
      String jawsScriptVal = keyElem.getAttribute("jawsscript");
      if (jawsScriptVal != null) {
        if (jawsScriptVal.trim().equals("false")) {
          jawsScript = false;
        }
      }
      if ("speakAll".equals(commandElement.getTagName())) {
        jawsSayAllStopIgnore = true;
      }
    }
  }
Пример #29
0
  private static List<Element> getTopLevelElementChildren(
      Element element, String parentName, String childrenName) throws TikaException {
    Node parentNode = null;
    if (parentName != null) {
      // Should be only zero or one <parsers> / <detectors> etc tag
      NodeList nodes = element.getElementsByTagName(parentName);
      if (nodes.getLength() > 1) {
        throw new TikaException("Properties may not contain multiple " + parentName + " entries");
      } else if (nodes.getLength() == 1) {
        parentNode = nodes.item(0);
      }
    } else {
      // All children directly on the master element
      parentNode = element;
    }

    if (parentNode != null) {
      // Find only the direct child parser/detector objects
      NodeList nodes = parentNode.getChildNodes();
      List<Element> elements = new ArrayList<Element>();
      for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node instanceof Element) {
          Element nodeE = (Element) node;
          if (childrenName.equals(nodeE.getTagName())) {
            elements.add(nodeE);
          }
        }
      }
      return elements;
    } else {
      // No elements of this type
      return Collections.emptyList();
    }
  }
  public void run() {
    /*
    	Pre-conditions: p and game have been instantiated.

    	Post-conditions:
    		There will no longer be a connection to the player
    		and the player can be removed from the game.

    	Semantics:
    		This method will loop while listening for messages
    		and moves from p. When the connection to the player
    		is lost this method will inform the game and stop
    		looping.

    */
    try {
      while ((message = p.getInput().readLine()) != null) {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(message));
        Document doc = builder.parse(is);

        Element root = doc.getDocumentElement();

        // Server only deals with messages
        if (root.getTagName().equals("message")) {
          parseMessage(root);
        }
      }
    } catch (Exception e) {
    }

    game.removePlayer(p);
  }