コード例 #1
0
  /** Calculate a location message for the event */
  private String getLocation(ValidationEvent event) {
    StringBuffer msg = new StringBuffer();

    ValidationEventLocator locator = event.getLocator();

    if (locator != null) {

      URL url = locator.getURL();
      Object obj = locator.getObject();
      Node node = locator.getNode();
      int line = locator.getLineNumber();

      if (url != null || line != -1) {
        msg.append("line " + line);
        if (url != null) msg.append(" of " + url);
      } else if (obj != null) {
        msg.append(" obj: " + obj.toString());
      } else if (node != null) {
        msg.append(" node: " + node.toString());
      }
    } else {
      msg.append(Messages.format(Messages.LOCATION_UNAVAILABLE));
    }

    return msg.toString();
  }
コード例 #2
0
 private static String getNodeValue(Node node, String nodeKey) {
   Node opt_item = node.getAttributes().getNamedItem(nodeKey);
   if (opt_item != null) {
     Matcher nameMatcher = attrExtractor.matcher(opt_item.toString());
     if (nameMatcher.find()) {
       return nameMatcher.group(1);
     }
   }
   return null;
 }
コード例 #3
0
  /**
   * Serialize the given node to a String.
   *
   * @param node Node to be serialized.
   * @return The serialized node as a java.lang.String instance.
   */
  public static String nodeToString(Node node) {

    if (importerDoc == null) {
      OMDOMFactory fac = new OMDOMFactory();
      importerDoc = (Document) fac.createOMDocument();
    }
    // Import the node as an AXIOM-DOOM node and use toSting()
    Node axiomNode = importerDoc.importNode(node, true);
    return axiomNode.toString();
  }
コード例 #4
0
ファイル: PlacesFile.java プロジェクト: edask/IMAPI
  public String FindTranslation(String xpathS) throws XPathExpressionException {

    XPath xpath = XPathFactory.newInstance().newXPath();
    String translation = "";
    NodeList nodes =
        (NodeList)
            xpath.evaluate(
                this.XpahthPlaces + "[dutch='" + xpathS + "']/english/text()",
                this.document,
                XPathConstants.NODESET);
    if (nodes != null) {
      int howmanyNodes = nodes.getLength();

      for (int i = 0; i < howmanyNodes; i++) {

        Node xNode = nodes.item(i);
        translation = xNode.getNodeValue();
      }
    } else {
      nodes =
          (NodeList)
              xpath.evaluate(
                  this.XpahthPlaces + "[english='" + xpathS + "']/dutch/text()",
                  this.document,
                  XPathConstants.NODESET);
      if (nodes != null) {
        int howmanyNodes = nodes.getLength();

        for (int i = 0; i < howmanyNodes; i++) {

          Node xNode = nodes.item(i);
          translation = xNode.toString();
        }
      }
    }

    return translation;
  }
コード例 #5
0
ファイル: XMLData.java プロジェクト: BryanMM/NoSQL
  /**
   * @return
   * @throws ParserConfigurationException
   * @throws SAXException
   * @throws IOException
   */
  public BinaryT<Keyword> LeerData()
      throws ParserConfigurationException, SAXException, IOException {
    BinaryT<Keyword> _nuevoArbol = new BinaryT();
    try {
      File file = new File("XMLDOWNLOAD.xml");

      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.parse(file);
      doc.getDocumentElement().normalize();
      data = doc.getElementsByTagName("URL");
      // System.out.println(data.getLength());

      for (int a = 0; a < data.getLength(); a++) {
        MyURL datos = new MyURL();
        NodeList PriEle = (NodeList) data.item(a);
        for (int b = 0; b < PriEle.getLength(); b++) {
          Node SecondEle = PriEle.item(b);
          String direct;
          if (SecondEle.getNodeType() == Node.ELEMENT_NODE) {
            Node TercerLevel = SecondEle.getFirstChild();

            if (TercerLevel.getNodeType() == Node.TEXT_NODE
                && SecondEle.getNodeName().equals("Directorio")) {
              prueba = TercerLevel.toString().substring(8, TercerLevel.toString().length() - 1);
            }

            if (TercerLevel.getNodeType() == Node.TEXT_NODE
                && SecondEle.getNodeName().equals("Keyword")) {
              Keyword _nuevo = new Keyword();

              _nuevo.setPalabra(
                  TercerLevel.toString().substring(8, TercerLevel.toString().lastIndexOf(":")));
              if (_nuevoArbol.contains(_nuevo) == false) {
                _nuevo.setDirectorio(prueba);
                _nuevo.getDirectorios().insert(prueba);

                _nuevo.getUrlReferencia().insertarFinal(prueba);
                _nuevoArbol.insert(_nuevo);
                // System.out.println("First");
                // _nuevo.getDirectorios().getData().imprimir();

              } else {
                // System.out.println("Second");
                _nuevoArbol.getNode(_nuevo).getData().getUrlReferencia().insertarFinal(prueba);

                // _nuevo.getDirectorios().getData().imprimir();

              }
            }
            // datos.getListaKeywords().insertarFinal(_nuevo);

          }
        }
      }
      return _nuevoArbol;

    } catch (ParserConfigurationException
        | SAXException
        | IOException
        | IllegalArgumentException e) {
      e.printStackTrace();
    }
    return _nuevoArbol;
  }
