Exemplo n.º 1
0
 private static Condition parse(Element element, LogHeaderDefinition definition) {
   String name = element.getTagName();
   if ("message".equals(name))
     try {
       return new MessageCondition(Pattern.compile(element.getTextContent()));
     } catch (PatternSyntaxException ex) {
       throw new RuntimeException(
           "[LogFilter] invalid regex " + element.getTextContent() + " in message element", ex);
     }
   else if ("field".equals(name)) {
     Attr attr = element.getAttributeNode("name");
     if (attr == null)
       throw new IllegalArgumentException("[LogFilter] name attribute missing in field element");
     int index = Arrays.asList(definition.groupNames).indexOf(attr.getNodeValue());
     try {
       Pattern pattern = Pattern.compile(element.getTextContent());
       return new FieldCondition(pattern, index);
     } catch (PatternSyntaxException ex) {
       throw new RuntimeException(
           "[LogFilter] invalid regex " + element.getTextContent() + " in field element", ex);
     }
   } else if ("and".equals(name)) return new AndCondition(getChildConditions(element, definition));
   else if ("or".equals(name)) return new OrCondition(getChildConditions(element, definition));
   else if ("not".equals(name)) {
     return new NotCondition(getChildConditions(element, definition)[0]);
   } else if ("index".equals(name)) {
     return new IndexCondition(Integer.parseInt(element.getTextContent()));
   } else if ("following".equals(name)) {
     boolean includeSelf = Boolean.parseBoolean(element.getAttribute("includeSelf"));
     return new FollowingCondition(getChildConditions(element, definition)[0], includeSelf);
   } else if ("preceding".equals(name)) {
     boolean includeSelf = Boolean.parseBoolean(element.getAttribute("includeSelf"));
     return new PrecedingCondition(getChildConditions(element, definition)[0], includeSelf);
   } else throw new RuntimeException("[LogFilter] invalid element " + name);
 }
Exemplo n.º 2
0
 private MathElement build(Element element) throws InkMLComplianceException {
   String n = element.getNodeName();
   if (n.equals("apply")) {
     Element ce = (Element) element.getFirstChild();
     Operator op = getOperator(ce);
     while (ce.getNextSibling() != null) {
       ce = (Element) ce.getNextSibling();
       op.appendParameter((Value) build(ce));
     }
     return op;
   } else if (n.equals("cn")) {
     return new Value(Double.parseDouble(element.getTextContent()));
   } else if (n.equals("exponentiale")) {
     return new Value(Math.E);
   } else if (n.equals("pe")) {
     return new Value(Math.PI);
   } else if (n.equals("true")) {
     return new Value(true);
   } else if (n.equals("false")) {
     return new Value(false);
   } else if (n.equals("ci")) {
     Identifier id = new Identifier(element.getTextContent());
     this.parameters.put(id.getId(), id);
     return id;
   } else {
     throw new InkMLComplianceException("Element '" + n + "' is not supported");
   }
 }
  private void writeElement(OutputNode thisNode, Element anyElement) throws Exception {
    thisNode.setName(anyElement.getLocalName());
    thisNode.getAttributes().remove("class");
    if (!getCurrentNamespace(thisNode).equals(anyElement.getNamespaceURI().toString())) {
      thisNode.setAttribute("xmlns", anyElement.getNamespaceURI().toString());
      thisNode.setReference(anyElement.getNamespaceURI().toString());
    }
    NodeList childList = anyElement.getChildNodes();
    boolean childElements = false;
    for (int i = 0; i < childList.getLength(); i++) {
      Node n = childList.item(i);
      if (n instanceof Attr) {
        thisNode.setAttribute(n.getNodeName(), n.getNodeValue());
      }
      if (n instanceof Element) {
        childElements = true;
        Element e = (Element) n;
        writeElement(thisNode.getChild(e.getLocalName()), e);
      }
    }
    if (anyElement.getNodeValue() != null) {
      thisNode.setValue(anyElement.getNodeValue());
    }

    // added to work with harmony ElementImpl... getNodeValue doesn't seem to work!!!
    if (!childElements && anyElement.getTextContent() != null) {
      thisNode.setValue(anyElement.getTextContent());
    }
  }
 @Override
 protected void postProcess(ParserContext context, BeanAssembler assembler, Element element) {
   super.postProcess(context, assembler, element);
   if (element.getTextContent() != null && !element.getTextContent().isEmpty()) {
     assembler.getBean().addPropertyValue("expression", element.getTextContent());
   }
 }
