gpt4 book ai didi

org.apache.knox.gateway.util.XmlUtils类的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 06:54:40 33 4
gpt4 key购买 nike

本文整理了Java中org.apache.knox.gateway.util.XmlUtils类的一些代码示例,展示了XmlUtils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlUtils类的具体详情如下:
包路径:org.apache.knox.gateway.util.XmlUtils
类名称:XmlUtils

XmlUtils介绍

暂无

代码示例

代码示例来源:origin: apache/knox

@Override
public void store( GatewayDescriptor descriptor, Writer writer ) throws IOException {
 try {
  Document document = XmlUtils.createDocument();
  Element gateway = document.createElement( GATEWAY );
  document.appendChild( gateway );
  for( ResourceDescriptor resource : descriptor.resources() ) {
   gateway.appendChild( createResource( document, resource ) );
  }
  XmlUtils.writeXml( document, writer );
 } catch( ParserConfigurationException | TransformerException e ) {
  throw new IOException( e );
 }
}

代码示例来源:origin: apache/knox

public static void writeXml( Document document, Writer writer ) throws TransformerException {
 Transformer t = XmlUtils.getTransformer( false, true, 4, false );
 writeXml( document, writer, t );
}

代码示例来源:origin: org.apache.knox/gateway-util-common

public static Document readXml( File file ) throws ParserConfigurationException, IOException, SAXException {
 return readXml( new FileInputStream( file ));
}

代码示例来源:origin: org.apache.knox/gateway-shell

@Override
 public Response call() throws Exception {
  Document document = XmlUtils.createDocument();
  Element root = document.createElement( ELEMENT_TABLE_SCHEMA );
  document.appendChild( root );
  for( Family<Request> family : families ) {
   Element columnSchema = document.createElement( ELEMENT_COLUMN_SCHEMA );
   columnSchema.setAttribute( ATTRIBUTE_NAME, family.name() );
   for( Attribute attribute : family.attributes() ) {
    columnSchema.setAttribute( attribute.getName(), attribute.getValue().toString() );
   }
   root.appendChild( columnSchema );
  }
  StringWriter writer = new StringWriter();
  Transformer t = XmlUtils.getTransformer( true, false, 0, false );
  XmlUtils.writeXml( document, writer, t );
  URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/schema" );
  HttpPost request = new HttpPost( uri.build() );
  HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", StandardCharsets.UTF_8 ) );
  request.setEntity( entity );
  return new Response( execute( request ) );
 }
};

代码示例来源:origin: org.apache.knox/gateway-server

private void mergeWebXmlOverrides( File webInfDir ) throws IOException, SAXException, ParserConfigurationException, TransformerException {
 File webXmlFile = new File( webInfDir, "web.xml" );
 Document webXmlDoc;
 if( webXmlFile.exists() ) {
  // Backup original web.xml file.
  File originalWebXmlFile = new File( webInfDir, "original-web.xml" );
  FileUtils.copyFile( webXmlFile, originalWebXmlFile );
  webXmlDoc = XmlUtils.readXml( webXmlFile );
 } else {
  webXmlDoc = XmlUtils.createDocument();
  webXmlDoc.appendChild( webXmlDoc.createElement( "web-app" ) );
 }
 File overrideWebXmlFile = new File( webInfDir, "override-web.xml" );
 if( overrideWebXmlFile.exists() ) {
  Document overrideWebXmlDoc = XmlUtils.readXml( overrideWebXmlFile );
  Element originalRoot = webXmlDoc.getDocumentElement();
  Element overrideRoot = overrideWebXmlDoc.getDocumentElement();
  NodeList overrideNodes = overrideRoot.getChildNodes();
  for( int i = 0, n = overrideNodes.getLength(); i < n; i++ ) {
   Node overrideNode = overrideNodes.item( i );
   if( overrideNode.getNodeType() == Node.ELEMENT_NODE ) {
    Node importedNode = webXmlDoc.importNode( overrideNode, true );
    originalRoot.appendChild( importedNode );
   }
  }
  
  XmlUtils.writeXml( webXmlDoc, new OutputStreamWriter(new FileOutputStream(webXmlFile), StandardCharsets.UTF_8) );
 }
}

代码示例来源:origin: org.apache.knox/gateway-util-common

public static Document createDocument() throws ParserConfigurationException {
 return createDocument(true);
}

代码示例来源:origin: org.apache.knox/gateway-provider-rewrite