コード例 #6
0
  public static void loadPagesAndDrawers(
      Workspace workspace, Element root, FactoryManager manager) {
    List<Page> pageList = new ArrayList<Page>();
    // pagesToAdd is needed so that we can add pages all at once
    // to the page bar once all the the pages been loaded
    // Before adding all the pages, this method makes a check
    // if there is only one page with an empty name - if so, it will just
    // add the page to the workspace/block canvas but not add it to this
    // LinkedHashMap<Page, PageBlockDrawer> pagesToAdd = new LinkedHashMap<Page, PageBlockDrawer>();
    LinkedHashMap<String, ArrayList<RenderableBlock>> blocksForDrawers =
        new LinkedHashMap<String, ArrayList<RenderableBlock>>();
    LinkedHashMap<Page, ArrayList<RenderableBlock>> blocksForPages =
        new LinkedHashMap<Page, ArrayList<RenderableBlock>>();

    NodeList pagesRoot = root.getElementsByTagName("Pages");
    if (pagesRoot != null) {
      // isBlankPage denotes if the page being loaded is a default blank page
      // in other words, the project did not specify any pages for their environment.
      // EvoBeaker does this
      boolean isBlankPage = false;
      Node pagesNode = pagesRoot.item(0);
      if (pagesNode == null) {
        return; // short-circuit exit if there's nothing to load
      }
      Node opt_item = pagesNode.getAttributes().getNamedItem("drawer-with-page");
      if (opt_item != null) {
        Matcher nameMatcher = attrExtractor.matcher(opt_item.toString());
        if (nameMatcher.find()) // will be true
        {
          Workspace.everyPageHasDrawer = nameMatcher.group(1).equals("yes") ? true : false;
        }
      }
      opt_item = pagesNode.getAttributes().getNamedItem("is-blank-page");
      if (opt_item != null) {
        Matcher nameMatcher = attrExtractor.matcher(opt_item.toString());
        if (nameMatcher.find()) // will be true
        {
          isBlankPage = nameMatcher.group(1).equals("yes") ? true : false;
        }
      }

      // whether pages should show a control to collapse them or not
      boolean collapsiblePages = getBooleanValue(pagesNode, "collapsible-pages");

      Page page;
      NodeList pages = pagesNode.getChildNodes();
      Node pageNode;
      String pageName = "";
      String pageDrawer = null;
      Color pageColor = null;
      boolean pageInFullView = true;
      int pageWidth = -1;
      String pageId = null;
      for (int i = 0; i < pages.getLength(); i++) { // find them
        pageNode = pages.item(i);
        if (pageNode.getNodeName().equals("Page")) { // a page entry
          pageName = getNodeValue(pageNode, "page-name");
          pageColor = getColorValue(pageNode, "page-color");
          pageWidth = getIntValue(pageNode, "page-width");
          pageDrawer = getNodeValue(pageNode, "page-drawer");
          pageInFullView = getBooleanValue(pageNode, "page-infullview");
          pageId = getNodeValue(pageNode, "page-id");
          page =
              new Page(
                  workspace,
                  pageName,
                  pageWidth,
                  0,
                  pageDrawer,
                  pageInFullView,
                  pageColor,
                  collapsiblePages);
          page.setPageId(pageId);

          NodeList pageNodes = pageNode.getChildNodes();
          String drawer = null;
          if (Workspace.everyPageHasDrawer) {
            // create drawer instance
            manager.addDynamicDrawer(page.getPageDrawer());
            ArrayList<RenderableBlock> drawerBlocks = new ArrayList<RenderableBlock>();

            for (int k = 0; k < pageNodes.getLength(); k++) {
              Node drawerNode = pageNodes.item(k);
              if (drawerNode.getNodeName().equals("PageDrawer")) {
                NodeList genusMembers = drawerNode.getChildNodes();
                String genusName;
                for (int j = 0; j < genusMembers.getLength(); j++) {
                  Node genusMember = genusMembers.item(j);
                  if (genusMember.getNodeName().equals("BlockGenusMember")) {
                    genusName = genusMember.getTextContent();
                    assert BlockGenus.getGenusWithName(genusName) != null
                        : "Unknown BlockGenus: " + genusName;
                    Block block = new Block(workspace, genusName);
                    drawerBlocks.add(
                        new FactoryRenderableBlock(workspace, manager, block.getBlockID()));
                  }
                }
                blocksForDrawers.put(drawer, drawerBlocks);
                break; // there can only be one drawer for this page
              }
            }
          }

          if (isBlankPage) {
            // place a blank page as the first page
            workspace.putPage(page, 0);
            // if the system uses blank pages, then we expect only one page
            break; // we anticipate only one page
          } else {
            // we add to the end of the set of pages
            int position = pageList.size();
            // add to workspace
            if (position == 0) {
              // replace the blank default page
              workspace.putPage(page, 0);
            } else {
              workspace.addPage(page, position);
            }
            pageList.add(position, page);
          }

          blocksForPages.put(page, page.loadPageFrom(pageNode, false));
        }
      }
      // add blocks in drawers
      for (String d : blocksForDrawers.keySet()) {
        manager.addDynamicBlocks(blocksForDrawers.get(d), d);
      }
      // blocks in pages
      for (Page p : blocksForPages.keySet()) {
        p.addLoadedBlocks(blocksForPages.get(p), false);
      }
    }
  }