Exemplo n.º 5
0
 private synchronized void launchBrowser() {
   try {
     // Note, we use standard DOM to read in the XML. This is necessary so that
     // Launcher has fewer dependencies.
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     Document document = factory.newDocumentBuilder().parse(configFile);
     Element rootElement = document.getDocumentElement();
     Element adminElement = (Element) rootElement.getElementsByTagName("adminConsole").item(0);
     String port = "-1";
     String securePort = "-1";
     Element portElement = (Element) adminElement.getElementsByTagName("port").item(0);
     if (portElement != null) {
       port = portElement.getTextContent();
     }
     Element securePortElement = (Element) adminElement.getElementsByTagName("securePort").item(0);
     if (securePortElement != null) {
       securePort = securePortElement.getTextContent();
     }
     if ("-1".equals(port)) {
       BrowserLauncher.openURL("https://127.0.0.1:" + securePort + "/index.html");
     } else {
       BrowserLauncher.openURL("http://127.0.0.1:" + port + "/index.html");
     }
   } catch (Exception e) {
     // Make sure to print the exception
     e.printStackTrace(System.out);
     JOptionPane.showMessageDialog(new JFrame(), configFile + " " + e.getMessage());
   }
 }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
0
  public static Message parseMessage(Document document) {
    NodeList childs = document.getDocumentElement().getChildNodes();

    boolean isMessage = false;
    boolean success = false;
    String text = "";

    for (int i = 0; i < childs.getLength(); i++) {
      if (childs.item(i) instanceof Element) {
        Element el = (Element) childs.item(i);

        if (el.getNodeName().equals("text") || el.getNodeName().equals("message")) {
          text = el.getTextContent();
        }

        if (el.getNodeName().equals("success")) {
          isMessage = true;

          success = Boolean.parseBoolean(el.getTextContent());
        }
      }
    }

    if (isMessage) {
      return new Message(success, text);
    }

    return null;
  }
Exemplo n.º 8
0
  private static Header parseHeader(Node parent) throws XmlParserException {
    Header header = new Header();

    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;
      try {
        if (element.getTagName().equals("nrpeaks"))
          header.setNrPeaks(Integer.parseInt(element.getTextContent()));
        else if (element.getTagName().equals("date")) header.setDate(element.getTextContent());
        else if (element.getTagName().equals("owner")) header.setOwner(element.getTextContent());
        else if (element.getTagName().equals("description"))
          header.setDescription(element.getTextContent());
        else if (element.getTagName().equals("sets")) header.addSetInfos(parseSets(element));
        else if (element.getTagName().equals("measurements"))
          header.addMeasurementInfos(parseMeasurements(element));
        else if (element.getTagName().equals("annotations")) {
          Vector<Annotation> annotations = parseAnnotations(element);
          if (annotations != null)
            for (Annotation annotation : annotations) header.addAnnotation(annotation);
        }
      } catch (Exception e) {
        throw new XmlParserException(
            "Invalid value in header (" + element.getTagName() + "): '" + e.getMessage() + "'.");
      }
    }

    return header;
  }
Exemplo n.º 9
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;
  }