private static final void writeBufferedElement( Node node, Writer writer ) throws IOException {
 try {
  Transformer t = XmlUtils.getTransformer( false, false, 0, true );
  t.transform( new DOMSource( node ), new StreamResult( writer ) );
 } catch( TransformerException e ) {
  throw new IOException( e );
 }
}

代码示例来源:origin: apache/knox

@Override
 public Response call() throws Exception {
  Document document = XmlUtils.createDocument();
  Element root = document.createElement( ELEMENT_TABLE_SCHEMA );
  document.appendChild( root );
  for( Family<Request> family : families ) {
   Element columnSchema = document.createElement( ELEMENT_COLUMN_SCHEMA );
   columnSchema.setAttribute( ATTRIBUTE_NAME, family.name() );
   for( Attribute attribute : family.attributes() ) {
    columnSchema.setAttribute( attribute.getName(), attribute.getValue().toString() );
   }
   root.appendChild( columnSchema );
  }
  StringWriter writer = new StringWriter();
  Transformer t = XmlUtils.getTransformer( true, false, 0, false );
  XmlUtils.writeXml( document, writer, t );
  URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/schema" );
  HttpPost request = new HttpPost( uri.build() );
  HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", StandardCharsets.UTF_8 ) );
  request.setEntity( entity );
  return new Response( execute( request ) );
 }
};

代码示例来源:origin: apache/knox

webXmlDoc = XmlUtils.readXml( webXmlFile );
} else {
 webXmlDoc = XmlUtils.createDocument();
 webXmlDoc.appendChild( webXmlDoc.createElement( "web-app" ) );
 Document overrideWebXmlDoc = XmlUtils.readXml( overrideWebXmlFile );
 Element originalRoot = webXmlDoc.getDocumentElement();
 Element overrideRoot = overrideWebXmlDoc.getDocumentElement();
  XmlUtils.writeXml(webXmlDoc, outputStreamWriter);

代码示例来源:origin: apache/knox

public static Document createDocument() throws ParserConfigurationException {
 return createDocument(true);
}

代码示例来源:origin: apache/knox

private static void writeBufferedElement( Node node, Writer writer ) throws IOException {
  try {
   Transformer t = XmlUtils.getTransformer( false, false, 0, true );
   t.transform( new DOMSource( node ), new StreamResult( writer ) );
  } catch( TransformerException e ) {
   throw new IOException( e );
  }
 }
}

代码示例来源:origin: org.apache.knox/gateway-shell

@Override
 public Response call() throws Exception {
  Document document = XmlUtils.createDocument();
  Element root = document.createElement( ELEMENT_CELL_SET );
  document.appendChild( root );
  Element row = document.createElement( ELEMENT_ROW );
  row.setAttribute( ATTRIBUTE_KEY, Base64.encodeBase64String( rowId.getBytes( StandardCharsets.UTF_8 ) ) );
  root.appendChild( row );
  for( InsertableColumn column : columns ) {
   Element cell = document.createElement( ELEMENT_CELL );
   cell.setAttribute( ATTRIBUTE_COLUMN, column.encodedName() );
   if( column.time() != null ) {
    cell.setAttribute( ATTRIBUTE_TIMESTAMP, column.time().toString() );
   }
   cell.setTextContent( column.encodedValue() );
   row.appendChild( cell );
  }
  StringWriter writer = new StringWriter();
  Transformer t = XmlUtils.getTransformer( true, false, 0, false );
  XmlUtils.writeXml( document, writer, t );
  URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/false-row-key" );
  HttpPost request = new HttpPost( uri.build() );
  HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", StandardCharsets.UTF_8 ) );
  request.setEntity( entity );
  return new Response( execute( request ) );
 }
};

代码示例来源:origin: org.apache.knox/gateway-server

@Override
public void store( GatewayDescriptor descriptor, Writer writer ) throws IOException {
 try {
  Document document = XmlUtils.createDocument();
  Element gateway = document.createElement( GATEWAY );
  document.appendChild( gateway );
  for( ResourceDescriptor resource : descriptor.resources() ) {
   gateway.appendChild( createResource( document, resource ) );
  }
  XmlUtils.writeXml( document, writer );
 } catch( ParserConfigurationException e ) {
  throw new IOException( e );
 } catch( TransformerException e ) {
  throw new IOException( e );
 }
}

代码示例来源:origin: org.apache.knox/gateway-util-common