コード例 #7
0
  public static void loadBlockDrawerSets(
      Workspace workspace, Element root, FactoryManager manager) {
    Pattern attrExtractor = Pattern.compile("\"(.*)\"");
    Matcher nameMatcher;
    NodeList drawerSetNodes = root.getElementsByTagName("BlockDrawerSet");
    Node drawerSetNode;
    for (int i = 0; i < drawerSetNodes.getLength(); i++) {
      drawerSetNode = drawerSetNodes.item(i);
      if (drawerSetNode.getNodeName().equals("BlockDrawerSet")) {
        NodeList drawerNodes = drawerSetNode.getChildNodes();
        Node drawerNode;
        // retreive drawer information of this bar
        for (int j = 0; j < drawerNodes.getLength(); j++) {
          drawerNode = drawerNodes.item(j);
          if (drawerNode.getNodeName().equals("BlockDrawer")) {
            String drawerName = null;
            Color buttonColor = Color.blue;
            StringTokenizer col;
            nameMatcher =
                attrExtractor.matcher(drawerNode.getAttributes().getNamedItem("name").toString());
            if (nameMatcher.find()) { // will be true
              drawerName = nameMatcher.group(1);
            }

            // get drawer's color:
            Node colorNode = drawerNode.getAttributes().getNamedItem("button-color");
            //    					if(colorNode == null){
            //    						buttonColor = Color.blue;
            //    						System.out.println("Loading a drawer without defined color: ");
            //    						for(int ai=0; ai<drawerNode.getAttributes().getLength(); ai++){
            //
            //	System.out.println("\t"+drawerNode.getAttributes().item(ai).getNodeName()+
            //        								", "+drawerNode.getAttributes().item(ai).getNodeValue());
            //        					}
            //    					}else{
            if (colorNode != null) {
              nameMatcher = attrExtractor.matcher(colorNode.toString());
              if (nameMatcher.find()) { // will be true
                col = new StringTokenizer(nameMatcher.group(1));
                if (col.countTokens() == 3) {
                  buttonColor =
                      new Color(
                          Integer.parseInt(col.nextToken()),
                          Integer.parseInt(col.nextToken()),
                          Integer.parseInt(col.nextToken()));
                } else {
                  buttonColor = Color.BLACK;
                }
              }
            }

            manager.addStaticDrawer(drawerName, buttonColor);

            // get block genuses in drawer and create blocks
            NodeList drawerBlocks = drawerNode.getChildNodes();
            Node blockNode;
            ArrayList<RenderableBlock> drawerRBs = new ArrayList<RenderableBlock>();
            for (int k = 0; k < drawerBlocks.getLength(); k++) {
              blockNode = drawerBlocks.item(k);
              if (blockNode.getNodeName().equals("BlockGenusMember")) {
                String genusName = blockNode.getTextContent();
                assert BlockGenus.getGenusWithName(genusName) != null
                    : "Unknown BlockGenus: " + genusName;
                Block newBlock;
                // don't link factory blocks to their stubs because they will
                // forever remain inside the drawer and never be active
                newBlock = new Block(workspace, genusName, false);
                drawerRBs.add(
                    new FactoryRenderableBlock(workspace, manager, newBlock.getBlockID()));
              }
            }
            manager.addStaticBlocks(drawerRBs, drawerName);
          }
        }
      }
    }
  }
コード例 #8
0
 public String toString() {
   return source.toString();
 }
コード例 #9
0
ファイル: CWRCStream.java プロジェクト: cwrc/CWRC-merger
 @Override
 public String getId(Node node) {
   return node.toString();
 }
コード例 #10
0
 public String toString() {
   return "XmlNode: type=" + dom.getNodeType() + " dom=" + dom.toString();
 }