Exemplo n.º 10
0
 private void appendDescription(Element syncData, MSTask task) {
   // description
   Element body = DOMUtils.getUniqueElement(syncData, "Body");
   if (body != null) {
     Element data = DOMUtils.getUniqueElement(body, "Data");
     if (data != null) {
       Type bodyType =
           Type.fromInt(
               Integer.parseInt(DOMUtils.getUniqueElement(body, "Type").getTextContent()));
       String txt = data.getTextContent();
       if (bodyType == Type.PLAIN_TEXT) {
         task.setDescription(data.getTextContent());
       } else if (bodyType == Type.RTF) {
         task.setDescription(RTFUtils.extractB64CompressedRTF(txt));
       } else {
         logger.warn("Unsupported body type: " + bodyType + "\n" + txt);
       }
     }
   }
   Element rtf = DOMUtils.getUniqueElement(syncData, "Compressed_RTF");
   if (rtf != null) {
     String txt = rtf.getTextContent();
     task.setDescription(RTFUtils.extractB64CompressedRTF(txt));
   }
 }
Exemplo n.º 11
0
  public void testTld() throws Exception {

    InputStream in = ClassLoader.getSystemResourceAsStream("META-INF/metawidget-faces.tld");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.streamBetween(in, out);
    Document document = XmlUtils.documentFromString(out.toString());

    Element root = document.getDocumentElement();
    assertEquals(root.getNodeName(), "taglib");

    // org.metawidget.faces.taglib.html.HtmlMetawidgetTag

    Element tag = XmlUtils.getChildNamed(root, "tag");
    Element tagclass = XmlUtils.getChildNamed(tag, "tagclass");
    assertEquals(tagclass.getTextContent(), "org.metawidget.faces.taglib.html.HtmlMetawidgetTag");

    Element bodycontent = XmlUtils.getSiblingNamed(tagclass, "bodycontent");
    assertEquals(bodycontent.getTextContent(), "JSP");

    // org.metawidget.faces.taglib.StubTag

    tag = XmlUtils.getSiblingNamed(tag, "tag");
    tagclass = XmlUtils.getChildNamed(tag, "tagclass");
    assertEquals(tagclass.getTextContent(), "org.metawidget.faces.taglib.StubTag");

    bodycontent = XmlUtils.getSiblingNamed(tagclass, "bodycontent");
    assertEquals(bodycontent.getTextContent(), "JSP");
  }
Exemplo n.º 12
0
  private void ReaderPeriodoDemonstracaoFinanceira(File fileXML)
      throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory builderfactory = DocumentBuilderFactory.newInstance();

    DocumentBuilder docbuilder = builderfactory.newDocumentBuilder();
    Document document = docbuilder.parse(fileXML);
    document.normalize();

    Element elementAOPDF = getSubtag(document, "ArrayOfPeriodoDemonstracaoFinanceira");
    NodeList nodelistNIP = getNodeList(elementAOPDF, "NumeroIdentificacaoPeriodo");
    NodeList nodelistDIP = getNodeList(elementAOPDF, "DataInicioPeriodo");
    NodeList nodelistDFP = getNodeList(elementAOPDF, "DataFimPeriodo");

    NIP = new String[nodelistNIP.getLength()];
    I_DATAINICIOPERIODO = new String[nodelistDIP.getLength()];
    I_DATAFIMPERIODO = new String[nodelistDFP.getLength()];

    for (int i = 0; i < nodelistNIP.getLength(); i++) {
      Node nodeNIP = nodelistNIP.item(i);
      Node nodeDIP = nodelistDIP.item(i);
      Node nodeDFP = nodelistDFP.item(i);
      Element elementNIP = (Element) nodeNIP;
      Element elementDIP = (Element) nodeDIP;
      Element elementDFP = (Element) nodeDFP;

      NIP[i] = elementNIP.getTextContent();
      I_DATAINICIOPERIODO[i] = elementDIP.getTextContent();
      I_DATAFIMPERIODO[i] = elementDFP.getTextContent();
    }
  }