public static void writeXml( Document document, Writer writer ) throws TransformerException {
 Transformer t = XmlUtils.getTransformer( false, true, 4, false );
 writeXml( document, writer, t );
}

代码示例来源:origin: org.apache.knox/gateway-provider-rewrite

protected HtmlFilterReaderBase( Reader reader ) throws IOException, ParserConfigurationException {
 this.reader = reader;
 document = XmlUtils.createDocument( false );
 stack = new Stack<>();
 parser = new StreamedSource( reader );
 iterator = parser.iterator();
 writer = new StringWriter();
 buffer = writer.getBuffer();
 offset = 0;
}

代码示例来源:origin: apache/knox

public static Document readXml( File file ) throws ParserConfigurationException, IOException, SAXException {
 return readXml(Files.newInputStream(file.toPath()));
}

代码示例来源:origin: apache/knox

@Override
 public Response call() throws Exception {
  Document document = XmlUtils.createDocument();
  Element root = document.createElement( ELEMENT_CELL_SET );
  document.appendChild( root );
  Element row = document.createElement( ELEMENT_ROW );
  row.setAttribute( ATTRIBUTE_KEY, Base64.encodeBase64String( rowId.getBytes( StandardCharsets.UTF_8 ) ) );
  root.appendChild( row );
  for( InsertableColumn column : columns ) {
   Element cell = document.createElement( ELEMENT_CELL );
   cell.setAttribute( ATTRIBUTE_COLUMN, column.encodedName() );
   if( column.time() != null ) {
    cell.setAttribute( ATTRIBUTE_TIMESTAMP, column.time().toString() );
   }
   cell.setTextContent( column.encodedValue() );
   row.appendChild( cell );
  }
  StringWriter writer = new StringWriter();
  Transformer t = XmlUtils.getTransformer( true, false, 0, false );
  XmlUtils.writeXml( document, writer, t );
  URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/false-row-key" );
  HttpPost request = new HttpPost( uri.build() );
  HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", StandardCharsets.UTF_8 ) );
  request.setEntity( entity );
  return new Response( execute( request ) );
 }
};

代码示例来源:origin: apache/knox

@Override
public void store( UrlRewriteRulesDescriptor descriptor, Writer writer ) throws IOException {
 try {
  Document document = XmlUtils.createDocument();
  XmlUtils.writeXml( document, writer );

代码示例来源:origin: org.apache.knox/gateway-provider-rewrite

private void processStartDocument( StartDocument event ) throws ParserConfigurationException {
 //System.out.println( "SD=" + event );
 String s;
 document = XmlUtils.createDocument( false );
 pushLevel( null, event, document, document, config );
 writer.write( "<?xml" );
 s = event.getVersion();
 if( s == null ) {
  s = DEFAULT_XML_VERSION;
 }
 writer.write( " version=\"");
 writer.write( s );
 writer.write( "\"" );
 s = event.getCharacterEncodingScheme();
 if( s != null ) {
  writer.write( " encoding=\"");
  writer.write( s );
  writer.write( "\"" );
 }
 writer.write( " standalone=\"");
 writer.write( event.isStandalone() ? "yes" : "no" );
 writer.write( "\"" );
 writer.write( "?>" );
}

代码示例来源:origin: apache/knox

public static HaDescriptor load(InputStream inputStream) throws IOException {
 HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
 try {
   Document document = XmlUtils.readXml( inputStream );
   NodeList nodeList = document.getElementsByTagName(SERVICE_ELEMENT);
   if (nodeList != null && nodeList.getLength() > 0) {
    for (int i = 0; i < nodeList.getLength(); i++) {
      Element element = (Element) nodeList.item(i);
      HaServiceConfig config = HaDescriptorFactory.createServiceConfig(element.getAttribute(SERVICE_NAME_ATTRIBUTE),
         element.getAttribute(ENABLED_ATTRIBUTE),
         element.getAttribute(MAX_FAILOVER_ATTEMPTS),
         element.getAttribute(FAILOVER_SLEEP),
         element.getAttribute(MAX_RETRY_ATTEMPTS),
         element.getAttribute(RETRY_SLEEP),
         element.getAttribute(ZOOKEEPER_ENSEMBLE),
         element.getAttribute(ZOOKEEPER_NAMESPACE));
      descriptor.addServiceConfig(config);
    }
   }
 } catch (ParserConfigurationException | SAXException e) {
   LOG.failedToLoadHaDescriptor(e);
   throw new IOException(e);
 }
 return descriptor;
}

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com