Exemplo n.º 13
0
  public Receta leerReceta(String nombre) throws IOException {
    Receta receta = null;

    File file = new File(rutaAlmacenamientoExterno + "recetas.xml");
    if (file.exists()) {
      Document doc = getDoc("recetas.xml");

      if (doc != null) {

        // Get a list of all elements in the document
        NodeList list = doc.getElementsByTagName("receta");

        for (int i = 0; i < list.getLength(); i++) {
          // Get element
          Element current = (Element) list.item(i);
          if (current.getAttribute("nombre").equals(nombre.trim())) {

            NodeList ingredientes = current.getElementsByTagName("ingrediente");
            List<Ingrediente> ings = new ArrayList<Ingrediente>();
            for (int j = 0; j < ingredientes.getLength(); j++) {
              Element elem = (Element) ingredientes.item(j);
              Ingrediente ing =
                  new Ingrediente(elem.getAttribute("nombre"), elem.getAttribute("cantidad"));
              ings.add(ing);
            }

            NodeList elaboracionList = current.getElementsByTagName("elaboracion");
            // Como solo hay 1 cojo el pos=0
            Element elab = (Element) elaboracionList.item(0);
            // Comprobamos el modo mediante el atributo "mode"
            if (elab.getAttribute("mode").equals("simple")) {
              // Modo simple
              receta = new RecetaSimple(nombre, ings, elab.getTextContent());

            } else if (elab.getAttribute("mode").equals("advanced")) {
              // Modo avanzado
              List<Paso> pasosList = new ArrayList<Paso>();
              NodeList pasos = elab.getElementsByTagName("paso");
              for (int j = 0; j < pasos.getLength(); j++) {
                Element elem = (Element) pasos.item(j);
                if (elem.hasAttribute("path")) {
                  // El paso tiene imagen asociada
                  Paso p = new Paso(elem.getTextContent(), elem.getAttribute("path"));
                  p.setNumber(elem.getAttribute("numero"));
                  pasosList.add(p);
                } else {
                  Paso p = new Paso(elem.getTextContent());
                  p.setNumber(elem.getAttribute("numero"));
                  pasosList.add(p);
                }
              }
              receta = new RecetaAdvanced(nombre, ings, pasosList);
            }
          }
        }
      }
    }

    return receta;
  }
Exemplo n.º 14
0
  /*
   * (non-Javadoc)
   * @see addressbook.model.PersistenceAccess#load()
   */
  public void load() throws IOException {

    // Read data from given file into DOM document
    final FileInputStream in = new FileInputStream(dataFile);
    Document document = null;
    try {
      document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
    } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    in.close();

    // Put document data in address book
    // Get AddressBookAccess
    Element ab = null;
    if (document.getElementsByTagName("AddressBook").getLength() == 1) {
      ab = (Element) document.getElementsByTagName("AddressBook").item(0);
    } else {
      // Parse error
      throw new IOException("No single AddressBookAccess element found");
    }

    // Read and store entries
    NodeList list = ab.getChildNodes();
    for (int i = 0; i < list.getLength(); ++i) {
      if (list.item(i).getNodeType() == Node.ELEMENT_NODE) {

        Entry entry = new Entry();
        Element el = (Element) list.item(i);

        // Personal data
        entry.setName(el.getAttribute("FirstName"), el.getAttribute("SurName"));
        entry.setGender(
            el.getAttribute("Gender").equalsIgnoreCase("M") ? Gender.Male : Gender.Female);
        entry.setDateOfBirth(Entry.dateFormatter.parseDateTime(el.getAttribute("DateOfBirth")));

        // Contact Information
        if (el.getElementsByTagName("Contact").getLength() > 0) {
          Element contactEl = (Element) el.getElementsByTagName("Contact").item(0);
          if (contactEl.getAttribute("type").equalsIgnoreCase("phone")) {
            entry.setContactPhoneNumber(Integer.parseInt(contactEl.getTextContent()));
          } else if (contactEl.getAttribute("type").equalsIgnoreCase("email")) {
            entry.setContactEmailAddress(contactEl.getTextContent());
          }
        }

        try {
          addEntry(entry);
        } catch (SizeLimitReachedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
 /**
  * Get the text content of the _child_ element or return default value if element does not
  * exist. The elements are used for selection but the namespace is ignored.
  *
  * @param element
  * @param tagName
  * @param defaultValue
  */
 public static String getTextContentOfChild(
     Element element, String tagName, String defaultValue) {
   Element child = getFirstChildElement(element, tagName);
   if (child == null || child.getTextContent().trim().isEmpty()) {
     return defaultValue;
   }
   return child.getTextContent();
 }
Exemplo n.º 16
0
  @Override
  public void refreshList(String[] sss) throws Exception {
    String content = NetUtils.doGet("http://optifine.net/downloads");
    if (versions != null) return;
    versionMap = new HashMap<>();
    versions = new ArrayList<>();

    content = content.replace("&nbsp;", " ").replace("&gt;", ">").replace("&lt;", "<");

    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = factory.newDocumentBuilder();
      Document doc = db.parse(new StringBufferInputStream(content));
      Element r = doc.getDocumentElement();
      NodeList tables = r.getElementsByTagName("table");
      for (int i = 0; i < tables.getLength(); i++) {
        Element e = (Element) tables.item(i);
        if ("downloadTable".equals(e.getAttribute("class"))) {
          NodeList tr = e.getElementsByTagName("tr");
          for (int k = 0; k < tr.getLength(); k++) {
            NodeList downloadLine = ((Element) tr.item(k)).getElementsByTagName("td");
            OptiFineVersion v = new OptiFineVersion();
            for (int j = 0; j < downloadLine.getLength(); j++) {
              Element td = (Element) downloadLine.item(j);
              if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineMirror"))
                v.mirror = ((Element) td.getElementsByTagName("a").item(0)).getAttribute("href");
              if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDownload"))
                v.dl = ((Element) td.getElementsByTagName("a").item(0)).getAttribute("href");
              if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDate"))
                v.date = td.getTextContent();
              if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineFile"))
                v.ver = td.getTextContent();
            }
            if (StrUtils.isBlank(v.mcver)) {
              Pattern p = Pattern.compile("OptiFine (.*?) ");
              Matcher m = p.matcher(v.ver);
              while (m.find()) v.mcver = StrUtils.formatVersion(m.group(1));
            }
            InstallerVersion iv = new InstallerVersion(v.ver, StrUtils.formatVersion(v.mcver));
            iv.installer = iv.universal = v.mirror;
            root.add(v);
            versions.add(iv);

            List<InstallerVersion> ivl =
                ArrayUtils.tryGetMapWithList(versionMap, StrUtils.formatVersion(v.mcver));
            ivl.add(iv);
          }
        }
      }
    } catch (ParserConfigurationException | SAXException | IOException | DOMException ex) {
      throw new RuntimeException(ex);
    }

    Collections.sort(versions, InstallerVersionComparator.INSTANCE);
  }
  @Test
  public void testSearch() throws Exception {
    String input =
        "exec native('search;SELECT Account.Id, Account.Type, Account.Name FROM Account')";

    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);

    QueryResult qr = Mockito.mock(QueryResult.class);
    Mockito.stub(qr.isDone()).toReturn(true);

    ArrayList<SObject> results = new ArrayList<SObject>();
    ArrayList<Object> values = new ArrayList<Object>();

    SObject s = Mockito.mock(SObject.class);
    // Mockito.stub(s.getId()).toReturn("theID");
    Mockito.stub(s.getType()).toReturn("Account");
    results.add(s);

    Element e1 = Mockito.mock(Element.class);
    Mockito.stub(e1.getTextContent()).toReturn("The ID");
    values.add(e1);

    Element e2 = Mockito.mock(Element.class);
    Mockito.stub(e2.getTextContent()).toReturn("The Type");
    values.add(e2);

    Element e3 = Mockito.mock(Element.class);
    Mockito.stub(e3.getTextContent()).toReturn("The Name");
    values.add(e3);

    Mockito.stub(s.getAny()).toReturn(values);
    Mockito.stub(qr.getRecords()).toReturn(results);
    Mockito.stub(
            connection.query(
                "SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false))
        .toReturn(qr);

    DirectQueryExecution execution =
        (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();

    Mockito.verify(connection, Mockito.times(1))
        .query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false);

    assertArrayEquals(
        new Object[] {"The ID", "The Type", "The Name"}, (Object[]) execution.next().get(0));
  }
 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();
       }
     }
   }
 }
Exemplo n.º 19
0
  public void readHelper(org.w3c.dom.Element docElement) {

    // overwrite whatever was in the data structure
    this.urls = null;

    if (docElement.getNodeName().equals("urls")) {
      // System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
      // NodeList nList = doc.getElementsByTagName("service");

      NodeList nList = docElement.getChildNodes();

      for (int temp = 0; temp < nList.getLength(); temp++) {

        Node nNode = nList.item(temp);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {

          org.w3c.dom.Element eElement = (org.w3c.dom.Element) nNode;

          // System.out.println(eElement.getTextContent());
          String url = eElement.getTextContent();
          if (this.urls == null) {
            this.urls = new ArrayList<String>();
          }
          this.urls.add(url);
        }
      }
    }
  }
  /**
   * WhiteboardObjectTextJabberImpl constructor.
   *
   * @param xml the XML string object to parse.
   */
  public WhiteboardObjectTextJabberImpl(String xml) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
      builder = factory.newDocumentBuilder();
      InputStream in = new ByteArrayInputStream(xml.getBytes());
      Document doc = builder.parse(in);

      Element e = doc.getDocumentElement();
      String elementName = e.getNodeName();
      if (elementName.equals("text")) {
        // we have a text
        String id = e.getAttribute("id");
        double x = Double.parseDouble(e.getAttribute("x"));
        double y = Double.parseDouble(e.getAttribute("y"));
        String fill = e.getAttribute("fill");
        String fontFamily = e.getAttribute("font-family");
        int fontSize = Integer.parseInt(e.getAttribute("font-size"));
        String text = e.getTextContent();

        this.setID(id);
        this.setWhiteboardPoint(new WhiteboardPoint(x, y));
        this.setFontName(fontFamily);
        this.setFontSize(fontSize);
        this.setText(text);
        this.setColor(Color.decode(fill).getRGB());
      }
    } catch (ParserConfigurationException ex) {
      if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml);
    } catch (IOException ex) {
      if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml);
    } catch (Exception ex) {
      if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml);
    }
  }
Exemplo n.º 21
0
 public String getCopyrightText() {
   final Element copyrightNode = getNode(COPYRIGHT);
   if (copyrightNode != null) {
     return copyrightNode.getTextContent();
   }
   return null;
 }
Exemplo n.º 22
0
  public static WarConfig fromXml(Node webapp) throws IOException {
    String path;
    Element root;
    Selector selector;
    List<String> statics;

    try {
      root = webapp.join("WEB-INF/project.xml").readXml().getDocumentElement();
      selector = webapp.getWorld().getXml().getSelector();
      statics = new ArrayList<>();
      for (Element element : selector.elements(root, "application/static/path")) {
        path = element.getTextContent();
        path = path.trim();
        if (path.isEmpty() || path.startsWith("/")) {
          throw new IllegalStateException(path);
        }
        if (!path.endsWith("/")) {
          path = path + "/";
        }
        statics.add(path);
      }
      return new WarConfig(statics);
    } catch (SAXException e) {
      throw new IOException("cannot load project descriptor: " + e);
    }
  }
Exemplo n.º 23
0
 public boolean shouldProtect(String name) {
   Element protectionElement = getElement("MemoryProtection/Protect" + name, dbMeta, false);
   if (protectionElement == null) {
     return false;
   }
   return Boolean.valueOf(protectionElement.getTextContent());
 }
Exemplo n.º 24
0
 public void readXML(Document document) {
   NodeList propertiesList = document.getDocumentElement().getElementsByTagName("properties");
   if (propertiesList.getLength() > 0) {
     for (int j = 0; j < propertiesList.getLength(); j++) {
       Node m = propertiesList.item(j);
       if (m.getNodeType() == Node.ELEMENT_NODE) {
         Element propertiesE = (Element) m;
         layoutClassName = propertiesE.getAttribute("layoutClassName");
         name = propertiesE.getAttribute("name");
         NodeList propertyList = propertiesE.getElementsByTagName("property");
         for (int i = 0; i < propertyList.getLength(); i++) {
           Node n = propertyList.item(i);
           if (n.getNodeType() == Node.ELEMENT_NODE) {
             Element propertyE = (Element) n;
             String propStr = propertyE.getAttribute("property");
             String classStr = propertyE.getAttribute("class");
             String valStr = propertyE.getTextContent();
             Object value = parse(classStr, valStr);
             if (value != null) {
               propertyNames.add(propStr);
               propertyValues.add(value);
             }
           }
         }
         break;
       }
     }
   }
 }
  public static CustomXmlTraceDefinition extractDefinition(Element definitionElement) {
    CustomXmlTraceDefinition def = new CustomXmlTraceDefinition();

    def.definitionName = definitionElement.getAttribute(NAME_ATTRIBUTE);
    if (def.definitionName == null) return null;

    NodeList nodeList = definitionElement.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node node = nodeList.item(i);
      String nodeName = node.getNodeName();
      if (nodeName.equals(TIME_STAMP_OUTPUT_FORMAT_ELEMENT)) {
        Element formatElement = (Element) node;
        def.timeStampOutputFormat = formatElement.getTextContent();
      } else if (nodeName.equals(INPUT_ELEMENT_ELEMENT)) {
        InputElement inputElement = extractInputElement((Element) node);
        if (inputElement != null) {
          if (def.rootInputElement == null) {
            def.rootInputElement = inputElement;
          } else {
            return null;
          }
        }
      } else if (nodeName.equals(OUTPUT_COLUMN_ELEMENT)) {
        Element outputColumnElement = (Element) node;
        OutputColumn outputColumn = new OutputColumn();
        outputColumn.name = outputColumnElement.getAttribute(NAME_ATTRIBUTE);
        def.outputs.add(outputColumn);
      }
    }
    return def;
  }
Exemplo n.º 26
0
  private static AbstractCanvasObject createText(Element elt) {
    int x = Integer.parseInt(elt.getAttribute("x"));
    int y = Integer.parseInt(elt.getAttribute("y"));
    String text = elt.getTextContent();
    Text ret = new Text(x, y, text);

    String fontFamily = elt.getAttribute("font-family");
    String fontStyle = elt.getAttribute("font-style");
    String fontWeight = elt.getAttribute("font-weight");
    String fontSize = elt.getAttribute("font-size");
    int styleFlags = 0;
    if (fontStyle.equals("italic")) styleFlags |= Font.ITALIC;
    if (fontWeight.equals("bold")) styleFlags |= Font.BOLD;
    int size = Integer.parseInt(fontSize);
    ret.setValue(DrawAttr.FONT, new Font(fontFamily, styleFlags, size));

    String alignStr = elt.getAttribute("text-anchor");
    AttributeOption halign;
    if (alignStr.equals("start")) {
      halign = DrawAttr.ALIGN_LEFT;
    } else if (alignStr.equals("end")) {
      halign = DrawAttr.ALIGN_RIGHT;
    } else {
      halign = DrawAttr.ALIGN_CENTER;
    }
    ret.setValue(DrawAttr.ALIGNMENT, halign);

    // fill color is handled after we return
    return ret;
  }
Exemplo n.º 27
0
  /**
   * @param filePath
   * @param output
   * @throws InvalidFormatException
   * @throws IOException
   * @throws ParserConfigurationException
   * @throws TransformerException
   */
  public static void convert(String filePath, String output)
      throws InvalidFormatException, IOException, ParserConfigurationException,
          TransformerException {
    XlsxConverter converter = new XlsxConverter(filePath, output);

    Integer sheetNum = converter.x.getNumberOfSheets();
    for (int i = 0; i < sheetNum; i++) {
      XSSFSheet sheet = converter.x.getSheet(converter.x.getSheetName(i));
      String sheetName = converter.x.getSheetName(i);
      System.out.println("----starting process sheet : " + sheetName);
      // add sheet title
      {
        Element title = converter.htmlDocumentFacade.createHeader2();
        title.setTextContent(sheetName);
        converter.page.appendChild(title);
      }

      converter.processSheet(converter.page, sheet);
    }

    converter.htmlDocumentFacade.updateStylesheet();

    Element style =
        (Element) converter.htmlDocumentFacade.getDocument().getElementsByTagName("style").item(0);

    style.setTextContent(converter.css.append(style.getTextContent()).toString());

    converter.saveAsHtml(output, converter.htmlDocumentFacade.getDocument());
  }
Exemplo n.º 28
0
 public void load(Element domElement) {
   NodeList ch_list = domElement.getElementsByTagName("OGLParameter");
   for (int i = 0; i < ch_list.getLength(); ++i) {
     Element chEle = (Element) ch_list.item(i);
     addParameter(chEle.getAttribute("name"), chEle.getTextContent());
   }
 }
Exemplo n.º 29
0
  private Command buildCommand(Element elem) throws ProcessException {
    String cmdName = elem.getNodeName();
    Command command = null;

    if (cmdName == null) {
      throw new ProcessException("unable to parse command from " + elem.getTextContent());
    } else if ("wd".equalsIgnoreCase(cmdName)) {
      System.out.println("Parsing wd");
      command = new WDCommand();
      command.parse(elem);
    } else if ("file".equalsIgnoreCase(cmdName)) {
      System.out.println("Parsing file");
      command = new FileCommand();
      command.parse(elem);
    } else if ("cmd".equalsIgnoreCase(cmdName)) {
      System.out.println("Parsing cmd");
      command = new CmdCommand();
      command.parse(elem);
    } else if ("pipe".equalsIgnoreCase(cmdName)) {
      System.out.println("Parsing pipe");
      command = new PipeCommand();
      command.parse(elem);

    } else {
      throw new ProcessException("Unknown command " + cmdName + " from: " + elem.getBaseURI());
    }

    return command;
  }
Exemplo n.º 30
0
  /**
   * Convenience method to update a template bean definition from overriding XML data. If <code>
   * overrides</code> contains attribute <code>attribute</code> or a child element with name <code>
   * attribute</code>, transfer that attribute as a bean property onto <code>template</code>,
   * overwriting the default value.
   *
   * @param reference if true, the value of the attribute is to be interpreted as a runtime bean
   *     name reference; otherwise it is interpreted as a literal value
   */
  public static boolean overrideProperty(
      String attribute, BeanDefinition template, Element overrides, boolean reference) {
    Object value = null;
    if (overrides.hasAttribute(attribute)) {
      value = overrides.getAttribute(attribute);
    } else {
      NodeList children = overrides.getElementsByTagNameNS("*", attribute);
      if (children.getLength() == 1) {
        Element child = (Element) children.item(0);
        value = child.getTextContent();
      }
    }

    if (value != null) {
      if (reference) value = new RuntimeBeanReference(value.toString());

      String propName = Conventions.attributeNameToPropertyName(attribute);
      MutablePropertyValues props = template.getPropertyValues();
      props.removePropertyValue(propName);
      props.addPropertyValue(propName, value);
      return true;
    }

    return false;
  }